INNER CODE UNIT · Go
TestContract_ErrorAndAbortedStopSkipStopGuard
voocel/ainovel-cli · internal/agents/agentcore_contract_test.go:149
func TestContract_ErrorAndAbortedStopSkipStopGuard(t *testing.T) {
for _, stop := range []agentcore.StopReason{agentcore.StopReasonError, agentcore.StopReasonAborted} {
t.Run(string(stop), func(t *testing.T) {
var guardCalls atomic.Int32
model := &contractModel{fn: func(int, []agentcore.Message) (*agentcore.LLMResponse, error) {
return &agentcore.LLMResponse{Message: assistantText("dead", stop)}, nil
}}
_ = runSubagent(t, subagent.Config{
Name: "dying", Description: "contract", Model: model,
SystemPrompt: "test", MaxTurns: 5,
StopGuardFactory: func(_, _ string) agentcore.StopGuard {
return func(context.Context, agentcore.StopInfo) agentcore.StopDecision {
guardCalls.Add(1)
return agentcore.StopDecision{Allow: true}
}
},
}) // error/aborted 停机的 error 语义由 subagent 层定义,这里只关心 guard 是否被触达
if guardCalls.Load() != 0 {