| 1 | package agent |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "errors" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | |
| 9 | "reasonix/internal/provider" |
| 10 | "reasonix/internal/tool" |
| 11 | ) |
| 12 | |
| 13 | func TestTaskSetupFailurePreservesAllocatedSubagentOutcome(t *testing.T) { |
| 14 | workspace := t.TempDir() |
| 15 | store := NewSubagentStore(t.TempDir()) |
| 16 | task := NewTaskTool(nil, nil, tool.NewRegistry(), 20, 0, 0, 0, 0, 0, 0, 0, "", "sys", nil, 0, "", "", nil). |
| 17 | WithTranscripts(store, workspace, "model", "effort") |
| 18 | task.resolveProvider = func(string, string) (provider.Provider, *provider.Pricing, int, error) { |
| 19 | return nil, nil, 0, errors.New("profile unavailable") |
| 20 | } |
| 21 | out, err := task.Execute(WithParentSession(context.Background(), "parent"), []byte(`{"prompt":"inspect","model":"child-model"}`)) |
| 22 | if err == nil || !strings.Contains(err.Error(), "profile unavailable") { |
| 23 | t.Fatalf("Execute error = %v, want setup failure", err) |
| 24 | } |
| 25 | outcome, ok := ParseSubagentOutcome(out) |
| 26 | if !ok || outcome.Ref == "" || outcome.Status != SubagentOutcomeFailed { |
| 27 | t.Fatalf("outcome = %+v, output=%q, want failed ref", outcome, out) |
| 28 | } |
| 29 | meta, metaErr := store.LoadMeta(outcome.Ref) |
| 30 | if metaErr != nil || meta.Status != SubagentFailed || meta.ErrorCode != "subagent_error" { |
| 31 | t.Fatalf("metadata = %+v/%v, want retained failed outcome", meta, metaErr) |
| 32 | } |
| 33 | } |
| 34 |