| 1 | package provider |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestToolCallRecordPersistsStableIdentityAndRecoveryStates(t *testing.T) { |
| 9 | record := ToolCallRecord{ |
| 10 | Identity: ActionIdentity{SessionID: "s", TurnID: "t", AttemptID: "a", CallID: "c", CanonicalTool: "write_file", ArgumentDigest: "sha", ResourceScope: "workspace:/tmp/x"}, |
| 11 | State: ToolRunStarted, ReadOnly: false, IdempotencyKey: "idem", StartedAt: 10, |
| 12 | } |
| 13 | raw, err := json.Marshal(record) |
| 14 | if err != nil { |
| 15 | t.Fatal(err) |
| 16 | } |
| 17 | var got ToolCallRecord |
| 18 | if err := json.Unmarshal(raw, &got); err != nil { |
| 19 | t.Fatal(err) |
| 20 | } |
| 21 | if got.Identity != record.Identity || got.State != ToolRunStarted || got.IdempotencyKey != "idem" { |
| 22 | t.Fatalf("record round trip = %+v", got) |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | func TestToolResultRunStatePreservesDurableTerminalStates(t *testing.T) { |
| 27 | for _, state := range []ToolRunState{ToolRunPending, ToolRunStarted, ToolRunRunning, ToolRunFailed, ToolRunCancelled} { |
| 28 | if got := ToolResultRunState(Message{ToolRunState: state}); got != state { |
| 29 | t.Fatalf("state %q classified as %q", state, got) |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 |