@leitwerk-dev/test-support 0.2.0 → 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.
Files changed (130) hide show
  1. package/dist/{chunk-KPSK7EMY.js → chunk-5BZSJ4OO.js} +22 -157
  2. package/dist/chunk-5BZSJ4OO.js.map +1 -0
  3. package/dist/{chunk-2IICIB6D.js → chunk-E4Y7XND5.js} +40 -4
  4. package/dist/chunk-E4Y7XND5.js.map +1 -0
  5. package/dist/{chunk-JUH3LUYK.js → chunk-EXHTWQAE.js} +5 -1
  6. package/dist/chunk-EXHTWQAE.js.map +1 -0
  7. package/dist/chunk-KJVNI2UP.js +17 -0
  8. package/dist/chunk-KJVNI2UP.js.map +1 -0
  9. package/dist/{chunk-7I4OCTF3.js → chunk-OE4NHDVS.js} +15 -4
  10. package/dist/chunk-OE4NHDVS.js.map +1 -0
  11. package/dist/chunk-P2FF4AP7.js +72 -0
  12. package/dist/chunk-P2FF4AP7.js.map +1 -0
  13. package/dist/chunk-RY6Y6V5E.js +54 -0
  14. package/dist/chunk-RY6Y6V5E.js.map +1 -0
  15. package/dist/compact-process-detail-fixture.d.ts +3 -0
  16. package/dist/compact-process-detail-fixture.d.ts.map +1 -1
  17. package/dist/extension-integration-harness.d.ts +357 -0
  18. package/dist/extension-integration-harness.d.ts.map +1 -0
  19. package/dist/fakes/fake-git-ops.d.ts +12 -0
  20. package/dist/fakes/fake-git-ops.d.ts.map +1 -1
  21. package/dist/fakes/fake-llm.d.ts +11 -0
  22. package/dist/fakes/fake-llm.d.ts.map +1 -1
  23. package/dist/fakes/index.d.ts +1 -1
  24. package/dist/fakes/index.d.ts.map +1 -1
  25. package/dist/fakes/index.js +105 -4
  26. package/dist/fakes/index.js.map +1 -1
  27. package/dist/fixtures.d.ts +2 -0
  28. package/dist/fixtures.d.ts.map +1 -1
  29. package/dist/fixtures.js +157 -2
  30. package/dist/fixtures.js.map +1 -1
  31. package/dist/http-launch.d.ts +2 -1
  32. package/dist/http-launch.d.ts.map +1 -1
  33. package/dist/index.d.ts +6 -13
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +13 -119
  36. package/dist/index.js.map +1 -1
  37. package/dist/integration-harness.d.ts +36 -1
  38. package/dist/integration-harness.d.ts.map +1 -1
  39. package/dist/integration.d.ts +3 -3
  40. package/dist/integration.d.ts.map +1 -1
  41. package/dist/integration.js +693 -13
  42. package/dist/integration.js.map +1 -1
  43. package/dist/local-git.d.ts +105 -8
  44. package/dist/local-git.d.ts.map +1 -1
  45. package/dist/local-git.js +155 -24
  46. package/dist/local-git.js.map +1 -1
  47. package/dist/model-provider-fixtures.d.ts +9 -1
  48. package/dist/model-provider-fixtures.d.ts.map +1 -1
  49. package/dist/observations.d.ts +7 -0
  50. package/dist/observations.d.ts.map +1 -0
  51. package/dist/polling.d.ts +1 -0
  52. package/dist/polling.d.ts.map +1 -1
  53. package/dist/process-driver.d.ts +5 -1
  54. package/dist/process-driver.d.ts.map +1 -1
  55. package/dist/process-fixtures.d.ts +56 -0
  56. package/dist/process-fixtures.d.ts.map +1 -0
  57. package/dist/process.d.ts +440 -0
  58. package/dist/process.d.ts.map +1 -0
  59. package/dist/process.js +484 -0
  60. package/dist/process.js.map +1 -0
  61. package/dist/question-fixtures.d.ts +2 -0
  62. package/dist/question-fixtures.d.ts.map +1 -1
  63. package/dist/server-extension-test-harness.d.ts +43 -3
  64. package/dist/server-extension-test-harness.d.ts.map +1 -1
  65. package/dist/stub-worker-entry.js +1 -1
  66. package/dist/supported-question-fixtures.d.ts +96 -0
  67. package/dist/supported-question-fixtures.d.ts.map +1 -0
  68. package/dist/test-capability.d.ts +9 -0
  69. package/dist/test-capability.d.ts.map +1 -0
  70. package/dist/test-diagnostics.d.ts +14 -0
  71. package/dist/test-diagnostics.d.ts.map +1 -0
  72. package/dist/worker-testing/in-process-worker-spawn.d.ts +19 -1
  73. package/dist/worker-testing/in-process-worker-spawn.d.ts.map +1 -1
  74. package/dist/worker-testing/index.d.ts +6 -7
  75. package/dist/worker-testing/index.d.ts.map +1 -1
  76. package/dist/worker-testing/index.js +32 -22
  77. package/dist/worker-testing/index.js.map +1 -1
  78. package/dist/worker-testing/schema-driven-stub-pi.d.ts +5 -0
  79. package/dist/worker-testing/schema-driven-stub-pi.d.ts.map +1 -1
  80. package/dist/worker-testing/stub-pi-controls.d.ts +4 -0
  81. package/dist/worker-testing/stub-pi-controls.d.ts.map +1 -1
  82. package/dist/worker-testing/stub-pi-tree-handle.d.ts +78 -2
  83. package/dist/worker-testing/stub-pi-tree-handle.d.ts.map +1 -1
  84. package/dist/worker-testing/worker-runtime-harness.d.ts +37 -2
  85. package/dist/worker-testing/worker-runtime-harness.d.ts.map +1 -1
  86. package/dist/worker-testing/worker-start-payload.d.ts +17 -1
  87. package/dist/worker-testing/worker-start-payload.d.ts.map +1 -1
  88. package/package.json +14 -8
  89. package/src/compact-process-detail-fixture.ts +9 -1
  90. package/src/extension-integration-harness.ts +1059 -0
  91. package/src/fakes/fake-git-ops.ts +12 -0
  92. package/src/fakes/fake-llm.ts +11 -0
  93. package/src/fakes/index.ts +1 -1
  94. package/src/fixtures.ts +16 -0
  95. package/src/http-launch.ts +2 -1
  96. package/src/index.ts +13 -42
  97. package/src/integration-harness.ts +100 -9
  98. package/src/integration.ts +23 -9
  99. package/src/local-git.ts +196 -45
  100. package/src/model-provider-fixtures.ts +15 -2
  101. package/src/observations.ts +19 -0
  102. package/src/polling.ts +1 -0
  103. package/src/process-driver.ts +7 -1
  104. package/src/process-fixtures.ts +123 -0
  105. package/src/process.ts +768 -0
  106. package/src/question-fixtures.ts +2 -0
  107. package/src/server-extension-test-harness.ts +64 -7
  108. package/src/supported-question-fixtures.ts +168 -0
  109. package/src/test-capability.ts +9 -0
  110. package/src/test-diagnostics.ts +69 -0
  111. package/src/worker-testing/in-process-worker-spawn.ts +44 -4
  112. package/src/worker-testing/index.ts +4 -30
  113. package/src/worker-testing/schema-driven-stub-pi.ts +8 -1
  114. package/src/worker-testing/stub-pi-controls.ts +4 -0
  115. package/src/worker-testing/stub-pi-tree-handle.ts +87 -3
  116. package/src/worker-testing/worker-runtime-harness.ts +57 -6
  117. package/src/worker-testing/worker-start-payload.ts +17 -1
  118. package/dist/chunk-2IICIB6D.js.map +0 -1
  119. package/dist/chunk-3MQO3NCX.js +0 -15
  120. package/dist/chunk-3MQO3NCX.js.map +0 -1
  121. package/dist/chunk-7I4OCTF3.js.map +0 -1
  122. package/dist/chunk-7ZK5QRGP.js +0 -98
  123. package/dist/chunk-7ZK5QRGP.js.map +0 -1
  124. package/dist/chunk-JUH3LUYK.js.map +0 -1
  125. package/dist/chunk-KPSK7EMY.js.map +0 -1
  126. package/dist/chunk-MV4W6NOO.js +0 -105
  127. package/dist/chunk-MV4W6NOO.js.map +0 -1
  128. package/dist/test-app.d.ts +0 -23
  129. package/dist/test-app.d.ts.map +0 -1
  130. package/src/test-app.ts +0 -82
package/src/local-git.ts CHANGED
@@ -10,19 +10,30 @@ import {
10
10
  } from "node:fs";
11
11
  import path from "node:path";
12
12
  import type { RepositoryFeedbackItem, RepositoryPullRequest } from "@leitwerk-dev/process-sdk";
13
+ import { traceTestSubprocess } from "./test-diagnostics.js";
13
14
 
15
+ // Internal operational tests retain subprocess diagnostics.
16
+ export { createTestDiagnostics } from "./test-diagnostics.js";
17
+
18
+ /** @public */
14
19
  export interface LocalRepositorySeed {
20
+ /** @public */
15
21
  owner: string;
22
+ /** @public */
16
23
  name: string;
24
+ /** @internal */
17
25
  defaultBranch?: string;
26
+ /** @public */
18
27
  files?: Record<string, string>;
19
- /** Retain a pre-existing sandbox checkout layout. */
28
+ /** Retain a pre-existing sandbox checkout layout. @internal */
20
29
  directoryName?: string;
30
+ /** @internal */
21
31
  commitMessage?: string;
32
+ /** @internal */
22
33
  signoff?: boolean;
23
34
  }
24
35
 
25
- /** Reject escaping paths and symlinks, including a not-yet-created file's parents. */
36
+ /** Reject escaping paths and symlinks, including a not-yet-created file's parents. @public */
26
37
  export function localPath(root: string, relative: string): string {
27
38
  if (lstatSync(root, { throwIfNoEntry: false })?.isSymbolicLink())
28
39
  throw new Error("Local provider storage must not contain symlinks");
@@ -39,11 +50,13 @@ export function localPath(root: string, relative: string): string {
39
50
  return target;
40
51
  }
41
52
 
42
- export function readLocalJson<T extends { version: number }>(
43
- root: string,
44
- file: string,
45
- initial: T,
46
- ): T {
53
+ /** @public */
54
+ export function readLocalJson<
55
+ T extends {
56
+ /** @internal */
57
+ version: number;
58
+ },
59
+ >(root: string, file: string, initial: T): T {
47
60
  const target = localPath(root, file);
48
61
  if (!existsSync(target)) return structuredClone(initial);
49
62
  const value = JSON.parse(readFileSync(target, "utf8")) as T;
@@ -52,6 +65,7 @@ export function readLocalJson<T extends { version: number }>(
52
65
  return value;
53
66
  }
54
67
 
68
+ /** @public */
55
69
  export function writeLocalJson(root: string, file: string, value: unknown): void {
56
70
  const target = localPath(root, file);
57
71
  const temporary = localPath(root, `${file}.tmp`);
@@ -59,14 +73,30 @@ export function writeLocalJson(root: string, file: string, value: unknown): void
59
73
  renameSync(temporary, target);
60
74
  }
61
75
 
62
- /** Persist local adapter state with a shared clock and monotonically increasing ids. */
76
+ /** Persist local adapter state with a shared clock and monotonically increasing ids. @public */
63
77
  export class LocalProviderStore<
64
- S extends { version: number; sequence: number },
65
- O extends { root: string; now?: () => number; nextId?: () => number },
78
+ S extends {
79
+ /** @internal */
80
+ version: number;
81
+ /** @internal */
82
+ sequence: number;
83
+ },
84
+ O extends {
85
+ /** @internal */
86
+ root: string;
87
+ /** @internal */
88
+ now?: () => number;
89
+ /** @internal */
90
+ nextId?: () => number;
91
+ },
66
92
  > {
93
+ /** @public */
67
94
  readonly git: LocalGit;
95
+ /** @public */
68
96
  state: S;
97
+ /** @public */
69
98
  constructor(
99
+ /** @public */
70
100
  readonly options: O,
71
101
  private readonly file: string,
72
102
  initial: S,
@@ -74,44 +104,80 @@ export class LocalProviderStore<
74
104
  this.git = new LocalGit(options.root);
75
105
  this.state = readLocalJson(options.root, file, initial);
76
106
  }
107
+ /** @public */
77
108
  save() {
78
109
  writeLocalJson(this.options.root, this.file, this.state);
79
110
  }
111
+ /** @internal */
80
112
  id() {
81
113
  this.state.sequence = Math.max(this.state.sequence + 1, this.options.nextId?.() ?? 0);
82
114
  return this.state.sequence;
83
115
  }
116
+ /** @internal */
84
117
  timestamp() {
85
118
  return new Date(this.options.now?.() ?? Date.now()).toISOString();
86
119
  }
87
120
  }
88
121
 
122
+ /** @public */
89
123
  type LocalPullRequest = Pick<
90
124
  RepositoryPullRequest,
91
125
  "number" | "title" | "body" | "state" | "merged" | "merge_commit_sha" | "head" | "base"
92
126
  >;
127
+ /** @public */
93
128
  interface LocalPullRequestRepository<P extends LocalPullRequest> {
94
- repository: { ssh_url: string };
129
+ /** @public */
130
+ repository: {
131
+ /** @internal */
132
+ ssh_url: string;
133
+ };
134
+ /** @public */
95
135
  pulls: P[];
96
136
  }
97
137
 
98
- /** Common PR operations; adapters retain their provider-specific state and clients. */
138
+ /** Common PR operations; adapters retain their provider-specific state and clients. @public */
99
139
  export class LocalForgeStore<
100
- S extends { version: number; sequence: number },
101
- O extends { root: string; baseUrl: string; now?: () => number; nextId?: () => number },
140
+ S extends {
141
+ /** @internal */
142
+ version: number;
143
+ /** @internal */
144
+ sequence: number;
145
+ },
146
+ O extends {
147
+ /** @internal */
148
+ root: string;
149
+ /** @internal */
150
+ baseUrl: string;
151
+ /** @internal */
152
+ now?: () => number;
153
+ /** @internal */
154
+ nextId?: () => number;
155
+ },
102
156
  > extends LocalProviderStore<S, O> {
157
+ /** @public */
103
158
  newRepository(seed: LocalRepositorySeed) {
104
159
  const { bare, branch } = this.git.seed(seed);
105
160
  return {
161
+ /** @public */
106
162
  id: this.id(),
107
- owner: { login: seed.owner },
163
+ /** @public */
164
+ owner: {
165
+ /** @internal */
166
+ login: seed.owner,
167
+ },
168
+ /** @public */
108
169
  name: seed.name,
170
+ /** @public */
109
171
  full_name: `${seed.owner}/${seed.name}`,
172
+ /** @public */
110
173
  ssh_url: bare,
174
+ /** @public */
111
175
  html_url: `${this.options.baseUrl}/__local`,
176
+ /** @public */
112
177
  default_branch: branch,
113
178
  };
114
179
  }
180
+ /** @internal */
115
181
  pullRequestClient<P extends LocalPullRequest>(
116
182
  repo: (owner: string, name: string) => LocalPullRequestRepository<P>,
117
183
  missing = "Unknown local pull request",
@@ -122,14 +188,17 @@ export class LocalForgeStore<
122
188
  return pr;
123
189
  };
124
190
  return {
191
+ /** @internal */
125
192
  getPullRequest: async (owner: string, name: string, number: number) =>
126
193
  this.refresh(repo(owner, name), pull(owner, name, number)),
194
+ /** @internal */
127
195
  listPullRequests: async (owner: string, name: string, state = "open") => {
128
196
  const r = repo(owner, name);
129
197
  return r.pulls
130
198
  .filter((p) => state === "all" || p.state === state)
131
199
  .map((p) => this.refresh(r, p));
132
200
  },
201
+ /** @internal */
133
202
  updatePullRequest: async (
134
203
  owner: string,
135
204
  name: string,
@@ -144,6 +213,7 @@ export class LocalForgeStore<
144
213
  },
145
214
  };
146
215
  }
216
+ /** @public */
147
217
  refresh<P extends LocalPullRequest>(repo: LocalPullRequestRepository<P>, pr: P): P {
148
218
  if (pr.state === "open") {
149
219
  const { headSha, baseSha, ...mergeability } = this.git.mergeability(
@@ -157,6 +227,7 @@ export class LocalForgeStore<
157
227
  }
158
228
  return structuredClone(pr);
159
229
  }
230
+ /** @public */
160
231
  merge<P extends LocalPullRequest>(repo: LocalPullRequestRepository<P>, number: number): P {
161
232
  const pr = repo.pulls.find((p) => p.number === number);
162
233
  if (!pr || pr.state !== "open") throw new Error("Pull request is not open");
@@ -167,8 +238,17 @@ export class LocalForgeStore<
167
238
  this.save();
168
239
  return structuredClone(pr);
169
240
  }
241
+ /** @public */
170
242
  addFeedback<F extends RepositoryFeedbackItem>(
171
- repo: { pulls: Array<{ number: number }>; feedback: Record<string, F[]> },
243
+ repo: {
244
+ /** @public */
245
+ pulls: Array<{
246
+ /** @internal */
247
+ number: number;
248
+ }>;
249
+ /** @public */
250
+ feedback: Record<string, F[]>;
251
+ },
172
252
  number: number,
173
253
  input: Omit<F, "id" | "createdAt">,
174
254
  ): F {
@@ -179,40 +259,88 @@ export class LocalForgeStore<
179
259
  this.save();
180
260
  return value;
181
261
  }
262
+ /** @public */
182
263
  newComment(body: string) {
183
264
  return {
265
+ /** @internal */
184
266
  id: this.id(),
267
+ /** @internal */
185
268
  body,
186
- user: { login: "leitwerk-bot" },
269
+ /** @public */
270
+ user: {
271
+ /** @public */
272
+ login: "leitwerk-bot",
273
+ },
274
+ /** @internal */
187
275
  created_at: this.timestamp(),
188
276
  };
189
277
  }
278
+ /** @internal */
190
279
  newPullRequest(
191
- repo: { repository: { ssh_url: string } },
192
- input: { title: string; body: string; head: string; base: string },
280
+ repo: {
281
+ /** @internal */
282
+ repository: {
283
+ /** @internal */
284
+ ssh_url: string;
285
+ };
286
+ },
287
+ input: {
288
+ /** @internal */
289
+ title: string;
290
+ /** @internal */
291
+ body: string;
292
+ /** @internal */
293
+ head: string;
294
+ /** @internal */
295
+ base: string;
296
+ },
193
297
  ) {
194
298
  const number = this.id();
195
299
  return {
300
+ /** @internal */
196
301
  number,
302
+ /** @internal */
197
303
  title: input.title,
304
+ /** @internal */
198
305
  body: input.body,
306
+ /** @internal */
199
307
  state: "open",
308
+ /** @internal */
200
309
  merged: false,
310
+ /** @internal */
201
311
  merge_commit_sha: null,
312
+ /** @internal */
202
313
  html_url: `${this.options.baseUrl}/__local#pr-${number}`,
203
- head: { ref: input.head, sha: this.git.head(repo.repository.ssh_url, input.head) },
204
- base: { ref: input.base, sha: this.git.head(repo.repository.ssh_url, input.base) },
314
+ /** @internal */
315
+ head: {
316
+ /** @internal */
317
+ ref: input.head,
318
+ /** @internal */
319
+ sha: this.git.head(repo.repository.ssh_url, input.head),
320
+ },
321
+ /** @internal */
322
+ base: {
323
+ /** @internal */
324
+ ref: input.base,
325
+ /** @internal */
326
+ sha: this.git.head(repo.repository.ssh_url, input.base),
327
+ },
205
328
  };
206
329
  }
207
330
  }
208
331
 
209
- /** Real Git with file-only transport and no ambient credentials or hooks. */
332
+ /** Real Git with file-only transport and no ambient credentials or hooks. @public */
210
333
  export class LocalGit {
211
- constructor(readonly root: string) {
334
+ /** @public */
335
+ constructor(
336
+ /** @internal */
337
+ readonly root: string,
338
+ ) {
212
339
  if (lstatSync(root, { throwIfNoEntry: false })?.isSymbolicLink())
213
340
  throw new Error("Local Git root must not be a symlink");
214
341
  mkdirSync(root, { recursive: true, mode: 0o700 });
215
342
  }
343
+ /** @public */
216
344
  run(directory: string, args: string[]): string {
217
345
  const base = realpathSync(this.root);
218
346
  const directoryPath = path.resolve(directory);
@@ -221,32 +349,36 @@ export class LocalGit {
221
349
  directoryPath,
222
350
  );
223
351
  const cwd = localPath(this.root, relative);
224
- return execFileSync(
225
- "git",
226
- ["-c", "protocol.file.allow=always", "-c", "core.hooksPath=/dev/null", ...args],
227
- {
228
- cwd,
229
- encoding: "utf8",
230
- stdio: ["ignore", "pipe", "pipe"],
231
- env: {
232
- PATH: process.env.PATH,
233
- HOME: this.root,
234
- GIT_CONFIG_NOSYSTEM: "1",
235
- GIT_CONFIG_GLOBAL: "/dev/null",
236
- GIT_TERMINAL_PROMPT: "0",
237
- GIT_ALLOW_PROTOCOL: "file",
238
- GIT_AUTHOR_NAME: "Sandbox Developer",
239
- GIT_AUTHOR_EMAIL: "developer@sandbox.invalid",
240
- GIT_COMMITTER_NAME: "Sandbox Developer",
241
- GIT_COMMITTER_EMAIL: "developer@sandbox.invalid",
352
+ return traceTestSubprocess(`git ${args[0] ?? ""}`, () =>
353
+ execFileSync(
354
+ "git",
355
+ ["-c", "protocol.file.allow=always", "-c", "core.hooksPath=/dev/null", ...args],
356
+ {
357
+ cwd,
358
+ encoding: "utf8",
359
+ stdio: ["ignore", "pipe", "pipe"],
360
+ env: {
361
+ PATH: process.env.PATH,
362
+ HOME: this.root,
363
+ GIT_CONFIG_NOSYSTEM: "1",
364
+ GIT_CONFIG_GLOBAL: "/dev/null",
365
+ GIT_TERMINAL_PROMPT: "0",
366
+ GIT_ALLOW_PROTOCOL: "file",
367
+ GIT_AUTHOR_NAME: "Sandbox Developer",
368
+ GIT_AUTHOR_EMAIL: "developer@sandbox.invalid",
369
+ GIT_COMMITTER_NAME: "Sandbox Developer",
370
+ GIT_COMMITTER_EMAIL: "developer@sandbox.invalid",
371
+ },
242
372
  },
243
- },
244
- ).trim();
373
+ ).trim(),
374
+ );
245
375
  }
376
+ /** @public */
246
377
  head(directory: string, ref: string): string {
247
378
  if (!/^[a-zA-Z0-9_./-]+$/.test(ref) || ref.startsWith("-")) throw new Error("Invalid Git ref");
248
379
  return this.run(directory, ["rev-parse", "--verify", `${ref}^{commit}`]);
249
380
  }
381
+ /** @internal */
250
382
  isAncestor(directory: string, ancestor: string, descendant: string): boolean {
251
383
  return this.isAncestorCommit(
252
384
  directory,
@@ -264,11 +396,21 @@ export class LocalGit {
264
396
  throw error;
265
397
  }
266
398
  }
399
+ /** @internal */
267
400
  mergeability(
268
401
  directory: string,
269
402
  head: string,
270
403
  base: string,
271
- ): { headSha: string; baseSha: string; mergeable: boolean; mergeable_state: string } {
404
+ ): {
405
+ /** @internal */
406
+ headSha: string;
407
+ /** @internal */
408
+ baseSha: string;
409
+ /** @internal */
410
+ mergeable: boolean;
411
+ /** @internal */
412
+ mergeable_state: string;
413
+ } {
272
414
  const headSha = this.head(directory, head),
273
415
  baseSha = this.head(directory, base);
274
416
  const revisions = { headSha, baseSha };
@@ -283,6 +425,7 @@ export class LocalGit {
283
425
  }
284
426
  return { ...revisions, mergeable: true, mergeable_state: "behind" };
285
427
  }
428
+ /** @internal */
286
429
  merge(directory: string, head: string, base: string): string {
287
430
  const h = this.head(directory, head),
288
431
  b = this.head(directory, base);
@@ -303,7 +446,15 @@ export class LocalGit {
303
446
  this.run(directory, ["update-ref", `refs/heads/${base}`, commit, b]);
304
447
  return commit;
305
448
  }
306
- seed(seed: LocalRepositorySeed): { bare: string; worktree: string; branch: string } {
449
+ /** @internal */
450
+ seed(seed: LocalRepositorySeed): {
451
+ /** @internal */
452
+ bare: string;
453
+ /** @internal */
454
+ worktree: string;
455
+ /** @internal */
456
+ branch: string;
457
+ } {
307
458
  for (const value of [seed.owner, seed.name, seed.directoryName ?? seed.name])
308
459
  if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(value))
309
460
  throw new Error("Invalid local repository name");
@@ -4,9 +4,22 @@ import {
4
4
  defineModelProviders,
5
5
  } from "@leitwerk-dev/process-sdk";
6
6
 
7
+ /** @public */
8
+ export type FixtureModelProviderSet = ReturnType<typeof defineModelProviders>;
9
+
10
+ /** @public */
7
11
  export function fixtureModelProviders(
8
- ...models: { id: string; modelId: string; piProvider?: string; server?: boolean }[]
9
- ) {
12
+ ...models: {
13
+ /** @public */
14
+ id: string;
15
+ /** @public */
16
+ modelId: string;
17
+ /** @internal */
18
+ piProvider?: string;
19
+ /** @public */
20
+ server?: boolean;
21
+ }[]
22
+ ): FixtureModelProviderSet {
10
23
  return defineModelProviders((rawConfig) =>
11
24
  models.map(({ id, modelId, piProvider = id, server = false }) => ({
12
25
  definition: defineModelProvider({
@@ -0,0 +1,19 @@
1
+ /** Recursively readonly observations detached from the running harness. @public */
2
+ export type TestObservation<T> = T extends readonly (infer V)[]
3
+ ? readonly TestObservation<V>[]
4
+ : T extends object
5
+ ? { readonly [K in keyof T]: TestObservation<T[K]> }
6
+ : T;
7
+
8
+ /** @internal */
9
+ export function observe<T>(value: T): TestObservation<T> {
10
+ function freeze(value: unknown): void {
11
+ if (value && typeof value === "object") {
12
+ for (const child of Object.values(value)) freeze(child);
13
+ Object.freeze(value);
14
+ }
15
+ }
16
+ const detached = structuredClone(value);
17
+ freeze(detached);
18
+ return detached as TestObservation<T>;
19
+ }
package/src/polling.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /** @public */
1
2
  export async function waitForValue<T>(
2
3
  read: () => T | Promise<T>,
3
4
  predicate: (value: T) => boolean,
@@ -2,14 +2,16 @@ import type { ProcessInstance } from "@leitwerk-dev/domain";
2
2
  import type { AppContext } from "@leitwerk-dev/server";
3
3
  import { waitForValue } from "./polling.js";
4
4
 
5
- /** Drive a running or restarted app without bypassing process HTTP actions. */
5
+ /** Drive a running or restarted app without bypassing process HTTP actions. @public */
6
6
  export function createProcessDriver(context: () => AppContext) {
7
+ /** @public */
7
8
  async function post(url: string, payload: Record<string, unknown> = {}) {
8
9
  const response = await context().app.inject({ method: "POST", url, payload });
9
10
  if (response.statusCode !== 200)
10
11
  throw new Error(`POST ${url} failed with ${response.statusCode}: ${response.body}`);
11
12
  return response;
12
13
  }
14
+ /** @public */
13
15
  async function waitForProcess(
14
16
  id: string,
15
17
  predicate: (process: ProcessInstance) => boolean,
@@ -39,8 +41,11 @@ export function createProcessDriver(context: () => AppContext) {
39
41
  }
40
42
  }
41
43
  return {
44
+ /** @public */
42
45
  post,
46
+ /** @public */
43
47
  waitForProcess,
48
+ /** @public */
44
49
  wait: (id: string, turn: string | null, lifecycle = "waiting", timeout = 12000) =>
45
50
  waitForProcess(
46
51
  id,
@@ -49,6 +54,7 @@ export function createProcessDriver(context: () => AppContext) {
49
54
  timeout,
50
55
  lifecycle === "error",
51
56
  ),
57
+ /** @public */
52
58
  action: (id: string, action: string, input: Record<string, unknown> = {}) =>
53
59
  post(`/api/processes/${encodeURIComponent(id)}/actions/${encodeURIComponent(action)}`, {
54
60
  input,
@@ -0,0 +1,123 @@
1
+ import type { ProcessInstance, ProcessProject } from "@leitwerk-dev/domain";
2
+ import {
3
+ createTestProcessInstance,
4
+ createTestProcessProject,
5
+ } from "@leitwerk-dev/extension-runtime/testing";
6
+ import type { ExtensionProcessDefinition } from "@leitwerk-dev/process-sdk";
7
+
8
+ /** Business position for an unaccepted fixture. @public */
9
+ export interface ProcessFixturePosition {
10
+ /** @public */
11
+ selectedTurnId: string | null;
12
+ /** @public */
13
+ lifecycleStatus: ProcessInstance["lifecycleStatus"];
14
+ }
15
+
16
+ /** Inputs deliberately exclude execution and acceptance records. @public */
17
+ export interface ProcessFixtureOptions<TParams = unknown, TState = unknown> {
18
+ /** @public */
19
+ id?: string;
20
+ /** @public */
21
+ processId?: string;
22
+ /** @public */
23
+ params?: TParams;
24
+ /** @public */
25
+ state?: TState;
26
+ /** @public */
27
+ position?: ProcessFixturePosition;
28
+ /** @public */
29
+ title?: string | null;
30
+ /** @public */
31
+ externalId?: string | null;
32
+ /** @public */
33
+ externalUrl?: string | null;
34
+ /** @public */
35
+ metadata?: Record<string, unknown> | null;
36
+ /** @public */
37
+ planRevision?: number;
38
+ }
39
+
40
+ /** Construct deterministic business data, validating codecs and turns when defined. @public */
41
+ export function createProcessFixture<TParams = unknown, TState = unknown>(
42
+ options: ProcessFixtureOptions<TParams, TState> = {},
43
+ definition?: ExtensionProcessDefinition<TParams, TState>,
44
+ ): ProcessInstance {
45
+ if (
46
+ options.planRevision !== undefined &&
47
+ (!Number.isSafeInteger(options.planRevision) || options.planRevision < 0)
48
+ )
49
+ throw new Error("planRevision must be a non-negative safe integer");
50
+ if (definition && options.processId && options.processId !== definition.id) {
51
+ throw new Error("Fixture process id does not match definition");
52
+ }
53
+ const params = definition ? definition.paramsCodec.parse(options.params) : options.params;
54
+ const state = definition
55
+ ? definition.stateCodec.parse(
56
+ options.state === undefined ? definition.initialState(params as TParams) : options.state,
57
+ )
58
+ : options.state;
59
+ const position = options.position ?? {
60
+ selectedTurnId: definition?.entryTurnId ?? null,
61
+ lifecycleStatus: definition ? "active" : "discovered",
62
+ };
63
+ if (
64
+ definition &&
65
+ position.selectedTurnId !== null &&
66
+ !definition.turns.has(position.selectedTurnId)
67
+ ) {
68
+ throw new Error(`Undeclared fixture turn '${position.selectedTurnId}'`);
69
+ }
70
+ return createTestProcessInstance({
71
+ id: options.id ?? "agt_test",
72
+ processId: definition?.id ?? options.processId ?? "test_process",
73
+ title: options.title ?? null,
74
+ externalId: options.externalId ?? null,
75
+ externalUrl: options.externalUrl ?? null,
76
+ metadata: structuredClone(options.metadata ?? null),
77
+ planRevision: options.planRevision ?? 0,
78
+ selectedTurnId: position.selectedTurnId,
79
+ lifecycleStatus: position.lifecycleStatus,
80
+ paramsJson:
81
+ params === undefined
82
+ ? null
83
+ : JSON.stringify(definition ? definition.paramsCodec.serialize(params as TParams) : params),
84
+ stateJson:
85
+ state === undefined
86
+ ? null
87
+ : JSON.stringify(definition ? definition.stateCodec.serialize(state as TState) : state),
88
+ });
89
+ }
90
+
91
+ /** Repository business data; ownership comes from the supplied process. @public */
92
+ export interface ProjectFixtureOptions {
93
+ /** Provider-owned repository bindings. @public */
94
+ metadata?: Record<string, unknown> | null;
95
+ /** @public */
96
+ id?: string;
97
+ /** @public */
98
+ process?: Pick<ProcessInstance, "id">;
99
+ /** @public */
100
+ key?: string;
101
+ /** @public */
102
+ repoLocator?: string;
103
+ /** @public */
104
+ repoLocatorKind?: ProcessProject["repoLocatorKind"];
105
+ /** @public */
106
+ baseBranch?: string;
107
+ /** @public */
108
+ workBranch?: string | null;
109
+ }
110
+
111
+ /** Construct a deterministic repository fixture correlated with its process. @public */
112
+ export function createProjectFixture(options: ProjectFixtureOptions = {}): ProcessProject {
113
+ return createTestProcessProject({
114
+ id: options.id ?? `prj_${options.key ?? "test"}`,
115
+ metadata: structuredClone(options.metadata ?? null),
116
+ instanceId: options.process?.id ?? "agt_test",
117
+ key: options.key ?? "component-a",
118
+ repoLocator: options.repoLocator ?? "https://example.invalid/component-a.git",
119
+ repoLocatorKind: options.repoLocatorKind ?? "remote_url",
120
+ baseBranch: options.baseBranch ?? "main",
121
+ workBranch: options.workBranch ?? null,
122
+ });
123
+ }