| 1 | package checkpoint |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "os" |
| 6 | "testing" |
| 7 | |
| 8 | "reasonix/internal/provider" |
| 9 | ) |
| 10 | |
| 11 | func TestRecoveryIdentityPersistsOnlyFirstWriter(t *testing.T) { |
| 12 | dir := t.TempDir() |
| 13 | s := New(dir, dir) |
| 14 | s.Begin(1, "write", 1) |
| 15 | first := RecoveryIdentity{Action: provider.ActionIdentity{TurnID: "turn", CallID: "first", AttemptID: "attempt", ArgumentDigest: "args"}, TranscriptDigest: "transcript"} |
| 16 | if err := s.BindRecoveryIdentity(first); err != nil { |
| 17 | t.Fatal(err) |
| 18 | } |
| 19 | second := first |
| 20 | second.Action.CallID = "second" |
| 21 | if err := s.BindRecoveryIdentity(second); err != nil { |
| 22 | t.Fatal(err) |
| 23 | } |
| 24 | raw, err := os.ReadFile(s.v3MetaPath(1)) |
| 25 | if err != nil { |
| 26 | t.Fatal(err) |
| 27 | } |
| 28 | var persisted Checkpoint |
| 29 | if err := json.Unmarshal(raw, &persisted); err != nil { |
| 30 | t.Fatal(err) |
| 31 | } |
| 32 | if persisted.Recovery == nil || *persisted.Recovery != first { |
| 33 | t.Fatalf("checkpoint identity=%+v", persisted.Recovery) |
| 34 | } |
| 35 | } |
| 36 |