@leitwerk-dev/server 0.2.1 → 0.3.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/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  createAppContext
3
- } from "./chunk-CNITOV76.js";
3
+ } from "./chunk-LK3RO6C7.js";
4
4
  import {
5
5
  getDefaultConfig,
6
6
  loadConfig
7
- } from "./chunk-ZSKM25SD.js";
7
+ } from "./chunk-KIOQNNG6.js";
8
8
  export {
9
9
  createAppContext,
10
10
  getDefaultConfig,
package/dist/main.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  createAppContext
3
- } from "./chunk-CNITOV76.js";
3
+ } from "./chunk-LK3RO6C7.js";
4
4
  import {
5
5
  DatabaseSchemaMismatchError,
6
6
  loadConfig,
7
7
  sanitizeConfigForLogging
8
- } from "./chunk-ZSKM25SD.js";
8
+ } from "./chunk-KIOQNNG6.js";
9
9
 
10
10
  // src/main.ts
11
11
  import path2 from "node:path";
@@ -58,7 +58,7 @@ async function runDeploymentPreflight(input) {
58
58
  await mkdir(scratchRoot, { recursive: true });
59
59
  const databaseCopyPath = path.join(scratchRoot, "database", "leitwerk.sqlite");
60
60
  await backupProductionDatabase({ sourcePath, destinationPath: databaseCopyPath });
61
- const createContext = input.createContext ?? (await import("./app-7PKX73TU.js")).createAppContext;
61
+ const createContext = input.createContext ?? (await import("./app-4QSV4FUQ.js")).createAppContext;
62
62
  let ctx2 = null;
63
63
  try {
64
64
  ctx2 = await createContext({
@@ -1,3 +1,4 @@
1
+ import type { ResolvedTurnStart } from "@leitwerk-dev/domain";
1
2
  import type { AppContext } from "../app.js";
2
3
  /** @internal */
3
4
  export declare function createAcceptedLlmTurn(ctx: AppContext | null, input: Parameters<AppContext["deps"]["turnRecords"]["create"]>[0] & {
@@ -23,6 +24,10 @@ export declare function createAcceptedLlmTurnStart(ctx: AppContext, input: {
23
24
  /** @internal */
24
25
  id?: string;
25
26
  /** @internal */
27
+ preparedStart?: Extract<ResolvedTurnStart, {
28
+ kind: "llm";
29
+ }>;
30
+ /** @internal */
26
31
  model?: {
27
32
  /** @internal */
28
33
  profileId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"accepted-turn-start.d.ts","sourceRoot":"","sources":["../../src/test-helpers/accepted-turn-start.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,gBAAgB;AAChB,wBAAgB,qBAAqB,CACpC,GAAG,EAAE,UAAU,GAAG,IAAI,EACtB,KAAK,EAAE,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG;IACnE,gBAAgB;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,gBAAgB;IAChB,QAAQ,EAAE,KAAK,CAAC;CAChB,EACD,OAAO,GAAE,UAAU,CAAC,OAAO,0BAA0B,CAAC,CAAC,CAAC,CAAC,GAAG;IAC3D,gBAAgB;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gBAAgB;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACb,oDAyBN;AAED,gBAAgB;AAChB,wBAAgB,0BAA0B,CACzC,GAAG,EAAE,UAAU,EACf,KAAK,EAAE;IACN,gBAAgB;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,gBAAgB;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB;IAChB,MAAM,EAAE,MAAM,CAAC;CACf,EACD,qBAAqB,EAAE,MAAM,EAC7B,OAAO,GAAE;IACR,gBAAgB;IAChB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,gBAAgB;IAChB,KAAK,CAAC,EAAE;QACP,gBAAgB;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,gBAAgB;QAChB,UAAU,EAAE,MAAM,CAAC;QACnB,gBAAgB;QAChB,OAAO,EAAE,MAAM,CAAC;QAChB,gBAAgB;QAChB,aAAa,EAAE,KAAK,CAAC;KACrB,CAAC;IACF,gBAAgB;IAChB,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,gBAAgB;IAChB,sBAAsB,CAAC,EAAE,MAAM,CAAC;CAC3B,kDA+BN"}
1
+ {"version":3,"file":"accepted-turn-start.d.ts","sourceRoot":"","sources":["../../src/test-helpers/accepted-turn-start.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,gBAAgB;AAChB,wBAAgB,qBAAqB,CACpC,GAAG,EAAE,UAAU,GAAG,IAAI,EACtB,KAAK,EAAE,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG;IACnE,gBAAgB;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,gBAAgB;IAChB,QAAQ,EAAE,KAAK,CAAC;CAChB,EACD,OAAO,GAAE,UAAU,CAAC,OAAO,0BAA0B,CAAC,CAAC,CAAC,CAAC,GAAG;IAC3D,gBAAgB;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gBAAgB;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACb,oDAyBN;AAED,gBAAgB;AAChB,wBAAgB,0BAA0B,CACzC,GAAG,EAAE,UAAU,EACf,KAAK,EAAE;IACN,gBAAgB;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,gBAAgB;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB;IAChB,MAAM,EAAE,MAAM,CAAC;CACf,EACD,qBAAqB,EAAE,MAAM,EAC7B,OAAO,GAAE;IACR,gBAAgB;IAChB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,gBAAgB;IAChB,aAAa,CAAC,EAAE,OAAO,CAAC,iBAAiB,EAAE;QAAE,IAAI,EAAE,KAAK,CAAA;KAAE,CAAC,CAAC;IAC5D,gBAAgB;IAChB,KAAK,CAAC,EAAE;QACP,gBAAgB;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,gBAAgB;QAChB,UAAU,EAAE,MAAM,CAAC;QACnB,gBAAgB;QAChB,OAAO,EAAE,MAAM,CAAC;QAChB,gBAAgB;QAChB,aAAa,EAAE,KAAK,CAAC;KACrB,CAAC;IACF,gBAAgB;IAChB,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,gBAAgB;IAChB,sBAAsB,CAAC,EAAE,MAAM,CAAC;CAC3B,kDA+BN"}
@@ -0,0 +1,14 @@
1
+ import type { ProcessInstance, ResolvedTurnStart } from "@leitwerk-dev/domain";
2
+ import type { ExtensionCatalog } from "@leitwerk-dev/extension-runtime";
3
+ import type { PiResourceBundle } from "@leitwerk-dev/worker-protocol";
4
+ import type { AppContext } from "../app.js";
5
+ /** Prepare fixture resources through the same provider preflight as admitted work. @internal */
6
+ export declare function prepareAcceptedFixtureStart(ctx: AppContext, process: ProcessInstance, turnId: string, contributions: ExtensionCatalog["piContributions"]): Promise<{
7
+ /** @internal */
8
+ start: Extract<ResolvedTurnStart, {
9
+ kind: "llm";
10
+ }>;
11
+ /** @internal */
12
+ bundle: PiResourceBundle;
13
+ }>;
14
+ //# sourceMappingURL=prepared-fixture-start.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prepared-fixture-start.d.ts","sourceRoot":"","sources":["../../src/test-helpers/prepared-fixture-start.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAK5C,gGAAgG;AAChG,wBAAsB,2BAA2B,CAChD,GAAG,EAAE,UAAU,EACf,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,gBAAgB,CAAC,iBAAiB,CAAC,GAChD,OAAO,CAAC;IACV,gBAAgB;IAChB,KAAK,EAAE,OAAO,CAAC,iBAAiB,EAAE;QAAE,IAAI,EAAE,KAAK,CAAA;KAAE,CAAC,CAAC;IACnD,gBAAgB;IAChB,MAAM,EAAE,gBAAgB,CAAC;CACzB,CAAC,CAsDD"}
package/dist/testing.d.ts CHANGED
@@ -2,6 +2,7 @@ export type { ReadonlyPiSessionTree } from "./pi-session-tree.js";
2
2
  export { buildTurnTraceIndexFromSession } from "./process-turn-trace.js";
3
3
  export { buildProcessUiSnapshotProjections } from "./process-ui-snapshot-presenter.js";
4
4
  export { createAcceptedLlmTurn } from "./test-helpers/accepted-turn-start.js";
5
+ export { prepareAcceptedFixtureStart } from "./test-helpers/prepared-fixture-start.js";
5
6
  export { writeProcessSessionSnapshot } from "./test-helpers/session-snapshot-fixtures.js";
6
7
  export { createTestDeps } from "./test-helpers/unit-deps.js";
7
8
  //# sourceMappingURL=testing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,8BAA8B,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,iCAAiC,EAAE,MAAM,oCAAoC,CAAC;AACvF,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,2BAA2B,EAAE,MAAM,6CAA6C,CAAC;AAC1F,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC"}
1
+ {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,8BAA8B,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,iCAAiC,EAAE,MAAM,oCAAoC,CAAC;AACvF,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,2BAA2B,EAAE,MAAM,0CAA0C,CAAC;AACvF,OAAO,EAAE,2BAA2B,EAAE,MAAM,6CAA6C,CAAC;AAC1F,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC"}
package/dist/testing.js CHANGED
@@ -6,10 +6,13 @@ import {
6
6
  createDatabase,
7
7
  createFileBackedProcessSessionSnapshotStore,
8
8
  createInMemoryDatabase,
9
+ createPiResourceBundleCache,
9
10
  createProjectedSessionSnapshotStore,
10
11
  createServerProcessModelPolicy,
11
- getDefaultConfig
12
- } from "./chunk-ZSKM25SD.js";
12
+ createWrites,
13
+ getDefaultConfig,
14
+ prepareCreatedTurnStarts
15
+ } from "./chunk-KIOQNNG6.js";
13
16
 
14
17
  // src/test-helpers/accepted-turn-start.ts
15
18
  function createAcceptedLlmTurn(ctx, input, options = {}) {
@@ -49,7 +52,7 @@ function createAcceptedLlmTurnStart(ctx, input, acceptedWorkerLeaseId, options =
49
52
  continuation: null,
50
53
  state: {
51
54
  kind: "accepted",
52
- start: {
55
+ start: options.preparedStart ?? {
53
56
  kind: "llm",
54
57
  model: options.model ?? {
55
58
  profileId: "fixture-profile",
@@ -69,6 +72,60 @@ function createAcceptedLlmTurnStart(ctx, input, acceptedWorkerLeaseId, options =
69
72
  });
70
73
  }
71
74
 
75
+ // src/test-helpers/prepared-fixture-start.ts
76
+ async function prepareAcceptedFixtureStart(ctx, process, turnId, contributions) {
77
+ const profileId = process.selectedTurnModelProfileId ?? process.defaultModelProfileId ?? ctx.config.process_configs?.[process.processId]?.default_model_profile;
78
+ const write = {
79
+ kind: "create",
80
+ input: {
81
+ instanceId: process.id,
82
+ turnId,
83
+ turnType: "llm",
84
+ proposedTurnRecordId: "fixture-preflight",
85
+ startKind: "selected_turn",
86
+ recoveryTurnRecordId: null,
87
+ continuation: null,
88
+ state: {
89
+ kind: "preparation_failed",
90
+ requestedModelProfileId: profileId ?? null,
91
+ providerOptions: {},
92
+ code: "model_required",
93
+ safeSummary: "Fixture preparation"
94
+ }
95
+ }
96
+ };
97
+ const writes = createWrites({ turnStartWrites: [write] });
98
+ const bundleCache = createPiResourceBundleCache();
99
+ const result = await prepareCreatedTurnStarts(
100
+ {
101
+ config: ctx.config,
102
+ registry: ctx.modelProviderRegistry,
103
+ modelStatusCache: ctx.modelStatusCache,
104
+ piContributions: contributions,
105
+ bundleCache,
106
+ projects: ctx.deps.projects,
107
+ processSkills: ctx.deps.processSkills
108
+ },
109
+ { ...process, selectedTurnId: turnId, selectedTurnModelProfileId: profileId ?? null },
110
+ writes
111
+ );
112
+ if (!result.ok) throw new Error(`Cannot prepare accepted fixture: ${result.message}`);
113
+ const state = write.input.state;
114
+ if (state.kind !== "starting" || state.start.kind !== "llm") {
115
+ throw new Error(
116
+ `Cannot prepare accepted fixture: ${state.kind === "preparation_failed" ? state.safeSummary : state.kind}`
117
+ );
118
+ }
119
+ const bundle = bundleCache.get(state.start.piResourceSnapshotDigest);
120
+ if (!bundle) throw new Error("Prepared fixture resource bundle is missing");
121
+ return {
122
+ /** @internal */
123
+ start: state.start,
124
+ /** @internal */
125
+ bundle
126
+ };
127
+ }
128
+
72
129
  // src/test-helpers/session-snapshot-fixtures.ts
73
130
  async function writeProcessSessionSnapshot(ctx, instanceId, entries) {
74
131
  const store = createProjectedSessionSnapshotStore(
@@ -356,6 +413,7 @@ export {
356
413
  buildTurnTraceIndexFromSession,
357
414
  createAcceptedLlmTurn,
358
415
  createTestDeps,
416
+ prepareAcceptedFixtureStart,
359
417
  writeProcessSessionSnapshot
360
418
  };
361
419
  //# sourceMappingURL=testing.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/test-helpers/accepted-turn-start.ts","../src/test-helpers/session-snapshot-fixtures.ts","../src/test-helpers/process-fixtures.ts","../src/test-helpers/unit-deps.ts"],"sourcesContent":["import type { AppContext } from \"../app.js\";\n\n/** @internal */\nexport function createAcceptedLlmTurn(\n\tctx: AppContext | null,\n\tinput: Parameters<AppContext[\"deps\"][\"turnRecords\"][\"create\"]>[0] & {\n\t\t/** @internal */\n\t\tid: string;\n\t\t/** @internal */\n\t\tturnType: \"llm\";\n\t},\n\toptions: Parameters<typeof createAcceptedLlmTurnStart>[3] & {\n\t\t/** @internal */\n\t\tcurrent?: boolean;\n\t\t/** @internal */\n\t\tworkerId?: string;\n\t} = {},\n) {\n\tif (!ctx) throw new Error(\"Server context not initialized\");\n\tconst current = options.current ?? input.status === \"running\";\n\tconst lease = ctx.deps.leases.create({\n\t\tinstanceId: input.instanceId,\n\t\tworkerId: options.workerId ?? `wkr_${input.id}`,\n\t\tstate: current ? (input.status === \"failed\" ? \"failed\" : \"busy\") : \"exited\",\n\t});\n\tconst start = createAcceptedLlmTurnStart(ctx, input, lease.id, options);\n\tconst record = ctx.deps.turnRecords.create({\n\t\t...input,\n\t\tturnStartRecordId: start.id,\n\t\tacceptedWorkerLeaseId: lease.id,\n\t});\n\tif (current) {\n\t\tctx.deps.processes.update(input.instanceId, {\n\t\t\tcurrentExecution: { kind: \"worker_start\", id: start.id },\n\t\t});\n\t} else {\n\t\tctx.deps.leases.update(lease.id, {\n\t\t\texitedAt: input.endedAt ?? input.startedAt ?? new Date().toISOString(),\n\t\t});\n\t}\n\treturn record;\n}\n\n/** @internal */\nexport function createAcceptedLlmTurnStart(\n\tctx: AppContext,\n\tinput: {\n\t\t/** @internal */\n\t\tid: string;\n\t\t/** @internal */\n\t\tinstanceId: string;\n\t\t/** @internal */\n\t\tturnId: string;\n\t},\n\tacceptedWorkerLeaseId: string,\n\toptions: {\n\t\t/** @internal */\n\t\tid?: string;\n\t\t/** @internal */\n\t\tmodel?: {\n\t\t\t/** @internal */\n\t\t\tprofileId: string;\n\t\t\t/** @internal */\n\t\t\tproviderId: string;\n\t\t\t/** @internal */\n\t\t\tmodelId: string;\n\t\t\t/** @internal */\n\t\t\tthinkingLevel: \"off\";\n\t\t};\n\t\t/** @internal */\n\t\tpiResourceSnapshotDigest?: string;\n\t\t/** @internal */\n\t\tworkerRuntimeProfileId?: string;\n\t} = {},\n) {\n\treturn ctx.deps.turnStarts.create({\n\t\tid: options.id ?? `tsr_${input.id}`,\n\t\tinstanceId: input.instanceId,\n\t\tturnId: input.turnId,\n\t\tturnType: \"llm\",\n\t\tproposedTurnRecordId: input.id,\n\t\tstartKind: \"selected_turn\",\n\t\trecoveryTurnRecordId: null,\n\t\tcontinuation: null,\n\t\tstate: {\n\t\t\tkind: \"accepted\",\n\t\t\tstart: {\n\t\t\t\tkind: \"llm\",\n\t\t\t\tmodel: options.model ?? {\n\t\t\t\t\tprofileId: \"fixture-profile\",\n\t\t\t\t\tproviderId: \"fixture-provider\",\n\t\t\t\t\tmodelId: \"fixture-model\",\n\t\t\t\t\tthinkingLevel: \"off\",\n\t\t\t\t},\n\t\t\t\tproviderOptions: {},\n\t\t\t\tproviderWorkerConfig: null,\n\t\t\t\tpiResourceSnapshotDigest: options.piResourceSnapshotDigest ?? \"fixture-resource-digest\",\n\t\t\t\tworkerRuntimeProfileId: options.workerRuntimeProfileId ?? \"local\",\n\t\t\t\tpiSettings: {},\n\t\t\t},\n\t\t\tturnRecordId: input.id,\n\t\t\tacceptedWorkerLeaseId,\n\t\t},\n\t});\n}\n","import type { AppContext } from \"../app.js\";\nimport { createAllRepos } from \"../db/repositories.js\";\nimport { createFileBackedProcessSessionSnapshotStore } from \"../process-session-store.js\";\nimport { createProjectedSessionSnapshotStore } from \"../session-summary-projection.js\";\n\n/** Accept fixture snapshots through the same persisted projection as worker uploads. @internal */\nexport async function writeProcessSessionSnapshot(\n\tctx: Pick<AppContext, \"db\" | \"config\">,\n\tinstanceId: string,\n\tentries: readonly unknown[],\n): Promise<void> {\n\tconst store = createProjectedSessionSnapshotStore(\n\t\tcreateFileBackedProcessSessionSnapshotStore(ctx.config.storage.tree_files_dir),\n\t\tcreateAllRepos(ctx.db),\n\t);\n\tawait store.writeSnapshot(\n\t\tinstanceId,\n\t\t`${entries.map((entry) => JSON.stringify(entry)).join(\"\\n\")}\\n`,\n\t);\n}\n","import type { TurnId } from \"@leitwerk-dev/domain\";\nimport {\n\ttype AutomaticTurnDefinition,\n\tautomaticTurn,\n\tdefineProcess,\n\ttype ExtensionProcessDefinition,\n\temptyParamsCodec,\n\ttype HumanTurnDefinition,\n\thumanTurn,\n\ttype LlmTurnDefinition,\n\tllmTurn,\n\ttype TurnDefinition,\n} from \"@leitwerk-dev/process-sdk\";\n\nexport function createFixtureLlmTurn(\n\tdescription: string,\n\toverrides: Partial<LlmTurnDefinition<string, Record<string, never>, Record<string, never>>> = {},\n): LlmTurnDefinition<string, Record<string, never>, Record<string, never>> {\n\treturn llmTurn({\n\t\tavailableTools: [],\n\t\tdescription,\n\t\tbranchType: \"primary\",\n\t\tcontext: \"fresh\",\n\t\tprompt: async () => description,\n\t\tturnEnd: { outcome: \"done\", params: {}, complete: true },\n\t\t...overrides,\n\t});\n}\n\nexport function createFixtureHumanTurn(\n\toverrides: Partial<HumanTurnDefinition<Record<string, never>, Record<string, never>>> = {},\n): HumanTurnDefinition<Record<string, never>, Record<string, never>> {\n\treturn humanTurn({\n\t\tdescription: \"Review\",\n\t\treviewSemanticRef: \"plan\",\n\t\tactions: {\n\t\t\tmark_done: {\n\t\t\t\tlabel: \"Mark done\",\n\t\t\t\tacceptanceState: \"accepted\",\n\t\t\t\tcomplete: true,\n\t\t\t},\n\t\t},\n\t\t...overrides,\n\t});\n}\n\nexport function createFixtureAutomaticTurn(\n\tdescription = \"Automatic turn\",\n): AutomaticTurnDefinition<\"done\", Record<string, never>, Record<string, never>> {\n\treturn automaticTurn<Record<string, never>, Record<string, never>, \"done\">({\n\t\tdescription,\n\t\trun: async () => ({ outcome: \"done\", params: {} }),\n\t\tturnEnd: { outcome: \"done\", params: {}, complete: true },\n\t});\n}\n\nfunction ensureFixtureTurnIsValid(\n\tdefinition: TurnDefinition<Record<string, never>, Record<string, never>>,\n): TurnDefinition<Record<string, never>, Record<string, never>> {\n\tif (definition.kind === \"human\" && Object.keys(definition.actions).length === 0) {\n\t\treturn {\n\t\t\t...definition,\n\t\t\tactions: {\n\t\t\t\t__fixture_noop: { label: \"No-op\", acceptanceState: \"neutral\", complete: true },\n\t\t\t},\n\t\t};\n\t}\n\tif (\n\t\t(definition.kind === \"llm\" || definition.kind === \"automatic\") &&\n\t\tObject.keys(definition.outcomes ?? {}).length === 0 &&\n\t\t!definition.turnEnd\n\t) {\n\t\treturn {\n\t\t\t...definition,\n\t\t\tturnEnd: { outcome: \"done\", params: {}, complete: true },\n\t\t} as TurnDefinition<Record<string, never>, Record<string, never>>;\n\t}\n\treturn definition;\n}\n\nexport function createFixtureProcess(input: {\n\tid: string;\n\tentry: TurnId;\n\talternateEntries?: readonly TurnId[];\n\tturns?: Record<string, TurnDefinition<Record<string, never>, Record<string, never>>>;\n}): ExtensionProcessDefinition<Record<string, never>, Record<string, never>> {\n\tconst turns = input.turns ?? {};\n\tconst entries = [input.entry, ...(input.alternateEntries ?? [])];\n\treturn defineProcess<Record<string, never>, Record<string, never>>({\n\t\tid: input.id,\n\t\tdisplayName: input.id,\n\t\tentry: input.entry,\n\t\t...(input.alternateEntries ? { alternateEntries: input.alternateEntries } : {}),\n\t\tparamsCodec: emptyParamsCodec,\n\t\tstateCodec: emptyParamsCodec,\n\t\tinitialState: () => ({}),\n\t\tturns:\n\t\t\tObject.keys(turns).length > 0\n\t\t\t\t? Object.fromEntries(\n\t\t\t\t\t\tObject.entries(turns).map(([turnId, definition]) => [\n\t\t\t\t\t\t\tturnId,\n\t\t\t\t\t\t\tensureFixtureTurnIsValid(definition),\n\t\t\t\t\t\t]),\n\t\t\t\t\t)\n\t\t\t\t: Object.fromEntries(entries.map((turnId) => [turnId, createFixtureLlmTurn(turnId)])),\n\t});\n}\n\nexport function createProcessGraphRegistry(\n\tprocesses: readonly ExtensionProcessDefinition<unknown, unknown>[],\n): ReadonlyMap<string, ExtensionProcessDefinition<unknown, unknown>> {\n\treturn new Map(\n\t\tprocesses.map(\n\t\t\t(process) => [process.id, process as ExtensionProcessDefinition<unknown, unknown>] as const,\n\t\t),\n\t);\n}\n\nexport function createTurnOwnershipFixtureProcess(\n\tid = \"turn_ownership_process\",\n): ExtensionProcessDefinition<Record<string, never>, Record<string, never>> {\n\treturn createFixtureProcess({\n\t\tid,\n\t\tentry: \"llm_turn\",\n\t\tturns: {\n\t\t\tllm_turn: createFixtureLlmTurn(\"LLM turn\"),\n\t\t\tautomatic_turn: createFixtureAutomaticTurn(),\n\t\t\thuman_turn: createFixtureHumanTurn(),\n\t\t},\n\t});\n}\n\nexport function createDefaultTestProcessGraphRegistry(): ReadonlyMap<\n\tstring,\n\tExtensionProcessDefinition<unknown, unknown>\n> {\n\tconst ticket = createFixtureProcess({\n\t\tid: \"ticket_issue_process\",\n\t\tentry: \"generate_plan\",\n\t\tturns: {\n\t\t\tgenerate_plan: createFixtureLlmTurn(\"generate_plan\", {\n\t\t\t\tresultSemanticRef: \"plan\",\n\t\t\t\tturnEnd: undefined,\n\t\t\t\toutcomes: { plan_saved: { description: \"plan_saved\", parameters: {}, to: \"plan_review\" } },\n\t\t\t}),\n\t\t\tplan_review: createFixtureHumanTurn({\n\t\t\t\treviewSemanticRef: \"plan\",\n\t\t\t\tactions: {\n\t\t\t\t\trevision_requested: {\n\t\t\t\t\t\tlabel: \"Request revision\",\n\t\t\t\t\t\tacceptanceState: \"requires_changes\",\n\t\t\t\t\t\tto: \"generate_plan\",\n\t\t\t\t\t},\n\t\t\t\t\tplan_approved: {\n\t\t\t\t\t\tlabel: \"Approve plan\",\n\t\t\t\t\t\tacceptanceState: \"accepted\",\n\t\t\t\t\t\tto: \"implement\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t\timplement: createFixtureLlmTurn(\"implement\", {\n\t\t\t\tturnEnd: { outcome: \"done\", params: {}, to: \"handoff_review\" },\n\t\t\t}),\n\t\t\thandoff_review: createFixtureLlmTurn(\"handoff_review\", {\n\t\t\t\tturnEnd: { outcome: \"created\", params: {}, to: \"run_llm_review\" },\n\t\t\t}),\n\t\t\trun_llm_review: createFixtureLlmTurn(\"run_llm_review\", {\n\t\t\t\tresultSemanticRef: \"review\",\n\t\t\t\tturnEnd: undefined,\n\t\t\t\toutcomes: {\n\t\t\t\t\tissues_found: { description: \"issues_found\", parameters: {}, to: \"address_review\" },\n\t\t\t\t\tno_issues: { description: \"no_issues\", parameters: {}, to: \"implementation_review\" },\n\t\t\t\t},\n\t\t\t}),\n\t\t\taddress_review: createFixtureLlmTurn(\"address_review\", {\n\t\t\t\tturnEnd: { outcome: \"comments_addressed\", params: {}, to: \"verify_build\" },\n\t\t\t}),\n\t\t\tverify_build: createFixtureLlmTurn(\"verify_build\", {\n\t\t\t\tturnEnd: undefined,\n\t\t\t\toutcomes: {\n\t\t\t\t\tbuild_failing: { description: \"build_failing\", parameters: {}, to: \"fix_build\" },\n\t\t\t\t\tbuild_passing: {\n\t\t\t\t\t\tdescription: \"build_passing\",\n\t\t\t\t\t\tparameters: {},\n\t\t\t\t\t\tto: \"commit_and_complete\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t\tfix_build: createFixtureLlmTurn(\"fix_build\", {\n\t\t\t\tturnEnd: { outcome: \"build_fixed\", params: {}, to: \"verify_build\" },\n\t\t\t}),\n\t\t\tcommit_and_complete: createFixtureLlmTurn(\"commit_and_complete\", {\n\t\t\t\tturnEnd: { outcome: \"committed\", params: {}, to: \"implementation_review\" },\n\t\t\t}),\n\t\t\timplementation_review: createFixtureHumanTurn({\n\t\t\t\treviewSemanticRef: \"review\",\n\t\t\t}),\n\t\t},\n\t});\n\tconst mrPolish = createFixtureProcess({\n\t\tid: \"mr_polish_process\",\n\t\tentry: \"address_review\",\n\t\tturns: {\n\t\t\taddress_review: createFixtureLlmTurn(\"address_review\", {\n\t\t\t\tturnEnd: { outcome: \"comments_addressed\", params: {}, to: \"verify_build\" },\n\t\t\t}),\n\t\t\tverify_build: createFixtureLlmTurn(\"verify_build\", {\n\t\t\t\tturnEnd: undefined,\n\t\t\t\toutcomes: {\n\t\t\t\t\tbuild_failing: { description: \"build_failing\", parameters: {}, to: \"fix_build\" },\n\t\t\t\t\tbuild_passing: {\n\t\t\t\t\t\tdescription: \"build_passing\",\n\t\t\t\t\t\tparameters: {},\n\t\t\t\t\t\tto: \"commit_and_complete\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t\tfix_build: createFixtureLlmTurn(\"fix_build\", {\n\t\t\t\tturnEnd: { outcome: \"build_fixed\", params: {}, to: \"verify_build\" },\n\t\t\t}),\n\t\t\tcommit_and_complete: createFixtureLlmTurn(\"commit_and_complete\", {\n\t\t\t\tturnEnd: { outcome: \"committed\", params: {}, to: \"mr_polish_review\" },\n\t\t\t}),\n\t\t\tmr_polish_review: createFixtureHumanTurn({\n\t\t\t\treviewSemanticRef: \"review\",\n\t\t\t}),\n\t\t},\n\t});\n\treturn createProcessGraphRegistry([\n\t\tticket as ExtensionProcessDefinition<unknown, unknown>,\n\t\tmrPolish as ExtensionProcessDefinition<unknown, unknown>,\n\t]);\n}\n","import type { ProcessLaunchPlanServiceLike } from \"@leitwerk-dev/process-sdk\";\nimport { getDefaultConfig } from \"../config/config-loader.js\";\nimport { createDatabase, createInMemoryDatabase, type LeitwerkDb } from \"../db/database.js\";\nimport { createAllRepos, type RepositoryBundle } from \"../db/repositories.js\";\nimport type { ModelStatusCacheSnapshot } from \"../model-providers/model-status-cache.js\";\nimport {\n\tcreateServerProcessModelPolicy,\n\ttype ServerProcessModelPolicy,\n} from \"../process-model-policy/index.js\";\nimport { type Broadcaster, createBroadcaster } from \"../ws/broadcast.js\";\nimport { createDefaultTestProcessGraphRegistry } from \"./process-fixtures.js\";\n\n/** @internal */\nexport interface TestDeps extends RepositoryBundle {\n\t/** @internal */\n\tdb: LeitwerkDb;\n\t/** @internal */\n\tbroadcaster: Broadcaster;\n\t/** @internal */\n\tprocessModelPolicy: ServerProcessModelPolicy;\n\t/** @internal */\n\tlaunchPlans: ProcessLaunchPlanServiceLike;\n\t/** @internal */\n\tgetModelAvailabilitySnapshot: () => ModelStatusCacheSnapshot;\n}\n\n/** Select a turn-start fixture without creating a turn record or attempt. */\nexport function createSelectedTurnStart(\n\tdeps: TestDeps,\n\tinput: Omit<\n\t\tParameters<TestDeps[\"turnStarts\"][\"create\"]>[0],\n\t\t\"startKind\" | \"recoveryTurnRecordId\" | \"continuation\"\n\t>,\n) {\n\tconst record = deps.turnStarts.create({\n\t\t...input,\n\t\tstartKind: \"selected_turn\",\n\t\trecoveryTurnRecordId: null,\n\t\tcontinuation: null,\n\t});\n\tdeps.processes.update(input.instanceId, {\n\t\tcurrentExecution: { kind: \"worker_start\", id: record.id },\n\t});\n\treturn record;\n}\n\n/** @internal */\nexport function createTestDeps(\n\toptions: {\n\t\t/** @internal */\n\t\tsqlitePath?: string;\n\t} = {},\n): TestDeps {\n\tconst db = options.sqlitePath\n\t\t? createDatabase({ sqlitePath: options.sqlitePath, enableWAL: false })\n\t\t: createInMemoryDatabase();\n\tconst repos = createAllRepos(db);\n\tconst config = getDefaultConfig();\n\tconst processModelPolicy = createServerProcessModelPolicy({\n\t\tconfig,\n\t\tprocessGraphs: createDefaultTestProcessGraphRegistry(),\n\t\tprocessActionRegistry: { getTurnDefinition: () => undefined },\n\t});\n\tconst launchPlans: ProcessLaunchPlanServiceLike = {\n\t\tasync prepare(launchPlan, opts = {}) {\n\t\t\treturn processModelPolicy.prepareLaunchPlan(launchPlan, opts);\n\t\t},\n\t};\n\tconst getModelAvailabilitySnapshot = (): ModelStatusCacheSnapshot => ({\n\t\trevision: 1,\n\t\tcapturedAt: new Date().toISOString(),\n\t\tavailabilityTransitions: [],\n\t\tprofiles: config.pi.model_profiles.map((profile) => ({\n\t\t\tprofileId: profile.id,\n\t\t\tproviderId: profile.provider,\n\t\t\tmodelId: profile.model_id,\n\t\t\tavailability: \"available\",\n\t\t\tcheckedAt: new Date().toISOString(),\n\t\t\texpiresAt: new Date(Date.now() + 60_000).toISOString(),\n\t\t})),\n\t});\n\tconst createTurnRecord = repos.turnRecords.create.bind(repos.turnRecords);\n\trepos.turnRecords.create = (input) => {\n\t\tconst turnType = input.turnType ?? \"llm\";\n\t\tif (\n\t\t\t(turnType === \"llm\" || turnType === \"automatic\") &&\n\t\t\t(!input.turnStartRecordId || !input.acceptedWorkerLeaseId)\n\t\t) {\n\t\t\tconst turnRecordId = input.id ?? `trn_fixture_${crypto.randomUUID()}`;\n\t\t\tconst isCurrent =\n\t\t\t\tinput.status === \"running\" || input.status === \"failed\" || input.status === undefined;\n\t\t\tconst lease = repos.leases.create({\n\t\t\t\tinstanceId: input.instanceId,\n\t\t\t\tworkerId: `wkr_fixture_${turnRecordId}`,\n\t\t\t\tstate: input.status === \"failed\" ? \"failed\" : isCurrent ? \"busy\" : \"exited\",\n\t\t\t});\n\t\t\tconst start = repos.turnStarts.create({\n\t\t\t\tid: `tsr_fixture_${turnRecordId}`,\n\t\t\t\tinstanceId: input.instanceId,\n\t\t\t\tturnId: input.turnId,\n\t\t\t\tturnType,\n\t\t\t\tproposedTurnRecordId: turnRecordId,\n\t\t\t\tstartKind: \"selected_turn\",\n\t\t\t\trecoveryTurnRecordId: null,\n\t\t\t\tcontinuation: null,\n\t\t\t\tstate: {\n\t\t\t\t\tkind: \"accepted\",\n\t\t\t\t\tstart:\n\t\t\t\t\t\tturnType === \"automatic\"\n\t\t\t\t\t\t\t? { kind: \"automatic\" }\n\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\tkind: \"llm\",\n\t\t\t\t\t\t\t\t\tmodel: {\n\t\t\t\t\t\t\t\t\t\tprofileId: input.modelProfileId ?? \"fixture-model\",\n\t\t\t\t\t\t\t\t\t\tproviderId: \"fixture-provider\",\n\t\t\t\t\t\t\t\t\t\tmodelId: \"fixture-model\",\n\t\t\t\t\t\t\t\t\t\tthinkingLevel: \"low\",\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tproviderOptions: {},\n\t\t\t\t\t\t\t\t\tproviderWorkerConfig: null,\n\t\t\t\t\t\t\t\t\tpiResourceSnapshotDigest: \"fixture-resource-snapshot\",\n\t\t\t\t\t\t\t\t\tworkerRuntimeProfileId: \"local\",\n\t\t\t\t\t\t\t\t\tpiSettings: {},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\tturnRecordId,\n\t\t\t\t\tacceptedWorkerLeaseId: lease.id,\n\t\t\t\t},\n\t\t\t});\n\t\t\tconst record = createTurnRecord({\n\t\t\t\t...input,\n\t\t\t\tid: turnRecordId,\n\t\t\t\tturnStartRecordId: start.id,\n\t\t\t\tacceptedWorkerLeaseId: lease.id,\n\t\t\t});\n\t\t\tif (isCurrent) {\n\t\t\t\trepos.processes.update(record.instanceId, {\n\t\t\t\t\tcurrentExecution: { kind: \"worker_start\", id: start.id },\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\trepos.leases.update(lease.id, { exitedAt: record.endedAt ?? record.startedAt });\n\t\t\t}\n\t\t\treturn record;\n\t\t}\n\t\treturn createTurnRecord(input);\n\t};\n\treturn {\n\t\tdb,\n\t\t...repos,\n\t\tbroadcaster: createBroadcaster(),\n\t\tprocessModelPolicy,\n\t\tlaunchPlans,\n\t\tgetModelAvailabilitySnapshot,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;AAGO,SAAS,sBACf,KACA,OAMA,UAKI,CAAC,GACJ;AACD,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,gCAAgC;AAC1D,QAAM,UAAU,QAAQ,WAAW,MAAM,WAAW;AACpD,QAAM,QAAQ,IAAI,KAAK,OAAO,OAAO;AAAA,IACpC,YAAY,MAAM;AAAA,IAClB,UAAU,QAAQ,YAAY,OAAO,MAA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,YAAM,QAAQ,MAAM,WAAW,OAAO;AAAA,QACrC,IAAI,eAAe,YAAY;AAAA,QAC/B,YAAY,MAAM;AAAA,QAClB,QAAQ,MAAM;AAAA,QACd;AAAA,QACA,sBAAsB;AAAA,QACtB,WAAW;AAAA,QACX,sBAAsB;AAAA,QACtB,cAAc;AAAA,QACd,OAAO;AAAA,UACN,MAAM;AAAA,UACN,OACC,aAAa,cACV,EAAE,MAAM,YAAY,IACpB;AAAA,YACA,MAAM;AAAA,YACN,OAAO;AAAA,cACN,WAAW,MAAM,kBAAkB;AAAA,cACnC,YAAY;AAAA,cACZ,SAAS;AAAA,cACT,eAAe;AAAA,YAChB;AAAA,YACA,iBAAiB,CAAC;AAAA,YAClB,sBAAsB;AAAA,YACtB,0BAA0B;AAAA,YAC1B,wBAAwB;AAAA,YACxB,YAAY,CAAC;AAAA,UACd;AAAA,UACH;AAAA,UACA,uBAAuB,MAAM;AAAA,QAC9B;AAAA,MACD,CAAC;AACD,YAAM,SAAS,iBAAiB;AAAA,QAC/B,GAAG;AAAA,QACH,IAAI;AAAA,QACJ,mBAAmB,MAAM;AAAA,QACzB,uBAAuB,MAAM;AAAA,MAC9B,CAAC;AACD,UAAI,WAAW;AACd,cAAM,UAAU,OAAO,OAAO,YAAY;AAAA,UACzC,kBAAkB,EAAE,MAAM,gBAAgB,IAAI,MAAM,GAAG;AAAA,QACxD,CAAC;AAAA,MACF,OAAO;AACN,cAAM,OAAO,OAAO,MAAM,IAAI,EAAE,UAAU,OAAO,WAAW,OAAO,UAAU,CAAC;AAAA,MAC/E;AACA,aAAO;AAAA,IACR;AACA,WAAO,iBAAiB,KAAK;AAAA,EAC9B;AACA,SAAO;AAAA,IACN;AAAA,IACA,GAAG;AAAA,IACH,aAAa,kBAAkB;AAAA,IAC/B;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;","names":[]}
1
+ {"version":3,"sources":["../src/test-helpers/accepted-turn-start.ts","../src/test-helpers/prepared-fixture-start.ts","../src/test-helpers/session-snapshot-fixtures.ts","../src/test-helpers/process-fixtures.ts","../src/test-helpers/unit-deps.ts"],"sourcesContent":["import type { ResolvedTurnStart } from \"@leitwerk-dev/domain\";\nimport type { AppContext } from \"../app.js\";\n\n/** @internal */\nexport function createAcceptedLlmTurn(\n\tctx: AppContext | null,\n\tinput: Parameters<AppContext[\"deps\"][\"turnRecords\"][\"create\"]>[0] & {\n\t\t/** @internal */\n\t\tid: string;\n\t\t/** @internal */\n\t\tturnType: \"llm\";\n\t},\n\toptions: Parameters<typeof createAcceptedLlmTurnStart>[3] & {\n\t\t/** @internal */\n\t\tcurrent?: boolean;\n\t\t/** @internal */\n\t\tworkerId?: string;\n\t} = {},\n) {\n\tif (!ctx) throw new Error(\"Server context not initialized\");\n\tconst current = options.current ?? input.status === \"running\";\n\tconst lease = ctx.deps.leases.create({\n\t\tinstanceId: input.instanceId,\n\t\tworkerId: options.workerId ?? `wkr_${input.id}`,\n\t\tstate: current ? (input.status === \"failed\" ? \"failed\" : \"busy\") : \"exited\",\n\t});\n\tconst start = createAcceptedLlmTurnStart(ctx, input, lease.id, options);\n\tconst record = ctx.deps.turnRecords.create({\n\t\t...input,\n\t\tturnStartRecordId: start.id,\n\t\tacceptedWorkerLeaseId: lease.id,\n\t});\n\tif (current) {\n\t\tctx.deps.processes.update(input.instanceId, {\n\t\t\tcurrentExecution: { kind: \"worker_start\", id: start.id },\n\t\t});\n\t} else {\n\t\tctx.deps.leases.update(lease.id, {\n\t\t\texitedAt: input.endedAt ?? input.startedAt ?? new Date().toISOString(),\n\t\t});\n\t}\n\treturn record;\n}\n\n/** @internal */\nexport function createAcceptedLlmTurnStart(\n\tctx: AppContext,\n\tinput: {\n\t\t/** @internal */\n\t\tid: string;\n\t\t/** @internal */\n\t\tinstanceId: string;\n\t\t/** @internal */\n\t\tturnId: string;\n\t},\n\tacceptedWorkerLeaseId: string,\n\toptions: {\n\t\t/** @internal */\n\t\tid?: string;\n\t\t/** @internal */\n\t\tpreparedStart?: Extract<ResolvedTurnStart, { kind: \"llm\" }>;\n\t\t/** @internal */\n\t\tmodel?: {\n\t\t\t/** @internal */\n\t\t\tprofileId: string;\n\t\t\t/** @internal */\n\t\t\tproviderId: string;\n\t\t\t/** @internal */\n\t\t\tmodelId: string;\n\t\t\t/** @internal */\n\t\t\tthinkingLevel: \"off\";\n\t\t};\n\t\t/** @internal */\n\t\tpiResourceSnapshotDigest?: string;\n\t\t/** @internal */\n\t\tworkerRuntimeProfileId?: string;\n\t} = {},\n) {\n\treturn ctx.deps.turnStarts.create({\n\t\tid: options.id ?? `tsr_${input.id}`,\n\t\tinstanceId: input.instanceId,\n\t\tturnId: input.turnId,\n\t\tturnType: \"llm\",\n\t\tproposedTurnRecordId: input.id,\n\t\tstartKind: \"selected_turn\",\n\t\trecoveryTurnRecordId: null,\n\t\tcontinuation: null,\n\t\tstate: {\n\t\t\tkind: \"accepted\",\n\t\t\tstart: options.preparedStart ?? {\n\t\t\t\tkind: \"llm\",\n\t\t\t\tmodel: options.model ?? {\n\t\t\t\t\tprofileId: \"fixture-profile\",\n\t\t\t\t\tproviderId: \"fixture-provider\",\n\t\t\t\t\tmodelId: \"fixture-model\",\n\t\t\t\t\tthinkingLevel: \"off\",\n\t\t\t\t},\n\t\t\t\tproviderOptions: {},\n\t\t\t\tproviderWorkerConfig: null,\n\t\t\t\tpiResourceSnapshotDigest: options.piResourceSnapshotDigest ?? \"fixture-resource-digest\",\n\t\t\t\tworkerRuntimeProfileId: options.workerRuntimeProfileId ?? \"local\",\n\t\t\t\tpiSettings: {},\n\t\t\t},\n\t\t\tturnRecordId: input.id,\n\t\t\tacceptedWorkerLeaseId,\n\t\t},\n\t});\n}\n","import type { ProcessInstance, ResolvedTurnStart } from \"@leitwerk-dev/domain\";\nimport type { ExtensionCatalog } from \"@leitwerk-dev/extension-runtime\";\nimport type { PiResourceBundle } from \"@leitwerk-dev/worker-protocol\";\nimport type { AppContext } from \"../app.js\";\nimport { createPiResourceBundleCache } from \"../pi-resources/index.js\";\nimport { prepareCreatedTurnStarts } from \"../process-engine/turn-start-preflight.js\";\nimport { createWrites, type TurnStartWrite } from \"../process-engine/writes/writes.js\";\n\n/** Prepare fixture resources through the same provider preflight as admitted work. @internal */\nexport async function prepareAcceptedFixtureStart(\n\tctx: AppContext,\n\tprocess: ProcessInstance,\n\tturnId: string,\n\tcontributions: ExtensionCatalog[\"piContributions\"],\n): Promise<{\n\t/** @internal */\n\tstart: Extract<ResolvedTurnStart, { kind: \"llm\" }>;\n\t/** @internal */\n\tbundle: PiResourceBundle;\n}> {\n\tconst profileId =\n\t\tprocess.selectedTurnModelProfileId ??\n\t\tprocess.defaultModelProfileId ??\n\t\tctx.config.process_configs?.[process.processId]?.default_model_profile;\n\tconst write: Extract<TurnStartWrite, { kind: \"create\" }> = {\n\t\tkind: \"create\",\n\t\tinput: {\n\t\t\tinstanceId: process.id,\n\t\t\tturnId,\n\t\t\tturnType: \"llm\",\n\t\t\tproposedTurnRecordId: \"fixture-preflight\",\n\t\t\tstartKind: \"selected_turn\",\n\t\t\trecoveryTurnRecordId: null,\n\t\t\tcontinuation: null,\n\t\t\tstate: {\n\t\t\t\tkind: \"preparation_failed\",\n\t\t\t\trequestedModelProfileId: profileId ?? null,\n\t\t\t\tproviderOptions: {},\n\t\t\t\tcode: \"model_required\",\n\t\t\t\tsafeSummary: \"Fixture preparation\",\n\t\t\t},\n\t\t},\n\t};\n\tconst writes = createWrites({ turnStartWrites: [write] });\n\tconst bundleCache = createPiResourceBundleCache();\n\tconst result = await prepareCreatedTurnStarts(\n\t\t{\n\t\t\tconfig: ctx.config,\n\t\t\tregistry: ctx.modelProviderRegistry,\n\t\t\tmodelStatusCache: ctx.modelStatusCache,\n\t\t\tpiContributions: contributions,\n\t\t\tbundleCache,\n\t\t\tprojects: ctx.deps.projects,\n\t\t\tprocessSkills: ctx.deps.processSkills,\n\t\t},\n\t\t{ ...process, selectedTurnId: turnId, selectedTurnModelProfileId: profileId ?? null },\n\t\twrites,\n\t);\n\tif (!result.ok) throw new Error(`Cannot prepare accepted fixture: ${result.message}`);\n\tconst state = write.input.state;\n\tif (state.kind !== \"starting\" || state.start.kind !== \"llm\") {\n\t\tthrow new Error(\n\t\t\t`Cannot prepare accepted fixture: ${state.kind === \"preparation_failed\" ? state.safeSummary : state.kind}`,\n\t\t);\n\t}\n\tconst bundle = bundleCache.get(state.start.piResourceSnapshotDigest);\n\tif (!bundle) throw new Error(\"Prepared fixture resource bundle is missing\");\n\treturn {\n\t\t/** @internal */\n\t\tstart: state.start,\n\t\t/** @internal */\n\t\tbundle,\n\t};\n}\n","import type { AppContext } from \"../app.js\";\nimport { createAllRepos } from \"../db/repositories.js\";\nimport { createFileBackedProcessSessionSnapshotStore } from \"../process-session-store.js\";\nimport { createProjectedSessionSnapshotStore } from \"../session-summary-projection.js\";\n\n/** Accept fixture snapshots through the same persisted projection as worker uploads. @internal */\nexport async function writeProcessSessionSnapshot(\n\tctx: Pick<AppContext, \"db\" | \"config\">,\n\tinstanceId: string,\n\tentries: readonly unknown[],\n): Promise<void> {\n\tconst store = createProjectedSessionSnapshotStore(\n\t\tcreateFileBackedProcessSessionSnapshotStore(ctx.config.storage.tree_files_dir),\n\t\tcreateAllRepos(ctx.db),\n\t);\n\tawait store.writeSnapshot(\n\t\tinstanceId,\n\t\t`${entries.map((entry) => JSON.stringify(entry)).join(\"\\n\")}\\n`,\n\t);\n}\n","import type { TurnId } from \"@leitwerk-dev/domain\";\nimport {\n\ttype AutomaticTurnDefinition,\n\tautomaticTurn,\n\tdefineProcess,\n\ttype ExtensionProcessDefinition,\n\temptyParamsCodec,\n\ttype HumanTurnDefinition,\n\thumanTurn,\n\ttype LlmTurnDefinition,\n\tllmTurn,\n\ttype TurnDefinition,\n} from \"@leitwerk-dev/process-sdk\";\n\nexport function createFixtureLlmTurn(\n\tdescription: string,\n\toverrides: Partial<LlmTurnDefinition<string, Record<string, never>, Record<string, never>>> = {},\n): LlmTurnDefinition<string, Record<string, never>, Record<string, never>> {\n\treturn llmTurn({\n\t\tavailableTools: [],\n\t\tdescription,\n\t\tbranchType: \"primary\",\n\t\tcontext: \"fresh\",\n\t\tprompt: async () => description,\n\t\tturnEnd: { outcome: \"done\", params: {}, complete: true },\n\t\t...overrides,\n\t});\n}\n\nexport function createFixtureHumanTurn(\n\toverrides: Partial<HumanTurnDefinition<Record<string, never>, Record<string, never>>> = {},\n): HumanTurnDefinition<Record<string, never>, Record<string, never>> {\n\treturn humanTurn({\n\t\tdescription: \"Review\",\n\t\treviewSemanticRef: \"plan\",\n\t\tactions: {\n\t\t\tmark_done: {\n\t\t\t\tlabel: \"Mark done\",\n\t\t\t\tacceptanceState: \"accepted\",\n\t\t\t\tcomplete: true,\n\t\t\t},\n\t\t},\n\t\t...overrides,\n\t});\n}\n\nexport function createFixtureAutomaticTurn(\n\tdescription = \"Automatic turn\",\n): AutomaticTurnDefinition<\"done\", Record<string, never>, Record<string, never>> {\n\treturn automaticTurn<Record<string, never>, Record<string, never>, \"done\">({\n\t\tdescription,\n\t\trun: async () => ({ outcome: \"done\", params: {} }),\n\t\tturnEnd: { outcome: \"done\", params: {}, complete: true },\n\t});\n}\n\nfunction ensureFixtureTurnIsValid(\n\tdefinition: TurnDefinition<Record<string, never>, Record<string, never>>,\n): TurnDefinition<Record<string, never>, Record<string, never>> {\n\tif (definition.kind === \"human\" && Object.keys(definition.actions).length === 0) {\n\t\treturn {\n\t\t\t...definition,\n\t\t\tactions: {\n\t\t\t\t__fixture_noop: { label: \"No-op\", acceptanceState: \"neutral\", complete: true },\n\t\t\t},\n\t\t};\n\t}\n\tif (\n\t\t(definition.kind === \"llm\" || definition.kind === \"automatic\") &&\n\t\tObject.keys(definition.outcomes ?? {}).length === 0 &&\n\t\t!definition.turnEnd\n\t) {\n\t\treturn {\n\t\t\t...definition,\n\t\t\tturnEnd: { outcome: \"done\", params: {}, complete: true },\n\t\t} as TurnDefinition<Record<string, never>, Record<string, never>>;\n\t}\n\treturn definition;\n}\n\nexport function createFixtureProcess(input: {\n\tid: string;\n\tentry: TurnId;\n\talternateEntries?: readonly TurnId[];\n\tturns?: Record<string, TurnDefinition<Record<string, never>, Record<string, never>>>;\n}): ExtensionProcessDefinition<Record<string, never>, Record<string, never>> {\n\tconst turns = input.turns ?? {};\n\tconst entries = [input.entry, ...(input.alternateEntries ?? [])];\n\treturn defineProcess<Record<string, never>, Record<string, never>>({\n\t\tid: input.id,\n\t\tdisplayName: input.id,\n\t\tentry: input.entry,\n\t\t...(input.alternateEntries ? { alternateEntries: input.alternateEntries } : {}),\n\t\tparamsCodec: emptyParamsCodec,\n\t\tstateCodec: emptyParamsCodec,\n\t\tinitialState: () => ({}),\n\t\tturns:\n\t\t\tObject.keys(turns).length > 0\n\t\t\t\t? Object.fromEntries(\n\t\t\t\t\t\tObject.entries(turns).map(([turnId, definition]) => [\n\t\t\t\t\t\t\tturnId,\n\t\t\t\t\t\t\tensureFixtureTurnIsValid(definition),\n\t\t\t\t\t\t]),\n\t\t\t\t\t)\n\t\t\t\t: Object.fromEntries(entries.map((turnId) => [turnId, createFixtureLlmTurn(turnId)])),\n\t});\n}\n\nexport function createProcessGraphRegistry(\n\tprocesses: readonly ExtensionProcessDefinition<unknown, unknown>[],\n): ReadonlyMap<string, ExtensionProcessDefinition<unknown, unknown>> {\n\treturn new Map(\n\t\tprocesses.map(\n\t\t\t(process) => [process.id, process as ExtensionProcessDefinition<unknown, unknown>] as const,\n\t\t),\n\t);\n}\n\nexport function createTurnOwnershipFixtureProcess(\n\tid = \"turn_ownership_process\",\n): ExtensionProcessDefinition<Record<string, never>, Record<string, never>> {\n\treturn createFixtureProcess({\n\t\tid,\n\t\tentry: \"llm_turn\",\n\t\tturns: {\n\t\t\tllm_turn: createFixtureLlmTurn(\"LLM turn\"),\n\t\t\tautomatic_turn: createFixtureAutomaticTurn(),\n\t\t\thuman_turn: createFixtureHumanTurn(),\n\t\t},\n\t});\n}\n\nexport function createDefaultTestProcessGraphRegistry(): ReadonlyMap<\n\tstring,\n\tExtensionProcessDefinition<unknown, unknown>\n> {\n\tconst ticket = createFixtureProcess({\n\t\tid: \"ticket_issue_process\",\n\t\tentry: \"generate_plan\",\n\t\tturns: {\n\t\t\tgenerate_plan: createFixtureLlmTurn(\"generate_plan\", {\n\t\t\t\tresultSemanticRef: \"plan\",\n\t\t\t\tturnEnd: undefined,\n\t\t\t\toutcomes: { plan_saved: { description: \"plan_saved\", parameters: {}, to: \"plan_review\" } },\n\t\t\t}),\n\t\t\tplan_review: createFixtureHumanTurn({\n\t\t\t\treviewSemanticRef: \"plan\",\n\t\t\t\tactions: {\n\t\t\t\t\trevision_requested: {\n\t\t\t\t\t\tlabel: \"Request revision\",\n\t\t\t\t\t\tacceptanceState: \"requires_changes\",\n\t\t\t\t\t\tto: \"generate_plan\",\n\t\t\t\t\t},\n\t\t\t\t\tplan_approved: {\n\t\t\t\t\t\tlabel: \"Approve plan\",\n\t\t\t\t\t\tacceptanceState: \"accepted\",\n\t\t\t\t\t\tto: \"implement\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t\timplement: createFixtureLlmTurn(\"implement\", {\n\t\t\t\tturnEnd: { outcome: \"done\", params: {}, to: \"handoff_review\" },\n\t\t\t}),\n\t\t\thandoff_review: createFixtureLlmTurn(\"handoff_review\", {\n\t\t\t\tturnEnd: { outcome: \"created\", params: {}, to: \"run_llm_review\" },\n\t\t\t}),\n\t\t\trun_llm_review: createFixtureLlmTurn(\"run_llm_review\", {\n\t\t\t\tresultSemanticRef: \"review\",\n\t\t\t\tturnEnd: undefined,\n\t\t\t\toutcomes: {\n\t\t\t\t\tissues_found: { description: \"issues_found\", parameters: {}, to: \"address_review\" },\n\t\t\t\t\tno_issues: { description: \"no_issues\", parameters: {}, to: \"implementation_review\" },\n\t\t\t\t},\n\t\t\t}),\n\t\t\taddress_review: createFixtureLlmTurn(\"address_review\", {\n\t\t\t\tturnEnd: { outcome: \"comments_addressed\", params: {}, to: \"verify_build\" },\n\t\t\t}),\n\t\t\tverify_build: createFixtureLlmTurn(\"verify_build\", {\n\t\t\t\tturnEnd: undefined,\n\t\t\t\toutcomes: {\n\t\t\t\t\tbuild_failing: { description: \"build_failing\", parameters: {}, to: \"fix_build\" },\n\t\t\t\t\tbuild_passing: {\n\t\t\t\t\t\tdescription: \"build_passing\",\n\t\t\t\t\t\tparameters: {},\n\t\t\t\t\t\tto: \"commit_and_complete\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t\tfix_build: createFixtureLlmTurn(\"fix_build\", {\n\t\t\t\tturnEnd: { outcome: \"build_fixed\", params: {}, to: \"verify_build\" },\n\t\t\t}),\n\t\t\tcommit_and_complete: createFixtureLlmTurn(\"commit_and_complete\", {\n\t\t\t\tturnEnd: { outcome: \"committed\", params: {}, to: \"implementation_review\" },\n\t\t\t}),\n\t\t\timplementation_review: createFixtureHumanTurn({\n\t\t\t\treviewSemanticRef: \"review\",\n\t\t\t}),\n\t\t},\n\t});\n\tconst mrPolish = createFixtureProcess({\n\t\tid: \"mr_polish_process\",\n\t\tentry: \"address_review\",\n\t\tturns: {\n\t\t\taddress_review: createFixtureLlmTurn(\"address_review\", {\n\t\t\t\tturnEnd: { outcome: \"comments_addressed\", params: {}, to: \"verify_build\" },\n\t\t\t}),\n\t\t\tverify_build: createFixtureLlmTurn(\"verify_build\", {\n\t\t\t\tturnEnd: undefined,\n\t\t\t\toutcomes: {\n\t\t\t\t\tbuild_failing: { description: \"build_failing\", parameters: {}, to: \"fix_build\" },\n\t\t\t\t\tbuild_passing: {\n\t\t\t\t\t\tdescription: \"build_passing\",\n\t\t\t\t\t\tparameters: {},\n\t\t\t\t\t\tto: \"commit_and_complete\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t\tfix_build: createFixtureLlmTurn(\"fix_build\", {\n\t\t\t\tturnEnd: { outcome: \"build_fixed\", params: {}, to: \"verify_build\" },\n\t\t\t}),\n\t\t\tcommit_and_complete: createFixtureLlmTurn(\"commit_and_complete\", {\n\t\t\t\tturnEnd: { outcome: \"committed\", params: {}, to: \"mr_polish_review\" },\n\t\t\t}),\n\t\t\tmr_polish_review: createFixtureHumanTurn({\n\t\t\t\treviewSemanticRef: \"review\",\n\t\t\t}),\n\t\t},\n\t});\n\treturn createProcessGraphRegistry([\n\t\tticket as ExtensionProcessDefinition<unknown, unknown>,\n\t\tmrPolish as ExtensionProcessDefinition<unknown, unknown>,\n\t]);\n}\n","import type { ProcessLaunchPlanServiceLike } from \"@leitwerk-dev/process-sdk\";\nimport { getDefaultConfig } from \"../config/config-loader.js\";\nimport { createDatabase, createInMemoryDatabase, type LeitwerkDb } from \"../db/database.js\";\nimport { createAllRepos, type RepositoryBundle } from \"../db/repositories.js\";\nimport type { ModelStatusCacheSnapshot } from \"../model-providers/model-status-cache.js\";\nimport {\n\tcreateServerProcessModelPolicy,\n\ttype ServerProcessModelPolicy,\n} from \"../process-model-policy/index.js\";\nimport { type Broadcaster, createBroadcaster } from \"../ws/broadcast.js\";\nimport { createDefaultTestProcessGraphRegistry } from \"./process-fixtures.js\";\n\n/** @internal */\nexport interface TestDeps extends RepositoryBundle {\n\t/** @internal */\n\tdb: LeitwerkDb;\n\t/** @internal */\n\tbroadcaster: Broadcaster;\n\t/** @internal */\n\tprocessModelPolicy: ServerProcessModelPolicy;\n\t/** @internal */\n\tlaunchPlans: ProcessLaunchPlanServiceLike;\n\t/** @internal */\n\tgetModelAvailabilitySnapshot: () => ModelStatusCacheSnapshot;\n}\n\n/** Select a turn-start fixture without creating a turn record or attempt. */\nexport function createSelectedTurnStart(\n\tdeps: TestDeps,\n\tinput: Omit<\n\t\tParameters<TestDeps[\"turnStarts\"][\"create\"]>[0],\n\t\t\"startKind\" | \"recoveryTurnRecordId\" | \"continuation\"\n\t>,\n) {\n\tconst record = deps.turnStarts.create({\n\t\t...input,\n\t\tstartKind: \"selected_turn\",\n\t\trecoveryTurnRecordId: null,\n\t\tcontinuation: null,\n\t});\n\tdeps.processes.update(input.instanceId, {\n\t\tcurrentExecution: { kind: \"worker_start\", id: record.id },\n\t});\n\treturn record;\n}\n\n/** @internal */\nexport function createTestDeps(\n\toptions: {\n\t\t/** @internal */\n\t\tsqlitePath?: string;\n\t} = {},\n): TestDeps {\n\tconst db = options.sqlitePath\n\t\t? createDatabase({ sqlitePath: options.sqlitePath, enableWAL: false })\n\t\t: createInMemoryDatabase();\n\tconst repos = createAllRepos(db);\n\tconst config = getDefaultConfig();\n\tconst processModelPolicy = createServerProcessModelPolicy({\n\t\tconfig,\n\t\tprocessGraphs: createDefaultTestProcessGraphRegistry(),\n\t\tprocessActionRegistry: { getTurnDefinition: () => undefined },\n\t});\n\tconst launchPlans: ProcessLaunchPlanServiceLike = {\n\t\tasync prepare(launchPlan, opts = {}) {\n\t\t\treturn processModelPolicy.prepareLaunchPlan(launchPlan, opts);\n\t\t},\n\t};\n\tconst getModelAvailabilitySnapshot = (): ModelStatusCacheSnapshot => ({\n\t\trevision: 1,\n\t\tcapturedAt: new Date().toISOString(),\n\t\tavailabilityTransitions: [],\n\t\tprofiles: config.pi.model_profiles.map((profile) => ({\n\t\t\tprofileId: profile.id,\n\t\t\tproviderId: profile.provider,\n\t\t\tmodelId: profile.model_id,\n\t\t\tavailability: \"available\",\n\t\t\tcheckedAt: new Date().toISOString(),\n\t\t\texpiresAt: new Date(Date.now() + 60_000).toISOString(),\n\t\t})),\n\t});\n\tconst createTurnRecord = repos.turnRecords.create.bind(repos.turnRecords);\n\trepos.turnRecords.create = (input) => {\n\t\tconst turnType = input.turnType ?? \"llm\";\n\t\tif (\n\t\t\t(turnType === \"llm\" || turnType === \"automatic\") &&\n\t\t\t(!input.turnStartRecordId || !input.acceptedWorkerLeaseId)\n\t\t) {\n\t\t\tconst turnRecordId = input.id ?? `trn_fixture_${crypto.randomUUID()}`;\n\t\t\tconst isCurrent =\n\t\t\t\tinput.status === \"running\" || input.status === \"failed\" || input.status === undefined;\n\t\t\tconst lease = repos.leases.create({\n\t\t\t\tinstanceId: input.instanceId,\n\t\t\t\tworkerId: `wkr_fixture_${turnRecordId}`,\n\t\t\t\tstate: input.status === \"failed\" ? \"failed\" : isCurrent ? \"busy\" : \"exited\",\n\t\t\t});\n\t\t\tconst start = repos.turnStarts.create({\n\t\t\t\tid: `tsr_fixture_${turnRecordId}`,\n\t\t\t\tinstanceId: input.instanceId,\n\t\t\t\tturnId: input.turnId,\n\t\t\t\tturnType,\n\t\t\t\tproposedTurnRecordId: turnRecordId,\n\t\t\t\tstartKind: \"selected_turn\",\n\t\t\t\trecoveryTurnRecordId: null,\n\t\t\t\tcontinuation: null,\n\t\t\t\tstate: {\n\t\t\t\t\tkind: \"accepted\",\n\t\t\t\t\tstart:\n\t\t\t\t\t\tturnType === \"automatic\"\n\t\t\t\t\t\t\t? { kind: \"automatic\" }\n\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\tkind: \"llm\",\n\t\t\t\t\t\t\t\t\tmodel: {\n\t\t\t\t\t\t\t\t\t\tprofileId: input.modelProfileId ?? \"fixture-model\",\n\t\t\t\t\t\t\t\t\t\tproviderId: \"fixture-provider\",\n\t\t\t\t\t\t\t\t\t\tmodelId: \"fixture-model\",\n\t\t\t\t\t\t\t\t\t\tthinkingLevel: \"low\",\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tproviderOptions: {},\n\t\t\t\t\t\t\t\t\tproviderWorkerConfig: null,\n\t\t\t\t\t\t\t\t\tpiResourceSnapshotDigest: \"fixture-resource-snapshot\",\n\t\t\t\t\t\t\t\t\tworkerRuntimeProfileId: \"local\",\n\t\t\t\t\t\t\t\t\tpiSettings: {},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\tturnRecordId,\n\t\t\t\t\tacceptedWorkerLeaseId: lease.id,\n\t\t\t\t},\n\t\t\t});\n\t\t\tconst record = createTurnRecord({\n\t\t\t\t...input,\n\t\t\t\tid: turnRecordId,\n\t\t\t\tturnStartRecordId: start.id,\n\t\t\t\tacceptedWorkerLeaseId: lease.id,\n\t\t\t});\n\t\t\tif (isCurrent) {\n\t\t\t\trepos.processes.update(record.instanceId, {\n\t\t\t\t\tcurrentExecution: { kind: \"worker_start\", id: start.id },\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\trepos.leases.update(lease.id, { exitedAt: record.endedAt ?? record.startedAt });\n\t\t\t}\n\t\t\treturn record;\n\t\t}\n\t\treturn createTurnRecord(input);\n\t};\n\treturn {\n\t\tdb,\n\t\t...repos,\n\t\tbroadcaster: createBroadcaster(),\n\t\tprocessModelPolicy,\n\t\tlaunchPlans,\n\t\tgetModelAvailabilitySnapshot,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAIO,SAAS,sBACf,KACA,OAMA,UAKI,CAAC,GACJ;AACD,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,gCAAgC;AAC1D,QAAM,UAAU,QAAQ,WAAW,MAAM,WAAW;AACpD,QAAM,QAAQ,IAAI,KAAK,OAAO,OAAO;AAAA,IACpC,YAAY,MAAM;AAAA,IAClB,UAAU,QAAQ,YAAY,OAAO,MAAM,EAAE;AAAA,IAC7C,OAAO,UAAW,MAAM,WAAW,WAAW,WAAW,SAAU;AAAA,EACpE,CAAC;AACD,QAAM,QAAQ,2BAA2B,KAAK,OAAO,MAAM,IAAI,OAAO;AACtE,QAAM,SAAS,IAAI,KAAK,YAAY,OAAO;AAAA,IAC1C,GAAG;AAAA,IACH,mBAAmB,MAAM;AAAA,IACzB,uBAAuB,MAAM;AAAA,EAC9B,CAAC;AACD,MAAI,SAAS;AACZ,QAAI,KAAK,UAAU,OAAO,MAAM,YAAY;AAAA,MAC3C,kBAAkB,EAAE,MAAM,gBAAgB,IAAI,MAAM,GAAG;AAAA,IACxD,CAAC;AAAA,EACF,OAAO;AACN,QAAI,KAAK,OAAO,OAAO,MAAM,IAAI;AAAA,MAChC,UAAU,MAAM,WAAW,MAAM,cAAa,oBAAI,KAAK,GAAE,YAAY;AAAA,IACtE,CAAC;AAAA,EACF;AACA,SAAO;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BAAwB;AAAA,YACxB,YAAY,CAAC;AAAA,UACd;AAAA,UACH;AAAA,UACA,uBAAuB,MAAM;AAAA,QAC9B;AAAA,MACD,CAAC;AACD,YAAM,SAAS,iBAAiB;AAAA,QAC/B,GAAG;AAAA,QACH,IAAI;AAAA,QACJ,mBAAmB,MAAM;AAAA,QACzB,uBAAuB,MAAM;AAAA,MAC9B,CAAC;AACD,UAAI,WAAW;AACd,cAAM,UAAU,OAAO,OAAO,YAAY;AAAA,UACzC,kBAAkB,EAAE,MAAM,gBAAgB,IAAI,MAAM,GAAG;AAAA,QACxD,CAAC;AAAA,MACF,OAAO;AACN,cAAM,OAAO,OAAO,MAAM,IAAI,EAAE,UAAU,OAAO,WAAW,OAAO,UAAU,CAAC;AAAA,MAC/E;AACA,aAAO;AAAA,IACR;AACA,WAAO,iBAAiB,KAAK;AAAA,EAC9B;AACA,SAAO;AAAA,IACN;AAAA,IACA,GAAG;AAAA,IACH,aAAa,kBAAkB;AAAA,IAC/B;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leitwerk-dev/server",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/leitwerk-dev/leitwerk.git",
@@ -28,15 +28,15 @@
28
28
  "@earendil-works/pi-coding-agent": "^0.81.1",
29
29
  "@fastify/cookie": "11.0.2",
30
30
  "@fastify/websocket": "^11.2.0",
31
- "@leitwerk-dev/domain": "0.2.1",
32
- "@leitwerk-dev/extension-runtime": "0.2.1",
33
- "@leitwerk-dev/external-writes": "0.2.1",
34
- "@leitwerk-dev/process-sdk": "0.2.1",
35
- "@leitwerk-dev/protocol": "0.2.1",
36
- "@leitwerk-dev/session-transfer": "0.2.1",
37
- "@leitwerk-dev/watcher-utils": "0.2.1",
38
- "@leitwerk-dev/worker-protocol": "0.2.1",
39
- "@leitwerk-dev/worker-runners": "0.2.1",
31
+ "@leitwerk-dev/domain": "0.3.0",
32
+ "@leitwerk-dev/extension-runtime": "0.3.0",
33
+ "@leitwerk-dev/external-writes": "0.3.0",
34
+ "@leitwerk-dev/process-sdk": "0.3.0",
35
+ "@leitwerk-dev/protocol": "0.3.0",
36
+ "@leitwerk-dev/session-transfer": "0.3.0",
37
+ "@leitwerk-dev/watcher-utils": "0.3.0",
38
+ "@leitwerk-dev/worker-protocol": "0.3.0",
39
+ "@leitwerk-dev/worker-runners": "0.3.0",
40
40
  "cron-parser": "^5.5.0",
41
41
  "defu": "^6.1.7",
42
42
  "drizzle-orm": "1.0.0-rc.4",
@@ -48,7 +48,7 @@
48
48
  "yaml": "^2.8.3"
49
49
  },
50
50
  "optionalDependencies": {
51
- "@leitwerk-dev/worker": "0.2.1"
51
+ "@leitwerk-dev/worker": "0.3.0"
52
52
  },
53
53
  "devDependencies": {
54
54
  "tsup": "^8.5.1",
@@ -1,3 +1,4 @@
1
+ import type { ResolvedTurnStart } from "@leitwerk-dev/domain";
1
2
  import type { AppContext } from "../app.js";
2
3
 
3
4
  /** @internal */
@@ -57,6 +58,8 @@ export function createAcceptedLlmTurnStart(
57
58
  /** @internal */
58
59
  id?: string;
59
60
  /** @internal */
61
+ preparedStart?: Extract<ResolvedTurnStart, { kind: "llm" }>;
62
+ /** @internal */
60
63
  model?: {
61
64
  /** @internal */
62
65
  profileId: string;
@@ -84,7 +87,7 @@ export function createAcceptedLlmTurnStart(
84
87
  continuation: null,
85
88
  state: {
86
89
  kind: "accepted",
87
- start: {
90
+ start: options.preparedStart ?? {
88
91
  kind: "llm",
89
92
  model: options.model ?? {
90
93
  profileId: "fixture-profile",
@@ -0,0 +1,74 @@
1
+ import type { ProcessInstance, ResolvedTurnStart } from "@leitwerk-dev/domain";
2
+ import type { ExtensionCatalog } from "@leitwerk-dev/extension-runtime";
3
+ import type { PiResourceBundle } from "@leitwerk-dev/worker-protocol";
4
+ import type { AppContext } from "../app.js";
5
+ import { createPiResourceBundleCache } from "../pi-resources/index.js";
6
+ import { prepareCreatedTurnStarts } from "../process-engine/turn-start-preflight.js";
7
+ import { createWrites, type TurnStartWrite } from "../process-engine/writes/writes.js";
8
+
9
+ /** Prepare fixture resources through the same provider preflight as admitted work. @internal */
10
+ export async function prepareAcceptedFixtureStart(
11
+ ctx: AppContext,
12
+ process: ProcessInstance,
13
+ turnId: string,
14
+ contributions: ExtensionCatalog["piContributions"],
15
+ ): Promise<{
16
+ /** @internal */
17
+ start: Extract<ResolvedTurnStart, { kind: "llm" }>;
18
+ /** @internal */
19
+ bundle: PiResourceBundle;
20
+ }> {
21
+ const profileId =
22
+ process.selectedTurnModelProfileId ??
23
+ process.defaultModelProfileId ??
24
+ ctx.config.process_configs?.[process.processId]?.default_model_profile;
25
+ const write: Extract<TurnStartWrite, { kind: "create" }> = {
26
+ kind: "create",
27
+ input: {
28
+ instanceId: process.id,
29
+ turnId,
30
+ turnType: "llm",
31
+ proposedTurnRecordId: "fixture-preflight",
32
+ startKind: "selected_turn",
33
+ recoveryTurnRecordId: null,
34
+ continuation: null,
35
+ state: {
36
+ kind: "preparation_failed",
37
+ requestedModelProfileId: profileId ?? null,
38
+ providerOptions: {},
39
+ code: "model_required",
40
+ safeSummary: "Fixture preparation",
41
+ },
42
+ },
43
+ };
44
+ const writes = createWrites({ turnStartWrites: [write] });
45
+ const bundleCache = createPiResourceBundleCache();
46
+ const result = await prepareCreatedTurnStarts(
47
+ {
48
+ config: ctx.config,
49
+ registry: ctx.modelProviderRegistry,
50
+ modelStatusCache: ctx.modelStatusCache,
51
+ piContributions: contributions,
52
+ bundleCache,
53
+ projects: ctx.deps.projects,
54
+ processSkills: ctx.deps.processSkills,
55
+ },
56
+ { ...process, selectedTurnId: turnId, selectedTurnModelProfileId: profileId ?? null },
57
+ writes,
58
+ );
59
+ if (!result.ok) throw new Error(`Cannot prepare accepted fixture: ${result.message}`);
60
+ const state = write.input.state;
61
+ if (state.kind !== "starting" || state.start.kind !== "llm") {
62
+ throw new Error(
63
+ `Cannot prepare accepted fixture: ${state.kind === "preparation_failed" ? state.safeSummary : state.kind}`,
64
+ );
65
+ }
66
+ const bundle = bundleCache.get(state.start.piResourceSnapshotDigest);
67
+ if (!bundle) throw new Error("Prepared fixture resource bundle is missing");
68
+ return {
69
+ /** @internal */
70
+ start: state.start,
71
+ /** @internal */
72
+ bundle,
73
+ };
74
+ }
package/src/testing.ts CHANGED
@@ -2,5 +2,6 @@ export type { ReadonlyPiSessionTree } from "./pi-session-tree.js";
2
2
  export { buildTurnTraceIndexFromSession } from "./process-turn-trace.js";
3
3
  export { buildProcessUiSnapshotProjections } from "./process-ui-snapshot-presenter.js";
4
4
  export { createAcceptedLlmTurn } from "./test-helpers/accepted-turn-start.js";
5
+ export { prepareAcceptedFixtureStart } from "./test-helpers/prepared-fixture-start.js";
5
6
  export { writeProcessSessionSnapshot } from "./test-helpers/session-snapshot-fixtures.js";
6
7
  export { createTestDeps } from "./test-helpers/unit-deps.js";
@@ -1,8 +0,0 @@
1
- import {
2
- createAppContext
3
- } from "./chunk-CNITOV76.js";
4
- import "./chunk-ZSKM25SD.js";
5
- export {
6
- createAppContext
7
- };
8
- //# sourceMappingURL=app-7PKX73TU.js.map