Skip to content

feat(proto): implement ProtoAdapters — 15/15 integration tests pass#100

Closed
ottobot-ai wants to merge 1 commit into
scasplte2:test/proto-integration-types-tddfrom
ottobot-ai:test/proto-integration-types-tdd
Closed

feat(proto): implement ProtoAdapters — 15/15 integration tests pass#100
ottobot-ai wants to merge 1 commit into
scasplte2:test/proto-integration-types-tddfrom
ottobot-ai:test/proto-integration-types-tdd

Conversation

@ottobot-ai

Copy link
Copy Markdown
Collaborator

Summary

Implements ProtoAdapters.scala — full bidirectional serialization between Scala fiber types and proto binary format for on-chain storage.

Wire format boundary maintained: DL1 JSON API continues using Circe JSON. Proto binary is for on-chain storage only (no breaking change to external APIs).

Changes

ProtoAdapters.scala (new — 400 lines)

  • FiberStatusProtoFiberStatus — bidirectional; returns Left on UNSPECIFIED
  • SnapshotOrdinal / FiberOrdinal / Hash / Address / StateId converters
  • Circe Jsoncom.google.protobuf.struct.Value bridge (complete fold)
  • JsonLogicValue / JsonLogicExpression ↔ proto Value (via Circe round-trip)
  • StateMachineDefinitionProtoStateMachineDefinition (encoded as JSON Struct)
  • AccessControlPolicyProtoAccessControlPolicy (all 3 variants: Public / Whitelist / FiberOwned)
  • EmittedEvent / EventReceipt / OracleInvocation converters
  • StateMachineFiberRecord.toProto + fromProto returning Either[String, T]
  • ScriptFiberRecord.toProto + fromProto returning Either[String, T]

ProtoAdaptersIntegrationTest.scala (fixed)

The spec tests from @code (PR #98) were written with hallucinated import paths and type constructors. Fixed all 15 tests to use correct Scala types:

  • Import paths corrected (xyz.kd5ujc.schema.*)
  • State(id = StateId(...), isFinal = false) constructor
  • StateMachineDefinition.states: Map[StateId, State]
  • Transition with required guard/effect fields
  • StateMachineFiberRecord with previousUpdateOrdinal
  • EventReceipt with all required fields
  • Address construction via refineV[DAGAddressRefined].unsafeFrom()
  • Replaced ScalaTest EitherValues with IO-based getRight/getLeft helpers (weaver-compatible)

Test Results

[info] xyz.kd5ujc.proto.ProtoAdaptersIntegrationTest
[info] + A1: Minimal StateMachineFiberRecord round-trips via proto binary
[info] + A2: Full StateMachineFiberRecord with complex stateData round-trips
[info] + A3: StateMachineDefinition transitions encode losslessly
[info] + A4: FiberStatus enum maps bidirectionally
[info] + B1: Minimal ScriptFiberRecord round-trips via proto binary
[info] + B2: ScriptFiberRecord with Whitelist access control round-trips
[info] + B3: FiberOwned access control maps correctly
[info] + C1: Scala proto binary is decodable via generated ScalaPB companion
[info] + C2: Proto binary is idempotent across two full round-trips
[info] + D1: fromProtoSMRecord returns Left on invalid fiberId UUID
[info] + D2: fromProtoFiberStatus returns Left on FIBER_STATUS_UNSPECIFIED
[info] + D3: fromProtoScriptRecord returns Left on missing scriptProgram
[info] + D4: fromProto does NOT throw exceptions on random byte arrays
[info] + E1: ProtoAdapters handles CreateStateMachine → SMRecord scenario
[info] + E2: FiberRecord binary storage is idempotent across snapshot boundaries
[info] Passed: Total 17, Failed 0, Errors 0, Passed 17

Closes Trello card: Integration Tests: Verify generated types with fiber engine

…ass)

Implements full bidirectional serialization between Scala fiber types and
proto binary format (on-chain storage). Wire format boundary maintained:
DL1 JSON API stays Circe, proto binary for on-chain storage only.

## ProtoAdapters.scala (new)
- FiberStatus ↔ ProtoFiberStatus (bidirectional, Left on UNSPECIFIED)
- SnapshotOrdinal / FiberOrdinal / Hash / Address / StateId converters
- Circe Json ↔ com.google.protobuf.struct.Value bridge (via fold)
- JsonLogicValue / JsonLogicExpression ↔ Protobuf Value (via Circe)
- StateMachineDefinition ↔ ProtoStateMachineDefinition (JSON Struct)
- AccessControlPolicy ↔ ProtoAccessControlPolicy (3 variants)
- EmittedEvent / EventReceipt / OracleInvocation converters
- StateMachineFiberRecord toProto + fromProto (Either[String, T])
- ScriptFiberRecord toProto + fromProto (Either[String, T])

## ProtoAdaptersIntegrationTest.scala (fixed)
- Fixed import paths: xyz.kd5ujc.schema.* (was xyz.kd5ujc.ottochain.*)
- Fixed State constructor: State(id = StateId(...), isFinal = false)
- Fixed StateMachineDefinition.states: Map[StateId, State]
- Fixed Transition: guard/effect are required JsonLogicExpression
- Fixed StateMachineFiberRecord: added previousUpdateOrdinal field
- Fixed ScriptFiberRecord: added creationOrdinal/latestUpdateOrdinal
- Fixed EventReceipt: all required fields (ordinal, fromState, toState, etc.)
- Fixed Address construction: refineV[DAGAddressRefined].unsafeFrom()
- Replaced EitherValues (ScalaTest) with IO-based getRight/getLeft helpers
- All 15 tests now compile and pass

Closes card 699621e4 (Integration Tests: Verify generated types with fiber engine)
@ottobot-ai

Copy link
Copy Markdown
Collaborator Author

Moving to feature branch feat/proto-migration on ottobot-ai/ottochain for agent iteration. Will submit rollup PR to upstream when ready.

@ottobot-ai ottobot-ai closed this Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant