@leitwerk-dev/test-support 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-7I4OCTF3.js → chunk-2PCDTYVH.js} +7 -2
- package/dist/chunk-2PCDTYVH.js.map +1 -0
- package/dist/{chunk-KPSK7EMY.js → chunk-5BZSJ4OO.js} +22 -157
- package/dist/chunk-5BZSJ4OO.js.map +1 -0
- package/dist/{chunk-2IICIB6D.js → chunk-ECAWLVYB.js} +38 -4
- package/dist/chunk-ECAWLVYB.js.map +1 -0
- package/dist/{chunk-JUH3LUYK.js → chunk-EXHTWQAE.js} +5 -1
- package/dist/chunk-EXHTWQAE.js.map +1 -0
- package/dist/compact-process-detail-fixture.d.ts +3 -0
- package/dist/compact-process-detail-fixture.d.ts.map +1 -1
- package/dist/fakes/fake-git-ops.d.ts +12 -0
- package/dist/fakes/fake-git-ops.d.ts.map +1 -1
- package/dist/fakes/fake-llm.d.ts +11 -0
- package/dist/fakes/fake-llm.d.ts.map +1 -1
- package/dist/fakes/index.d.ts +1 -1
- package/dist/fakes/index.d.ts.map +1 -1
- package/dist/fakes/index.js +105 -4
- package/dist/fakes/index.js.map +1 -1
- package/dist/fixtures.js +104 -2
- package/dist/fixtures.js.map +1 -1
- package/dist/http-launch.d.ts +2 -1
- package/dist/http-launch.d.ts.map +1 -1
- package/dist/index.d.ts +23 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -53
- package/dist/index.js.map +1 -1
- package/dist/integration-harness.d.ts +36 -1
- package/dist/integration-harness.d.ts.map +1 -1
- package/dist/integration.d.ts +2 -3
- package/dist/integration.d.ts.map +1 -1
- package/dist/integration.js +131 -13
- package/dist/integration.js.map +1 -1
- package/dist/local-git.d.ts +105 -8
- package/dist/local-git.d.ts.map +1 -1
- package/dist/local-git.js +155 -24
- package/dist/local-git.js.map +1 -1
- package/dist/model-provider-fixtures.d.ts +9 -1
- package/dist/model-provider-fixtures.d.ts.map +1 -1
- package/dist/polling.d.ts +1 -0
- package/dist/polling.d.ts.map +1 -1
- package/dist/process-driver.d.ts +5 -1
- package/dist/process-driver.d.ts.map +1 -1
- package/dist/question-fixtures.d.ts +2 -0
- package/dist/question-fixtures.d.ts.map +1 -1
- package/dist/server-extension-test-harness.d.ts +43 -3
- package/dist/server-extension-test-harness.d.ts.map +1 -1
- package/dist/stub-worker-entry.js +1 -1
- package/dist/test-diagnostics.d.ts +14 -0
- package/dist/test-diagnostics.d.ts.map +1 -0
- package/dist/worker-testing/in-process-worker-spawn.d.ts +17 -1
- package/dist/worker-testing/in-process-worker-spawn.d.ts.map +1 -1
- package/dist/worker-testing/index.d.ts +6 -7
- package/dist/worker-testing/index.d.ts.map +1 -1
- package/dist/worker-testing/index.js +32 -22
- package/dist/worker-testing/index.js.map +1 -1
- package/dist/worker-testing/schema-driven-stub-pi.d.ts +5 -0
- package/dist/worker-testing/schema-driven-stub-pi.d.ts.map +1 -1
- package/dist/worker-testing/stub-pi-controls.d.ts +4 -0
- package/dist/worker-testing/stub-pi-controls.d.ts.map +1 -1
- package/dist/worker-testing/stub-pi-tree-handle.d.ts +76 -2
- package/dist/worker-testing/stub-pi-tree-handle.d.ts.map +1 -1
- package/dist/worker-testing/worker-runtime-harness.d.ts +37 -2
- package/dist/worker-testing/worker-runtime-harness.d.ts.map +1 -1
- package/dist/worker-testing/worker-start-payload.d.ts +17 -1
- package/dist/worker-testing/worker-start-payload.d.ts.map +1 -1
- package/package.json +9 -8
- package/src/compact-process-detail-fixture.ts +9 -1
- package/src/fakes/fake-git-ops.ts +12 -0
- package/src/fakes/fake-llm.ts +11 -0
- package/src/fakes/index.ts +1 -1
- package/src/http-launch.ts +2 -1
- package/src/index.ts +28 -42
- package/src/integration-harness.ts +100 -9
- package/src/integration.ts +2 -9
- package/src/local-git.ts +195 -45
- package/src/model-provider-fixtures.ts +15 -2
- package/src/polling.ts +1 -0
- package/src/process-driver.ts +7 -1
- package/src/question-fixtures.ts +2 -0
- package/src/server-extension-test-harness.ts +64 -7
- package/src/test-diagnostics.ts +69 -0
- package/src/worker-testing/in-process-worker-spawn.ts +29 -2
- package/src/worker-testing/index.ts +4 -30
- package/src/worker-testing/schema-driven-stub-pi.ts +8 -1
- package/src/worker-testing/stub-pi-controls.ts +4 -0
- package/src/worker-testing/stub-pi-tree-handle.ts +82 -3
- package/src/worker-testing/worker-runtime-harness.ts +57 -6
- package/src/worker-testing/worker-start-payload.ts +17 -1
- package/dist/chunk-2IICIB6D.js.map +0 -1
- package/dist/chunk-3MQO3NCX.js +0 -15
- package/dist/chunk-3MQO3NCX.js.map +0 -1
- package/dist/chunk-7I4OCTF3.js.map +0 -1
- package/dist/chunk-7ZK5QRGP.js +0 -98
- package/dist/chunk-7ZK5QRGP.js.map +0 -1
- package/dist/chunk-JUH3LUYK.js.map +0 -1
- package/dist/chunk-KPSK7EMY.js.map +0 -1
- package/dist/chunk-MV4W6NOO.js +0 -105
- package/dist/chunk-MV4W6NOO.js.map +0 -1
- package/dist/test-app.d.ts +0 -23
- package/dist/test-app.d.ts.map +0 -1
- package/src/test-app.ts +0 -82
|
@@ -17,8 +17,16 @@ type ServerMessageType = ServerToWorkerMessage["type"];
|
|
|
17
17
|
type ServerMessagePayloadByType = {
|
|
18
18
|
[T in ServerMessageType]: Extract<ServerToWorkerMessage, { type: T }>["payload"];
|
|
19
19
|
};
|
|
20
|
+
/** @internal */
|
|
20
21
|
type WorkerMessageType = WorkerToServerMessage["type"];
|
|
21
|
-
|
|
22
|
+
/** @internal */
|
|
23
|
+
type WorkerMessageByType<T extends WorkerMessageType> = Extract<
|
|
24
|
+
WorkerToServerMessage,
|
|
25
|
+
{
|
|
26
|
+
/** @internal */
|
|
27
|
+
type: T;
|
|
28
|
+
}
|
|
29
|
+
>;
|
|
22
30
|
type MessageWaiter = {
|
|
23
31
|
type: WorkerMessageType;
|
|
24
32
|
count: number;
|
|
@@ -31,11 +39,15 @@ type Scheduled = {
|
|
|
31
39
|
handler(): void;
|
|
32
40
|
};
|
|
33
41
|
|
|
42
|
+
/** @internal */
|
|
34
43
|
export interface ManualWorkerRuntimeScheduler extends WorkerRuntimeScheduler {
|
|
44
|
+
/** @internal */
|
|
35
45
|
advanceBy(delayMs: number): Promise<void>;
|
|
46
|
+
/** @internal */
|
|
36
47
|
pendingDelays(): number[];
|
|
37
48
|
}
|
|
38
49
|
|
|
50
|
+
/** @internal */
|
|
39
51
|
export function createManualWorkerRuntimeScheduler(
|
|
40
52
|
initialNow = new Date("2025-01-01T00:00:00.000Z"),
|
|
41
53
|
): ManualWorkerRuntimeScheduler {
|
|
@@ -83,12 +95,15 @@ export function createManualWorkerRuntimeScheduler(
|
|
|
83
95
|
};
|
|
84
96
|
}
|
|
85
97
|
|
|
98
|
+
/** @internal */
|
|
86
99
|
export interface WorkerRuntimeHarnessOptions {
|
|
100
|
+
/** @internal */
|
|
87
101
|
config?: Partial<WorkerRuntimeConfig>;
|
|
88
|
-
/** Optional default used by start() and startLlmTo(). */
|
|
102
|
+
/** Optional default used by start() and startLlmTo(). @internal */
|
|
89
103
|
startPayload?: WorkerStartPayload;
|
|
90
|
-
/** Model the server's durable terminal acknowledgement. Defaults to true. */
|
|
104
|
+
/** Model the server's durable terminal acknowledgement. Defaults to true. @internal */
|
|
91
105
|
autoAcknowledgeTerminals?: boolean;
|
|
106
|
+
/** @internal */
|
|
92
107
|
adapters: Pick<WorkerRuntimeAdapters, "piFactory" | "gitOps"> &
|
|
93
108
|
Partial<
|
|
94
109
|
Pick<
|
|
@@ -103,10 +118,22 @@ export interface WorkerRuntimeHarnessOptions {
|
|
|
103
118
|
>;
|
|
104
119
|
}
|
|
105
120
|
|
|
121
|
+
/** @internal */
|
|
106
122
|
export type WorkerRuntimeObservation =
|
|
107
|
-
| {
|
|
108
|
-
|
|
123
|
+
| {
|
|
124
|
+
/** @internal */
|
|
125
|
+
kind: "ipc";
|
|
126
|
+
/** @internal */
|
|
127
|
+
type: WorkerToServerMessage["type"];
|
|
128
|
+
}
|
|
129
|
+
| {
|
|
130
|
+
/** @internal */
|
|
131
|
+
kind: "extension";
|
|
132
|
+
/** @internal */
|
|
133
|
+
event: string;
|
|
134
|
+
};
|
|
109
135
|
|
|
136
|
+
/** @internal */
|
|
110
137
|
export function createWorkerRuntimeHarness(options: WorkerRuntimeHarnessOptions) {
|
|
111
138
|
let messageHandler: ((message: ServerToWorkerMessage) => void) | undefined;
|
|
112
139
|
let errorHandler: ((error: Error) => void) | undefined;
|
|
@@ -226,26 +253,36 @@ export function createWorkerRuntimeHarness(options: WorkerRuntimeHarnessOptions)
|
|
|
226
253
|
});
|
|
227
254
|
|
|
228
255
|
return {
|
|
256
|
+
/** @internal */
|
|
229
257
|
scheduler,
|
|
258
|
+
/** @internal */
|
|
230
259
|
outgoing,
|
|
260
|
+
/** @internal */
|
|
231
261
|
observations,
|
|
262
|
+
/** @internal */
|
|
232
263
|
exitCodes,
|
|
264
|
+
/** @internal */
|
|
233
265
|
get transportStartCount() {
|
|
234
266
|
return transportStartCount;
|
|
235
267
|
},
|
|
268
|
+
/** @internal */
|
|
236
269
|
get transportStopCount() {
|
|
237
270
|
return transportStopCount;
|
|
238
271
|
},
|
|
272
|
+
/** @internal */
|
|
239
273
|
deliver,
|
|
274
|
+
/** @internal */
|
|
240
275
|
async connect() {
|
|
241
276
|
await runtime.start();
|
|
242
277
|
},
|
|
278
|
+
/** @internal */
|
|
243
279
|
async start(payload = options.startPayload) {
|
|
244
280
|
if (!payload) throw new Error("WorkerRuntimeHarness.start requires a start payload");
|
|
245
281
|
await this.connect();
|
|
246
282
|
deliver("worker.start", payload);
|
|
247
283
|
await this.flush();
|
|
248
284
|
},
|
|
285
|
+
/** @internal */
|
|
249
286
|
async stop(reason: string) {
|
|
250
287
|
const terminal = [...outgoing]
|
|
251
288
|
.reverse()
|
|
@@ -261,7 +298,15 @@ export function createWorkerRuntimeHarness(options: WorkerRuntimeHarnessOptions)
|
|
|
261
298
|
}
|
|
262
299
|
await runtime.stop(reason);
|
|
263
300
|
},
|
|
264
|
-
|
|
301
|
+
/** @internal */
|
|
302
|
+
async acceptStart(
|
|
303
|
+
acceptance: {
|
|
304
|
+
/** @internal */
|
|
305
|
+
startRecordId?: string;
|
|
306
|
+
/** @internal */
|
|
307
|
+
turnRecordId?: string;
|
|
308
|
+
} = {},
|
|
309
|
+
) {
|
|
265
310
|
if (!latestStart) throw new Error("Cannot accept a turn before worker.start");
|
|
266
311
|
deliver("worker.turn_start_accepted", {
|
|
267
312
|
startRecordId: acceptance.startRecordId ?? latestStart.turnStart.id,
|
|
@@ -269,6 +314,7 @@ export function createWorkerRuntimeHarness(options: WorkerRuntimeHarnessOptions)
|
|
|
269
314
|
});
|
|
270
315
|
await this.flush();
|
|
271
316
|
},
|
|
317
|
+
/** @internal */
|
|
272
318
|
async startLlmTo<T extends WorkerMessageType>(
|
|
273
319
|
type: T,
|
|
274
320
|
payload = options.startPayload,
|
|
@@ -282,12 +328,15 @@ export function createWorkerRuntimeHarness(options: WorkerRuntimeHarnessOptions)
|
|
|
282
328
|
await this.acceptStart();
|
|
283
329
|
return this.waitForMessage(type);
|
|
284
330
|
},
|
|
331
|
+
/** @internal */
|
|
285
332
|
reconnect() {
|
|
286
333
|
connectHandler?.();
|
|
287
334
|
},
|
|
335
|
+
/** @internal */
|
|
288
336
|
failTransport(error: Error) {
|
|
289
337
|
errorHandler?.(error);
|
|
290
338
|
},
|
|
339
|
+
/** @internal */
|
|
291
340
|
async waitForMessage<T extends WorkerMessageType>(
|
|
292
341
|
type: T,
|
|
293
342
|
count = 1,
|
|
@@ -302,6 +351,7 @@ export function createWorkerRuntimeHarness(options: WorkerRuntimeHarnessOptions)
|
|
|
302
351
|
}),
|
|
303
352
|
);
|
|
304
353
|
},
|
|
354
|
+
/** @internal */
|
|
305
355
|
async flush() {
|
|
306
356
|
for (let index = 0; index < 100; index++)
|
|
307
357
|
await new Promise<void>((resolve) => setImmediate(resolve));
|
|
@@ -309,4 +359,5 @@ export function createWorkerRuntimeHarness(options: WorkerRuntimeHarnessOptions)
|
|
|
309
359
|
};
|
|
310
360
|
}
|
|
311
361
|
|
|
362
|
+
/** @internal */
|
|
312
363
|
export type WorkerRuntimeHarness = ReturnType<typeof createWorkerRuntimeHarness>;
|
|
@@ -13,26 +13,42 @@ import {
|
|
|
13
13
|
type WorkerStartPayload,
|
|
14
14
|
} from "@leitwerk-dev/worker-protocol";
|
|
15
15
|
|
|
16
|
+
/** @internal */
|
|
16
17
|
type LlmStart = Extract<ResolvedTurnStart, { kind: "llm" }>;
|
|
18
|
+
/** @internal */
|
|
17
19
|
type LlmModel = LlmStart["model"];
|
|
18
20
|
|
|
21
|
+
/** @internal */
|
|
19
22
|
export interface TestLlmWorkerStartPayloadOptions {
|
|
23
|
+
/** @internal */
|
|
20
24
|
root: string;
|
|
25
|
+
/** @internal */
|
|
21
26
|
processSnapshot: ProcessInstanceSnapshot;
|
|
27
|
+
/** @internal */
|
|
22
28
|
projectSnapshots?: ProcessProjectSnapshot[];
|
|
29
|
+
/** @internal */
|
|
23
30
|
turnResultMarkdownBySemanticRef?: WorkerStartPayload["turnResultMarkdownBySemanticRef"];
|
|
31
|
+
/** @internal */
|
|
24
32
|
turnResultMarkdownByProduct?: WorkerStartPayload["turnResultMarkdownByProduct"];
|
|
33
|
+
/** @internal */
|
|
25
34
|
pendingInputs?: InputDelivery[];
|
|
35
|
+
/** @internal */
|
|
26
36
|
workerLeaseId?: string;
|
|
37
|
+
/** @internal */
|
|
27
38
|
startRecordId?: string;
|
|
39
|
+
/** @internal */
|
|
28
40
|
turnRecordId?: string;
|
|
41
|
+
/** @internal */
|
|
29
42
|
model?: LlmModel;
|
|
43
|
+
/** @internal */
|
|
30
44
|
credential?: WorkerCredentialMaterial | null;
|
|
45
|
+
/** @internal */
|
|
31
46
|
resume?: boolean;
|
|
47
|
+
/** @internal */
|
|
32
48
|
now?: string;
|
|
33
49
|
}
|
|
34
50
|
|
|
35
|
-
/** Builds a valid public LLM worker.start payload with canonical Pi resources. */
|
|
51
|
+
/** Builds a valid public LLM worker.start payload with canonical Pi resources. @internal */
|
|
36
52
|
export function createTestLlmWorkerStartPayload(
|
|
37
53
|
options: TestLlmWorkerStartPayloadOptions,
|
|
38
54
|
): WorkerStartPayload {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/worker-testing/stub-pi-tree-handle.ts","../src/worker-testing/schema-driven-stub-pi.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { CURRENT_SESSION_VERSION, type SessionHeader } from \"@earendil-works/pi-coding-agent\";\nimport type {\n\tPiCustomMessageInput,\n\tPiCustomTool,\n\tPiEvent,\n\tPiEventHandler,\n\tPiPromptOptions,\n\tPiRunDetails,\n\tPiSessionDiagnostic,\n\tPiSessionDiagnosticHandler,\n\tPiTreeEntry,\n\tPiTreeHandle,\n\tPiTreeNode,\n\tPiTurnExecutionResult,\n} from \"@leitwerk-dev/process-sdk\";\nimport { isEnoent } from \"@leitwerk-dev/process-sdk\";\nimport type {\n\tPiManagedBootstrapOptions,\n\tPiManagedBootstrapResult,\n\tPiTreeHandleFactory,\n\tPiTreeHandleOptions,\n\tPiTreePlanningOptions,\n\tPiTreePlanningSnapshot,\n} from \"@leitwerk-dev/worker\";\n\nexport interface StubToolCallScriptCall {\n\ttoolName: string;\n\targs: Record<string, unknown>;\n\tintermediateEntryCount?: number;\n}\n\nexport type StubToolCallScriptItem =\n\t| StubToolCallScriptCall\n\t| {\n\t\t\tcalls: readonly StubToolCallScriptCall[];\n\t\t\ttextChunks?: readonly string[];\n\t\t\tthinkingChunks?: readonly string[];\n\t\t\tchunkDelayMs?: number;\n\t\t\t/** Optional scripted model reaction to a tool result, within the same turn. */\n\t\t\tafterToolResult?: (\n\t\t\t\tcall: StubToolCallScriptCall,\n\t\t\t\tresult: unknown,\n\t\t\t) => StubToolCallScriptCall | undefined;\n\t };\n\nexport interface StubToolCallScriptResolverContext {\n\tpromptText: string;\n\ttools: readonly PiCustomTool[];\n\tinstanceId?: string;\n\tworkspaceRoot?: string;\n\tsessionCwd?: string;\n\ttreeFile: string;\n\tturnSequence: number;\n}\n\nexport type StubToolCallScriptResolver = (\n\tcontext: StubToolCallScriptResolverContext,\n) => StubToolCallScriptItem | undefined | Promise<StubToolCallScriptItem | undefined>;\n\nfunction stringifyToolResult(result: unknown): string {\n\tif (typeof result === \"string\") {\n\t\treturn result;\n\t}\n\tif (result === undefined) {\n\t\treturn \"ok\";\n\t}\n\ttry {\n\t\treturn JSON.stringify(result, null, 2);\n\t} catch {\n\t\treturn String(result);\n\t}\n}\n\nfunction expandStubToolCallScriptItem(item: StubToolCallScriptItem): StubToolCallScriptCall[] {\n\tif (\"calls\" in item) {\n\t\treturn [...item.calls];\n\t}\n\treturn [item];\n}\n\nfunction stubToolCallId(turnSeq: number, totalCalls: number, index: number): string {\n\tif (totalCalls <= 1) {\n\t\treturn `tool-${turnSeq}`;\n\t}\n\treturn `tool-${turnSeq}-${index + 1}`;\n}\n\ninterface StubPiTreeState {\n\theader?: SessionHeader;\n\tturnSeq: number;\n\tcurrentLeafId: string | null;\n\tentries: Map<string, PiTreeEntry>;\n\tchildIdsByParent: Map<string | null, string[]>;\n}\n\ninterface PersistedStubPiTreeState {\n\tturnSeq: number;\n\tcurrentLeafId: string | null;\n\tentries: PiTreeEntry[];\n\tchildIdsByParent: Array<{ parentId: string | null; childIds: string[] }>;\n}\n\nfunction createEmptyStubPiTreeState(): StubPiTreeState {\n\treturn {\n\t\tturnSeq: 0,\n\t\tcurrentLeafId: null,\n\t\tentries: new Map<string, PiTreeEntry>(),\n\t\tchildIdsByParent: new Map<string | null, string[]>(),\n\t};\n}\n\nfunction indexStubEntry(state: StubPiTreeState, entry: PiTreeEntry): void {\n\tstate.entries.set(entry.id, entry);\n\tconst siblings = state.childIdsByParent.get(entry.parentId) ?? [];\n\tsiblings.push(entry.id);\n\tstate.childIdsByParent.set(entry.parentId, siblings);\n}\n\nfunction deriveStubLeafIdFromEntries(state: StubPiTreeState): string | null {\n\tlet leafId: string | null = null;\n\tfor (const entryId of state.entries.keys()) {\n\t\tleafId = entryId;\n\t}\n\treturn leafId;\n}\n\nfunction serializeStubPiTreeState(state: StubPiTreeState, recordSessionTrace: boolean): string {\n\tif (recordSessionTrace) {\n\t\treturn `${[\n\t\t\tJSON.stringify({\n\t\t\t\t...state.header,\n\t\t\t\tstubState: { turnSeq: state.turnSeq, currentLeafId: state.currentLeafId },\n\t\t\t}),\n\t\t\t...[...state.entries.values()].map((entry) => JSON.stringify(entry)),\n\t\t].join(\"\\n\")}\\n`;\n\t}\n\tconst persisted: PersistedStubPiTreeState = {\n\t\tturnSeq: state.turnSeq,\n\t\tcurrentLeafId: state.currentLeafId,\n\t\tentries: [...state.entries.values()],\n\t\tchildIdsByParent: [...state.childIdsByParent.entries()].map(([parentId, childIds]) => ({\n\t\t\tparentId,\n\t\t\tchildIds: [...childIds],\n\t\t})),\n\t};\n\treturn JSON.stringify(persisted);\n}\n\nfunction deserializeStubPiTreeState(value: string): StubPiTreeState {\n\tconst lines = value.trim().split(\"\\n\");\n\tconst header = JSON.parse(lines[0]) as SessionHeader & {\n\t\tstubState?: { turnSeq: number; currentLeafId: string | null };\n\t};\n\tif (header.type === \"session\") {\n\t\tconst entries = lines\n\t\t\t.slice(1)\n\t\t\t.filter(Boolean)\n\t\t\t.map((line) => JSON.parse(line) as PiTreeEntry);\n\t\tconst state = createEmptyStubPiTreeState();\n\t\tstate.header = header;\n\t\tstate.turnSeq = header.stubState?.turnSeq ?? 0;\n\t\tstate.currentLeafId = header.stubState?.currentLeafId ?? null;\n\t\tfor (const entry of entries) indexStubEntry(state, entry);\n\t\treturn state;\n\t}\n\tconst parsed = JSON.parse(value) as PersistedStubPiTreeState;\n\treturn {\n\t\tturnSeq: typeof parsed.turnSeq === \"number\" ? parsed.turnSeq : 0,\n\t\tcurrentLeafId:\n\t\t\ttypeof parsed.currentLeafId === \"string\" || parsed.currentLeafId === null\n\t\t\t\t? parsed.currentLeafId\n\t\t\t\t: null,\n\t\tentries: new Map((parsed.entries ?? []).map((entry) => [entry.id, entry])),\n\t\tchildIdsByParent: new Map(\n\t\t\t(parsed.childIdsByParent ?? []).map((entry) => [entry.parentId, [...entry.childIds]]),\n\t\t),\n\t};\n}\n\nexport class StubPiTreeHandle implements PiTreeHandle {\n\treadonly sessionId: string;\n\treadonly treeFile: string;\n\treadonly isResumed: boolean;\n\n\treadonly prompts: string[] = [];\n\treadonly steers: string[] = [];\n\tbeforeTurn?: (\n\t\tkind: \"prompt\" | \"literal\" | \"custom\" | \"continue\",\n\t\toptions: PiPromptOptions | undefined,\n\t\tpromptText: string | undefined,\n\t) => boolean | undefined | Promise<boolean | undefined>;\n\n\tprivate _closed = false;\n\tprivate turnAbort = new AbortController();\n\tprivate branchDriftPending = false;\n\tprivate readonly handlers = new Set<PiEventHandler>();\n\tprivate readonly diagnosticHandlers = new Set<PiSessionDiagnosticHandler>();\n\tprivate readonly toolCallScriptResolver?: StubToolCallScriptResolver;\n\tprivate readonly state: StubPiTreeState;\n\tprivate readonly runDetails: PiRunDetails;\n\tprivate readonly persistState?: (() => Promise<void>) | undefined;\n\tprivate readonly recordSessionTrace: boolean;\n\n\tconstructor(options: {\n\t\tsessionId: string;\n\t\ttreeFile: string;\n\t\tisResumed: boolean;\n\t\ttoolCallScriptResolver?: StubToolCallScriptResolver;\n\t\tstate?: StubPiTreeState;\n\t\trunDetails?: Partial<PiRunDetails>;\n\t\tpersistState?: () => Promise<void>;\n\t\trecordSessionTrace?: boolean;\n\t}) {\n\t\tthis.sessionId = options.sessionId;\n\t\tthis.treeFile = options.treeFile;\n\t\tthis.isResumed = options.isResumed;\n\t\tthis.toolCallScriptResolver = options.toolCallScriptResolver;\n\t\tthis.state = options.state ?? createEmptyStubPiTreeState();\n\t\tthis.persistState = options.persistState;\n\t\tthis.recordSessionTrace = options.recordSessionTrace ?? false;\n\t\tthis.runDetails = {\n\t\t\tloadedAgentsFiles: options.runDetails?.loadedAgentsFiles?.map((file) => ({ ...file })) ?? [],\n\t\t\tloadedSkills: options.runDetails?.loadedSkills?.map((skill) => ({ ...skill })) ?? [],\n\t\t\tavailableToolNames: [...(options.runDetails?.availableToolNames ?? [])],\n\t\t};\n\t}\n\n\tget closed(): boolean {\n\t\treturn this._closed;\n\t}\n\n\tfailNextTurnWithBranchDrift(): void {\n\t\tthis.branchDriftPending = true;\n\t}\n\n\tprivate assertOpen(): void {\n\t\tif (this._closed) {\n\t\t\tthrow new Error(\"Handle is closed\");\n\t\t}\n\t}\n\n\tprivate addEntry(entry: PiTreeEntry): void {\n\t\tindexStubEntry(this.state, entry);\n\t\tthis.state.currentLeafId = entry.id;\n\t}\n\n\tprivate createMessageEntry(\n\t\tid: string,\n\t\tparentId: string | null,\n\t\trole: \"user\" | \"assistant\",\n\t\tcontent: unknown,\n\t\ttimestamp: string,\n\t): PiTreeEntry {\n\t\treturn {\n\t\t\tid,\n\t\t\tparentId,\n\t\t\ttype: \"message\",\n\t\t\ttimestamp,\n\t\t\tmessage: {\n\t\t\t\trole,\n\t\t\t\tcontent,\n\t\t\t},\n\t\t};\n\t}\n\n\tprivate emitEvent(event: PiEvent): void {\n\t\tfor (const handler of this.handlers) {\n\t\t\thandler(event);\n\t\t}\n\t}\n\n\tgetRunDetails(): PiRunDetails {\n\t\treturn {\n\t\t\tloadedAgentsFiles: this.runDetails.loadedAgentsFiles.map((file) => ({ ...file })),\n\t\t\tloadedSkills: this.runDetails.loadedSkills.map((skill) => ({ ...skill })),\n\t\t\tavailableToolNames: [...this.runDetails.availableToolNames],\n\t\t};\n\t}\n\n\tgetLeafId(): string | null {\n\t\treturn this.state.currentLeafId;\n\t}\n\n\tgetEntry(id: string): PiTreeEntry | undefined {\n\t\treturn this.state.entries.get(id);\n\t}\n\n\tgetBranch(fromId: string | undefined = this.state.currentLeafId ?? undefined): PiTreeEntry[] {\n\t\tif (!fromId) {\n\t\t\treturn [];\n\t\t}\n\t\tconst branch: PiTreeEntry[] = [];\n\t\tlet currentId: string | null = fromId;\n\t\twhile (currentId) {\n\t\t\tconst entry = this.state.entries.get(currentId);\n\t\t\tif (!entry) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tbranch.push(entry);\n\t\t\tcurrentId = entry.parentId;\n\t\t}\n\t\tbranch.reverse();\n\t\treturn branch;\n\t}\n\n\tgetChildren(parentId: string): PiTreeEntry[] {\n\t\treturn (this.state.childIdsByParent.get(parentId) ?? [])\n\t\t\t.map((childId) => this.state.entries.get(childId))\n\t\t\t.filter((entry): entry is PiTreeEntry => entry !== undefined);\n\t}\n\n\tgetTree(): PiTreeNode[] {\n\t\tconst buildNode = (entry: PiTreeEntry): PiTreeNode => ({\n\t\t\tentry,\n\t\t\tchildren: this.getChildren(entry.id).map(buildNode),\n\t\t});\n\t\treturn (this.state.childIdsByParent.get(null) ?? [])\n\t\t\t.map((entryId) => this.state.entries.get(entryId))\n\t\t\t.filter((entry): entry is PiTreeEntry => entry !== undefined)\n\t\t\t.map(buildNode);\n\t}\n\n\tasync branch(entryId: string): Promise<void> {\n\t\tthis.assertOpen();\n\t\tif (!this.state.entries.has(entryId)) {\n\t\t\tthrow new Error(`Unknown Pi entry '${entryId}'`);\n\t\t}\n\t\tthis.state.currentLeafId = entryId;\n\t\tawait this.persistState?.();\n\t}\n\n\tasync branchFromRoot(): Promise<void> {\n\t\tthis.assertOpen();\n\t\tthis.state.currentLeafId = null;\n\t\tawait this.persistState?.();\n\t}\n\n\tasync resetLeaf(): Promise<void> {\n\t\tawait this.branchFromRoot();\n\t}\n\n\tasync compact(_customInstructions?: string, details?: unknown): Promise<{ summary: string }> {\n\t\tthis.assertOpen();\n\t\tconst timestamp = new Date().toISOString();\n\t\tconst compactionEntryId = `compaction-${++this.state.turnSeq}`;\n\t\tthis.addEntry({\n\t\t\tid: compactionEntryId,\n\t\t\tparentId: this.state.currentLeafId,\n\t\t\ttype: \"compaction\",\n\t\t\ttimestamp,\n\t\t\tdetails,\n\t\t});\n\t\tawait this.persistState?.();\n\t\treturn { summary: \"Stub compaction\" };\n\t}\n\n\tprivate async executeTurn(input: {\n\t\tkind: \"prompt\" | \"literal\" | \"custom\" | \"continue\";\n\t\tpromptText?: string;\n\t\toptions?: PiPromptOptions;\n\t\tappendPromptUserMessage: boolean;\n\t}): Promise<PiTurnExecutionResult> {\n\t\tthis.assertOpen();\n\t\tthis.turnAbort = new AbortController();\n\t\tconst signal = this.turnAbort.signal;\n\t\tif ((await this.beforeTurn?.(input.kind, input.options, input.promptText)) === false) {\n\t\t\tinput.options = undefined;\n\t\t}\n\t\tsignal.throwIfAborted();\n\t\tif (this.branchDriftPending) {\n\t\t\tthis.branchDriftPending = false;\n\t\t\tthrow Object.assign(new Error(\"stubbed Pi branch drift\"), {\n\t\t\t\tname: \"PiBranchDriftError\",\n\t\t\t\tfailureCode: \"branch_drift\",\n\t\t\t\ttoTurnFailureOptions: () => ({\n\t\t\t\t\tfailureCode: \"branch_drift\",\n\t\t\t\t\tfailureDetails: { operation: input.kind },\n\t\t\t\t\trecoveryContext: null,\n\t\t\t\t\trestorePrimaryLeaf: false,\n\t\t\t\t}),\n\t\t\t});\n\t\t}\n\t\tif (input.promptText !== undefined) {\n\t\t\tthis.prompts.push(input.promptText);\n\t\t}\n\t\tconst startLeafId = this.state.currentLeafId;\n\t\tconst turnId = `turn-${++this.state.turnSeq}`;\n\t\tconst timestamp = new Date().toISOString();\n\t\tconst createdEntryIds: string[] = [];\n\t\tif (input.appendPromptUserMessage) {\n\t\t\tconst userEntryId = `user-${this.state.turnSeq}`;\n\t\t\tthis.addEntry(\n\t\t\t\tthis.createMessageEntry(\n\t\t\t\t\tuserEntryId,\n\t\t\t\t\tthis.state.currentLeafId,\n\t\t\t\t\t\"user\",\n\t\t\t\t\tinput.promptText ?? \"\",\n\t\t\t\t\ttimestamp,\n\t\t\t\t),\n\t\t\t);\n\t\t\tcreatedEntryIds.push(userEntryId);\n\t\t}\n\t\tawait this.persistState?.();\n\t\tsignal.throwIfAborted();\n\t\tthis.emitEvent({ type: \"turn.start\", turnId, data: {}, timestamp });\n\n\t\tconst tools = new Map((input.options?.tools ?? []).map((tool) => [tool.name, tool]));\n\t\tlet assistantContent = input.promptText ?? \"Continued.\";\n\t\tlet assistantContentFromScriptedMarkdown = false;\n\t\tconst scriptedItem = await this.toolCallScriptResolver?.({\n\t\t\ttreeFile: this.treeFile,\n\t\t\tturnSequence: this.state.turnSeq,\n\t\t\tpromptText: input.promptText ?? \"\",\n\t\t\ttools: input.options?.tools ?? [],\n\t\t});\n\t\tsignal.throwIfAborted();\n\t\tconst hasScriptedChunks = Boolean(\n\t\t\tscriptedItem &&\n\t\t\t\t\"calls\" in scriptedItem &&\n\t\t\t\t(scriptedItem.textChunks?.length ?? 0) + (scriptedItem.thinkingChunks?.length ?? 0),\n\t\t);\n\t\tif (hasScriptedChunks) assistantContent = \"\";\n\t\tif (scriptedItem && \"calls\" in scriptedItem) {\n\t\t\tconst streamed = { thinking: \"\", text: \"\" };\n\t\t\tconst streamEntryId = `stream-${this.state.turnSeq}`;\n\t\t\tconst streamParentId = this.state.currentLeafId;\n\t\t\tconst chunks = [\n\t\t\t\t...(scriptedItem.thinkingChunks ?? []).map((text) => ({\n\t\t\t\t\ttext,\n\t\t\t\t\tstreamType: \"thinking\" as const,\n\t\t\t\t})),\n\t\t\t\t...(scriptedItem.textChunks ?? []).map((text) => ({ text, streamType: \"text\" as const })),\n\t\t\t];\n\t\t\tfor (const { text, streamType } of chunks) {\n\t\t\t\tsignal.throwIfAborted();\n\t\t\t\tstreamed[streamType] += text;\n\t\t\t\tassistantContent = streamed.text;\n\t\t\t\tif (this.recordSessionTrace) {\n\t\t\t\t\tconst entry = this.createMessageEntry(\n\t\t\t\t\t\tstreamEntryId,\n\t\t\t\t\t\tstreamParentId,\n\t\t\t\t\t\t\"assistant\",\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t...(streamed.thinking ? [{ type: \"thinking\", thinking: streamed.thinking }] : []),\n\t\t\t\t\t\t\t...(streamed.text ? [{ type: \"text\", text: streamed.text }] : []),\n\t\t\t\t\t\t],\n\t\t\t\t\t\ttimestamp,\n\t\t\t\t\t);\n\t\t\t\t\tif (this.state.entries.has(streamEntryId)) this.state.entries.set(streamEntryId, entry);\n\t\t\t\t\telse {\n\t\t\t\t\t\tthis.addEntry(entry);\n\t\t\t\t\t\tcreatedEntryIds.push(streamEntryId);\n\t\t\t\t\t}\n\t\t\t\t\tawait this.persistState?.();\n\t\t\t\t}\n\t\t\t\tthis.emitEvent({\n\t\t\t\t\ttype: \"stream.delta\",\n\t\t\t\t\tturnId,\n\t\t\t\t\tdata: { text, streamType },\n\t\t\t\t\ttimestamp: new Date().toISOString(),\n\t\t\t\t});\n\t\t\t\tsignal.throwIfAborted();\n\t\t\t\tif (scriptedItem.chunkDelayMs)\n\t\t\t\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\t\t\t\tconst timer = setTimeout(() => {\n\t\t\t\t\t\t\tsignal.removeEventListener(\"abort\", abort);\n\t\t\t\t\t\t\tresolve();\n\t\t\t\t\t\t}, scriptedItem.chunkDelayMs);\n\t\t\t\t\t\tconst abort = () => {\n\t\t\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\t\t\treject(signal.reason);\n\t\t\t\t\t\t};\n\t\t\t\t\t\tsignal.addEventListener(\"abort\", abort, { once: true });\n\t\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tconst scriptedCalls = scriptedItem ? expandStubToolCallScriptItem(scriptedItem) : [];\n\t\tif (scriptedCalls.length > 0) {\n\t\t\tfor (const [callIndex, scriptedCall] of scriptedCalls.entries()) {\n\t\t\t\tsignal.throwIfAborted();\n\t\t\t\tconst toolCallId = stubToolCallId(this.state.turnSeq, scriptedCalls.length, callIndex);\n\t\t\t\tthis.emitEvent({\n\t\t\t\t\ttype: \"tool.call\",\n\t\t\t\t\tturnId,\n\t\t\t\t\tdata: {\n\t\t\t\t\t\ttoolCallId,\n\t\t\t\t\t\tname: scriptedCall.toolName,\n\t\t\t\t\t\targuments: scriptedCall.args,\n\t\t\t\t\t},\n\t\t\t\t\ttimestamp,\n\t\t\t\t});\n\t\t\t\tconst tool = tools.get(scriptedCall.toolName);\n\t\t\t\tif (!tool && scriptedCall.toolName === \"markdown_result\") {\n\t\t\t\t\tconst markdown = (scriptedCall.args as { markdown?: unknown }).markdown;\n\t\t\t\t\tif (typeof markdown === \"string\") {\n\t\t\t\t\t\tassistantContent = markdown;\n\t\t\t\t\t\tassistantContentFromScriptedMarkdown = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (tool) {\n\t\t\t\t\tif (this.recordSessionTrace) {\n\t\t\t\t\t\tconst entryId = `call-${toolCallId}`;\n\t\t\t\t\t\tthis.addEntry(\n\t\t\t\t\t\t\tthis.createMessageEntry(\n\t\t\t\t\t\t\t\tentryId,\n\t\t\t\t\t\t\t\tthis.state.currentLeafId,\n\t\t\t\t\t\t\t\t\"assistant\",\n\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\ttype: \"toolCall\",\n\t\t\t\t\t\t\t\t\t\tid: toolCallId,\n\t\t\t\t\t\t\t\t\t\tname: scriptedCall.toolName,\n\t\t\t\t\t\t\t\t\t\targuments: scriptedCall.args,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tnew Date().toISOString(),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tcreatedEntryIds.push(entryId);\n\t\t\t\t\t\tawait this.persistState?.();\n\t\t\t\t\t}\n\t\t\t\t\tconst recordToolResult = async (result: unknown, isError: boolean) => {\n\t\t\t\t\t\tif (!this.recordSessionTrace) return;\n\t\t\t\t\t\tconst entryId = `result-${toolCallId}`;\n\t\t\t\t\t\tconst entry = {\n\t\t\t\t\t\t\tid: entryId,\n\t\t\t\t\t\t\tparentId: this.state.currentLeafId,\n\t\t\t\t\t\t\ttype: \"message\",\n\t\t\t\t\t\t\ttimestamp: new Date().toISOString(),\n\t\t\t\t\t\t\tmessage: {\n\t\t\t\t\t\t\t\trole: \"toolResult\",\n\t\t\t\t\t\t\t\ttoolCallId,\n\t\t\t\t\t\t\t\ttoolName: scriptedCall.toolName,\n\t\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: stringifyToolResult(result) }],\n\t\t\t\t\t\t\t\tisError,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t};\n\t\t\t\t\t\tthis.addEntry(entry);\n\t\t\t\t\t\tcreatedEntryIds.push(entryId);\n\t\t\t\t\t\tawait this.persistState?.();\n\t\t\t\t\t};\n\t\t\t\t\ttry {\n\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\tconst blocked = input.options?.shouldBlockToolCall?.(scriptedCall.toolName);\n\t\t\t\t\t\tif (blocked) throw new Error(blocked);\n\t\t\t\t\t\tconst result = await tool.execute(scriptedCall.args, {\n\t\t\t\t\t\t\ttoolCallId,\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\tsuspendPromptGuards: input.options?.suspendPromptGuards,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\tif (!assistantContentFromScriptedMarkdown) {\n\t\t\t\t\t\t\tassistantContent = stringifyToolResult(result);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tawait recordToolResult(result, false);\n\t\t\t\t\t\tconst followUp =\n\t\t\t\t\t\t\tscriptedItem && \"calls\" in scriptedItem\n\t\t\t\t\t\t\t\t? scriptedItem.afterToolResult?.(scriptedCall, result)\n\t\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\t\tif (followUp) scriptedCalls.push(followUp);\n\t\t\t\t\t\tthis.emitEvent({\n\t\t\t\t\t\t\ttype: \"tool.result\",\n\t\t\t\t\t\t\tturnId,\n\t\t\t\t\t\t\tdata: { toolCallId, name: scriptedCall.toolName, result },\n\t\t\t\t\t\t\ttimestamp,\n\t\t\t\t\t\t});\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tawait recordToolResult(error instanceof Error ? error.message : String(error), true);\n\t\t\t\t\t\tthis.emitEvent({\n\t\t\t\t\t\t\ttype: \"error\",\n\t\t\t\t\t\t\tturnId,\n\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t\t\t\ttoolName: scriptedCall.toolName,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\ttimestamp,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tthrow error;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor (let i = 0; i < (scriptedCall.intermediateEntryCount ?? 0); i++) {\n\t\t\t\t\tconst intermediateEntryId =\n\t\t\t\t\t\tscriptedCalls.length === 1\n\t\t\t\t\t\t\t? `intermediate-${this.state.turnSeq}-${i + 1}`\n\t\t\t\t\t\t\t: `intermediate-${this.state.turnSeq}-${callIndex + 1}-${i + 1}`;\n\t\t\t\t\tthis.addEntry(\n\t\t\t\t\t\tthis.createMessageEntry(\n\t\t\t\t\t\t\tintermediateEntryId,\n\t\t\t\t\t\t\tthis.state.currentLeafId,\n\t\t\t\t\t\t\t\"assistant\",\n\t\t\t\t\t\t\t`Intermediate entry ${i + 1}`,\n\t\t\t\t\t\t\ttimestamp,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t\tcreatedEntryIds.push(intermediateEntryId);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (tools.size > 0 && !hasScriptedChunks) {\n\t\t\tthrow new Error(\n\t\t\t\t`Stub Pi prompt requires a stub tool-call script when tools are provided (${[...tools.keys()].join(\", \")})`,\n\t\t\t);\n\t\t} else if (input.promptText !== undefined && !hasScriptedChunks) {\n\t\t\tthis.emitEvent({\n\t\t\t\ttype: \"stream.delta\",\n\t\t\t\tturnId,\n\t\t\t\tdata: { text: input.promptText },\n\t\t\t\ttimestamp,\n\t\t\t});\n\t\t}\n\n\t\tsignal.throwIfAborted();\n\t\t// Keep the result entry ID without repeating content already saved in the stream entry.\n\t\tthis.addEntry(\n\t\t\tthis.createMessageEntry(\n\t\t\t\tturnId,\n\t\t\t\tthis.state.currentLeafId,\n\t\t\t\t\"assistant\",\n\t\t\t\tthis.recordSessionTrace && hasScriptedChunks && scriptedCalls.length === 0\n\t\t\t\t\t? []\n\t\t\t\t\t: assistantContent,\n\t\t\t\ttimestamp,\n\t\t\t),\n\t\t);\n\t\tcreatedEntryIds.push(turnId);\n\t\tawait this.persistState?.();\n\t\tsignal.throwIfAborted();\n\t\tthis.emitEvent({ type: \"turn.end\", turnId, data: {}, timestamp });\n\t\tconst resultEntryId = this.state.currentLeafId;\n\t\tif (!resultEntryId) {\n\t\t\tthrow new Error(\n\t\t\t\tinput.appendPromptUserMessage\n\t\t\t\t\t? \"Stub Pi prompt completed without an active leaf\"\n\t\t\t\t\t: \"Stub Pi continuation completed without an active leaf\",\n\t\t\t);\n\t\t}\n\t\treturn {\n\t\t\tstartLeafId,\n\t\t\tendLeafId: resultEntryId,\n\t\t\tcreatedEntryIds,\n\t\t\tresultEntryId,\n\t\t\tassistantMarkdown: assistantContent,\n\t\t};\n\t}\n\n\tasync prompt(text: string, options: PiPromptOptions = {}): Promise<PiTurnExecutionResult> {\n\t\treturn await this.executeTurn({\n\t\t\tkind: \"prompt\",\n\t\t\tpromptText: text,\n\t\t\toptions,\n\t\t\tappendPromptUserMessage: true,\n\t\t});\n\t}\n\n\tasync promptLiteral(text: string, options: PiPromptOptions = {}): Promise<PiTurnExecutionResult> {\n\t\treturn await this.executeTurn({\n\t\t\tkind: \"literal\",\n\t\t\tpromptText: text,\n\t\t\toptions,\n\t\t\tappendPromptUserMessage: true,\n\t\t});\n\t}\n\n\tasync promptCustom(\n\t\tinput: PiCustomMessageInput,\n\t\toptions: PiPromptOptions = {},\n\t): Promise<PiTurnExecutionResult> {\n\t\tconst startLeafId = this.getLeafId();\n\t\tconst promptEntryId = await this.appendCustomMessage(input);\n\t\tconst result = await this.executeTurn({\n\t\t\tkind: \"custom\",\n\t\t\toptions,\n\t\t\tappendPromptUserMessage: false,\n\t\t});\n\t\treturn {\n\t\t\t...result,\n\t\t\tstartLeafId,\n\t\t\tcreatedEntryIds: [promptEntryId, ...result.createdEntryIds],\n\t\t};\n\t}\n\n\tasync continueTurn(options: PiPromptOptions = {}): Promise<PiTurnExecutionResult> {\n\t\treturn await this.executeTurn({\n\t\t\tkind: \"continue\",\n\t\t\toptions,\n\t\t\tappendPromptUserMessage: false,\n\t\t});\n\t}\n\n\tasync appendUserMessage(text: string): Promise<string> {\n\t\tthis.assertOpen();\n\t\tconst timestamp = new Date().toISOString();\n\t\tconst userEntryId = `user-${++this.state.turnSeq}`;\n\t\tthis.addEntry(\n\t\t\tthis.createMessageEntry(userEntryId, this.state.currentLeafId, \"user\", text, timestamp),\n\t\t);\n\t\tawait this.persistState?.();\n\t\treturn userEntryId;\n\t}\n\n\tasync appendCustomMessage(input: PiCustomMessageInput): Promise<string> {\n\t\tthis.assertOpen();\n\t\tconst timestamp = new Date().toISOString();\n\t\tconst entryId = `custom-${++this.state.turnSeq}`;\n\t\tthis.addEntry({\n\t\t\tid: entryId,\n\t\t\tparentId: this.state.currentLeafId,\n\t\t\ttype: \"custom_message\",\n\t\t\ttimestamp,\n\t\t\tcustomType: \"leitwerk\",\n\t\t\tcontent: input.content,\n\t\t\tdetails: input.details,\n\t\t});\n\t\tawait this.persistState?.();\n\t\treturn entryId;\n\t}\n\n\tasync steer(text: string): Promise<void> {\n\t\tthis.assertOpen();\n\t\tthis.steers.push(text);\n\t}\n\n\tasync abortTurn(): Promise<void> {\n\t\tthis.assertOpen();\n\t\tthis.turnAbort.abort(new Error(\"Scripted turn aborted\"));\n\t}\n\n\tsubscribe(handler: PiEventHandler): () => void {\n\t\tthis.handlers.add(handler);\n\t\treturn () => {\n\t\t\tthis.handlers.delete(handler);\n\t\t};\n\t}\n\n\tsubscribeDiagnostics(handler: PiSessionDiagnosticHandler): () => void {\n\t\tthis.diagnosticHandlers.add(handler);\n\t\treturn () => {\n\t\t\tthis.diagnosticHandlers.delete(handler);\n\t\t};\n\t}\n\n\temitDiagnostic(diagnostic: PiSessionDiagnostic): void {\n\t\tfor (const handler of this.diagnosticHandlers) handler(diagnostic);\n\t}\n\n\tasync close(): Promise<void> {\n\t\tthis.turnAbort.abort(new Error(\"Scripted session closed\"));\n\t\tawait this.persistState?.();\n\t\tthis._closed = true;\n\t\tthis.handlers.clear();\n\t\tthis.diagnosticHandlers.clear();\n\t}\n}\n\nexport interface StubPiTreeHandleFactoryOptions {\n\ttoolCallScriptResolver?: StubToolCallScriptResolver;\n\t/** Persist SDK-readable JSONL with reasoning and tool messages for history/detail tests. */\n\trecordSessionTrace?: boolean;\n}\n\nexport class StubPiTreeHandleFactory implements PiTreeHandleFactory {\n\treadonly sessions: StubPiTreeHandle[] = [];\n\ttoolCallScriptResolver?: StubToolCallScriptResolver;\n\n\tprivate seq = 0;\n\tprivate readonly treeStateByFile = new Map<string, StubPiTreeState>();\n\tprivate readonly recordSessionTrace: boolean;\n\n\tconstructor(options: StubPiTreeHandleFactoryOptions = {}) {\n\t\tthis.toolCallScriptResolver = options.toolCallScriptResolver;\n\t\tthis.recordSessionTrace = options.recordSessionTrace ?? false;\n\t}\n\n\tasync prepareManagedBootstrap(\n\t\topts: PiManagedBootstrapOptions,\n\t): Promise<PiManagedBootstrapResult> {\n\t\treturn {\n\t\t\tloadedResourceIds: opts.manifest.provenance.map(\n\t\t\t\t(resource: { snapshotPath: string }) => resource.snapshotPath,\n\t\t\t),\n\t\t\tloadedAgentsFiles: [],\n\t\t\tloadedSkillFiles: [],\n\t\t\tresolvedModel: { ...opts.expectedModel },\n\t\t\tdiagnostics: [],\n\t\t};\n\t}\n\n\tasync inspectPrimaryTree(opts: PiTreePlanningOptions): Promise<PiTreePlanningSnapshot> {\n\t\tlet treeState = this.treeStateByFile.get(opts.treeFile);\n\t\tif (!treeState) {\n\t\t\ttry {\n\t\t\t\ttreeState = deserializeStubPiTreeState(readFileSync(opts.treeFile, \"utf8\"));\n\t\t\t} catch (error) {\n\t\t\t\tif (isEnoent(error)) {\n\t\t\t\t\treturn { currentLeafId: null, entries: [] };\n\t\t\t\t}\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tcurrentLeafId: treeState.currentLeafId ?? deriveStubLeafIdFromEntries(treeState),\n\t\t\tentries: [...treeState.entries.values()].map((entry) => ({\n\t\t\t\tid: entry.id,\n\t\t\t\tparentId: entry.parentId,\n\t\t\t})),\n\t\t};\n\t}\n\n\tasync createPrimaryTreeHandle(opts: PiTreeHandleOptions): Promise<PiTreeHandle> {\n\t\tconst persistState = async (state: StubPiTreeState): Promise<void> => {\n\t\t\tthis.treeStateByFile.set(opts.treeFile, state);\n\t\t\ttry {\n\t\t\t\tmkdirSync(path.dirname(opts.treeFile), { recursive: true });\n\t\t\t\twriteFileSync(\n\t\t\t\t\topts.treeFile,\n\t\t\t\t\tserializeStubPiTreeState(state, this.recordSessionTrace),\n\t\t\t\t\t\"utf8\",\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\tif (\n\t\t\t\t\ttypeof error !== \"object\" ||\n\t\t\t\t\terror === null ||\n\t\t\t\t\t!(\"code\" in error) ||\n\t\t\t\t\t![\"ENOENT\", \"EACCES\", \"EROFS\", \"EPERM\"].includes(\n\t\t\t\t\t\tString((error as { code?: unknown }).code),\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tlet treeState = this.treeStateByFile.get(opts.treeFile);\n\t\tif (!treeState && opts.resume) {\n\t\t\ttry {\n\t\t\t\tconst persisted = readFileSync(opts.treeFile, \"utf8\");\n\t\t\t\ttreeState = deserializeStubPiTreeState(persisted);\n\t\t\t} catch (error) {\n\t\t\t\tif (\n\t\t\t\t\ttypeof error === \"object\" &&\n\t\t\t\t\terror !== null &&\n\t\t\t\t\t\"code\" in error &&\n\t\t\t\t\t(error as { code?: unknown }).code !== \"ENOENT\"\n\t\t\t\t) {\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\ttreeState ??= createEmptyStubPiTreeState();\n\t\ttreeState.header ??= {\n\t\t\ttype: \"session\",\n\t\t\tversion: CURRENT_SESSION_VERSION,\n\t\t\tid: randomUUID(),\n\t\t\ttimestamp: new Date().toISOString(),\n\t\t\tcwd: opts.sessionCwd ?? opts.workspaceRoot ?? path.dirname(opts.treeFile),\n\t\t};\n\t\tif (opts.resume) {\n\t\t\ttreeState.currentLeafId = deriveStubLeafIdFromEntries(treeState);\n\t\t}\n\t\tthis.treeStateByFile.set(opts.treeFile, treeState);\n\t\tconst piHandle = new StubPiTreeHandle({\n\t\t\tsessionId: `stub-${++this.seq}`,\n\t\t\ttreeFile: opts.treeFile,\n\t\t\tisResumed: opts.resume,\n\t\t\ttoolCallScriptResolver: this.toolCallScriptResolver\n\t\t\t\t? (context) =>\n\t\t\t\t\t\tthis.toolCallScriptResolver?.({\n\t\t\t\t\t\t\t...context,\n\t\t\t\t\t\t\tinstanceId: opts.instanceId,\n\t\t\t\t\t\t\tworkspaceRoot: opts.workspaceRoot,\n\t\t\t\t\t\t\tsessionCwd: opts.sessionCwd,\n\t\t\t\t\t\t})\n\t\t\t\t: undefined,\n\t\t\tstate: treeState,\n\t\t\tpersistState: () => persistState(treeState),\n\t\t\trecordSessionTrace: this.recordSessionTrace,\n\t\t\trunDetails: {\n\t\t\t\tavailableToolNames: opts.piConfig?.availableToolNames ?? [],\n\t\t\t},\n\t\t});\n\t\tthis.sessions.push(piHandle);\n\t\tif (!opts.resume) {\n\t\t\tawait persistState(treeState);\n\t\t}\n\t\treturn piHandle;\n\t}\n}\n","import {\n\tStubPiTreeHandleFactory,\n\ttype StubToolCallScriptResolver,\n\ttype StubToolCallScriptResolverContext,\n} from \"./stub-pi-tree-handle.js\";\n\nfunction isObjectLike(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n\nexport function synthesizeStubArgValue(key: string, spec: unknown): unknown {\n\tif (key === \"changedProjects\") {\n\t\treturn undefined;\n\t}\n\tconst type = isObjectLike(spec) && typeof spec.type === \"string\" ? spec.type : \"string\";\n\tswitch (type) {\n\t\tcase \"number\":\n\t\tcase \"integer\":\n\t\t\treturn 1;\n\t\tcase \"boolean\":\n\t\t\treturn true;\n\t\tcase \"array\": {\n\t\t\tconst itemSpec = isObjectLike(spec) ? spec.items : undefined;\n\t\t\treturn [synthesizeStubArgValue(`${key}_item`, itemSpec)];\n\t\t}\n\t\tcase \"object\":\n\t\t\treturn {};\n\t\tdefault:\n\t\t\treturn `${key} value`;\n\t}\n}\n\nexport function synthesizeStubToolArgs(\n\tparameters: Record<string, unknown>,\n): Record<string, unknown> {\n\tconst parameterEntries =\n\t\tisObjectLike(parameters) && parameters.type === \"object\" && isObjectLike(parameters.properties)\n\t\t\t? Object.entries(parameters.properties)\n\t\t\t: Object.entries(parameters);\n\treturn Object.fromEntries(\n\t\tparameterEntries.map(([key, spec]) => [key, synthesizeStubArgValue(key, spec)]),\n\t);\n}\n\nexport function createSchemaDrivenToolCallScriptResolver(): StubToolCallScriptResolver {\n\treturn ({ tools }: StubToolCallScriptResolverContext) => {\n\t\tconst markdownTool = tools.find((tool) => tool.name === \"markdown_result\");\n\t\tconst completionTool = tools.find(\n\t\t\t(tool) => tool.name !== \"markdown_result\" && tool.name !== \"upload_result_images\",\n\t\t);\n\t\tif (markdownTool && completionTool) {\n\t\t\treturn {\n\t\t\t\tcalls: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttoolName: markdownTool.name,\n\t\t\t\t\t\targs: synthesizeStubToolArgs(markdownTool.parameters),\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttoolName: completionTool.name,\n\t\t\t\t\t\targs: synthesizeStubToolArgs(completionTool.parameters),\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\t\t}\n\t\tconst tool = markdownTool ?? completionTool ?? tools[0];\n\t\tif (!tool) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn {\n\t\t\ttoolName: tool.name,\n\t\t\targs: synthesizeStubToolArgs(tool.parameters),\n\t\t};\n\t};\n}\n\nexport function createSchemaDrivenStubPiFactory(\n\toptions: { toolCallScriptResolver?: StubToolCallScriptResolver } = {},\n): StubPiTreeHandleFactory {\n\treturn new StubPiTreeHandleFactory({\n\t\ttoolCallScriptResolver:\n\t\t\toptions.toolCallScriptResolver ?? createSchemaDrivenToolCallScriptResolver(),\n\t});\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAC3B,SAAS,WAAW,cAAc,qBAAqB;AACvD,OAAO,UAAU;AACjB,SAAS,+BAAmD;AAe5D,SAAS,gBAAgB;AA4CzB,SAAS,oBAAoB,QAAyB;AACrD,MAAI,OAAO,WAAW,UAAU;AAC/B,WAAO;AAAA,EACR;AACA,MAAI,WAAW,QAAW;AACzB,WAAO;AAAA,EACR;AACA,MAAI;AACH,WAAO,KAAK,UAAU,QAAQ,MAAM,CAAC;AAAA,EACtC,QAAQ;AACP,WAAO,OAAO,MAAM;AAAA,EACrB;AACD;AAEA,SAAS,6BAA6B,MAAwD;AAC7F,MAAI,WAAW,MAAM;AACpB,WAAO,CAAC,GAAG,KAAK,KAAK;AAAA,EACtB;AACA,SAAO,CAAC,IAAI;AACb;AAEA,SAAS,eAAe,SAAiB,YAAoB,OAAuB;AACnF,MAAI,cAAc,GAAG;AACpB,WAAO,QAAQ,OAAO;AAAA,EACvB;AACA,SAAO,QAAQ,OAAO,IAAI,QAAQ,CAAC;AACpC;AAiBA,SAAS,6BAA8C;AACtD,SAAO;AAAA,IACN,SAAS;AAAA,IACT,eAAe;AAAA,IACf,SAAS,oBAAI,IAAyB;AAAA,IACtC,kBAAkB,oBAAI,IAA6B;AAAA,EACpD;AACD;AA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AAa,UAAU;AAAA,UACrD;AAAA,UACA;AAAA,YACC,UAAU,eAAe;AAAA,YACzB,MAAM,uBAAuB,eAAe,UAAU;AAAA,UACvD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AACA,UAAM,OAAO,gBAAgB,kBAAkB,MAAM,CAAC;AACtD,QAAI,CAAC,MAAM;AACV,aAAO;AAAA,IACR;AACA,WAAO;AAAA,MACN,UAAU,KAAK;AAAA,MACf,MAAM,uBAAuB,KAAK,UAAU;AAAA,IAC7C;AAAA,EACD;AACD;AAEO,SAAS,gCACf,UAAmE,CAAC,GAC1C;AAC1B,SAAO,IAAI,wBAAwB;AAAA,IAClC,wBACC,QAAQ,0BAA0B,yCAAyC;AAAA,EAC7E,CAAC;AACF;","names":["tool"]}
|
package/dist/chunk-3MQO3NCX.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// src/worker-testing/stub-pi-controls.ts
|
|
2
|
-
function createStubToolScriptController() {
|
|
3
|
-
const queue = [];
|
|
4
|
-
return {
|
|
5
|
-
resolver: () => queue.shift(),
|
|
6
|
-
set(script) {
|
|
7
|
-
queue.splice(0, queue.length, ...script);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export {
|
|
13
|
-
createStubToolScriptController
|
|
14
|
-
};
|
|
15
|
-
//# sourceMappingURL=chunk-3MQO3NCX.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/worker-testing/stub-pi-controls.ts"],"sourcesContent":["import type { StubToolCallScriptItem, StubToolCallScriptResolver } from \"./stub-pi-tree-handle.js\";\n\nexport interface StubToolScriptController {\n\treadonly resolver: StubToolCallScriptResolver;\n\tset(script: StubToolCallScriptItem[]): void;\n}\n\nexport function createStubToolScriptController(): StubToolScriptController {\n\tconst queue: StubToolCallScriptItem[] = [];\n\treturn {\n\t\tresolver: () => queue.shift(),\n\t\tset(script) {\n\t\t\tqueue.splice(0, queue.length, ...script);\n\t\t},\n\t};\n}\n"],"mappings":";AAOO,SAAS,iCAA2D;AAC1E,QAAM,QAAkC,CAAC;AACzC,SAAO;AAAA,IACN,UAAU,MAAM,MAAM,MAAM;AAAA,IAC5B,IAAI,QAAQ;AACX,YAAM,OAAO,GAAG,MAAM,QAAQ,GAAG,MAAM;AAAA,IACxC;AAAA,EACD;AACD;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/worker-testing/in-process-worker-spawn.ts"],"sourcesContent":["import type { ChildProcess, spawn } from \"node:child_process\";\nimport { EventEmitter } from \"node:events\";\nimport { createRequire } from \"node:module\";\nimport { PassThrough } from \"node:stream\";\nimport { setTimeout as delay } from \"node:timers/promises\";\nimport type { ExtensionCatalog } from \"@leitwerk-dev/extension-runtime\";\nimport type { PiTreeHandleFactory } from \"@leitwerk-dev/worker\";\nimport { createWorkerEntryRuntime } from \"@leitwerk-dev/worker\";\nimport { createSchemaDrivenStubPiFactory } from \"./schema-driven-stub-pi.js\";\nimport type { StubToolCallScriptResolver } from \"./stub-pi-tree-handle.js\";\n\nconst require = createRequire(import.meta.url);\nconst WebSocket =\n\t(require(\"ws\") as { WebSocket?: unknown; default?: unknown }).WebSocket ??\n\t(require(\"ws\") as { default?: unknown }).default ??\n\trequire(\"ws\");\n\nexport interface InProcessWorkerSpawnOptions {\n\textensionCatalog?: ExtensionCatalog | Promise<ExtensionCatalog>;\n\tpiFactory?: PiTreeHandleFactory;\n\ttoolCallScriptResolver?: StubToolCallScriptResolver;\n\t/** Optional delays at real connection and managed-runtime preparation boundaries. */\n\tstartupDelays?: (instanceId: string) => { connectMs: number; prepareMs: number } | undefined;\n}\n\n/**\n * Fast local-runner-shaped spawn fake. The worker receives the local runner's\n * env and connects over WebSocket just like Docker/Kubernetes workers do.\n */\nexport function createInProcessWorkerSpawn(\n\toptions: InProcessWorkerSpawnOptions = {},\n): typeof spawn {\n\tconst piFactory =\n\t\toptions.piFactory ??\n\t\tcreateSchemaDrivenStubPiFactory({\n\t\t\ttoolCallScriptResolver: options.toolCallScriptResolver,\n\t\t});\n\treturn ((\n\t\tcommand: string,\n\t\targs: readonly string[] = [],\n\t\tspawnOptions?: { env?: NodeJS.ProcessEnv },\n\t) => {\n\t\tconst stderr = new PassThrough();\n\t\tconst child = new EventEmitter() as unknown as ChildProcess;\n\t\tconst emitter = child as unknown as EventEmitter;\n\t\tlet exited = false;\n\t\tconst cancellation = new AbortController();\n\t\tconst timing = options.startupDelays?.(spawnOptions?.env?.LEITWERK_INSTANCE_ID ?? \"\");\n\t\tconst pause = (ms: number) => delay(ms, undefined, { signal: cancellation.signal });\n\n\t\tlet runtime: ReturnType<typeof createWorkerEntryRuntime> | null = null;\n\t\tconst finish = (code: number) => {\n\t\t\tif (!exited) {\n\t\t\t\texited = true;\n\t\t\t\tcancellation.abort();\n\t\t\t\temitter.emit(\"exit\", code, null);\n\t\t\t}\n\t\t};\n\n\t\tObject.assign(child, {\n\t\t\tstderr,\n\t\t\tpid: Math.floor(Math.random() * 100_000) + 1_000,\n\t\t\tkill: (_signal?: NodeJS.Signals | number) => {\n\t\t\t\tfinish(0);\n\t\t\t\tvoid runtime?.stop(\"test_kill\").catch(() => {});\n\t\t\t\treturn true;\n\t\t\t},\n\t\t\tspawnfile: command,\n\t\t\tspawnargs: [command, ...args],\n\t\t});\n\n\t\truntime = createWorkerEntryRuntime({\n\t\t\textensionCatalog: options.extensionCatalog,\n\t\t\tpiFactory: timing\n\t\t\t\t? {\n\t\t\t\t\t\tasync prepareManagedBootstrap(input) {\n\t\t\t\t\t\t\tawait pause(timing.prepareMs);\n\t\t\t\t\t\t\treturn piFactory.prepareManagedBootstrap(input);\n\t\t\t\t\t\t},\n\t\t\t\t\t\tinspectPrimaryTree: (input) => piFactory.inspectPrimaryTree(input),\n\t\t\t\t\t\tcreatePrimaryTreeHandle: (input) => piFactory.createPrimaryTreeHandle(input),\n\t\t\t\t\t}\n\t\t\t\t: piFactory,\n\t\t\tstderr,\n\t\t\tenv: spawnOptions?.env ?? process.env,\n\t\t\texit: finish,\n\t\t});\n\n\t\tsetImmediate(() => {\n\t\t\tif (exited) return;\n\t\t\t(globalThis as unknown as { WebSocket?: unknown }).WebSocket = WebSocket;\n\t\t\tvoid (async () => {\n\t\t\t\tif (timing) await pause(timing.connectMs);\n\t\t\t\tif (!exited) await runtime?.start();\n\t\t\t})().catch((error: unknown) => {\n\t\t\t\tif (exited) return;\n\t\t\t\tstderr.write(`${error instanceof Error ? error.message : String(error)}\\n`);\n\t\t\t\tfinish(1);\n\t\t\t});\n\t\t});\n\n\t\treturn child;\n\t}) as typeof spawn;\n}\n"],"mappings":";;;;;AACA,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;AAC5B,SAAS,cAAc,aAAa;AAGpC,SAAS,gCAAgC;AAIzC,IAAMA,WAAU,cAAc,YAAY,GAAG;AAC7C,IAAM,YACJA,SAAQ,IAAI,EAAiD,aAC7DA,SAAQ,IAAI,EAA4B,WACzCA,SAAQ,IAAI;AAcN,SAAS,2BACf,UAAuC,CAAC,GACzB;AACf,QAAM,YACL,QAAQ,aACR,gCAAgC;AAAA,IAC/B,wBAAwB,QAAQ;AAAA,EACjC,CAAC;AACF,UAAQ,CACP,SACA,OAA0B,CAAC,GAC3B,iBACI;AACJ,UAAM,SAAS,IAAI,YAAY;AAC/B,UAAM,QAAQ,IAAI,aAAa;AAC/B,UAAM,UAAU;AAChB,QAAI,SAAS;AACb,UAAM,eAAe,IAAI,gBAAgB;AACzC,UAAM,SAAS,QAAQ,gBAAgB,cAAc,KAAK,wBAAwB,EAAE;AACpF,UAAM,QAAQ,CAAC,OAAe,MAAM,IAAI,QAAW,EAAE,QAAQ,aAAa,OAAO,CAAC;AAElF,QAAI,UAA8D;AAClE,UAAM,SAAS,CAAC,SAAiB;AAChC,UAAI,CAAC,QAAQ;AACZ,iBAAS;AACT,qBAAa,MAAM;AACnB,gBAAQ,KAAK,QAAQ,MAAM,IA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
import path from "path";
|
|
3
|
-
var FakeGitOps = class {
|
|
4
|
-
constructor(templates) {
|
|
5
|
-
this.templates = templates;
|
|
6
|
-
}
|
|
7
|
-
templates;
|
|
8
|
-
operations = [];
|
|
9
|
-
files = /* @__PURE__ */ new Map();
|
|
10
|
-
repoState = /* @__PURE__ */ new Map();
|
|
11
|
-
abs(repoDir, filePath) {
|
|
12
|
-
return path.normalize(path.join(repoDir, filePath));
|
|
13
|
-
}
|
|
14
|
-
async writeFile(repoDir, filePath, content) {
|
|
15
|
-
this.operations.push(`writeFile:${filePath}`);
|
|
16
|
-
this.files.set(this.abs(repoDir, filePath), content);
|
|
17
|
-
}
|
|
18
|
-
async readFile(repoDir, filePath) {
|
|
19
|
-
return this.files.get(this.abs(repoDir, filePath)) ?? null;
|
|
20
|
-
}
|
|
21
|
-
async clone(repoLocator, targetDir) {
|
|
22
|
-
this.operations.push(`clone:${path.basename(targetDir)}`);
|
|
23
|
-
const n = path.normalize(targetDir);
|
|
24
|
-
const prefix = n + path.sep;
|
|
25
|
-
for (const k of [...this.files.keys()]) {
|
|
26
|
-
if (k === n || k.startsWith(prefix)) {
|
|
27
|
-
this.files.delete(k);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
const tmpl = this.templates.get(repoLocator);
|
|
31
|
-
if (!tmpl) {
|
|
32
|
-
throw new Error(`unknown repo ${repoLocator}`);
|
|
33
|
-
}
|
|
34
|
-
for (const [rel, content] of Object.entries(tmpl)) {
|
|
35
|
-
this.files.set(path.join(targetDir, rel), content);
|
|
36
|
-
}
|
|
37
|
-
this.repoState.set(n, {
|
|
38
|
-
currentBranch: "main",
|
|
39
|
-
branches: /* @__PURE__ */ new Set(["main"])
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
async checkout(repoDir, branch) {
|
|
43
|
-
const st = this.repoState.get(path.normalize(repoDir));
|
|
44
|
-
if (!st) {
|
|
45
|
-
throw new Error("not a repo");
|
|
46
|
-
}
|
|
47
|
-
st.branches.add(branch);
|
|
48
|
-
st.currentBranch = branch;
|
|
49
|
-
}
|
|
50
|
-
async createBranch(repoDir, branchName, _startPoint) {
|
|
51
|
-
const st = this.repoState.get(path.normalize(repoDir));
|
|
52
|
-
if (!st) {
|
|
53
|
-
throw new Error("not a repo");
|
|
54
|
-
}
|
|
55
|
-
st.branches.add(branchName);
|
|
56
|
-
}
|
|
57
|
-
async branchExists(repoDir, branchName) {
|
|
58
|
-
const st = this.repoState.get(path.normalize(repoDir));
|
|
59
|
-
return st?.branches.has(branchName) ?? false;
|
|
60
|
-
}
|
|
61
|
-
async getHeadSha(repoDir) {
|
|
62
|
-
const st = this.repoState.get(path.normalize(repoDir));
|
|
63
|
-
if (!st) {
|
|
64
|
-
throw new Error("not a repo");
|
|
65
|
-
}
|
|
66
|
-
return Buffer.from(`${repoDir}:${st.currentBranch}`).toString("hex").slice(0, 40).padEnd(40, "0");
|
|
67
|
-
}
|
|
68
|
-
async listFiles(repoDir, pattern) {
|
|
69
|
-
const normRoot = path.normalize(repoDir);
|
|
70
|
-
const prefix = normRoot + path.sep;
|
|
71
|
-
const out = [];
|
|
72
|
-
for (const k of this.files.keys()) {
|
|
73
|
-
if (k !== normRoot && !k.startsWith(prefix)) {
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
const rel = k === normRoot ? "" : k.slice(prefix.length);
|
|
77
|
-
if (!rel) {
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
const relPosix = rel.split(path.sep).join("/");
|
|
81
|
-
if (pattern === "**/AGENTS.md") {
|
|
82
|
-
if (relPosix.endsWith("AGENTS.md")) {
|
|
83
|
-
out.push(relPosix);
|
|
84
|
-
}
|
|
85
|
-
} else if (pattern === "**/.cursor/skills/**/SKILL.md") {
|
|
86
|
-
if (/^\.cursor\/skills\/[^/]+\/SKILL\.md$/.test(relPosix)) {
|
|
87
|
-
out.push(relPosix);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return out.sort((a, b) => a.localeCompare(b));
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
export {
|
|
96
|
-
FakeGitOps
|
|
97
|
-
};
|
|
98
|
-
//# sourceMappingURL=chunk-7ZK5QRGP.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/fakes/fake-git-ops.ts"],"sourcesContent":["import path from \"node:path\";\n\nexport type RepoTemplate = Record<string, string>;\n\n/**\n * Structurally compatible with RunRootGitOps — call sites annotate\n * `const git: RunRootGitOps = new FakeGitOps(...)` so TS catches drift.\n */\nexport class FakeGitOps {\n\treadonly operations: string[] = [];\n\tprivate readonly files = new Map<string, string>();\n\tprivate readonly repoState = new Map<string, { currentBranch: string; branches: Set<string> }>();\n\n\tconstructor(private readonly templates: Map<string, RepoTemplate>) {}\n\n\tprivate abs(repoDir: string, filePath: string): string {\n\t\treturn path.normalize(path.join(repoDir, filePath));\n\t}\n\n\tasync writeFile(repoDir: string, filePath: string, content: string): Promise<void> {\n\t\tthis.operations.push(`writeFile:${filePath}`);\n\t\tthis.files.set(this.abs(repoDir, filePath), content);\n\t}\n\n\tasync readFile(repoDir: string, filePath: string): Promise<string | null> {\n\t\treturn this.files.get(this.abs(repoDir, filePath)) ?? null;\n\t}\n\n\tasync clone(repoLocator: string, targetDir: string): Promise<void> {\n\t\tthis.operations.push(`clone:${path.basename(targetDir)}`);\n\t\tconst n = path.normalize(targetDir);\n\t\tconst prefix = n + path.sep;\n\t\tfor (const k of [...this.files.keys()]) {\n\t\t\tif (k === n || k.startsWith(prefix)) {\n\t\t\t\tthis.files.delete(k);\n\t\t\t}\n\t\t}\n\t\tconst tmpl = this.templates.get(repoLocator);\n\t\tif (!tmpl) {\n\t\t\tthrow new Error(`unknown repo ${repoLocator}`);\n\t\t}\n\t\tfor (const [rel, content] of Object.entries(tmpl)) {\n\t\t\tthis.files.set(path.join(targetDir, rel), content);\n\t\t}\n\t\tthis.repoState.set(n, {\n\t\t\tcurrentBranch: \"main\",\n\t\t\tbranches: new Set([\"main\"]),\n\t\t});\n\t}\n\n\tasync checkout(repoDir: string, branch: string): Promise<void> {\n\t\tconst st = this.repoState.get(path.normalize(repoDir));\n\t\tif (!st) {\n\t\t\tthrow new Error(\"not a repo\");\n\t\t}\n\t\tst.branches.add(branch);\n\t\tst.currentBranch = branch;\n\t}\n\n\tasync createBranch(repoDir: string, branchName: string, _startPoint: string): Promise<void> {\n\t\tconst st = this.repoState.get(path.normalize(repoDir));\n\t\tif (!st) {\n\t\t\tthrow new Error(\"not a repo\");\n\t\t}\n\t\tst.branches.add(branchName);\n\t}\n\n\tasync branchExists(repoDir: string, branchName: string): Promise<boolean> {\n\t\tconst st = this.repoState.get(path.normalize(repoDir));\n\t\treturn st?.branches.has(branchName) ?? false;\n\t}\n\n\tasync getHeadSha(repoDir: string): Promise<string> {\n\t\tconst st = this.repoState.get(path.normalize(repoDir));\n\t\tif (!st) {\n\t\t\tthrow new Error(\"not a repo\");\n\t\t}\n\t\treturn Buffer.from(`${repoDir}:${st.currentBranch}`)\n\t\t\t.toString(\"hex\")\n\t\t\t.slice(0, 40)\n\t\t\t.padEnd(40, \"0\");\n\t}\n\n\tasync listFiles(repoDir: string, pattern: string): Promise<string[]> {\n\t\tconst normRoot = path.normalize(repoDir);\n\t\tconst prefix = normRoot + path.sep;\n\t\tconst out: string[] = [];\n\t\tfor (const k of this.files.keys()) {\n\t\t\tif (k !== normRoot && !k.startsWith(prefix)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst rel = k === normRoot ? \"\" : k.slice(prefix.length);\n\t\t\tif (!rel) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst relPosix = rel.split(path.sep).join(\"/\");\n\t\t\tif (pattern === \"**/AGENTS.md\") {\n\t\t\t\tif (relPosix.endsWith(\"AGENTS.md\")) {\n\t\t\t\t\tout.push(relPosix);\n\t\t\t\t}\n\t\t\t} else if (pattern === \"**/.cursor/skills/**/SKILL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;AAC/B,UAAM,MAAgB,CAAC;AACvB,eAAW,KAAK,KAAK,MAAM,KAAK,GAAG;AAClC,UAAI,MAAM,YAAY,CAAC,EAAE,WAAW,MAAM,GAAG;AAC5C;AAAA,MACD;AACA,YAAM,MAAM,MAAM,WAAW,KAAK,EAAE,MAAM,OAAO,MAAM;AACvD,UAAI,CAAC,KAAK;AACT;AAAA,MACD;AACA,YAAM,WAAW,IAAI,MAAM,KAAK,GAAG,EAAE,KAAK,GAAG;AAC7C,UAAI,YAAY,gBAAgB;AAC/B,YAAI,SAAS,SAAS,WAAW,GAAG;AACnC,cAAI,KAAK,QAAQ;AAAA,QAClB;AAAA,MACD,WAAW,YAAY,iCAAiC;AACvD,YAAI,uCAAuC,KAAK,QAAQ,GAAG;AAC1D,cAAI,KAAK,QAAQ;AAAA,QAClB;AAAA,MACD;AAAA,IACD;AACA,WAAO,IAAI,KAAK,CAAC,GAAG,MAAM,EAAE,cAAc,CAAC,CAAC;AAAA,EAC7C;AACD;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/fakes/fake-llm.ts"],"sourcesContent":["export interface LlmResponse {\n\tcontent: string;\n\ttoolCalls?: Array<{\n\t\tname: string;\n\t\targuments: Record<string, unknown>;\n\t}>;\n}\n\nexport type LlmHandler = (prompt: string) => LlmResponse;\n\n/**\n * Deterministic in-memory LLM fake for automated system tests.\n * Responds with scripted outputs based on registered handlers.\n */\nexport class FakeLlmProvider {\n\tprivate handlers: LlmHandler[] = [];\n\tprivate callIndex = 0;\n\treadonly calls: string[] = [];\n\n\tonPrompt(handler: LlmHandler): void {\n\t\tthis.handlers.push(handler);\n\t}\n\n\trespond(prompt: string): LlmResponse {\n\t\tthis.calls.push(prompt);\n\t\tconst handler = this.handlers[this.callIndex % this.handlers.length];\n\t\tif (handler) {\n\t\t\tthis.callIndex++;\n\t\t\treturn handler(prompt);\n\t\t}\n\t\treturn { content: \"No handler registered for this prompt.\" };\n\t}\n\n\treset(): void {\n\t\tthis.handlers = [];\n\t\tthis.callIndex = 0;\n\t\tthis.calls.length = 0;\n\t}\n}\n"],"mappings":";AAcO,IAAM,kBAAN,MAAsB;AAAA,EACpB,WAAyB,CAAC;AAAA,EAC1B,YAAY;AAAA,EACX,QAAkB,CAAC;AAAA,EAE5B,SAAS,SAA2B;AACnC,SAAK,SAAS,KAAK,OAAO;AAAA,EAC3B;AAAA,EAEA,QAAQ,QAA6B;AACpC,SAAK,MAAM,KAAK,MAAM;AACtB,UAAM,UAAU,KAAK,SAAS,KAAK,YAAY,KAAK,SAAS,MAAM;AACnE,QAAI,SAAS;AACZ,WAAK;AACL,aAAO,QAAQ,MAAM;AAAA,IACtB;AACA,WAAO,EAAE,SAAS,yCAAyC;AAAA,EAC5D;AAAA,EAEA,QAAc;AACb,SAAK,WAAW,CAAC;AACjB,SAAK,YAAY;AACjB,SAAK,MAAM,SAAS;AAAA,EACrB;AACD;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/integration-harness.ts","../src/polling.ts","../src/server-extension-test-harness.ts","../src/test-app.ts"],"sourcesContent":["import type { ExtensionCatalog } from \"@leitwerk-dev/extension-runtime\";\nimport type { ProvidedCapability } from \"@leitwerk-dev/process-sdk\";\nimport {\n\ttype AppContext,\n\ttype AppOptions,\n\tcreateAppContext,\n\tgetDefaultConfig,\n\ttype LeitwerkConfig,\n} from \"@leitwerk-dev/server\";\nimport { createInProcessWorkerSpawn } from \"./in-process-worker.js\";\n\nexport interface IntegrationHarness<\n\tTResources extends Record<string, unknown> = Record<string, never>,\n> {\n\tctx: AppContext;\n\tconfig: LeitwerkConfig;\n\taddress: string;\n\tresources: TResources;\n}\n\nexport interface IntegrationHarnessOptions<\n\tTResources extends Record<string, unknown> = Record<string, never>,\n> {\n\tconfig?: LeitwerkConfig;\n\tconfigOverride?: (config: LeitwerkConfig) => void;\n\tappOverrides?: Partial<AppOptions>;\n\tlisten?: boolean;\n\tinProcessWorkers?: boolean;\n\textensionCatalog: ExtensionCatalog | Promise<ExtensionCatalog>;\n\tpreProvidedCapabilities?: readonly ProvidedCapability[];\n\tresources?: TResources;\n}\n\nexport async function createIntegrationHarness<\n\tTResources extends Record<string, unknown> = Record<string, never>,\n>(opts: IntegrationHarnessOptions<TResources>): Promise<IntegrationHarness<TResources>> {\n\tconst config = opts.config ?? getDefaultConfig();\n\tif (!opts.appOverrides?.workerRunnerRuntime) {\n\t\tconfig.workers.runner = \"local\";\n\t}\n\topts.configOverride?.(config);\n\n\tconst extensionCatalog = await Promise.resolve(opts.extensionCatalog);\n\n\tconst appOpts: AppOptions = {\n\t\tlogger: false,\n\t\tconfig,\n\t\textensionCatalog,\n\t\tpreProvidedCapabilities: opts.preProvidedCapabilities,\n\t\t...opts.appOverrides,\n\t};\n\n\tif (opts.inProcessWorkers !== false && !appOpts.localWorkerSpawnImpl) {\n\t\tappOpts.localWorkerSpawnImpl = createInProcessWorkerSpawn({\n\t\t\textensionCatalog,\n\t\t});\n\t}\n\tconst ctx = await createAppContext(appOpts);\n\n\tlet address = \"\";\n\tif (opts.listen !== false || config.workers.runner === \"local\") {\n\t\tawait ctx.app.listen({ host: \"127.0.0.1\", port: 0 });\n\t\tconst info = ctx.app.server.address();\n\t\tconst port = typeof info === \"object\" && info ? info.port : 0;\n\t\taddress = `http://127.0.0.1:${port}`;\n\t\tctx.config.server.base_url = address;\n\t}\n\n\treturn {\n\t\tctx,\n\t\tconfig,\n\t\taddress,\n\t\tresources: opts.resources ?? ({} as TResources),\n\t};\n}\n","export async function waitForValue<T>(\n\tread: () => T | Promise<T>,\n\tpredicate: (value: T) => boolean,\n\ttimeoutMs = 5_000,\n): Promise<T> {\n\tconst deadline = Date.now() + timeoutMs;\n\twhile (true) {\n\t\tconst value = await read();\n\t\tif (predicate(value)) {\n\t\t\treturn value;\n\t\t}\n\t\tif (Date.now() >= deadline) {\n\t\t\tthrow new Error(\"Timed out waiting for value\");\n\t\t}\n\t\tawait new Promise((resolve) => setTimeout(resolve, 25));\n\t}\n}\n","import { type ExtensionCatalog, setupServerExtensions } from \"@leitwerk-dev/extension-runtime\";\nimport { buildExtensionCatalogFromModules } from \"@leitwerk-dev/extension-runtime/testing\";\nimport {\n\ttype CoreServerSetupDeps,\n\tcoreHostCapabilities,\n\tcreateCapabilityAccessor,\n\tcreateEventBus,\n\ttype IntegrationToolDefinition,\n\ttype LeitwerkExtensionModule,\n\ttype ProvidedCapability,\n\ttype ServerExtensionAPI,\n\ttype ServerExtensionEventMap,\n} from \"@leitwerk-dev/process-sdk\";\nimport { flushAsyncWork } from \"@leitwerk-dev/worker-protocol\";\n\nexport { flushAsyncWork };\n\n/** Register a test provider and expose its poll result without erasing its type. */\nexport function createPollingTestExtension<T>(\n\tmanifest: LeitwerkExtensionModule[\"manifest\"],\n\tsetup: (api: ServerExtensionAPI) => { poll(): Promise<T> } | undefined,\n) {\n\tlet provider: ReturnType<typeof setup>;\n\treturn {\n\t\tmanifest,\n\t\tsetupServer(api: ServerExtensionAPI) {\n\t\t\tprovider = setup(api);\n\t\t},\n\t\tpoll() {\n\t\t\tif (!provider) throw new Error(`Test provider '${manifest.id}' has not been initialized`);\n\t\t\treturn provider.poll();\n\t\t},\n\t};\n}\n\nexport function createToolCollector() {\n\tconst tools = new Map<string, IntegrationToolDefinition>();\n\tconst api = {\n\t\ttool: (tool: IntegrationToolDefinition) => tools.set(tool.name, tool),\n\t} as unknown as ServerExtensionAPI;\n\treturn { api, tools };\n}\n\nexport interface InMemoryExternalWriteLog {\n\trecords: { dedupKey: string }[];\n\thasDedupKey(key: string): boolean;\n\trecord(input: { dedupKey: string }): { dedupKey: string };\n\tgetDedupKeys(): ReadonlySet<string>;\n}\n\nexport function createInMemoryExternalWriteLog(): InMemoryExternalWriteLog {\n\tconst dedupKeys = new Set<string>();\n\tconst records: { dedupKey: string }[] = [];\n\treturn {\n\t\trecords,\n\t\thasDedupKey(key: string) {\n\t\t\treturn dedupKeys.has(key);\n\t\t},\n\t\trecord(input: { dedupKey: string }) {\n\t\t\tdedupKeys.add(input.dedupKey);\n\t\t\trecords.push(input);\n\t\t\treturn input;\n\t\t},\n\t\tgetDedupKeys() {\n\t\t\treturn dedupKeys;\n\t\t},\n\t};\n}\n\nfunction createDefaultServerSetupDeps(): CoreServerSetupDeps {\n\treturn {\n\t\tserverBaseUrl: \"https://leitwerk.example\",\n\t\tcomponents: {},\n\t\texternalWrites: createInMemoryExternalWriteLog(),\n\t\tpolling: {\n\t\t\tcreate(options) {\n\t\t\t\treturn { poll: options.pollOnce };\n\t\t\t},\n\t\t},\n\t\trepositoryCredentials: { register: () => {} },\n\t\tprocesses: {\n\t\t\tcreate: () => {\n\t\t\t\tthrow new Error(\"not used\");\n\t\t\t},\n\t\t\tgetById: () => null,\n\t\t\tlistAll: () => [],\n\t\t\tupdate: () => null,\n\t\t},\n\t\tprojects: {\n\t\t\tcreate: () => {\n\t\t\t\tthrow new Error(\"not used\");\n\t\t\t},\n\t\t\tgetByInstanceAndKey: () => null,\n\t\t\tupdate: () => null,\n\t\t\tlistByInstance: () => [],\n\t\t},\n\t\tevents: { create: () => {}, listByInstance: () => [] },\n\t\tbroadcaster: { sendDurable: () => {} },\n\t\tcommands: {\n\t\t\tgetDeferredProcessActivationSnapshots: () => ({ outcome: \"process_not_found\" }),\n\t\t\tactivateDeferredProcess: async () => ({\n\t\t\t\tok: true,\n\t\t\t\tprocess: null,\n\t\t\t\tdata: { outcome: \"not_applicable\" },\n\t\t\t}),\n\t\t\tparkDeferredProcessActivationFailure: async () => ({\n\t\t\t\tok: true,\n\t\t\t\tprocess: null,\n\t\t\t\tdata: { outcome: \"parked\" },\n\t\t\t}),\n\t\t\tstartProcess: async () => ({ ok: true, process: null }),\n\t\t\tabortProcess: async () => ({ ok: true, process: null }),\n\t\t\tretryProcess: async () => ({ ok: true, process: null }),\n\t\t\tcontinueFailedTurn: async () => ({ ok: true, process: null }),\n\t\t\tqueueInputs: async () => ({ ok: true, process: null }),\n\t\t},\n\t\tprocessActions: {\n\t\t\tlistVisibleActions: () => [],\n\t\t\texecuteAction: async () => ({ ok: true, process: null }),\n\t\t},\n\t\texternalSources: {\n\t\t\tlistArmed: () => [],\n\t\t\tfire: async () => ({ ok: true, process: null }),\n\t\t},\n\t\tgetSupervisor: () => undefined,\n\t\tlauncherService: {\n\t\t\tlistUiLaunchers: () => [],\n\t\t\tresolveUiDefaults: async () => ({}),\n\t\t\tresolveUiOptions: async () => ({}),\n\t\t\tresolveUiRelaunchInput: async (_launcherId, previousInput) => ({ ...previousInput }),\n\t\t\tresolveUiLauncher: async () => ({ ok: false as const, errors: [] }),\n\t\t},\n\t\tlauncherRecentValues: {\n\t\t\tlist: () => ({}),\n\t\t\trecord: () => {},\n\t\t},\n\t\tlauncherModelConfigs: {\n\t\t\tgetSchema: async () => null,\n\t\t\tpreview: async () => null,\n\t\t},\n\t\tlaunchPlans: {\n\t\t\tasync prepare(launchPlan, opts) {\n\t\t\t\treturn {\n\t\t\t\t\tok: true as const,\n\t\t\t\t\tlaunchPlan,\n\t\t\t\t\tmodelConfig: opts?.modelConfig ?? {},\n\t\t\t\t\twarnings: [],\n\t\t\t\t};\n\t\t\t},\n\t\t},\n\t\tlaunchRuns: {\n\t\t\tasync startProgrammatic() {\n\t\t\t\tthrow new Error(\"not used\");\n\t\t\t},\n\t\t\tasync startWatcher() {\n\t\t\t\tthrow new Error(\"not used\");\n\t\t\t},\n\t\t},\n\t};\n}\n\nexport function createTestServerSetupCapability(\n\toverrides: Partial<CoreServerSetupDeps> = {},\n): CoreServerSetupDeps {\n\tconst defaults = createDefaultServerSetupDeps();\n\treturn {\n\t\t...defaults,\n\t\t...overrides,\n\t\tprocesses: { ...defaults.processes, ...overrides.processes },\n\t\tprojects: { ...defaults.projects, ...overrides.projects },\n\t\tevents: { ...defaults.events, ...overrides.events },\n\t\tbroadcaster: { ...defaults.broadcaster, ...overrides.broadcaster },\n\t\tcommands: { ...defaults.commands, ...overrides.commands },\n\t\tprocessActions: { ...defaults.processActions, ...overrides.processActions },\n\t\texternalSources: { ...defaults.externalSources, ...overrides.externalSources },\n\t\tlauncherService: { ...defaults.launcherService, ...overrides.launcherService },\n\t\tlauncherRecentValues: {\n\t\t\t...defaults.launcherRecentValues,\n\t\t\t...overrides.launcherRecentValues,\n\t\t},\n\t\tlauncherModelConfigs: {\n\t\t\t...defaults.launcherModelConfigs,\n\t\t\t...overrides.launcherModelConfigs,\n\t\t},\n\t\tlaunchPlans: { ...defaults.launchPlans, ...overrides.launchPlans },\n\t\tlaunchRuns: { ...defaults.launchRuns, ...overrides.launchRuns },\n\t};\n}\n\nexport interface ServerExtensionTestHarness {\n\tcatalog: ExtensionCatalog;\n\tevents: ReturnType<typeof createEventBus>;\n\tserverSetup: CoreServerSetupDeps;\n\tstartHooks: Array<() => void | Promise<void>>;\n\tstopHooks: Array<() => void | Promise<void>>;\n\tflushAsyncWork: typeof flushAsyncWork;\n}\n\nexport async function setupServerExtensionTest(input: {\n\tmodules: readonly LeitwerkExtensionModule[];\n\tprovidedCapabilities?: readonly ProvidedCapability[];\n\tserverSetup?: Partial<CoreServerSetupDeps>;\n\tonStart?: (handler: () => void | Promise<void>) => void;\n\tonStop?: (handler: () => void | Promise<void>) => void;\n}): Promise<ServerExtensionTestHarness> {\n\tconst catalog = await buildExtensionCatalogFromModules(input.modules);\n\tconst events = createEventBus<ServerExtensionEventMap>();\n\tconst serverSetup = createTestServerSetupCapability(input.serverSetup);\n\tconst capabilities = createCapabilityAccessor([\n\t\t{\n\t\t\ttoken: coreHostCapabilities.serverSetup,\n\t\t\tvalue: serverSetup,\n\t\t},\n\t\t...(input.providedCapabilities ?? []),\n\t]);\n\tconst startHooks: Array<() => void | Promise<void>> = [];\n\tconst stopHooks: Array<() => void | Promise<void>> = [];\n\n\tawait setupServerExtensions(catalog, {\n\t\tevents,\n\t\tprovide: capabilities.provide.bind(capabilities),\n\t\tget: capabilities.get.bind(capabilities),\n\t\trequire: capabilities.require.bind(capabilities),\n\t\ttool() {},\n\t\tonStart(handler) {\n\t\t\tstartHooks.push(handler);\n\t\t\tinput.onStart?.(handler);\n\t\t},\n\t\tonStop(handler) {\n\t\t\tstopHooks.push(handler);\n\t\t\tinput.onStop?.(handler);\n\t\t},\n\t});\n\n\treturn {\n\t\tcatalog,\n\t\tevents,\n\t\tserverSetup,\n\t\tstartHooks,\n\t\tstopHooks,\n\t\tflushAsyncWork,\n\t};\n}\n","import type { ExtensionCatalog } from \"@leitwerk-dev/extension-runtime\";\nimport type { ProvidedCapability } from \"@leitwerk-dev/process-sdk\";\nimport {\n\ttype AppContext,\n\tcreateAppContext,\n\tgetDefaultConfig,\n\ttype LeitwerkConfig,\n} from \"@leitwerk-dev/server\";\nimport type { FastifyInstance } from \"fastify\";\nimport { FakeLlmProvider } from \"./fakes/fake-llm.js\";\nimport { createInProcessWorkerSpawn } from \"./in-process-worker.js\";\n\nexport interface TestAppBase {\n\tserver: FastifyInstance;\n\tctx: AppContext;\n\taddress: string;\n\tllm: FakeLlmProvider;\n\tclose: () => Promise<void>;\n}\n\nexport type TestApp<TResources extends Record<string, unknown> = Record<string, never>> =\n\tTestAppBase & TResources;\n\nexport interface TestAppOptions<\n\tTResources extends Record<string, unknown> = Record<string, never>,\n> {\n\textensionCatalog: ExtensionCatalog | Promise<ExtensionCatalog>;\n\tpreProvidedCapabilities?: readonly ProvidedCapability[];\n\tresources?: TResources;\n\tlisten?: boolean;\n\tinProcessWorkers?: boolean;\n\tconfigureConfig?: (config: LeitwerkConfig) => void;\n}\n\nexport async function createTestApp<\n\tTResources extends Record<string, unknown> = Record<string, never>,\n>(opts: TestAppOptions<TResources>): Promise<TestApp<TResources>> {\n\tconst llm = new FakeLlmProvider();\n\tconst config = getDefaultConfig();\n\tconfig.workers.runner = \"local\";\n\tconfig.workers.shutdown_grace_period = \"100ms\";\n\topts.configureConfig?.(config);\n\n\tconst ctx = await createAppContext({\n\t\tlogger: false,\n\t\tconfig,\n\t\t// Default to in-process stub workers so integration tests do not boot the\n\t\t// real Pi runtime or touch a developer's ambient Pi setup.\n\t\textensionCatalog: opts.extensionCatalog,\n\t\tpreProvidedCapabilities: opts.preProvidedCapabilities,\n\t\t...(opts.inProcessWorkers !== false\n\t\t\t? {\n\t\t\t\t\tlocalWorkerSpawnImpl: createInProcessWorkerSpawn({\n\t\t\t\t\t\textensionCatalog: opts.extensionCatalog,\n\t\t\t\t\t}),\n\t\t\t\t}\n\t\t\t: {}),\n\t});\n\n\tlet address = \"\";\n\tif (opts.listen !== false || config.workers.runner === \"local\") {\n\t\tawait ctx.app.listen({ host: \"127.0.0.1\", port: 0 });\n\t\tconst addressInfo = ctx.app.server.address();\n\t\tconst port = typeof addressInfo === \"object\" && addressInfo ? addressInfo.port : 0;\n\t\taddress = `http://127.0.0.1:${port}`;\n\t\tctx.config.server.base_url = address;\n\t}\n\n\treturn {\n\t\tserver: ctx.app,\n\t\tctx,\n\t\taddress,\n\t\tllm,\n\t\t...(opts.resources ?? ({} as TResources)),\n\t\tclose: async () => {\n\t\t\tawait ctx.supervisor.shutdownAll(\"test_app_close\");\n\t\t\tctx.app.server.closeIdleConnections?.();\n\t\t\tctx.app.server.closeAllConnections?.();\n\t\t\tawait ctx.app.close();\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;AAEA;AAAA,EAGC;AAAA,EACA;AAAA,OAEM;AAyBP,eAAsB,yBAEpB,MAAsF;AACvF,QAAM,SAAS,KAAK,UAAU,iBAAiB;AAC/C,MAAI,CAAC,KAAK,cAAc,qBAAqB;AAC5C,WAAO,QAAQ,SAAS;AAAA,EACzB;AACA,OAAK,iBAAiB,MAAM;AAE5B,QAAM,mBAAmB,MAAM,QAAQ,QAAQ,KAAK,gBAAgB;AAEpE,QAAM,UAAsB;AAAA,IAC3B,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA,yBAAyB,KAAK;AAAA,IAC9B,GAAG,KAAK;AAAA,EACT;AAEA,MAAI,KAAK,qBAAqB,SAAS,CAAC,QAAQ,sBAAsB;AACrE,Y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,IACvB,yBAAyB,KAAK;AAAA,IAC9B,GAAI,KAAK,qBAAqB,QAC3B;AAAA,MACA,sBAAsB,2BAA2B;AAAA,QAChD,kBAAkB,KAAK;AAAA,MACxB,CAAC;AAAA,IACF,IACC,CAAC;AAAA,EACL,CAAC;AAED,MAAI,UAAU;AACd,MAAI,KAAK,WAAW,SAAS,OAAO,QAAQ,WAAW,SAAS;AAC/D,UAAM,IAAI,IAAI,OAAO,EAAE,MAAM,aAAa,MAAM,EAAE,CAAC;AACnD,UAAM,cAAc,IAAI,IAAI,OAAO,QAAQ;AAC3C,UAAM,OAAO,OAAO,gBAAgB,YAAY,cAAc,YAAY,OAAO;AACjF,cAAU,oBAAoB,IAAI;AAClC,QAAI,OAAO,OAAO,WAAW;AAAA,EAC9B;AAEA,SAAO;AAAA,IACN,QAAQ,IAAI;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAI,KAAK,aAAc,CAAC;AAAA,IACxB,OAAO,YAAY;AAClB,YAAM,IAAI,WAAW,YAAY,gBAAgB;AACjD,UAAI,IAAI,OAAO,uBAAuB;AACtC,UAAI,IAAI,OAAO,sBAAsB;AACrC,YAAM,IAAI,IAAI,MAAM;AAAA,IACrB;AAAA,EACD;AACD;","names":["createAppContext","getDefaultConfig","getDefaultConfig","createAppContext"]}
|
package/dist/chunk-MV4W6NOO.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
// src/compact-process-detail-fixture.ts
|
|
2
|
-
import {
|
|
3
|
-
createReadonlyEntryTree
|
|
4
|
-
} from "@leitwerk-dev/protocol";
|
|
5
|
-
import {
|
|
6
|
-
buildProcessUiSnapshotProjections,
|
|
7
|
-
buildTurnTraceIndexFromSession
|
|
8
|
-
} from "@leitwerk-dev/server/testing";
|
|
9
|
-
var EMPTY_TRACE = {
|
|
10
|
-
assistant: { text: "", thinking: "", lastUpdatedAt: null },
|
|
11
|
-
toolCalls: [],
|
|
12
|
-
traceItems: [],
|
|
13
|
-
usage: null,
|
|
14
|
-
piInput: null
|
|
15
|
-
};
|
|
16
|
-
function createCompactProcessDetailFixtureFactory() {
|
|
17
|
-
const reasoningSourceByInstanceId = /* @__PURE__ */ new Map();
|
|
18
|
-
function compact(input) {
|
|
19
|
-
const legacy = input;
|
|
20
|
-
if (!Array.isArray(legacy.turnRecords)) {
|
|
21
|
-
return input;
|
|
22
|
-
}
|
|
23
|
-
const sessionEntries = legacy.piSessionEntries ?? [];
|
|
24
|
-
const entryTree = createReadonlyEntryTree(sessionEntries);
|
|
25
|
-
const sessionTree = {
|
|
26
|
-
...entryTree,
|
|
27
|
-
treeFile: "ui-compact-fixture",
|
|
28
|
-
header: null,
|
|
29
|
-
getTree: () => []
|
|
30
|
-
};
|
|
31
|
-
const traceIndex = buildTurnTraceIndexFromSession({
|
|
32
|
-
tree: sessionTree,
|
|
33
|
-
turnRecords: legacy.turnRecords,
|
|
34
|
-
events: legacy.events
|
|
35
|
-
});
|
|
36
|
-
const active = legacy.primaryPath.turnState.activeTurn;
|
|
37
|
-
if (active)
|
|
38
|
-
traceIndex[active.turnRecordId] = {
|
|
39
|
-
...EMPTY_TRACE,
|
|
40
|
-
...traceIndex[active.turnRecordId],
|
|
41
|
-
assistant: active.assistant,
|
|
42
|
-
traceItems: active.traceItems,
|
|
43
|
-
usage: active.usage,
|
|
44
|
-
toolCalls: active.toolCalls.map(({ result, ...tool }) => ({
|
|
45
|
-
...tool,
|
|
46
|
-
resultText: typeof result === "string" ? result : result == null ? null : JSON.stringify(result),
|
|
47
|
-
truncated: false
|
|
48
|
-
}))
|
|
49
|
-
};
|
|
50
|
-
const signature = sessionEntries.length > 0 ? `test-session:${JSON.stringify(sessionEntries).length}` : null;
|
|
51
|
-
const projections = buildProcessUiSnapshotProjections({
|
|
52
|
-
process: legacy.process,
|
|
53
|
-
turnRecords: legacy.turnRecords,
|
|
54
|
-
turnAnnotations: legacy.turnAnnotations,
|
|
55
|
-
events: legacy.events,
|
|
56
|
-
inputs: legacy.inputs,
|
|
57
|
-
selectedTurn: legacy.selectedTurn ?? null,
|
|
58
|
-
primaryPathSnapshot: legacy.primaryPath,
|
|
59
|
-
sessionTree
|
|
60
|
-
});
|
|
61
|
-
const compactDetail = {
|
|
62
|
-
...projections,
|
|
63
|
-
instanceTree: legacy.instanceTree ?? { currentLeafId: null, nodes: [], edges: [] },
|
|
64
|
-
leafOutcomeSnapshots: legacy.leafOutcomeSnapshots,
|
|
65
|
-
questionRequests: [],
|
|
66
|
-
toolApprovalRequests: [],
|
|
67
|
-
processDisplayName: legacy.processDisplayName,
|
|
68
|
-
processFlow: legacy.processFlow,
|
|
69
|
-
definesLeafOutcome: legacy.definesLeafOutcome,
|
|
70
|
-
selectedTurn: legacy.selectedTurn ?? null,
|
|
71
|
-
scheduledAction: legacy.scheduledAction ?? null,
|
|
72
|
-
modelConfiguration: legacy.modelConfiguration,
|
|
73
|
-
runDetails: legacy.runDetails,
|
|
74
|
-
launchConfiguration: legacy.launchConfiguration,
|
|
75
|
-
actions: legacy.actions,
|
|
76
|
-
toolRenderers: legacy.toolRenderers,
|
|
77
|
-
persistedModelSelectionWarning: null,
|
|
78
|
-
session: { signature },
|
|
79
|
-
sessionTransfer: null
|
|
80
|
-
};
|
|
81
|
-
reasoningSourceByInstanceId.set(projections.process.id, {
|
|
82
|
-
signature,
|
|
83
|
-
traceIndex,
|
|
84
|
-
liveTurnRecordId: active?.turnRecordId ?? null
|
|
85
|
-
});
|
|
86
|
-
return compactDetail;
|
|
87
|
-
}
|
|
88
|
-
function reasoningResponse(instanceId, turnRecordId) {
|
|
89
|
-
const source = reasoningSourceByInstanceId.get(instanceId);
|
|
90
|
-
return {
|
|
91
|
-
instanceId,
|
|
92
|
-
turnRecordId,
|
|
93
|
-
state: source?.liveTurnRecordId === turnRecordId ? "live" : "committed",
|
|
94
|
-
throughEventSequence: 0,
|
|
95
|
-
sessionSignature: source?.signature ?? null,
|
|
96
|
-
reasoning: source?.traceIndex[turnRecordId] ?? EMPTY_TRACE
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
return { compact, reasoningResponse };
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export {
|
|
103
|
-
createCompactProcessDetailFixtureFactory
|
|
104
|
-
};
|
|
105
|
-
//# sourceMappingURL=chunk-MV4W6NOO.js.map
|