mandrel 2.85.0 → 2.87.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/.agents/docs/agentrc-reference.json +2 -1
- package/.agents/docs/configuration.md +36 -14
- package/.agents/schemas/agentrc.schema.json +48 -9
- package/.agents/scripts/coverage-capture.js +23 -3
- package/.agents/scripts/evidence-gate.js +2 -2
- package/.agents/scripts/lib/baselines/bundle-size-scorer.js +115 -0
- package/.agents/scripts/lib/baselines/coverage-updater-cli.js +129 -28
- package/.agents/scripts/lib/baselines/crap-updater-cli.js +31 -10
- package/.agents/scripts/lib/baselines/duplication-scanner.js +25 -1
- package/.agents/scripts/lib/baselines/refresh-service.js +55 -19
- package/.agents/scripts/lib/close-validation/process.js +6 -0
- package/.agents/scripts/lib/close-validation/runner.js +22 -6
- package/.agents/scripts/lib/config/gates/coverage.schema.js +1 -1
- package/.agents/scripts/lib/config/gates/shared.js +1 -1
- package/.agents/scripts/lib/config/quality.js +6 -2
- package/.agents/scripts/lib/config-settings-schema-delivery.js +41 -2
- package/.agents/scripts/lib/coverage-baseline.js +7 -6
- package/.agents/scripts/lib/coverage-capture.js +44 -0
- package/.agents/scripts/lib/full-suite-lock.js +98 -38
- package/.agents/scripts/lib/full-suite-queue.js +45 -18
- package/.agents/scripts/lib/generated/agentrc-validator.js +1 -1
- package/.agents/scripts/lib/observability/source-classifier.js +1 -0
- package/.agents/scripts/lib/orchestration/check-baselines/phases/evaluate.js +29 -2
- package/.agents/scripts/lib/orchestration/story-handoff.js +19 -1
- package/.agents/scripts/lib/suite-admission.js +410 -0
- package/.agents/scripts/update-bundle-size-baseline.js +56 -0
- package/.agents/scripts/update-coverage-baseline.js +16 -41
- package/.agents/scripts/update-duplication-baseline.js +13 -3
- package/docs/CHANGELOG.md +14 -0
- package/package.json +7 -1
|
@@ -7,10 +7,13 @@ import fs from 'node:fs';
|
|
|
7
7
|
import path from 'node:path';
|
|
8
8
|
import picomatch from 'picomatch';
|
|
9
9
|
import { write, writeFile } from './baselines/writer.js';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
captureStampPath,
|
|
12
|
+
missingCoverageArtifactMessage,
|
|
13
|
+
} from './coverage-capture.js';
|
|
11
14
|
|
|
12
15
|
const COVERAGE_FINAL_PATH = 'coverage/coverage-final.json';
|
|
13
|
-
|
|
16
|
+
const COVERAGE_BASELINE_PATH = 'baselines/coverage.json';
|
|
14
17
|
// Percentage points; baselines store two decimals.
|
|
15
18
|
export const COVERAGE_TOLERANCE = 0.01;
|
|
16
19
|
// One instrumentation event of slack per axis: V8 coverage flaps by a single
|
|
@@ -84,7 +87,7 @@ export function scoreCoverageFinal({ raw, cwd, scope }) {
|
|
|
84
87
|
return out;
|
|
85
88
|
}
|
|
86
89
|
|
|
87
|
-
/** Throws, naming the capture
|
|
90
|
+
/** Throws, naming the capture contract, when the artifact is missing. */
|
|
88
91
|
export function readCoverageFinal(cwd, opts = {}, fsImpl) {
|
|
89
92
|
const resolvedFs = fsImpl ?? fs;
|
|
90
93
|
const coveragePath =
|
|
@@ -95,9 +98,7 @@ export function readCoverageFinal(cwd, opts = {}, fsImpl) {
|
|
|
95
98
|
? coveragePath
|
|
96
99
|
: path.resolve(cwd, coveragePath);
|
|
97
100
|
if (!resolvedFs.existsSync(abs)) {
|
|
98
|
-
throw new Error(
|
|
99
|
-
`coverage-final.json not found at ${abs}. Run \`npm run test:coverage\` first.`,
|
|
100
|
-
);
|
|
101
|
+
throw new Error(missingCoverageArtifactMessage(abs));
|
|
101
102
|
}
|
|
102
103
|
return JSON.parse(resolvedFs.readFileSync(abs, 'utf8'));
|
|
103
104
|
}
|
|
@@ -478,6 +478,50 @@ export function creditedCapture(runCaptureFn, { requireCredited, logger }) {
|
|
|
478
478
|
};
|
|
479
479
|
}
|
|
480
480
|
|
|
481
|
+
/**
|
|
482
|
+
* The capture contract every coverage consumer leans on: `test:coverage`
|
|
483
|
+
* writes Istanbul per-file JSON at `coveragePath`. A summary-only reporter
|
|
484
|
+
* cannot feed the coverage or CRAP baselines (CRAP joins per-function maps).
|
|
485
|
+
*
|
|
486
|
+
* @param {string} abs Absolute artifact path that was looked for.
|
|
487
|
+
* @returns {string}
|
|
488
|
+
*/
|
|
489
|
+
export function missingCoverageArtifactMessage(abs) {
|
|
490
|
+
return (
|
|
491
|
+
`coverage artifact not found at ${abs}. \`npm run test:coverage\` must ` +
|
|
492
|
+
'write Istanbul per-file JSON (the `json` reporter → coverage-final.json) ' +
|
|
493
|
+
'at delivery.quality.gates.coverage.coveragePath; a `json-summary` ' +
|
|
494
|
+
'(coverage-summary.json) alone cannot feed the coverage or CRAP baselines.'
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Wrap a capture runner so a green run that left no artifact at
|
|
500
|
+
* `coveragePath` exits 1: a broken capture contract, not a capture. Every
|
|
501
|
+
* capture path already returns before stamping on a non-zero code.
|
|
502
|
+
*
|
|
503
|
+
* @param {(opts: object) => Promise<number>} run
|
|
504
|
+
* @param {{ cwd: string, coveragePath: string,
|
|
505
|
+
* existsSync?: (p: string) => boolean,
|
|
506
|
+
* logger: { error: Function } }} opts
|
|
507
|
+
* @returns {(opts: object) => Promise<number>}
|
|
508
|
+
*/
|
|
509
|
+
export function requireCaptureArtifact(
|
|
510
|
+
run,
|
|
511
|
+
{ cwd, coveragePath, existsSync = fs.existsSync, logger },
|
|
512
|
+
) {
|
|
513
|
+
return async (captureOpts) => {
|
|
514
|
+
const code = await run(captureOpts);
|
|
515
|
+
if (code !== 0) return code;
|
|
516
|
+
const abs = path.resolve(cwd, coveragePath);
|
|
517
|
+
if (existsSync(abs)) return 0;
|
|
518
|
+
logger.error(
|
|
519
|
+
`[coverage-capture] ✖ test:coverage passed but ${missingCoverageArtifactMessage(abs)}`,
|
|
520
|
+
);
|
|
521
|
+
return 1;
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
|
|
481
525
|
/**
|
|
482
526
|
* Stamp the pre-spawn digest (the tree the run measured), and write nothing
|
|
483
527
|
* when the post-run digest differs — the artifact then describes a tree no
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* full-suite-lock.js —
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* full-suite-lock.js — admit suite spawns across one repository's worktrees
|
|
3
|
+
* (they contend for cores and shared artifacts), over the `sweep-lock.js`
|
|
4
|
+
* primitive. An undeclared spawn runs exclusively; a declared one is admitted
|
|
5
|
+
* against a capacity budget by `suite-admission.js`.
|
|
5
6
|
*
|
|
6
7
|
* It queues, never overlaps: an expired wait behind a live holder spawns
|
|
7
8
|
* nothing ({@link LOCK_WAIT_EXPIRED_EXIT_CODE}). A dead holder is taken over
|
|
@@ -16,6 +17,17 @@ import { getQuality } from './config/quality.js';
|
|
|
16
17
|
import { mainCheckoutRoot } from './config/temp-paths.js';
|
|
17
18
|
import { isFirstInLine, waitInLine } from './full-suite-queue.js';
|
|
18
19
|
import { acquireSweepLock } from './single-story-sweep/sweep-lock.js';
|
|
20
|
+
import {
|
|
21
|
+
ADMISSION_REFUSED_EXIT_CODE,
|
|
22
|
+
completedProgress,
|
|
23
|
+
createAttempt,
|
|
24
|
+
describeRefusal,
|
|
25
|
+
FULL_SUITE_STALE_MS,
|
|
26
|
+
resolveAdmission,
|
|
27
|
+
resolveSuiteCapacity,
|
|
28
|
+
} from './suite-admission.js';
|
|
29
|
+
|
|
30
|
+
export { ADMISSION_REFUSED_EXIT_CODE };
|
|
19
31
|
|
|
20
32
|
/** Environment escape hatch: set to `0`/`false`/`off`/`no` to disable. */
|
|
21
33
|
export const FULL_SUITE_LOCK_ENV = 'MANDREL_FULL_SUITE_LOCK';
|
|
@@ -38,6 +50,9 @@ const FALSEY = /^(0|false|off|no)$/i;
|
|
|
38
50
|
|
|
39
51
|
const LOCK_TAG = '[full-suite-lock]';
|
|
40
52
|
|
|
53
|
+
/** The argv coverage capture spawns — its workload identity. */
|
|
54
|
+
const COVERAGE_CAPTURE_ARGV = Object.freeze(['npm', 'run', 'test:coverage']);
|
|
55
|
+
|
|
41
56
|
const LOCK_DEFAULTS = Object.freeze({
|
|
42
57
|
enabled: true,
|
|
43
58
|
log: () => {},
|
|
@@ -49,24 +64,26 @@ const LOCK_DEFAULTS = Object.freeze({
|
|
|
49
64
|
sleepFn: (ms) => defaultSleep(ms),
|
|
50
65
|
acquireOnceFn: (opts) => acquireSweepLock(opts),
|
|
51
66
|
onWaitExpired: () => LOCK_WAIT_EXPIRED_EXIT_CODE,
|
|
67
|
+
onAdmissionRefused: () => ADMISSION_REFUSED_EXIT_CODE,
|
|
68
|
+
workload: Object.freeze({ kind: 'exclusive' }),
|
|
69
|
+
capacity: resolveSuiteCapacity(),
|
|
52
70
|
onLockOutcome: () => {},
|
|
53
71
|
onLockProgress: () => {},
|
|
54
72
|
rerunCommand: 'the same command',
|
|
55
73
|
});
|
|
56
74
|
|
|
57
75
|
/**
|
|
58
|
-
* The one wait budget every
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* holder (heartbeating at a third of its own threshold) is never read stale.
|
|
76
|
+
* The one wait budget every lock taker uses: a holder's suite is killed at
|
|
77
|
+
* its supervisor's `killBoundMs` (the coverage gate's `timeoutMs`). Staleness
|
|
78
|
+
* is fixed, never derived from the waiter's budget — a waiter with a shorter
|
|
79
|
+
* budget than the holder's timeout must not read a live holder stale.
|
|
63
80
|
*
|
|
64
81
|
* @param {number} [killBoundMs]
|
|
65
82
|
* @returns {{ waitMs: number, staleMs: number }}
|
|
66
83
|
*/
|
|
67
84
|
export function resolveFullSuiteLockBudget(killBoundMs) {
|
|
68
85
|
const waitMs = Math.max(MIN_WAIT_MS, Number(killBoundMs) || 0);
|
|
69
|
-
return { waitMs, staleMs:
|
|
86
|
+
return { waitMs, staleMs: FULL_SUITE_STALE_MS };
|
|
70
87
|
}
|
|
71
88
|
|
|
72
89
|
/**
|
|
@@ -101,28 +118,34 @@ export function resolveFullSuiteLockPath({
|
|
|
101
118
|
/**
|
|
102
119
|
* Uncontended fast path, skipped when waiters are queued (no overtaking).
|
|
103
120
|
*
|
|
104
|
-
* @returns {{ lock: object|null, lockPath: string|null
|
|
105
|
-
* `lockPath` means wait;
|
|
121
|
+
* @returns {{ attempt: object|null, lock: object|null, lockPath: string|null,
|
|
122
|
+
* blocking?: object }} null `lock` with a `lockPath` means wait; a null
|
|
123
|
+
* `lockPath` means no lock.
|
|
106
124
|
*/
|
|
107
|
-
function beginLock(
|
|
108
|
-
const
|
|
109
|
-
if (
|
|
110
|
-
|
|
111
|
-
|
|
125
|
+
function beginLock(opts) {
|
|
126
|
+
const lockPath = lockHome(opts);
|
|
127
|
+
if (lockPath === null) return NO_LOCK;
|
|
128
|
+
const attempt = createAttempt({ ...opts, lockPath });
|
|
129
|
+
return { attempt, lockPath, ...firstTry(opts, attempt, lockPath) };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const NO_LOCK = Object.freeze({ attempt: null, lock: null, lockPath: null });
|
|
133
|
+
|
|
134
|
+
const QUEUED = Object.freeze({ reason: 'queue' });
|
|
135
|
+
|
|
136
|
+
function firstTry({ staleMs, fsImpl }, attempt, lockPath) {
|
|
137
|
+
if (!isFirstInLine({ lockPath, ticket: null, staleMs, fsImpl })) {
|
|
138
|
+
return { lock: null, blocking: QUEUED };
|
|
112
139
|
}
|
|
113
|
-
|
|
114
|
-
lockPath: resolved,
|
|
115
|
-
timeoutMs: staleMs,
|
|
116
|
-
fsImpl,
|
|
117
|
-
});
|
|
118
|
-
if (first.acquired) return { lock: first, lockPath: resolved };
|
|
119
|
-
// A hard I/O error will not resolve by waiting — proceed unserialized.
|
|
120
|
-
return first.reason === 'error'
|
|
121
|
-
? NO_LOCK
|
|
122
|
-
: { lock: null, lockPath: resolved };
|
|
140
|
+
return afterFirst(attempt.tryOnce());
|
|
123
141
|
}
|
|
124
142
|
|
|
125
|
-
|
|
143
|
+
/** A hard I/O error will not resolve by waiting — proceed unserialized. */
|
|
144
|
+
function afterFirst(first) {
|
|
145
|
+
if (first.acquired) return { lock: first };
|
|
146
|
+
if (first.reason === 'error') return { lock: null, lockPath: null };
|
|
147
|
+
return { lock: null, blocking: first.blocking };
|
|
148
|
+
}
|
|
126
149
|
|
|
127
150
|
/**
|
|
128
151
|
* @param {{ enabled: boolean, cwd: string, lockPath?: string }} where
|
|
@@ -179,19 +202,33 @@ function consult(probe, applies) {
|
|
|
179
202
|
*/
|
|
180
203
|
export async function withFullSuiteLockAsync(options, spawn) {
|
|
181
204
|
const opts = withDefaults(options);
|
|
182
|
-
|
|
183
|
-
const
|
|
184
|
-
lock === null && lockPath !== null
|
|
185
|
-
? await waitInLine({ ...opts, lockPath })
|
|
186
|
-
: { held: lock, expired: false, waited: false, waitedMs: 0 };
|
|
187
|
-
reportOutcome(opts.onLockOutcome, wait);
|
|
205
|
+
if (isRefused(opts)) return refuse(opts);
|
|
206
|
+
const begun = beginLock(opts);
|
|
188
207
|
try {
|
|
208
|
+
const wait = await awaitTurn(opts, begun);
|
|
209
|
+
reportOutcome(opts.onLockOutcome, wait);
|
|
189
210
|
return await spawnOrStandIn(opts, wait, spawn);
|
|
190
211
|
} finally {
|
|
191
|
-
|
|
212
|
+
begun.attempt?.release();
|
|
192
213
|
}
|
|
193
214
|
}
|
|
194
215
|
|
|
216
|
+
function isRefused({ enabled, workload }) {
|
|
217
|
+
return enabled && workload?.kind === 'refused';
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function refuse(opts) {
|
|
221
|
+
opts.log(describeRefusal(opts.workload));
|
|
222
|
+
return opts.onAdmissionRefused(opts.workload);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function awaitTurn(opts, { attempt, lock, lockPath, blocking }) {
|
|
226
|
+
if (lock !== null || lockPath === null) {
|
|
227
|
+
return { held: lock, expired: false, waited: false, waitedMs: 0 };
|
|
228
|
+
}
|
|
229
|
+
return waitInLine({ ...opts, lockPath, attempt, blocking });
|
|
230
|
+
}
|
|
231
|
+
|
|
195
232
|
/** An I/O-error wait is no outcome; a throwing callback never costs the spawn. */
|
|
196
233
|
function reportOutcome(onLockOutcome, wait) {
|
|
197
234
|
if (!isFinishedWait(wait)) return;
|
|
@@ -225,8 +262,23 @@ async function spawnOrStandIn(opts, wait, spawn) {
|
|
|
225
262
|
);
|
|
226
263
|
return probe.value;
|
|
227
264
|
}
|
|
228
|
-
|
|
229
|
-
|
|
265
|
+
return wait.expired
|
|
266
|
+
? opts.onWaitExpired(wait.holder)
|
|
267
|
+
: await timedSpawn(opts, wait, spawn);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** Wait and execution reach progress as separate figures. */
|
|
271
|
+
async function timedSpawn(opts, wait, spawn) {
|
|
272
|
+
const startedAt = opts.nowFn();
|
|
273
|
+
const result = await spawn({ lockWaitMs: wait.waitedMs ?? 0 });
|
|
274
|
+
if (wait.waited) reportCompleted(opts, wait, opts.nowFn() - startedAt);
|
|
275
|
+
return result;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function reportCompleted(opts, wait, ranMs) {
|
|
279
|
+
try {
|
|
280
|
+
opts.onLockProgress(completedProgress(wait.waitedMs, opts.waitMs, ranMs));
|
|
281
|
+
} catch {}
|
|
230
282
|
}
|
|
231
283
|
|
|
232
284
|
/**
|
|
@@ -240,14 +292,19 @@ function defaultSleep(ms) {
|
|
|
240
292
|
}
|
|
241
293
|
|
|
242
294
|
/**
|
|
295
|
+
* The one admission policy every caller resolves: enablement, budget,
|
|
296
|
+
* capacity, and the workload `argv` classifies to.
|
|
297
|
+
*
|
|
243
298
|
* @param {object} [config]
|
|
244
299
|
* @param {Record<string, string|undefined>} [env]
|
|
300
|
+
* @param {string[]} [argv]
|
|
245
301
|
*/
|
|
246
|
-
export function fullSuiteLockPolicy(config, env = process.env) {
|
|
302
|
+
export function fullSuiteLockPolicy(config, env = process.env, argv) {
|
|
247
303
|
return {
|
|
248
304
|
...resolveFullSuiteLockBudget(getQuality(config).coverage?.timeoutMs),
|
|
249
305
|
enabled: isFullSuiteLockEnabled({ config, env }),
|
|
250
306
|
onWaitExpired: () => LOCK_WAIT_EXPIRED_EXIT_CODE,
|
|
307
|
+
...resolveAdmission(config, argv),
|
|
251
308
|
};
|
|
252
309
|
}
|
|
253
310
|
|
|
@@ -267,7 +324,10 @@ export function lockedCapture(
|
|
|
267
324
|
env = process.env,
|
|
268
325
|
lockOptions = {},
|
|
269
326
|
) {
|
|
270
|
-
const policy = {
|
|
327
|
+
const policy = {
|
|
328
|
+
...fullSuiteLockPolicy(config, env, COVERAGE_CAPTURE_ARGV),
|
|
329
|
+
...lockOptions,
|
|
330
|
+
};
|
|
271
331
|
return (captureOpts = {}) =>
|
|
272
332
|
withFullSuiteLockAsync(
|
|
273
333
|
{
|
|
@@ -12,6 +12,12 @@ import {
|
|
|
12
12
|
isHolderAlive,
|
|
13
13
|
readLockHolderPid,
|
|
14
14
|
} from './single-story-sweep/sweep-lock.js';
|
|
15
|
+
import {
|
|
16
|
+
admissionWaitLine,
|
|
17
|
+
admittedLine,
|
|
18
|
+
blockingLabel,
|
|
19
|
+
publicBlocking,
|
|
20
|
+
} from './suite-admission.js';
|
|
15
21
|
|
|
16
22
|
const LOCK_TAG = '[full-suite-lock]';
|
|
17
23
|
|
|
@@ -177,9 +183,10 @@ function holderLabel(lockPath, fsImpl) {
|
|
|
177
183
|
|
|
178
184
|
/**
|
|
179
185
|
* @typedef {{
|
|
180
|
-
* phase: 'waiting'|'still-waiting'|'
|
|
186
|
+
* phase: 'waiting'|'still-waiting'|'admitted'|'completed'|'expired',
|
|
181
187
|
* waitedSeconds: number, waitBudgetSeconds: number,
|
|
182
|
-
* holder?: LockHolder, queueAhead?: number,
|
|
188
|
+
* holder?: LockHolder, queueAhead?: number, blocking?: object,
|
|
189
|
+
* waitMs?: number, executionMs?: number,
|
|
183
190
|
* }} LockProgress
|
|
184
191
|
*/
|
|
185
192
|
|
|
@@ -187,7 +194,8 @@ function holderLabel(lockPath, fsImpl) {
|
|
|
187
194
|
* @param {{
|
|
188
195
|
* lockPath: string, waitMs: number, pollMs: number, staleMs: number,
|
|
189
196
|
* reportMs: number, fsImpl: object, nowFn: () => number,
|
|
190
|
-
* sleepFn: (ms: number) => Promise<void>,
|
|
197
|
+
* sleepFn: (ms: number) => Promise<void>,
|
|
198
|
+
* attempt: { tryOnce: () => object }, workload?: object,
|
|
191
199
|
* log: (m: string) => void, rerunCommand: string,
|
|
192
200
|
* onLockProgress?: (progress: LockProgress) => void,
|
|
193
201
|
* }} opts A throwing `onLockProgress` is swallowed.
|
|
@@ -196,6 +204,7 @@ function holderLabel(lockPath, fsImpl) {
|
|
|
196
204
|
export async function waitInLine(opts) {
|
|
197
205
|
const { lockPath, fsImpl, nowFn } = opts;
|
|
198
206
|
const clock = waitClock(opts);
|
|
207
|
+
clock.blocking = opts.blocking ?? null;
|
|
199
208
|
announceWait(opts);
|
|
200
209
|
reportProgress(opts, clock, 'waiting', null);
|
|
201
210
|
const ticket = enqueueWaiter({ lockPath, nowFn, fsImpl });
|
|
@@ -225,25 +234,36 @@ function reportProgress(opts, clock, phase, ticket, knownHolder) {
|
|
|
225
234
|
phase,
|
|
226
235
|
waitedSeconds: clock.waited(),
|
|
227
236
|
waitBudgetSeconds: Math.round(Math.max(0, opts.waitMs) / 1000),
|
|
228
|
-
...(phase === '
|
|
237
|
+
...(phase === 'admitted'
|
|
238
|
+
? {}
|
|
239
|
+
: waitContext(opts, ticket, knownHolder, clock.blocking)),
|
|
229
240
|
});
|
|
230
241
|
} catch {}
|
|
231
242
|
}
|
|
232
243
|
|
|
233
|
-
/** Holder and
|
|
234
|
-
function waitContext(
|
|
235
|
-
const
|
|
244
|
+
/** Holder, queue position and what blocks admission, each when known. */
|
|
245
|
+
function waitContext(opts, ticket, known, blocking) {
|
|
246
|
+
const { lockPath, staleMs, fsImpl, nowFn } = opts;
|
|
247
|
+
const holder = known ?? waitHolder(opts, blocking);
|
|
236
248
|
const queueAhead = countAhead({ lockPath, ticket, staleMs, nowFn, fsImpl });
|
|
237
249
|
return {
|
|
238
250
|
...(holder.ownerId === null && holder.pid === null ? {} : { holder }),
|
|
239
251
|
...(queueAhead === null ? {} : { queueAhead }),
|
|
252
|
+
...publicBlocking(blocking, queueAhead),
|
|
240
253
|
};
|
|
241
254
|
}
|
|
242
255
|
|
|
243
|
-
function
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
256
|
+
function waitHolder({ lockPath, fsImpl, nowFn }, blocking) {
|
|
257
|
+
return blocking?.holder ?? readLockHolder(lockPath, { fsImpl, nowFn });
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function announceWait(opts) {
|
|
261
|
+
const line = admissionWaitLine(opts.workload, opts.blocking, opts.waitMs);
|
|
262
|
+
opts.log(line ?? exclusiveWaitLine(opts));
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function exclusiveWaitLine({ lockPath, waitMs, fsImpl }) {
|
|
266
|
+
return `${LOCK_TAG} ⏳ another full suite is already running on this host (${holderLabel(lockPath, fsImpl)}) — waiting up to ${Math.round(waitMs / 1000)}s for it to finish before spawning.`;
|
|
247
267
|
}
|
|
248
268
|
|
|
249
269
|
function giveUp(opts, clock) {
|
|
@@ -269,13 +289,12 @@ async function pollForTurn(opts, ticket, clock) {
|
|
|
269
289
|
await opts.sleepFn(Math.max(0, opts.pollMs));
|
|
270
290
|
refreshTicket(ticket, { nowFn, fsImpl });
|
|
271
291
|
const attempt = isFirstInLine({ lockPath, ticket, staleMs, nowFn, fsImpl })
|
|
272
|
-
? opts.
|
|
273
|
-
: { acquired: false };
|
|
292
|
+
? opts.attempt.tryOnce()
|
|
293
|
+
: { acquired: false, blocking: { reason: 'queue' } };
|
|
294
|
+
clock.blocking = attempt.blocking ?? null;
|
|
274
295
|
if (attempt.acquired) {
|
|
275
|
-
log(
|
|
276
|
-
|
|
277
|
-
);
|
|
278
|
-
reportProgress(opts, clock, 'acquired', ticket);
|
|
296
|
+
log(acquiredLine(opts.workload, clock.waited()));
|
|
297
|
+
reportProgress(opts, clock, 'admitted', ticket);
|
|
279
298
|
return { held: attempt, expired: false };
|
|
280
299
|
}
|
|
281
300
|
// A hard I/O error will not resolve by waiting; it is not an expiry.
|
|
@@ -285,11 +304,19 @@ async function pollForTurn(opts, ticket, clock) {
|
|
|
285
304
|
return null;
|
|
286
305
|
}
|
|
287
306
|
|
|
307
|
+
function acquiredLine(workload, waited) {
|
|
308
|
+
return (
|
|
309
|
+
admittedLine(workload, waited) ??
|
|
310
|
+
`${LOCK_TAG} ✅ acquired the full-suite lock (waited ${waited}s).`
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
288
314
|
function reportStillWaiting(opts, clock, ticket) {
|
|
289
315
|
const { lockPath, fsImpl, nowFn, log, reportMs } = opts;
|
|
290
316
|
if (nowFn() < clock.nextReport) return;
|
|
317
|
+
const reason = blockingLabel(clock.blocking) ?? holderLabel(lockPath, fsImpl);
|
|
291
318
|
log(
|
|
292
|
-
`${LOCK_TAG} ⏳ still waiting for the full-suite lock (${
|
|
319
|
+
`${LOCK_TAG} ⏳ still waiting for the full-suite lock (${reason}, waited ${clock.waited()}s).`,
|
|
293
320
|
);
|
|
294
321
|
reportProgress(opts, clock, 'still-waiting', ticket);
|
|
295
322
|
clock.nextReport += reportMs;
|