@leitwerk-dev/test-support 0.2.0 → 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.
- package/dist/{chunk-7I4OCTF3.js → chunk-2PCDTYVH.js} +7 -2
- package/dist/chunk-2PCDTYVH.js.map +1 -0
- package/dist/{chunk-KPSK7EMY.js → chunk-5BZSJ4OO.js} +22 -157
- package/dist/chunk-5BZSJ4OO.js.map +1 -0
- package/dist/{chunk-2IICIB6D.js → chunk-ECAWLVYB.js} +38 -4
- package/dist/chunk-ECAWLVYB.js.map +1 -0
- package/dist/{chunk-JUH3LUYK.js → chunk-EXHTWQAE.js} +5 -1
- package/dist/chunk-EXHTWQAE.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/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.js +104 -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 +23 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -53
- 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 +2 -3
- package/dist/integration.d.ts.map +1 -1
- package/dist/integration.js +131 -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/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/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/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 +17 -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 +76 -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 +9 -8
- package/src/compact-process-detail-fixture.ts +9 -1
- 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/http-launch.ts +2 -1
- package/src/index.ts +28 -42
- package/src/integration-harness.ts +100 -9
- package/src/integration.ts +2 -9
- package/src/local-git.ts +195 -45
- package/src/model-provider-fixtures.ts +15 -2
- package/src/polling.ts +1 -0
- package/src/process-driver.ts +7 -1
- package/src/question-fixtures.ts +2 -0
- package/src/server-extension-test-harness.ts +64 -7
- package/src/test-diagnostics.ts +69 -0
- package/src/worker-testing/in-process-worker-spawn.ts +29 -2
- 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 +82 -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,29 @@ 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
|
+
export { createTestDiagnostics } from "./test-diagnostics.js";
|
|
16
|
+
|
|
17
|
+
/** @public */
|
|
14
18
|
export interface LocalRepositorySeed {
|
|
19
|
+
/** @public */
|
|
15
20
|
owner: string;
|
|
21
|
+
/** @public */
|
|
16
22
|
name: string;
|
|
23
|
+
/** @internal */
|
|
17
24
|
defaultBranch?: string;
|
|
25
|
+
/** @public */
|
|
18
26
|
files?: Record<string, string>;
|
|
19
|
-
/** Retain a pre-existing sandbox checkout layout. */
|
|
27
|
+
/** Retain a pre-existing sandbox checkout layout. @internal */
|
|
20
28
|
directoryName?: string;
|
|
29
|
+
/** @internal */
|
|
21
30
|
commitMessage?: string;
|
|
31
|
+
/** @internal */
|
|
22
32
|
signoff?: boolean;
|
|
23
33
|
}
|
|
24
34
|
|
|
25
|
-
/** Reject escaping paths and symlinks, including a not-yet-created file's parents. */
|
|
35
|
+
/** Reject escaping paths and symlinks, including a not-yet-created file's parents. @public */
|
|
26
36
|
export function localPath(root: string, relative: string): string {
|
|
27
37
|
if (lstatSync(root, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
28
38
|
throw new Error("Local provider storage must not contain symlinks");
|
|
@@ -39,11 +49,13 @@ export function localPath(root: string, relative: string): string {
|
|
|
39
49
|
return target;
|
|
40
50
|
}
|
|
41
51
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
52
|
+
/** @public */
|
|
53
|
+
export function readLocalJson<
|
|
54
|
+
T extends {
|
|
55
|
+
/** @internal */
|
|
56
|
+
version: number;
|
|
57
|
+
},
|
|
58
|
+
>(root: string, file: string, initial: T): T {
|
|
47
59
|
const target = localPath(root, file);
|
|
48
60
|
if (!existsSync(target)) return structuredClone(initial);
|
|
49
61
|
const value = JSON.parse(readFileSync(target, "utf8")) as T;
|
|
@@ -52,6 +64,7 @@ export function readLocalJson<T extends { version: number }>(
|
|
|
52
64
|
return value;
|
|
53
65
|
}
|
|
54
66
|
|
|
67
|
+
/** @public */
|
|
55
68
|
export function writeLocalJson(root: string, file: string, value: unknown): void {
|
|
56
69
|
const target = localPath(root, file);
|
|
57
70
|
const temporary = localPath(root, `${file}.tmp`);
|
|
@@ -59,14 +72,30 @@ export function writeLocalJson(root: string, file: string, value: unknown): void
|
|
|
59
72
|
renameSync(temporary, target);
|
|
60
73
|
}
|
|
61
74
|
|
|
62
|
-
/** Persist local adapter state with a shared clock and monotonically increasing ids. */
|
|
75
|
+
/** Persist local adapter state with a shared clock and monotonically increasing ids. @public */
|
|
63
76
|
export class LocalProviderStore<
|
|
64
|
-
S extends {
|
|
65
|
-
|
|
77
|
+
S extends {
|
|
78
|
+
/** @internal */
|
|
79
|
+
version: number;
|
|
80
|
+
/** @internal */
|
|
81
|
+
sequence: number;
|
|
82
|
+
},
|
|
83
|
+
O extends {
|
|
84
|
+
/** @internal */
|
|
85
|
+
root: string;
|
|
86
|
+
/** @internal */
|
|
87
|
+
now?: () => number;
|
|
88
|
+
/** @internal */
|
|
89
|
+
nextId?: () => number;
|
|
90
|
+
},
|
|
66
91
|
> {
|
|
92
|
+
/** @public */
|
|
67
93
|
readonly git: LocalGit;
|
|
94
|
+
/** @public */
|
|
68
95
|
state: S;
|
|
96
|
+
/** @public */
|
|
69
97
|
constructor(
|
|
98
|
+
/** @public */
|
|
70
99
|
readonly options: O,
|
|
71
100
|
private readonly file: string,
|
|
72
101
|
initial: S,
|
|
@@ -74,44 +103,80 @@ export class LocalProviderStore<
|
|
|
74
103
|
this.git = new LocalGit(options.root);
|
|
75
104
|
this.state = readLocalJson(options.root, file, initial);
|
|
76
105
|
}
|
|
106
|
+
/** @public */
|
|
77
107
|
save() {
|
|
78
108
|
writeLocalJson(this.options.root, this.file, this.state);
|
|
79
109
|
}
|
|
110
|
+
/** @internal */
|
|
80
111
|
id() {
|
|
81
112
|
this.state.sequence = Math.max(this.state.sequence + 1, this.options.nextId?.() ?? 0);
|
|
82
113
|
return this.state.sequence;
|
|
83
114
|
}
|
|
115
|
+
/** @internal */
|
|
84
116
|
timestamp() {
|
|
85
117
|
return new Date(this.options.now?.() ?? Date.now()).toISOString();
|
|
86
118
|
}
|
|
87
119
|
}
|
|
88
120
|
|
|
121
|
+
/** @public */
|
|
89
122
|
type LocalPullRequest = Pick<
|
|
90
123
|
RepositoryPullRequest,
|
|
91
124
|
"number" | "title" | "body" | "state" | "merged" | "merge_commit_sha" | "head" | "base"
|
|
92
125
|
>;
|
|
126
|
+
/** @public */
|
|
93
127
|
interface LocalPullRequestRepository<P extends LocalPullRequest> {
|
|
94
|
-
|
|
128
|
+
/** @public */
|
|
129
|
+
repository: {
|
|
130
|
+
/** @internal */
|
|
131
|
+
ssh_url: string;
|
|
132
|
+
};
|
|
133
|
+
/** @public */
|
|
95
134
|
pulls: P[];
|
|
96
135
|
}
|
|
97
136
|
|
|
98
|
-
/** Common PR operations; adapters retain their provider-specific state and clients. */
|
|
137
|
+
/** Common PR operations; adapters retain their provider-specific state and clients. @public */
|
|
99
138
|
export class LocalForgeStore<
|
|
100
|
-
S extends {
|
|
101
|
-
|
|
139
|
+
S extends {
|
|
140
|
+
/** @internal */
|
|
141
|
+
version: number;
|
|
142
|
+
/** @internal */
|
|
143
|
+
sequence: number;
|
|
144
|
+
},
|
|
145
|
+
O extends {
|
|
146
|
+
/** @internal */
|
|
147
|
+
root: string;
|
|
148
|
+
/** @internal */
|
|
149
|
+
baseUrl: string;
|
|
150
|
+
/** @internal */
|
|
151
|
+
now?: () => number;
|
|
152
|
+
/** @internal */
|
|
153
|
+
nextId?: () => number;
|
|
154
|
+
},
|
|
102
155
|
> extends LocalProviderStore<S, O> {
|
|
156
|
+
/** @public */
|
|
103
157
|
newRepository(seed: LocalRepositorySeed) {
|
|
104
158
|
const { bare, branch } = this.git.seed(seed);
|
|
105
159
|
return {
|
|
160
|
+
/** @public */
|
|
106
161
|
id: this.id(),
|
|
107
|
-
|
|
162
|
+
/** @public */
|
|
163
|
+
owner: {
|
|
164
|
+
/** @internal */
|
|
165
|
+
login: seed.owner,
|
|
166
|
+
},
|
|
167
|
+
/** @public */
|
|
108
168
|
name: seed.name,
|
|
169
|
+
/** @public */
|
|
109
170
|
full_name: `${seed.owner}/${seed.name}`,
|
|
171
|
+
/** @public */
|
|
110
172
|
ssh_url: bare,
|
|
173
|
+
/** @public */
|
|
111
174
|
html_url: `${this.options.baseUrl}/__local`,
|
|
175
|
+
/** @public */
|
|
112
176
|
default_branch: branch,
|
|
113
177
|
};
|
|
114
178
|
}
|
|
179
|
+
/** @internal */
|
|
115
180
|
pullRequestClient<P extends LocalPullRequest>(
|
|
116
181
|
repo: (owner: string, name: string) => LocalPullRequestRepository<P>,
|
|
117
182
|
missing = "Unknown local pull request",
|
|
@@ -122,14 +187,17 @@ export class LocalForgeStore<
|
|
|
122
187
|
return pr;
|
|
123
188
|
};
|
|
124
189
|
return {
|
|
190
|
+
/** @internal */
|
|
125
191
|
getPullRequest: async (owner: string, name: string, number: number) =>
|
|
126
192
|
this.refresh(repo(owner, name), pull(owner, name, number)),
|
|
193
|
+
/** @internal */
|
|
127
194
|
listPullRequests: async (owner: string, name: string, state = "open") => {
|
|
128
195
|
const r = repo(owner, name);
|
|
129
196
|
return r.pulls
|
|
130
197
|
.filter((p) => state === "all" || p.state === state)
|
|
131
198
|
.map((p) => this.refresh(r, p));
|
|
132
199
|
},
|
|
200
|
+
/** @internal */
|
|
133
201
|
updatePullRequest: async (
|
|
134
202
|
owner: string,
|
|
135
203
|
name: string,
|
|
@@ -144,6 +212,7 @@ export class LocalForgeStore<
|
|
|
144
212
|
},
|
|
145
213
|
};
|
|
146
214
|
}
|
|
215
|
+
/** @public */
|
|
147
216
|
refresh<P extends LocalPullRequest>(repo: LocalPullRequestRepository<P>, pr: P): P {
|
|
148
217
|
if (pr.state === "open") {
|
|
149
218
|
const { headSha, baseSha, ...mergeability } = this.git.mergeability(
|
|
@@ -157,6 +226,7 @@ export class LocalForgeStore<
|
|
|
157
226
|
}
|
|
158
227
|
return structuredClone(pr);
|
|
159
228
|
}
|
|
229
|
+
/** @public */
|
|
160
230
|
merge<P extends LocalPullRequest>(repo: LocalPullRequestRepository<P>, number: number): P {
|
|
161
231
|
const pr = repo.pulls.find((p) => p.number === number);
|
|
162
232
|
if (!pr || pr.state !== "open") throw new Error("Pull request is not open");
|
|
@@ -167,8 +237,17 @@ export class LocalForgeStore<
|
|
|
167
237
|
this.save();
|
|
168
238
|
return structuredClone(pr);
|
|
169
239
|
}
|
|
240
|
+
/** @public */
|
|
170
241
|
addFeedback<F extends RepositoryFeedbackItem>(
|
|
171
|
-
repo: {
|
|
242
|
+
repo: {
|
|
243
|
+
/** @public */
|
|
244
|
+
pulls: Array<{
|
|
245
|
+
/** @internal */
|
|
246
|
+
number: number;
|
|
247
|
+
}>;
|
|
248
|
+
/** @public */
|
|
249
|
+
feedback: Record<string, F[]>;
|
|
250
|
+
},
|
|
172
251
|
number: number,
|
|
173
252
|
input: Omit<F, "id" | "createdAt">,
|
|
174
253
|
): F {
|
|
@@ -179,40 +258,88 @@ export class LocalForgeStore<
|
|
|
179
258
|
this.save();
|
|
180
259
|
return value;
|
|
181
260
|
}
|
|
261
|
+
/** @public */
|
|
182
262
|
newComment(body: string) {
|
|
183
263
|
return {
|
|
264
|
+
/** @internal */
|
|
184
265
|
id: this.id(),
|
|
266
|
+
/** @internal */
|
|
185
267
|
body,
|
|
186
|
-
|
|
268
|
+
/** @public */
|
|
269
|
+
user: {
|
|
270
|
+
/** @public */
|
|
271
|
+
login: "leitwerk-bot",
|
|
272
|
+
},
|
|
273
|
+
/** @internal */
|
|
187
274
|
created_at: this.timestamp(),
|
|
188
275
|
};
|
|
189
276
|
}
|
|
277
|
+
/** @internal */
|
|
190
278
|
newPullRequest(
|
|
191
|
-
repo: {
|
|
192
|
-
|
|
279
|
+
repo: {
|
|
280
|
+
/** @internal */
|
|
281
|
+
repository: {
|
|
282
|
+
/** @internal */
|
|
283
|
+
ssh_url: string;
|
|
284
|
+
};
|
|
285
|
+
},
|
|
286
|
+
input: {
|
|
287
|
+
/** @internal */
|
|
288
|
+
title: string;
|
|
289
|
+
/** @internal */
|
|
290
|
+
body: string;
|
|
291
|
+
/** @internal */
|
|
292
|
+
head: string;
|
|
293
|
+
/** @internal */
|
|
294
|
+
base: string;
|
|
295
|
+
},
|
|
193
296
|
) {
|
|
194
297
|
const number = this.id();
|
|
195
298
|
return {
|
|
299
|
+
/** @internal */
|
|
196
300
|
number,
|
|
301
|
+
/** @internal */
|
|
197
302
|
title: input.title,
|
|
303
|
+
/** @internal */
|
|
198
304
|
body: input.body,
|
|
305
|
+
/** @internal */
|
|
199
306
|
state: "open",
|
|
307
|
+
/** @internal */
|
|
200
308
|
merged: false,
|
|
309
|
+
/** @internal */
|
|
201
310
|
merge_commit_sha: null,
|
|
311
|
+
/** @internal */
|
|
202
312
|
html_url: `${this.options.baseUrl}/__local#pr-${number}`,
|
|
203
|
-
|
|
204
|
-
|
|
313
|
+
/** @internal */
|
|
314
|
+
head: {
|
|
315
|
+
/** @internal */
|
|
316
|
+
ref: input.head,
|
|
317
|
+
/** @internal */
|
|
318
|
+
sha: this.git.head(repo.repository.ssh_url, input.head),
|
|
319
|
+
},
|
|
320
|
+
/** @internal */
|
|
321
|
+
base: {
|
|
322
|
+
/** @internal */
|
|
323
|
+
ref: input.base,
|
|
324
|
+
/** @internal */
|
|
325
|
+
sha: this.git.head(repo.repository.ssh_url, input.base),
|
|
326
|
+
},
|
|
205
327
|
};
|
|
206
328
|
}
|
|
207
329
|
}
|
|
208
330
|
|
|
209
|
-
/** Real Git with file-only transport and no ambient credentials or hooks. */
|
|
331
|
+
/** Real Git with file-only transport and no ambient credentials or hooks. @public */
|
|
210
332
|
export class LocalGit {
|
|
211
|
-
|
|
333
|
+
/** @public */
|
|
334
|
+
constructor(
|
|
335
|
+
/** @internal */
|
|
336
|
+
readonly root: string,
|
|
337
|
+
) {
|
|
212
338
|
if (lstatSync(root, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
213
339
|
throw new Error("Local Git root must not be a symlink");
|
|
214
340
|
mkdirSync(root, { recursive: true, mode: 0o700 });
|
|
215
341
|
}
|
|
342
|
+
/** @public */
|
|
216
343
|
run(directory: string, args: string[]): string {
|
|
217
344
|
const base = realpathSync(this.root);
|
|
218
345
|
const directoryPath = path.resolve(directory);
|
|
@@ -221,32 +348,36 @@ export class LocalGit {
|
|
|
221
348
|
directoryPath,
|
|
222
349
|
);
|
|
223
350
|
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
|
-
|
|
351
|
+
return traceTestSubprocess(`git ${args[0] ?? ""}`, () =>
|
|
352
|
+
execFileSync(
|
|
353
|
+
"git",
|
|
354
|
+
["-c", "protocol.file.allow=always", "-c", "core.hooksPath=/dev/null", ...args],
|
|
355
|
+
{
|
|
356
|
+
cwd,
|
|
357
|
+
encoding: "utf8",
|
|
358
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
359
|
+
env: {
|
|
360
|
+
PATH: process.env.PATH,
|
|
361
|
+
HOME: this.root,
|
|
362
|
+
GIT_CONFIG_NOSYSTEM: "1",
|
|
363
|
+
GIT_CONFIG_GLOBAL: "/dev/null",
|
|
364
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
365
|
+
GIT_ALLOW_PROTOCOL: "file",
|
|
366
|
+
GIT_AUTHOR_NAME: "Sandbox Developer",
|
|
367
|
+
GIT_AUTHOR_EMAIL: "developer@sandbox.invalid",
|
|
368
|
+
GIT_COMMITTER_NAME: "Sandbox Developer",
|
|
369
|
+
GIT_COMMITTER_EMAIL: "developer@sandbox.invalid",
|
|
370
|
+
},
|
|
242
371
|
},
|
|
243
|
-
|
|
244
|
-
)
|
|
372
|
+
).trim(),
|
|
373
|
+
);
|
|
245
374
|
}
|
|
375
|
+
/** @public */
|
|
246
376
|
head(directory: string, ref: string): string {
|
|
247
377
|
if (!/^[a-zA-Z0-9_./-]+$/.test(ref) || ref.startsWith("-")) throw new Error("Invalid Git ref");
|
|
248
378
|
return this.run(directory, ["rev-parse", "--verify", `${ref}^{commit}`]);
|
|
249
379
|
}
|
|
380
|
+
/** @internal */
|
|
250
381
|
isAncestor(directory: string, ancestor: string, descendant: string): boolean {
|
|
251
382
|
return this.isAncestorCommit(
|
|
252
383
|
directory,
|
|
@@ -264,11 +395,21 @@ export class LocalGit {
|
|
|
264
395
|
throw error;
|
|
265
396
|
}
|
|
266
397
|
}
|
|
398
|
+
/** @internal */
|
|
267
399
|
mergeability(
|
|
268
400
|
directory: string,
|
|
269
401
|
head: string,
|
|
270
402
|
base: string,
|
|
271
|
-
): {
|
|
403
|
+
): {
|
|
404
|
+
/** @internal */
|
|
405
|
+
headSha: string;
|
|
406
|
+
/** @internal */
|
|
407
|
+
baseSha: string;
|
|
408
|
+
/** @internal */
|
|
409
|
+
mergeable: boolean;
|
|
410
|
+
/** @internal */
|
|
411
|
+
mergeable_state: string;
|
|
412
|
+
} {
|
|
272
413
|
const headSha = this.head(directory, head),
|
|
273
414
|
baseSha = this.head(directory, base);
|
|
274
415
|
const revisions = { headSha, baseSha };
|
|
@@ -283,6 +424,7 @@ export class LocalGit {
|
|
|
283
424
|
}
|
|
284
425
|
return { ...revisions, mergeable: true, mergeable_state: "behind" };
|
|
285
426
|
}
|
|
427
|
+
/** @internal */
|
|
286
428
|
merge(directory: string, head: string, base: string): string {
|
|
287
429
|
const h = this.head(directory, head),
|
|
288
430
|
b = this.head(directory, base);
|
|
@@ -303,7 +445,15 @@ export class LocalGit {
|
|
|
303
445
|
this.run(directory, ["update-ref", `refs/heads/${base}`, commit, b]);
|
|
304
446
|
return commit;
|
|
305
447
|
}
|
|
306
|
-
|
|
448
|
+
/** @internal */
|
|
449
|
+
seed(seed: LocalRepositorySeed): {
|
|
450
|
+
/** @internal */
|
|
451
|
+
bare: string;
|
|
452
|
+
/** @internal */
|
|
453
|
+
worktree: string;
|
|
454
|
+
/** @internal */
|
|
455
|
+
branch: string;
|
|
456
|
+
} {
|
|
307
457
|
for (const value of [seed.owner, seed.name, seed.directoryName ?? seed.name])
|
|
308
458
|
if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(value))
|
|
309
459
|
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({
|
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,
|
package/src/question-fixtures.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { NormalizedQuestion, ProcessQuestionRequest } from "@leitwerk-dev/domain";
|
|
2
2
|
|
|
3
|
+
/** @internal */
|
|
3
4
|
export function createTestQuestion(
|
|
4
5
|
overrides: Partial<NormalizedQuestion> = {},
|
|
5
6
|
): NormalizedQuestion {
|
|
@@ -12,6 +13,7 @@ export function createTestQuestion(
|
|
|
12
13
|
};
|
|
13
14
|
}
|
|
14
15
|
|
|
16
|
+
/** @internal */
|
|
15
17
|
export function createTestQuestionRequest(
|
|
16
18
|
overrides: Partial<ProcessQuestionRequest> = {},
|
|
17
19
|
): ProcessQuestionRequest {
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { type ExtensionCatalog, setupServerExtensions } from "@leitwerk-dev/extension-runtime";
|
|
2
2
|
import { buildExtensionCatalogFromModules } from "@leitwerk-dev/extension-runtime/testing";
|
|
3
|
+
import {
|
|
4
|
+
bindExternalWrites,
|
|
5
|
+
type ExternalWriteLogRepoLike,
|
|
6
|
+
} from "@leitwerk-dev/external-writes/internal";
|
|
3
7
|
import {
|
|
4
8
|
type CoreServerSetupDeps,
|
|
5
9
|
coreHostCapabilities,
|
|
@@ -15,17 +19,25 @@ import { flushAsyncWork } from "@leitwerk-dev/worker-protocol";
|
|
|
15
19
|
|
|
16
20
|
export { flushAsyncWork };
|
|
17
21
|
|
|
18
|
-
/** Register a test provider and expose its poll result without erasing its type. */
|
|
22
|
+
/** Register a test provider and expose its poll result without erasing its type. @public */
|
|
19
23
|
export function createPollingTestExtension<T>(
|
|
20
24
|
manifest: LeitwerkExtensionModule["manifest"],
|
|
21
|
-
setup: (api: ServerExtensionAPI) =>
|
|
25
|
+
setup: (api: ServerExtensionAPI) =>
|
|
26
|
+
| {
|
|
27
|
+
/** @internal */
|
|
28
|
+
poll(): Promise<T>;
|
|
29
|
+
}
|
|
30
|
+
| undefined,
|
|
22
31
|
) {
|
|
23
32
|
let provider: ReturnType<typeof setup>;
|
|
24
33
|
return {
|
|
34
|
+
/** @internal */
|
|
25
35
|
manifest,
|
|
36
|
+
/** @internal */
|
|
26
37
|
setupServer(api: ServerExtensionAPI) {
|
|
27
38
|
provider = setup(api);
|
|
28
39
|
},
|
|
40
|
+
/** @public */
|
|
29
41
|
poll() {
|
|
30
42
|
if (!provider) throw new Error(`Test provider '${manifest.id}' has not been initialized`);
|
|
31
43
|
return provider.poll();
|
|
@@ -33,21 +45,52 @@ export function createPollingTestExtension<T>(
|
|
|
33
45
|
};
|
|
34
46
|
}
|
|
35
47
|
|
|
36
|
-
|
|
48
|
+
/** @internal */
|
|
49
|
+
export function createToolCollector(
|
|
50
|
+
writes: ExternalWriteLogRepoLike = createInMemoryExternalWriteLog(),
|
|
51
|
+
) {
|
|
37
52
|
const tools = new Map<string, IntegrationToolDefinition>();
|
|
38
53
|
const api = {
|
|
39
|
-
tool: (tool: IntegrationToolDefinition) =>
|
|
54
|
+
tool: (tool: IntegrationToolDefinition) =>
|
|
55
|
+
tools.set(tool.name, {
|
|
56
|
+
...tool,
|
|
57
|
+
execute: (ctx, args) =>
|
|
58
|
+
tool.execute(
|
|
59
|
+
{ ...ctx, externalWrites: bindExternalWrites(writes, ctx.process.id) },
|
|
60
|
+
args,
|
|
61
|
+
),
|
|
62
|
+
}),
|
|
40
63
|
} as unknown as ServerExtensionAPI;
|
|
41
|
-
return {
|
|
64
|
+
return {
|
|
65
|
+
/** @internal */
|
|
66
|
+
api,
|
|
67
|
+
/** @internal */
|
|
68
|
+
tools,
|
|
69
|
+
};
|
|
42
70
|
}
|
|
43
71
|
|
|
72
|
+
/** @internal */
|
|
44
73
|
export interface InMemoryExternalWriteLog {
|
|
45
|
-
|
|
74
|
+
/** @internal */
|
|
75
|
+
records: {
|
|
76
|
+
/** @internal */
|
|
77
|
+
dedupKey: string;
|
|
78
|
+
}[];
|
|
79
|
+
/** @internal */
|
|
46
80
|
hasDedupKey(key: string): boolean;
|
|
47
|
-
|
|
81
|
+
/** @internal */
|
|
82
|
+
record(input: {
|
|
83
|
+
/** @internal */
|
|
84
|
+
dedupKey: string;
|
|
85
|
+
}): {
|
|
86
|
+
/** @internal */
|
|
87
|
+
dedupKey: string;
|
|
88
|
+
};
|
|
89
|
+
/** @internal */
|
|
48
90
|
getDedupKeys(): ReadonlySet<string>;
|
|
49
91
|
}
|
|
50
92
|
|
|
93
|
+
/** @internal */
|
|
51
94
|
export function createInMemoryExternalWriteLog(): InMemoryExternalWriteLog {
|
|
52
95
|
const dedupKeys = new Set<string>();
|
|
53
96
|
const records: { dedupKey: string }[] = [];
|
|
@@ -159,6 +202,7 @@ function createDefaultServerSetupDeps(): CoreServerSetupDeps {
|
|
|
159
202
|
};
|
|
160
203
|
}
|
|
161
204
|
|
|
205
|
+
/** @public */
|
|
162
206
|
export function createTestServerSetupCapability(
|
|
163
207
|
overrides: Partial<CoreServerSetupDeps> = {},
|
|
164
208
|
): CoreServerSetupDeps {
|
|
@@ -187,20 +231,33 @@ export function createTestServerSetupCapability(
|
|
|
187
231
|
};
|
|
188
232
|
}
|
|
189
233
|
|
|
234
|
+
/** @internal */
|
|
190
235
|
export interface ServerExtensionTestHarness {
|
|
236
|
+
/** @internal */
|
|
191
237
|
catalog: ExtensionCatalog;
|
|
238
|
+
/** @internal */
|
|
192
239
|
events: ReturnType<typeof createEventBus>;
|
|
240
|
+
/** @internal */
|
|
193
241
|
serverSetup: CoreServerSetupDeps;
|
|
242
|
+
/** @internal */
|
|
194
243
|
startHooks: Array<() => void | Promise<void>>;
|
|
244
|
+
/** @internal */
|
|
195
245
|
stopHooks: Array<() => void | Promise<void>>;
|
|
246
|
+
/** @internal */
|
|
196
247
|
flushAsyncWork: typeof flushAsyncWork;
|
|
197
248
|
}
|
|
198
249
|
|
|
250
|
+
/** @internal */
|
|
199
251
|
export async function setupServerExtensionTest(input: {
|
|
252
|
+
/** @internal */
|
|
200
253
|
modules: readonly LeitwerkExtensionModule[];
|
|
254
|
+
/** @internal */
|
|
201
255
|
providedCapabilities?: readonly ProvidedCapability[];
|
|
256
|
+
/** @internal */
|
|
202
257
|
serverSetup?: Partial<CoreServerSetupDeps>;
|
|
258
|
+
/** @internal */
|
|
203
259
|
onStart?: (handler: () => void | Promise<void>) => void;
|
|
260
|
+
/** @internal */
|
|
204
261
|
onStop?: (handler: () => void | Promise<void>) => void;
|
|
205
262
|
}): Promise<ServerExtensionTestHarness> {
|
|
206
263
|
const catalog = await buildExtensionCatalogFromModules(input.modules);
|