@leitwerk-dev/test-support 0.2.1 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-2PCDTYVH.js → chunk-JGXSXRIJ.js} +10 -4
- package/dist/chunk-JGXSXRIJ.js.map +1 -0
- package/dist/chunk-KJVNI2UP.js +17 -0
- package/dist/chunk-KJVNI2UP.js.map +1 -0
- package/dist/chunk-P2FF4AP7.js +72 -0
- package/dist/chunk-P2FF4AP7.js.map +1 -0
- package/dist/chunk-RY6Y6V5E.js +54 -0
- package/dist/chunk-RY6Y6V5E.js.map +1 -0
- package/dist/{chunk-ECAWLVYB.js → chunk-WT7V7REB.js} +4 -1
- package/dist/chunk-WT7V7REB.js.map +1 -0
- package/dist/extension-integration-harness.d.ts +357 -0
- package/dist/extension-integration-harness.d.ts.map +1 -0
- package/dist/fixtures.d.ts +2 -0
- package/dist/fixtures.d.ts.map +1 -1
- package/dist/fixtures.js +53 -0
- package/dist/fixtures.js.map +1 -1
- package/dist/index.d.ts +2 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -67
- package/dist/index.js.map +1 -1
- package/dist/integration.d.ts +1 -0
- package/dist/integration.d.ts.map +1 -1
- package/dist/integration.js +503 -2
- package/dist/integration.js.map +1 -1
- package/dist/local-git.d.ts.map +1 -1
- package/dist/local-git.js.map +1 -1
- package/dist/observations.d.ts +7 -0
- package/dist/observations.d.ts.map +1 -0
- package/dist/process-fixtures.d.ts +56 -0
- package/dist/process-fixtures.d.ts.map +1 -0
- package/dist/process.d.ts +440 -0
- package/dist/process.d.ts.map +1 -0
- package/dist/process.js +484 -0
- package/dist/process.js.map +1 -0
- package/dist/stub-worker-entry.js +1 -1
- package/dist/supported-question-fixtures.d.ts +96 -0
- package/dist/supported-question-fixtures.d.ts.map +1 -0
- package/dist/test-capability.d.ts +9 -0
- package/dist/test-capability.d.ts.map +1 -0
- package/dist/worker-testing/in-process-worker-spawn.d.ts +2 -0
- package/dist/worker-testing/in-process-worker-spawn.d.ts.map +1 -1
- package/dist/worker-testing/index.js +2 -2
- package/dist/worker-testing/stub-pi-tree-handle.d.ts +15 -0
- package/dist/worker-testing/stub-pi-tree-handle.d.ts.map +1 -1
- package/package.json +14 -9
- package/src/extension-integration-harness.ts +966 -0
- package/src/fixtures.ts +16 -0
- package/src/index.ts +4 -19
- package/src/integration.ts +21 -0
- package/src/local-git.ts +1 -0
- package/src/observations.ts +19 -0
- package/src/process-fixtures.ts +123 -0
- package/src/process.ts +768 -0
- package/src/supported-question-fixtures.ts +148 -0
- package/src/test-capability.ts +9 -0
- package/src/worker-testing/in-process-worker-spawn.ts +15 -2
- package/src/worker-testing/stub-pi-tree-handle.ts +19 -0
- package/dist/chunk-2PCDTYVH.js.map +0 -1
- package/dist/chunk-ECAWLVYB.js.map +0 -1
package/dist/process.js
ADDED
|
@@ -0,0 +1,484 @@
|
|
|
1
|
+
import {
|
|
2
|
+
observe
|
|
3
|
+
} from "./chunk-KJVNI2UP.js";
|
|
4
|
+
import {
|
|
5
|
+
createProcessFixture
|
|
6
|
+
} from "./chunk-RY6Y6V5E.js";
|
|
7
|
+
import {
|
|
8
|
+
createTestServerSetupCapability
|
|
9
|
+
} from "./chunk-5BZSJ4OO.js";
|
|
10
|
+
|
|
11
|
+
// src/process.ts
|
|
12
|
+
import { bindExternalWrites } from "@leitwerk-dev/external-writes/internal";
|
|
13
|
+
import { setupServerExtensions } from "@leitwerk-dev/extension-runtime";
|
|
14
|
+
import {
|
|
15
|
+
buildExtensionCatalogFromModules,
|
|
16
|
+
buildServerProcessForTest,
|
|
17
|
+
buildWorkerProcessForTest,
|
|
18
|
+
createTestServerProcessContext
|
|
19
|
+
} from "@leitwerk-dev/extension-runtime/testing";
|
|
20
|
+
import {
|
|
21
|
+
buildProcessLaunchers,
|
|
22
|
+
buildProcessWatchers,
|
|
23
|
+
coreHostCapabilities,
|
|
24
|
+
createCapabilityAccessor,
|
|
25
|
+
resolveHumanTurnView,
|
|
26
|
+
toProcessGraphView
|
|
27
|
+
} from "@leitwerk-dev/process-sdk";
|
|
28
|
+
async function createExtensionTestHarness(options = {}) {
|
|
29
|
+
const catalog = await buildExtensionCatalogFromModules(options.extensions ?? []);
|
|
30
|
+
const receipts = [];
|
|
31
|
+
const externalWrites = {
|
|
32
|
+
hasDedupKey: (key) => receipts.some((receipt) => receipt.dedupKey === key),
|
|
33
|
+
record(input) {
|
|
34
|
+
const receipt = structuredClone(input);
|
|
35
|
+
receipts.push(receipt);
|
|
36
|
+
return receipt;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const capabilities = createCapabilityAccessor([
|
|
40
|
+
{
|
|
41
|
+
token: coreHostCapabilities.serverSetup,
|
|
42
|
+
value: createTestServerSetupCapability({ externalWrites })
|
|
43
|
+
},
|
|
44
|
+
...options.capabilities ?? []
|
|
45
|
+
]);
|
|
46
|
+
const tools = /* @__PURE__ */ new Map();
|
|
47
|
+
const starts = [];
|
|
48
|
+
const stops = [];
|
|
49
|
+
const listeners = /* @__PURE__ */ new Map();
|
|
50
|
+
const pendingEvents = /* @__PURE__ */ new Set();
|
|
51
|
+
const eventErrors = [];
|
|
52
|
+
let toolSequence = 0;
|
|
53
|
+
function emit(type, event) {
|
|
54
|
+
for (const listener of listeners.get(type) ?? []) {
|
|
55
|
+
const task = Promise.resolve().then(() => listener(structuredClone(event))).catch((error) => {
|
|
56
|
+
eventErrors.push(error);
|
|
57
|
+
}).finally(() => pendingEvents.delete(task));
|
|
58
|
+
pendingEvents.add(task);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async function drainEvents() {
|
|
62
|
+
let timer;
|
|
63
|
+
try {
|
|
64
|
+
await Promise.race([
|
|
65
|
+
(async () => {
|
|
66
|
+
while (pendingEvents.size) await Promise.all([...pendingEvents]);
|
|
67
|
+
})(),
|
|
68
|
+
new Promise((_resolve, reject) => {
|
|
69
|
+
timer = setTimeout(
|
|
70
|
+
() => reject(new Error("Extension event handlers did not settle within 12 seconds")),
|
|
71
|
+
12e3
|
|
72
|
+
);
|
|
73
|
+
})
|
|
74
|
+
]);
|
|
75
|
+
} finally {
|
|
76
|
+
clearTimeout(timer);
|
|
77
|
+
}
|
|
78
|
+
if (eventErrors.length)
|
|
79
|
+
throw new AggregateError(eventErrors.splice(0), "Extension event handler failed");
|
|
80
|
+
}
|
|
81
|
+
let closed = false;
|
|
82
|
+
function assertOpen() {
|
|
83
|
+
if (closed) throw new Error("Extension test harness is closed");
|
|
84
|
+
}
|
|
85
|
+
async function close() {
|
|
86
|
+
if (closed) return;
|
|
87
|
+
closed = true;
|
|
88
|
+
const failures = [];
|
|
89
|
+
for (const stop of stops.reverse()) {
|
|
90
|
+
try {
|
|
91
|
+
await stop();
|
|
92
|
+
} catch (error) {
|
|
93
|
+
failures.push(error);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
listeners.clear();
|
|
97
|
+
try {
|
|
98
|
+
await drainEvents();
|
|
99
|
+
} catch (error) {
|
|
100
|
+
failures.push(error);
|
|
101
|
+
}
|
|
102
|
+
if (failures.length) throw new AggregateError(failures, "Extension cleanup failed");
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
await setupServerExtensions(
|
|
106
|
+
catalog,
|
|
107
|
+
{
|
|
108
|
+
provide: capabilities.provide.bind(capabilities),
|
|
109
|
+
get: capabilities.get.bind(capabilities),
|
|
110
|
+
require: capabilities.require.bind(capabilities),
|
|
111
|
+
tool(tool) {
|
|
112
|
+
if (tools.has(tool.name)) throw new Error(`Duplicate integration tool '${tool.name}'`);
|
|
113
|
+
tools.set(tool.name, tool);
|
|
114
|
+
},
|
|
115
|
+
events: {
|
|
116
|
+
on(type, listener) {
|
|
117
|
+
const set = listeners.get(type) ?? /* @__PURE__ */ new Set();
|
|
118
|
+
set.add(listener);
|
|
119
|
+
listeners.set(type, set);
|
|
120
|
+
},
|
|
121
|
+
off(type, listener) {
|
|
122
|
+
listeners.get(type)?.delete(listener);
|
|
123
|
+
},
|
|
124
|
+
emit
|
|
125
|
+
},
|
|
126
|
+
onStart: (hook) => {
|
|
127
|
+
starts.push(hook);
|
|
128
|
+
},
|
|
129
|
+
onStop: (hook) => {
|
|
130
|
+
stops.push(hook);
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
(id) => structuredClone(options.extensionConfig?.[id] ?? {})
|
|
134
|
+
);
|
|
135
|
+
for (const start of starts) await start();
|
|
136
|
+
await drainEvents();
|
|
137
|
+
} catch (error) {
|
|
138
|
+
await close().catch(() => {
|
|
139
|
+
});
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
async function callTool(name, args, fixture = {}) {
|
|
143
|
+
assertOpen();
|
|
144
|
+
const tool = tools.get(name);
|
|
145
|
+
if (!tool) throw new Error(`Unknown integration tool '${name}'`);
|
|
146
|
+
const process = createProcessFixture(fixture);
|
|
147
|
+
const projects = structuredClone([...fixture.projects ?? []]);
|
|
148
|
+
for (const project of projects)
|
|
149
|
+
if (project.instanceId !== process.id) throw new Error("Project belongs to another process");
|
|
150
|
+
const turn = {
|
|
151
|
+
id: "trn_test",
|
|
152
|
+
instanceId: process.id,
|
|
153
|
+
turnId: process.selectedTurnId ?? "test_turn",
|
|
154
|
+
turnType: "automatic",
|
|
155
|
+
status: "running",
|
|
156
|
+
attemptNumber: 1,
|
|
157
|
+
parentTurnRecordId: null,
|
|
158
|
+
pathType: "primary",
|
|
159
|
+
forkPiEntryId: null,
|
|
160
|
+
resultPiEntryId: null,
|
|
161
|
+
modelProfileId: null,
|
|
162
|
+
turnResultMarkdown: null,
|
|
163
|
+
errorSummary: null,
|
|
164
|
+
errorClass: null,
|
|
165
|
+
startedAt: process.createdAt,
|
|
166
|
+
endedAt: null
|
|
167
|
+
};
|
|
168
|
+
return observe(
|
|
169
|
+
await tool.execute(
|
|
170
|
+
{
|
|
171
|
+
process,
|
|
172
|
+
projects,
|
|
173
|
+
turn,
|
|
174
|
+
project: projects.find((project) => project.key === args.projectKey) ?? (projects.length === 1 ? projects[0] ?? null : null),
|
|
175
|
+
idempotencyKey: fixture.invocationId ?? `${process.id}:test_tool:${++toolSequence}`,
|
|
176
|
+
ticketDestination: structuredClone(fixture.ticketDestination),
|
|
177
|
+
externalWrites: bindExternalWrites(externalWrites, process.id),
|
|
178
|
+
signal: new AbortController().signal
|
|
179
|
+
},
|
|
180
|
+
tool.parse ? tool.parse(structuredClone(args)) : structuredClone(args)
|
|
181
|
+
)
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
function destinationProvider(name) {
|
|
185
|
+
assertOpen();
|
|
186
|
+
const provider = tools.get(name)?.capability?.destinations;
|
|
187
|
+
if (!provider) throw new Error(`Tool '${name}' has no ticket destinations`);
|
|
188
|
+
return provider;
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
/** List destinations through the registered tool capability. @public */
|
|
192
|
+
async listToolDestinations(name, actor) {
|
|
193
|
+
return observe(await destinationProvider(name).list({ actor: structuredClone(actor) }));
|
|
194
|
+
},
|
|
195
|
+
/** Resolve an authorized destination snapshot. @public */
|
|
196
|
+
async resolveToolDestination(name, destinationId, actor) {
|
|
197
|
+
return observe(
|
|
198
|
+
await destinationProvider(name).resolve({ actor: structuredClone(actor), destinationId })
|
|
199
|
+
);
|
|
200
|
+
},
|
|
201
|
+
/** Validate a saved destination against the provider. @public */
|
|
202
|
+
async validateToolDestination(name, snapshot) {
|
|
203
|
+
await destinationProvider(name).validate(structuredClone(snapshot));
|
|
204
|
+
},
|
|
205
|
+
/** Detached descriptions of registered tools. @public */
|
|
206
|
+
describeTools() {
|
|
207
|
+
assertOpen();
|
|
208
|
+
return observe(
|
|
209
|
+
[...tools.values()].map(({ name, description, parameters }) => ({
|
|
210
|
+
/** @public */
|
|
211
|
+
name,
|
|
212
|
+
/** @public */
|
|
213
|
+
description,
|
|
214
|
+
/** @public */
|
|
215
|
+
parameters
|
|
216
|
+
}))
|
|
217
|
+
);
|
|
218
|
+
},
|
|
219
|
+
/** Detached receipts, including writes recorded before an invocation failed. @public */
|
|
220
|
+
writeReceipts() {
|
|
221
|
+
assertOpen();
|
|
222
|
+
return observe(receipts);
|
|
223
|
+
},
|
|
224
|
+
/** Run an integration tool registered by an extension. @public */
|
|
225
|
+
callTool,
|
|
226
|
+
/** Deliver an event and await its registered handlers. @public */
|
|
227
|
+
async emit(type, event) {
|
|
228
|
+
assertOpen();
|
|
229
|
+
emit(type, event);
|
|
230
|
+
await drainEvents();
|
|
231
|
+
},
|
|
232
|
+
/** Run cleanup hooks once, including when another hook fails. @public */
|
|
233
|
+
close,
|
|
234
|
+
/** Bind a definition and independent default fixtures. @public */
|
|
235
|
+
process(definition, initial = {}) {
|
|
236
|
+
assertOpen();
|
|
237
|
+
const defaults = structuredClone(initial);
|
|
238
|
+
const worker = buildWorkerProcessForTest(definition);
|
|
239
|
+
const server = buildServerProcessForTest(definition);
|
|
240
|
+
const launchers = buildProcessLaunchers(definition)?.launchers;
|
|
241
|
+
const watchers = buildProcessWatchers(definition)?.watchers;
|
|
242
|
+
function context(fixture = {}) {
|
|
243
|
+
assertOpen();
|
|
244
|
+
const input = structuredClone({ ...defaults, ...fixture });
|
|
245
|
+
const process = createProcessFixture(input, definition);
|
|
246
|
+
const projects = input.projects ?? [];
|
|
247
|
+
for (const project of projects)
|
|
248
|
+
if (project.instanceId !== process.id)
|
|
249
|
+
throw new Error("Project belongs to another process");
|
|
250
|
+
return {
|
|
251
|
+
process,
|
|
252
|
+
projects,
|
|
253
|
+
params: definition.paramsCodec.parse(JSON.parse(process.paramsJson ?? "null")),
|
|
254
|
+
state: definition.stateCodec.parse(JSON.parse(process.stateJson ?? "null")),
|
|
255
|
+
turnResultMarkdownByProduct: input.products,
|
|
256
|
+
workspaceRoot: input.workspaceRoot
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
function effects(fixture) {
|
|
260
|
+
const base = context(fixture);
|
|
261
|
+
const result = {
|
|
262
|
+
transitions: [],
|
|
263
|
+
inputs: [],
|
|
264
|
+
events: [],
|
|
265
|
+
lifecycle: []
|
|
266
|
+
};
|
|
267
|
+
const ctx = createTestServerProcessContext({
|
|
268
|
+
...base,
|
|
269
|
+
transition: async (next) => {
|
|
270
|
+
result.transitions.push(structuredClone(next));
|
|
271
|
+
},
|
|
272
|
+
queueInput: (input) => {
|
|
273
|
+
result.inputs.push(structuredClone(input));
|
|
274
|
+
},
|
|
275
|
+
emitEvent: (type, data) => {
|
|
276
|
+
result.events.push({ type, data: structuredClone(data) });
|
|
277
|
+
},
|
|
278
|
+
applyLifecycleEffects: (effect) => {
|
|
279
|
+
result.lifecycle.push(structuredClone(effect));
|
|
280
|
+
},
|
|
281
|
+
readProductTurnResultMarkdown: (name) => base.turnResultMarkdownByProduct?.[name] ?? null,
|
|
282
|
+
readSemanticTurnResultMarkdown: (name) => base.turnResultMarkdownByProduct?.[name] ?? null
|
|
283
|
+
});
|
|
284
|
+
return { ctx, result };
|
|
285
|
+
}
|
|
286
|
+
context();
|
|
287
|
+
return {
|
|
288
|
+
/** Return data descriptions without exposing registered handlers. @public */
|
|
289
|
+
describe() {
|
|
290
|
+
assertOpen();
|
|
291
|
+
return observe({
|
|
292
|
+
/** @public */
|
|
293
|
+
id: definition.id,
|
|
294
|
+
/** @public */
|
|
295
|
+
entryTurnId: definition.entryTurnId,
|
|
296
|
+
entryTurnIds: [definition.entryTurnId, ...definition.alternateEntryTurnIds ?? []],
|
|
297
|
+
/** @public */
|
|
298
|
+
turns: [...definition.turns].map(([id, binding]) => ({
|
|
299
|
+
id,
|
|
300
|
+
kind: binding.definition.kind,
|
|
301
|
+
description: binding.definition.description,
|
|
302
|
+
...binding.definition.kind === "llm" ? {
|
|
303
|
+
availableTools: binding.definition.availableTools,
|
|
304
|
+
branchType: binding.definition.branchType,
|
|
305
|
+
context: binding.definition.context,
|
|
306
|
+
restorePrimaryLeafAfterTurn: binding.definition.restorePrimaryLeafAfterTurn,
|
|
307
|
+
startFrom: binding.definition.startFrom,
|
|
308
|
+
publishedProduct: binding.definition.publishedProduct,
|
|
309
|
+
consumedProducts: binding.definition.consumedProducts
|
|
310
|
+
} : binding.definition.kind === "human" ? { humanView: resolveHumanTurnView({ turnId: id, turn: binding.definition }) } : {}
|
|
311
|
+
})),
|
|
312
|
+
/** @public */
|
|
313
|
+
transitions: [
|
|
314
|
+
...toProcessGraphView(definition).turns
|
|
315
|
+
].flatMap(
|
|
316
|
+
([from, turn]) => turn.transitions.map((transition) => ({ from, ...transition }))
|
|
317
|
+
),
|
|
318
|
+
/** @public */
|
|
319
|
+
actions: [...server?.actions.values() ?? []].map((a) => ({
|
|
320
|
+
/** @public */
|
|
321
|
+
id: a.id,
|
|
322
|
+
label: a.label,
|
|
323
|
+
form: a.form
|
|
324
|
+
})),
|
|
325
|
+
/** @public */
|
|
326
|
+
launchers: [...launchers?.values() ?? []].map((a) => ({
|
|
327
|
+
/** @public */
|
|
328
|
+
id: a.id,
|
|
329
|
+
label: a.label,
|
|
330
|
+
description: a.description,
|
|
331
|
+
launchConfigSchema: a.ui.launchConfigSchema
|
|
332
|
+
})),
|
|
333
|
+
/** @public */
|
|
334
|
+
watchers: [...watchers?.values() ?? []].map((a) => ({
|
|
335
|
+
/** @public */
|
|
336
|
+
id: a.id,
|
|
337
|
+
label: a.label,
|
|
338
|
+
description: a.description,
|
|
339
|
+
source: a.source.id
|
|
340
|
+
}))
|
|
341
|
+
});
|
|
342
|
+
},
|
|
343
|
+
/** Resolve a UI launcher using its own validation. @public */
|
|
344
|
+
async resolveLaunch(id, input) {
|
|
345
|
+
const ctx = context();
|
|
346
|
+
const launcher = launchers?.get(id);
|
|
347
|
+
if (!launcher) throw new Error(`Unknown launcher '${id}'`);
|
|
348
|
+
return observe(await launcher.ui.resolveLaunchConfig(structuredClone(input), ctx));
|
|
349
|
+
},
|
|
350
|
+
/** Prepare persisted launcher input for a new launch. @public */
|
|
351
|
+
async prepareRelaunch(id, previousInput) {
|
|
352
|
+
const ctx = context();
|
|
353
|
+
const launcher = launchers?.get(id);
|
|
354
|
+
if (!launcher) throw new Error(`Unknown launcher '${id}'`);
|
|
355
|
+
return observe(
|
|
356
|
+
await launcher.ui.resolveRelaunchInput?.(structuredClone(previousInput), ctx) ?? previousInput
|
|
357
|
+
);
|
|
358
|
+
},
|
|
359
|
+
/** Parse source configuration and resolve a matching watcher event. @public */
|
|
360
|
+
async resolveWatcherLaunch(id, event, config) {
|
|
361
|
+
const ctx = context();
|
|
362
|
+
const watcher = watchers?.get(id);
|
|
363
|
+
if (!watcher) throw new Error(`Unknown watcher '${id}'`);
|
|
364
|
+
const parsed = watcher.source.parseConfig(structuredClone(config));
|
|
365
|
+
if (!parsed.enabled || watcher.matches && !await watcher.matches(structuredClone(event), ctx))
|
|
366
|
+
return null;
|
|
367
|
+
return observe(await watcher.resolveLaunchConfig(structuredClone(event), ctx));
|
|
368
|
+
},
|
|
369
|
+
/** Run preparation, prompt evaluation, and the registered worker handler. @public */
|
|
370
|
+
async evaluateTurn(id, options2 = {}) {
|
|
371
|
+
const binding = definition.turns.get(id);
|
|
372
|
+
const handler = worker?.turns.get(id);
|
|
373
|
+
if (!binding || !handler) throw new Error(`Unknown worker turn '${id}'`);
|
|
374
|
+
const base = context({
|
|
375
|
+
...options2.fixture,
|
|
376
|
+
position: { selectedTurnId: id, lifecycleStatus: "active" }
|
|
377
|
+
});
|
|
378
|
+
const prompts = [];
|
|
379
|
+
const tools2 = [];
|
|
380
|
+
const progress = [];
|
|
381
|
+
const completed = [];
|
|
382
|
+
const requestedTools = /* @__PURE__ */ new Set();
|
|
383
|
+
const parked = [];
|
|
384
|
+
const responses = structuredClone([...options2.responses ?? []]);
|
|
385
|
+
const ctx = {
|
|
386
|
+
...base,
|
|
387
|
+
async callIntegrationTool(name, args) {
|
|
388
|
+
const def = binding.definition;
|
|
389
|
+
const allowed = def.kind === "llm" ? def.resolveIntegrationTools?.(base.params, base.state) ?? def.integrationTools : def.kind === "automatic" ? def.integrationTools : [];
|
|
390
|
+
if (!allowed?.includes(name))
|
|
391
|
+
throw new Error(`Integration tool '${name}' is not declared for '${id}'`);
|
|
392
|
+
tools2.push({ name, arguments: structuredClone(args) });
|
|
393
|
+
return callTool(name, args, {
|
|
394
|
+
...defaults,
|
|
395
|
+
...options2.fixture,
|
|
396
|
+
processId: definition.id,
|
|
397
|
+
params: base.params,
|
|
398
|
+
state: base.state,
|
|
399
|
+
position: { selectedTurnId: id, lifecycleStatus: "active" }
|
|
400
|
+
});
|
|
401
|
+
},
|
|
402
|
+
reportProgress: (report) => {
|
|
403
|
+
progress.push(structuredClone(report));
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
await handler({
|
|
407
|
+
ctx,
|
|
408
|
+
async turn(def) {
|
|
409
|
+
for (const name of [
|
|
410
|
+
...def.availableTools,
|
|
411
|
+
...Object.keys(def.outcomes ?? {}),
|
|
412
|
+
...def.resolveIntegrationTools?.(base.params, base.state) ?? def.integrationTools ?? [],
|
|
413
|
+
...def.askQuestions ? ["ask_questions"] : []
|
|
414
|
+
])
|
|
415
|
+
requestedTools.add(name);
|
|
416
|
+
const prepared = await def.prepare?.({
|
|
417
|
+
...ctx,
|
|
418
|
+
callIntegrationTool: ctx.callIntegrationTool,
|
|
419
|
+
reportProgress: ctx.reportProgress
|
|
420
|
+
});
|
|
421
|
+
prompts.push(await def.prompt({ ...ctx, prepared }));
|
|
422
|
+
const response = responses.shift();
|
|
423
|
+
if (!response)
|
|
424
|
+
throw new Error(
|
|
425
|
+
`Script exhausted while evaluating '${definition.id}/${id}' after ${prompts.length} prompt(s)`
|
|
426
|
+
);
|
|
427
|
+
if (def.turnEnd?.outcome !== response.outcome && !Object.hasOwn(def.outcomes ?? {}, response.outcome))
|
|
428
|
+
throw new Error(`Undeclared outcome '${response.outcome}' for '${id}'`);
|
|
429
|
+
completed.push(response);
|
|
430
|
+
return { outcome: response.outcome, params: response.params ?? {} };
|
|
431
|
+
},
|
|
432
|
+
async complete(input) {
|
|
433
|
+
completed.push(structuredClone(input));
|
|
434
|
+
},
|
|
435
|
+
park(reason) {
|
|
436
|
+
parked.push(reason);
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
return observe({
|
|
440
|
+
prompts,
|
|
441
|
+
tools: tools2,
|
|
442
|
+
requestedTools: [...requestedTools],
|
|
443
|
+
progress,
|
|
444
|
+
completed,
|
|
445
|
+
parked
|
|
446
|
+
});
|
|
447
|
+
},
|
|
448
|
+
/** Evaluate a process action and collect its requested effects. @public */
|
|
449
|
+
async evaluateAction(id, input = {}, fixture) {
|
|
450
|
+
const action = server?.actions.get(id);
|
|
451
|
+
if (!action) throw new Error(`Unknown action '${id}'`);
|
|
452
|
+
const { ctx, result } = effects(fixture);
|
|
453
|
+
await action.plan?.(structuredClone(input), ctx);
|
|
454
|
+
await action.execute?.(structuredClone(input), ctx);
|
|
455
|
+
return observe(result);
|
|
456
|
+
},
|
|
457
|
+
/** Evaluate process-owned outcome handling against fresh business data. @public */
|
|
458
|
+
async evaluateOutcome(id, outcome, fixture) {
|
|
459
|
+
if (!definition.turns.has(id)) throw new Error(`Undeclared turn '${id}'`);
|
|
460
|
+
const { ctx, result } = effects({
|
|
461
|
+
...fixture,
|
|
462
|
+
position: fixture?.position ?? defaults.position ?? { selectedTurnId: id, lifecycleStatus: "active" }
|
|
463
|
+
});
|
|
464
|
+
for (const handler of server?.turnOutcomeHandlers.get(id) ?? [])
|
|
465
|
+
await handler(
|
|
466
|
+
{
|
|
467
|
+
turnId: id,
|
|
468
|
+
turnRecordId: "trn_test",
|
|
469
|
+
outcome: outcome.outcome,
|
|
470
|
+
params: structuredClone(outcome.params ?? {}),
|
|
471
|
+
turnResultMarkdown: outcome.markdown
|
|
472
|
+
},
|
|
473
|
+
ctx
|
|
474
|
+
);
|
|
475
|
+
return observe(result);
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
export {
|
|
482
|
+
createExtensionTestHarness
|
|
483
|
+
};
|
|
484
|
+
//# sourceMappingURL=process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/process.ts"],"sourcesContent":["import { bindExternalWrites } from \"@leitwerk-dev/external-writes/internal\";\nimport type { ExtensionTestCapability } from \"./test-capability.js\";\n\nexport type { ExtensionTestCapability } from \"./test-capability.js\";\n\nimport type {\n\tActor,\n\tProcessProject,\n\tProcessTurnRecord,\n\tTurnProgressReport,\n} from \"@leitwerk-dev/domain\";\nimport { setupServerExtensions } from \"@leitwerk-dev/extension-runtime\";\nimport {\n\tbuildExtensionCatalogFromModules,\n\tbuildServerProcessForTest,\n\tbuildWorkerProcessForTest,\n\tcreateTestServerProcessContext,\n} from \"@leitwerk-dev/extension-runtime/testing\";\nimport {\n\tbuildProcessLaunchers,\n\tbuildProcessWatchers,\n\tcoreHostCapabilities,\n\tcreateCapabilityAccessor,\n\ttype ExtensionProcessDefinition,\n\ttype FormDefinition,\n\ttype IntegrationToolDefinition,\n\ttype LeitwerkExtensionModule,\n\ttype ProcessLifecycleEffects,\n\tresolveHumanTurnView,\n\ttype ServerProcessContext,\n\ttype TicketCreationDestinationSnapshot,\n\ttoProcessGraphView,\n} from \"@leitwerk-dev/process-sdk\";\nimport { observe, type TestObservation } from \"./observations.js\";\nimport { createProcessFixture, type ProcessFixtureOptions } from \"./process-fixtures.js\";\nimport { createTestServerSetupCapability } from \"./server-extension-test-harness.js\";\n\nexport type { TestObservation } from \"./observations.js\";\n\n/** Data-only process descriptions. @public */\nexport interface ExtensionProcessDescription {\n\t/** @public */\n\tid: string;\n\t/** @public */\n\tentryTurnId: string;\n\t/** @public */\n\tentryTurnIds: string[];\n\t/** @public */\n\tturns: {\n\t\t/** @public */\n\t\tid: string;\n\t\t/** @public */\n\t\tkind: string;\n\t\t/** @public */\n\t\tdescription: string;\n\t\t/** @public */\n\t\tavailableTools?: readonly string[];\n\t\t/** @public */\n\t\tbranchType?: string;\n\t\t/** @public */\n\t\tcontext?: string;\n\t\t/** @public */\n\t\trestorePrimaryLeafAfterTurn?: boolean;\n\t\t/** Human action descriptions, including scheduling and acceptance. @public */\n\t\thumanView?: {\n\t\t\t/** @public */\n\t\t\tactions: readonly {\n\t\t\t\t/** @public */\n\t\t\t\tactionId: string;\n\t\t\t\t/** @public */\n\t\t\t\tacceptanceState: string;\n\t\t\t\t/** @public */\n\t\t\t\tlabel?: string;\n\t\t\t\t/** @public */\n\t\t\t\tdescription?: string;\n\t\t\t\t/** @public */\n\t\t\t\tscheduling?: {\n\t\t\t\t\t/** @public */\n\t\t\t\t\tpreview: {\n\t\t\t\t\t\t/** @public */\n\t\t\t\t\t\tkind: string;\n\t\t\t\t\t\t/** @public */\n\t\t\t\t\t\ttrigger?: string;\n\t\t\t\t\t\t/** @public */\n\t\t\t\t\t\tturnId?: string | null;\n\t\t\t\t\t\t/** @public */\n\t\t\t\t\t\tlifecycleStatus?: string;\n\t\t\t\t\t};\n\t\t\t\t};\n\t\t\t}[];\n\t\t};\n\t\t/** @public */\n\t\tstartFrom?: unknown;\n\t\t/** @public */\n\t\tpublishedProduct?: string;\n\t\t/** @public */\n\t\tconsumedProducts?: readonly string[];\n\t}[];\n\t/** @public */\n\ttransitions: {\n\t\t/** @public */\n\t\tfrom: string;\n\t\t/** @public */\n\t\tnextTurnId?: string;\n\t\t/** @public */\n\t\tlifecycleStatus?: string;\n\t\t/** @public */\n\t\toutcome?: string;\n\t\t/** @public */\n\t\ttrigger?: string;\n\t}[];\n\t/** @public */\n\tactions: {\n\t\t/** @public */\n\t\tid: string;\n\t\t/** @public */\n\t\tlabel: string;\n\t\t/** @public */\n\t\tform?: FormDefinition;\n\t}[];\n\t/** @public */\n\tlaunchers: {\n\t\t/** @public */\n\t\tid: string;\n\t\t/** @public */\n\t\tlabel: string;\n\t\t/** @public */\n\t\tdescription: string;\n\t\t/** @public */\n\t\tlaunchConfigSchema: FormDefinition;\n\t}[];\n\t/** @public */\n\twatchers: {\n\t\t/** @public */\n\t\tid: string;\n\t\t/** @public */\n\t\tlabel: string;\n\t\t/** @public */\n\t\tdescription: string;\n\t\t/** @public */\n\t\tsource: string;\n\t}[];\n}\n\n/** Independent business data for each evaluation. @public */\nexport interface ExtensionToolFixture extends ExtensionProcessFixture {\n\t/** Reuse an invocation identity when retrying the same external write. @public */\n\tinvocationId?: string;\n\t/** Authorized ticket destination resolved by the owning extension. @public */\n\tticketDestination?: TicketCreationDestinationSnapshot;\n}\n\n/** Receipt recorded by an extension-owned external write. @public */\nexport interface ExtensionTestWriteReceipt {\n\t/** @public */\n\tinstanceId: string;\n\t/** @public */\n\twriteType: string;\n\t/** @public */\n\tdedupKey: string;\n\t/** @public */\n\tmetadata?: unknown;\n}\n\n/** Independent business data for each evaluation. @public */\nexport interface ExtensionProcessFixture<TParams = unknown, TState = unknown>\n\textends ProcessFixtureOptions<TParams, TState> {\n\t/** @public */\n\n\tprojects?: readonly ProcessProject[];\n\t/** Named product markdown available to prompts and effects. @public */\n\tproducts?: Readonly<Record<string, string>>;\n\t/** Workspace for process-owned file operations. @public */\n\tworkspaceRoot?: string;\n}\n\n/** Scripted result of one LLM invocation. @public */\nexport interface ExtensionTurnResponse {\n\t/** @public */\n\n\toutcome: string;\n\n\t/** @public */\n\n\tparams?: Record<string, unknown>;\n\n\t/** @public */\n\n\tmarkdown?: string | null;\n\t/** @public */\n\tresultSummary?: string;\n}\n\n/** Observable effects of process-owned server behavior. @public */\nexport interface ExtensionProcessEffects<TState = unknown> {\n\t/** @public */\n\n\ttransitions: {\n\t\t/** @public */\n\t\tturnId?: string | null;\n\n\t\t/** @public */\n\n\t\tlifecycleStatus?: string;\n\n\t\t/** @public */\n\n\t\tstate?: TState;\n\n\t\t/** @public */\n\n\t\ttrigger?: string;\n\t}[];\n\n\t/** @public */\n\n\tinputs: {\n\t\t/** @public */\n\t\tsource: string;\n\n\t\t/** @public */\n\n\t\tkind: string;\n\n\t\t/** @public */\n\n\t\tbodyMarkdown: string;\n\n\t\t/** @public */\n\n\t\ttarget?: unknown;\n\t}[];\n\n\t/** @public */\n\n\tevents: {\n\t\t/** @public */\n\t\ttype: string;\n\n\t\t/** @public */\n\t\tdata: unknown;\n\t}[];\n\n\t/** @public */\n\n\tlifecycle: ProcessLifecycleEffects[];\n}\n\n/** Extension registration inputs; adapters remain owned by their extensions. @public */\nexport interface ExtensionTestHarnessOptions {\n\t/** Configuration keyed by extension manifest id. @public */\n\textensionConfig?: Readonly<Record<string, unknown>>;\n\t/** @public */\n\n\textensions?: readonly LeitwerkExtensionModule[];\n\n\t/** @public */\n\n\tcapabilities?: readonly ExtensionTestCapability[];\n}\n\n/** Evaluate registered behavior without a database or worker. @public */\nexport async function createExtensionTestHarness(options: ExtensionTestHarnessOptions = {}) {\n\tconst catalog = await buildExtensionCatalogFromModules(options.extensions ?? []);\n\tconst receipts: ExtensionTestWriteReceipt[] = [];\n\tconst externalWrites = {\n\t\thasDedupKey: (key: string) => receipts.some((receipt) => receipt.dedupKey === key),\n\t\trecord(input: ExtensionTestWriteReceipt) {\n\t\t\tconst receipt = structuredClone(input);\n\t\t\treceipts.push(receipt);\n\t\t\treturn receipt;\n\t\t},\n\t};\n\tconst capabilities = createCapabilityAccessor([\n\t\t{\n\t\t\ttoken: coreHostCapabilities.serverSetup,\n\t\t\tvalue: createTestServerSetupCapability({ externalWrites }),\n\t\t},\n\t\t...(options.capabilities ?? []),\n\t]);\n\tconst tools = new Map<string, IntegrationToolDefinition<unknown>>();\n\tconst starts: (() => void | Promise<void>)[] = [];\n\tconst stops: (() => void | Promise<void>)[] = [];\n\tconst listeners = new Map<string, Set<(event: never) => void | Promise<void>>>();\n\tconst pendingEvents = new Set<Promise<void>>();\n\tconst eventErrors: unknown[] = [];\n\tlet toolSequence = 0;\n\tfunction emit(type: string, event: unknown) {\n\t\tfor (const listener of listeners.get(type) ?? []) {\n\t\t\tconst task = Promise.resolve()\n\t\t\t\t.then(() => listener(structuredClone(event) as never))\n\t\t\t\t.catch((error) => {\n\t\t\t\t\teventErrors.push(error);\n\t\t\t\t})\n\t\t\t\t.finally(() => pendingEvents.delete(task));\n\t\t\tpendingEvents.add(task);\n\t\t}\n\t}\n\tasync function drainEvents() {\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\ttry {\n\t\t\tawait Promise.race([\n\t\t\t\t(async () => {\n\t\t\t\t\twhile (pendingEvents.size) await Promise.all([...pendingEvents]);\n\t\t\t\t})(),\n\t\t\t\tnew Promise<never>((_resolve, reject) => {\n\t\t\t\t\ttimer = setTimeout(\n\t\t\t\t\t\t() => reject(new Error(\"Extension event handlers did not settle within 12 seconds\")),\n\t\t\t\t\t\t12000,\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t\t]);\n\t\t} finally {\n\t\t\tclearTimeout(timer);\n\t\t}\n\t\tif (eventErrors.length)\n\t\t\tthrow new AggregateError(eventErrors.splice(0), \"Extension event handler failed\");\n\t}\n\tlet closed = false;\n\tfunction assertOpen() {\n\t\tif (closed) throw new Error(\"Extension test harness is closed\");\n\t}\n\t/** @public */\n\tasync function close() {\n\t\tif (closed) return;\n\t\tclosed = true;\n\t\tconst failures: unknown[] = [];\n\t\tfor (const stop of stops.reverse()) {\n\t\t\ttry {\n\t\t\t\tawait stop();\n\t\t\t} catch (error) {\n\t\t\t\tfailures.push(error);\n\t\t\t}\n\t\t}\n\t\tlisteners.clear();\n\t\ttry {\n\t\t\tawait drainEvents();\n\t\t} catch (error) {\n\t\t\tfailures.push(error);\n\t\t}\n\t\tif (failures.length) throw new AggregateError(failures, \"Extension cleanup failed\");\n\t}\n\ttry {\n\t\tawait setupServerExtensions(\n\t\t\tcatalog,\n\t\t\t{\n\t\t\t\tprovide: capabilities.provide.bind(capabilities),\n\t\t\t\tget: capabilities.get.bind(capabilities),\n\t\t\t\trequire: capabilities.require.bind(capabilities),\n\t\t\t\ttool(tool) {\n\t\t\t\t\tif (tools.has(tool.name)) throw new Error(`Duplicate integration tool '${tool.name}'`);\n\t\t\t\t\ttools.set(tool.name, tool as IntegrationToolDefinition<unknown>);\n\t\t\t\t},\n\t\t\t\tevents: {\n\t\t\t\t\ton(type, listener) {\n\t\t\t\t\t\tconst set = listeners.get(type) ?? new Set();\n\t\t\t\t\t\tset.add(listener);\n\t\t\t\t\t\tlisteners.set(type, set);\n\t\t\t\t\t},\n\t\t\t\t\toff(type, listener) {\n\t\t\t\t\t\tlisteners.get(type)?.delete(listener);\n\t\t\t\t\t},\n\t\t\t\t\temit,\n\t\t\t\t},\n\t\t\t\tonStart: (hook) => {\n\t\t\t\t\tstarts.push(hook);\n\t\t\t\t},\n\t\t\t\tonStop: (hook) => {\n\t\t\t\t\tstops.push(hook);\n\t\t\t\t},\n\t\t\t},\n\t\t\t(id) => structuredClone(options.extensionConfig?.[id] ?? {}),\n\t\t);\n\t\tfor (const start of starts) await start();\n\t\tawait drainEvents();\n\t} catch (error) {\n\t\tawait close().catch(() => {});\n\t\tthrow error;\n\t}\n\n\t/** @public */\n\tasync function callTool(\n\t\tname: string,\n\t\targs: Record<string, unknown>,\n\t\tfixture: ExtensionToolFixture = {},\n\t) {\n\t\tassertOpen();\n\t\tconst tool = tools.get(name);\n\t\tif (!tool) throw new Error(`Unknown integration tool '${name}'`);\n\t\tconst process = createProcessFixture(fixture);\n\t\tconst projects = structuredClone([...(fixture.projects ?? [])]);\n\t\tfor (const project of projects)\n\t\t\tif (project.instanceId !== process.id) throw new Error(\"Project belongs to another process\");\n\t\tconst turn: ProcessTurnRecord = {\n\t\t\tid: \"trn_test\",\n\t\t\tinstanceId: process.id,\n\t\t\tturnId: process.selectedTurnId ?? \"test_turn\",\n\t\t\tturnType: \"automatic\",\n\t\t\tstatus: \"running\",\n\t\t\tattemptNumber: 1,\n\t\t\tparentTurnRecordId: null,\n\t\t\tpathType: \"primary\",\n\t\t\tforkPiEntryId: null,\n\t\t\tresultPiEntryId: null,\n\t\t\tmodelProfileId: null,\n\t\t\tturnResultMarkdown: null,\n\t\t\terrorSummary: null,\n\t\t\terrorClass: null,\n\t\t\tstartedAt: process.createdAt,\n\t\t\tendedAt: null,\n\t\t};\n\t\treturn observe(\n\t\t\tawait tool.execute(\n\t\t\t\t{\n\t\t\t\t\tprocess,\n\t\t\t\t\tprojects,\n\t\t\t\t\tturn,\n\t\t\t\t\tproject:\n\t\t\t\t\t\tprojects.find((project) => project.key === args.projectKey) ??\n\t\t\t\t\t\t(projects.length === 1 ? (projects[0] ?? null) : null),\n\t\t\t\t\tidempotencyKey: fixture.invocationId ?? `${process.id}:test_tool:${++toolSequence}`,\n\t\t\t\t\tticketDestination: structuredClone(fixture.ticketDestination),\n\t\t\t\t\texternalWrites: bindExternalWrites(externalWrites, process.id),\n\t\t\t\t\tsignal: new AbortController().signal,\n\t\t\t\t},\n\t\t\t\ttool.parse ? tool.parse(structuredClone(args)) : structuredClone(args),\n\t\t\t),\n\t\t);\n\t}\n\n\tfunction destinationProvider(name: string) {\n\t\tassertOpen();\n\t\tconst provider = tools.get(name)?.capability?.destinations;\n\t\tif (!provider) throw new Error(`Tool '${name}' has no ticket destinations`);\n\t\treturn provider;\n\t}\n\treturn {\n\t\t/** List destinations through the registered tool capability. @public */\n\t\tasync listToolDestinations(name: string, actor: Actor) {\n\t\t\treturn observe(await destinationProvider(name).list({ actor: structuredClone(actor) }));\n\t\t},\n\t\t/** Resolve an authorized destination snapshot. @public */\n\t\tasync resolveToolDestination(name: string, destinationId: string, actor: Actor) {\n\t\t\treturn observe(\n\t\t\t\tawait destinationProvider(name).resolve({ actor: structuredClone(actor), destinationId }),\n\t\t\t);\n\t\t},\n\t\t/** Validate a saved destination against the provider. @public */\n\t\tasync validateToolDestination(name: string, snapshot: TicketCreationDestinationSnapshot) {\n\t\t\tawait destinationProvider(name).validate(structuredClone(snapshot));\n\t\t},\n\t\t/** Detached descriptions of registered tools. @public */\n\t\tdescribeTools() {\n\t\t\tassertOpen();\n\t\t\treturn observe(\n\t\t\t\t[...tools.values()].map(({ name, description, parameters }) => ({\n\t\t\t\t\t/** @public */\n\t\t\t\t\tname,\n\t\t\t\t\t/** @public */\n\t\t\t\t\tdescription,\n\t\t\t\t\t/** @public */\n\t\t\t\t\tparameters,\n\t\t\t\t})),\n\t\t\t);\n\t\t},\n\t\t/** Detached receipts, including writes recorded before an invocation failed. @public */\n\t\twriteReceipts() {\n\t\t\tassertOpen();\n\t\t\treturn observe(receipts);\n\t\t},\n\t\t/** Run an integration tool registered by an extension. @public */\n\t\tcallTool,\n\t\t/** Deliver an event and await its registered handlers. @public */\n\t\tasync emit(type: string, event: unknown) {\n\t\t\tassertOpen();\n\t\t\temit(type, event);\n\t\t\tawait drainEvents();\n\t\t},\n\t\t/** Run cleanup hooks once, including when another hook fails. @public */\n\t\tclose,\n\t\t/** Bind a definition and independent default fixtures. @public */\n\t\tprocess<TParams, TState>(\n\t\t\tdefinition: ExtensionProcessDefinition<TParams, TState>,\n\t\t\tinitial: ExtensionProcessFixture<TParams, TState> = {},\n\t\t) {\n\t\t\tassertOpen();\n\t\t\tconst defaults = structuredClone(initial);\n\t\t\tconst worker = buildWorkerProcessForTest(definition);\n\t\t\tconst server = buildServerProcessForTest(definition);\n\t\t\tconst launchers = buildProcessLaunchers(definition)?.launchers;\n\t\t\tconst watchers = buildProcessWatchers(definition)?.watchers;\n\t\t\tfunction context(fixture: ExtensionProcessFixture<TParams, TState> = {}) {\n\t\t\t\tassertOpen();\n\t\t\t\tconst input = structuredClone({ ...defaults, ...fixture });\n\t\t\t\tconst process = createProcessFixture(input, definition);\n\t\t\t\tconst projects = input.projects ?? [];\n\t\t\t\tfor (const project of projects)\n\t\t\t\t\tif (project.instanceId !== process.id)\n\t\t\t\t\t\tthrow new Error(\"Project belongs to another process\");\n\t\t\t\treturn {\n\t\t\t\t\tprocess,\n\t\t\t\t\tprojects,\n\t\t\t\t\tparams: definition.paramsCodec.parse(JSON.parse(process.paramsJson ?? \"null\")),\n\t\t\t\t\tstate: definition.stateCodec.parse(JSON.parse(process.stateJson ?? \"null\")),\n\t\t\t\t\tturnResultMarkdownByProduct: input.products,\n\t\t\t\t\tworkspaceRoot: input.workspaceRoot,\n\t\t\t\t};\n\t\t\t}\n\t\t\tfunction effects(fixture?: ExtensionProcessFixture<TParams, TState>) {\n\t\t\t\tconst base = context(fixture);\n\t\t\t\tconst result: ExtensionProcessEffects<TState> = {\n\t\t\t\t\ttransitions: [],\n\t\t\t\t\tinputs: [],\n\t\t\t\t\tevents: [],\n\t\t\t\t\tlifecycle: [],\n\t\t\t\t};\n\t\t\t\tconst ctx = createTestServerProcessContext({\n\t\t\t\t\t...base,\n\t\t\t\t\ttransition: async (next) => {\n\t\t\t\t\t\tresult.transitions.push(structuredClone(next));\n\t\t\t\t\t},\n\t\t\t\t\tqueueInput: (input) => {\n\t\t\t\t\t\tresult.inputs.push(structuredClone(input));\n\t\t\t\t\t},\n\t\t\t\t\temitEvent: (type, data) => {\n\t\t\t\t\t\tresult.events.push({ type, data: structuredClone(data) });\n\t\t\t\t\t},\n\t\t\t\t\tapplyLifecycleEffects: (effect) => {\n\t\t\t\t\t\tresult.lifecycle.push(structuredClone(effect));\n\t\t\t\t\t},\n\t\t\t\t\treadProductTurnResultMarkdown: (name) => base.turnResultMarkdownByProduct?.[name] ?? null,\n\t\t\t\t\treadSemanticTurnResultMarkdown: (name) =>\n\t\t\t\t\t\tbase.turnResultMarkdownByProduct?.[name] ?? null,\n\t\t\t\t});\n\t\t\t\treturn { ctx, result };\n\t\t\t}\n\t\t\tcontext();\n\t\t\treturn {\n\t\t\t\t/** Return data descriptions without exposing registered handlers. @public */\n\t\t\t\tdescribe(): TestObservation<ExtensionProcessDescription> {\n\t\t\t\t\tassertOpen();\n\t\t\t\t\treturn observe({\n\t\t\t\t\t\t/** @public */\n\t\t\t\t\t\tid: definition.id,\n\t\t\t\t\t\t/** @public */\n\t\t\t\t\t\tentryTurnId: definition.entryTurnId,\n\t\t\t\t\t\tentryTurnIds: [definition.entryTurnId, ...(definition.alternateEntryTurnIds ?? [])],\n\t\t\t\t\t\t/** @public */\n\t\t\t\t\t\tturns: [...definition.turns].map(([id, binding]) => ({\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\tkind: binding.definition.kind,\n\t\t\t\t\t\t\tdescription: binding.definition.description,\n\t\t\t\t\t\t\t...(binding.definition.kind === \"llm\"\n\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\tavailableTools: binding.definition.availableTools,\n\t\t\t\t\t\t\t\t\t\tbranchType: binding.definition.branchType,\n\t\t\t\t\t\t\t\t\t\tcontext: binding.definition.context,\n\t\t\t\t\t\t\t\t\t\trestorePrimaryLeafAfterTurn: binding.definition.restorePrimaryLeafAfterTurn,\n\t\t\t\t\t\t\t\t\t\tstartFrom: binding.definition.startFrom,\n\t\t\t\t\t\t\t\t\t\tpublishedProduct: binding.definition.publishedProduct,\n\t\t\t\t\t\t\t\t\t\tconsumedProducts: binding.definition.consumedProducts,\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t: binding.definition.kind === \"human\"\n\t\t\t\t\t\t\t\t\t? { humanView: resolveHumanTurnView({ turnId: id, turn: binding.definition }) }\n\t\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t})),\n\t\t\t\t\t\t/** @public */\n\t\t\t\t\t\ttransitions: [\n\t\t\t\t\t\t\t...toProcessGraphView(definition as ExtensionProcessDefinition).turns,\n\t\t\t\t\t\t].flatMap(([from, turn]) =>\n\t\t\t\t\t\t\tturn.transitions.map((transition) => ({ from, ...transition })),\n\t\t\t\t\t\t),\n\t\t\t\t\t\t/** @public */\n\t\t\t\t\t\tactions: [...(server?.actions.values() ?? [])].map((a) => ({\n\t\t\t\t\t\t\t/** @public */\n\t\t\t\t\t\t\tid: a.id,\n\t\t\t\t\t\t\tlabel: a.label,\n\t\t\t\t\t\t\tform: a.form,\n\t\t\t\t\t\t})),\n\t\t\t\t\t\t/** @public */\n\t\t\t\t\t\tlaunchers: [...(launchers?.values() ?? [])].map((a) => ({\n\t\t\t\t\t\t\t/** @public */\n\t\t\t\t\t\t\tid: a.id,\n\t\t\t\t\t\t\tlabel: a.label,\n\t\t\t\t\t\t\tdescription: a.description,\n\t\t\t\t\t\t\tlaunchConfigSchema: a.ui.launchConfigSchema as FormDefinition,\n\t\t\t\t\t\t})),\n\t\t\t\t\t\t/** @public */\n\t\t\t\t\t\twatchers: [...(watchers?.values() ?? [])].map((a) => ({\n\t\t\t\t\t\t\t/** @public */\n\t\t\t\t\t\t\tid: a.id,\n\t\t\t\t\t\t\tlabel: a.label,\n\t\t\t\t\t\t\tdescription: a.description,\n\t\t\t\t\t\t\tsource: a.source.id,\n\t\t\t\t\t\t})),\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\t/** Resolve a UI launcher using its own validation. @public */\n\t\t\t\tasync resolveLaunch(id: string, input: Record<string, unknown>) {\n\t\t\t\t\tconst ctx = context();\n\t\t\t\t\tconst launcher = launchers?.get(id);\n\t\t\t\t\tif (!launcher) throw new Error(`Unknown launcher '${id}'`);\n\t\t\t\t\treturn observe(await launcher.ui.resolveLaunchConfig(structuredClone(input), ctx));\n\t\t\t\t},\n\t\t\t\t/** Prepare persisted launcher input for a new launch. @public */\n\t\t\t\tasync prepareRelaunch(id: string, previousInput: Record<string, unknown>) {\n\t\t\t\t\tconst ctx = context();\n\t\t\t\t\tconst launcher = launchers?.get(id);\n\t\t\t\t\tif (!launcher) throw new Error(`Unknown launcher '${id}'`);\n\t\t\t\t\treturn observe(\n\t\t\t\t\t\t(await launcher.ui.resolveRelaunchInput?.(structuredClone(previousInput), ctx)) ??\n\t\t\t\t\t\t\tpreviousInput,\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\t/** Parse source configuration and resolve a matching watcher event. @public */\n\t\t\t\tasync resolveWatcherLaunch(id: string, event: unknown, config: unknown) {\n\t\t\t\t\tconst ctx = context();\n\t\t\t\t\tconst watcher = watchers?.get(id);\n\t\t\t\t\tif (!watcher) throw new Error(`Unknown watcher '${id}'`);\n\t\t\t\t\tconst parsed = watcher.source.parseConfig(structuredClone(config));\n\t\t\t\t\tif (\n\t\t\t\t\t\t!parsed.enabled ||\n\t\t\t\t\t\t(watcher.matches && !(await watcher.matches(structuredClone(event), ctx)))\n\t\t\t\t\t)\n\t\t\t\t\t\treturn null;\n\t\t\t\t\treturn observe(await watcher.resolveLaunchConfig(structuredClone(event), ctx));\n\t\t\t\t},\n\t\t\t\t/** Run preparation, prompt evaluation, and the registered worker handler. @public */\n\t\t\t\tasync evaluateTurn(\n\t\t\t\t\tid: string,\n\t\t\t\t\toptions: {\n\t\t\t\t\t\t/** @public */\n\t\t\t\t\t\tresponses?: readonly ExtensionTurnResponse[];\n\n\t\t\t\t\t\t/** @public */\n\n\t\t\t\t\t\tfixture?: ExtensionProcessFixture<TParams, TState>;\n\t\t\t\t\t} = {},\n\t\t\t\t) {\n\t\t\t\t\tconst binding = definition.turns.get(id);\n\t\t\t\t\tconst handler = worker?.turns.get(id);\n\t\t\t\t\tif (!binding || !handler) throw new Error(`Unknown worker turn '${id}'`);\n\t\t\t\t\tconst base = context({\n\t\t\t\t\t\t...options.fixture,\n\t\t\t\t\t\tposition: { selectedTurnId: id, lifecycleStatus: \"active\" },\n\t\t\t\t\t});\n\t\t\t\t\tconst prompts: string[] = [];\n\t\t\t\t\tconst tools: { name: string; arguments: Record<string, unknown> }[] = [];\n\t\t\t\t\tconst progress: TurnProgressReport[] = [];\n\t\t\t\t\tconst completed: ExtensionTurnResponse[] = [];\n\t\t\t\t\tconst requestedTools = new Set<string>();\n\t\t\t\t\tconst parked: (string | undefined)[] = [];\n\t\t\t\t\tconst responses = structuredClone([...(options.responses ?? [])]);\n\t\t\t\t\tconst ctx = {\n\t\t\t\t\t\t...base,\n\t\t\t\t\t\tasync callIntegrationTool(name: string, args: Record<string, unknown>) {\n\t\t\t\t\t\t\tconst def = binding.definition;\n\t\t\t\t\t\t\tconst allowed =\n\t\t\t\t\t\t\t\tdef.kind === \"llm\"\n\t\t\t\t\t\t\t\t\t? (def.resolveIntegrationTools?.(base.params, base.state) ?? def.integrationTools)\n\t\t\t\t\t\t\t\t\t: def.kind === \"automatic\"\n\t\t\t\t\t\t\t\t\t\t? def.integrationTools\n\t\t\t\t\t\t\t\t\t\t: [];\n\t\t\t\t\t\t\tif (!allowed?.includes(name))\n\t\t\t\t\t\t\t\tthrow new Error(`Integration tool '${name}' is not declared for '${id}'`);\n\t\t\t\t\t\t\ttools.push({ name, arguments: structuredClone(args) });\n\t\t\t\t\t\t\treturn callTool(name, args, {\n\t\t\t\t\t\t\t\t...defaults,\n\t\t\t\t\t\t\t\t...options.fixture,\n\t\t\t\t\t\t\t\tprocessId: definition.id,\n\t\t\t\t\t\t\t\tparams: base.params,\n\t\t\t\t\t\t\t\tstate: base.state,\n\t\t\t\t\t\t\t\tposition: { selectedTurnId: id, lifecycleStatus: \"active\" },\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t},\n\t\t\t\t\t\treportProgress: (report: TurnProgressReport) => {\n\t\t\t\t\t\t\tprogress.push(structuredClone(report));\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t\tawait handler({\n\t\t\t\t\t\tctx,\n\t\t\t\t\t\tasync turn(def) {\n\t\t\t\t\t\t\tfor (const name of [\n\t\t\t\t\t\t\t\t...def.availableTools,\n\t\t\t\t\t\t\t\t...Object.keys(def.outcomes ?? {}),\n\t\t\t\t\t\t\t\t...(def.resolveIntegrationTools?.(base.params, base.state) ??\n\t\t\t\t\t\t\t\t\tdef.integrationTools ??\n\t\t\t\t\t\t\t\t\t[]),\n\t\t\t\t\t\t\t\t...(def.askQuestions ? [\"ask_questions\"] : []),\n\t\t\t\t\t\t\t])\n\t\t\t\t\t\t\t\trequestedTools.add(name);\n\t\t\t\t\t\t\tconst prepared = await def.prepare?.({\n\t\t\t\t\t\t\t\t...ctx,\n\t\t\t\t\t\t\t\tcallIntegrationTool: ctx.callIntegrationTool,\n\t\t\t\t\t\t\t\treportProgress: ctx.reportProgress,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tprompts.push(await def.prompt({ ...ctx, prepared }));\n\t\t\t\t\t\t\tconst response = responses.shift();\n\t\t\t\t\t\t\tif (!response)\n\t\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t\t`Script exhausted while evaluating '${definition.id}/${id}' after ${prompts.length} prompt(s)`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tdef.turnEnd?.outcome !== response.outcome &&\n\t\t\t\t\t\t\t\t!Object.hasOwn(def.outcomes ?? {}, response.outcome)\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tthrow new Error(`Undeclared outcome '${response.outcome}' for '${id}'`);\n\t\t\t\t\t\t\tcompleted.push(response);\n\t\t\t\t\t\t\treturn { outcome: response.outcome as never, params: response.params ?? {} };\n\t\t\t\t\t\t},\n\t\t\t\t\t\tasync complete(input) {\n\t\t\t\t\t\t\tcompleted.push(structuredClone(input));\n\t\t\t\t\t\t},\n\t\t\t\t\t\tpark(reason) {\n\t\t\t\t\t\t\tparked.push(reason);\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t\treturn observe({\n\t\t\t\t\t\tprompts,\n\t\t\t\t\t\ttools,\n\t\t\t\t\t\trequestedTools: [...requestedTools],\n\t\t\t\t\t\tprogress,\n\t\t\t\t\t\tcompleted,\n\t\t\t\t\t\tparked,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\t/** Evaluate a process action and collect its requested effects. @public */\n\t\t\t\tasync evaluateAction(\n\t\t\t\t\tid: string,\n\t\t\t\t\tinput: Record<string, unknown> = {},\n\t\t\t\t\tfixture?: ExtensionProcessFixture<TParams, TState>,\n\t\t\t\t): Promise<TestObservation<ExtensionProcessEffects<TState>>> {\n\t\t\t\t\tconst action = server?.actions.get(id);\n\t\t\t\t\tif (!action) throw new Error(`Unknown action '${id}'`);\n\t\t\t\t\tconst { ctx, result } = effects(fixture);\n\t\t\t\t\tawait action.plan?.(structuredClone(input), ctx);\n\t\t\t\t\tawait action.execute?.(structuredClone(input), ctx);\n\t\t\t\t\treturn observe(result);\n\t\t\t\t},\n\t\t\t\t/** Evaluate process-owned outcome handling against fresh business data. @public */\n\t\t\t\tasync evaluateOutcome(\n\t\t\t\t\tid: string,\n\t\t\t\t\toutcome: ExtensionTurnResponse,\n\t\t\t\t\tfixture?: ExtensionProcessFixture<TParams, TState>,\n\t\t\t\t): Promise<TestObservation<ExtensionProcessEffects<TState>>> {\n\t\t\t\t\tif (!definition.turns.has(id)) throw new Error(`Undeclared turn '${id}'`);\n\t\t\t\t\tconst { ctx, result } = effects({\n\t\t\t\t\t\t...fixture,\n\t\t\t\t\t\tposition: fixture?.position ??\n\t\t\t\t\t\t\tdefaults.position ?? { selectedTurnId: id, lifecycleStatus: \"active\" },\n\t\t\t\t\t});\n\t\t\t\t\tfor (const handler of server?.turnOutcomeHandlers.get(id) ?? [])\n\t\t\t\t\t\tawait handler(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tturnId: id,\n\t\t\t\t\t\t\t\tturnRecordId: \"trn_test\",\n\t\t\t\t\t\t\t\toutcome: outcome.outcome,\n\t\t\t\t\t\t\t\tparams: structuredClone(outcome.params ?? {}),\n\t\t\t\t\t\t\t\tturnResultMarkdown: outcome.markdown,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tctx as ServerProcessContext<TParams, TState>,\n\t\t\t\t\t\t);\n\t\t\t\t\treturn observe(result);\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,0BAA0B;AAWnC,SAAS,6BAA6B;AACtC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAMA;AAAA,EAGA;AAAA,OACM;AAsOP,eAAsB,2BAA2B,UAAuC,CAAC,GAAG;AAC3F,QAAM,UAAU,MAAM,iCAAiC,QAAQ,cAAc,CAAC,C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QACtB;AAAA;AAAA,QAEA,MAAM,gBACL,IACA,SACA,SAC4D;AAC5D,cAAI,CAAC,WAAW,MAAM,IAAI,EAAE,EAAG,OAAM,IAAI,MAAM,oBAAoB,EAAE,GAAG;AACxE,gBAAM,EAAE,KAAK,OAAO,IAAI,QAAQ;AAAA,YAC/B,GAAG;AAAA,YACH,UAAU,SAAS,YAClB,SAAS,YAAY,EAAE,gBAAgB,IAAI,iBAAiB,SAAS;AAAA,UACvE,CAAC;AACD,qBAAW,WAAW,QAAQ,oBAAoB,IAAI,EAAE,KAAK,CAAC;AAC7D,kBAAM;AAAA,cACL;AAAA,gBACC,QAAQ;AAAA,gBACR,cAAc;AAAA,gBACd,SAAS,QAAQ;AAAA,gBACjB,QAAQ,gBAAgB,QAAQ,UAAU,CAAC,CAAC;AAAA,gBAC5C,oBAAoB,QAAQ;AAAA,cAC7B;AAAA,cACA;AAAA,YACD;AACD,iBAAO,QAAQ,MAAM;AAAA,QACtB;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;","names":["options","tools"]}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { type Actor } from "@leitwerk-dev/domain";
|
|
2
|
+
/** A normalized question with stable option identities. @public */
|
|
3
|
+
export interface QuestionFixture {
|
|
4
|
+
/** @public */
|
|
5
|
+
id: string;
|
|
6
|
+
/** @public */
|
|
7
|
+
question: string;
|
|
8
|
+
/** @public */
|
|
9
|
+
selection: "single" | "multiple";
|
|
10
|
+
/** @public */
|
|
11
|
+
options: readonly {
|
|
12
|
+
/** @public */
|
|
13
|
+
id: string;
|
|
14
|
+
/** @public */
|
|
15
|
+
label: string;
|
|
16
|
+
/** @public */
|
|
17
|
+
details: string | null;
|
|
18
|
+
}[];
|
|
19
|
+
}
|
|
20
|
+
/** Correlated question request data without persistence access. @public */
|
|
21
|
+
export interface QuestionRequestFixture {
|
|
22
|
+
/** @public */
|
|
23
|
+
id: string;
|
|
24
|
+
/** @public */
|
|
25
|
+
instanceId: string;
|
|
26
|
+
/** @public */
|
|
27
|
+
turnRecordId: string;
|
|
28
|
+
/** @public */
|
|
29
|
+
toolCallId: string;
|
|
30
|
+
/** @public */
|
|
31
|
+
questions: readonly QuestionFixture[];
|
|
32
|
+
/** @public */
|
|
33
|
+
status: "open" | "answered" | "cancelled";
|
|
34
|
+
/** @public */
|
|
35
|
+
answers: readonly string[] | null;
|
|
36
|
+
/** @public */
|
|
37
|
+
askedAt: string;
|
|
38
|
+
/** @public */
|
|
39
|
+
answeredAt: string | null;
|
|
40
|
+
/** @public */
|
|
41
|
+
answeredBy: Actor | null;
|
|
42
|
+
/** @public */
|
|
43
|
+
cancelledAt: string | null;
|
|
44
|
+
}
|
|
45
|
+
/** Question content with generated stable option identities. @public */
|
|
46
|
+
export interface QuestionFixtureOptions {
|
|
47
|
+
/** @public */
|
|
48
|
+
question?: string;
|
|
49
|
+
/** @public */
|
|
50
|
+
selection?: "single" | "multiple";
|
|
51
|
+
/** @public */
|
|
52
|
+
options?: readonly {
|
|
53
|
+
/** @public */
|
|
54
|
+
label: string;
|
|
55
|
+
/** @public */
|
|
56
|
+
details?: string | null;
|
|
57
|
+
}[];
|
|
58
|
+
}
|
|
59
|
+
/** Normalize content using the application's question contract. @public */
|
|
60
|
+
export declare function createQuestionFixture(options?: QuestionFixtureOptions): QuestionFixture;
|
|
61
|
+
/** Resolution determines status and all resolution timestamps. @public */
|
|
62
|
+
export type QuestionFixtureResolution = {
|
|
63
|
+
/** @public */
|
|
64
|
+
status: "answered";
|
|
65
|
+
/** @public */
|
|
66
|
+
answers: readonly string[];
|
|
67
|
+
/** @public */
|
|
68
|
+
actor?: Actor;
|
|
69
|
+
} | {
|
|
70
|
+
/** @public */
|
|
71
|
+
status: "cancelled";
|
|
72
|
+
};
|
|
73
|
+
/** Reference inputs and question content, without durable status overrides. @public */
|
|
74
|
+
export interface QuestionRequestFixtureOptions {
|
|
75
|
+
/** @public */
|
|
76
|
+
id?: string;
|
|
77
|
+
/** @public */
|
|
78
|
+
process?: {
|
|
79
|
+
/** @public */
|
|
80
|
+
id: string;
|
|
81
|
+
};
|
|
82
|
+
/** @public */
|
|
83
|
+
turn?: {
|
|
84
|
+
/** @public */
|
|
85
|
+
id: string;
|
|
86
|
+
/** @public */
|
|
87
|
+
instanceId: string;
|
|
88
|
+
};
|
|
89
|
+
/** @public */
|
|
90
|
+
questions?: readonly QuestionFixtureOptions[];
|
|
91
|
+
/** @public */
|
|
92
|
+
resolution?: QuestionFixtureResolution;
|
|
93
|
+
}
|
|
94
|
+
/** Create a consistent request; reject conflicting process and turn references. @public */
|
|
95
|
+
export declare function createQuestionRequestFixture(options?: QuestionRequestFixtureOptions): QuestionRequestFixture;
|
|
96
|
+
//# sourceMappingURL=supported-question-fixtures.d.ts.map
|