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:
@@ -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)
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user