@leitwerk-dev/test-support 0.1.9 → 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-KIDBCGNW.js → chunk-2PCDTYVH.js} +26 -26
- package/dist/chunk-2PCDTYVH.js.map +1 -0
- package/dist/chunk-5BZSJ4OO.js +192 -0
- package/dist/chunk-5BZSJ4OO.js.map +1 -0
- package/dist/{chunk-QFCJV2VA.js → chunk-ECAWLVYB.js} +224 -17
- 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 +111 -2
- package/dist/fakes/index.js.map +1 -1
- package/dist/fixtures.js +137 -2
- package/dist/fixtures.js.map +1 -1
- package/dist/http-launch.d.ts +9 -0
- package/dist/http-launch.d.ts.map +1 -0
- package/dist/index.d.ts +24 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +113 -12
- 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 +3 -3
- package/dist/integration.d.ts.map +1 -1
- package/dist/integration.js +184 -4
- package/dist/integration.js.map +1 -1
- package/dist/local-git.d.ts +231 -0
- package/dist/local-git.d.ts.map +1 -0
- package/dist/local-git.js +428 -0
- package/dist/local-git.js.map +1 -0
- package/dist/model-provider-fixtures.d.ts +15 -0
- package/dist/model-provider-fixtures.d.ts.map +1 -0
- package/dist/polling.d.ts +2 -1
- package/dist/polling.d.ts.map +1 -1
- package/dist/process-driver.d.ts +14 -0
- package/dist/process-driver.d.ts.map +1 -0
- 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 +57 -2
- package/dist/server-extension-test-harness.d.ts.map +1 -1
- package/dist/stub-worker-entry.js +9 -5
- package/dist/stub-worker-entry.js.map +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 +21 -0
- 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 +381 -7
- 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 +93 -1
- 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 +15 -9
- package/src/compact-process-detail-fixture.ts +37 -3
- 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 +88 -0
- package/src/index.ts +31 -41
- package/src/integration-harness.ts +100 -9
- package/src/integration.ts +3 -9
- package/src/local-git.ts +499 -0
- package/src/model-provider-fixtures.ts +36 -0
- package/src/polling.ts +3 -2
- package/src/process-driver.ts +63 -0
- package/src/question-fixtures.ts +2 -0
- package/src/server-extension-test-harness.ts +100 -6
- package/src/test-diagnostics.ts +69 -0
- package/src/worker-testing/in-process-worker-spawn.ts +49 -2
- package/src/worker-testing/index.ts +4 -26
- 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 +301 -21
- package/src/worker-testing/worker-runtime-harness.ts +57 -6
- package/src/worker-testing/worker-start-payload.ts +18 -1
- package/dist/chunk-3MQO3NCX.js +0 -15
- package/dist/chunk-3MQO3NCX.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-KIDBCGNW.js.map +0 -1
- package/dist/chunk-QFCJV2VA.js.map +0 -1
- package/dist/chunk-R4KVUGWR.js +0 -83
- package/dist/chunk-R4KVUGWR.js.map +0 -1
- package/dist/chunk-ST2C4VKX.js +0 -297
- package/dist/chunk-ST2C4VKX.js.map +0 -1
- package/dist/compact-process-detail-fixture.js +0 -73
- package/dist/compact-process-detail-fixture.js.map +0 -1
- package/dist/fakes/fake-git-ops.js +0 -101
- package/dist/fakes/fake-git-ops.js.map +0 -1
- package/dist/fakes/fake-llm.js +0 -27
- package/dist/fakes/fake-llm.js.map +0 -1
- package/dist/in-process-worker.js +0 -2
- package/dist/in-process-worker.js.map +0 -1
- package/dist/integration-harness.js +0 -38
- package/dist/integration-harness.js.map +0 -1
- package/dist/polling.js +0 -14
- package/dist/polling.js.map +0 -1
- package/dist/question-fixtures.js +0 -26
- package/dist/question-fixtures.js.map +0 -1
- package/dist/server-extension-test-harness.js +0 -169
- package/dist/server-extension-test-harness.js.map +0 -1
- package/dist/test-app.d.ts +0 -23
- package/dist/test-app.d.ts.map +0 -1
- package/dist/test-app.js +0 -47
- package/dist/test-app.js.map +0 -1
- package/dist/worker-testing/in-process-worker-spawn.js +0 -61
- package/dist/worker-testing/in-process-worker-spawn.js.map +0 -1
- package/dist/worker-testing/ipc-harness.d.ts +0 -11
- package/dist/worker-testing/ipc-harness.d.ts.map +0 -1
- package/dist/worker-testing/ipc-harness.js +0 -17
- package/dist/worker-testing/ipc-harness.js.map +0 -1
- package/dist/worker-testing/schema-driven-stub-pi.js +0 -65
- package/dist/worker-testing/schema-driven-stub-pi.js.map +0 -1
- package/dist/worker-testing/stub-pi-controls.js +0 -10
- package/dist/worker-testing/stub-pi-controls.js.map +0 -1
- package/dist/worker-testing/stub-pi-tree-handle.js +0 -515
- package/dist/worker-testing/stub-pi-tree-handle.js.map +0 -1
- package/dist/worker-testing/worker-runtime-harness.js +0 -231
- package/dist/worker-testing/worker-runtime-harness.js.map +0 -1
- package/dist/worker-testing/worker-start-payload.js +0 -101
- package/dist/worker-testing/worker-start-payload.js.map +0 -1
- package/dist/workspace-source-aliases.d.ts +0 -6
- package/dist/workspace-source-aliases.d.ts.map +0 -1
- package/dist/workspace-source-aliases.js +0 -126
- package/dist/workspace-source-aliases.js.map +0 -1
- package/src/test-app.ts +0 -82
- package/src/worker-testing/ipc-harness.ts +0 -19
- package/src/workspace-source-aliases.ts +0 -171
|
@@ -1,32 +1,107 @@
|
|
|
1
1
|
import { type ExtensionCatalog, setupServerExtensions } from "@leitwerk-dev/extension-runtime";
|
|
2
2
|
import { buildExtensionCatalogFromModules } from "@leitwerk-dev/extension-runtime/testing";
|
|
3
|
+
import {
|
|
4
|
+
bindExternalWrites,
|
|
5
|
+
type ExternalWriteLogRepoLike,
|
|
6
|
+
} from "@leitwerk-dev/external-writes/internal";
|
|
3
7
|
import {
|
|
4
8
|
type CoreServerSetupDeps,
|
|
5
9
|
coreHostCapabilities,
|
|
6
10
|
createCapabilityAccessor,
|
|
7
11
|
createEventBus,
|
|
12
|
+
type IntegrationToolDefinition,
|
|
8
13
|
type LeitwerkExtensionModule,
|
|
9
14
|
type ProvidedCapability,
|
|
15
|
+
type ServerExtensionAPI,
|
|
10
16
|
type ServerExtensionEventMap,
|
|
11
17
|
} from "@leitwerk-dev/process-sdk";
|
|
12
|
-
import { flushAsyncWork } from "
|
|
18
|
+
import { flushAsyncWork } from "@leitwerk-dev/worker-protocol";
|
|
13
19
|
|
|
14
20
|
export { flushAsyncWork };
|
|
15
21
|
|
|
22
|
+
/** Register a test provider and expose its poll result without erasing its type. @public */
|
|
23
|
+
export function createPollingTestExtension<T>(
|
|
24
|
+
manifest: LeitwerkExtensionModule["manifest"],
|
|
25
|
+
setup: (api: ServerExtensionAPI) =>
|
|
26
|
+
| {
|
|
27
|
+
/** @internal */
|
|
28
|
+
poll(): Promise<T>;
|
|
29
|
+
}
|
|
30
|
+
| undefined,
|
|
31
|
+
) {
|
|
32
|
+
let provider: ReturnType<typeof setup>;
|
|
33
|
+
return {
|
|
34
|
+
/** @internal */
|
|
35
|
+
manifest,
|
|
36
|
+
/** @internal */
|
|
37
|
+
setupServer(api: ServerExtensionAPI) {
|
|
38
|
+
provider = setup(api);
|
|
39
|
+
},
|
|
40
|
+
/** @public */
|
|
41
|
+
poll() {
|
|
42
|
+
if (!provider) throw new Error(`Test provider '${manifest.id}' has not been initialized`);
|
|
43
|
+
return provider.poll();
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** @internal */
|
|
49
|
+
export function createToolCollector(
|
|
50
|
+
writes: ExternalWriteLogRepoLike = createInMemoryExternalWriteLog(),
|
|
51
|
+
) {
|
|
52
|
+
const tools = new Map<string, IntegrationToolDefinition>();
|
|
53
|
+
const api = {
|
|
54
|
+
tool: (tool: IntegrationToolDefinition) =>
|
|
55
|
+
tools.set(tool.name, {
|
|
56
|
+
...tool,
|
|
57
|
+
execute: (ctx, args) =>
|
|
58
|
+
tool.execute(
|
|
59
|
+
{ ...ctx, externalWrites: bindExternalWrites(writes, ctx.process.id) },
|
|
60
|
+
args,
|
|
61
|
+
),
|
|
62
|
+
}),
|
|
63
|
+
} as unknown as ServerExtensionAPI;
|
|
64
|
+
return {
|
|
65
|
+
/** @internal */
|
|
66
|
+
api,
|
|
67
|
+
/** @internal */
|
|
68
|
+
tools,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** @internal */
|
|
16
73
|
export interface InMemoryExternalWriteLog {
|
|
74
|
+
/** @internal */
|
|
75
|
+
records: {
|
|
76
|
+
/** @internal */
|
|
77
|
+
dedupKey: string;
|
|
78
|
+
}[];
|
|
79
|
+
/** @internal */
|
|
17
80
|
hasDedupKey(key: string): boolean;
|
|
18
|
-
|
|
81
|
+
/** @internal */
|
|
82
|
+
record(input: {
|
|
83
|
+
/** @internal */
|
|
84
|
+
dedupKey: string;
|
|
85
|
+
}): {
|
|
86
|
+
/** @internal */
|
|
87
|
+
dedupKey: string;
|
|
88
|
+
};
|
|
89
|
+
/** @internal */
|
|
19
90
|
getDedupKeys(): ReadonlySet<string>;
|
|
20
91
|
}
|
|
21
92
|
|
|
93
|
+
/** @internal */
|
|
22
94
|
export function createInMemoryExternalWriteLog(): InMemoryExternalWriteLog {
|
|
23
95
|
const dedupKeys = new Set<string>();
|
|
96
|
+
const records: { dedupKey: string }[] = [];
|
|
24
97
|
return {
|
|
98
|
+
records,
|
|
25
99
|
hasDedupKey(key: string) {
|
|
26
100
|
return dedupKeys.has(key);
|
|
27
101
|
},
|
|
28
102
|
record(input: { dedupKey: string }) {
|
|
29
103
|
dedupKeys.add(input.dedupKey);
|
|
104
|
+
records.push(input);
|
|
30
105
|
return input;
|
|
31
106
|
},
|
|
32
107
|
getDedupKeys() {
|
|
@@ -40,6 +115,11 @@ function createDefaultServerSetupDeps(): CoreServerSetupDeps {
|
|
|
40
115
|
serverBaseUrl: "https://leitwerk.example",
|
|
41
116
|
components: {},
|
|
42
117
|
externalWrites: createInMemoryExternalWriteLog(),
|
|
118
|
+
polling: {
|
|
119
|
+
create(options) {
|
|
120
|
+
return { poll: options.pollOnce };
|
|
121
|
+
},
|
|
122
|
+
},
|
|
43
123
|
repositoryCredentials: { register: () => {} },
|
|
44
124
|
processes: {
|
|
45
125
|
create: () => {
|
|
@@ -111,17 +191,18 @@ function createDefaultServerSetupDeps(): CoreServerSetupDeps {
|
|
|
111
191
|
};
|
|
112
192
|
},
|
|
113
193
|
},
|
|
114
|
-
|
|
115
|
-
async
|
|
194
|
+
launchRuns: {
|
|
195
|
+
async startProgrammatic() {
|
|
116
196
|
throw new Error("not used");
|
|
117
197
|
},
|
|
118
|
-
async
|
|
198
|
+
async startWatcher() {
|
|
119
199
|
throw new Error("not used");
|
|
120
200
|
},
|
|
121
201
|
},
|
|
122
202
|
};
|
|
123
203
|
}
|
|
124
204
|
|
|
205
|
+
/** @public */
|
|
125
206
|
export function createTestServerSetupCapability(
|
|
126
207
|
overrides: Partial<CoreServerSetupDeps> = {},
|
|
127
208
|
): CoreServerSetupDeps {
|
|
@@ -146,24 +227,37 @@ export function createTestServerSetupCapability(
|
|
|
146
227
|
...overrides.launcherModelConfigs,
|
|
147
228
|
},
|
|
148
229
|
launchPlans: { ...defaults.launchPlans, ...overrides.launchPlans },
|
|
149
|
-
|
|
230
|
+
launchRuns: { ...defaults.launchRuns, ...overrides.launchRuns },
|
|
150
231
|
};
|
|
151
232
|
}
|
|
152
233
|
|
|
234
|
+
/** @internal */
|
|
153
235
|
export interface ServerExtensionTestHarness {
|
|
236
|
+
/** @internal */
|
|
154
237
|
catalog: ExtensionCatalog;
|
|
238
|
+
/** @internal */
|
|
155
239
|
events: ReturnType<typeof createEventBus>;
|
|
240
|
+
/** @internal */
|
|
156
241
|
serverSetup: CoreServerSetupDeps;
|
|
242
|
+
/** @internal */
|
|
157
243
|
startHooks: Array<() => void | Promise<void>>;
|
|
244
|
+
/** @internal */
|
|
158
245
|
stopHooks: Array<() => void | Promise<void>>;
|
|
246
|
+
/** @internal */
|
|
159
247
|
flushAsyncWork: typeof flushAsyncWork;
|
|
160
248
|
}
|
|
161
249
|
|
|
250
|
+
/** @internal */
|
|
162
251
|
export async function setupServerExtensionTest(input: {
|
|
252
|
+
/** @internal */
|
|
163
253
|
modules: readonly LeitwerkExtensionModule[];
|
|
254
|
+
/** @internal */
|
|
164
255
|
providedCapabilities?: readonly ProvidedCapability[];
|
|
256
|
+
/** @internal */
|
|
165
257
|
serverSetup?: Partial<CoreServerSetupDeps>;
|
|
258
|
+
/** @internal */
|
|
166
259
|
onStart?: (handler: () => void | Promise<void>) => void;
|
|
260
|
+
/** @internal */
|
|
167
261
|
onStop?: (handler: () => void | Promise<void>) => void;
|
|
168
262
|
}): Promise<ServerExtensionTestHarness> {
|
|
169
263
|
const catalog = await buildExtensionCatalogFromModules(input.modules);
|
|
@@ -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
|
+
}
|
|
@@ -2,6 +2,7 @@ import type { ChildProcess, spawn } from "node:child_process";
|
|
|
2
2
|
import { EventEmitter } from "node:events";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { PassThrough } from "node:stream";
|
|
5
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
5
6
|
import type { ExtensionCatalog } from "@leitwerk-dev/extension-runtime";
|
|
6
7
|
import type { PiTreeHandleFactory } from "@leitwerk-dev/worker";
|
|
7
8
|
import { createWorkerEntryRuntime } from "@leitwerk-dev/worker";
|
|
@@ -14,16 +15,39 @@ const WebSocket =
|
|
|
14
15
|
(require("ws") as { default?: unknown }).default ??
|
|
15
16
|
require("ws");
|
|
16
17
|
|
|
18
|
+
/** @public */
|
|
17
19
|
export interface InProcessWorkerSpawnOptions {
|
|
20
|
+
/** @public */
|
|
18
21
|
extensionCatalog?: ExtensionCatalog | Promise<ExtensionCatalog>;
|
|
22
|
+
/** @public */
|
|
19
23
|
piFactory?: PiTreeHandleFactory;
|
|
24
|
+
/** @public */
|
|
20
25
|
toolCallScriptResolver?: StubToolCallScriptResolver;
|
|
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;
|
|
21
44
|
}
|
|
22
45
|
|
|
23
46
|
/**
|
|
24
47
|
* Fast local-runner-shaped spawn fake. The worker receives the local runner's
|
|
25
48
|
* env and connects over WebSocket just like Docker/Kubernetes workers do.
|
|
26
49
|
*/
|
|
50
|
+
/** @public */
|
|
27
51
|
export function createInProcessWorkerSpawn(
|
|
28
52
|
options: InProcessWorkerSpawnOptions = {},
|
|
29
53
|
): typeof spawn {
|
|
@@ -41,11 +65,15 @@ export function createInProcessWorkerSpawn(
|
|
|
41
65
|
const child = new EventEmitter() as unknown as ChildProcess;
|
|
42
66
|
const emitter = child as unknown as EventEmitter;
|
|
43
67
|
let exited = false;
|
|
68
|
+
const cancellation = new AbortController();
|
|
69
|
+
const timing = options.startupDelays?.(spawnOptions?.env?.LEITWERK_INSTANCE_ID ?? "");
|
|
70
|
+
const pause = (ms: number) => delay(ms, undefined, { signal: cancellation.signal });
|
|
44
71
|
|
|
45
72
|
let runtime: ReturnType<typeof createWorkerEntryRuntime> | null = null;
|
|
46
73
|
const finish = (code: number) => {
|
|
47
74
|
if (!exited) {
|
|
48
75
|
exited = true;
|
|
76
|
+
cancellation.abort();
|
|
49
77
|
emitter.emit("exit", code, null);
|
|
50
78
|
}
|
|
51
79
|
};
|
|
@@ -64,8 +92,23 @@ export function createInProcessWorkerSpawn(
|
|
|
64
92
|
|
|
65
93
|
runtime = createWorkerEntryRuntime({
|
|
66
94
|
extensionCatalog: options.extensionCatalog,
|
|
67
|
-
piFactory
|
|
95
|
+
piFactory: timing
|
|
96
|
+
? {
|
|
97
|
+
async prepareManagedBootstrap(input) {
|
|
98
|
+
await pause(timing.prepareMs);
|
|
99
|
+
return piFactory.prepareManagedBootstrap(input);
|
|
100
|
+
},
|
|
101
|
+
inspectPrimaryTree: (input) => piFactory.inspectPrimaryTree(input),
|
|
102
|
+
createPrimaryTreeHandle: (input) => piFactory.createPrimaryTreeHandle(input),
|
|
103
|
+
}
|
|
104
|
+
: piFactory,
|
|
68
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
|
+
}),
|
|
69
112
|
env: spawnOptions?.env ?? process.env,
|
|
70
113
|
exit: finish,
|
|
71
114
|
});
|
|
@@ -73,7 +116,11 @@ export function createInProcessWorkerSpawn(
|
|
|
73
116
|
setImmediate(() => {
|
|
74
117
|
if (exited) return;
|
|
75
118
|
(globalThis as unknown as { WebSocket?: unknown }).WebSocket = WebSocket;
|
|
76
|
-
void
|
|
119
|
+
void (async () => {
|
|
120
|
+
if (timing) await pause(timing.connectMs);
|
|
121
|
+
if (!exited) await runtime?.start();
|
|
122
|
+
})().catch((error: unknown) => {
|
|
123
|
+
if (exited) return;
|
|
77
124
|
stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
78
125
|
finish(1);
|
|
79
126
|
});
|
|
@@ -1,36 +1,14 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "../in-process-worker.js";
|
|
5
|
-
export { baseEnvelope, flushAsyncWork, testConfigSnapshot } from "./ipc-harness.js";
|
|
6
|
-
export {
|
|
7
|
-
createSchemaDrivenStubPiFactory,
|
|
8
|
-
createSchemaDrivenToolCallScriptResolver,
|
|
9
|
-
synthesizeStubArgValue,
|
|
10
|
-
synthesizeStubToolArgs,
|
|
11
|
-
} from "./schema-driven-stub-pi.js";
|
|
12
|
-
export {
|
|
13
|
-
createStubToolScriptController,
|
|
14
|
-
type StubToolScriptController,
|
|
15
|
-
} 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";
|
|
16
4
|
export {
|
|
17
5
|
StubPiTreeHandle,
|
|
18
6
|
StubPiTreeHandleFactory,
|
|
19
|
-
type StubPiTreeHandleFactoryOptions,
|
|
20
7
|
type StubToolCallScriptCall,
|
|
21
|
-
type StubToolCallScriptItem,
|
|
22
8
|
type StubToolCallScriptResolver,
|
|
23
|
-
type StubToolCallScriptResolverContext,
|
|
24
9
|
} from "./stub-pi-tree-handle.js";
|
|
25
10
|
export {
|
|
26
11
|
createManualWorkerRuntimeScheduler,
|
|
27
12
|
createWorkerRuntimeHarness,
|
|
28
|
-
type ManualWorkerRuntimeScheduler,
|
|
29
|
-
type WorkerRuntimeHarness,
|
|
30
|
-
type WorkerRuntimeHarnessOptions,
|
|
31
|
-
type WorkerRuntimeObservation,
|
|
32
13
|
} from "./worker-runtime-harness.js";
|
|
33
|
-
export {
|
|
34
|
-
createTestLlmWorkerStartPayload,
|
|
35
|
-
type TestLlmWorkerStartPayloadOptions,
|
|
36
|
-
} 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 {
|