| 1 | package control |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "errors" |
| 6 | "os" |
| 7 | "testing" |
| 8 | |
| 9 | "reasonix/internal/agent" |
| 10 | "reasonix/internal/event" |
| 11 | "reasonix/internal/session" |
| 12 | "reasonix/internal/tool" |
| 13 | ) |
| 14 | |
| 15 | func TestGoalCommandDoesNotStartProviderAfterPersistenceFailure(t *testing.T) { |
| 16 | store, err := session.CreateWithOptions(t.TempDir()+"/goal-command-failure", "goal-command-failure", session.OpenOptions{ |
| 17 | Sync: func(*os.File) error { return errors.New("injected sync failure") }, |
| 18 | }) |
| 19 | if err != nil { |
| 20 | t.Fatal(err) |
| 21 | } |
| 22 | service, err := session.NewService("desktop", failingFlushPersistence{session: store}) |
| 23 | if err != nil { |
| 24 | t.Fatal(err) |
| 25 | } |
| 26 | t.Cleanup(func() { _ = service.CloseAll(context.Background()) }) |
| 27 | runtime, err := service.Create(t.Context(), session.CreateOptions{SessionID: "goal-command-failure"}) |
| 28 | if err != nil { |
| 29 | t.Fatal(err) |
| 30 | } |
| 31 | if _, err := runtime.Session().AppendBatch(t.Context(), "seed", []session.Event{{Kind: "tool/result", Payload: []byte(`{"id":"seed-call","name":"bash","output":"seed"}`)}}); err != nil { |
| 32 | t.Fatal(err) |
| 33 | } |
| 34 | if _, err := runtime.Session().Flush(t.Context()); err == nil { |
| 35 | t.Fatal("seed Flush unexpectedly succeeded") |
| 36 | } |
| 37 | runner := &modelErrorGoalRunner{} |
| 38 | exec := agent.New(nil, tool.NewRegistry(), agent.NewSession("system"), agent.Options{}, event.Discard) |
| 39 | c := newOwnedTestController(t, Options{Runner: runner, Executor: exec, Sink: event.Discard, SessionService: service, SessionRuntime: runtime, ExclusiveSession: true}) |
| 40 | t.Cleanup(c.ReleaseResources) |
| 41 | |
| 42 | c.Submit("/goal ship the durable fix") |
| 43 | if runner.calls != 0 { |
| 44 | t.Fatalf("provider calls = %d, want zero", runner.calls) |
| 45 | } |
| 46 | if snapshot := runtime.Session().Snapshot(); snapshot.PersistenceStatus != session.PersistenceUncertain { |
| 47 | t.Fatalf("persistence status = %q, want uncertain", snapshot.PersistenceStatus) |
| 48 | } |
| 49 | } |
| 50 |