The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import type { |
| 2 | OrchestrationV2ThreadProjection, |
| 3 | OrchestrationV2ThreadShell, |
| 4 | } from "@t3tools/contracts"; |
| 5 | import { describe, expect, it } from "vite-plus/test"; |
| 6 | |
| 7 | import { selectThreadRelationshipShells } from "./entities"; |
| 8 | |
| 9 | type Projection = Parameters<typeof selectThreadRelationshipShells>[1]; |
| 10 | |
| 11 | const shell = (id: string, parentThreadId: string | null = null) => |
| 12 | ({ |
| 13 | id, |
| 14 | forkedFrom: null, |
| 15 | lineage: { parentThreadId, relationshipToParent: parentThreadId === null ? null : "fork" }, |
| 16 | }) as unknown as OrchestrationV2ThreadShell; |
| 17 | |
| 18 | const threadId = "current" as OrchestrationV2ThreadShell["id"]; |
| 19 | |
| 20 | describe("selectThreadRelationshipShells", () => { |
| 21 | it("keeps the thread, its parent, its children and the threads its projection names", () => { |
| 22 | const threads = [ |
| 23 | shell("current", "parent"), |
| 24 | shell("parent"), |
| 25 | shell("child", "current"), |
| 26 | shell("subagent-child"), |
| 27 | shell("workflow-member"), |
| 28 | shell("transfer-source"), |
| 29 | shell("unrelated"), |
| 30 | shell("grandchild", "child"), |
| 31 | ]; |
| 32 | const projection = { |
| 33 | thread: threads[0], |
| 34 | subagents: [ |
| 35 | { |
| 36 | childThreadId: "subagent-child", |
| 37 | workflow: { agents: [{ childThreadId: "workflow-member" }, {}] }, |
| 38 | }, |
| 39 | { childThreadId: null }, |
| 40 | ], |
| 41 | contextTransfers: [{ sourceThreadId: "transfer-source", targetThreadId: "current" }], |
| 42 | } as unknown as Pick< |
| 43 | OrchestrationV2ThreadProjection, |
| 44 | "thread" | "subagents" | "contextTransfers" |
| 45 | >; |
| 46 | |
| 47 | expect( |
| 48 | selectThreadRelationshipShells(threadId, projection, threads).map((thread) => thread.id), |
| 49 | ).toEqual([ |
| 50 | "current", |
| 51 | "parent", |
| 52 | "child", |
| 53 | "subagent-child", |
| 54 | "workflow-member", |
| 55 | "transfer-source", |
| 56 | ]); |
| 57 | }); |
| 58 | |
| 59 | it("finds the parent from the shell before the projection loads", () => { |
| 60 | const threads = [shell("current", "parent"), shell("parent"), shell("unrelated")]; |
| 61 | expect( |
| 62 | selectThreadRelationshipShells(threadId, null as Projection, threads).map( |
| 63 | (thread) => thread.id, |
| 64 | ), |
| 65 | ).toEqual(["current", "parent"]); |
| 66 | }); |
| 67 | }); |