|
1 | 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | +import { NodeId, ProviderDriverKind, RunId, ThreadId } from "@t3tools/contracts"; |
2 | 3 |
|
3 | | -import { resolveSubagentRowPresentation, workflowGroupSummary } from "./threadAgentsPresentation"; |
| 4 | +import { |
| 5 | + resolveSubagentRowPresentation, |
| 6 | + resolveSubagentStopTarget, |
| 7 | + workflowGroupSummary, |
| 8 | +} from "./threadAgentsPresentation"; |
4 | 9 |
|
5 | 10 | const base = { |
6 | 11 | title: null, |
@@ -93,3 +98,92 @@ describe("workflowGroupSummary", () => { |
93 | 98 | ); |
94 | 99 | }); |
95 | 100 | }); |
| 101 | + |
| 102 | +const stopAgent = { |
| 103 | + id: NodeId.make("agent"), |
| 104 | + threadId: ThreadId.make("parent"), |
| 105 | + childThreadId: ThreadId.make("child"), |
| 106 | + status: "running" as const, |
| 107 | + origin: "app_owned" as const, |
| 108 | + driver: ProviderDriverKind.make("codex"), |
| 109 | + runId: RunId.make("run"), |
| 110 | + nativeTaskRef: null, |
| 111 | +}; |
| 112 | + |
| 113 | +describe("resolveSubagentStopTarget", () => { |
| 114 | + it.each(["pending", "running", "waiting"] as const)( |
| 115 | + "interrupts only the child of an app-owned %s agent", |
| 116 | + (status) => { |
| 117 | + expect(resolveSubagentStopTarget({ ...stopAgent, status })).toEqual({ |
| 118 | + kind: "subagent", |
| 119 | + input: { threadId: stopAgent.childThreadId }, |
| 120 | + }); |
| 121 | + expect(resolveSubagentStopTarget({ ...stopAgent, status, childThreadId: null })).toBeNull(); |
| 122 | + }, |
| 123 | + ); |
| 124 | + |
| 125 | + it.each(["idle", "completed", "failed", "cancelled", "interrupted"] as const)( |
| 126 | + "offers no Stop for a %s agent", |
| 127 | + (status) => { |
| 128 | + expect(resolveSubagentStopTarget({ ...stopAgent, status })).toBeNull(); |
| 129 | + }, |
| 130 | + ); |
| 131 | + |
| 132 | + const native = { |
| 133 | + ...stopAgent, |
| 134 | + origin: "provider_native" as const, |
| 135 | + driver: ProviderDriverKind.make("claudeAgent"), |
| 136 | + childThreadId: null, |
| 137 | + nativeTaskRef: { |
| 138 | + driver: ProviderDriverKind.make("claudeAgent"), |
| 139 | + strength: "strong" as const, |
| 140 | + nativeId: "native-task", |
| 141 | + }, |
| 142 | + }; |
| 143 | + |
| 144 | + it("targets a supported native task without interrupting its parent run", () => { |
| 145 | + expect(resolveSubagentStopTarget(native)).toEqual({ |
| 146 | + kind: "subagent", |
| 147 | + input: { threadId: native.threadId, subagentId: native.id }, |
| 148 | + }); |
| 149 | + }); |
| 150 | + |
| 151 | + it("hides native Stop when the task cannot be identified or stopped", () => { |
| 152 | + expect(resolveSubagentStopTarget({ ...native, nativeTaskRef: null })).toBeNull(); |
| 153 | + expect( |
| 154 | + resolveSubagentStopTarget({ |
| 155 | + ...native, |
| 156 | + nativeTaskRef: { ...native.nativeTaskRef, strength: "weak" }, |
| 157 | + }), |
| 158 | + ).toBeNull(); |
| 159 | + expect( |
| 160 | + resolveSubagentStopTarget({ |
| 161 | + ...native, |
| 162 | + nativeTaskRef: { ...native.nativeTaskRef, nativeId: null }, |
| 163 | + }), |
| 164 | + ).toBeNull(); |
| 165 | + expect(resolveSubagentStopTarget({ ...native, runId: null })).toBeNull(); |
| 166 | + expect(resolveSubagentStopTarget({ ...native, status: "completed" })).toBeNull(); |
| 167 | + expect( |
| 168 | + resolveSubagentStopTarget({ ...native, driver: ProviderDriverKind.make("codex") }), |
| 169 | + ).toBeNull(); |
| 170 | + }); |
| 171 | + |
| 172 | + it("stops the whole workflow through its own command", () => { |
| 173 | + const workflow = { name: "Review", phases: [], agents: [] }; |
| 174 | + expect(resolveSubagentStopTarget({ ...native, workflow })).toEqual({ |
| 175 | + kind: "workflow", |
| 176 | + input: { threadId: native.threadId, subagentId: native.id }, |
| 177 | + }); |
| 178 | + expect(resolveSubagentStopTarget({ ...native, workflow, status: "waiting" })).toBeNull(); |
| 179 | + expect(resolveSubagentStopTarget({ ...stopAgent, workflow })).toBeNull(); |
| 180 | + expect(resolveSubagentStopTarget({ ...native, workflow, nativeTaskRef: null })).toBeNull(); |
| 181 | + expect( |
| 182 | + resolveSubagentStopTarget({ |
| 183 | + ...native, |
| 184 | + workflow, |
| 185 | + nativeTaskRef: { ...native.nativeTaskRef, nativeId: "" }, |
| 186 | + }), |
| 187 | + ).toBeNull(); |
| 188 | + }); |
| 189 | +}); |
0 commit comments