| 1 | package eventwire |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "reasonix/internal/checkpoint" |
| 6 | "reasonix/internal/event" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | func TestTurnResultWireRoundTrip(t *testing.T) { |
| 11 | turn, exitCode := 0, 1 |
| 12 | in := event.Event{Kind: event.TurnDone, CheckpointTurn: &turn, Receipt: &event.CompletionReceipt{ |
| 13 | Verdict: "partial", Diff: &checkpoint.TurnChanges{ID: "result-1", Turn: 0, Coverage: "partial", Files: []checkpoint.TurnFile{}, Reasons: []string{"active_writer"}}, |
| 14 | Verifications: []event.ReceiptVerification{{Command: "go test ./...", ToolCallID: "call-1", ToolResultID: "entry-1", ExitCode: &exitCode, Interrupted: true}}, |
| 15 | }} |
| 16 | b, err := json.Marshal(ToWire(in)) |
| 17 | if err != nil { |
| 18 | t.Fatal(err) |
| 19 | } |
| 20 | var decoded Event |
| 21 | if err := json.Unmarshal(b, &decoded); err != nil { |
| 22 | t.Fatal(err) |
| 23 | } |
| 24 | receipt := CompletionReceiptEvent(decoded.Receipt) |
| 25 | if receipt.Verifications[0].ToolResultID != "entry-1" { |
| 26 | t.Fatal("stable log source lost") |
| 27 | } |
| 28 | if decoded.CheckpointTurn == nil || *decoded.CheckpointTurn != 0 || receipt.Diff.ID != "result-1" || !receipt.Verifications[0].Interrupted || receipt.Verifications[0].ToolCallID != "call-1" || *receipt.Verifications[0].ExitCode != 1 { |
| 29 | t.Fatalf("roundtrip: %s", b) |
| 30 | } |
| 31 | var old struct { |
| 32 | Kind string `json:"kind"` |
| 33 | Receipt struct { |
| 34 | Verdict string `json:"verdict"` |
| 35 | } `json:"receipt"` |
| 36 | } |
| 37 | if err := json.Unmarshal(b, &old); err != nil || old.Kind != "turn_done" || old.Receipt.Verdict != "partial" { |
| 38 | t.Fatalf("old reader: %+v %v", old, err) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | func TestVerificationProgressIsHostMetadata(t *testing.T) { |
| 43 | wire := ToWire(event.Event{Kind: event.ToolProgress, Tool: event.Tool{ID: "check", Verifying: true}}) |
| 44 | if wire.Tool == nil || !wire.Tool.Verifying || wire.Tool.Output != "" { |
| 45 | t.Fatalf("progress: %+v", wire) |
| 46 | } |
| 47 | } |
| 48 |