|
7 | 7 | snapshotComposerSend, |
8 | 8 | withMessageContext, |
9 | 9 | deriveAvailableRevertTurnCounts, |
| 10 | + deriveThreadPendingBackgroundTasks, |
10 | 11 | } from "./ChatView.logic"; |
11 | 12 | import { recallCheckoutIsRepo, rememberCheckoutIsRepo } from "./ChatView.logic"; |
12 | 13 | import { ProviderDriverKind, type ServerProvider } from "@t3tools/contracts"; |
@@ -1224,6 +1225,113 @@ describe("deriveAvailableRevertTurnCounts", () => { |
1224 | 1225 | }); |
1225 | 1226 | }); |
1226 | 1227 |
|
| 1228 | +describe("deriveThreadPendingBackgroundTasks", () => { |
| 1229 | + const base = makeThreadProjectionFixture(); |
| 1230 | + const run = (ordinal: number, status: string) => ({ |
| 1231 | + id: RunId.make(`run-${ordinal}`), |
| 1232 | + ordinal, |
| 1233 | + status, |
| 1234 | + }); |
| 1235 | + const item = (ordinal: number, type: string, nativeId: string, input: string) => ({ |
| 1236 | + id: TurnItemId.make(`item-${nativeId}`), |
| 1237 | + type, |
| 1238 | + status: "running", |
| 1239 | + title: null, |
| 1240 | + runId: RunId.make(`run-${ordinal}`), |
| 1241 | + nativeItemRef: { nativeId }, |
| 1242 | + input, |
| 1243 | + }); |
| 1244 | + const projection = (overrides: object) => |
| 1245 | + ({ ...base, ...overrides }) as unknown as ReturnType<typeof makeThreadProjectionFixture>; |
| 1246 | + |
| 1247 | + it.each(["queued", "preparing", "running"])( |
| 1248 | + "keeps an earlier run's background shell while a %s follow-up run has a foreground command", |
| 1249 | + (followUpStatus) => { |
| 1250 | + expect( |
| 1251 | + deriveThreadPendingBackgroundTasks( |
| 1252 | + projection({ |
| 1253 | + runs: [run(1, "completed"), run(2, followUpStatus)], |
| 1254 | + turnItems: [ |
| 1255 | + item(1, "command_execution", "shell-1", "sleep 600"), |
| 1256 | + item(2, "command_execution", "shell-2", "sleep 15"), |
| 1257 | + ], |
| 1258 | + }), |
| 1259 | + ), |
| 1260 | + ).toEqual([{ taskId: "shell-1", description: "sleep 600", kind: "command" }]); |
| 1261 | + }, |
| 1262 | + ); |
| 1263 | + |
| 1264 | + it("does not list a live run's child from the provider roster as background", () => { |
| 1265 | + // The roster is not run-tied; Muse keys it by the child session id its rows carry. |
| 1266 | + expect( |
| 1267 | + deriveThreadPendingBackgroundTasks( |
| 1268 | + projection({ |
| 1269 | + runs: [run(1, "completed"), run(2, "running")], |
| 1270 | + providerThreads: [ |
| 1271 | + { |
| 1272 | + id: "provider-thread-1", |
| 1273 | + providerInstanceId: base.thread.providerInstanceId, |
| 1274 | + pendingBackgroundTasks: [ |
| 1275 | + { taskId: "child-session-1", kind: "subagent" }, |
| 1276 | + { taskId: "child-session-2", kind: "subagent" }, |
| 1277 | + ], |
| 1278 | + }, |
| 1279 | + ], |
| 1280 | + turnItems: [ |
| 1281 | + { ...item(1, "subagent", "child-session-1", ""), prompt: "child 1" }, |
| 1282 | + { ...item(2, "subagent", "child-session-2", ""), prompt: "child 2" }, |
| 1283 | + ], |
| 1284 | + }), |
| 1285 | + ), |
| 1286 | + ).toEqual([ |
| 1287 | + { |
| 1288 | + taskId: "child-session-1", |
| 1289 | + kind: "subagent", |
| 1290 | + providerInstanceId: base.thread.providerInstanceId, |
| 1291 | + }, |
| 1292 | + ]); |
| 1293 | + }); |
| 1294 | + |
| 1295 | + it("keeps an earlier run's roster-only monitor while a follow-up run executes", () => { |
| 1296 | + // Claude completes the Monitor launch row on success; only the roster tracks the task. |
| 1297 | + expect( |
| 1298 | + deriveThreadPendingBackgroundTasks( |
| 1299 | + projection({ |
| 1300 | + runs: [run(1, "completed"), run(2, "running")], |
| 1301 | + providerThreads: [ |
| 1302 | + { |
| 1303 | + id: "provider-thread-1", |
| 1304 | + providerInstanceId: base.thread.providerInstanceId, |
| 1305 | + pendingBackgroundTasks: [{ taskId: "b1htjkjev", kind: "monitor" }], |
| 1306 | + }, |
| 1307 | + ], |
| 1308 | + turnItems: [ |
| 1309 | + { ...item(1, "dynamic_tool", "toolu-monitor", ""), status: "completed" }, |
| 1310 | + item(2, "command_execution", "shell-2", "sleep 15"), |
| 1311 | + ], |
| 1312 | + }), |
| 1313 | + ), |
| 1314 | + ).toEqual([{ taskId: "b1htjkjev", kind: "monitor" }]); |
| 1315 | + }); |
| 1316 | + |
| 1317 | + it("keeps the provider roster while a follow-up run only waits in the queue", () => { |
| 1318 | + expect( |
| 1319 | + deriveThreadPendingBackgroundTasks( |
| 1320 | + projection({ |
| 1321 | + runs: [run(1, "waiting"), run(2, "queued")], |
| 1322 | + providerThreads: [ |
| 1323 | + { |
| 1324 | + id: "provider-thread-1", |
| 1325 | + providerInstanceId: base.thread.providerInstanceId, |
| 1326 | + pendingBackgroundTasks: [{ taskId: "task-1", kind: "background_task" }], |
| 1327 | + }, |
| 1328 | + ], |
| 1329 | + }), |
| 1330 | + ), |
| 1331 | + ).toEqual([{ taskId: "task-1", kind: "background_task" }]); |
| 1332 | + }); |
| 1333 | +}); |
| 1334 | + |
1227 | 1335 | describe("Open in for the host environment", () => { |
1228 | 1336 | it("shows both local environments when the primary has a separate WSL home", () => { |
1229 | 1337 | const primaryEnvironmentId = EnvironmentId.make("wsl"); |
|
0 commit comments