@operad-io/dev 0.0.1 → 0.1.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/README.md +8 -791
- package/dev.schema.json +46 -17
- package/package.json +7 -7
- package/src/actions.ts +9 -2
- package/src/chat.ts +1 -1
- package/src/gate.ts +83 -30
- package/src/index.ts +2 -1
- package/src/integrate.ts +59 -9
- package/src/integration-queue.ts +154 -16
- package/src/mainclone.ts +43 -4
- package/src/marks.ts +1 -1
- package/src/model.ts +8 -0
- package/src/notcode.ts +39 -0
- package/src/project-settings.ts +7 -0
- package/src/rerun.ts +15 -3
- package/src/schedule.ts +1 -1
- package/src/service.ts +80 -15
- package/src/settings.ts +36 -4
package/src/integration-queue.ts
CHANGED
|
@@ -12,6 +12,11 @@
|
|
|
12
12
|
* A ticket is written only by its own task. Claims and "integrate alone" marks
|
|
13
13
|
* are separate files the leader owns (`c-<leader>.json`, `s-<task>.json`), so a
|
|
14
14
|
* task that leaves while it is claimed is never written back.
|
|
15
|
+
*
|
|
16
|
+
* Withdrawing a ticket and a leader's last check-and-push take the same lock
|
|
17
|
+
* (`land.lock`): either the withdrawal comes first, so the leader sees it and
|
|
18
|
+
* lands without that task, or the push comes first, so the task stays in the
|
|
19
|
+
* batch. The lock is held across the push, and nothing slower.
|
|
15
20
|
*/
|
|
16
21
|
|
|
17
22
|
import {
|
|
@@ -50,11 +55,12 @@ export interface BatchResult {
|
|
|
50
55
|
readonly head: string;
|
|
51
56
|
readonly note?: string | undefined;
|
|
52
57
|
/**
|
|
53
|
-
* `pending` from before the leader pushes until
|
|
54
|
-
*
|
|
55
|
-
*
|
|
58
|
+
* `pending` from before the leader pushes until the push succeeds, `pushed`
|
|
59
|
+
* once it has, and `done` after the leader recorded the merge. A pending
|
|
60
|
+
* result whose leader is gone is settled by whether `head` landed. A result
|
|
61
|
+
* without a state is done.
|
|
56
62
|
*/
|
|
57
|
-
readonly state?: "pending" | "done" | undefined;
|
|
63
|
+
readonly state?: "pending" | "pushed" | "done" | undefined;
|
|
58
64
|
readonly members: readonly { readonly task: string; readonly sha: string }[];
|
|
59
65
|
}
|
|
60
66
|
|
|
@@ -71,6 +77,24 @@ export type Turn =
|
|
|
71
77
|
| { readonly kind: "turn" }
|
|
72
78
|
| { readonly kind: "batched"; readonly leader: string; readonly result: BatchResult };
|
|
73
79
|
|
|
80
|
+
/** What withdrawing a ticket found: it went, or the leader had already pushed it. */
|
|
81
|
+
export type Withdrawal =
|
|
82
|
+
| { readonly kind: "withdrawn" }
|
|
83
|
+
| { readonly kind: "merged"; readonly leader: string; readonly result: BatchResult };
|
|
84
|
+
|
|
85
|
+
/** What a leader's last check, publish and push did. */
|
|
86
|
+
export type Landing = "withdrawn" | "pushed" | "failed";
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Test-only hooks. Production code never sets them. `lockWait` replaces the
|
|
90
|
+
* wait of the land lock so a test can see a withdrawal wait behind a push;
|
|
91
|
+
* `withdrawn` reports what that withdrawal found.
|
|
92
|
+
*/
|
|
93
|
+
export const integrationQueueTestHooks: {
|
|
94
|
+
lockWait?: ((ms: number) => Promise<void>) | undefined;
|
|
95
|
+
withdrawn?: ((task: string, kind: Withdrawal["kind"]) => void) | undefined;
|
|
96
|
+
} = {};
|
|
97
|
+
|
|
74
98
|
export interface QueueOptions {
|
|
75
99
|
readonly home: string;
|
|
76
100
|
readonly repository: { readonly name: string; readonly path: string };
|
|
@@ -111,6 +135,10 @@ function safeName(task: string): string {
|
|
|
111
135
|
return task.replace(/[^A-Za-z0-9._-]/g, "_");
|
|
112
136
|
}
|
|
113
137
|
|
|
138
|
+
function landLockPath(directory: string): string {
|
|
139
|
+
return join(directory, "land.lock");
|
|
140
|
+
}
|
|
141
|
+
|
|
114
142
|
function writeAtomic(path: string, value: unknown): void {
|
|
115
143
|
const temporary = `${path}.${process.pid}.tmp`;
|
|
116
144
|
writeFileSync(temporary, JSON.stringify(value));
|
|
@@ -171,6 +199,26 @@ export class IntegrationQueue {
|
|
|
171
199
|
return join(this.directory, `r-${safeName(leader)}.json`);
|
|
172
200
|
}
|
|
173
201
|
|
|
202
|
+
/** The lock a withdrawal and a leader's last check-and-push share. */
|
|
203
|
+
private withLandLock<T>(work: () => Promise<T> | T): Promise<T> {
|
|
204
|
+
const wait = integrationQueueTestHooks.lockWait;
|
|
205
|
+
return withLockFile(landLockPath(this.directory), work, {
|
|
206
|
+
label: "integration queue",
|
|
207
|
+
onLog: () => {},
|
|
208
|
+
...(wait === undefined ? {} : { wait }),
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** Removes this task's ticket and its "integrate alone" mark. */
|
|
213
|
+
private removeTicket(): void {
|
|
214
|
+
this.joined = false;
|
|
215
|
+
rmSync(this.ticketPath(this.options.task), { force: true });
|
|
216
|
+
rmSync(this.soloPath(this.options.task), { force: true });
|
|
217
|
+
// Looking prunes what no one needs now: a leader's claim and result stay
|
|
218
|
+
// while a task it claimed is still queued.
|
|
219
|
+
this.tickets();
|
|
220
|
+
}
|
|
221
|
+
|
|
174
222
|
/** The live tickets in queue order; tickets of dead processes are dropped. */
|
|
175
223
|
tickets(): readonly Ticket[] {
|
|
176
224
|
let names: string[];
|
|
@@ -272,14 +320,65 @@ export class IntegrationQueue {
|
|
|
272
320
|
}
|
|
273
321
|
|
|
274
322
|
/** Gives the turn back, and the ticket with it. */
|
|
275
|
-
leave(): void {
|
|
323
|
+
async leave(): Promise<void> {
|
|
276
324
|
if (!this.joined) return;
|
|
277
|
-
this.
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
325
|
+
await this.withLandLock(() => this.removeTicket());
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* A withdrawal takes the land lock, so it cannot slip between a leader's last
|
|
330
|
+
* check and its push. It removes the ticket unless the leader already pushed
|
|
331
|
+
* a batch that lists this task; then it says so and leaves the task to record
|
|
332
|
+
* its merge.
|
|
333
|
+
*/
|
|
334
|
+
async withdraw(): Promise<Withdrawal> {
|
|
335
|
+
const withdrawal = await this.withLandLock(() => {
|
|
336
|
+
const me = this.options.task;
|
|
337
|
+
const mine = this.tickets().find((ticket) => ticket.task === me);
|
|
338
|
+
// A follower reads its leader's result; the leader reads its own. The
|
|
339
|
+
// leader's ticket is still here while it pushes, so it must be asked too.
|
|
340
|
+
const leader = mine === undefined ? undefined : (mine.claimedBy ?? me);
|
|
341
|
+
if (leader !== undefined) {
|
|
342
|
+
const result = this.readResult(leader);
|
|
343
|
+
if (
|
|
344
|
+
result !== undefined &&
|
|
345
|
+
result.state !== "pending" &&
|
|
346
|
+
result.members.some((member) => member.task === me)
|
|
347
|
+
) {
|
|
348
|
+
return { kind: "merged" as const, leader, result };
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
this.removeTicket();
|
|
352
|
+
return { kind: "withdrawn" as const };
|
|
353
|
+
});
|
|
354
|
+
integrationQueueTestHooks.withdrawn?.(this.options.task, withdrawal.kind);
|
|
355
|
+
return withdrawal;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* The leader's last check, its result and the push, under the land lock. A
|
|
360
|
+
* ticket that left first makes this land without its batch; a push that
|
|
361
|
+
* lands first leaves a result a waiting withdrawal reads as merged.
|
|
362
|
+
*/
|
|
363
|
+
async landWhenStillQueued(
|
|
364
|
+
followers: readonly Ticket[],
|
|
365
|
+
result: BatchResult,
|
|
366
|
+
push: () => Promise<boolean> | boolean,
|
|
367
|
+
): Promise<Landing> {
|
|
368
|
+
return this.withLandLock(async () => {
|
|
369
|
+
const queued = new Set(this.tickets().map((ticket) => ticket.task));
|
|
370
|
+
if (
|
|
371
|
+
!queued.has(this.options.task) ||
|
|
372
|
+
this.stillQueued(followers).length !== followers.length
|
|
373
|
+
) {
|
|
374
|
+
return "withdrawn" as const;
|
|
375
|
+
}
|
|
376
|
+
this.publish(result);
|
|
377
|
+
const pushed = await push();
|
|
378
|
+
if (!pushed) return "failed" as const;
|
|
379
|
+
this.markPushed();
|
|
380
|
+
return "pushed" as const;
|
|
381
|
+
});
|
|
283
382
|
}
|
|
284
383
|
|
|
285
384
|
private readResult(leader: string): BatchResult | undefined {
|
|
@@ -321,8 +420,19 @@ export class IntegrationQueue {
|
|
|
321
420
|
}
|
|
322
421
|
holder = claimed;
|
|
323
422
|
}
|
|
324
|
-
if (this.options.signal?.aborted === true)
|
|
325
|
-
|
|
423
|
+
if (this.options.signal?.aborted === true) {
|
|
424
|
+
const withdrawal = await this.withdraw();
|
|
425
|
+
if (withdrawal.kind === "merged") {
|
|
426
|
+
return {
|
|
427
|
+
kind: "batched",
|
|
428
|
+
leader: withdrawal.leader,
|
|
429
|
+
result: withdrawal.result,
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
throw new IntegrationQueueCancelled();
|
|
433
|
+
}
|
|
434
|
+
// Only a withdrawal removes a live task's ticket; its run is cancelled.
|
|
435
|
+
if (mine === undefined) throw new IntegrationQueueCancelled();
|
|
326
436
|
if (holder === undefined) {
|
|
327
437
|
const head = tickets.find((ticket) => ticket.claimedBy === undefined);
|
|
328
438
|
if (head !== undefined && head.task === me) return { kind: "turn" };
|
|
@@ -379,7 +489,14 @@ export class IntegrationQueue {
|
|
|
379
489
|
writeAtomic(this.resultPath(this.options.task), { ...result, state: "pending" });
|
|
380
490
|
}
|
|
381
491
|
|
|
382
|
-
/** The push landed
|
|
492
|
+
/** The push landed: a waiting withdrawal now reads the batch as merged. */
|
|
493
|
+
private markPushed(): void {
|
|
494
|
+
const result = this.readResult(this.options.task);
|
|
495
|
+
if (result === undefined) return;
|
|
496
|
+
writeAtomic(this.resultPath(this.options.task), { ...result, state: "pushed" });
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/** The leader has recorded the merge: the result is final. */
|
|
383
500
|
finish(): void {
|
|
384
501
|
const result = this.readResult(this.options.task);
|
|
385
502
|
if (result === undefined) return;
|
|
@@ -387,7 +504,28 @@ export class IntegrationQueue {
|
|
|
387
504
|
}
|
|
388
505
|
|
|
389
506
|
/** A claimed task is done with the result. */
|
|
390
|
-
done(): void {
|
|
391
|
-
this.leave();
|
|
507
|
+
async done(): Promise<void> {
|
|
508
|
+
await this.leave();
|
|
392
509
|
}
|
|
393
510
|
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Takes a task out of the integration queue on behalf of a cancel, with the
|
|
514
|
+
* land lock a leader's last check-and-push takes. It answers `merged` when the
|
|
515
|
+
* leader already pushed a batch that lists the task.
|
|
516
|
+
*/
|
|
517
|
+
export async function withdrawIntegration(
|
|
518
|
+
home: string,
|
|
519
|
+
repository: { readonly name: string; readonly path: string },
|
|
520
|
+
task: string,
|
|
521
|
+
): Promise<Withdrawal> {
|
|
522
|
+
return new IntegrationQueue({
|
|
523
|
+
home,
|
|
524
|
+
repository,
|
|
525
|
+
task,
|
|
526
|
+
run: "",
|
|
527
|
+
verified: "",
|
|
528
|
+
message: "",
|
|
529
|
+
say: () => {},
|
|
530
|
+
}).withdraw();
|
|
531
|
+
}
|
package/src/mainclone.ts
CHANGED
|
@@ -23,6 +23,18 @@ export type CommandRunner = (
|
|
|
23
23
|
line: string,
|
|
24
24
|
) => Promise<CommandResult>;
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* The task's durable record of whether this merge's prepare still has to run.
|
|
28
|
+
* It is saved before the fast-forward, so a restart after the clone moved runs
|
|
29
|
+
* the lines even when the clone already holds the commit.
|
|
30
|
+
*/
|
|
31
|
+
export interface PrepareMarker {
|
|
32
|
+
/** True when the record says this merge moved the clone and prepare is not done. */
|
|
33
|
+
readonly due: boolean;
|
|
34
|
+
/** Saves whether prepare is due; false when the record could not be written. */
|
|
35
|
+
readonly save: (due: boolean) => Promise<boolean>;
|
|
36
|
+
}
|
|
37
|
+
|
|
26
38
|
/** What happened to the main clone. */
|
|
27
39
|
export interface MainCloneOutcome {
|
|
28
40
|
readonly updated: boolean;
|
|
@@ -57,6 +69,18 @@ async function prepare(
|
|
|
57
69
|
return { updated: true, prepared: true, note: "prepare done" };
|
|
58
70
|
}
|
|
59
71
|
|
|
72
|
+
/** Runs prepare and records that it is no longer due, even when a line failed. */
|
|
73
|
+
async function prepareAndClear(
|
|
74
|
+
repository: string,
|
|
75
|
+
lines: readonly string[],
|
|
76
|
+
run: CommandRunner,
|
|
77
|
+
marker: PrepareMarker | undefined,
|
|
78
|
+
): Promise<MainCloneOutcome> {
|
|
79
|
+
const outcome = await prepare(repository, lines, run);
|
|
80
|
+
await marker?.save(false);
|
|
81
|
+
return outcome;
|
|
82
|
+
}
|
|
83
|
+
|
|
60
84
|
/** The text a task's Changes shows, or undefined when there is nothing to say. */
|
|
61
85
|
export function mainCloneChange(outcome: MainCloneOutcome): string | undefined {
|
|
62
86
|
if (!outcome.updated) return `main clone not updated: ${outcome.note ?? "unknown"}`;
|
|
@@ -65,7 +89,9 @@ export function mainCloneChange(outcome: MainCloneOutcome): string | undefined {
|
|
|
65
89
|
|
|
66
90
|
/**
|
|
67
91
|
* Fast-forwards the main clone to `sha` when it is on `branch` and clean, then
|
|
68
|
-
* runs the prepare lines there when the clone moved.
|
|
92
|
+
* runs the prepare lines there when the clone moved. A marker left by an
|
|
93
|
+
* interrupted merge makes a replay run prepare even when the clone already
|
|
94
|
+
* holds the commit.
|
|
69
95
|
*/
|
|
70
96
|
export async function updateMainClone(
|
|
71
97
|
repository: string,
|
|
@@ -73,6 +99,7 @@ export async function updateMainClone(
|
|
|
73
99
|
sha: string,
|
|
74
100
|
lines: readonly string[],
|
|
75
101
|
run: CommandRunner,
|
|
102
|
+
marker?: PrepareMarker | undefined,
|
|
76
103
|
): Promise<MainCloneOutcome> {
|
|
77
104
|
const current = git(repository, ["symbolic-ref", "--short", "-q", "HEAD"]);
|
|
78
105
|
if (!current.ok || current.out !== branch) {
|
|
@@ -88,15 +115,27 @@ export async function updateMainClone(
|
|
|
88
115
|
if (status.out.length > 0) {
|
|
89
116
|
return { updated: false, note: "uncommitted changes" };
|
|
90
117
|
}
|
|
91
|
-
|
|
92
|
-
|
|
118
|
+
const already = git(repository, ["merge-base", "--is-ancestor", sha, "HEAD"]).ok;
|
|
119
|
+
if (already) {
|
|
120
|
+
if (marker?.due !== true) return { updated: true };
|
|
121
|
+
if (lines.length === 0) {
|
|
122
|
+
await marker.save(false);
|
|
123
|
+
return { updated: true };
|
|
124
|
+
}
|
|
125
|
+
return prepareAndClear(repository, lines, run, marker);
|
|
126
|
+
}
|
|
127
|
+
if (lines.length > 0 && marker !== undefined) {
|
|
128
|
+
if (!(await marker.save(true))) {
|
|
129
|
+
return { updated: false, note: "cannot record that prepare is due" };
|
|
130
|
+
}
|
|
93
131
|
}
|
|
94
132
|
const merge = git(repository, ["merge", "--ff-only", sha]);
|
|
95
133
|
if (!merge.ok) {
|
|
134
|
+
if (lines.length > 0 && marker !== undefined) await marker.save(false);
|
|
96
135
|
return {
|
|
97
136
|
updated: false,
|
|
98
137
|
note: `cannot fast-forward: ${lastLine(merge.err || merge.out) || "git merge failed"}`,
|
|
99
138
|
};
|
|
100
139
|
}
|
|
101
|
-
return
|
|
140
|
+
return prepareAndClear(repository, lines, run, marker);
|
|
102
141
|
}
|
package/src/marks.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The mark and badge a dev row carries (
|
|
2
|
+
* The mark and badge a dev row carries (ADR 0016). The marks
|
|
3
3
|
* are read from the same task and plan data the views read: the phase, what
|
|
4
4
|
* the attempt has recorded so far, and the holds the scheduler keeps.
|
|
5
5
|
*/
|
package/src/model.ts
CHANGED
|
@@ -162,6 +162,8 @@ export interface VerifyRecord {
|
|
|
162
162
|
/** The file the failed command's output was written to. */
|
|
163
163
|
readonly log?: string | null;
|
|
164
164
|
readonly message?: string | null;
|
|
165
|
+
/** The check's reason: `stall` names a command that stopped writing. */
|
|
166
|
+
readonly reason?: string | null;
|
|
165
167
|
readonly lineNumber?: number | null;
|
|
166
168
|
/** The gate commands this verify ran, as they were when it ran. */
|
|
167
169
|
readonly commands?: readonly string[];
|
|
@@ -241,6 +243,8 @@ export interface ReviewRunRecord {
|
|
|
241
243
|
readonly verified?: readonly string[] | null;
|
|
242
244
|
/** How many of the findings are at or above the fix level. */
|
|
243
245
|
readonly counted?: number | null;
|
|
246
|
+
/** Which entry of the fallback list a fallback run used; 0 when unset. */
|
|
247
|
+
readonly fallbackIndex?: number | null;
|
|
244
248
|
}
|
|
245
249
|
|
|
246
250
|
/**
|
|
@@ -257,6 +261,8 @@ export interface PendingReviewRun {
|
|
|
257
261
|
readonly args: readonly string[];
|
|
258
262
|
readonly model: string;
|
|
259
263
|
readonly reason: ReviewRunReason;
|
|
264
|
+
/** Which entry of the fallback list a fallback run uses; 0 when unset. */
|
|
265
|
+
readonly fallbackIndex?: number | null;
|
|
260
266
|
readonly run?: string | null;
|
|
261
267
|
/** The report path inside the gate worktree this call was given. */
|
|
262
268
|
readonly report?: string | null;
|
|
@@ -311,6 +317,8 @@ export interface IntegrationRecord {
|
|
|
311
317
|
/** True when the branch head was no longer the verified commit. */
|
|
312
318
|
readonly headMoved?: boolean | null;
|
|
313
319
|
readonly pushed?: boolean | null;
|
|
320
|
+
/** True when this merge moved the clone and its prepare lines have not finished. */
|
|
321
|
+
readonly prepareDue?: boolean | null;
|
|
314
322
|
readonly message?: string | null;
|
|
315
323
|
readonly command?: string | null;
|
|
316
324
|
readonly log?: string | null;
|
package/src/notcode.ts
CHANGED
|
@@ -20,6 +20,11 @@
|
|
|
20
20
|
* rerun. The check then passes; the kind tells the flaky-test count whether
|
|
21
21
|
* the machine was to blame (see `isLoaded`).
|
|
22
22
|
*
|
|
23
|
+
* A `test-timeout` is code, not the machine, when the failed test was rerun
|
|
24
|
+
* alone, timed out again, and the load during that rerun stayed below the
|
|
25
|
+
* flaky load limit (`check.flakyLoadLimit`, default twice the cores): the
|
|
26
|
+
* result goes to the worker as a failure with a rework note.
|
|
27
|
+
*
|
|
23
28
|
* For a result of kind 1 to 3, `runCheckSteadily` waits until the machine's
|
|
24
29
|
* 1-minute load average is below the limit (`check.loadLimit`, default the
|
|
25
30
|
* number of cores), runs the check once more by itself, and reports a second
|
|
@@ -29,6 +34,7 @@
|
|
|
29
34
|
|
|
30
35
|
import { machineLoad, type MachineLoad } from "@operad-io/engine/platform";
|
|
31
36
|
import { waitFor } from "./gate.ts";
|
|
37
|
+
import { flakyLoadLimitOf } from "./flaky.ts";
|
|
32
38
|
import { readSince, type CheckRun } from "./rerun.ts";
|
|
33
39
|
import { isRecord } from "@operad-io/engine";
|
|
34
40
|
|
|
@@ -181,6 +187,33 @@ export interface CheckLoad {
|
|
|
181
187
|
readonly end: MachineLoad;
|
|
182
188
|
}
|
|
183
189
|
|
|
190
|
+
/**
|
|
191
|
+
* The checked result with a note when it is a test that timed out when run
|
|
192
|
+
* alone under a load below the flaky limit; otherwise undefined.
|
|
193
|
+
*/
|
|
194
|
+
function timeoutAlone(
|
|
195
|
+
checked: CheckRun,
|
|
196
|
+
load: CheckLoad,
|
|
197
|
+
flakyLimit: number | undefined,
|
|
198
|
+
): CheckRun | undefined {
|
|
199
|
+
if (checked.aloneRerun !== true) return undefined;
|
|
200
|
+
const facts = factsOf(checked);
|
|
201
|
+
if (classifyCheck(facts)?.kind !== "test-timeout") return undefined;
|
|
202
|
+
const limit = flakyLoadLimitOf(flakyLimit, load.end);
|
|
203
|
+
// Busy means above the limit, as `flaky.ts` reads it. The reading spans the whole
|
|
204
|
+
// check run (full suite and alone rerun), so a quiet reading is a strict test.
|
|
205
|
+
if (load.start.load1 > limit || load.end.load1 > limit) return undefined;
|
|
206
|
+
const outcome = checked.outcome;
|
|
207
|
+
if (outcome === undefined) return undefined;
|
|
208
|
+
const data = isRecord(outcome.data) ? outcome.data : {};
|
|
209
|
+
const names = failedTests(facts.log).map((test) => test.name).join("; ");
|
|
210
|
+
const seconds = testTimeoutOf(facts.line) / 1000;
|
|
211
|
+
const peak = Math.max(load.start.load1, load.end.load1);
|
|
212
|
+
const log = typeof data.log === "string" ? `; log: ${data.log}` : "";
|
|
213
|
+
const message = `the failed test "${names}" timed out at ${seconds} s when run alone under load ${Number(peak.toFixed(1))} on ${load.end.cores} cores${log}`;
|
|
214
|
+
return { ...checked, outcome: { ...outcome, data: { ...data, message } } };
|
|
215
|
+
}
|
|
216
|
+
|
|
184
217
|
export interface SteadyCheck {
|
|
185
218
|
readonly checked: CheckRun;
|
|
186
219
|
/** Set when the check ended "not the code" twice: a person decides. */
|
|
@@ -229,6 +262,8 @@ async function waitForQuiet(
|
|
|
229
262
|
export async function runCheckSteadily(input: {
|
|
230
263
|
readonly run: () => Promise<CheckRun>;
|
|
231
264
|
readonly limit: number | undefined;
|
|
265
|
+
/** `check.flakyLoadLimit`: a timeout alone below it is the code's. */
|
|
266
|
+
readonly flakyLimit?: number | undefined;
|
|
232
267
|
readonly signal?: AbortSignal | undefined;
|
|
233
268
|
readonly log?: ((text: string) => Promise<unknown> | unknown) | undefined;
|
|
234
269
|
}): Promise<SteadyCheck> {
|
|
@@ -242,6 +277,8 @@ export async function runCheckSteadily(input: {
|
|
|
242
277
|
const first = await input.run();
|
|
243
278
|
const firstEnd = sample();
|
|
244
279
|
const loads: CheckLoad[] = [{ start: firstStart, end: firstEnd }];
|
|
280
|
+
const firstCode = timeoutAlone(first, { start: firstStart, end: firstEnd }, input.flakyLimit);
|
|
281
|
+
if (firstCode !== undefined) return { checked: firstCode, runs: 1, load: peak, loads };
|
|
245
282
|
if (!worthAnotherRun(classifyRun(first))) {
|
|
246
283
|
return { checked: first, runs: 1, load: peak, loads };
|
|
247
284
|
}
|
|
@@ -252,6 +289,8 @@ export async function runCheckSteadily(input: {
|
|
|
252
289
|
const second = await input.run();
|
|
253
290
|
const after = sample();
|
|
254
291
|
loads.push({ start: secondStart, end: after });
|
|
292
|
+
const secondCode = timeoutAlone(second, { start: secondStart, end: after }, input.flakyLimit);
|
|
293
|
+
if (secondCode !== undefined) return { checked: secondCode, runs: 2, load: peak, loads };
|
|
255
294
|
const found = classifyRun(second);
|
|
256
295
|
if (!worthAnotherRun(found)) {
|
|
257
296
|
return { checked: second, runs: 2, load: peak, loads };
|
package/src/project-settings.ts
CHANGED
|
@@ -82,6 +82,13 @@ export const DEV_PROJECT_SETTINGS: ProjectSettingsDeclaration = {
|
|
|
82
82
|
description:
|
|
83
83
|
"The longest one check may run, in seconds, before it counts as failed.",
|
|
84
84
|
},
|
|
85
|
+
stallSecs: {
|
|
86
|
+
type: "number",
|
|
87
|
+
minimum: 1,
|
|
88
|
+
editable: true,
|
|
89
|
+
description:
|
|
90
|
+
"How long a check may write nothing, in seconds, before it is stopped and fails as a stall. Unset turns the limit off.",
|
|
91
|
+
},
|
|
85
92
|
},
|
|
86
93
|
},
|
|
87
94
|
reviewer: {
|
package/src/rerun.ts
CHANGED
|
@@ -34,6 +34,8 @@ export interface CheckRun {
|
|
|
34
34
|
readonly passedOnRerun: readonly string[];
|
|
35
35
|
/** The `failed` settings of the command whose match found each of those tests. */
|
|
36
36
|
readonly failedBy?: ReadonlyMap<string, FailedRerun> | undefined;
|
|
37
|
+
/** Set when the result is the failed test's own rerun, run alone, failing again. */
|
|
38
|
+
readonly aloneRerun?: boolean | undefined;
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
/** The line drawn between the two runs in the check log. */
|
|
@@ -119,7 +121,13 @@ export async function runCheckWithRerun(
|
|
|
119
121
|
const firstData = dataOf(first.outcome);
|
|
120
122
|
const failed = first.hostError !== undefined || first.outcome?.result === "fail";
|
|
121
123
|
// Only a plain failure is rerun: not a cancel, not a hang.
|
|
122
|
-
if (
|
|
124
|
+
if (
|
|
125
|
+
!failed ||
|
|
126
|
+
rerun <= 0 ||
|
|
127
|
+
firstData.reason === "timeout" ||
|
|
128
|
+
firstData.reason === "stall" ||
|
|
129
|
+
first.hostError !== undefined
|
|
130
|
+
) {
|
|
123
131
|
return { ...first, rerun: false, note: undefined, passedOnRerun: [] };
|
|
124
132
|
}
|
|
125
133
|
const label =
|
|
@@ -144,10 +152,12 @@ export async function runCheckWithRerun(
|
|
|
144
152
|
note: `${label} failed, passed on rerun${attempts > 1 ? ` ${attempts}` : ""}`,
|
|
145
153
|
};
|
|
146
154
|
}
|
|
155
|
+
const reason = dataOf(last.outcome).reason;
|
|
147
156
|
if (
|
|
148
157
|
last.hostError !== undefined ||
|
|
149
158
|
last.outcome?.result !== "fail" ||
|
|
150
|
-
|
|
159
|
+
reason === "timeout" ||
|
|
160
|
+
reason === "stall"
|
|
151
161
|
) {
|
|
152
162
|
break;
|
|
153
163
|
}
|
|
@@ -277,8 +287,10 @@ export async function runCheckCommands(
|
|
|
277
287
|
};
|
|
278
288
|
const finish = (
|
|
279
289
|
result: Pick<CheckRun, "outcome" | "hostError">,
|
|
290
|
+
aloneRerun = false,
|
|
280
291
|
): CheckRun => ({
|
|
281
292
|
...result,
|
|
293
|
+
...(aloneRerun ? { aloneRerun: true } : {}),
|
|
282
294
|
rerun: reran,
|
|
283
295
|
passedOnRerun: passed,
|
|
284
296
|
failedBy,
|
|
@@ -368,7 +380,7 @@ export async function runCheckCommands(
|
|
|
368
380
|
`the failed test "${name}" failed again when run alone`,
|
|
369
381
|
),
|
|
370
382
|
hostError: again.hostError,
|
|
371
|
-
});
|
|
383
|
+
}, again.hostError === undefined);
|
|
372
384
|
}
|
|
373
385
|
const note = describePass(passed);
|
|
374
386
|
if (note !== undefined) notes.push(note);
|
package/src/schedule.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The dev plugin's scheduler. The kernel calls `onTick`; this module decides
|
|
3
3
|
* which ready tasks start, which reviewed task auto merge answers, and when a
|
|
4
|
-
* plan is finished. Scheduling lives here, not in the kernel (
|
|
4
|
+
* plan is finished. Scheduling lives here, not in the kernel (ADR 0002 D1).
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { DEFAULT_POOL } from "@operad-io/pool";
|