Skip to content
Source
Sign inSign up
Open History to see the last commit

entities.relationshipShells.test.ts

67 lines2.1 KB

1import type {
2 OrchestrationV2ThreadProjection,
3 OrchestrationV2ThreadShell,
4} from "@t3tools/contracts";
5import { describe, expect, it } from "vite-plus/test";
6​
7import { selectThreadRelationshipShells } from "./entities";
8​
9type Projection = Parameters<typeof selectThreadRelationshipShells>[1];
10​
11const 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​
18const threadId = "current" as OrchestrationV2ThreadShell["id"];
19​
20describe("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});