@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
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { threadId } from "node:worker_threads";
|
|
3
|
+
|
|
4
|
+
const active = new AsyncLocalStorage<ReturnType<typeof createTestDiagnostics>>();
|
|
5
|
+
|
|
6
|
+
/** @internal Bounded, in-memory trace. Call report from onTestFailed; successful tests stay quiet. */
|
|
7
|
+
export function createTestDiagnostics(label: string) {
|
|
8
|
+
const started = performance.now();
|
|
9
|
+
const events: Record<string, unknown>[] = [];
|
|
10
|
+
let dropped = 0;
|
|
11
|
+
const mark = (stage: string, details: Record<string, unknown> = {}) => {
|
|
12
|
+
if (events.length === 512) {
|
|
13
|
+
events.shift();
|
|
14
|
+
dropped++;
|
|
15
|
+
}
|
|
16
|
+
events.push({
|
|
17
|
+
...details,
|
|
18
|
+
stage,
|
|
19
|
+
at: new Date().toISOString(),
|
|
20
|
+
elapsedMs: Math.round(performance.now() - started),
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
const diagnostics = {
|
|
24
|
+
/** @internal */
|
|
25
|
+
mark,
|
|
26
|
+
/** @internal */
|
|
27
|
+
run<T>(fn: () => T): T {
|
|
28
|
+
return active.run(diagnostics, fn);
|
|
29
|
+
},
|
|
30
|
+
/** @internal */
|
|
31
|
+
format() {
|
|
32
|
+
return JSON.stringify({ label, pid: process.pid, threadId, dropped, events }, null, 2);
|
|
33
|
+
},
|
|
34
|
+
/** @internal */
|
|
35
|
+
report() {
|
|
36
|
+
mark("diagnostics.report");
|
|
37
|
+
console.error(diagnostics.format());
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
mark("test.start");
|
|
41
|
+
return diagnostics;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** @internal Logs only the operation name and exit metadata, never arguments, output or environment. */
|
|
45
|
+
export function traceTestSubprocess<T>(operation: string, run: () => T): T {
|
|
46
|
+
const trace = active.getStore();
|
|
47
|
+
if (!trace) return run();
|
|
48
|
+
const started = performance.now();
|
|
49
|
+
trace.mark("subprocess.start", { operation });
|
|
50
|
+
try {
|
|
51
|
+
const result = run();
|
|
52
|
+
trace.mark("subprocess.exit", {
|
|
53
|
+
operation,
|
|
54
|
+
status: 0,
|
|
55
|
+
durationMs: Math.round(performance.now() - started),
|
|
56
|
+
});
|
|
57
|
+
return result;
|
|
58
|
+
} catch (error) {
|
|
59
|
+
const details = error as { status?: unknown; signal?: unknown; code?: unknown } | null;
|
|
60
|
+
trace.mark("subprocess.exit", {
|
|
61
|
+
operation,
|
|
62
|
+
durationMs: Math.round(performance.now() - started),
|
|
63
|
+
status: typeof details?.status === "number" ? details.status : null,
|
|
64
|
+
signal: typeof details?.signal === "string" ? details.signal : null,
|
|
65
|
+
code: typeof details?.code === "string" ? details.code : null,
|
|
66
|
+
});
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -15,18 +15,39 @@ const WebSocket =
|
|
|
15
15
|
(require("ws") as { default?: unknown }).default ??
|
|
16
16
|
require("ws");
|
|
17
17
|
|
|
18
|
+
/** @public */
|
|
18
19
|
export interface InProcessWorkerSpawnOptions {
|
|
20
|
+
/** @public */
|
|
19
21
|
extensionCatalog?: ExtensionCatalog | Promise<ExtensionCatalog>;
|
|
22
|
+
/** @public */
|
|
20
23
|
piFactory?: PiTreeHandleFactory;
|
|
24
|
+
/** @public */
|
|
21
25
|
toolCallScriptResolver?: StubToolCallScriptResolver;
|
|
22
|
-
/** Optional delays at real connection and managed-runtime preparation boundaries. */
|
|
23
|
-
startupDelays?: (instanceId: string) =>
|
|
26
|
+
/** Optional delays at real connection and managed-runtime preparation boundaries. @internal */
|
|
27
|
+
startupDelays?: (instanceId: string) =>
|
|
28
|
+
| {
|
|
29
|
+
/** @internal */
|
|
30
|
+
connectMs: number;
|
|
31
|
+
/** @internal */
|
|
32
|
+
prepareMs: number;
|
|
33
|
+
}
|
|
34
|
+
| undefined;
|
|
35
|
+
/** @internal Sanitized IPC observations, correlated even after fixture teardown. */
|
|
36
|
+
onConnectionDiagnostic?: (event: {
|
|
37
|
+
/** @internal */
|
|
38
|
+
instanceId: string;
|
|
39
|
+
/** @internal */
|
|
40
|
+
workerId: string;
|
|
41
|
+
/** @internal */
|
|
42
|
+
message: string;
|
|
43
|
+
}) => void;
|
|
24
44
|
}
|
|
25
45
|
|
|
26
46
|
/**
|
|
27
47
|
* Fast local-runner-shaped spawn fake. The worker receives the local runner's
|
|
28
48
|
* env and connects over WebSocket just like Docker/Kubernetes workers do.
|
|
29
49
|
*/
|
|
50
|
+
/** @public */
|
|
30
51
|
export function createInProcessWorkerSpawn(
|
|
31
52
|
options: InProcessWorkerSpawnOptions = {},
|
|
32
53
|
): typeof spawn {
|
|
@@ -82,6 +103,12 @@ export function createInProcessWorkerSpawn(
|
|
|
82
103
|
}
|
|
83
104
|
: piFactory,
|
|
84
105
|
stderr,
|
|
106
|
+
onConnectionDiagnostic: (message) =>
|
|
107
|
+
options.onConnectionDiagnostic?.({
|
|
108
|
+
instanceId: spawnOptions?.env?.LEITWERK_INSTANCE_ID ?? "",
|
|
109
|
+
workerId: spawnOptions?.env?.LEITWERK_WORKER_ID ?? "",
|
|
110
|
+
message,
|
|
111
|
+
}),
|
|
85
112
|
env: spawnOptions?.env ?? process.env,
|
|
86
113
|
exit: finish,
|
|
87
114
|
});
|
|
@@ -1,40 +1,14 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
flushAsyncWork,
|
|
5
|
-
} from "@leitwerk-dev/worker-protocol";
|
|
6
|
-
export {
|
|
7
|
-
createInProcessWorkerSpawn,
|
|
8
|
-
type InProcessWorkerSpawnOptions,
|
|
9
|
-
} from "../in-process-worker.js";
|
|
10
|
-
export {
|
|
11
|
-
createSchemaDrivenStubPiFactory,
|
|
12
|
-
createSchemaDrivenToolCallScriptResolver,
|
|
13
|
-
synthesizeStubArgValue,
|
|
14
|
-
synthesizeStubToolArgs,
|
|
15
|
-
} from "./schema-driven-stub-pi.js";
|
|
16
|
-
export {
|
|
17
|
-
createStubToolScriptController,
|
|
18
|
-
type StubToolScriptController,
|
|
19
|
-
} from "./stub-pi-controls.js";
|
|
1
|
+
export { flushAsyncWork } from "@leitwerk-dev/worker-protocol";
|
|
2
|
+
export { createInProcessWorkerSpawn } from "../in-process-worker.js";
|
|
3
|
+
export { createStubToolScriptController } from "./stub-pi-controls.js";
|
|
20
4
|
export {
|
|
21
5
|
StubPiTreeHandle,
|
|
22
6
|
StubPiTreeHandleFactory,
|
|
23
|
-
type StubPiTreeHandleFactoryOptions,
|
|
24
7
|
type StubToolCallScriptCall,
|
|
25
|
-
type StubToolCallScriptItem,
|
|
26
8
|
type StubToolCallScriptResolver,
|
|
27
|
-
type StubToolCallScriptResolverContext,
|
|
28
9
|
} from "./stub-pi-tree-handle.js";
|
|
29
10
|
export {
|
|
30
11
|
createManualWorkerRuntimeScheduler,
|
|
31
12
|
createWorkerRuntimeHarness,
|
|
32
|
-
type ManualWorkerRuntimeScheduler,
|
|
33
|
-
type WorkerRuntimeHarness,
|
|
34
|
-
type WorkerRuntimeHarnessOptions,
|
|
35
|
-
type WorkerRuntimeObservation,
|
|
36
13
|
} from "./worker-runtime-harness.js";
|
|
37
|
-
export {
|
|
38
|
-
createTestLlmWorkerStartPayload,
|
|
39
|
-
type TestLlmWorkerStartPayloadOptions,
|
|
40
|
-
} from "./worker-start-payload.js";
|
|
14
|
+
export { createTestLlmWorkerStartPayload } from "./worker-start-payload.js";
|
|
@@ -8,6 +8,7 @@ function isObjectLike(value: unknown): value is Record<string, unknown> {
|
|
|
8
8
|
return typeof value === "object" && value !== null;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
/** @internal */
|
|
11
12
|
export function synthesizeStubArgValue(key: string, spec: unknown): unknown {
|
|
12
13
|
if (key === "changedProjects") {
|
|
13
14
|
return undefined;
|
|
@@ -30,6 +31,7 @@ export function synthesizeStubArgValue(key: string, spec: unknown): unknown {
|
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
/** @internal */
|
|
33
35
|
export function synthesizeStubToolArgs(
|
|
34
36
|
parameters: Record<string, unknown>,
|
|
35
37
|
): Record<string, unknown> {
|
|
@@ -42,6 +44,7 @@ export function synthesizeStubToolArgs(
|
|
|
42
44
|
);
|
|
43
45
|
}
|
|
44
46
|
|
|
47
|
+
/** @internal */
|
|
45
48
|
export function createSchemaDrivenToolCallScriptResolver(): StubToolCallScriptResolver {
|
|
46
49
|
return ({ tools }: StubToolCallScriptResolverContext) => {
|
|
47
50
|
const markdownTool = tools.find((tool) => tool.name === "markdown_result");
|
|
@@ -73,8 +76,12 @@ export function createSchemaDrivenToolCallScriptResolver(): StubToolCallScriptRe
|
|
|
73
76
|
};
|
|
74
77
|
}
|
|
75
78
|
|
|
79
|
+
/** @internal */
|
|
76
80
|
export function createSchemaDrivenStubPiFactory(
|
|
77
|
-
options: {
|
|
81
|
+
options: {
|
|
82
|
+
/** @internal */
|
|
83
|
+
toolCallScriptResolver?: StubToolCallScriptResolver;
|
|
84
|
+
} = {},
|
|
78
85
|
): StubPiTreeHandleFactory {
|
|
79
86
|
return new StubPiTreeHandleFactory({
|
|
80
87
|
toolCallScriptResolver:
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type { StubToolCallScriptItem, StubToolCallScriptResolver } from "./stub-pi-tree-handle.js";
|
|
2
2
|
|
|
3
|
+
/** @internal */
|
|
3
4
|
export interface StubToolScriptController {
|
|
5
|
+
/** @internal */
|
|
4
6
|
readonly resolver: StubToolCallScriptResolver;
|
|
7
|
+
/** @internal */
|
|
5
8
|
set(script: StubToolCallScriptItem[]): void;
|
|
6
9
|
}
|
|
7
10
|
|
|
11
|
+
/** @internal */
|
|
8
12
|
export function createStubToolScriptController(): StubToolScriptController {
|
|
9
13
|
const queue: StubToolCallScriptItem[] = [];
|
|
10
14
|
return {
|
|
@@ -26,36 +26,54 @@ import type {
|
|
|
26
26
|
PiTreePlanningSnapshot,
|
|
27
27
|
} from "@leitwerk-dev/worker";
|
|
28
28
|
|
|
29
|
+
/** @public */
|
|
29
30
|
export interface StubToolCallScriptCall {
|
|
31
|
+
/** @public */
|
|
30
32
|
toolName: string;
|
|
33
|
+
/** @public */
|
|
31
34
|
args: Record<string, unknown>;
|
|
35
|
+
/** @internal */
|
|
32
36
|
intermediateEntryCount?: number;
|
|
33
37
|
}
|
|
34
38
|
|
|
39
|
+
/** @public */
|
|
35
40
|
export type StubToolCallScriptItem =
|
|
36
41
|
| StubToolCallScriptCall
|
|
37
42
|
| {
|
|
43
|
+
/** @public */
|
|
38
44
|
calls: readonly StubToolCallScriptCall[];
|
|
45
|
+
/** @public */
|
|
39
46
|
textChunks?: readonly string[];
|
|
47
|
+
/** @public */
|
|
40
48
|
thinkingChunks?: readonly string[];
|
|
49
|
+
/** @public */
|
|
41
50
|
chunkDelayMs?: number;
|
|
42
|
-
/** Optional scripted model reaction to a tool result, within the same turn. */
|
|
51
|
+
/** Optional scripted model reaction to a tool result, within the same turn. @internal */
|
|
43
52
|
afterToolResult?: (
|
|
44
53
|
call: StubToolCallScriptCall,
|
|
45
54
|
result: unknown,
|
|
46
55
|
) => StubToolCallScriptCall | undefined;
|
|
47
56
|
};
|
|
48
57
|
|
|
58
|
+
/** @public */
|
|
49
59
|
export interface StubToolCallScriptResolverContext {
|
|
60
|
+
/** @public */
|
|
50
61
|
promptText: string;
|
|
62
|
+
/** @public */
|
|
51
63
|
tools: readonly PiCustomTool[];
|
|
64
|
+
/** @public */
|
|
52
65
|
instanceId?: string;
|
|
66
|
+
/** @public */
|
|
53
67
|
workspaceRoot?: string;
|
|
68
|
+
/** @public */
|
|
54
69
|
sessionCwd?: string;
|
|
70
|
+
/** @public */
|
|
55
71
|
treeFile: string;
|
|
72
|
+
/** @internal */
|
|
56
73
|
turnSequence: number;
|
|
57
74
|
}
|
|
58
75
|
|
|
76
|
+
/** @public */
|
|
59
77
|
export type StubToolCallScriptResolver = (
|
|
60
78
|
context: StubToolCallScriptResolverContext,
|
|
61
79
|
) => StubToolCallScriptItem | undefined | Promise<StubToolCallScriptItem | undefined>;
|
|
@@ -88,11 +106,17 @@ function stubToolCallId(turnSeq: number, totalCalls: number, index: number): str
|
|
|
88
106
|
return `tool-${turnSeq}-${index + 1}`;
|
|
89
107
|
}
|
|
90
108
|
|
|
109
|
+
/** @internal */
|
|
91
110
|
interface StubPiTreeState {
|
|
111
|
+
/** @internal */
|
|
92
112
|
header?: SessionHeader;
|
|
113
|
+
/** @internal */
|
|
93
114
|
turnSeq: number;
|
|
115
|
+
/** @internal */
|
|
94
116
|
currentLeafId: string | null;
|
|
117
|
+
/** @internal */
|
|
95
118
|
entries: Map<string, PiTreeEntry>;
|
|
119
|
+
/** @internal */
|
|
96
120
|
childIdsByParent: Map<string | null, string[]>;
|
|
97
121
|
}
|
|
98
122
|
|
|
@@ -180,13 +204,20 @@ function deserializeStubPiTreeState(value: string): StubPiTreeState {
|
|
|
180
204
|
};
|
|
181
205
|
}
|
|
182
206
|
|
|
207
|
+
/** @public */
|
|
183
208
|
export class StubPiTreeHandle implements PiTreeHandle {
|
|
209
|
+
/** @public */
|
|
184
210
|
readonly sessionId: string;
|
|
211
|
+
/** @internal */
|
|
185
212
|
readonly treeFile: string;
|
|
213
|
+
/** @internal */
|
|
186
214
|
readonly isResumed: boolean;
|
|
187
215
|
|
|
216
|
+
/** @internal */
|
|
188
217
|
readonly prompts: string[] = [];
|
|
218
|
+
/** @internal */
|
|
189
219
|
readonly steers: string[] = [];
|
|
220
|
+
/** @internal */
|
|
190
221
|
beforeTurn?: (
|
|
191
222
|
kind: "prompt" | "literal" | "custom" | "continue",
|
|
192
223
|
options: PiPromptOptions | undefined,
|
|
@@ -204,14 +235,23 @@ export class StubPiTreeHandle implements PiTreeHandle {
|
|
|
204
235
|
private readonly persistState?: (() => Promise<void>) | undefined;
|
|
205
236
|
private readonly recordSessionTrace: boolean;
|
|
206
237
|
|
|
238
|
+
/** @internal */
|
|
207
239
|
constructor(options: {
|
|
240
|
+
/** @internal */
|
|
208
241
|
sessionId: string;
|
|
242
|
+
/** @internal */
|
|
209
243
|
treeFile: string;
|
|
244
|
+
/** @internal */
|
|
210
245
|
isResumed: boolean;
|
|
246
|
+
/** @internal */
|
|
211
247
|
toolCallScriptResolver?: StubToolCallScriptResolver;
|
|
248
|
+
/** @internal */
|
|
212
249
|
state?: StubPiTreeState;
|
|
250
|
+
/** @internal */
|
|
213
251
|
runDetails?: Partial<PiRunDetails>;
|
|
252
|
+
/** @internal */
|
|
214
253
|
persistState?: () => Promise<void>;
|
|
254
|
+
/** @internal */
|
|
215
255
|
recordSessionTrace?: boolean;
|
|
216
256
|
}) {
|
|
217
257
|
this.sessionId = options.sessionId;
|
|
@@ -228,10 +268,12 @@ export class StubPiTreeHandle implements PiTreeHandle {
|
|
|
228
268
|
};
|
|
229
269
|
}
|
|
230
270
|
|
|
271
|
+
/** @internal */
|
|
231
272
|
get closed(): boolean {
|
|
232
273
|
return this._closed;
|
|
233
274
|
}
|
|
234
275
|
|
|
276
|
+
/** @internal */
|
|
235
277
|
failNextTurnWithBranchDrift(): void {
|
|
236
278
|
this.branchDriftPending = true;
|
|
237
279
|
}
|
|
@@ -272,6 +314,7 @@ export class StubPiTreeHandle implements PiTreeHandle {
|
|
|
272
314
|
}
|
|
273
315
|
}
|
|
274
316
|
|
|
317
|
+
/** @internal */
|
|
275
318
|
getRunDetails(): PiRunDetails {
|
|
276
319
|
return {
|
|
277
320
|
loadedAgentsFiles: this.runDetails.loadedAgentsFiles.map((file) => ({ ...file })),
|
|
@@ -280,14 +323,17 @@ export class StubPiTreeHandle implements PiTreeHandle {
|
|
|
280
323
|
};
|
|
281
324
|
}
|
|
282
325
|
|
|
326
|
+
/** @internal */
|
|
283
327
|
getLeafId(): string | null {
|
|
284
328
|
return this.state.currentLeafId;
|
|
285
329
|
}
|
|
286
330
|
|
|
331
|
+
/** @internal */
|
|
287
332
|
getEntry(id: string): PiTreeEntry | undefined {
|
|
288
333
|
return this.state.entries.get(id);
|
|
289
334
|
}
|
|
290
335
|
|
|
336
|
+
/** @public */
|
|
291
337
|
getBranch(fromId: string | undefined = this.state.currentLeafId ?? undefined): PiTreeEntry[] {
|
|
292
338
|
if (!fromId) {
|
|
293
339
|
return [];
|
|
@@ -306,12 +352,14 @@ export class StubPiTreeHandle implements PiTreeHandle {
|
|
|
306
352
|
return branch;
|
|
307
353
|
}
|
|
308
354
|
|
|
355
|
+
/** @internal */
|
|
309
356
|
getChildren(parentId: string): PiTreeEntry[] {
|
|
310
357
|
return (this.state.childIdsByParent.get(parentId) ?? [])
|
|
311
358
|
.map((childId) => this.state.entries.get(childId))
|
|
312
359
|
.filter((entry): entry is PiTreeEntry => entry !== undefined);
|
|
313
360
|
}
|
|
314
361
|
|
|
362
|
+
/** @internal */
|
|
315
363
|
getTree(): PiTreeNode[] {
|
|
316
364
|
const buildNode = (entry: PiTreeEntry): PiTreeNode => ({
|
|
317
365
|
entry,
|
|
@@ -323,6 +371,7 @@ export class StubPiTreeHandle implements PiTreeHandle {
|
|
|
323
371
|
.map(buildNode);
|
|
324
372
|
}
|
|
325
373
|
|
|
374
|
+
/** @internal */
|
|
326
375
|
async branch(entryId: string): Promise<void> {
|
|
327
376
|
this.assertOpen();
|
|
328
377
|
if (!this.state.entries.has(entryId)) {
|
|
@@ -332,17 +381,26 @@ export class StubPiTreeHandle implements PiTreeHandle {
|
|
|
332
381
|
await this.persistState?.();
|
|
333
382
|
}
|
|
334
383
|
|
|
384
|
+
/** @internal */
|
|
335
385
|
async branchFromRoot(): Promise<void> {
|
|
336
386
|
this.assertOpen();
|
|
337
387
|
this.state.currentLeafId = null;
|
|
338
388
|
await this.persistState?.();
|
|
339
389
|
}
|
|
340
390
|
|
|
391
|
+
/** @internal */
|
|
341
392
|
async resetLeaf(): Promise<void> {
|
|
342
393
|
await this.branchFromRoot();
|
|
343
394
|
}
|
|
344
395
|
|
|
345
|
-
|
|
396
|
+
/** @internal */
|
|
397
|
+
async compact(
|
|
398
|
+
_customInstructions?: string,
|
|
399
|
+
details?: unknown,
|
|
400
|
+
): Promise<{
|
|
401
|
+
/** @internal */
|
|
402
|
+
summary: string;
|
|
403
|
+
}> {
|
|
346
404
|
this.assertOpen();
|
|
347
405
|
const timestamp = new Date().toISOString();
|
|
348
406
|
const compactionEntryId = `compaction-${++this.state.turnSeq}`;
|
|
@@ -645,6 +703,7 @@ export class StubPiTreeHandle implements PiTreeHandle {
|
|
|
645
703
|
};
|
|
646
704
|
}
|
|
647
705
|
|
|
706
|
+
/** @internal */
|
|
648
707
|
async prompt(text: string, options: PiPromptOptions = {}): Promise<PiTurnExecutionResult> {
|
|
649
708
|
return await this.executeTurn({
|
|
650
709
|
kind: "prompt",
|
|
@@ -654,6 +713,7 @@ export class StubPiTreeHandle implements PiTreeHandle {
|
|
|
654
713
|
});
|
|
655
714
|
}
|
|
656
715
|
|
|
716
|
+
/** @internal */
|
|
657
717
|
async promptLiteral(text: string, options: PiPromptOptions = {}): Promise<PiTurnExecutionResult> {
|
|
658
718
|
return await this.executeTurn({
|
|
659
719
|
kind: "literal",
|
|
@@ -663,6 +723,7 @@ export class StubPiTreeHandle implements PiTreeHandle {
|
|
|
663
723
|
});
|
|
664
724
|
}
|
|
665
725
|
|
|
726
|
+
/** @internal */
|
|
666
727
|
async promptCustom(
|
|
667
728
|
input: PiCustomMessageInput,
|
|
668
729
|
options: PiPromptOptions = {},
|
|
@@ -681,6 +742,7 @@ export class StubPiTreeHandle implements PiTreeHandle {
|
|
|
681
742
|
};
|
|
682
743
|
}
|
|
683
744
|
|
|
745
|
+
/** @internal */
|
|
684
746
|
async continueTurn(options: PiPromptOptions = {}): Promise<PiTurnExecutionResult> {
|
|
685
747
|
return await this.executeTurn({
|
|
686
748
|
kind: "continue",
|
|
@@ -689,6 +751,7 @@ export class StubPiTreeHandle implements PiTreeHandle {
|
|
|
689
751
|
});
|
|
690
752
|
}
|
|
691
753
|
|
|
754
|
+
/** @internal */
|
|
692
755
|
async appendUserMessage(text: string): Promise<string> {
|
|
693
756
|
this.assertOpen();
|
|
694
757
|
const timestamp = new Date().toISOString();
|
|
@@ -700,6 +763,7 @@ export class StubPiTreeHandle implements PiTreeHandle {
|
|
|
700
763
|
return userEntryId;
|
|
701
764
|
}
|
|
702
765
|
|
|
766
|
+
/** @internal */
|
|
703
767
|
async appendCustomMessage(input: PiCustomMessageInput): Promise<string> {
|
|
704
768
|
this.assertOpen();
|
|
705
769
|
const timestamp = new Date().toISOString();
|
|
@@ -717,16 +781,19 @@ export class StubPiTreeHandle implements PiTreeHandle {
|
|
|
717
781
|
return entryId;
|
|
718
782
|
}
|
|
719
783
|
|
|
784
|
+
/** @internal */
|
|
720
785
|
async steer(text: string): Promise<void> {
|
|
721
786
|
this.assertOpen();
|
|
722
787
|
this.steers.push(text);
|
|
723
788
|
}
|
|
724
789
|
|
|
790
|
+
/** @internal */
|
|
725
791
|
async abortTurn(): Promise<void> {
|
|
726
792
|
this.assertOpen();
|
|
727
793
|
this.turnAbort.abort(new Error("Scripted turn aborted"));
|
|
728
794
|
}
|
|
729
795
|
|
|
796
|
+
/** @internal */
|
|
730
797
|
subscribe(handler: PiEventHandler): () => void {
|
|
731
798
|
this.handlers.add(handler);
|
|
732
799
|
return () => {
|
|
@@ -734,6 +801,7 @@ export class StubPiTreeHandle implements PiTreeHandle {
|
|
|
734
801
|
};
|
|
735
802
|
}
|
|
736
803
|
|
|
804
|
+
/** @internal */
|
|
737
805
|
subscribeDiagnostics(handler: PiSessionDiagnosticHandler): () => void {
|
|
738
806
|
this.diagnosticHandlers.add(handler);
|
|
739
807
|
return () => {
|
|
@@ -741,10 +809,12 @@ export class StubPiTreeHandle implements PiTreeHandle {
|
|
|
741
809
|
};
|
|
742
810
|
}
|
|
743
811
|
|
|
812
|
+
/** @internal */
|
|
744
813
|
emitDiagnostic(diagnostic: PiSessionDiagnostic): void {
|
|
745
814
|
for (const handler of this.diagnosticHandlers) handler(diagnostic);
|
|
746
815
|
}
|
|
747
816
|
|
|
817
|
+
/** @internal */
|
|
748
818
|
async close(): Promise<void> {
|
|
749
819
|
this.turnAbort.abort(new Error("Scripted session closed"));
|
|
750
820
|
await this.persistState?.();
|
|
@@ -754,25 +824,32 @@ export class StubPiTreeHandle implements PiTreeHandle {
|
|
|
754
824
|
}
|
|
755
825
|
}
|
|
756
826
|
|
|
827
|
+
/** @public */
|
|
757
828
|
export interface StubPiTreeHandleFactoryOptions {
|
|
829
|
+
/** @public */
|
|
758
830
|
toolCallScriptResolver?: StubToolCallScriptResolver;
|
|
759
|
-
/** Persist SDK-readable JSONL with reasoning and tool messages for history/detail tests. */
|
|
831
|
+
/** Persist SDK-readable JSONL with reasoning and tool messages for history/detail tests. @public */
|
|
760
832
|
recordSessionTrace?: boolean;
|
|
761
833
|
}
|
|
762
834
|
|
|
835
|
+
/** @public */
|
|
763
836
|
export class StubPiTreeHandleFactory implements PiTreeHandleFactory {
|
|
837
|
+
/** @public */
|
|
764
838
|
readonly sessions: StubPiTreeHandle[] = [];
|
|
839
|
+
/** @internal */
|
|
765
840
|
toolCallScriptResolver?: StubToolCallScriptResolver;
|
|
766
841
|
|
|
767
842
|
private seq = 0;
|
|
768
843
|
private readonly treeStateByFile = new Map<string, StubPiTreeState>();
|
|
769
844
|
private readonly recordSessionTrace: boolean;
|
|
770
845
|
|
|
846
|
+
/** @public */
|
|
771
847
|
constructor(options: StubPiTreeHandleFactoryOptions = {}) {
|
|
772
848
|
this.toolCallScriptResolver = options.toolCallScriptResolver;
|
|
773
849
|
this.recordSessionTrace = options.recordSessionTrace ?? false;
|
|
774
850
|
}
|
|
775
851
|
|
|
852
|
+
/** @internal */
|
|
776
853
|
async prepareManagedBootstrap(
|
|
777
854
|
opts: PiManagedBootstrapOptions,
|
|
778
855
|
): Promise<PiManagedBootstrapResult> {
|
|
@@ -787,6 +864,7 @@ export class StubPiTreeHandleFactory implements PiTreeHandleFactory {
|
|
|
787
864
|
};
|
|
788
865
|
}
|
|
789
866
|
|
|
867
|
+
/** @internal */
|
|
790
868
|
async inspectPrimaryTree(opts: PiTreePlanningOptions): Promise<PiTreePlanningSnapshot> {
|
|
791
869
|
let treeState = this.treeStateByFile.get(opts.treeFile);
|
|
792
870
|
if (!treeState) {
|
|
@@ -808,6 +886,7 @@ export class StubPiTreeHandleFactory implements PiTreeHandleFactory {
|
|
|
808
886
|
};
|
|
809
887
|
}
|
|
810
888
|
|
|
889
|
+
/** @public */
|
|
811
890
|
async createPrimaryTreeHandle(opts: PiTreeHandleOptions): Promise<PiTreeHandle> {
|
|
812
891
|
const persistState = async (state: StubPiTreeState): Promise<void> => {
|
|
813
892
|
this.treeStateByFile.set(opts.treeFile, state);
|