@leitwerk-dev/test-support 0.1.9 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/dist/{chunk-KIDBCGNW.js → chunk-2PCDTYVH.js} +26 -26
  2. package/dist/chunk-2PCDTYVH.js.map +1 -0
  3. package/dist/chunk-5BZSJ4OO.js +192 -0
  4. package/dist/chunk-5BZSJ4OO.js.map +1 -0
  5. package/dist/{chunk-QFCJV2VA.js → chunk-ECAWLVYB.js} +224 -17
  6. package/dist/chunk-ECAWLVYB.js.map +1 -0
  7. package/dist/{chunk-JUH3LUYK.js → chunk-EXHTWQAE.js} +5 -1
  8. package/dist/chunk-EXHTWQAE.js.map +1 -0
  9. package/dist/compact-process-detail-fixture.d.ts +3 -0
  10. package/dist/compact-process-detail-fixture.d.ts.map +1 -1
  11. package/dist/fakes/fake-git-ops.d.ts +12 -0
  12. package/dist/fakes/fake-git-ops.d.ts.map +1 -1
  13. package/dist/fakes/fake-llm.d.ts +11 -0
  14. package/dist/fakes/fake-llm.d.ts.map +1 -1
  15. package/dist/fakes/index.d.ts +1 -1
  16. package/dist/fakes/index.d.ts.map +1 -1
  17. package/dist/fakes/index.js +111 -2
  18. package/dist/fakes/index.js.map +1 -1
  19. package/dist/fixtures.js +137 -2
  20. package/dist/fixtures.js.map +1 -1
  21. package/dist/http-launch.d.ts +9 -0
  22. package/dist/http-launch.d.ts.map +1 -0
  23. package/dist/index.d.ts +24 -12
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +113 -12
  26. package/dist/index.js.map +1 -1
  27. package/dist/integration-harness.d.ts +36 -1
  28. package/dist/integration-harness.d.ts.map +1 -1
  29. package/dist/integration.d.ts +3 -3
  30. package/dist/integration.d.ts.map +1 -1
  31. package/dist/integration.js +184 -4
  32. package/dist/integration.js.map +1 -1
  33. package/dist/local-git.d.ts +231 -0
  34. package/dist/local-git.d.ts.map +1 -0
  35. package/dist/local-git.js +428 -0
  36. package/dist/local-git.js.map +1 -0
  37. package/dist/model-provider-fixtures.d.ts +15 -0
  38. package/dist/model-provider-fixtures.d.ts.map +1 -0
  39. package/dist/polling.d.ts +2 -1
  40. package/dist/polling.d.ts.map +1 -1
  41. package/dist/process-driver.d.ts +14 -0
  42. package/dist/process-driver.d.ts.map +1 -0
  43. package/dist/question-fixtures.d.ts +2 -0
  44. package/dist/question-fixtures.d.ts.map +1 -1
  45. package/dist/server-extension-test-harness.d.ts +57 -2
  46. package/dist/server-extension-test-harness.d.ts.map +1 -1
  47. package/dist/stub-worker-entry.js +9 -5
  48. package/dist/stub-worker-entry.js.map +1 -1
  49. package/dist/test-diagnostics.d.ts +14 -0
  50. package/dist/test-diagnostics.d.ts.map +1 -0
  51. package/dist/worker-testing/in-process-worker-spawn.d.ts +21 -0
  52. package/dist/worker-testing/in-process-worker-spawn.d.ts.map +1 -1
  53. package/dist/worker-testing/index.d.ts +6 -7
  54. package/dist/worker-testing/index.d.ts.map +1 -1
  55. package/dist/worker-testing/index.js +381 -7
  56. package/dist/worker-testing/index.js.map +1 -1
  57. package/dist/worker-testing/schema-driven-stub-pi.d.ts +5 -0
  58. package/dist/worker-testing/schema-driven-stub-pi.d.ts.map +1 -1
  59. package/dist/worker-testing/stub-pi-controls.d.ts +4 -0
  60. package/dist/worker-testing/stub-pi-controls.d.ts.map +1 -1
  61. package/dist/worker-testing/stub-pi-tree-handle.d.ts +93 -1
  62. package/dist/worker-testing/stub-pi-tree-handle.d.ts.map +1 -1
  63. package/dist/worker-testing/worker-runtime-harness.d.ts +37 -2
  64. package/dist/worker-testing/worker-runtime-harness.d.ts.map +1 -1
  65. package/dist/worker-testing/worker-start-payload.d.ts +17 -1
  66. package/dist/worker-testing/worker-start-payload.d.ts.map +1 -1
  67. package/package.json +15 -9
  68. package/src/compact-process-detail-fixture.ts +37 -3
  69. package/src/fakes/fake-git-ops.ts +12 -0
  70. package/src/fakes/fake-llm.ts +11 -0
  71. package/src/fakes/index.ts +1 -1
  72. package/src/http-launch.ts +88 -0
  73. package/src/index.ts +31 -41
  74. package/src/integration-harness.ts +100 -9
  75. package/src/integration.ts +3 -9
  76. package/src/local-git.ts +499 -0
  77. package/src/model-provider-fixtures.ts +36 -0
  78. package/src/polling.ts +3 -2
  79. package/src/process-driver.ts +63 -0
  80. package/src/question-fixtures.ts +2 -0
  81. package/src/server-extension-test-harness.ts +100 -6
  82. package/src/test-diagnostics.ts +69 -0
  83. package/src/worker-testing/in-process-worker-spawn.ts +49 -2
  84. package/src/worker-testing/index.ts +4 -26
  85. package/src/worker-testing/schema-driven-stub-pi.ts +8 -1
  86. package/src/worker-testing/stub-pi-controls.ts +4 -0
  87. package/src/worker-testing/stub-pi-tree-handle.ts +301 -21
  88. package/src/worker-testing/worker-runtime-harness.ts +57 -6
  89. package/src/worker-testing/worker-start-payload.ts +18 -1
  90. package/dist/chunk-3MQO3NCX.js +0 -15
  91. package/dist/chunk-3MQO3NCX.js.map +0 -1
  92. package/dist/chunk-7ZK5QRGP.js +0 -98
  93. package/dist/chunk-7ZK5QRGP.js.map +0 -1
  94. package/dist/chunk-JUH3LUYK.js.map +0 -1
  95. package/dist/chunk-KIDBCGNW.js.map +0 -1
  96. package/dist/chunk-QFCJV2VA.js.map +0 -1
  97. package/dist/chunk-R4KVUGWR.js +0 -83
  98. package/dist/chunk-R4KVUGWR.js.map +0 -1
  99. package/dist/chunk-ST2C4VKX.js +0 -297
  100. package/dist/chunk-ST2C4VKX.js.map +0 -1
  101. package/dist/compact-process-detail-fixture.js +0 -73
  102. package/dist/compact-process-detail-fixture.js.map +0 -1
  103. package/dist/fakes/fake-git-ops.js +0 -101
  104. package/dist/fakes/fake-git-ops.js.map +0 -1
  105. package/dist/fakes/fake-llm.js +0 -27
  106. package/dist/fakes/fake-llm.js.map +0 -1
  107. package/dist/in-process-worker.js +0 -2
  108. package/dist/in-process-worker.js.map +0 -1
  109. package/dist/integration-harness.js +0 -38
  110. package/dist/integration-harness.js.map +0 -1
  111. package/dist/polling.js +0 -14
  112. package/dist/polling.js.map +0 -1
  113. package/dist/question-fixtures.js +0 -26
  114. package/dist/question-fixtures.js.map +0 -1
  115. package/dist/server-extension-test-harness.js +0 -169
  116. package/dist/server-extension-test-harness.js.map +0 -1
  117. package/dist/test-app.d.ts +0 -23
  118. package/dist/test-app.d.ts.map +0 -1
  119. package/dist/test-app.js +0 -47
  120. package/dist/test-app.js.map +0 -1
  121. package/dist/worker-testing/in-process-worker-spawn.js +0 -61
  122. package/dist/worker-testing/in-process-worker-spawn.js.map +0 -1
  123. package/dist/worker-testing/ipc-harness.d.ts +0 -11
  124. package/dist/worker-testing/ipc-harness.d.ts.map +0 -1
  125. package/dist/worker-testing/ipc-harness.js +0 -17
  126. package/dist/worker-testing/ipc-harness.js.map +0 -1
  127. package/dist/worker-testing/schema-driven-stub-pi.js +0 -65
  128. package/dist/worker-testing/schema-driven-stub-pi.js.map +0 -1
  129. package/dist/worker-testing/stub-pi-controls.js +0 -10
  130. package/dist/worker-testing/stub-pi-controls.js.map +0 -1
  131. package/dist/worker-testing/stub-pi-tree-handle.js +0 -515
  132. package/dist/worker-testing/stub-pi-tree-handle.js.map +0 -1
  133. package/dist/worker-testing/worker-runtime-harness.js +0 -231
  134. package/dist/worker-testing/worker-runtime-harness.js.map +0 -1
  135. package/dist/worker-testing/worker-start-payload.js +0 -101
  136. package/dist/worker-testing/worker-start-payload.js.map +0 -1
  137. package/dist/workspace-source-aliases.d.ts +0 -6
  138. package/dist/workspace-source-aliases.d.ts.map +0 -1
  139. package/dist/workspace-source-aliases.js +0 -126
  140. package/dist/workspace-source-aliases.js.map +0 -1
  141. package/src/test-app.ts +0 -82
  142. package/src/worker-testing/ipc-harness.ts +0 -19
  143. package/src/workspace-source-aliases.ts +0 -171
@@ -0,0 +1,88 @@
1
+ import type { LaunchRun } from "@leitwerk-dev/domain";
2
+
3
+ /** Accepts a launch-run request shape and waits for its admitted process commit. @internal */
4
+ export async function postImmediateLaunchRequest(
5
+ input: string | URL | Request,
6
+ init?: RequestInit,
7
+ ): Promise<Response> {
8
+ const url = new URL(String(input));
9
+ const match = /^\/api\/launchers\/([^/]+)\/launch-runs$/.exec(url.pathname);
10
+ if (!match?.[1]) throw new Error(`Expected an immediate launch-run URL, received '${url}'`);
11
+ const body = init?.body ? (JSON.parse(String(init.body)) as Record<string, unknown>) : {};
12
+ return postImmediateLaunch(url.origin, decodeURIComponent(match[1]), body);
13
+ }
14
+
15
+ /**
16
+ * Admits an immediate launch through the public asynchronous HTTP contract and waits until the
17
+ * process commit or a pre-commit failure is observable. Intended for integration-test setup.
18
+ */
19
+ /** @public */
20
+ export async function postImmediateLaunch(
21
+ serverBaseUrl: string,
22
+ launcherId: string,
23
+ body: Record<string, unknown>,
24
+ ): Promise<Response> {
25
+ const admitted = await fetch(
26
+ `${serverBaseUrl.replace(/\/$/, "")}/api/launchers/${encodeURIComponent(launcherId)}/launch-runs`,
27
+ {
28
+ method: "POST",
29
+ headers: { "content-type": "application/json", "idempotency-key": crypto.randomUUID() },
30
+ body: JSON.stringify({ ...body, schedule: { mode: "now" } }),
31
+ },
32
+ );
33
+ const admittedBody = (await admitted.json()) as { launchRunId?: string };
34
+ if (admitted.status !== 202 || !admittedBody.launchRunId) {
35
+ return new Response(JSON.stringify(admittedBody), {
36
+ status: admitted.status,
37
+ headers: { "content-type": "application/json" },
38
+ });
39
+ }
40
+
41
+ let launchRun: LaunchRun;
42
+ const deadline = Date.now() + 10_000;
43
+ for (;;) {
44
+ const response = await fetch(
45
+ `${serverBaseUrl.replace(/\/$/, "")}/api/launch-runs/${admittedBody.launchRunId}`,
46
+ );
47
+ const responseBody = (await response.json()) as { launchRun: LaunchRun };
48
+ if (
49
+ responseBody.launchRun.instanceId ||
50
+ ["failed", "cancelled"].includes(responseBody.launchRun.status)
51
+ ) {
52
+ launchRun = responseBody.launchRun;
53
+ break;
54
+ }
55
+ if (Date.now() >= deadline) throw new Error("Timed out waiting for immediate launch admission");
56
+ await new Promise((resolve) => setTimeout(resolve, 10));
57
+ }
58
+
59
+ if (!launchRun.instanceId) {
60
+ const failure = launchRun.steps.find((step) => step.status === "failed");
61
+ return new Response(
62
+ JSON.stringify({
63
+ error: failure?.safeSummary ?? "Launch failed",
64
+ launchRunId: launchRun.id,
65
+ }),
66
+ { status: 400, headers: { "content-type": "application/json" } },
67
+ );
68
+ }
69
+ const detailResponse = await fetch(
70
+ `${serverBaseUrl.replace(/\/$/, "")}/api/processes/${encodeURIComponent(launchRun.instanceId)}`,
71
+ );
72
+ const detail = (await detailResponse.json()) as { process: unknown; projects?: unknown[] };
73
+ const failure = launchRun.steps.find((step) => step.status === "failed");
74
+ return new Response(
75
+ JSON.stringify({
76
+ process: detail.process,
77
+ projects: detail.projects ?? [],
78
+ launchRunId: launchRun.id,
79
+ ...(launchRun.status === "failed"
80
+ ? { error: failure?.safeSummary ?? "Process was created, but startup failed" }
81
+ : {}),
82
+ }),
83
+ {
84
+ status: launchRun.status === "failed" ? 200 : 201,
85
+ headers: { "content-type": "application/json" },
86
+ },
87
+ );
88
+ }
package/src/index.ts CHANGED
@@ -1,45 +1,35 @@
1
- export { createCompactProcessDetailFixtureFactory } from "./compact-process-detail-fixture.js";
2
- export { FakeGitOps, type RepoTemplate } from "./fakes/fake-git-ops.js";
3
- export { FakeLlmProvider, type LlmResponse } from "./fakes/fake-llm.js";
1
+ import { createInMemoryExternalWriteLog as createInMemoryExternalWriteLogImpl } from "./server-extension-test-harness.js";
2
+
3
+ export { FakeLlmProvider } from "./fakes/fake-llm.js";
4
+ export { postImmediateLaunch, postImmediateLaunchRequest } from "./http-launch.js";
4
5
  export {
5
- createInProcessWorkerSpawn,
6
- type InProcessWorkerSpawnOptions,
7
- } from "./in-process-worker.js";
6
+ type FixtureModelProviderSet,
7
+ fixtureModelProviders,
8
+ } from "./model-provider-fixtures.js";
8
9
  export {
9
- createIntegrationHarness,
10
- type IntegrationHarness,
11
- type IntegrationHarnessOptions,
12
- } from "./integration-harness.js";
13
- export { waitForValue } from "./polling.js";
14
- export {
15
- createInMemoryExternalWriteLog,
10
+ createPollingTestExtension,
16
11
  createTestServerSetupCapability,
17
- type InMemoryExternalWriteLog,
18
- type ServerExtensionTestHarness,
19
- setupServerExtensionTest,
12
+ createToolCollector,
20
13
  } from "./server-extension-test-harness.js";
21
- export { createTestApp, type TestApp, type TestAppOptions } from "./test-app.js";
22
- export {
23
- baseEnvelope,
24
- flushAsyncWork,
25
- testConfigSnapshot,
26
- } from "./worker-testing/ipc-harness.js";
27
- export {
28
- createSchemaDrivenStubPiFactory,
29
- createSchemaDrivenToolCallScriptResolver,
30
- synthesizeStubArgValue,
31
- synthesizeStubToolArgs,
32
- } from "./worker-testing/schema-driven-stub-pi.js";
33
- export {
34
- createStubToolScriptController,
35
- type StubToolScriptController,
36
- } from "./worker-testing/stub-pi-controls.js";
37
- export {
38
- StubPiTreeHandle,
39
- StubPiTreeHandleFactory,
40
- type StubPiTreeHandleFactoryOptions,
41
- type StubToolCallScriptCall,
42
- type StubToolCallScriptItem,
43
- type StubToolCallScriptResolver,
44
- type StubToolCallScriptResolverContext,
45
- } from "./worker-testing/stub-pi-tree-handle.js";
14
+ /** @internal */
15
+ export function createInMemoryExternalWriteLog(): {
16
+ /** @internal */
17
+ records: Array<{
18
+ /** @internal */
19
+ dedupKey: string;
20
+ }>;
21
+ /** @internal */
22
+ hasDedupKey(key: string): boolean;
23
+ /** @internal */
24
+ record(input: {
25
+ /** @internal */
26
+ dedupKey: string;
27
+ }): {
28
+ /** @internal */
29
+ dedupKey: string;
30
+ };
31
+ /** @internal */
32
+ getDedupKeys(): ReadonlySet<string>;
33
+ } {
34
+ return createInMemoryExternalWriteLogImpl();
35
+ }
@@ -1,3 +1,6 @@
1
+ import { mkdtempSync, rmSync } from "node:fs";
2
+ import { tmpdir } from "node:os";
3
+ import path from "node:path";
1
4
  import type { ExtensionCatalog } from "@leitwerk-dev/extension-runtime";
2
5
  import type { ProvidedCapability } from "@leitwerk-dev/process-sdk";
3
6
  import {
@@ -7,30 +10,104 @@ import {
7
10
  getDefaultConfig,
8
11
  type LeitwerkConfig,
9
12
  } from "@leitwerk-dev/server";
10
- import { createInProcessWorkerSpawn } from "./in-process-worker.js";
13
+ import {
14
+ createInProcessWorkerSpawn,
15
+ type InProcessWorkerSpawnOptions,
16
+ } from "./in-process-worker.js";
11
17
 
18
+ /** @public */
12
19
  export interface IntegrationHarness<
13
20
  TResources extends Record<string, unknown> = Record<string, never>,
14
21
  > {
22
+ /** @public */
15
23
  ctx: AppContext;
24
+ /** @public */
25
+ close(): Promise<void>;
26
+ /** @internal */
16
27
  config: LeitwerkConfig;
28
+ /** @public */
17
29
  address: string;
30
+ /** @internal */
18
31
  resources: TResources;
19
32
  }
20
33
 
34
+ /** @public */
21
35
  export interface IntegrationHarnessOptions<
22
36
  TResources extends Record<string, unknown> = Record<string, never>,
23
37
  > {
38
+ /** @internal */
24
39
  config?: LeitwerkConfig;
40
+ /** @public */
25
41
  configOverride?: (config: LeitwerkConfig) => void;
42
+ /** @public */
26
43
  appOverrides?: Partial<AppOptions>;
44
+ /** @internal */
27
45
  listen?: boolean;
28
- inProcessWorkers?: boolean;
46
+ /** Start background services when binding a listener. Defaults to true. @public */
47
+ backgroundServices?: boolean;
48
+ /** @internal */
49
+ inProcessWorkers?: boolean | Omit<InProcessWorkerSpawnOptions, "extensionCatalog">;
50
+ /** @public */
29
51
  extensionCatalog: ExtensionCatalog | Promise<ExtensionCatalog>;
52
+ /** @internal */
30
53
  preProvidedCapabilities?: readonly ProvidedCapability[];
54
+ /** @internal */
31
55
  resources?: TResources;
32
56
  }
33
57
 
58
+ /** Owns disposable file-backed storage; close retains it for the next open, dispose removes it. @internal */
59
+ export function createPersistentIntegrationFixture(
60
+ prefix: string,
61
+ configure?: (config: LeitwerkConfig) => void,
62
+ ) {
63
+ const root = mkdtempSync(path.join(tmpdir(), prefix));
64
+ let harness: IntegrationHarness | undefined;
65
+ /** @internal */
66
+ function createConfig() {
67
+ const config = getDefaultConfig();
68
+ config.storage.sqlite_path = path.join(root, "state.sqlite");
69
+ config.storage.process_workspaces_dir = path.join(root, "workspaces");
70
+ config.storage.tree_files_dir = path.join(root, "trees");
71
+ config.pi.agent_dir = path.join(root, "pi");
72
+ configure?.(config);
73
+ return config;
74
+ }
75
+ /** @internal */
76
+ async function close() {
77
+ await harness?.close();
78
+ harness = undefined;
79
+ }
80
+ return {
81
+ /** @internal */
82
+ root,
83
+ /** @internal */
84
+ createConfig,
85
+ /** @internal */
86
+ context() {
87
+ if (!harness) throw new Error("Fixture is not open");
88
+ return harness.ctx;
89
+ },
90
+ /** @internal */
91
+ async open(options: IntegrationHarnessOptions) {
92
+ harness = await createIntegrationHarness({
93
+ ...options,
94
+ config: options.config ?? createConfig(),
95
+ });
96
+ return harness;
97
+ },
98
+ /** @internal */
99
+ close,
100
+ /** @internal */
101
+ async dispose() {
102
+ try {
103
+ await close();
104
+ } finally {
105
+ rmSync(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
106
+ }
107
+ },
108
+ };
109
+ }
110
+ /** @public */
34
111
  export async function createIntegrationHarness<
35
112
  TResources extends Record<string, unknown> = Record<string, never>,
36
113
  >(opts: IntegrationHarnessOptions<TResources>): Promise<IntegrationHarness<TResources>> {
@@ -52,24 +129,38 @@ export async function createIntegrationHarness<
52
129
 
53
130
  if (opts.inProcessWorkers !== false && !appOpts.localWorkerSpawnImpl) {
54
131
  appOpts.localWorkerSpawnImpl = createInProcessWorkerSpawn({
132
+ ...(typeof opts.inProcessWorkers === "object" ? opts.inProcessWorkers : {}),
55
133
  extensionCatalog,
56
134
  });
57
135
  }
58
136
  const ctx = await createAppContext(appOpts);
59
137
 
60
138
  let address = "";
61
- if (opts.listen !== false || config.workers.runner === "local") {
62
- await ctx.app.listen({ host: "127.0.0.1", port: 0 });
63
- const info = ctx.app.server.address();
64
- const port = typeof info === "object" && info ? info.port : 0;
65
- address = `http://127.0.0.1:${port}`;
66
- ctx.config.server.base_url = address;
139
+ try {
140
+ if (opts.listen !== false) {
141
+ if (opts.backgroundServices !== false) {
142
+ ({ address } = await ctx.listen({
143
+ host: "127.0.0.1",
144
+ port: 0,
145
+ useBoundAddressAsBaseUrl: true,
146
+ }));
147
+ } else {
148
+ address = await ctx.app.listen({ host: "127.0.0.1", port: 0 });
149
+ ctx.config.server.base_url = address;
150
+ }
151
+ }
152
+ } catch (error) {
153
+ await ctx.close().catch(() => {});
154
+ throw error;
67
155
  }
68
156
 
69
157
  return {
70
158
  ctx,
159
+ close: () => ctx.close(),
71
160
  config,
72
- address,
161
+ get address() {
162
+ return address || (ctx.app.server.listening ? ctx.config.server.base_url : "");
163
+ },
73
164
  resources: opts.resources ?? ({} as TResources),
74
165
  };
75
166
  }
@@ -1,14 +1,8 @@
1
1
  export {
2
2
  createIntegrationHarness,
3
+ createPersistentIntegrationFixture,
3
4
  type IntegrationHarness,
4
- type IntegrationHarnessOptions,
5
5
  } from "./integration-harness.js";
6
6
  export { waitForValue } from "./polling.js";
7
- export {
8
- createInMemoryExternalWriteLog,
9
- createTestServerSetupCapability,
10
- type InMemoryExternalWriteLog,
11
- type ServerExtensionTestHarness,
12
- setupServerExtensionTest,
13
- } from "./server-extension-test-harness.js";
14
- export { createTestApp, type TestApp, type TestAppOptions } from "./test-app.js";
7
+ export { createProcessDriver } from "./process-driver.js";
8
+ export { createTestServerSetupCapability } from "./server-extension-test-harness.js";