|
1 | 1 | import { expect, it } from "@effect/vitest"; |
2 | 2 | import { |
3 | 3 | CommandId, |
| 4 | + NodeId, |
4 | 5 | type OrchestrationV2Command, |
| 6 | + type OrchestrationV2ThreadShell, |
5 | 7 | ProjectId, |
6 | 8 | ProviderInstanceId, |
7 | 9 | RunId, |
8 | 10 | ThreadId, |
9 | 11 | } from "@t3tools/contracts"; |
10 | 12 |
|
11 | | -import { withCreationProvenance } from "./ThreadManagementService.ts"; |
| 13 | +import { userFacingShellSnapshot, withCreationProvenance } from "./ThreadManagementService.ts"; |
12 | 14 |
|
13 | 15 | it("stamps authoritative provenance on commands that create threads or messages", () => { |
14 | 16 | const command: OrchestrationV2Command = { |
@@ -55,3 +57,59 @@ it("leaves commands that do not create durable authored content unchanged", () = |
55 | 57 | }), |
56 | 58 | ).toBe(command); |
57 | 59 | }); |
| 60 | + |
| 61 | +it("removes internal subagent children from active and archived shell collections", () => { |
| 62 | + const rootId = ThreadId.make("thread:thread-management:root"); |
| 63 | + const forkId = ThreadId.make("thread:thread-management:fork"); |
| 64 | + const lineageSubagentId = ThreadId.make("thread:thread-management:lineage-subagent"); |
| 65 | + const nodeSubagentId = ThreadId.make("thread:thread-management:node-subagent"); |
| 66 | + const shell = ( |
| 67 | + id: ThreadId, |
| 68 | + lineage: OrchestrationV2ThreadShell["lineage"], |
| 69 | + forkedFrom: OrchestrationV2ThreadShell["forkedFrom"], |
| 70 | + ) => |
| 71 | + ({ |
| 72 | + id, |
| 73 | + lineage, |
| 74 | + forkedFrom, |
| 75 | + }) as OrchestrationV2ThreadShell; |
| 76 | + const rootLineage = { |
| 77 | + rootThreadId: rootId, |
| 78 | + parentThreadId: null, |
| 79 | + relationshipToParent: null, |
| 80 | + } as const; |
| 81 | + const snapshot = userFacingShellSnapshot({ |
| 82 | + schemaVersion: 3, |
| 83 | + snapshotSequence: 10, |
| 84 | + threads: [ |
| 85 | + shell(rootId, rootLineage, null), |
| 86 | + shell( |
| 87 | + forkId, |
| 88 | + { |
| 89 | + rootThreadId: rootId, |
| 90 | + parentThreadId: rootId, |
| 91 | + relationshipToParent: "fork", |
| 92 | + }, |
| 93 | + { type: "run", threadId: rootId, runId: RunId.make("run:thread-management:fork") }, |
| 94 | + ), |
| 95 | + shell( |
| 96 | + lineageSubagentId, |
| 97 | + { |
| 98 | + rootThreadId: rootId, |
| 99 | + parentThreadId: rootId, |
| 100 | + relationshipToParent: "subagent", |
| 101 | + }, |
| 102 | + null, |
| 103 | + ), |
| 104 | + ], |
| 105 | + archivedThreads: [ |
| 106 | + shell(nodeSubagentId, rootLineage, { |
| 107 | + type: "node", |
| 108 | + nodeId: NodeId.make("node:thread-management:subagent"), |
| 109 | + }), |
| 110 | + ], |
| 111 | + }); |
| 112 | + |
| 113 | + expect(snapshot.threads.map((thread) => thread.id)).toEqual([rootId, forkId]); |
| 114 | + expect(snapshot.archivedThreads).toEqual([]); |
| 115 | +}); |
0 commit comments