mandrel 2.113.0 → 2.115.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 -0
- package/.agents/docs/configuration.md +11 -4
- package/.agents/schemas/agentrc.schema.json +13 -1
- package/.agents/scripts/acceptance-eval.js +2 -2
- package/.agents/scripts/ceremony-derive.js +15 -2
- package/.agents/scripts/lib/baselines/crap-preview-scan.js +15 -8
- package/.agents/scripts/lib/baselines/crap-preview-touched.js +140 -0
- package/.agents/scripts/lib/baselines/crap-prune.js +86 -0
- package/.agents/scripts/lib/baselines/duplication-scan-child.js +19 -0
- package/.agents/scripts/lib/baselines/duplication-scan-fork.js +76 -0
- package/.agents/scripts/lib/baselines/kinds/crap.js +12 -4
- package/.agents/scripts/lib/baselines/refresh-service.js +14 -15
- package/.agents/scripts/lib/baselines/seat-missing.js +1 -1
- package/.agents/scripts/lib/config/gates/coverage.schema.js +1 -1
- package/.agents/scripts/lib/config/gates/crap.schema.js +7 -0
- package/.agents/scripts/lib/config/gates/duplication.schema.js +7 -0
- package/.agents/scripts/lib/config/quality.js +3 -0
- package/.agents/scripts/lib/coverage-capture-delta.js +26 -3
- package/.agents/scripts/lib/coverage-capture-own-fix.js +35 -19
- package/.agents/scripts/lib/coverage-capture.js +62 -14
- package/.agents/scripts/lib/crap-engine.js +3 -5
- package/.agents/scripts/lib/crap-utils.js +12 -2
- package/.agents/scripts/lib/generated/agentrc-validator.js +2 -2
- package/.agents/scripts/lib/git-branch-lifecycle.js +2 -1
- package/.agents/scripts/lib/orchestration/handoff-gates.js +25 -8
- package/.agents/scripts/lib/orchestration/story-handoff.js +131 -41
- package/.agents/scripts/single-story-init.js +43 -5
- package/.agents/scripts/story-handoff.js +6 -2
- package/.agents/workflows/helpers/deliver-digest.md +3 -3
- package/.agents/workflows/helpers/deliver-reference.md +13 -4
- package/docs/CHANGELOG.md +20 -0
- package/package.json +1 -1
|
@@ -35,11 +35,8 @@ import { isScorableSourceFile } from '../source-extensions.js';
|
|
|
35
35
|
import { toPosix } from '../util/paths.js';
|
|
36
36
|
import { buildBundleSizeScorer } from './bundle-size-scorer.js';
|
|
37
37
|
import { decodeEnvelope } from './codec.js';
|
|
38
|
-
import {
|
|
39
|
-
|
|
40
|
-
resolveFormatExtensions,
|
|
41
|
-
scanDuplication,
|
|
42
|
-
} from './duplication-scanner.js';
|
|
38
|
+
import { runDuplicationScan } from './duplication-scan-fork.js';
|
|
39
|
+
import { resolveFormatExtensions } from './duplication-scanner.js';
|
|
43
40
|
import { checkBaselineAhead, getKindModule } from './kernel.js';
|
|
44
41
|
import { filterExcludedRows } from './kinds/maintainability.js';
|
|
45
42
|
import { canonicalizeBaselinePath } from './path-canon.js';
|
|
@@ -260,10 +257,10 @@ const KIND_SCORER_BUILDERS = Object.freeze({
|
|
|
260
257
|
* parallel implementation would report its own disagreement as drift.
|
|
261
258
|
*
|
|
262
259
|
* @param {string} kind
|
|
263
|
-
* @param {{ cwd: string }} opts
|
|
260
|
+
* @param {{ cwd: string, detect?: (opts: object) => Promise<object[]> }} opts
|
|
264
261
|
* @returns {((files: string[], opts: object) => Promise<object[]> | object[]) | undefined}
|
|
265
262
|
*/
|
|
266
|
-
export function resolveDefaultScorer(kind, { cwd } = {}) {
|
|
263
|
+
export function resolveDefaultScorer(kind, { cwd, detect } = {}) {
|
|
267
264
|
const builder = KIND_SCORER_BUILDERS[kind];
|
|
268
265
|
if (typeof builder !== 'function') return undefined;
|
|
269
266
|
const effectiveCwd = cwd ?? process.cwd();
|
|
@@ -273,7 +270,7 @@ export function resolveDefaultScorer(kind, { cwd } = {}) {
|
|
|
273
270
|
} catch {
|
|
274
271
|
quality = undefined;
|
|
275
272
|
}
|
|
276
|
-
return builder({ cwd: effectiveCwd, quality });
|
|
273
|
+
return builder({ cwd: effectiveCwd, quality, detect });
|
|
277
274
|
}
|
|
278
275
|
|
|
279
276
|
/** The CRAP stamp anchors where check-baselines does: target dirs + root. */
|
|
@@ -761,12 +758,14 @@ function buildDefaultDuplicationScorer({ cwd, config, quality, detect } = {}) {
|
|
|
761
758
|
: [];
|
|
762
759
|
return async (_files, opts) => {
|
|
763
760
|
const effectiveCwd = opts?.cwd ?? cwd ?? process.cwd();
|
|
764
|
-
return
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
761
|
+
return runDuplicationScan(
|
|
762
|
+
{
|
|
763
|
+
targetDirs,
|
|
764
|
+
cwd: effectiveCwd,
|
|
765
|
+
ignoreGlobs,
|
|
766
|
+
additionalFormats: dupCfg.additionalFormats,
|
|
767
|
+
},
|
|
768
|
+
{ detect, scanHeapMb: dupCfg.scanHeapMb },
|
|
769
|
+
);
|
|
771
770
|
};
|
|
772
771
|
}
|
|
@@ -153,7 +153,7 @@ function buildSeatedEnvelope({ kind, priorEnvelope, seated }) {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
/** A behind CRAP baseline needs a full re-seed; seating would mix semantics. */
|
|
156
|
-
function assertCrapPriorCurrent(kind, envelope) {
|
|
156
|
+
export function assertCrapPriorCurrent(kind, envelope) {
|
|
157
157
|
if (kind !== 'crap' || !envelope) return;
|
|
158
158
|
const stamp = envelope.scoringSemantics;
|
|
159
159
|
if (classifyScoringSemantics(stamp) !== 'behind') return;
|
|
@@ -128,7 +128,7 @@ export const COVERAGE_GATE = {
|
|
|
128
128
|
minimum: 0,
|
|
129
129
|
maximum: 50,
|
|
130
130
|
description:
|
|
131
|
-
"Opt-in own-fix delta refresh for `captureScope: affected`. `0` (default) keeps it off. `N >= 1` lets a delta that today's rule refuses for a Story overlap or a config file be re-measured as a delta when it splits, along HEAD's first-parent chain, into base-sync merges that pass today's rule and the Story's own non-merge commits touching at most `N` suite-input files, with no config file, no deleted or renamed suite input and no
|
|
131
|
+
"Opt-in own-fix delta refresh for `captureScope: affected`. `0` (default) keeps it off. `N >= 1` lets a delta that today's rule refuses for a Story overlap or a config file be re-measured as a delta when it splits, along HEAD's first-parent chain, into base-sync merges that pass today's rule and the Story's own non-merge commits touching at most `N` suite-input files, with no config file, no deleted or renamed suite input and no test file: a changed test moves the rows of sources mandrel cannot name, so it refuses the split. A red capture keeps the last green stamp for this split alone. Rows outside the delta can go stale in either direction; validate against full captures before raising it. `10` is a reasonable start.",
|
|
132
132
|
default: COVERAGE_GATE_DEFAULTS.ownFixDeltaMaxFiles,
|
|
133
133
|
},
|
|
134
134
|
},
|
|
@@ -49,6 +49,13 @@ export const CRAP_GATE = {
|
|
|
49
49
|
default: [...CRAP_GATE_DEFAULTS.ignoreGlobs],
|
|
50
50
|
},
|
|
51
51
|
incrementalCoverage: INCREMENTAL_COVERAGE_SCHEMA,
|
|
52
|
+
previewScope: {
|
|
53
|
+
type: 'string',
|
|
54
|
+
enum: ['file', 'touched-methods'],
|
|
55
|
+
description:
|
|
56
|
+
'What the CRAP preview judges in a changed file. `file` compares every method to its row. `touched-methods` compares only methods whose line range intersects a hunk of the diff against the base: other regressions print as informational rows and pass. New methods always face `newMethodCeiling`, and a method whose hunks cannot be read is judged.',
|
|
57
|
+
default: CRAP_GATE_DEFAULTS.previewScope,
|
|
58
|
+
},
|
|
52
59
|
coveragePath: {
|
|
53
60
|
type: ['string', 'null'],
|
|
54
61
|
minLength: 1,
|
|
@@ -29,6 +29,13 @@ export const DUPLICATION_GATE = {
|
|
|
29
29
|
'Extra jscpd format names (e.g. `python`, `go`) the duplication gate scans on top of the scorable formats it always reads. Extend-only: the scorable formats cannot be removed, and naming one here is a no-op. An unknown format name fails the scan rather than measuring nothing. The CRAP, MI, coverage and native-review gates still score only the scorable list (Story #5849).',
|
|
30
30
|
default: [],
|
|
31
31
|
},
|
|
32
|
+
scanHeapMb: {
|
|
33
|
+
type: 'integer',
|
|
34
|
+
minimum: 256,
|
|
35
|
+
description:
|
|
36
|
+
'V8 old-space limit, in MB, of the child process that runs the whole-tree duplication scan. The need grows with the scanned tree. It is a ceiling, not an allocation, and it reaches only that child.',
|
|
37
|
+
default: 4096,
|
|
38
|
+
},
|
|
32
39
|
ignoreGlobs: {
|
|
33
40
|
type: 'array',
|
|
34
41
|
items: { type: 'string', minLength: 1 },
|
|
@@ -58,6 +58,7 @@ export const CRAP_GATE_DEFAULTS = Object.freeze({
|
|
|
58
58
|
// Healthy runs resolve ~98%; a coordinate mismatch resolves 4–6%.
|
|
59
59
|
minMethodResolutionRate: 0.75,
|
|
60
60
|
incrementalCoverage: DEFAULT_INCREMENTAL_COVERAGE,
|
|
61
|
+
previewScope: 'file',
|
|
61
62
|
});
|
|
62
63
|
|
|
63
64
|
export const MAINTAINABILITY_GATE_DEFAULTS = Object.freeze({
|
|
@@ -86,6 +87,7 @@ const CRAP_GATE_KEYS = new Set([
|
|
|
86
87
|
'incrementalCoverage',
|
|
87
88
|
'coveragePath',
|
|
88
89
|
'captureScript',
|
|
90
|
+
'previewScope',
|
|
89
91
|
]);
|
|
90
92
|
|
|
91
93
|
const COVERAGE_GATE_KEYS = new Set([
|
|
@@ -260,6 +262,7 @@ export function resolveMaintainabilityCrap(userCrap, coverageGate) {
|
|
|
260
262
|
enabled: userCrap.enabled ?? defaults.enabled,
|
|
261
263
|
targetDirs: resolveListValue(defaults.targetDirs, userCrap.targetDirs),
|
|
262
264
|
newMethodCeiling: userCrap.newMethodCeiling ?? defaults.newMethodCeiling,
|
|
265
|
+
previewScope: userCrap.previewScope ?? defaults.previewScope,
|
|
263
266
|
...resolveCrapCoverageSource(userCrap, coverage),
|
|
264
267
|
tolerance: toleranceScalar(
|
|
265
268
|
userCrap.tolerance,
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
filterSuiteInputPaths,
|
|
17
17
|
stampIsStale,
|
|
18
18
|
} from './coverage-capture.js';
|
|
19
|
-
import { judgeOwnFix } from './coverage-capture-own-fix.js';
|
|
19
|
+
import { judgeOwnFix, supersededSeed } from './coverage-capture-own-fix.js';
|
|
20
20
|
import { gitSpawn } from './git-utils.js';
|
|
21
21
|
|
|
22
22
|
/** Basenames whose change moves coverage beyond the files it names. */
|
|
@@ -268,6 +268,8 @@ function canRestamp(rule, delta) {
|
|
|
268
268
|
return !delta.some(isCoverageConfigFile);
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
+
const OWN_FIX_ONLY = 'a red run left only the own-fix split';
|
|
272
|
+
|
|
271
273
|
/** Main's committed delta since the stamp, judged by the shared rule. */
|
|
272
274
|
function classifyCommittedDelta({
|
|
273
275
|
cwd,
|
|
@@ -318,8 +320,9 @@ function classifyDeltaRefresh({
|
|
|
318
320
|
gitSpawnImpl: spawn = gitSpawn,
|
|
319
321
|
readFileSync = fs.readFileSync,
|
|
320
322
|
computeContentDigestImpl = computeContentDigest,
|
|
323
|
+
readStamp = readCaptureStamp,
|
|
321
324
|
}) {
|
|
322
|
-
const stamp =
|
|
325
|
+
const stamp = readStamp(cwd, crap.coveragePath, { readFileSync });
|
|
323
326
|
const no = (reason) => ({ eligible: false, reason, stamp });
|
|
324
327
|
if (typeof stamp?.digest !== 'string') return no('no digest stamp');
|
|
325
328
|
if (!stampStale({ stamp, cwd, crap, computeContentDigestImpl }))
|
|
@@ -377,7 +380,7 @@ function reportPlan(plan, crap, logger) {
|
|
|
377
380
|
*
|
|
378
381
|
* @returns {{ baseRef: string, dropFiles: string[], runCaptureImpl?: () => Promise<number> } | null}
|
|
379
382
|
*/
|
|
380
|
-
|
|
383
|
+
function planFromStamp({
|
|
381
384
|
freshness,
|
|
382
385
|
crap,
|
|
383
386
|
coverage,
|
|
@@ -402,3 +405,23 @@ export function planDeltaRefresh({
|
|
|
402
405
|
);
|
|
403
406
|
return null;
|
|
404
407
|
}
|
|
408
|
+
|
|
409
|
+
/** A superseded stamp seeds the own-fix split and no other delta. */
|
|
410
|
+
function classifySuperseded(stamp, opts) {
|
|
411
|
+
const plan = classifyDeltaRefresh({ ...opts, readStamp: () => stamp });
|
|
412
|
+
if (!plan.eligible || plan.ownFix) return plan;
|
|
413
|
+
return { ...plan, eligible: false, reason: OWN_FIX_ONLY };
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** @see planFromStamp; after a red run the plan also names the prior to merge. */
|
|
417
|
+
export function planDeltaRefresh(opts) {
|
|
418
|
+
const seed = supersededSeed(opts);
|
|
419
|
+
if (!seed) return planFromStamp(opts);
|
|
420
|
+
const plan = planFromStamp({
|
|
421
|
+
...opts,
|
|
422
|
+
freshness: { reason: 'stale' },
|
|
423
|
+
prior: seed.prior,
|
|
424
|
+
classifyDeltaRefreshImpl: (o) => classifySuperseded(seed.stamp, o),
|
|
425
|
+
});
|
|
426
|
+
return plan && { ...plan, prior: seed.prior };
|
|
427
|
+
}
|
|
@@ -6,8 +6,14 @@
|
|
|
6
6
|
* eligible, and every uncertainty refuses.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import path from 'node:path';
|
|
9
11
|
import picomatch from 'picomatch';
|
|
10
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
filterSuiteInputPaths,
|
|
14
|
+
supersededArtifactPath,
|
|
15
|
+
supersededStampPath,
|
|
16
|
+
} from './coverage-capture.js';
|
|
11
17
|
|
|
12
18
|
const TEST_FILE_RE = /\.(test|spec)\.[cm]?[jt]sx?$/;
|
|
13
19
|
const TEST_DIR_RE = /(^|\/)(tests?|__tests__|spec|e2e)\//;
|
|
@@ -119,34 +125,21 @@ function judgeOwnChanges(ctx, own) {
|
|
|
119
125
|
return ctx.inputs(paths).filter((f) => ctx.delta.has(f));
|
|
120
126
|
}
|
|
121
127
|
|
|
122
|
-
/**
|
|
123
|
-
function
|
|
124
|
-
const
|
|
125
|
-
if (
|
|
126
|
-
const out = must(ctx, [
|
|
127
|
-
'diff',
|
|
128
|
-
'--numstat',
|
|
129
|
-
ctx.commit,
|
|
130
|
-
'HEAD',
|
|
131
|
-
'--',
|
|
132
|
-
...tests,
|
|
133
|
-
]);
|
|
134
|
-
for (const [added, deleted, file] of lines(out).map((l) => l.split('\t'))) {
|
|
135
|
-
if (added === '-' || Number(deleted) > Number(added)) {
|
|
136
|
-
refuse(`own part removes lines from test file ${file}`);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
128
|
+
/** Only the test graph knows which sources a changed test reaches. */
|
|
129
|
+
function refuseOwnTest(files) {
|
|
130
|
+
const test = files.find(isTestPath);
|
|
131
|
+
if (test) refuse(`own part changes test file ${test}`);
|
|
139
132
|
}
|
|
140
133
|
|
|
141
134
|
function judge(ctx, { base, own }) {
|
|
142
135
|
judgeBase(ctx, base);
|
|
143
136
|
const ownFiles = judgeOwnChanges(ctx, own);
|
|
137
|
+
refuseOwnTest(ownFiles);
|
|
144
138
|
if (ownFiles.length > ctx.max) {
|
|
145
139
|
refuse(
|
|
146
140
|
`own part has ${ownFiles.length} suite-input file(s), over ownFixDeltaMaxFiles ${ctx.max}`,
|
|
147
141
|
);
|
|
148
142
|
}
|
|
149
|
-
judgeOwnTests(ctx, ownFiles);
|
|
150
143
|
const baseFiles = ctx.inputs(base).filter((f) => ctx.delta.has(f));
|
|
151
144
|
return { own: ownFiles.length, base: baseFiles.length };
|
|
152
145
|
}
|
|
@@ -230,3 +223,26 @@ export function judgeOwnFix(opts) {
|
|
|
230
223
|
reportOwnFix(p, crap, logger, opts.formatFreshnessDetail);
|
|
231
224
|
return { ...plan, rule, stamp, ownFix: own, report };
|
|
232
225
|
}
|
|
226
|
+
|
|
227
|
+
function readJson(file) {
|
|
228
|
+
try {
|
|
229
|
+
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
230
|
+
} catch {
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** A copy still held aside means a dead capture left the artifact unusable. */
|
|
236
|
+
function readSupersededStamp(cwd, coveragePath) {
|
|
237
|
+
if (fs.existsSync(supersededArtifactPath(cwd, coveragePath))) return null;
|
|
238
|
+
return readJson(supersededStampPath(cwd, coveragePath));
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** The last green stamp and restored artifact a red run left, when usable. */
|
|
242
|
+
export function supersededSeed({ freshness, coverage, args, crap, changed }) {
|
|
243
|
+
if (freshness.reason !== 'unstamped' || !changed) return null;
|
|
244
|
+
if (!(coverage?.ownFixDeltaMaxFiles >= 1)) return null;
|
|
245
|
+
const stamp = readSupersededStamp(args.cwd, crap.coveragePath);
|
|
246
|
+
const prior = readJson(path.resolve(args.cwd, crap.coveragePath));
|
|
247
|
+
return stamp && prior ? { stamp, prior } : null;
|
|
248
|
+
}
|
|
@@ -675,13 +675,61 @@ export function anyChangedUnderTargets(changedFiles, targetDirs) {
|
|
|
675
675
|
return filterFilesUnderTargets(changedFiles, targetDirs).length > 0;
|
|
676
676
|
}
|
|
677
677
|
|
|
678
|
-
/**
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
678
|
+
/** The last green capture's stamp, while a later run has not gone green. */
|
|
679
|
+
export function supersededStampPath(cwd, coveragePath) {
|
|
680
|
+
return `${captureStampPath(cwd, coveragePath)}.superseded`;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/** The artifact held aside for the duration of a capture. */
|
|
684
|
+
export function supersededArtifactPath(cwd, coveragePath) {
|
|
685
|
+
return `${path.resolve(cwd, coveragePath)}.superseded`;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
function heldPaths({ cwd, coveragePath }) {
|
|
689
|
+
return {
|
|
690
|
+
stamp: captureStampPath(cwd, coveragePath),
|
|
691
|
+
held: supersededStampPath(cwd, coveragePath),
|
|
692
|
+
artifact: path.resolve(cwd, coveragePath),
|
|
693
|
+
copy: supersededArtifactPath(cwd, coveragePath),
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
function retireLiveStamp({ stamp, held, copy }) {
|
|
698
|
+
if (!fs.existsSync(stamp)) return;
|
|
699
|
+
fs.renameSync(stamp, held);
|
|
700
|
+
fs.rmSync(copy, { force: true });
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
/** A copy that outlived its capture is the good one; never overwrite it. */
|
|
704
|
+
function copyArtifactAside({ held, artifact, copy }) {
|
|
705
|
+
if (!fs.existsSync(held) || fs.existsSync(copy)) return;
|
|
706
|
+
if (fs.existsSync(artifact)) fs.copyFileSync(artifact, copy);
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
function discardHeld({ held, copy }) {
|
|
710
|
+
fs.rmSync(held, { force: true });
|
|
711
|
+
fs.rmSync(copy, { force: true });
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
/** Green discards what was held; anything else puts the artifact back. */
|
|
715
|
+
function settleHeld(paths, code) {
|
|
716
|
+
if (code === 0 || !fs.existsSync(paths.copy)) return discardHeld(paths);
|
|
717
|
+
fs.renameSync(paths.copy, paths.artifact);
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
/** Run with the last green stamp and artifact held aside. */
|
|
721
|
+
async function holdingLastGreen(opts, run) {
|
|
722
|
+
if (!opts.coveragePath) return run();
|
|
723
|
+
const paths = heldPaths(opts);
|
|
724
|
+
retireLiveStamp(paths);
|
|
725
|
+
copyArtifactAside(paths);
|
|
726
|
+
let code;
|
|
727
|
+
try {
|
|
728
|
+
code = await run();
|
|
729
|
+
return code;
|
|
730
|
+
} finally {
|
|
731
|
+
settleHeld(paths, code);
|
|
732
|
+
}
|
|
685
733
|
}
|
|
686
734
|
|
|
687
735
|
/** GNU `timeout(1)` code, so callers tell a hang (124) from failing tests. */
|
|
@@ -707,9 +755,9 @@ export const COVERAGE_HOST_RESOURCES_EXIT_CODE = 77;
|
|
|
707
755
|
* worker. Takes no positional file args: node's runner would execute a
|
|
708
756
|
* forwarded source file as a test instead of filtering the suite. Scope a
|
|
709
757
|
* run through `env` instead. Given `coveragePath`, the capture stamp is
|
|
710
|
-
*
|
|
711
|
-
*
|
|
712
|
-
*
|
|
758
|
+
* moved aside before the spawn: a red, killed or crashed run must leave no
|
|
759
|
+
* stamp vouching for the tree — only `stampCapturedTree` after a green run
|
|
760
|
+
* writes one — and gets the prior artifact back.
|
|
713
761
|
*
|
|
714
762
|
* @param {{
|
|
715
763
|
* cwd: string,
|
|
@@ -724,14 +772,13 @@ export const COVERAGE_HOST_RESOURCES_EXIT_CODE = 77;
|
|
|
724
772
|
* }} opts
|
|
725
773
|
* @returns {Promise<number>}
|
|
726
774
|
*/
|
|
727
|
-
export function runCapture(opts = {}) {
|
|
775
|
+
export async function runCapture(opts = {}) {
|
|
728
776
|
const { script = COVERAGE_CAPTURE_DEFAULTS.captureScript, log = () => {} } =
|
|
729
777
|
opts;
|
|
730
|
-
dropCaptureStamp(opts);
|
|
731
778
|
const [cmd, ...args] = packageScriptArgv(opts.cwd ?? process.cwd(), script);
|
|
732
779
|
const command = [cmd, ...args].join(' ');
|
|
733
780
|
log(`[coverage-capture] ▶ ${command}`);
|
|
734
|
-
|
|
781
|
+
const supervised = {
|
|
735
782
|
...opts,
|
|
736
783
|
cmd,
|
|
737
784
|
args,
|
|
@@ -739,7 +786,8 @@ export function runCapture(opts = {}) {
|
|
|
739
786
|
log(
|
|
740
787
|
`[coverage-capture] ⏱ ${command} exceeded ${opts.timeoutMs}ms — killed its process group. Returning exit ${COVERAGE_TIMEOUT_EXIT_CODE}.`,
|
|
741
788
|
),
|
|
742
|
-
}
|
|
789
|
+
};
|
|
790
|
+
return holdingLastGreen(opts, () => runSupervisedSuite(supervised));
|
|
743
791
|
}
|
|
744
792
|
|
|
745
793
|
/** @param {number} code */
|
|
@@ -86,18 +86,16 @@ export function methodRowsFromReport(report, coverageForFile, mapLine = null) {
|
|
|
86
86
|
mapLine,
|
|
87
87
|
);
|
|
88
88
|
const cyclomatic = m?.cyclomatic ?? 0;
|
|
89
|
+
const endLine = resolveEndLine(m?.lineEnd, mapLine);
|
|
89
90
|
const coverage =
|
|
90
91
|
coverageForFile && coordinateSystem === COORDINATE_ORIGINAL
|
|
91
|
-
? coverageForMethodInEntry(
|
|
92
|
-
coverageForFile,
|
|
93
|
-
startLine,
|
|
94
|
-
resolveEndLine(m?.lineEnd, mapLine),
|
|
95
|
-
)
|
|
92
|
+
? coverageForMethodInEntry(coverageForFile, startLine, endLine)
|
|
96
93
|
: null;
|
|
97
94
|
const crap = coverage === null ? null : crapFormula(cyclomatic, coverage);
|
|
98
95
|
rows.push({
|
|
99
96
|
...identities[i],
|
|
100
97
|
startLine,
|
|
98
|
+
...(endLine === undefined ? {} : { endLine }),
|
|
101
99
|
cyclomatic,
|
|
102
100
|
coverage,
|
|
103
101
|
crap,
|
|
@@ -270,6 +270,7 @@ function projectScanRow(relPath, mr) {
|
|
|
270
270
|
// `method` may be a derived anonymous identity.
|
|
271
271
|
anonymous: mr.anonymous === true,
|
|
272
272
|
startLine: mr.startLine,
|
|
273
|
+
...(mr.endLine === undefined ? {} : { endLine: mr.endLine }),
|
|
273
274
|
cyclomatic: mr.cyclomatic,
|
|
274
275
|
coverage: mr.coverage,
|
|
275
276
|
crap: mr.crap,
|
|
@@ -416,6 +417,15 @@ function compareScanRows(a, b) {
|
|
|
416
417
|
return 0;
|
|
417
418
|
}
|
|
418
419
|
|
|
420
|
+
/** A file's coverage entry; one with no ranges has no coordinates to join. */
|
|
421
|
+
function joinableCoverageEntry(coverage, relPath) {
|
|
422
|
+
const entry = findCoverageEntry(coverage, relPath);
|
|
423
|
+
const hasRanges =
|
|
424
|
+
Object.keys(entry?.fnMap ?? {}).length > 0 ||
|
|
425
|
+
Object.keys(entry?.statementMap ?? {}).length > 0;
|
|
426
|
+
return hasRanges ? entry : null;
|
|
427
|
+
}
|
|
428
|
+
|
|
419
429
|
/** In-process scorer; the reference the worker output must match exactly. */
|
|
420
430
|
function scoreFileSerial(
|
|
421
431
|
{
|
|
@@ -428,7 +438,7 @@ function scoreFileSerial(
|
|
|
428
438
|
},
|
|
429
439
|
coverage,
|
|
430
440
|
) {
|
|
431
|
-
const entry =
|
|
441
|
+
const entry = joinableCoverageEntry(coverage, relPath);
|
|
432
442
|
if (
|
|
433
443
|
shouldSkipFileForNoCoverage(requireCoverage, entry, touched, baselineByKey)
|
|
434
444
|
) {
|
|
@@ -474,7 +484,7 @@ async function scoreFilesViaPool(queue, coverage) {
|
|
|
474
484
|
// Send each worker only its file's entry, not the whole coverage map.
|
|
475
485
|
const enrichedQueue = queue.map((item) => ({
|
|
476
486
|
...item,
|
|
477
|
-
coverageEntry:
|
|
487
|
+
coverageEntry: joinableCoverageEntry(coverage, item.relPath),
|
|
478
488
|
}));
|
|
479
489
|
const results = await runOnPool(CRAP_WORKER_URL, enrichedQueue, {
|
|
480
490
|
workerData: {},
|