@leitwerk-dev/test-support 0.3.1 → 0.4.0
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-JGXSXRIJ.js → chunk-3RWI5WJK.js} +2 -2
- package/dist/{chunk-5BZSJ4OO.js → chunk-DNUGHAYN.js} +37 -4
- package/dist/chunk-DNUGHAYN.js.map +1 -0
- package/dist/{chunk-P2FF4AP7.js → chunk-FDXRT6UZ.js} +57 -2
- package/dist/chunk-FDXRT6UZ.js.map +1 -0
- package/dist/{chunk-WT7V7REB.js → chunk-WRAVDPEM.js} +15 -27
- package/dist/chunk-WRAVDPEM.js.map +1 -0
- package/dist/extension-integration-harness.d.ts +2 -2
- package/dist/extension-integration-harness.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -26
- package/dist/index.js.map +1 -1
- package/dist/integration-harness.d.ts +2 -0
- package/dist/integration-harness.d.ts.map +1 -1
- package/dist/integration.d.ts +1 -1
- package/dist/integration.d.ts.map +1 -1
- package/dist/integration.js +30 -16
- package/dist/integration.js.map +1 -1
- package/dist/local-git.d.ts +9 -0
- package/dist/local-git.d.ts.map +1 -1
- package/dist/local-git.js +31 -0
- package/dist/local-git.js.map +1 -1
- package/dist/model-provider-fixtures.d.ts +7 -0
- package/dist/model-provider-fixtures.d.ts.map +1 -1
- package/dist/process.d.ts +32 -2
- package/dist/process.d.ts.map +1 -1
- package/dist/process.js +24 -15
- package/dist/process.js.map +1 -1
- package/dist/server-extension-test-harness.d.ts +3 -1
- package/dist/server-extension-test-harness.d.ts.map +1 -1
- package/dist/stub-worker-entry.js +1 -1
- package/dist/worker-testing/index.d.ts +1 -1
- package/dist/worker-testing/index.d.ts.map +1 -1
- package/dist/worker-testing/index.js +7 -4
- package/dist/worker-testing/index.js.map +1 -1
- package/dist/worker-testing/schema-driven-stub-pi.d.ts.map +1 -1
- package/dist/worker-testing/stub-pi-tree-handle.d.ts +2 -0
- package/dist/worker-testing/stub-pi-tree-handle.d.ts.map +1 -1
- package/dist/worker-testing/worker-start-payload.d.ts.map +1 -1
- package/package.json +10 -10
- package/src/extension-integration-harness.ts +11 -13
- package/src/index.ts +2 -0
- package/src/integration-harness.ts +17 -1
- package/src/integration.ts +1 -0
- package/src/local-git.ts +34 -0
- package/src/model-provider-fixtures.ts +40 -0
- package/src/process.ts +22 -12
- package/src/server-extension-test-harness.ts +40 -1
- package/src/worker-testing/index.ts +1 -0
- package/src/worker-testing/schema-driven-stub-pi.ts +11 -23
- package/src/worker-testing/stub-pi-tree-handle.ts +20 -1
- package/src/worker-testing/worker-start-payload.ts +1 -0
- package/dist/chunk-5BZSJ4OO.js.map +0 -1
- package/dist/chunk-P2FF4AP7.js.map +0 -1
- package/dist/chunk-WT7V7REB.js.map +0 -1
- /package/dist/{chunk-JGXSXRIJ.js.map → chunk-3RWI5WJK.js.map} +0 -0
package/dist/integration.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
postImmediateLaunch
|
|
3
|
-
|
|
2
|
+
postImmediateLaunch,
|
|
3
|
+
withDefaultModelFixture
|
|
4
|
+
} from "./chunk-FDXRT6UZ.js";
|
|
4
5
|
import {
|
|
5
6
|
observe
|
|
6
7
|
} from "./chunk-KJVNI2UP.js";
|
|
@@ -9,18 +10,19 @@ import {
|
|
|
9
10
|
} from "./chunk-RY6Y6V5E.js";
|
|
10
11
|
import {
|
|
11
12
|
createTestServerSetupCapability
|
|
12
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-DNUGHAYN.js";
|
|
13
14
|
import {
|
|
14
15
|
createInProcessWorkerSpawn
|
|
15
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-3RWI5WJK.js";
|
|
16
17
|
import {
|
|
17
|
-
StubPiTreeHandleFactory
|
|
18
|
-
|
|
18
|
+
StubPiTreeHandleFactory,
|
|
19
|
+
formatBranchText
|
|
20
|
+
} from "./chunk-WRAVDPEM.js";
|
|
19
21
|
|
|
20
22
|
// src/extension-integration-harness.ts
|
|
21
23
|
import { randomUUID } from "crypto";
|
|
22
24
|
import path2 from "path";
|
|
23
|
-
import { buildExtensionCatalogFromModules } from "@leitwerk-dev/extension-runtime/testing";
|
|
25
|
+
import { buildExtensionCatalogFromModules as buildExtensionCatalogFromModules2 } from "@leitwerk-dev/extension-runtime/testing";
|
|
24
26
|
import {
|
|
25
27
|
coreHostCapabilities
|
|
26
28
|
} from "@leitwerk-dev/process-sdk";
|
|
@@ -34,10 +36,20 @@ import { persistPiResourceBundleForStart } from "@leitwerk-dev/worker";
|
|
|
34
36
|
import { mkdtempSync, rmSync } from "fs";
|
|
35
37
|
import { tmpdir } from "os";
|
|
36
38
|
import path from "path";
|
|
39
|
+
import { buildExtensionCatalogFromModules } from "@leitwerk-dev/extension-runtime/testing";
|
|
37
40
|
import {
|
|
38
41
|
createAppContext,
|
|
39
42
|
getDefaultConfig
|
|
40
43
|
} from "@leitwerk-dev/server";
|
|
44
|
+
async function createTestAppContext(options = {}) {
|
|
45
|
+
const config = options.config ?? getDefaultConfig();
|
|
46
|
+
const catalog = await (options.extensionCatalog ?? buildExtensionCatalogFromModules([]));
|
|
47
|
+
return createAppContext({
|
|
48
|
+
...options,
|
|
49
|
+
config,
|
|
50
|
+
extensionCatalog: withDefaultModelFixture(config, catalog)
|
|
51
|
+
});
|
|
52
|
+
}
|
|
41
53
|
function createPersistentIntegrationFixture(prefix, configure) {
|
|
42
54
|
const root = mkdtempSync(path.join(tmpdir(), prefix));
|
|
43
55
|
let harness;
|
|
@@ -90,7 +102,10 @@ async function createIntegrationHarness(opts) {
|
|
|
90
102
|
config.workers.runner = "local";
|
|
91
103
|
}
|
|
92
104
|
opts.configOverride?.(config);
|
|
93
|
-
const extensionCatalog =
|
|
105
|
+
const extensionCatalog = withDefaultModelFixture(
|
|
106
|
+
config,
|
|
107
|
+
await Promise.resolve(opts.extensionCatalog)
|
|
108
|
+
);
|
|
94
109
|
const appOpts = {
|
|
95
110
|
logger: false,
|
|
96
111
|
config,
|
|
@@ -137,7 +152,7 @@ async function createIntegrationHarness(opts) {
|
|
|
137
152
|
|
|
138
153
|
// src/extension-integration-harness.ts
|
|
139
154
|
async function createExtensionIntegrationHarness(options) {
|
|
140
|
-
const catalog = await
|
|
155
|
+
const catalog = await buildExtensionCatalogFromModules2([
|
|
141
156
|
...options.polling === "manual" ? [
|
|
142
157
|
{
|
|
143
158
|
manifest: { id: "test-support-manual-polling", version: "1" },
|
|
@@ -164,6 +179,7 @@ async function createExtensionIntegrationHarness(options) {
|
|
|
164
179
|
thinking_level: model.thinkingLevel ?? "off"
|
|
165
180
|
}));
|
|
166
181
|
if (options.defaultModel) {
|
|
182
|
+
config.pi.default_model_profile = options.defaultModel;
|
|
167
183
|
config.pi.process_title_generation.model_profile = options.defaultModel;
|
|
168
184
|
config.process_configs = Object.fromEntries(
|
|
169
185
|
[...catalog.processes.keys()].map((id) => [
|
|
@@ -199,11 +215,7 @@ async function createExtensionIntegrationHarness(options) {
|
|
|
199
215
|
const prompt = input.identifiedPromptText ?? input.promptText;
|
|
200
216
|
observation.prompts.push(prompt);
|
|
201
217
|
const session = [...piFactory.sessions].reverse().find((session2) => session2.treeFile === input.treeFile);
|
|
202
|
-
const history = session?.getBranch()
|
|
203
|
-
if (entry.type === "custom_message") return entry.content;
|
|
204
|
-
if (entry.type === "message" && entry.message) return entry.message.content;
|
|
205
|
-
return "";
|
|
206
|
-
}).filter((value) => typeof value === "string").join("\n\n") ?? "";
|
|
218
|
+
const history = formatBranchText(session?.getBranch(), "");
|
|
207
219
|
const script = manual ? scripts.get(id) : await options.script?.(
|
|
208
220
|
id,
|
|
209
221
|
prompt,
|
|
@@ -518,9 +530,10 @@ async function createExtensionIntegrationHarness(options) {
|
|
|
518
530
|
/** Get a handle that remains valid across restart. @public */
|
|
519
531
|
process: processHandle,
|
|
520
532
|
/** Admit work through a registered UI launcher. @public */
|
|
521
|
-
async launch(id, input) {
|
|
533
|
+
async launch(id, input, modelConfig) {
|
|
522
534
|
const response = await postImmediateLaunch(context().config.server.base_url, id, {
|
|
523
|
-
launcherInput: input
|
|
535
|
+
launcherInput: input,
|
|
536
|
+
...modelConfig ? { modelConfig } : {}
|
|
524
537
|
});
|
|
525
538
|
const body = await response.json();
|
|
526
539
|
if (!response.ok || !body.process)
|
|
@@ -680,6 +693,7 @@ export {
|
|
|
680
693
|
createIntegrationHarness,
|
|
681
694
|
createPersistentIntegrationFixture,
|
|
682
695
|
createProcessDriver,
|
|
696
|
+
createTestAppContext,
|
|
683
697
|
createTestServerSetupCapability,
|
|
684
698
|
waitForValue
|
|
685
699
|
};
|
package/dist/integration.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/extension-integration-harness.ts","../src/integration-harness.ts","../src/polling.ts","../src/process-driver.ts"],"sourcesContent":["import type { ExtensionTestCapability } from \"./test-capability.js\";\n\nexport type { ExtensionTestCapability } from \"./test-capability.js\";\n\nimport { randomUUID } from \"node:crypto\";\nimport path from \"node:path\";\nimport type {\n\tActor,\n\tExternalWriteLog,\n\tProcessInstance,\n\tProcessProject,\n\tProcessTurnRecord,\n} from \"@leitwerk-dev/domain\";\nimport { buildExtensionCatalogFromModules } from \"@leitwerk-dev/extension-runtime/testing\";\nimport {\n\tcoreHostCapabilities,\n\ttype ExtensionProcessDefinition,\n\ttype LeitwerkExtensionModule,\n} from \"@leitwerk-dev/process-sdk\";\nimport {\n\tcreateAcceptedWorkerTurn,\n\tprepareAcceptedFixtureStart,\n} from \"@leitwerk-dev/server/testing\";\nimport { persistPiResourceBundleForStart } from \"@leitwerk-dev/worker\";\nimport { postImmediateLaunch } from \"./http-launch.js\";\nimport { createPersistentIntegrationFixture } from \"./integration-harness.js\";\nimport { observe, type TestObservation } from \"./observations.js\";\nimport { createProcessFixture, type ProcessFixtureOptions } from \"./process-fixtures.js\";\nimport type { QuestionRequestFixture } from \"./supported-question-fixtures.js\";\nimport { StubPiTreeHandleFactory } from \"./worker-testing/stub-pi-tree-handle.js\";\n\n/** Model-visible inputs for a scripted invocation. @public */\nexport interface IntegrationPromptObservation {\n\t/** @public */\n\tturnId: string;\n\t/** Working directory available for fixture repository edits. @public */\n\tcwd: string;\n\t/** Opaque branch-session identity for comparing execution relationships. @public */\n\tbranchId: string;\n\t/** Text inherited by the current branch. @public */\n\thistory: string;\n\t/** @public */\n\ttools: readonly {\n\t\t/** @public */\n\t\tname: string;\n\t\t/** @public */\n\t\tparameters: Record<string, unknown>;\n\t}[];\n}\n\n/** Rendered result retained at a tree leaf. @public */\nexport interface IntegrationLeafObservation {\n\t/** @public */\n\tid: string;\n\t/** @public */\n\tinstanceId: string;\n\t/** @public */\n\tleafEntryId: string;\n\t/** @public */\n\tturnRecordId: string | null;\n\t/** @public */\n\trendererId: string | null;\n\t/** @public */\n\tschemaVersion: number | null;\n\t/** @public */\n\tprops: Record<string, unknown> | null;\n\t/** @public */\n\tfallbackMarkdown: string | null;\n\t/** @public */\n\tstatus: \"ready\" | \"capture_error\";\n}\n\n/** Recorded semantic event. @public */\nexport interface IntegrationEventObservation {\n\t/** @public */\n\tid: string;\n\t/** @public */\n\teventType: string;\n\t/** @public */\n\tdata: Record<string, unknown>;\n\t/** @public */\n\tcreatedAt: string;\n}\n\n/** Durable annotation of process execution. @public */\nexport interface IntegrationAnnotationObservation {\n\t/** @public */\n\tid: string;\n\t/** @public */\n\tannotationType: string;\n\t/** @public */\n\tpayload: Record<string, unknown>;\n}\n\n/** One scripted model prompt, executed through registered tools. @public */\nexport interface IntegrationTurnScript {\n\t/** @public */\n\ttools: readonly IntegrationToolCall[];\n\t/** Scripted reasoning retained by the normal worker path. @public */\n\tthinking?: readonly string[];\n\t/** Assistant markdown for turns completed by model output. @public */\n\tmarkdown?: string;\n\t/** Optional model response after an integration-tool result. @public */\n\tafterToolResult?(call: IntegrationToolCall, result: unknown): IntegrationToolCall | undefined;\n}\n\n/** @public */\nexport interface IntegrationToolCall {\n\t/** @public */\n\tname: string;\n\t/** @public */\n\targuments: Record<string, unknown>;\n}\n\n/** Instruction delivered through the application's durable input queue. @public */\nexport interface IntegrationProcessInput {\n\t/** @public */\n\tbodyMarkdown: string;\n\t/** Target a published product branch. @public */\n\tproduct?: string;\n}\n\n/** Durable instruction delivery observations. @public */\nexport interface IntegrationInputObservation {\n\t/** @public */\n\tid: string;\n\t/** @public */\n\tinstanceId: string;\n\t/** @public */\n\tsequence: number;\n\t/** @public */\n\tsource: string;\n\t/** @public */\n\tkind: string;\n\t/** @public */\n\tbodyMarkdown: string;\n\t/** @public */\n\ttarget: {\n\t\t/** @public */\n\t\tproductName?: string;\n\t\t/** @public */\n\t\tsemanticRef?: string;\n\t} | null;\n\t/** @public */\n\tactor: Actor;\n\t/** @public */\n\treceivedAt: string;\n\t/** @public */\n\tconsumedAt: string | null;\n}\n\n/** Operator approval observations. @public */\nexport interface IntegrationApprovalObservation {\n\t/** @public */\n\tid: string;\n\t/** @public */\n\tinstanceId: string;\n\t/** @public */\n\tturnRecordId: string;\n\t/** @public */\n\ttoolCallId: string;\n\t/** @public */\n\ttoolName: string;\n\t/** @public */\n\targuments: Record<string, unknown>;\n\t/** @public */\n\tdestination: {\n\t\t/** @public */\n\t\tid: string;\n\t\t/** @public */\n\t\tdisplayName: string;\n\t\t/** @public */\n\t\tgroup?: string;\n\t\t/** @public */\n\t\tdescription?: string;\n\t} | null;\n\t/** @public */\n\tstatus: \"open\" | \"accepted\" | \"feedback\" | \"declined\" | \"cancelled\";\n\t/** @public */\n\trequestedAt: string;\n\t/** @public */\n\tresolvedAt: string | null;\n\t/** @public */\n\tresolvedBy: Actor | null;\n\t/** @public */\n\tfeedback: string | null;\n}\n\n/** Explicit accepted execution setup, independent of process business state. @public */\nexport interface AcceptedTurnFixture {\n\t/** @public */\n\tturnId: string;\n\t/** @public */\n\texecution:\n\t\t| {\n\t\t\t\t/** @public */\n\t\t\t\tstatus: \"running\";\n\t\t }\n\t\t| {\n\t\t\t\t/** @public */\n\t\t\t\tstatus: \"succeeded\";\n\t\t\t\t/** @public */\n\t\t\t\toutcome: string;\n\t\t\t\t/** @public */\n\t\t\t\tmarkdown: string;\n\t\t };\n}\n\n/** Detached durable observations. @public */\nexport interface ExtensionIntegrationSnapshot {\n\t/** Harness-owned process workspace. @public */\n\tworkspaceRoot: string;\n\t/** @public */\n\tevents: IntegrationEventObservation[];\n\t/** @public */\n\tannotations: IntegrationAnnotationObservation[];\n\t/** @public */\n\tleafOutcomes: IntegrationLeafObservation[];\n\n\t/** @public */\n\tprocess: ProcessInstance;\n\t/** @public */\n\tparams: unknown;\n\t/** @public */\n\tstate: unknown;\n\t/** @public */\n\tprojects: ProcessProject[];\n\t/** @public */\n\tturns: ProcessTurnRecord[];\n\t/** @public */\n\tinputs: IntegrationInputObservation[];\n\t/** @public */\n\tquestions: QuestionRequestFixture[];\n\t/** @public */\n\tapprovals: IntegrationApprovalObservation[];\n\t/** @public */\n\twriteReceipts: ExternalWriteLog[];\n}\n\n/** @public */\nexport interface ExtensionIntegrationHarnessOptions {\n\t/** Per-process watcher configuration. @public */\n\twatchers?: Readonly<Record<string, Record<string, unknown>>>;\n\t/** Advance extension provider pollers explicitly in tests. @public */\n\tpolling?: \"automatic\" | \"manual\";\n\t/** Host Docker boundary for extensions which require it. @public */\n\thostDocker?: {\n\t\t/** @public */\n\t\tpreflight(timeoutMs: number): Promise<void>;\n\t};\n\n\t/** Configuration keyed by extension manifest id. @public */\n\textensionConfig?: Readonly<Record<string, unknown>>;\n\t/** @public */\n\textensions: readonly LeitwerkExtensionModule[];\n\t/** @public */\n\tcapabilities?: readonly ExtensionTestCapability[];\n\t/** Automatic execution starts admitted work immediately. @public */\n\texecution?: \"automatic\" | \"manual\";\n\t/** Model catalog used by the supplied provider extensions. @public */\n\tmodels?: readonly {\n\t\t/** @public */\n\t\tid: string;\n\t\t/** @public */\n\t\tprovider: string;\n\t\t/** @public */\n\t\tmodelId: string;\n\t\t/** @public */\n\t\tthinkingLevel?: \"off\" | \"minimal\" | \"low\" | \"medium\" | \"high\" | \"xhigh\";\n\t}[];\n\t/** Default model profile for all registered processes. @public */\n\tdefaultModel?: string;\n\t/** Model scripts for automatic execution, in prompt order per process. @public */\n\tscript?(\n\t\tinstanceId: string,\n\t\tprompt: string,\n\t\tobservation: TestObservation<IntegrationPromptObservation>,\n\t): IntegrationTurnScript | Promise<IntegrationTurnScript>;\n}\n\n/** HTTP-shaped requests without a Fastify handle. @public */\nexport interface ExtensionTestRequest {\n\t/** @public */\n\tmethod?: \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\n\t/** @public */\n\turl: string;\n\t/** @public */\n\tpayload?: Record<string, unknown>;\n\t/** @public */\n\theaders?: Record<string, string>;\n}\n\n/** HTTP response observation. @public */\nexport interface ExtensionTestResponse {\n\t/** @public */\n\tstatusCode: number;\n\t/** @public */\n\tbody: string;\n\t/** @public */\n\tjson<T = unknown>(): T;\n}\n\n/** Accepted turn identity and optional retained result. @public */\nexport interface AcceptedTurnReference {\n\t/** @public */\n\tid: string;\n\t/** @public */\n\tinstanceId: string;\n\t/** @public */\n\tturnId: string;\n\t/** @public */\n\tartifact: {\n\t\t/** @public */ kind: \"turn_result\";\n\t\t/** @public */\n\t\tturnRecordId: string;\n\t} | null;\n}\n\n/** One durably settled worker execution. @public */\nexport interface IntegrationTurnResult {\n\t/** @public */\n\tturn: ProcessTurnRecord | null;\n\t/** @public */\n\toutcome: string | null;\n\t/** @public */\n\tfailure: string | null;\n\t/** @public */\n\tprompts: string[];\n\t/** @public */\n\ttoolResults: {\n\t\t/** @public */ name: string;\n\t\t/** @public */\n\t\tresult: unknown;\n\t}[];\n\t/** @public */\n\tresult: AcceptedTurnReference[\"artifact\"];\n}\n\n/** Durable process commands and observations. @public */\nexport interface ExtensionIntegrationProcess {\n\t/** @public */\n\treadonly id: string;\n\t/** @public */\n\tseedAcceptedTurn(fixture: AcceptedTurnFixture): Promise<TestObservation<AcceptedTurnReference>>;\n\t/** @public */\n\tsnapshot(): TestObservation<ExtensionIntegrationSnapshot>;\n\t/** @public */\n\twaitFor(\n\t\tcondition: (snapshot: TestObservation<ExtensionIntegrationSnapshot>) => boolean,\n\t\toptions?: {\n\t\t\t/** @public */ timeoutMs?: number;\n\t\t\t/** @public */\n\t\t\tdescription?: string;\n\t\t},\n\t): Promise<TestObservation<ExtensionIntegrationSnapshot>>;\n\t/** @public */\n\trunTurn(script?: IntegrationTurnScript): Promise<TestObservation<IntegrationTurnResult>>;\n\t/** @public */\n\taction(id: string, input?: Record<string, unknown>): Promise<ExtensionTestResponse>;\n\t/** @public */\n\tretry(): Promise<ExtensionTestResponse>;\n\t/** @public */\n\tsupplyInput(\n\t\tinput: IntegrationProcessInput,\n\t): Promise<TestObservation<ExtensionIntegrationSnapshot>>;\n\t/** @public */\n\tanswerQuestions(\n\t\tid: string,\n\t\tanswers: readonly {\n\t\t\t/** @public */\n\t\t\tselectedOptionIds: readonly string[];\n\t\t\t/** @public */\n\t\t\tfreeText: string;\n\t\t\t/** @public */\n\t\t\tcomment: string;\n\t\t}[],\n\t): Promise<ExtensionTestResponse>;\n\t/** @public */\n\trespondToApproval(\n\t\tid: string,\n\t\tresponse: {\n\t\t\t/** @public */\n\t\t\taction: \"accept\" | \"feedback\" | \"decline\";\n\t\t\t/** @public */\n\t\t\tfeedback?: string;\n\t\t},\n\t): Promise<ExtensionTestResponse>;\n}\n\n/** Disposable persistent extension test environment. @public */\nexport interface ExtensionIntegrationHarness {\n\t/** Detached processes discovered or launched by extensions. @public */\n\tprocesses(): TestObservation<ProcessInstance[]>;\n\n\t/** @public */\n\trequest(input: ExtensionTestRequest): Promise<ExtensionTestResponse>;\n\t/** @public */\n\tprocess(id: string): ExtensionIntegrationProcess;\n\t/** @public */\n\tlaunch(id: string, input: Record<string, unknown>): Promise<ExtensionIntegrationProcess>;\n\t/** @public */\n\tcreateProcess<TParams, TState>(\n\t\tdefinition: ExtensionProcessDefinition<TParams, TState>,\n\t\tinput?: Omit<ProcessFixtureOptions<TParams, TState>, \"id\" | \"processId\"> & {\n\t\t\t/** @public */\n\t\t\tprojects?: readonly ProcessProject[];\n\t\t},\n\t): Promise<ExtensionIntegrationProcess>;\n\t/** @public */\n\trestart(options?: {\n\t\t/** Update extension wiring on the reopened server. @public */\n\t\textensionConfig?: Readonly<Record<string, unknown>>;\n\t\t/** Apply external changes while the server is offline. @public */\n\t\twhileStopped?(): void | Promise<void>;\n\t}): Promise<void>;\n\t/** @public */\n\tclose(): Promise<void>;\n}\n\n/** Own server, workers, and disposable persistent storage. @public */\nexport async function createExtensionIntegrationHarness(\n\toptions: ExtensionIntegrationHarnessOptions,\n): Promise<ExtensionIntegrationHarness> {\n\tconst catalog = await buildExtensionCatalogFromModules([\n\t\t...(options.polling === \"manual\"\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tmanifest: { id: \"test-support-manual-polling\", version: \"1\" },\n\t\t\t\t\t\tsetupServer(api: import(\"@leitwerk-dev/process-sdk\").ServerExtensionAPI) {\n\t\t\t\t\t\t\tconst deps = api.get(coreHostCapabilities.serverSetup);\n\t\t\t\t\t\t\tif (!deps || Array.isArray(deps)) throw new Error(\"Missing polling host\");\n\t\t\t\t\t\t\tdeps.polling = {\n\t\t\t\t\t\t\t\tcreate(input) {\n\t\t\t\t\t\t\t\t\treturn { poll: input.pollOnce };\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: []),\n\t\t...options.extensions,\n\t]);\n\tconst persistent = createPersistentIntegrationFixture(\"leitwerk-extension-test-\", (config) => {\n\t\tconfig.extensions = structuredClone(options.extensionConfig ?? {});\n\t\tif (options.hostDocker && config.local_worker) config.local_worker.allow_host_docker = true;\n\t\tconfig.pi.model_profiles = (options.models ?? []).map((model) => ({\n\t\t\tid: model.id,\n\t\t\tprovider: model.provider,\n\t\t\tmodel_id: model.modelId,\n\t\t\tthinking_level: model.thinkingLevel ?? \"off\",\n\t\t}));\n\t\tif (options.defaultModel) {\n\t\t\tconfig.pi.process_title_generation.model_profile = options.defaultModel;\n\t\t\tconfig.process_configs = Object.fromEntries(\n\t\t\t\t[...catalog.processes.keys()].map((id) => [\n\t\t\t\t\tid,\n\t\t\t\t\t{\n\t\t\t\t\t\tdefault_model_profile: options.defaultModel,\n\t\t\t\t\t\tturn_configs: {},\n\t\t\t\t\t\twatchers: structuredClone(options.watchers?.[id] ?? {}),\n\t\t\t\t\t},\n\t\t\t\t]),\n\t\t\t);\n\t\t}\n\t});\n\tconst manual = options.execution === \"manual\";\n\tlet closed = false;\n\tconst pending = new Map<string, { turnId: string; resolve(): void }>();\n\tconst permits = new Set<string>();\n\tconst executing = new Set<string>();\n\tconst scripts = new Map<string, IntegrationTurnScript>();\n\tconst observations = new Map<\n\t\tstring,\n\t\t{ prompts: string[]; toolResults: { name: string; result: unknown }[] }\n\t>();\n\tconst context = () => {\n\t\tif (closed) throw new Error(\"Extension integration harness is closed\");\n\t\treturn persistent.context();\n\t};\n\tasync function open() {\n\t\tconst piFactory: StubPiTreeHandleFactory = new StubPiTreeHandleFactory({\n\t\t\trecordSessionTrace: true,\n\t\t\ttoolCallScriptResolver: async (input) => {\n\t\t\t\tconst id = input.instanceId;\n\t\t\t\tif (!id) throw new Error(\"Scripted prompt has no process identity\");\n\t\t\t\tconst observation = observations.get(id) ?? { prompts: [], toolResults: [] };\n\t\t\t\tobservations.set(id, observation);\n\t\t\t\tconst prompt = input.identifiedPromptText ?? input.promptText;\n\t\t\t\tobservation.prompts.push(prompt);\n\t\t\t\tconst session = [...piFactory.sessions]\n\t\t\t\t\t.reverse()\n\t\t\t\t\t.find((session) => session.treeFile === input.treeFile);\n\t\t\t\tconst history =\n\t\t\t\t\tsession\n\t\t\t\t\t\t?.getBranch()\n\t\t\t\t\t\t.map((entry) => {\n\t\t\t\t\t\t\tif (entry.type === \"custom_message\") return entry.content;\n\t\t\t\t\t\t\tif (entry.type === \"message\" && entry.message) return entry.message.content;\n\t\t\t\t\t\t\treturn \"\";\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.filter((value) => typeof value === \"string\")\n\t\t\t\t\t\t.join(\"\\n\\n\") ?? \"\";\n\t\t\t\tconst script = manual\n\t\t\t\t\t? scripts.get(id)\n\t\t\t\t\t: await options.script?.(\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\tprompt,\n\t\t\t\t\t\t\tobserve({\n\t\t\t\t\t\t\t\tturnId: context().deps.processes.getById(id)?.selectedTurnId ?? \"\",\n\t\t\t\t\t\t\t\tcwd: input.sessionCwd ?? input.workspaceRoot ?? \"\",\n\t\t\t\t\t\t\t\tbranchId: session?.sessionId ?? \"\",\n\t\t\t\t\t\t\t\thistory,\n\t\t\t\t\t\t\t\ttools: input.tools.map((tool) => ({\n\t\t\t\t\t\t\t\t\tname: tool.name,\n\t\t\t\t\t\t\t\t\tparameters: tool.parameters,\n\t\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\tscripts.delete(id);\n\t\t\t\tif (!script || (script.tools.length === 0 && script.markdown === undefined))\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Script exhausted for process '${id}' after ${observation.prompts.length} prompt(s)`,\n\t\t\t\t\t);\n\t\t\t\treturn {\n\t\t\t\t\tthinkingChunks: script.thinking ? [...script.thinking] : undefined,\n\t\t\t\t\ttextChunks: script.markdown === undefined ? undefined : [script.markdown],\n\t\t\t\t\tcalls: script.tools.map((call) => ({\n\t\t\t\t\t\ttoolName: call.name,\n\t\t\t\t\t\targs: structuredClone(call.arguments),\n\t\t\t\t\t})),\n\t\t\t\t\tafterToolResult(call, result) {\n\t\t\t\t\t\tobservation.toolResults.push({ name: call.toolName, result: structuredClone(result) });\n\t\t\t\t\t\tconst next = script.afterToolResult?.(\n\t\t\t\t\t\t\t{ name: call.toolName, arguments: structuredClone(call.args) },\n\t\t\t\t\t\t\tstructuredClone(result),\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn next ? { toolName: next.name, args: next.arguments } : undefined;\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t},\n\t\t});\n\t\tawait persistent.open({\n\t\t\tappOverrides: options.hostDocker\n\t\t\t\t? { localWorkerDockerPreflightImpl: options.hostDocker.preflight }\n\t\t\t\t: undefined,\n\t\t\textensionCatalog: catalog,\n\t\t\tpreProvidedCapabilities: options.capabilities,\n\t\t\tinProcessWorkers: {\n\t\t\t\tpiFactory,\n\t\t\t\tbeforeTurnBootstrap: manual\n\t\t\t\t\t? (id, turnId, signal) =>\n\t\t\t\t\t\t\tnew Promise<void>((resolve, reject) => {\n\t\t\t\t\t\t\t\tif (signal.aborted) {\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (permits.delete(id)) {\n\t\t\t\t\t\t\t\t\tresolve();\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (pending.has(id)) {\n\t\t\t\t\t\t\t\t\treject(new Error(`Conflicting pending worker for '${id}'`));\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst abort = () => {\n\t\t\t\t\t\t\t\t\tpending.delete(id);\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\tsignal.addEventListener(\"abort\", abort, { once: true });\n\t\t\t\t\t\t\t\tpending.set(id, {\n\t\t\t\t\t\t\t\t\tturnId,\n\t\t\t\t\t\t\t\t\tresolve() {\n\t\t\t\t\t\t\t\t\t\tsignal.removeEventListener(\"abort\", abort);\n\t\t\t\t\t\t\t\t\t\tpending.delete(id);\n\t\t\t\t\t\t\t\t\t\tresolve();\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})\n\t\t\t\t\t: undefined,\n\t\t\t},\n\t\t});\n\t}\n\ttry {\n\t\tawait open();\n\t} catch (error) {\n\t\tawait persistent.dispose();\n\t\tthrow error;\n\t}\n\t/** @public */\n\tasync function request(input: ExtensionTestRequest) {\n\t\tconst response = await context().app.inject({ ...input, method: input.method ?? \"GET\" });\n\t\treturn {\n\t\t\t/** @public */\n\t\t\tstatusCode: response.statusCode,\n\t\t\t/** @public */\n\t\t\tbody: response.body,\n\t\t\t/** @public */\n\t\t\tjson<T = unknown>(): T {\n\t\t\t\treturn JSON.parse(response.body) as T;\n\t\t\t},\n\t\t};\n\t}\n\tasync function post(url: string, payload: Record<string, unknown> = {}) {\n\t\tconst response = await request({ method: \"POST\", url, payload });\n\t\tif (response.statusCode >= 400)\n\t\t\tthrow new Error(`POST ${url}: ${response.statusCode} ${response.body}`);\n\t\treturn response;\n\t}\n\t/** @public */\n\tfunction processHandle(id: string): ExtensionIntegrationProcess {\n\t\tconst prefix = `/api/processes/${encodeURIComponent(id)}`;\n\t\t/** @public */\n\t\tfunction snapshot(): TestObservation<ExtensionIntegrationSnapshot> {\n\t\t\tconst { deps } = context();\n\t\t\tconst process = deps.processes.getById(id);\n\t\t\tif (!process) throw new Error(`Unknown process '${id}'`);\n\t\t\tconst definition = catalog.processes.get(process.processId);\n\t\t\treturn observe({\n\t\t\t\tworkspaceRoot: path.join(context().config.storage.process_workspaces_dir, id),\n\t\t\t\tevents: deps.events.listByInstance(id),\n\t\t\t\tannotations: deps.turnAnnotations.listByInstance(id),\n\t\t\t\tleafOutcomes: deps.leafOutcomeSnapshots.listByInstance(id),\n\t\t\t\tprocess,\n\t\t\t\tparams: definition?.paramsCodec.parse(JSON.parse(process.paramsJson ?? \"null\")),\n\t\t\t\tstate: definition?.stateCodec.parse(JSON.parse(process.stateJson ?? \"null\")),\n\t\t\t\tprojects: deps.projects.listByInstance(id),\n\t\t\t\tturns: deps.turnRecords.listByInstance(id),\n\t\t\t\tinputs: deps.inputs.listByInstance(id),\n\t\t\t\tquestions: deps.questionRequests.listByInstance(id),\n\t\t\t\tapprovals: deps.toolApprovalRequests.listByInstance(id),\n\t\t\t\twriteReceipts: deps.externalWrites.listByInstance(id),\n\t\t\t});\n\t\t}\n\t\t/** @public */\n\t\tasync function waitFor(\n\t\t\tcondition: (snapshot: TestObservation<ExtensionIntegrationSnapshot>) => boolean,\n\t\t\toptions: Parameters<ExtensionIntegrationProcess[\"waitFor\"]>[1] = {},\n\t\t) {\n\t\t\tconst deadline = Date.now() + (options.timeoutMs ?? 12000);\n\t\t\tfor (;;) {\n\t\t\t\tconst current = snapshot();\n\t\t\t\tif (condition(current)) return current;\n\t\t\t\tif (Date.now() >= deadline)\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Timed out waiting for ${id}: ${options.description ?? \"condition\"}; ${JSON.stringify({\n\t\t\t\t\t\t\tposition: {\n\t\t\t\t\t\t\t\tselectedTurnId: current.process.selectedTurnId,\n\t\t\t\t\t\t\t\tlifecycleStatus: current.process.lifecycleStatus,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tturns: current.turns.map((turn) => ({\n\t\t\t\t\t\t\t\tid: turn.id,\n\t\t\t\t\t\t\t\tturnId: turn.turnId,\n\t\t\t\t\t\t\t\tstatus: turn.status,\n\t\t\t\t\t\t\t\terror: turn.errorSummary,\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\tinputs: current.inputs.map((input) => ({\n\t\t\t\t\t\t\t\tid: input.id,\n\t\t\t\t\t\t\t\tconsumedAt: input.consumedAt,\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\tquestions: current.questions.map((question) => ({\n\t\t\t\t\t\t\t\tid: question.id,\n\t\t\t\t\t\t\t\tstatus: question.status,\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\tapprovals: current.approvals.map((approval) => ({\n\t\t\t\t\t\t\t\tid: approval.id,\n\t\t\t\t\t\t\t\tstatus: approval.status,\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t})}`,\n\t\t\t\t\t);\n\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, 10));\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\t/** @public */\n\t\t\tid,\n\t\t\t/** Establish correlated accepted records under exclusive server coordination. @public */\n\t\t\tasync seedAcceptedTurn(fixture) {\n\t\t\t\tconst ctx = context();\n\t\t\t\treturn ctx.deps.processOperations.runExclusive(id, async () => {\n\t\t\t\t\tconst process = ctx.deps.processes.getById(id);\n\t\t\t\t\tif (!process) throw new Error(`Unknown process '${id}'`);\n\t\t\t\t\tconst turn = catalog.processes\n\t\t\t\t\t\t.get(process.processId)\n\t\t\t\t\t\t?.turns.get(fixture.turnId)?.definition;\n\t\t\t\t\tif (!turn || (turn.kind !== \"llm\" && turn.kind !== \"automatic\"))\n\t\t\t\t\t\tthrow new Error(`Undeclared worker turn '${fixture.turnId}'`);\n\t\t\t\t\tif (process.currentExecution || ctx.deps.leases.getByInstance(id))\n\t\t\t\t\t\tthrow new Error(\"Cannot seed accepted execution while a live execution exists\");\n\t\t\t\t\tconst running = fixture.execution.status === \"running\";\n\t\t\t\t\tif (running && process.selectedTurnId !== fixture.turnId)\n\t\t\t\t\t\tthrow new Error(\"Running fixture must match the selected turn\");\n\t\t\t\t\tif (\n\t\t\t\t\t\tfixture.execution.status === \"succeeded\" &&\n\t\t\t\t\t\t!Object.hasOwn(turn.outcomes ?? {}, fixture.execution.outcome) &&\n\t\t\t\t\t\tturn.turnEnd?.outcome !== fixture.execution.outcome\n\t\t\t\t\t)\n\t\t\t\t\t\tthrow new Error(`Undeclared outcome '${fixture.execution.outcome}'`);\n\t\t\t\t\tif (fixture.execution.status === \"succeeded\" && !fixture.execution.markdown.trim())\n\t\t\t\t\t\tthrow new Error(\"A successful accepted fixture requires non-empty result markdown\");\n\t\t\t\t\tconst prepared =\n\t\t\t\t\t\tturn.kind === \"llm\"\n\t\t\t\t\t\t\t? await prepareAcceptedFixtureStart(\n\t\t\t\t\t\t\t\t\tctx,\n\t\t\t\t\t\t\t\t\tprocess,\n\t\t\t\t\t\t\t\t\tfixture.turnId,\n\t\t\t\t\t\t\t\t\tcatalog.piContributions,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t: null;\n\t\t\t\t\tconst turnId = `trn_${randomUUID()}`;\n\t\t\t\t\tif (prepared)\n\t\t\t\t\t\tawait persistPiResourceBundleForStart({\n\t\t\t\t\t\t\tbundlesDir: path.join(\n\t\t\t\t\t\t\t\tctx.config.storage.process_workspaces_dir,\n\t\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t\t\".leitwerk\",\n\t\t\t\t\t\t\t\t\"pi-resource-bundles\",\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tstartRecordId: `tsr_${turnId}`,\n\t\t\t\t\t\t\tdigest: prepared.bundle.digest,\n\t\t\t\t\t\t\tdeliveredBundle: prepared.bundle.bytes,\n\t\t\t\t\t\t});\n\t\t\t\t\treturn ctx.deps.transaction((repos) => {\n\t\t\t\t\t\tconst timestamp = new Date().toISOString();\n\t\t\t\t\t\tconst input = {\n\t\t\t\t\t\t\tid: turnId,\n\t\t\t\t\t\t\tinstanceId: id,\n\t\t\t\t\t\t\tturnId: fixture.turnId,\n\t\t\t\t\t\t\tstatus: fixture.execution.status,\n\t\t\t\t\t\t\tattemptNumber:\n\t\t\t\t\t\t\t\tMath.max(\n\t\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t\t...repos.turnRecords\n\t\t\t\t\t\t\t\t\t\t.listByInstance(id)\n\t\t\t\t\t\t\t\t\t\t.filter((record) => record.turnId === fixture.turnId)\n\t\t\t\t\t\t\t\t\t\t.map((record) => record.attemptNumber),\n\t\t\t\t\t\t\t\t) + 1,\n\t\t\t\t\t\t\tstartedAt: timestamp,\n\t\t\t\t\t\t\tendedAt: running ? null : timestamp,\n\t\t\t\t\t\t\tturnResultMarkdown:\n\t\t\t\t\t\t\t\tfixture.execution.status === \"succeeded\" ? fixture.execution.markdown : null,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tcreateAcceptedWorkerTurn(\n\t\t\t\t\t\t\t{ deps: repos },\n\t\t\t\t\t\t\t{ ...input, turnType: turn.kind, modelProfileId: prepared?.start.model.profileId },\n\t\t\t\t\t\t\t{ current: running, preparedStart: prepared?.start },\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (fixture.execution.status === \"succeeded\")\n\t\t\t\t\t\t\trepos.turnAnnotations.create({\n\t\t\t\t\t\t\t\tinstanceId: id,\n\t\t\t\t\t\t\t\tannotationType: \"turn_milestone\",\n\t\t\t\t\t\t\t\tannotationKey: `turn_milestone:${turnId}`,\n\t\t\t\t\t\t\t\treferences: [{ kind: \"turn_record\", turnRecordId: turnId, role: \"subject\" }],\n\t\t\t\t\t\t\t\tpayload: {\n\t\t\t\t\t\t\t\t\tturnId: fixture.turnId,\n\t\t\t\t\t\t\t\t\tturnType: turn.kind,\n\t\t\t\t\t\t\t\t\tpathType: \"primary\",\n\t\t\t\t\t\t\t\t\toutcome: fixture.execution.outcome,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\tif (running) repos.processes.update(id, { lifecycleStatus: \"active\" });\n\t\t\t\t\t\treturn observe({\n\t\t\t\t\t\t\tid: turnId,\n\t\t\t\t\t\t\tinstanceId: id,\n\t\t\t\t\t\t\tturnId: fixture.turnId,\n\t\t\t\t\t\t\tartifact: running ? null : { kind: \"turn_result\" as const, turnRecordId: turnId },\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t},\n\t\t\t/** Read detached durable business and execution observations. @public */\n\t\t\tsnapshot,\n\t\t\t/** Wait with a bounded deadline and final observations on failure. @public */\n\t\t\twaitFor,\n\t\t\t/** Execute one selected worker turn; resolves after durable completion or failure. @public */\n\t\t\tasync runTurn(script = { tools: [] }) {\n\t\t\t\tif (!manual) throw new Error(\"runTurn requires manual execution mode\");\n\t\t\t\tif (executing.has(id)) throw new Error(`A turn is already running for '${id}'`);\n\t\t\t\tconst before = snapshot();\n\t\t\t\tconst selected = before.process.selectedTurnId;\n\t\t\t\tconst turn = selected\n\t\t\t\t\t? catalog.processes.get(before.process.processId)?.turns.get(selected)?.definition\n\t\t\t\t\t: undefined;\n\t\t\t\tif (\n\t\t\t\t\t!selected ||\n\t\t\t\t\t!turn ||\n\t\t\t\t\t(turn.kind !== \"llm\" && turn.kind !== \"automatic\") ||\n\t\t\t\t\tbefore.process.lifecycleStatus !== \"active\"\n\t\t\t\t)\n\t\t\t\t\tthrow new Error(`Process '${id}' has no active worker turn: ${JSON.stringify(before)}`);\n\t\t\t\texecuting.add(id);\n\t\t\t\tconst previous = new Set(before.turns.map((turn) => turn.id));\n\t\t\t\tobservations.set(id, { prompts: [], toolResults: [] });\n\t\t\t\tscripts.set(id, script);\n\t\t\t\ttry {\n\t\t\t\t\tconst gate = pending.get(id);\n\t\t\t\t\tif (gate) {\n\t\t\t\t\t\tif (gate.turnId !== selected)\n\t\t\t\t\t\t\tthrow new Error(\"Pending turn does not match selected turn\");\n\t\t\t\t\t\tgate.resolve();\n\t\t\t\t\t} else permits.add(id);\n\t\t\t\t\tconst after = await waitFor(\n\t\t\t\t\t\t(current) =>\n\t\t\t\t\t\t\tcurrent.turns.some((turn) => !previous.has(turn.id) && turn.status !== \"running\") ||\n\t\t\t\t\t\t\tcurrent.process.lifecycleStatus === \"error\",\n\t\t\t\t\t\t{ description: `durable outcome of ${selected}` },\n\t\t\t\t\t);\n\t\t\t\t\tconst record = after.turns.find((turn) => !previous.has(turn.id));\n\t\t\t\t\tconst milestone = record\n\t\t\t\t\t\t? context().deps.turnAnnotations.findByKey(id, `turn_milestone:${record.id}`)\n\t\t\t\t\t\t: null;\n\t\t\t\t\treturn observe({\n\t\t\t\t\t\tturn: record ?? null,\n\t\t\t\t\t\toutcome:\n\t\t\t\t\t\t\ttypeof milestone?.payload.outcome === \"string\" ? milestone.payload.outcome : null,\n\t\t\t\t\t\tfailure:\n\t\t\t\t\t\t\trecord?.errorSummary ??\n\t\t\t\t\t\t\t(after.process.lifecycleStatus === \"error\"\n\t\t\t\t\t\t\t\t? \"Worker start failed before acceptance\"\n\t\t\t\t\t\t\t\t: null),\n\t\t\t\t\t\tprompts: observations.get(id)?.prompts ?? [],\n\t\t\t\t\t\ttoolResults: observations.get(id)?.toolResults ?? [],\n\t\t\t\t\t\tresult:\n\t\t\t\t\t\t\trecord?.status === \"succeeded\" && record.turnResultMarkdown\n\t\t\t\t\t\t\t\t? { kind: \"turn_result\" as const, turnRecordId: record.id }\n\t\t\t\t\t\t\t\t: null,\n\t\t\t\t\t});\n\t\t\t\t} finally {\n\t\t\t\t\texecuting.delete(id);\n\t\t\t\t\tscripts.delete(id);\n\t\t\t\t\tpermits.delete(id);\n\t\t\t\t}\n\t\t\t},\n\t\t\t/** Execute an application action. @public */\n\t\t\taction: (actionId, input = {}) =>\n\t\t\t\tpost(`${prefix}/actions/${encodeURIComponent(actionId)}`, { input }),\n\t\t\t/** Retry the failed execution through the application command. @public */\n\t\t\tretry: () => post(`${prefix}/retry`),\n\t\t\t/** Queue an instruction using the application command and normal delivery. @public */\n\t\t\tasync supplyInput(input) {\n\t\t\t\tconst result = await context().deps.processEngine.queueInputs(id, [\n\t\t\t\t\t{\n\t\t\t\t\t\tsource: \"app_steer\",\n\t\t\t\t\t\tkind: \"instruction\",\n\t\t\t\t\t\tbodyMarkdown: input.bodyMarkdown,\n\t\t\t\t\t\t...(input.product ? { target: { productName: input.product } } : {}),\n\t\t\t\t\t},\n\t\t\t\t]);\n\t\t\t\tif (!result.ok) throw new Error(`Input rejected: ${result.message}`);\n\t\t\t\treturn snapshot();\n\t\t\t},\n\t\t\t/** Answer an open question request. @public */\n\t\t\tanswerQuestions: (requestId, answers) =>\n\t\t\t\tpost(`${prefix}/question-requests/${encodeURIComponent(requestId)}/answers`, {\n\t\t\t\t\tdraft: answers,\n\t\t\t\t}),\n\t\t\t/** Resolve an open tool approval. @public */\n\t\t\trespondToApproval: (requestId, response) =>\n\t\t\t\tpost(`${prefix}/tool-approval-requests/${encodeURIComponent(requestId)}`, response),\n\t\t};\n\t}\n\treturn {\n\t\t/** Observe discovered processes. @public */\n\t\tprocesses: () => observe(context().deps.processes.listAll()),\n\t\t/** Send an HTTP-shaped request, retaining error status and body. @public */\n\t\trequest,\n\t\t/** Get a handle that remains valid across restart. @public */\n\t\tprocess: processHandle,\n\t\t/** Admit work through a registered UI launcher. @public */\n\t\tasync launch(id, input) {\n\t\t\tconst response = await postImmediateLaunch(context().config.server.base_url, id, {\n\t\t\t\tlauncherInput: input,\n\t\t\t});\n\t\t\tconst body = (await response.json()) as { process?: { id: string } };\n\t\t\tif (!response.ok || !body.process)\n\t\t\t\tthrow new Error(`Launch '${id}' failed: ${JSON.stringify(body)}`);\n\t\t\treturn processHandle(body.process.id);\n\t\t},\n\t\t/** Create validated business data and start an active position through the engine. @public */\n\t\tasync createProcess(definition, input = {}) {\n\t\t\tif (catalog.processes.get(definition.id) !== definition)\n\t\t\t\tthrow new Error(`Process '${definition.id}' must be registered by an extension`);\n\t\t\tconst fixture = createProcessFixture(input, definition);\n\t\t\tconst { deps } = context();\n\t\t\tconst process = deps.transaction((repos) => {\n\t\t\t\tconst process = repos.processes.create({\n\t\t\t\t\tprocessId: definition.id,\n\t\t\t\t\ttitle: fixture.title,\n\t\t\t\t\texternalId: fixture.externalId,\n\t\t\t\t\texternalUrl: fixture.externalUrl,\n\t\t\t\t\tmetadata: fixture.metadata,\n\t\t\t\t\tparamsJson: fixture.paramsJson,\n\t\t\t\t\tstateJson: fixture.stateJson,\n\t\t\t\t\tselectedTurnId: fixture.selectedTurnId,\n\t\t\t\t\tlifecycleStatus:\n\t\t\t\t\t\tfixture.lifecycleStatus === \"active\" ? \"waiting\" : fixture.lifecycleStatus,\n\t\t\t\t});\n\t\t\t\tif (fixture.planRevision !== 0)\n\t\t\t\t\trepos.processes.update(process.id, { planRevision: fixture.planRevision });\n\t\t\t\tfor (const project of input.projects ?? [])\n\t\t\t\t\trepos.projects.create({\n\t\t\t\t\t\tinstanceId: process.id,\n\t\t\t\t\t\tkey: project.key,\n\t\t\t\t\t\trepoLocator: project.repoLocator,\n\t\t\t\t\t\tbaseBranch: project.baseBranch,\n\t\t\t\t\t\tworkBranch: project.workBranch,\n\t\t\t\t\t\tmetadata: project.metadata,\n\t\t\t\t\t\texternalId: project.externalId,\n\t\t\t\t\t\texternalUrl: project.externalUrl,\n\t\t\t\t\t\tpipelineStatus: project.pipelineStatus,\n\t\t\t\t\t});\n\t\t\t\treturn process;\n\t\t\t});\n\t\t\tif (fixture.lifecycleStatus === \"active\" && fixture.selectedTurnId) {\n\t\t\t\tconst result = await deps.processEngine.startProcess(process.id, fixture.selectedTurnId);\n\t\t\t\tif (!result.ok) throw new Error(`Process start failed: ${result.message}`);\n\t\t\t}\n\t\t\treturn processHandle(process.id);\n\t\t},\n\t\t/** Reopen the same file-backed storage and retain existing handles. @public */\n\t\tasync restart(restartOptions = {}) {\n\t\t\tif (executing.size) throw new Error(\"Cannot restart during runTurn\");\n\t\t\tconst { deps } = context();\n\t\t\tconst paused = manual\n\t\t\t\t? deps.processes.listAll().flatMap((process) => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tprocess.lifecycleStatus !== \"active\" ||\n\t\t\t\t\t\t\tprocess.currentExecution?.kind !== \"worker_start\"\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn [];\n\t\t\t\t\t\tconst start = deps.turnStarts.getById(process.currentExecution.id);\n\t\t\t\t\t\treturn start?.state.kind === \"starting\"\n\t\t\t\t\t\t\t? [{ instanceId: process.id, startId: start.id }]\n\t\t\t\t\t\t\t: [];\n\t\t\t\t\t})\n\t\t\t\t: [];\n\t\t\tawait persistent.close();\n\t\t\tif (restartOptions.extensionConfig)\n\t\t\t\toptions.extensionConfig = structuredClone(restartOptions.extensionConfig);\n\t\t\tawait restartOptions.whileStopped?.();\n\t\t\tpending.clear();\n\t\t\tpermits.clear();\n\t\t\tscripts.clear();\n\t\t\tawait open();\n\t\t\tfor (const pausedStart of paused) {\n\t\t\t\tif (context().deps.processes.getById(pausedStart.instanceId)?.lifecycleStatus !== \"error\")\n\t\t\t\t\tcontinue;\n\t\t\t\tconst result = await context().deps.processEngine.retryStartup(\n\t\t\t\t\tpausedStart.instanceId,\n\t\t\t\t\tpausedStart.startId,\n\t\t\t\t);\n\t\t\t\tif (!result.ok)\n\t\t\t\t\tthrow new Error(`Cannot restore paused turn after restart: ${result.message}`);\n\t\t\t}\n\t\t},\n\t\t/** Release all resources and remove harness-owned files. @public */\n\t\tasync close() {\n\t\t\tif (closed) return;\n\t\t\tclosed = true;\n\t\t\ttry {\n\t\t\t\tawait persistent.dispose();\n\t\t\t} finally {\n\t\t\t\tpending.clear();\n\t\t\t\tpermits.clear();\n\t\t\t\tscripts.clear();\n\t\t\t}\n\t\t},\n\t};\n}\n","import { mkdtempSync, rmSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport path from \"node:path\";\nimport 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 {\n\tcreateInProcessWorkerSpawn,\n\ttype InProcessWorkerSpawnOptions,\n} from \"./in-process-worker.js\";\n\n/** @public */\nexport interface IntegrationHarness<\n\tTResources extends Record<string, unknown> = Record<string, never>,\n> {\n\t/** @public */\n\tctx: AppContext;\n\t/** @public */\n\tclose(): Promise<void>;\n\t/** @internal */\n\tconfig: LeitwerkConfig;\n\t/** @public */\n\taddress: string;\n\t/** @internal */\n\tresources: TResources;\n}\n\n/** @public */\nexport interface IntegrationHarnessOptions<\n\tTResources extends Record<string, unknown> = Record<string, never>,\n> {\n\t/** @internal */\n\tconfig?: LeitwerkConfig;\n\t/** @public */\n\tconfigOverride?: (config: LeitwerkConfig) => void;\n\t/** @public */\n\tappOverrides?: Partial<AppOptions>;\n\t/** @internal */\n\tlisten?: boolean;\n\t/** Start background services when binding a listener. Defaults to true. @public */\n\tbackgroundServices?: boolean;\n\t/** @internal */\n\tinProcessWorkers?: boolean | Omit<InProcessWorkerSpawnOptions, \"extensionCatalog\">;\n\t/** @public */\n\textensionCatalog: ExtensionCatalog | Promise<ExtensionCatalog>;\n\t/** @internal */\n\tpreProvidedCapabilities?: readonly ProvidedCapability[];\n\t/** @internal */\n\tresources?: TResources;\n}\n\n/** Owns disposable file-backed storage; close retains it for the next open, dispose removes it. @internal */\nexport function createPersistentIntegrationFixture(\n\tprefix: string,\n\tconfigure?: (config: LeitwerkConfig) => void,\n) {\n\tconst root = mkdtempSync(path.join(tmpdir(), prefix));\n\tlet harness: IntegrationHarness | undefined;\n\t/** @internal */\n\tfunction createConfig() {\n\t\tconst config = getDefaultConfig();\n\t\tconfig.storage.sqlite_path = path.join(root, \"state.sqlite\");\n\t\tconfig.storage.process_workspaces_dir = path.join(root, \"workspaces\");\n\t\tconfig.storage.tree_files_dir = path.join(root, \"trees\");\n\t\tconfig.pi.agent_dir = path.join(root, \"pi\");\n\t\tconfigure?.(config);\n\t\treturn config;\n\t}\n\t/** @internal */\n\tasync function close() {\n\t\tawait harness?.close();\n\t\tharness = undefined;\n\t}\n\treturn {\n\t\t/** @internal */\n\t\troot,\n\t\t/** @internal */\n\t\tcreateConfig,\n\t\t/** @internal */\n\t\tcontext() {\n\t\t\tif (!harness) throw new Error(\"Fixture is not open\");\n\t\t\treturn harness.ctx;\n\t\t},\n\t\t/** @internal */\n\t\tasync open(options: IntegrationHarnessOptions) {\n\t\t\tharness = await createIntegrationHarness({\n\t\t\t\t...options,\n\t\t\t\tconfig: options.config ?? createConfig(),\n\t\t\t});\n\t\t\treturn harness;\n\t\t},\n\t\t/** @internal */\n\t\tclose,\n\t\t/** @internal */\n\t\tasync dispose() {\n\t\t\ttry {\n\t\t\t\tawait close();\n\t\t\t} finally {\n\t\t\t\trmSync(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });\n\t\t\t}\n\t\t},\n\t};\n}\n/** @public */\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\t...(typeof opts.inProcessWorkers === \"object\" ? opts.inProcessWorkers : {}),\n\t\t\textensionCatalog,\n\t\t});\n\t}\n\tconst ctx = await createAppContext(appOpts);\n\n\tlet address = \"\";\n\ttry {\n\t\tif (opts.listen !== false) {\n\t\t\tif (opts.backgroundServices !== false) {\n\t\t\t\t({ address } = await ctx.listen({\n\t\t\t\t\thost: \"127.0.0.1\",\n\t\t\t\t\tport: 0,\n\t\t\t\t\tuseBoundAddressAsBaseUrl: true,\n\t\t\t\t}));\n\t\t\t} else {\n\t\t\t\taddress = await ctx.app.listen({ host: \"127.0.0.1\", port: 0 });\n\t\t\t\tctx.config.server.base_url = address;\n\t\t\t}\n\t\t}\n\t} catch (error) {\n\t\tawait ctx.close().catch(() => {});\n\t\tthrow error;\n\t}\n\n\treturn {\n\t\tctx,\n\t\tclose: () => ctx.close(),\n\t\tconfig,\n\t\tget address() {\n\t\t\treturn address || (ctx.app.server.listening ? ctx.config.server.base_url : \"\");\n\t\t},\n\t\tresources: opts.resources ?? ({} as TResources),\n\t};\n}\n","/** @public */\nexport 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 { ProcessInstance } from \"@leitwerk-dev/domain\";\nimport type { AppContext } from \"@leitwerk-dev/server\";\nimport { waitForValue } from \"./polling.js\";\n\n/** Drive a running or restarted app without bypassing process HTTP actions. @public */\nexport function createProcessDriver(context: () => AppContext) {\n\t/** @public */\n\tasync function post(url: string, payload: Record<string, unknown> = {}) {\n\t\tconst response = await context().app.inject({ method: \"POST\", url, payload });\n\t\tif (response.statusCode !== 200)\n\t\t\tthrow new Error(`POST ${url} failed with ${response.statusCode}: ${response.body}`);\n\t\treturn response;\n\t}\n\t/** @public */\n\tasync function waitForProcess(\n\t\tid: string,\n\t\tpredicate: (process: ProcessInstance) => boolean,\n\t\tdescription: string,\n\t\ttimeout = 12000,\n\t\tallowError = false,\n\t): Promise<ProcessInstance> {\n\t\ttry {\n\t\t\tconst process = await waitForValue(\n\t\t\t\t() => {\n\t\t\t\t\tconst current = context().deps.processes.getById(id);\n\t\t\t\t\tif (current?.lifecycleStatus === \"error\" && !allowError)\n\t\t\t\t\t\tthrow new Error(\"Process entered error lifecycle\");\n\t\t\t\t\treturn current;\n\t\t\t\t},\n\t\t\t\t(process) => !!process && predicate(process),\n\t\t\t\ttimeout,\n\t\t\t);\n\t\t\tif (!process) throw new Error(\"Missing process\");\n\t\t\treturn process;\n\t\t} catch (error) {\n\t\t\tconst { processes, turnRecords } = context().deps;\n\t\t\tthrow new Error(\n\t\t\t\t`Waiting for ${id}: ${description}; ${JSON.stringify({ process: processes.getById(id), turns: turnRecords.listByInstance(id) })}`,\n\t\t\t\t{ cause: error },\n\t\t\t);\n\t\t}\n\t}\n\treturn {\n\t\t/** @public */\n\t\tpost,\n\t\t/** @public */\n\t\twaitForProcess,\n\t\t/** @public */\n\t\twait: (id: string, turn: string | null, lifecycle = \"waiting\", timeout = 12000) =>\n\t\t\twaitForProcess(\n\t\t\t\tid,\n\t\t\t\t(p) => p.selectedTurnId === turn && p.lifecycleStatus === lifecycle,\n\t\t\t\t`${turn}/${lifecycle}`,\n\t\t\t\ttimeout,\n\t\t\t\tlifecycle === \"error\",\n\t\t\t),\n\t\t/** @public */\n\t\taction: (id: string, action: string, input: Record<string, unknown> = {}) =>\n\t\t\tpost(`/api/processes/${encodeURIComponent(id)}/actions/${encodeURIComponent(action)}`, {\n\t\t\t\tinput,\n\t\t\t}),\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAIA,SAAS,kBAAkB;AAC3B,OAAOA,WAAU;AAQjB,SAAS,wCAAwC;AACjD;AAAA,EACC;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OACM;AACP,SAAS,uCAAuC;;;ACvBhD,SAAS,aAAa,cAAc;AACpC,SAAS,cAAc;AACvB,OAAO,UAAU;AAGjB;AAAA,EAGC;AAAA,EACA;AAAA,OAEM;AA+CA,SAAS,mCACf,QACA,WACC;AACD,QAAM,OAAO,YAAY,KAAK,KAAK,OAAO,GAAG,MAAM,CAAC;AACpD,MAAI;AAEJ,WAAS,eAAe;AACvB,UAAM,SAAS,iBAAiB;AAChC,WAAO,QAAQ,cAAc,KAAK,KAAK,MAAM,cAAc;AAC3D,WAAO,QAAQ,yBAAyB,KAAK,KAAK,MAAM,YAAY;AACpE,WAAO,QAAQ,iBAAiB,KAAK,KAAK,MAAM,OAAO;AACvD,WAAO,GAAG,YAAY,KAAK,KAAK,MAAM,IAAI;AAC1C,gBAAY,MAAM;AAClB,WAAO;AAAA,EACR;AAEA,iBAAe,QAAQ;AACtB,UAAM,SAAS,MAAM;AACrB,cAAU;AAAA,EACX;AACA,SA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1D,GAAG,IAAI,IAAI,SAAS;AAAA,MACpB;AAAA,MACA,cAAc;AAAA,IACf;AAAA;AAAA,IAED,QAAQ,CAAC,IAAY,QAAgB,QAAiC,CAAC,MACtE,KAAK,kBAAkB,mBAAmB,EAAE,CAAC,YAAY,mBAAmB,MAAM,CAAC,IAAI;AAAA,MACtF;AAAA,IACD,CAAC;AAAA,EACH;AACD;","names":["path","session","path","options","turn","process","process"]}
|
|
1
|
+
{"version":3,"sources":["../src/extension-integration-harness.ts","../src/integration-harness.ts","../src/polling.ts","../src/process-driver.ts"],"sourcesContent":["import type { ExtensionTestCapability } from \"./test-capability.js\";\n\nexport type { ExtensionTestCapability } from \"./test-capability.js\";\n\nimport { randomUUID } from \"node:crypto\";\nimport path from \"node:path\";\nimport type {\n\tActor,\n\tExternalWriteLog,\n\tLaunchModelConfigInput,\n\tProcessInstance,\n\tProcessProject,\n\tProcessTurnRecord,\n} from \"@leitwerk-dev/domain\";\nimport { buildExtensionCatalogFromModules } from \"@leitwerk-dev/extension-runtime/testing\";\nimport {\n\tcoreHostCapabilities,\n\ttype ExtensionProcessDefinition,\n\ttype LeitwerkExtensionModule,\n} from \"@leitwerk-dev/process-sdk\";\nimport {\n\tcreateAcceptedWorkerTurn,\n\tprepareAcceptedFixtureStart,\n} from \"@leitwerk-dev/server/testing\";\nimport { persistPiResourceBundleForStart } from \"@leitwerk-dev/worker\";\nimport { postImmediateLaunch } from \"./http-launch.js\";\nimport { createPersistentIntegrationFixture } from \"./integration-harness.js\";\nimport { observe, type TestObservation } from \"./observations.js\";\nimport { createProcessFixture, type ProcessFixtureOptions } from \"./process-fixtures.js\";\nimport type { QuestionRequestFixture } from \"./supported-question-fixtures.js\";\nimport { formatBranchText, StubPiTreeHandleFactory } from \"./worker-testing/stub-pi-tree-handle.js\";\n\n/** Model-visible inputs for a scripted invocation. @public */\nexport interface IntegrationPromptObservation {\n\t/** @public */\n\tturnId: string;\n\t/** Working directory available for fixture repository edits. @public */\n\tcwd: string;\n\t/** Opaque branch-session identity for comparing execution relationships. @public */\n\tbranchId: string;\n\t/** Text inherited by the current branch. @public */\n\thistory: string;\n\t/** @public */\n\ttools: readonly {\n\t\t/** @public */\n\t\tname: string;\n\t\t/** @public */\n\t\tparameters: Record<string, unknown>;\n\t}[];\n}\n\n/** Rendered result retained at a tree leaf. @public */\nexport interface IntegrationLeafObservation {\n\t/** @public */\n\tid: string;\n\t/** @public */\n\tinstanceId: string;\n\t/** @public */\n\tleafEntryId: string;\n\t/** @public */\n\tturnRecordId: string | null;\n\t/** @public */\n\trendererId: string | null;\n\t/** @public */\n\tschemaVersion: number | null;\n\t/** @public */\n\tprops: Record<string, unknown> | null;\n\t/** @public */\n\tfallbackMarkdown: string | null;\n\t/** @public */\n\tstatus: \"ready\" | \"capture_error\";\n}\n\n/** Recorded semantic event. @public */\nexport interface IntegrationEventObservation {\n\t/** @public */\n\tid: string;\n\t/** @public */\n\teventType: string;\n\t/** @public */\n\tdata: Record<string, unknown>;\n\t/** @public */\n\tcreatedAt: string;\n}\n\n/** Durable annotation of process execution. @public */\nexport interface IntegrationAnnotationObservation {\n\t/** @public */\n\tid: string;\n\t/** @public */\n\tannotationType: string;\n\t/** @public */\n\tpayload: Record<string, unknown>;\n}\n\n/** One scripted model prompt, executed through registered tools. @public */\nexport interface IntegrationTurnScript {\n\t/** @public */\n\ttools: readonly IntegrationToolCall[];\n\t/** Scripted reasoning retained by the normal worker path. @public */\n\tthinking?: readonly string[];\n\t/** Assistant markdown for turns completed by model output. @public */\n\tmarkdown?: string;\n\t/** Optional model response after an integration-tool result. @public */\n\tafterToolResult?(call: IntegrationToolCall, result: unknown): IntegrationToolCall | undefined;\n}\n\n/** @public */\nexport interface IntegrationToolCall {\n\t/** @public */\n\tname: string;\n\t/** @public */\n\targuments: Record<string, unknown>;\n}\n\n/** Instruction delivered through the application's durable input queue. @public */\nexport interface IntegrationProcessInput {\n\t/** @public */\n\tbodyMarkdown: string;\n\t/** Target a published product branch. @public */\n\tproduct?: string;\n}\n\n/** Durable instruction delivery observations. @public */\nexport interface IntegrationInputObservation {\n\t/** @public */\n\tid: string;\n\t/** @public */\n\tinstanceId: string;\n\t/** @public */\n\tsequence: number;\n\t/** @public */\n\tsource: string;\n\t/** @public */\n\tkind: string;\n\t/** @public */\n\tbodyMarkdown: string;\n\t/** @public */\n\ttarget: {\n\t\t/** @public */\n\t\tproductName?: string;\n\t\t/** @public */\n\t\tsemanticRef?: string;\n\t} | null;\n\t/** @public */\n\tactor: Actor;\n\t/** @public */\n\treceivedAt: string;\n\t/** @public */\n\tconsumedAt: string | null;\n}\n\n/** Operator approval observations. @public */\nexport interface IntegrationApprovalObservation {\n\t/** @public */\n\tid: string;\n\t/** @public */\n\tinstanceId: string;\n\t/** @public */\n\tturnRecordId: string;\n\t/** @public */\n\ttoolCallId: string;\n\t/** @public */\n\ttoolName: string;\n\t/** @public */\n\targuments: Record<string, unknown>;\n\t/** @public */\n\tdestination: {\n\t\t/** @public */\n\t\tid: string;\n\t\t/** @public */\n\t\tdisplayName: string;\n\t\t/** @public */\n\t\tgroup?: string;\n\t\t/** @public */\n\t\tdescription?: string;\n\t} | null;\n\t/** @public */\n\tstatus: \"open\" | \"accepted\" | \"feedback\" | \"declined\" | \"cancelled\";\n\t/** @public */\n\trequestedAt: string;\n\t/** @public */\n\tresolvedAt: string | null;\n\t/** @public */\n\tresolvedBy: Actor | null;\n\t/** @public */\n\tfeedback: string | null;\n}\n\n/** Explicit accepted execution setup, independent of process business state. @public */\nexport interface AcceptedTurnFixture {\n\t/** @public */\n\tturnId: string;\n\t/** @public */\n\texecution:\n\t\t| {\n\t\t\t\t/** @public */\n\t\t\t\tstatus: \"running\";\n\t\t }\n\t\t| {\n\t\t\t\t/** @public */\n\t\t\t\tstatus: \"succeeded\";\n\t\t\t\t/** @public */\n\t\t\t\toutcome: string;\n\t\t\t\t/** @public */\n\t\t\t\tmarkdown: string;\n\t\t };\n}\n\n/** Detached durable observations. @public */\nexport interface ExtensionIntegrationSnapshot {\n\t/** Harness-owned process workspace. @public */\n\tworkspaceRoot: string;\n\t/** @public */\n\tevents: IntegrationEventObservation[];\n\t/** @public */\n\tannotations: IntegrationAnnotationObservation[];\n\t/** @public */\n\tleafOutcomes: IntegrationLeafObservation[];\n\n\t/** @public */\n\tprocess: ProcessInstance;\n\t/** @public */\n\tparams: unknown;\n\t/** @public */\n\tstate: unknown;\n\t/** @public */\n\tprojects: ProcessProject[];\n\t/** @public */\n\tturns: ProcessTurnRecord[];\n\t/** @public */\n\tinputs: IntegrationInputObservation[];\n\t/** @public */\n\tquestions: QuestionRequestFixture[];\n\t/** @public */\n\tapprovals: IntegrationApprovalObservation[];\n\t/** @public */\n\twriteReceipts: ExternalWriteLog[];\n}\n\n/** @public */\nexport interface ExtensionIntegrationHarnessOptions {\n\t/** Per-process watcher configuration. @public */\n\twatchers?: Readonly<Record<string, Record<string, unknown>>>;\n\t/** Advance extension provider pollers explicitly in tests. @public */\n\tpolling?: \"automatic\" | \"manual\";\n\t/** Host Docker boundary for extensions which require it. @public */\n\thostDocker?: {\n\t\t/** @public */\n\t\tpreflight(timeoutMs: number): Promise<void>;\n\t};\n\n\t/** Configuration keyed by extension manifest id. @public */\n\textensionConfig?: Readonly<Record<string, unknown>>;\n\t/** @public */\n\textensions: readonly LeitwerkExtensionModule[];\n\t/** @public */\n\tcapabilities?: readonly ExtensionTestCapability[];\n\t/** Automatic execution starts admitted work immediately. @public */\n\texecution?: \"automatic\" | \"manual\";\n\t/** Model catalog used by the supplied provider extensions. @public */\n\tmodels?: readonly {\n\t\t/** @public */\n\t\tid: string;\n\t\t/** @public */\n\t\tprovider: string;\n\t\t/** @public */\n\t\tmodelId: string;\n\t\t/** @public */\n\t\tthinkingLevel?: \"off\" | \"minimal\" | \"low\" | \"medium\" | \"high\" | \"xhigh\";\n\t}[];\n\t/** Default model profile for all registered processes. @public */\n\tdefaultModel?: string;\n\t/** Model scripts for automatic execution, in prompt order per process. @public */\n\tscript?(\n\t\tinstanceId: string,\n\t\tprompt: string,\n\t\tobservation: TestObservation<IntegrationPromptObservation>,\n\t): IntegrationTurnScript | Promise<IntegrationTurnScript>;\n}\n\n/** HTTP-shaped requests without a Fastify handle. @public */\nexport interface ExtensionTestRequest {\n\t/** @public */\n\tmethod?: \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\n\t/** @public */\n\turl: string;\n\t/** @public */\n\tpayload?: Record<string, unknown>;\n\t/** @public */\n\theaders?: Record<string, string>;\n}\n\n/** HTTP response observation. @public */\nexport interface ExtensionTestResponse {\n\t/** @public */\n\tstatusCode: number;\n\t/** @public */\n\tbody: string;\n\t/** @public */\n\tjson<T = unknown>(): T;\n}\n\n/** Accepted turn identity and optional retained result. @public */\nexport interface AcceptedTurnReference {\n\t/** @public */\n\tid: string;\n\t/** @public */\n\tinstanceId: string;\n\t/** @public */\n\tturnId: string;\n\t/** @public */\n\tartifact: {\n\t\t/** @public */ kind: \"turn_result\";\n\t\t/** @public */\n\t\tturnRecordId: string;\n\t} | null;\n}\n\n/** One durably settled worker execution. @public */\nexport interface IntegrationTurnResult {\n\t/** @public */\n\tturn: ProcessTurnRecord | null;\n\t/** @public */\n\toutcome: string | null;\n\t/** @public */\n\tfailure: string | null;\n\t/** @public */\n\tprompts: string[];\n\t/** @public */\n\ttoolResults: {\n\t\t/** @public */ name: string;\n\t\t/** @public */\n\t\tresult: unknown;\n\t}[];\n\t/** @public */\n\tresult: AcceptedTurnReference[\"artifact\"];\n}\n\n/** Durable process commands and observations. @public */\nexport interface ExtensionIntegrationProcess {\n\t/** @public */\n\treadonly id: string;\n\t/** @public */\n\tseedAcceptedTurn(fixture: AcceptedTurnFixture): Promise<TestObservation<AcceptedTurnReference>>;\n\t/** @public */\n\tsnapshot(): TestObservation<ExtensionIntegrationSnapshot>;\n\t/** @public */\n\twaitFor(\n\t\tcondition: (snapshot: TestObservation<ExtensionIntegrationSnapshot>) => boolean,\n\t\toptions?: {\n\t\t\t/** @public */ timeoutMs?: number;\n\t\t\t/** @public */\n\t\t\tdescription?: string;\n\t\t},\n\t): Promise<TestObservation<ExtensionIntegrationSnapshot>>;\n\t/** @public */\n\trunTurn(script?: IntegrationTurnScript): Promise<TestObservation<IntegrationTurnResult>>;\n\t/** @public */\n\taction(id: string, input?: Record<string, unknown>): Promise<ExtensionTestResponse>;\n\t/** @public */\n\tretry(): Promise<ExtensionTestResponse>;\n\t/** @public */\n\tsupplyInput(\n\t\tinput: IntegrationProcessInput,\n\t): Promise<TestObservation<ExtensionIntegrationSnapshot>>;\n\t/** @public */\n\tanswerQuestions(\n\t\tid: string,\n\t\tanswers: readonly {\n\t\t\t/** @public */\n\t\t\tselectedOptionIds: readonly string[];\n\t\t\t/** @public */\n\t\t\tfreeText: string;\n\t\t\t/** @public */\n\t\t\tcomment: string;\n\t\t}[],\n\t): Promise<ExtensionTestResponse>;\n\t/** @public */\n\trespondToApproval(\n\t\tid: string,\n\t\tresponse: {\n\t\t\t/** @public */\n\t\t\taction: \"accept\" | \"feedback\" | \"decline\";\n\t\t\t/** @public */\n\t\t\tfeedback?: string;\n\t\t},\n\t): Promise<ExtensionTestResponse>;\n}\n\n/** Disposable persistent extension test environment. @public */\nexport interface ExtensionIntegrationHarness {\n\t/** Detached processes discovered or launched by extensions. @public */\n\tprocesses(): TestObservation<ProcessInstance[]>;\n\n\t/** @public */\n\trequest(input: ExtensionTestRequest): Promise<ExtensionTestResponse>;\n\t/** @public */\n\tprocess(id: string): ExtensionIntegrationProcess;\n\t/** @public */\n\tlaunch(\n\t\tid: string,\n\t\tinput: Record<string, unknown>,\n\t\tmodelConfig?: LaunchModelConfigInput,\n\t): Promise<ExtensionIntegrationProcess>;\n\t/** @public */\n\tcreateProcess<TParams, TState>(\n\t\tdefinition: ExtensionProcessDefinition<TParams, TState>,\n\t\tinput?: Omit<ProcessFixtureOptions<TParams, TState>, \"id\" | \"processId\"> & {\n\t\t\t/** @public */\n\t\t\tprojects?: readonly ProcessProject[];\n\t\t},\n\t): Promise<ExtensionIntegrationProcess>;\n\t/** @public */\n\trestart(options?: {\n\t\t/** Update extension wiring on the reopened server. @public */\n\t\textensionConfig?: Readonly<Record<string, unknown>>;\n\t\t/** Apply external changes while the server is offline. @public */\n\t\twhileStopped?(): void | Promise<void>;\n\t}): Promise<void>;\n\t/** @public */\n\tclose(): Promise<void>;\n}\n\n/** Own server, workers, and disposable persistent storage. @public */\nexport async function createExtensionIntegrationHarness(\n\toptions: ExtensionIntegrationHarnessOptions,\n): Promise<ExtensionIntegrationHarness> {\n\tconst catalog = await buildExtensionCatalogFromModules([\n\t\t...(options.polling === \"manual\"\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tmanifest: { id: \"test-support-manual-polling\", version: \"1\" },\n\t\t\t\t\t\tsetupServer(api: import(\"@leitwerk-dev/process-sdk\").ServerExtensionAPI) {\n\t\t\t\t\t\t\tconst deps = api.get(coreHostCapabilities.serverSetup);\n\t\t\t\t\t\t\tif (!deps || Array.isArray(deps)) throw new Error(\"Missing polling host\");\n\t\t\t\t\t\t\tdeps.polling = {\n\t\t\t\t\t\t\t\tcreate(input) {\n\t\t\t\t\t\t\t\t\treturn { poll: input.pollOnce };\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: []),\n\t\t...options.extensions,\n\t]);\n\tconst persistent = createPersistentIntegrationFixture(\"leitwerk-extension-test-\", (config) => {\n\t\tconfig.extensions = structuredClone(options.extensionConfig ?? {});\n\t\tif (options.hostDocker && config.local_worker) config.local_worker.allow_host_docker = true;\n\t\tconfig.pi.model_profiles = (options.models ?? []).map((model) => ({\n\t\t\tid: model.id,\n\t\t\tprovider: model.provider,\n\t\t\tmodel_id: model.modelId,\n\t\t\tthinking_level: model.thinkingLevel ?? \"off\",\n\t\t}));\n\t\tif (options.defaultModel) {\n\t\t\tconfig.pi.default_model_profile = options.defaultModel;\n\t\t\tconfig.pi.process_title_generation.model_profile = options.defaultModel;\n\t\t\tconfig.process_configs = Object.fromEntries(\n\t\t\t\t[...catalog.processes.keys()].map((id) => [\n\t\t\t\t\tid,\n\t\t\t\t\t{\n\t\t\t\t\t\tdefault_model_profile: options.defaultModel,\n\t\t\t\t\t\tturn_configs: {},\n\t\t\t\t\t\twatchers: structuredClone(options.watchers?.[id] ?? {}),\n\t\t\t\t\t},\n\t\t\t\t]),\n\t\t\t);\n\t\t}\n\t});\n\tconst manual = options.execution === \"manual\";\n\tlet closed = false;\n\tconst pending = new Map<string, { turnId: string; resolve(): void }>();\n\tconst permits = new Set<string>();\n\tconst executing = new Set<string>();\n\tconst scripts = new Map<string, IntegrationTurnScript>();\n\tconst observations = new Map<\n\t\tstring,\n\t\t{ prompts: string[]; toolResults: { name: string; result: unknown }[] }\n\t>();\n\tconst context = () => {\n\t\tif (closed) throw new Error(\"Extension integration harness is closed\");\n\t\treturn persistent.context();\n\t};\n\tasync function open() {\n\t\tconst piFactory: StubPiTreeHandleFactory = new StubPiTreeHandleFactory({\n\t\t\trecordSessionTrace: true,\n\t\t\ttoolCallScriptResolver: async (input) => {\n\t\t\t\tconst id = input.instanceId;\n\t\t\t\tif (!id) throw new Error(\"Scripted prompt has no process identity\");\n\t\t\t\tconst observation = observations.get(id) ?? { prompts: [], toolResults: [] };\n\t\t\t\tobservations.set(id, observation);\n\t\t\t\tconst prompt = input.identifiedPromptText ?? input.promptText;\n\t\t\t\tobservation.prompts.push(prompt);\n\t\t\t\tconst session = [...piFactory.sessions]\n\t\t\t\t\t.reverse()\n\t\t\t\t\t.find((session) => session.treeFile === input.treeFile);\n\t\t\t\tconst history = formatBranchText(session?.getBranch(), \"\");\n\t\t\t\tconst script = manual\n\t\t\t\t\t? scripts.get(id)\n\t\t\t\t\t: await options.script?.(\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\tprompt,\n\t\t\t\t\t\t\tobserve({\n\t\t\t\t\t\t\t\tturnId: context().deps.processes.getById(id)?.selectedTurnId ?? \"\",\n\t\t\t\t\t\t\t\tcwd: input.sessionCwd ?? input.workspaceRoot ?? \"\",\n\t\t\t\t\t\t\t\tbranchId: session?.sessionId ?? \"\",\n\t\t\t\t\t\t\t\thistory,\n\t\t\t\t\t\t\t\ttools: input.tools.map((tool) => ({\n\t\t\t\t\t\t\t\t\tname: tool.name,\n\t\t\t\t\t\t\t\t\tparameters: tool.parameters,\n\t\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\tscripts.delete(id);\n\t\t\t\tif (!script || (script.tools.length === 0 && script.markdown === undefined))\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Script exhausted for process '${id}' after ${observation.prompts.length} prompt(s)`,\n\t\t\t\t\t);\n\t\t\t\treturn {\n\t\t\t\t\tthinkingChunks: script.thinking ? [...script.thinking] : undefined,\n\t\t\t\t\ttextChunks: script.markdown === undefined ? undefined : [script.markdown],\n\t\t\t\t\tcalls: script.tools.map((call) => ({\n\t\t\t\t\t\ttoolName: call.name,\n\t\t\t\t\t\targs: structuredClone(call.arguments),\n\t\t\t\t\t})),\n\t\t\t\t\tafterToolResult(call, result) {\n\t\t\t\t\t\tobservation.toolResults.push({ name: call.toolName, result: structuredClone(result) });\n\t\t\t\t\t\tconst next = script.afterToolResult?.(\n\t\t\t\t\t\t\t{ name: call.toolName, arguments: structuredClone(call.args) },\n\t\t\t\t\t\t\tstructuredClone(result),\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn next ? { toolName: next.name, args: next.arguments } : undefined;\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t},\n\t\t});\n\t\tawait persistent.open({\n\t\t\tappOverrides: options.hostDocker\n\t\t\t\t? { localWorkerDockerPreflightImpl: options.hostDocker.preflight }\n\t\t\t\t: undefined,\n\t\t\textensionCatalog: catalog,\n\t\t\tpreProvidedCapabilities: options.capabilities,\n\t\t\tinProcessWorkers: {\n\t\t\t\tpiFactory,\n\t\t\t\tbeforeTurnBootstrap: manual\n\t\t\t\t\t? (id, turnId, signal) =>\n\t\t\t\t\t\t\tnew Promise<void>((resolve, reject) => {\n\t\t\t\t\t\t\t\tif (signal.aborted) {\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (permits.delete(id)) {\n\t\t\t\t\t\t\t\t\tresolve();\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tif (pending.has(id)) {\n\t\t\t\t\t\t\t\t\treject(new Error(`Conflicting pending worker for '${id}'`));\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst abort = () => {\n\t\t\t\t\t\t\t\t\tpending.delete(id);\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\tsignal.addEventListener(\"abort\", abort, { once: true });\n\t\t\t\t\t\t\t\tpending.set(id, {\n\t\t\t\t\t\t\t\t\tturnId,\n\t\t\t\t\t\t\t\t\tresolve() {\n\t\t\t\t\t\t\t\t\t\tsignal.removeEventListener(\"abort\", abort);\n\t\t\t\t\t\t\t\t\t\tpending.delete(id);\n\t\t\t\t\t\t\t\t\t\tresolve();\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})\n\t\t\t\t\t: undefined,\n\t\t\t},\n\t\t});\n\t}\n\ttry {\n\t\tawait open();\n\t} catch (error) {\n\t\tawait persistent.dispose();\n\t\tthrow error;\n\t}\n\t/** @public */\n\tasync function request(input: ExtensionTestRequest) {\n\t\tconst response = await context().app.inject({ ...input, method: input.method ?? \"GET\" });\n\t\treturn {\n\t\t\t/** @public */\n\t\t\tstatusCode: response.statusCode,\n\t\t\t/** @public */\n\t\t\tbody: response.body,\n\t\t\t/** @public */\n\t\t\tjson<T = unknown>(): T {\n\t\t\t\treturn JSON.parse(response.body) as T;\n\t\t\t},\n\t\t};\n\t}\n\tasync function post(url: string, payload: Record<string, unknown> = {}) {\n\t\tconst response = await request({ method: \"POST\", url, payload });\n\t\tif (response.statusCode >= 400)\n\t\t\tthrow new Error(`POST ${url}: ${response.statusCode} ${response.body}`);\n\t\treturn response;\n\t}\n\t/** @public */\n\tfunction processHandle(id: string): ExtensionIntegrationProcess {\n\t\tconst prefix = `/api/processes/${encodeURIComponent(id)}`;\n\t\t/** @public */\n\t\tfunction snapshot(): TestObservation<ExtensionIntegrationSnapshot> {\n\t\t\tconst { deps } = context();\n\t\t\tconst process = deps.processes.getById(id);\n\t\t\tif (!process) throw new Error(`Unknown process '${id}'`);\n\t\t\tconst definition = catalog.processes.get(process.processId);\n\t\t\treturn observe({\n\t\t\t\tworkspaceRoot: path.join(context().config.storage.process_workspaces_dir, id),\n\t\t\t\tevents: deps.events.listByInstance(id),\n\t\t\t\tannotations: deps.turnAnnotations.listByInstance(id),\n\t\t\t\tleafOutcomes: deps.leafOutcomeSnapshots.listByInstance(id),\n\t\t\t\tprocess,\n\t\t\t\tparams: definition?.paramsCodec.parse(JSON.parse(process.paramsJson ?? \"null\")),\n\t\t\t\tstate: definition?.stateCodec.parse(JSON.parse(process.stateJson ?? \"null\")),\n\t\t\t\tprojects: deps.projects.listByInstance(id),\n\t\t\t\tturns: deps.turnRecords.listByInstance(id),\n\t\t\t\tinputs: deps.inputs.listByInstance(id),\n\t\t\t\tquestions: deps.questionRequests.listByInstance(id),\n\t\t\t\tapprovals: deps.toolApprovalRequests.listByInstance(id),\n\t\t\t\twriteReceipts: deps.externalWrites.listByInstance(id),\n\t\t\t});\n\t\t}\n\t\t/** @public */\n\t\tasync function waitFor(\n\t\t\tcondition: (snapshot: TestObservation<ExtensionIntegrationSnapshot>) => boolean,\n\t\t\toptions: Parameters<ExtensionIntegrationProcess[\"waitFor\"]>[1] = {},\n\t\t) {\n\t\t\tconst deadline = Date.now() + (options.timeoutMs ?? 12000);\n\t\t\tfor (;;) {\n\t\t\t\tconst current = snapshot();\n\t\t\t\tif (condition(current)) return current;\n\t\t\t\tif (Date.now() >= deadline)\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Timed out waiting for ${id}: ${options.description ?? \"condition\"}; ${JSON.stringify({\n\t\t\t\t\t\t\tposition: {\n\t\t\t\t\t\t\t\tselectedTurnId: current.process.selectedTurnId,\n\t\t\t\t\t\t\t\tlifecycleStatus: current.process.lifecycleStatus,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tturns: current.turns.map((turn) => ({\n\t\t\t\t\t\t\t\tid: turn.id,\n\t\t\t\t\t\t\t\tturnId: turn.turnId,\n\t\t\t\t\t\t\t\tstatus: turn.status,\n\t\t\t\t\t\t\t\terror: turn.errorSummary,\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\tinputs: current.inputs.map((input) => ({\n\t\t\t\t\t\t\t\tid: input.id,\n\t\t\t\t\t\t\t\tconsumedAt: input.consumedAt,\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\tquestions: current.questions.map((question) => ({\n\t\t\t\t\t\t\t\tid: question.id,\n\t\t\t\t\t\t\t\tstatus: question.status,\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t\tapprovals: current.approvals.map((approval) => ({\n\t\t\t\t\t\t\t\tid: approval.id,\n\t\t\t\t\t\t\t\tstatus: approval.status,\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t})}`,\n\t\t\t\t\t);\n\t\t\t\tawait new Promise((resolve) => setTimeout(resolve, 10));\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\t/** @public */\n\t\t\tid,\n\t\t\t/** Establish correlated accepted records under exclusive server coordination. @public */\n\t\t\tasync seedAcceptedTurn(fixture) {\n\t\t\t\tconst ctx = context();\n\t\t\t\treturn ctx.deps.processOperations.runExclusive(id, async () => {\n\t\t\t\t\tconst process = ctx.deps.processes.getById(id);\n\t\t\t\t\tif (!process) throw new Error(`Unknown process '${id}'`);\n\t\t\t\t\tconst turn = catalog.processes\n\t\t\t\t\t\t.get(process.processId)\n\t\t\t\t\t\t?.turns.get(fixture.turnId)?.definition;\n\t\t\t\t\tif (!turn || (turn.kind !== \"llm\" && turn.kind !== \"automatic\"))\n\t\t\t\t\t\tthrow new Error(`Undeclared worker turn '${fixture.turnId}'`);\n\t\t\t\t\tif (process.currentExecution || ctx.deps.leases.getByInstance(id))\n\t\t\t\t\t\tthrow new Error(\"Cannot seed accepted execution while a live execution exists\");\n\t\t\t\t\tconst running = fixture.execution.status === \"running\";\n\t\t\t\t\tif (running && process.selectedTurnId !== fixture.turnId)\n\t\t\t\t\t\tthrow new Error(\"Running fixture must match the selected turn\");\n\t\t\t\t\tif (\n\t\t\t\t\t\tfixture.execution.status === \"succeeded\" &&\n\t\t\t\t\t\t!Object.hasOwn(turn.outcomes ?? {}, fixture.execution.outcome) &&\n\t\t\t\t\t\tturn.turnEnd?.outcome !== fixture.execution.outcome\n\t\t\t\t\t)\n\t\t\t\t\t\tthrow new Error(`Undeclared outcome '${fixture.execution.outcome}'`);\n\t\t\t\t\tif (fixture.execution.status === \"succeeded\" && !fixture.execution.markdown.trim())\n\t\t\t\t\t\tthrow new Error(\"A successful accepted fixture requires non-empty result markdown\");\n\t\t\t\t\tconst prepared =\n\t\t\t\t\t\tturn.kind === \"llm\"\n\t\t\t\t\t\t\t? await prepareAcceptedFixtureStart(\n\t\t\t\t\t\t\t\t\tctx,\n\t\t\t\t\t\t\t\t\tprocess,\n\t\t\t\t\t\t\t\t\tfixture.turnId,\n\t\t\t\t\t\t\t\t\tcatalog.piContributions,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t: null;\n\t\t\t\t\tconst turnId = `trn_${randomUUID()}`;\n\t\t\t\t\tif (prepared)\n\t\t\t\t\t\tawait persistPiResourceBundleForStart({\n\t\t\t\t\t\t\tbundlesDir: path.join(\n\t\t\t\t\t\t\t\tctx.config.storage.process_workspaces_dir,\n\t\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t\t\".leitwerk\",\n\t\t\t\t\t\t\t\t\"pi-resource-bundles\",\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tstartRecordId: `tsr_${turnId}`,\n\t\t\t\t\t\t\tdigest: prepared.bundle.digest,\n\t\t\t\t\t\t\tdeliveredBundle: prepared.bundle.bytes,\n\t\t\t\t\t\t});\n\t\t\t\t\treturn ctx.deps.transaction((repos) => {\n\t\t\t\t\t\tconst timestamp = new Date().toISOString();\n\t\t\t\t\t\tconst input = {\n\t\t\t\t\t\t\tid: turnId,\n\t\t\t\t\t\t\tinstanceId: id,\n\t\t\t\t\t\t\tturnId: fixture.turnId,\n\t\t\t\t\t\t\tstatus: fixture.execution.status,\n\t\t\t\t\t\t\tattemptNumber:\n\t\t\t\t\t\t\t\tMath.max(\n\t\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\t\t...repos.turnRecords\n\t\t\t\t\t\t\t\t\t\t.listByInstance(id)\n\t\t\t\t\t\t\t\t\t\t.filter((record) => record.turnId === fixture.turnId)\n\t\t\t\t\t\t\t\t\t\t.map((record) => record.attemptNumber),\n\t\t\t\t\t\t\t\t) + 1,\n\t\t\t\t\t\t\tstartedAt: timestamp,\n\t\t\t\t\t\t\tendedAt: running ? null : timestamp,\n\t\t\t\t\t\t\tturnResultMarkdown:\n\t\t\t\t\t\t\t\tfixture.execution.status === \"succeeded\" ? fixture.execution.markdown : null,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tcreateAcceptedWorkerTurn(\n\t\t\t\t\t\t\t{ deps: repos },\n\t\t\t\t\t\t\t{ ...input, turnType: turn.kind, modelProfileId: prepared?.start.model.profileId },\n\t\t\t\t\t\t\t{ current: running, preparedStart: prepared?.start },\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (fixture.execution.status === \"succeeded\")\n\t\t\t\t\t\t\trepos.turnAnnotations.create({\n\t\t\t\t\t\t\t\tinstanceId: id,\n\t\t\t\t\t\t\t\tannotationType: \"turn_milestone\",\n\t\t\t\t\t\t\t\tannotationKey: `turn_milestone:${turnId}`,\n\t\t\t\t\t\t\t\treferences: [{ kind: \"turn_record\", turnRecordId: turnId, role: \"subject\" }],\n\t\t\t\t\t\t\t\tpayload: {\n\t\t\t\t\t\t\t\t\tturnId: fixture.turnId,\n\t\t\t\t\t\t\t\t\tturnType: turn.kind,\n\t\t\t\t\t\t\t\t\tpathType: \"primary\",\n\t\t\t\t\t\t\t\t\toutcome: fixture.execution.outcome,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\tif (running) repos.processes.update(id, { lifecycleStatus: \"active\" });\n\t\t\t\t\t\treturn observe({\n\t\t\t\t\t\t\tid: turnId,\n\t\t\t\t\t\t\tinstanceId: id,\n\t\t\t\t\t\t\tturnId: fixture.turnId,\n\t\t\t\t\t\t\tartifact: running ? null : { kind: \"turn_result\" as const, turnRecordId: turnId },\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t});\n\t\t\t},\n\t\t\t/** Read detached durable business and execution observations. @public */\n\t\t\tsnapshot,\n\t\t\t/** Wait with a bounded deadline and final observations on failure. @public */\n\t\t\twaitFor,\n\t\t\t/** Execute one selected worker turn; resolves after durable completion or failure. @public */\n\t\t\tasync runTurn(script = { tools: [] }) {\n\t\t\t\tif (!manual) throw new Error(\"runTurn requires manual execution mode\");\n\t\t\t\tif (executing.has(id)) throw new Error(`A turn is already running for '${id}'`);\n\t\t\t\tconst before = snapshot();\n\t\t\t\tconst selected = before.process.selectedTurnId;\n\t\t\t\tconst turn = selected\n\t\t\t\t\t? catalog.processes.get(before.process.processId)?.turns.get(selected)?.definition\n\t\t\t\t\t: undefined;\n\t\t\t\tif (\n\t\t\t\t\t!selected ||\n\t\t\t\t\t!turn ||\n\t\t\t\t\t(turn.kind !== \"llm\" && turn.kind !== \"automatic\") ||\n\t\t\t\t\tbefore.process.lifecycleStatus !== \"active\"\n\t\t\t\t)\n\t\t\t\t\tthrow new Error(`Process '${id}' has no active worker turn: ${JSON.stringify(before)}`);\n\t\t\t\texecuting.add(id);\n\t\t\t\tconst previous = new Set(before.turns.map((turn) => turn.id));\n\t\t\t\tobservations.set(id, { prompts: [], toolResults: [] });\n\t\t\t\tscripts.set(id, script);\n\t\t\t\ttry {\n\t\t\t\t\tconst gate = pending.get(id);\n\t\t\t\t\tif (gate) {\n\t\t\t\t\t\tif (gate.turnId !== selected)\n\t\t\t\t\t\t\tthrow new Error(\"Pending turn does not match selected turn\");\n\t\t\t\t\t\tgate.resolve();\n\t\t\t\t\t} else permits.add(id);\n\t\t\t\t\tconst after = await waitFor(\n\t\t\t\t\t\t(current) =>\n\t\t\t\t\t\t\tcurrent.turns.some((turn) => !previous.has(turn.id) && turn.status !== \"running\") ||\n\t\t\t\t\t\t\tcurrent.process.lifecycleStatus === \"error\",\n\t\t\t\t\t\t{ description: `durable outcome of ${selected}` },\n\t\t\t\t\t);\n\t\t\t\t\tconst record = after.turns.find((turn) => !previous.has(turn.id));\n\t\t\t\t\tconst milestone = record\n\t\t\t\t\t\t? context().deps.turnAnnotations.findByKey(id, `turn_milestone:${record.id}`)\n\t\t\t\t\t\t: null;\n\t\t\t\t\treturn observe({\n\t\t\t\t\t\tturn: record ?? null,\n\t\t\t\t\t\toutcome:\n\t\t\t\t\t\t\ttypeof milestone?.payload.outcome === \"string\" ? milestone.payload.outcome : null,\n\t\t\t\t\t\tfailure:\n\t\t\t\t\t\t\trecord?.errorSummary ??\n\t\t\t\t\t\t\t(after.process.lifecycleStatus === \"error\"\n\t\t\t\t\t\t\t\t? \"Worker start failed before acceptance\"\n\t\t\t\t\t\t\t\t: null),\n\t\t\t\t\t\tprompts: observations.get(id)?.prompts ?? [],\n\t\t\t\t\t\ttoolResults: observations.get(id)?.toolResults ?? [],\n\t\t\t\t\t\tresult:\n\t\t\t\t\t\t\trecord?.status === \"succeeded\" && record.turnResultMarkdown\n\t\t\t\t\t\t\t\t? { kind: \"turn_result\" as const, turnRecordId: record.id }\n\t\t\t\t\t\t\t\t: null,\n\t\t\t\t\t});\n\t\t\t\t} finally {\n\t\t\t\t\texecuting.delete(id);\n\t\t\t\t\tscripts.delete(id);\n\t\t\t\t\tpermits.delete(id);\n\t\t\t\t}\n\t\t\t},\n\t\t\t/** Execute an application action. @public */\n\t\t\taction: (actionId, input = {}) =>\n\t\t\t\tpost(`${prefix}/actions/${encodeURIComponent(actionId)}`, { input }),\n\t\t\t/** Retry the failed execution through the application command. @public */\n\t\t\tretry: () => post(`${prefix}/retry`),\n\t\t\t/** Queue an instruction using the application command and normal delivery. @public */\n\t\t\tasync supplyInput(input) {\n\t\t\t\tconst result = await context().deps.processEngine.queueInputs(id, [\n\t\t\t\t\t{\n\t\t\t\t\t\tsource: \"app_steer\",\n\t\t\t\t\t\tkind: \"instruction\",\n\t\t\t\t\t\tbodyMarkdown: input.bodyMarkdown,\n\t\t\t\t\t\t...(input.product ? { target: { productName: input.product } } : {}),\n\t\t\t\t\t},\n\t\t\t\t]);\n\t\t\t\tif (!result.ok) throw new Error(`Input rejected: ${result.message}`);\n\t\t\t\treturn snapshot();\n\t\t\t},\n\t\t\t/** Answer an open question request. @public */\n\t\t\tanswerQuestions: (requestId, answers) =>\n\t\t\t\tpost(`${prefix}/question-requests/${encodeURIComponent(requestId)}/answers`, {\n\t\t\t\t\tdraft: answers,\n\t\t\t\t}),\n\t\t\t/** Resolve an open tool approval. @public */\n\t\t\trespondToApproval: (requestId, response) =>\n\t\t\t\tpost(`${prefix}/tool-approval-requests/${encodeURIComponent(requestId)}`, response),\n\t\t};\n\t}\n\treturn {\n\t\t/** Observe discovered processes. @public */\n\t\tprocesses: () => observe(context().deps.processes.listAll()),\n\t\t/** Send an HTTP-shaped request, retaining error status and body. @public */\n\t\trequest,\n\t\t/** Get a handle that remains valid across restart. @public */\n\t\tprocess: processHandle,\n\t\t/** Admit work through a registered UI launcher. @public */\n\t\tasync launch(id, input, modelConfig) {\n\t\t\tconst response = await postImmediateLaunch(context().config.server.base_url, id, {\n\t\t\t\tlauncherInput: input,\n\t\t\t\t...(modelConfig ? { modelConfig } : {}),\n\t\t\t});\n\t\t\tconst body = (await response.json()) as { process?: { id: string } };\n\t\t\tif (!response.ok || !body.process)\n\t\t\t\tthrow new Error(`Launch '${id}' failed: ${JSON.stringify(body)}`);\n\t\t\treturn processHandle(body.process.id);\n\t\t},\n\t\t/** Create validated business data and start an active position through the engine. @public */\n\t\tasync createProcess(definition, input = {}) {\n\t\t\tif (catalog.processes.get(definition.id) !== definition)\n\t\t\t\tthrow new Error(`Process '${definition.id}' must be registered by an extension`);\n\t\t\tconst fixture = createProcessFixture(input, definition);\n\t\t\tconst { deps } = context();\n\t\t\tconst process = deps.transaction((repos) => {\n\t\t\t\tconst process = repos.processes.create({\n\t\t\t\t\tprocessId: definition.id,\n\t\t\t\t\ttitle: fixture.title,\n\t\t\t\t\texternalId: fixture.externalId,\n\t\t\t\t\texternalUrl: fixture.externalUrl,\n\t\t\t\t\tmetadata: fixture.metadata,\n\t\t\t\t\tparamsJson: fixture.paramsJson,\n\t\t\t\t\tstateJson: fixture.stateJson,\n\t\t\t\t\tselectedTurnId: fixture.selectedTurnId,\n\t\t\t\t\tlifecycleStatus:\n\t\t\t\t\t\tfixture.lifecycleStatus === \"active\" ? \"waiting\" : fixture.lifecycleStatus,\n\t\t\t\t});\n\t\t\t\tif (fixture.planRevision !== 0)\n\t\t\t\t\trepos.processes.update(process.id, { planRevision: fixture.planRevision });\n\t\t\t\tfor (const project of input.projects ?? [])\n\t\t\t\t\trepos.projects.create({\n\t\t\t\t\t\tinstanceId: process.id,\n\t\t\t\t\t\tkey: project.key,\n\t\t\t\t\t\trepoLocator: project.repoLocator,\n\t\t\t\t\t\tbaseBranch: project.baseBranch,\n\t\t\t\t\t\tworkBranch: project.workBranch,\n\t\t\t\t\t\tmetadata: project.metadata,\n\t\t\t\t\t\texternalId: project.externalId,\n\t\t\t\t\t\texternalUrl: project.externalUrl,\n\t\t\t\t\t\tpipelineStatus: project.pipelineStatus,\n\t\t\t\t\t});\n\t\t\t\treturn process;\n\t\t\t});\n\t\t\tif (fixture.lifecycleStatus === \"active\" && fixture.selectedTurnId) {\n\t\t\t\tconst result = await deps.processEngine.startProcess(process.id, fixture.selectedTurnId);\n\t\t\t\tif (!result.ok) throw new Error(`Process start failed: ${result.message}`);\n\t\t\t}\n\t\t\treturn processHandle(process.id);\n\t\t},\n\t\t/** Reopen the same file-backed storage and retain existing handles. @public */\n\t\tasync restart(restartOptions = {}) {\n\t\t\tif (executing.size) throw new Error(\"Cannot restart during runTurn\");\n\t\t\tconst { deps } = context();\n\t\t\tconst paused = manual\n\t\t\t\t? deps.processes.listAll().flatMap((process) => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tprocess.lifecycleStatus !== \"active\" ||\n\t\t\t\t\t\t\tprocess.currentExecution?.kind !== \"worker_start\"\n\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn [];\n\t\t\t\t\t\tconst start = deps.turnStarts.getById(process.currentExecution.id);\n\t\t\t\t\t\treturn start?.state.kind === \"starting\"\n\t\t\t\t\t\t\t? [{ instanceId: process.id, startId: start.id }]\n\t\t\t\t\t\t\t: [];\n\t\t\t\t\t})\n\t\t\t\t: [];\n\t\t\tawait persistent.close();\n\t\t\tif (restartOptions.extensionConfig)\n\t\t\t\toptions.extensionConfig = structuredClone(restartOptions.extensionConfig);\n\t\t\tawait restartOptions.whileStopped?.();\n\t\t\tpending.clear();\n\t\t\tpermits.clear();\n\t\t\tscripts.clear();\n\t\t\tawait open();\n\t\t\tfor (const pausedStart of paused) {\n\t\t\t\tif (context().deps.processes.getById(pausedStart.instanceId)?.lifecycleStatus !== \"error\")\n\t\t\t\t\tcontinue;\n\t\t\t\tconst result = await context().deps.processEngine.retryStartup(\n\t\t\t\t\tpausedStart.instanceId,\n\t\t\t\t\tpausedStart.startId,\n\t\t\t\t);\n\t\t\t\tif (!result.ok)\n\t\t\t\t\tthrow new Error(`Cannot restore paused turn after restart: ${result.message}`);\n\t\t\t}\n\t\t},\n\t\t/** Release all resources and remove harness-owned files. @public */\n\t\tasync close() {\n\t\t\tif (closed) return;\n\t\t\tclosed = true;\n\t\t\ttry {\n\t\t\t\tawait persistent.dispose();\n\t\t\t} finally {\n\t\t\t\tpending.clear();\n\t\t\t\tpermits.clear();\n\t\t\t\tscripts.clear();\n\t\t\t}\n\t\t},\n\t};\n}\n","import { mkdtempSync, rmSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport path from \"node:path\";\nimport type { ExtensionCatalog } from \"@leitwerk-dev/extension-runtime\";\nimport { buildExtensionCatalogFromModules } from \"@leitwerk-dev/extension-runtime/testing\";\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 {\n\tcreateInProcessWorkerSpawn,\n\ttype InProcessWorkerSpawnOptions,\n} from \"./in-process-worker.js\";\nimport { withDefaultModelFixture } from \"./model-provider-fixtures.js\";\n\n/** Server fixture with an explicit synthetic model when the test supplies no model catalog. @internal */\nexport async function createTestAppContext(options: AppOptions = {}): Promise<AppContext> {\n\tconst config = options.config ?? getDefaultConfig();\n\tconst catalog = await (options.extensionCatalog ?? buildExtensionCatalogFromModules([]));\n\treturn createAppContext({\n\t\t...options,\n\t\tconfig,\n\t\textensionCatalog: withDefaultModelFixture(config, catalog),\n\t});\n}\n\n/** @public */\nexport interface IntegrationHarness<\n\tTResources extends Record<string, unknown> = Record<string, never>,\n> {\n\t/** @public */\n\tctx: AppContext;\n\t/** @public */\n\tclose(): Promise<void>;\n\t/** @internal */\n\tconfig: LeitwerkConfig;\n\t/** @public */\n\taddress: string;\n\t/** @internal */\n\tresources: TResources;\n}\n\n/** @public */\nexport interface IntegrationHarnessOptions<\n\tTResources extends Record<string, unknown> = Record<string, never>,\n> {\n\t/** @internal */\n\tconfig?: LeitwerkConfig;\n\t/** @public */\n\tconfigOverride?: (config: LeitwerkConfig) => void;\n\t/** @public */\n\tappOverrides?: Partial<AppOptions>;\n\t/** @internal */\n\tlisten?: boolean;\n\t/** Start background services when binding a listener. Defaults to true. @public */\n\tbackgroundServices?: boolean;\n\t/** @internal */\n\tinProcessWorkers?: boolean | Omit<InProcessWorkerSpawnOptions, \"extensionCatalog\">;\n\t/** @public */\n\textensionCatalog: ExtensionCatalog | Promise<ExtensionCatalog>;\n\t/** @internal */\n\tpreProvidedCapabilities?: readonly ProvidedCapability[];\n\t/** @internal */\n\tresources?: TResources;\n}\n\n/** Owns disposable file-backed storage; close retains it for the next open, dispose removes it. @internal */\nexport function createPersistentIntegrationFixture(\n\tprefix: string,\n\tconfigure?: (config: LeitwerkConfig) => void,\n) {\n\tconst root = mkdtempSync(path.join(tmpdir(), prefix));\n\tlet harness: IntegrationHarness | undefined;\n\t/** @internal */\n\tfunction createConfig() {\n\t\tconst config = getDefaultConfig();\n\t\tconfig.storage.sqlite_path = path.join(root, \"state.sqlite\");\n\t\tconfig.storage.process_workspaces_dir = path.join(root, \"workspaces\");\n\t\tconfig.storage.tree_files_dir = path.join(root, \"trees\");\n\t\tconfig.pi.agent_dir = path.join(root, \"pi\");\n\t\tconfigure?.(config);\n\t\treturn config;\n\t}\n\t/** @internal */\n\tasync function close() {\n\t\tawait harness?.close();\n\t\tharness = undefined;\n\t}\n\treturn {\n\t\t/** @internal */\n\t\troot,\n\t\t/** @internal */\n\t\tcreateConfig,\n\t\t/** @internal */\n\t\tcontext() {\n\t\t\tif (!harness) throw new Error(\"Fixture is not open\");\n\t\t\treturn harness.ctx;\n\t\t},\n\t\t/** @internal */\n\t\tasync open(options: IntegrationHarnessOptions) {\n\t\t\tharness = await createIntegrationHarness({\n\t\t\t\t...options,\n\t\t\t\tconfig: options.config ?? createConfig(),\n\t\t\t});\n\t\t\treturn harness;\n\t\t},\n\t\t/** @internal */\n\t\tclose,\n\t\t/** @internal */\n\t\tasync dispose() {\n\t\t\ttry {\n\t\t\t\tawait close();\n\t\t\t} finally {\n\t\t\t\trmSync(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });\n\t\t\t}\n\t\t},\n\t};\n}\n/** @public */\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 = withDefaultModelFixture(\n\t\tconfig,\n\t\tawait Promise.resolve(opts.extensionCatalog),\n\t);\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\t...(typeof opts.inProcessWorkers === \"object\" ? opts.inProcessWorkers : {}),\n\t\t\textensionCatalog,\n\t\t});\n\t}\n\tconst ctx = await createAppContext(appOpts);\n\n\tlet address = \"\";\n\ttry {\n\t\tif (opts.listen !== false) {\n\t\t\tif (opts.backgroundServices !== false) {\n\t\t\t\t({ address } = await ctx.listen({\n\t\t\t\t\thost: \"127.0.0.1\",\n\t\t\t\t\tport: 0,\n\t\t\t\t\tuseBoundAddressAsBaseUrl: true,\n\t\t\t\t}));\n\t\t\t} else {\n\t\t\t\taddress = await ctx.app.listen({ host: \"127.0.0.1\", port: 0 });\n\t\t\t\tctx.config.server.base_url = address;\n\t\t\t}\n\t\t}\n\t} catch (error) {\n\t\tawait ctx.close().catch(() => {});\n\t\tthrow error;\n\t}\n\n\treturn {\n\t\tctx,\n\t\tclose: () => ctx.close(),\n\t\tconfig,\n\t\tget address() {\n\t\t\treturn address || (ctx.app.server.listening ? ctx.config.server.base_url : \"\");\n\t\t},\n\t\tresources: opts.resources ?? ({} as TResources),\n\t};\n}\n","/** @public */\nexport 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 { ProcessInstance } from \"@leitwerk-dev/domain\";\nimport type { AppContext } from \"@leitwerk-dev/server\";\nimport { waitForValue } from \"./polling.js\";\n\n/** Drive a running or restarted app without bypassing process HTTP actions. @public */\nexport function createProcessDriver(context: () => AppContext) {\n\t/** @public */\n\tasync function post(url: string, payload: Record<string, unknown> = {}) {\n\t\tconst response = await context().app.inject({ method: \"POST\", url, payload });\n\t\tif (response.statusCode !== 200)\n\t\t\tthrow new Error(`POST ${url} failed with ${response.statusCode}: ${response.body}`);\n\t\treturn response;\n\t}\n\t/** @public */\n\tasync function waitForProcess(\n\t\tid: string,\n\t\tpredicate: (process: ProcessInstance) => boolean,\n\t\tdescription: string,\n\t\ttimeout = 12000,\n\t\tallowError = false,\n\t): Promise<ProcessInstance> {\n\t\ttry {\n\t\t\tconst process = await waitForValue(\n\t\t\t\t() => {\n\t\t\t\t\tconst current = context().deps.processes.getById(id);\n\t\t\t\t\tif (current?.lifecycleStatus === \"error\" && !allowError)\n\t\t\t\t\t\tthrow new Error(\"Process entered error lifecycle\");\n\t\t\t\t\treturn current;\n\t\t\t\t},\n\t\t\t\t(process) => !!process && predicate(process),\n\t\t\t\ttimeout,\n\t\t\t);\n\t\t\tif (!process) throw new Error(\"Missing process\");\n\t\t\treturn process;\n\t\t} catch (error) {\n\t\t\tconst { processes, turnRecords } = context().deps;\n\t\t\tthrow new Error(\n\t\t\t\t`Waiting for ${id}: ${description}; ${JSON.stringify({ process: processes.getById(id), turns: turnRecords.listByInstance(id) })}`,\n\t\t\t\t{ cause: error },\n\t\t\t);\n\t\t}\n\t}\n\treturn {\n\t\t/** @public */\n\t\tpost,\n\t\t/** @public */\n\t\twaitForProcess,\n\t\t/** @public */\n\t\twait: (id: string, turn: string | null, lifecycle = \"waiting\", timeout = 12000) =>\n\t\t\twaitForProcess(\n\t\t\t\tid,\n\t\t\t\t(p) => p.selectedTurnId === turn && p.lifecycleStatus === lifecycle,\n\t\t\t\t`${turn}/${lifecycle}`,\n\t\t\t\ttimeout,\n\t\t\t\tlifecycle === \"error\",\n\t\t\t),\n\t\t/** @public */\n\t\taction: (id: string, action: string, input: Record<string, unknown> = {}) =>\n\t\t\tpost(`/api/processes/${encodeURIComponent(id)}/actions/${encodeURIComponent(action)}`, {\n\t\t\t\tinput,\n\t\t\t}),\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAIA,SAAS,kBAAkB;AAC3B,OAAOA,WAAU;AASjB,SAAS,oCAAAC,yCAAwC;AACjD;AAAA,EACC;AAAA,OAGM;AACP;AAAA,EACC;AAAA,EACA;AAAA,OACM;AACP,SAAS,uCAAuC;;;ACxBhD,SAAS,aAAa,cAAc;AACpC,SAAS,cAAc;AACvB,OAAO,UAAU;AAEjB,SAAS,wCAAwC;AAEjD;AAAA,EAGC;AAAA,EACA;AAAA,OAEM;AAQP,eAAsB,qBAAqB,UAAsB,CAAC,GAAwB;AACzF,QAAM,SAAS,QAAQ,UAAU,iBAAiB;AAClD,QAAM,UAAU,OAAO,QAAQ,oBAAoB,iCAAiC,CAAC,CAAC;AACtF,SAAO,iBAAiB;AAAA,IACvB,GAAG;AAAA,IACH;AAAA,IACA,kBAAkB,wBAAwB,QAAQ,OAAO;AAAA,EAC1D,CAAC;AACF;AA2CO,SAAS,mCACf,QACA,WACC;AACD,QAAM,OAAO,YAAY,KAAK,KAAK,OAAO,GAAG,MAAM,CAAC;AACpD,MAAI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eAAe,EAAE,EAAE,CAAC,CAAC;AAAA,QAC/H,EAAE,OAAO,MAAM;AAAA,MAChB;AAAA,IACD;AAAA,EACD;AACA,SAAO;AAAA;AAAA,IAEN;AAAA;AAAA,IAEA;AAAA;AAAA,IAEA,MAAM,CAAC,IAAY,MAAqB,YAAY,WAAW,UAAU,SACxE;AAAA,MACC;AAAA,MACA,CAAC,MAAM,EAAE,mBAAmB,QAAQ,EAAE,oBAAoB;AAAA,MAC1D,GAAG,IAAI,IAAI,SAAS;AAAA,MACpB;AAAA,MACA,cAAc;AAAA,IACf;AAAA;AAAA,IAED,QAAQ,CAAC,IAAY,QAAgB,QAAiC,CAAC,MACtE,KAAK,kBAAkB,mBAAmB,EAAE,CAAC,YAAY,mBAAmB,MAAM,CAAC,IAAI;AAAA,MACtF;AAAA,IACD,CAAC;AAAA,EACH;AACD;","names":["path","buildExtensionCatalogFromModules","buildExtensionCatalogFromModules","session","path","options","turn","process","process"]}
|
package/dist/local-git.d.ts
CHANGED
|
@@ -17,6 +17,15 @@ export interface LocalRepositorySeed {
|
|
|
17
17
|
/** @internal */
|
|
18
18
|
signoff?: boolean;
|
|
19
19
|
}
|
|
20
|
+
/** Copies immutable bare seeds into independent test fixtures. @internal */
|
|
21
|
+
export declare class LocalGitSeedCache {
|
|
22
|
+
private root;
|
|
23
|
+
private readonly templates;
|
|
24
|
+
/** Seed options select the template; an existing destination is never overwritten. @internal */
|
|
25
|
+
copy(git: LocalGit, seed: LocalRepositorySeed): string;
|
|
26
|
+
/** Release templates after the suite; copied repositories remain usable. @internal */
|
|
27
|
+
close(): void;
|
|
28
|
+
}
|
|
20
29
|
/** Reject escaping paths and symlinks, including a not-yet-created file's parents. @public */
|
|
21
30
|
export declare function localPath(root: string, relative: string): string;
|
|
22
31
|
/** @public */
|
package/dist/local-git.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-git.d.ts","sourceRoot":"","sources":["../src/local-git.ts"],"names":[],"mappings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AAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO;IAO5E,OAAO,CAAC,gBAAgB;IAUxB,gBAAgB;IAChB,YAAY,CACX,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACV;QACF,gBAAgB;QAChB,OAAO,EAAE,MAAM,CAAC;QAChB,gBAAgB;QAChB,OAAO,EAAE,MAAM,CAAC;QAChB,gBAAgB;QAChB,SAAS,EAAE,OAAO,CAAC;QACnB,gBAAgB;QAChB,eAAe,EAAE,MAAM,CAAC;KACxB;IAeD,gBAAgB;IAChB,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;IAoB5D,gBAAgB;IAChB,IAAI,CAAC,IAAI,EAAE,mBAAmB,GAAG;QAChC,gBAAgB;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,gBAAgB;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,gBAAgB;QAChB,MAAM,EAAE,MAAM,CAAC;KACf;CA2CD"}
|
package/dist/local-git.js
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
// src/local-git.ts
|
|
2
2
|
import { execFileSync } from "child_process";
|
|
3
3
|
import {
|
|
4
|
+
cpSync,
|
|
4
5
|
existsSync,
|
|
5
6
|
lstatSync,
|
|
6
7
|
mkdirSync,
|
|
8
|
+
mkdtempSync,
|
|
7
9
|
readFileSync,
|
|
8
10
|
realpathSync,
|
|
9
11
|
renameSync,
|
|
12
|
+
rmSync,
|
|
10
13
|
writeFileSync
|
|
11
14
|
} from "fs";
|
|
15
|
+
import { tmpdir } from "os";
|
|
12
16
|
import path from "path";
|
|
13
17
|
|
|
14
18
|
// src/test-diagnostics.ts
|
|
@@ -78,6 +82,32 @@ function traceTestSubprocess(operation, run) {
|
|
|
78
82
|
}
|
|
79
83
|
|
|
80
84
|
// src/local-git.ts
|
|
85
|
+
var LocalGitSeedCache = class {
|
|
86
|
+
root;
|
|
87
|
+
templates = /* @__PURE__ */ new Map();
|
|
88
|
+
/** Seed options select the template; an existing destination is never overwritten. @internal */
|
|
89
|
+
copy(git, seed) {
|
|
90
|
+
const key = JSON.stringify(seed);
|
|
91
|
+
let template = this.templates.get(key);
|
|
92
|
+
if (!template) {
|
|
93
|
+
this.root ??= mkdtempSync(path.join(tmpdir(), "leitwerk-git-seeds-"));
|
|
94
|
+
const directory = mkdtempSync(path.join(this.root, "seed-"));
|
|
95
|
+
template = new LocalGit(directory).seed(seed).bare;
|
|
96
|
+
this.templates.set(key, template);
|
|
97
|
+
}
|
|
98
|
+
const destination = localPath(git.root, `repositories/${path.basename(template)}`);
|
|
99
|
+
if (existsSync(destination)) throw new Error("Git seed destination already exists");
|
|
100
|
+
mkdirSync(path.dirname(destination), { recursive: true });
|
|
101
|
+
cpSync(template, destination, { recursive: true, force: false, errorOnExist: true });
|
|
102
|
+
return destination;
|
|
103
|
+
}
|
|
104
|
+
/** Release templates after the suite; copied repositories remain usable. @internal */
|
|
105
|
+
close() {
|
|
106
|
+
if (this.root) rmSync(this.root, { recursive: true, force: true });
|
|
107
|
+
this.root = void 0;
|
|
108
|
+
this.templates.clear();
|
|
109
|
+
}
|
|
110
|
+
};
|
|
81
111
|
function localPath(root, relative) {
|
|
82
112
|
if (lstatSync(root, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
83
113
|
throw new Error("Local provider storage must not contain symlinks");
|
|
@@ -419,6 +449,7 @@ var LocalGit = class {
|
|
|
419
449
|
export {
|
|
420
450
|
LocalForgeStore,
|
|
421
451
|
LocalGit,
|
|
452
|
+
LocalGitSeedCache,
|
|
422
453
|
LocalProviderStore,
|
|
423
454
|
createTestDiagnostics,
|
|
424
455
|
localPath,
|