@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.
- package/dist/{chunk-KPSK7EMY.js → chunk-5BZSJ4OO.js} +22 -157
- package/dist/chunk-5BZSJ4OO.js.map +1 -0
- package/dist/{chunk-2IICIB6D.js → chunk-E4Y7XND5.js} +40 -4
- package/dist/chunk-E4Y7XND5.js.map +1 -0
- package/dist/{chunk-JUH3LUYK.js → chunk-EXHTWQAE.js} +5 -1
- package/dist/chunk-EXHTWQAE.js.map +1 -0
- package/dist/chunk-KJVNI2UP.js +17 -0
- package/dist/chunk-KJVNI2UP.js.map +1 -0
- package/dist/{chunk-7I4OCTF3.js → chunk-OE4NHDVS.js} +15 -4
- package/dist/chunk-OE4NHDVS.js.map +1 -0
- package/dist/chunk-P2FF4AP7.js +72 -0
- package/dist/chunk-P2FF4AP7.js.map +1 -0
- package/dist/chunk-RY6Y6V5E.js +54 -0
- package/dist/chunk-RY6Y6V5E.js.map +1 -0
- package/dist/compact-process-detail-fixture.d.ts +3 -0
- package/dist/compact-process-detail-fixture.d.ts.map +1 -1
- package/dist/extension-integration-harness.d.ts +357 -0
- package/dist/extension-integration-harness.d.ts.map +1 -0
- package/dist/fakes/fake-git-ops.d.ts +12 -0
- package/dist/fakes/fake-git-ops.d.ts.map +1 -1
- package/dist/fakes/fake-llm.d.ts +11 -0
- package/dist/fakes/fake-llm.d.ts.map +1 -1
- package/dist/fakes/index.d.ts +1 -1
- package/dist/fakes/index.d.ts.map +1 -1
- package/dist/fakes/index.js +105 -4
- package/dist/fakes/index.js.map +1 -1
- package/dist/fixtures.d.ts +2 -0
- package/dist/fixtures.d.ts.map +1 -1
- package/dist/fixtures.js +157 -2
- package/dist/fixtures.js.map +1 -1
- package/dist/http-launch.d.ts +2 -1
- package/dist/http-launch.d.ts.map +1 -1
- package/dist/index.d.ts +6 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -119
- package/dist/index.js.map +1 -1
- package/dist/integration-harness.d.ts +36 -1
- package/dist/integration-harness.d.ts.map +1 -1
- package/dist/integration.d.ts +3 -3
- package/dist/integration.d.ts.map +1 -1
- package/dist/integration.js +693 -13
- package/dist/integration.js.map +1 -1
- package/dist/local-git.d.ts +105 -8
- package/dist/local-git.d.ts.map +1 -1
- package/dist/local-git.js +155 -24
- package/dist/local-git.js.map +1 -1
- package/dist/model-provider-fixtures.d.ts +9 -1
- package/dist/model-provider-fixtures.d.ts.map +1 -1
- package/dist/observations.d.ts +7 -0
- package/dist/observations.d.ts.map +1 -0
- package/dist/polling.d.ts +1 -0
- package/dist/polling.d.ts.map +1 -1
- package/dist/process-driver.d.ts +5 -1
- package/dist/process-driver.d.ts.map +1 -1
- package/dist/process-fixtures.d.ts +56 -0
- package/dist/process-fixtures.d.ts.map +1 -0
- package/dist/process.d.ts +440 -0
- package/dist/process.d.ts.map +1 -0
- package/dist/process.js +484 -0
- package/dist/process.js.map +1 -0
- package/dist/question-fixtures.d.ts +2 -0
- package/dist/question-fixtures.d.ts.map +1 -1
- package/dist/server-extension-test-harness.d.ts +43 -3
- package/dist/server-extension-test-harness.d.ts.map +1 -1
- package/dist/stub-worker-entry.js +1 -1
- package/dist/supported-question-fixtures.d.ts +96 -0
- package/dist/supported-question-fixtures.d.ts.map +1 -0
- package/dist/test-capability.d.ts +9 -0
- package/dist/test-capability.d.ts.map +1 -0
- package/dist/test-diagnostics.d.ts +14 -0
- package/dist/test-diagnostics.d.ts.map +1 -0
- package/dist/worker-testing/in-process-worker-spawn.d.ts +19 -1
- package/dist/worker-testing/in-process-worker-spawn.d.ts.map +1 -1
- package/dist/worker-testing/index.d.ts +6 -7
- package/dist/worker-testing/index.d.ts.map +1 -1
- package/dist/worker-testing/index.js +32 -22
- package/dist/worker-testing/index.js.map +1 -1
- package/dist/worker-testing/schema-driven-stub-pi.d.ts +5 -0
- package/dist/worker-testing/schema-driven-stub-pi.d.ts.map +1 -1
- package/dist/worker-testing/stub-pi-controls.d.ts +4 -0
- package/dist/worker-testing/stub-pi-controls.d.ts.map +1 -1
- package/dist/worker-testing/stub-pi-tree-handle.d.ts +78 -2
- package/dist/worker-testing/stub-pi-tree-handle.d.ts.map +1 -1
- package/dist/worker-testing/worker-runtime-harness.d.ts +37 -2
- package/dist/worker-testing/worker-runtime-harness.d.ts.map +1 -1
- package/dist/worker-testing/worker-start-payload.d.ts +17 -1
- package/dist/worker-testing/worker-start-payload.d.ts.map +1 -1
- package/package.json +14 -8
- package/src/compact-process-detail-fixture.ts +9 -1
- package/src/extension-integration-harness.ts +1059 -0
- package/src/fakes/fake-git-ops.ts +12 -0
- package/src/fakes/fake-llm.ts +11 -0
- package/src/fakes/index.ts +1 -1
- package/src/fixtures.ts +16 -0
- package/src/http-launch.ts +2 -1
- package/src/index.ts +13 -42
- package/src/integration-harness.ts +100 -9
- package/src/integration.ts +23 -9
- package/src/local-git.ts +196 -45
- package/src/model-provider-fixtures.ts +15 -2
- package/src/observations.ts +19 -0
- package/src/polling.ts +1 -0
- package/src/process-driver.ts +7 -1
- package/src/process-fixtures.ts +123 -0
- package/src/process.ts +768 -0
- package/src/question-fixtures.ts +2 -0
- package/src/server-extension-test-harness.ts +64 -7
- package/src/supported-question-fixtures.ts +168 -0
- package/src/test-capability.ts +9 -0
- package/src/test-diagnostics.ts +69 -0
- package/src/worker-testing/in-process-worker-spawn.ts +44 -4
- package/src/worker-testing/index.ts +4 -30
- package/src/worker-testing/schema-driven-stub-pi.ts +8 -1
- package/src/worker-testing/stub-pi-controls.ts +4 -0
- package/src/worker-testing/stub-pi-tree-handle.ts +87 -3
- package/src/worker-testing/worker-runtime-harness.ts +57 -6
- package/src/worker-testing/worker-start-payload.ts +17 -1
- package/dist/chunk-2IICIB6D.js.map +0 -1
- package/dist/chunk-3MQO3NCX.js +0 -15
- package/dist/chunk-3MQO3NCX.js.map +0 -1
- package/dist/chunk-7I4OCTF3.js.map +0 -1
- package/dist/chunk-7ZK5QRGP.js +0 -98
- package/dist/chunk-7ZK5QRGP.js.map +0 -1
- package/dist/chunk-JUH3LUYK.js.map +0 -1
- package/dist/chunk-KPSK7EMY.js.map +0 -1
- package/dist/chunk-MV4W6NOO.js +0 -105
- package/dist/chunk-MV4W6NOO.js.map +0 -1
- package/dist/test-app.d.ts +0 -23
- package/dist/test-app.d.ts.map +0 -1
- 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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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 {
|
|
65
|
-
|
|
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
|
-
|
|
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 {
|
|
101
|
-
|
|
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
|
-
|
|
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: {
|
|
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
|
-
|
|
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: {
|
|
192
|
-
|
|
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
|
-
|
|
204
|
-
|
|
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
|
-
|
|
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
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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
|
-
)
|
|
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
|
-
): {
|
|
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
|
-
|
|
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: {
|
|
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
package/src/process-driver.ts
CHANGED
|
@@ -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
|
+
}
|