Update agent tests for the ctx-cancel suspend contract

Rewrite the WithStopSignal-driven test in restore_test.go to use a
cancellable ctx. Update agent_test.go's "context cancellation"
case from asserting "cannot complete" failure to asserting a
SuspendedError. Add cancel_test.go covering both pre-first-turn
cancel (no LLM call, empty checkpoint persisted) and mid-run
cancel from inside a tool (just-completed turn preserved in the
checkpoint, second LLM call suppressed).

Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
This commit is contained in:
Aurélien Sibiril
2026-04-27 09:52:02 +02:00
parent 53747733b3
commit 1b62d39a2e
3 changed files with 145 additions and 6 deletions

View File

@@ -479,7 +479,7 @@ func TestRun(t *testing.T) {
)
t.Run(
"context cancellation",
"context cancellation triggers graceful suspend",
func(t *testing.T) {
t.Parallel()
@@ -500,8 +500,10 @@ func TestRun(t *testing.T) {
_, err := ag.Run(ctx, []llm.Message{userMessage("test")})
require.Error(t, err)
assert.Contains(t, err.Error(), "cannot complete")
var se *agent.SuspendedError
require.ErrorAs(t, err, &se)
require.NotNil(t, se.Checkpoint)
assert.Equal(t, agent.AgentStatusSuspended, se.Checkpoint.Status)
assert.Equal(t, 0, provider.calls)
},
)