mandrel 2.110.0 → 2.112.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/agents/acceptance-critic.md +14 -0
- package/.agents/agents/auditor.md +14 -0
- package/.agents/agents/plan-critic.md +5 -0
- package/.agents/agents/story-worker.md +4 -1
- package/.agents/audit-checklists/state-machines.md +21 -0
- package/.agents/docs/agentrc-reference.json +23 -10
- package/.agents/docs/configuration.md +362 -15
- package/.agents/docs/execution-reference.md +11 -0
- package/.agents/docs/workflows.md +2 -1
- package/.agents/rules/ci-remediation.md +28 -4
- package/.agents/rules/git-conventions-reference.md +7 -0
- package/.agents/schemas/agentrc.schema.json +179 -13
- package/.agents/schemas/audit-rules.json +28 -0
- package/.agents/schemas/baselines/baseline-envelope.schema.json +16 -4
- package/.agents/schemas/baselines/bundle-size.schema.json +1 -0
- package/.agents/schemas/baselines/coverage.schema.json +1 -0
- package/.agents/schemas/baselines/crap.schema.json +37 -10
- package/.agents/schemas/baselines/duplication.schema.json +1 -0
- package/.agents/schemas/baselines/maintainability.schema.json +1 -0
- package/.agents/schemas/baselines/mutation.schema.json +1 -0
- package/.agents/schemas/crap-report.schema.json +6 -5
- package/.agents/schemas/story-deliver-terminal.schema.json +49 -3
- package/.agents/schemas/story-progress.schema.json +1 -1
- package/.agents/schemas/validation-evidence.schema.json +2 -2
- package/.agents/scripts/boot-sweep.js +41 -3
- package/.agents/scripts/coverage-capture.js +39 -3
- package/.agents/scripts/coverage-ratchet.js +106 -0
- package/.agents/scripts/evidence-gate.js +84 -21
- package/.agents/scripts/file-ci-gap.js +220 -10
- package/.agents/scripts/lib/audit-baselines/read.js +8 -1
- package/.agents/scripts/lib/audit-baselines/trend.js +2 -1
- package/.agents/scripts/lib/audit-to-stories/audit-lenses.js +1 -0
- package/.agents/scripts/lib/baseline-loader.js +4 -2
- package/.agents/scripts/lib/baselines/codec.js +57 -0
- package/.agents/scripts/lib/baselines/crap-preview-incremental.js +8 -3
- package/.agents/scripts/lib/baselines/crap-preview-scan.js +10 -16
- package/.agents/scripts/lib/baselines/crap-updater-cli.js +4 -13
- package/.agents/scripts/lib/baselines/kernel.js +19 -1
- package/.agents/scripts/lib/baselines/kinds/_crap-codec.js +171 -0
- package/.agents/scripts/lib/baselines/kinds/_crap-read.js +56 -16
- package/.agents/scripts/lib/baselines/kinds/_shared-metric.js +0 -59
- package/.agents/scripts/lib/baselines/kinds/crap.js +283 -319
- package/.agents/scripts/lib/baselines/preview-gates.js +29 -10
- package/.agents/scripts/lib/baselines/reader.js +36 -9
- package/.agents/scripts/lib/baselines/refresh-service.js +79 -18
- package/.agents/scripts/lib/baselines/seat-missing.js +173 -7
- package/.agents/scripts/lib/baselines/writer.js +36 -21
- package/.agents/scripts/lib/changed-files.js +70 -6
- package/.agents/scripts/lib/child-exec.js +10 -0
- package/.agents/scripts/lib/claude/agents-projection.js +5 -5
- package/.agents/scripts/lib/close-lock-events.js +8 -3
- package/.agents/scripts/lib/close-validation/ci-deferral.js +40 -0
- package/.agents/scripts/lib/close-validation/gates.js +156 -32
- package/.agents/scripts/lib/close-validation/process.js +16 -7
- package/.agents/scripts/lib/close-validation/projections/crap.js +43 -10
- package/.agents/scripts/lib/close-validation/runner.js +160 -41
- package/.agents/scripts/lib/close-validation/skip-branch-test.js +144 -0
- package/.agents/scripts/lib/close-validation/test-delta.js +33 -8
- package/.agents/scripts/lib/codex/agents-projection.js +6 -0
- package/.agents/scripts/lib/config/agentrc-overlay.js +9 -5
- package/.agents/scripts/lib/config/explain.js +5 -2
- package/.agents/scripts/lib/config/gates/coverage.schema.js +53 -0
- package/.agents/scripts/lib/config/gates/crap-incremental-coverage.schema.js +1 -1
- package/.agents/scripts/lib/config/git-roots.js +38 -4
- package/.agents/scripts/lib/config/handoff.js +24 -0
- package/.agents/scripts/lib/config/quality.js +28 -12
- package/.agents/scripts/lib/config/worktree-isolation.js +2 -5
- package/.agents/scripts/lib/config-resolver.js +22 -2
- package/.agents/scripts/lib/config-settings-schema-delivery.js +87 -4
- package/.agents/scripts/lib/config-settings-schema-quality.js +36 -1
- package/.agents/scripts/lib/config-settings-schema.js +1 -1
- package/.agents/scripts/lib/coverage-capture-affected.js +1 -0
- package/.agents/scripts/lib/coverage-capture-delta.js +164 -32
- package/.agents/scripts/lib/coverage-capture-own-fix.js +232 -0
- package/.agents/scripts/lib/coverage-capture-usage.js +2 -2
- package/.agents/scripts/lib/coverage-capture.js +31 -0
- package/.agents/scripts/lib/coverage-deferral.js +96 -0
- package/.agents/scripts/lib/coverage-ratchet.js +187 -0
- package/.agents/scripts/lib/crap-baseline-join.js +5 -5
- package/.agents/scripts/lib/crap-engine.js +3 -3
- package/.agents/scripts/lib/crap-method-identity.js +104 -48
- package/.agents/scripts/lib/escomplex-anchor.js +135 -0
- package/.agents/scripts/lib/escomplex-kernel.js +30 -1
- package/.agents/scripts/lib/failure-rows.js +121 -0
- package/.agents/scripts/lib/full-suite-lock.js +44 -4
- package/.agents/scripts/lib/full-suite-queue.js +89 -13
- package/.agents/scripts/lib/generated/agentrc-validator.js +8 -2
- package/.agents/scripts/lib/gh-env.js +3 -6
- package/.agents/scripts/lib/gh-pr-rest.js +1 -0
- package/.agents/scripts/lib/git/base-sync-probe.js +182 -0
- package/.agents/scripts/lib/git-branch-lifecycle.js +9 -0
- package/.agents/scripts/lib/observability/close-telemetry.js +37 -2
- package/.agents/scripts/lib/observability/handoff-telemetry.js +170 -0
- package/.agents/scripts/lib/observability/review-dispositions.js +23 -6
- package/.agents/scripts/lib/observability/runtime-friction.js +17 -4
- package/.agents/scripts/lib/observability/source-classifier.js +3 -0
- package/.agents/scripts/lib/observability/story-outcome.js +393 -0
- package/.agents/scripts/lib/orchestration/check-baselines/phases/compare.js +2 -1
- package/.agents/scripts/lib/orchestration/check-baselines/phases/evaluate.js +19 -1
- package/.agents/scripts/lib/orchestration/check-baselines/phases/fail-detail.js +84 -0
- package/.agents/scripts/lib/orchestration/check-baselines/phases/pipeline.js +14 -5
- package/.agents/scripts/lib/orchestration/check-baselines/phases/refresh-ack.js +3 -2
- package/.agents/scripts/lib/orchestration/check-baselines/phases/report.js +26 -6
- package/.agents/scripts/lib/orchestration/ci-rerun-guard.js +124 -23
- package/.agents/scripts/lib/orchestration/code-review.js +223 -19
- package/.agents/scripts/lib/orchestration/handoff-gates.js +217 -44
- package/.agents/scripts/lib/orchestration/handoff-rescore.js +169 -0
- package/.agents/scripts/lib/orchestration/handoff-suite-of-record.js +45 -0
- package/.agents/scripts/lib/orchestration/plan-persist/run-plan-persist.js +5 -1
- package/.agents/scripts/lib/orchestration/plan-persist/source-rewrite.js +76 -4
- package/.agents/scripts/lib/orchestration/plan-persist/story-ops.js +2 -2
- package/.agents/scripts/lib/orchestration/preflight-lanes.js +208 -0
- package/.agents/scripts/lib/orchestration/review-base-ref.js +40 -17
- package/.agents/scripts/lib/orchestration/review-deposit.js +38 -12
- package/.agents/scripts/lib/orchestration/review-depth.js +21 -0
- package/.agents/scripts/lib/orchestration/review-history.js +124 -20
- package/.agents/scripts/lib/orchestration/review-providers/claude-verdict.js +23 -8
- package/.agents/scripts/lib/orchestration/review-providers/code-review.js +82 -39
- package/.agents/scripts/lib/orchestration/review-providers/critical-verifier.js +64 -11
- package/.agents/scripts/lib/orchestration/review-providers/degraded-gates.js +98 -3
- package/.agents/scripts/lib/orchestration/review-providers/finding-identity.js +6 -2
- package/.agents/scripts/lib/orchestration/review-providers/findings-renderer.js +55 -8
- package/.agents/scripts/lib/orchestration/review-providers/review-guidance.js +1 -0
- package/.agents/scripts/lib/orchestration/review-providers/review-provider-factory.js +42 -15
- package/.agents/scripts/lib/orchestration/review-providers/types.js +6 -0
- package/.agents/scripts/lib/orchestration/single-story-close/failed-terminal.js +10 -1
- package/.agents/scripts/lib/orchestration/single-story-close/gate-log.js +10 -0
- package/.agents/scripts/lib/orchestration/single-story-close/phases/base-sync.js +7 -4
- package/.agents/scripts/lib/orchestration/single-story-close/phases/close-validation.js +17 -2
- package/.agents/scripts/lib/orchestration/single-story-close/phases/code-review.js +59 -2
- package/.agents/scripts/lib/orchestration/single-story-close/phases/confirm-merge.js +13 -1
- package/.agents/scripts/lib/orchestration/single-story-close/phases/finish.js +15 -4
- package/.agents/scripts/lib/orchestration/single-story-close/phases/land-review-record.js +213 -0
- package/.agents/scripts/lib/orchestration/single-story-close/phases/normalize-pr-title.js +17 -2
- package/.agents/scripts/lib/orchestration/single-story-close/phases/open-pr.js +42 -20
- package/.agents/scripts/lib/orchestration/single-story-close/phases/post-land.js +51 -26
- package/.agents/scripts/lib/orchestration/single-story-close/phases/pre-push.js +3 -1
- package/.agents/scripts/lib/orchestration/single-story-close/phases/pull-request.js +51 -15
- package/.agents/scripts/lib/orchestration/single-story-close/phases/push.js +59 -11
- package/.agents/scripts/lib/orchestration/single-story-close/phases/reconcile-done.js +1 -0
- package/.agents/scripts/lib/orchestration/single-story-close/phases/review-block.js +31 -13
- package/.agents/scripts/lib/orchestration/single-story-close/phases/review-halt.js +29 -6
- package/.agents/scripts/lib/orchestration/single-story-close/phases/review-outcome.js +10 -12
- package/.agents/scripts/lib/orchestration/single-story-close/phases/review-override.js +19 -4
- package/.agents/scripts/lib/orchestration/single-story-close/result.js +43 -13
- package/.agents/scripts/lib/orchestration/single-story-close/review-overlap.js +73 -39
- package/.agents/scripts/lib/orchestration/single-story-close/runner.js +11 -2
- package/.agents/scripts/lib/orchestration/story-close/baseline-upward-writeback.js +3 -2
- package/.agents/scripts/lib/orchestration/story-close/duplication-close-rescore.js +20 -8
- package/.agents/scripts/lib/orchestration/story-deliver-terminal.js +7 -0
- package/.agents/scripts/lib/orchestration/story-handoff.js +789 -196
- package/.agents/scripts/lib/orchestration/ticketing/reads.js +2 -0
- package/.agents/scripts/lib/pr-body-lines.js +32 -0
- package/.agents/scripts/lib/single-story/ci-ratchet-gate.js +140 -0
- package/.agents/scripts/lib/single-story/confirm-and-land.js +17 -7
- package/.agents/scripts/lib/single-story/confirm-merge.js +12 -3
- package/.agents/scripts/lib/single-story-sweep/report-stalled-executing.js +202 -0
- package/.agents/scripts/lib/standalone-ratchets.js +37 -0
- package/.agents/scripts/lib/suite-admission.js +20 -8
- package/.agents/scripts/lib/suite-sizing.js +146 -0
- package/.agents/scripts/lib/workspace-provisioner.js +2 -2
- package/.agents/scripts/merge-baseline.js +14 -3
- package/.agents/scripts/providers/github/comments.js +19 -3
- package/.agents/scripts/providers/github.js +1 -0
- package/.agents/scripts/review-dispositions-report.js +1 -1
- package/.agents/scripts/role-scope-guard.js +267 -0
- package/.agents/scripts/single-story-close.js +4 -4
- package/.agents/scripts/single-story-confirm-merge.js +31 -5
- package/.agents/scripts/single-story-init.js +24 -4
- package/.agents/scripts/story-handoff.js +3 -3
- package/.agents/scripts/story-outcomes-report.js +231 -0
- package/.agents/scripts/story-review-compute.js +9 -5
- package/.agents/scripts/update-coverage-baseline.js +12 -2
- package/.agents/scripts/update-crap-baseline.js +9 -1
- package/.agents/workflows/audit-state-machines.md +213 -0
- package/.agents/workflows/helpers/code-review.md +63 -9
- package/.agents/workflows/helpers/deliver-digest.md +53 -54
- package/.agents/workflows/helpers/deliver-reference.md +236 -63
- package/.agents/workflows/helpers/deliver-story-reference.md +19 -8
- package/.agents/workflows/helpers/deliver-story.md +7 -2
- package/.agents/workflows/helpers/parallel-tooling.md +29 -0
- package/.agents/workflows/helpers/plan-reference.md +10 -2
- package/docs/CHANGELOG.md +56 -0
- package/lib/cli/doctor-checks/coverage-ratchet.js +54 -0
- package/lib/cli/doctor-checks/effective-agentrc.js +23 -0
- package/lib/cli/doctor-checks/llm-review.js +2 -11
- package/lib/cli/doctor-checks/sync-parity.js +5 -1
- package/lib/cli/doctor-checks/test-credit-path.js +7 -2
- package/lib/cli/registry.js +5 -0
- package/package.json +1 -1
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Per-kind module for the CRAP baseline.
|
|
3
|
-
* `{ path, method,
|
|
2
|
+
* Per-kind module for the CRAP baseline. In-memory row shape:
|
|
3
|
+
* `{ path, method, crap }`; on disk the rows are grouped by path (see
|
|
4
|
+
* `_crap-codec.js`). `startLine` lives on scan rows only.
|
|
4
5
|
*/
|
|
5
6
|
|
|
6
7
|
import path from 'node:path';
|
|
7
8
|
import { fileURLToPath } from 'node:url';
|
|
8
9
|
import { COVERAGE_CAPTURE_DEFAULTS } from '../../config/gates/coverage.schema.js';
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
COORDINATE_TRANSPILED,
|
|
12
|
-
deriveFixGuidance,
|
|
13
|
-
} from '../../crap-engine.js';
|
|
14
|
-
import { isAnonymousMethodLabel } from '../../crap-method-identity.js';
|
|
10
|
+
import { deriveFixGuidance } from '../../crap-engine.js';
|
|
11
|
+
import { methodStem } from '../../crap-method-identity.js';
|
|
15
12
|
import { resolveEscomplexVersion } from '../../crap-utils.js';
|
|
16
13
|
import { Logger } from '../../Logger.js';
|
|
17
14
|
import { resolveTsTranspilerVersion } from '../../transpile.js';
|
|
@@ -22,15 +19,16 @@ import {
|
|
|
22
19
|
} from '../envelope.js';
|
|
23
20
|
import { canonicalise } from '../path-canon.js';
|
|
24
21
|
import { mergeRowsByScope } from '../scope.js';
|
|
22
|
+
import { compareCrapRows } from './_crap-codec.js';
|
|
25
23
|
import {
|
|
26
24
|
buildNewViolation,
|
|
27
25
|
deriveUncoveredFiles,
|
|
28
26
|
formatNewViolationMeasure,
|
|
29
27
|
newMethodGateScore,
|
|
30
28
|
} from './_crap-new-method-gate.js';
|
|
29
|
+
import { classifyScoringSemantics, SCORING_SEMANTICS } from './_crap-read.js';
|
|
31
30
|
import {
|
|
32
31
|
makeAggregate,
|
|
33
|
-
makeCompare,
|
|
34
32
|
makeEpsilon,
|
|
35
33
|
makeRollup,
|
|
36
34
|
percentile,
|
|
@@ -39,7 +37,7 @@ import {
|
|
|
39
37
|
export const name = 'crap';
|
|
40
38
|
export const keyField = 'path';
|
|
41
39
|
|
|
42
|
-
export { loadCrapBaseline } from './_crap-read.js';
|
|
40
|
+
export { aheadStampOf, loadCrapBaseline } from './_crap-read.js';
|
|
43
41
|
|
|
44
42
|
const __filename = fileURLToPath(import.meta.url);
|
|
45
43
|
|
|
@@ -55,75 +53,34 @@ export function kernelVersion() {
|
|
|
55
53
|
return resolveEscomplexVersion(path.dirname(__filename));
|
|
56
54
|
}
|
|
57
55
|
|
|
58
|
-
/**
|
|
59
|
-
* Scoring-semantics stamp. The scorer version does not move when this repo's
|
|
60
|
-
* coverage join changes, yet rows scored under different joins are not
|
|
61
|
-
* comparable (phantom regressions and phantom passes), so the stamp fails
|
|
62
|
-
* closed across that boundary. Bump it whenever the coverage join, the line
|
|
63
|
-
* coordinate system, the unresolved-method policy, or the method identity
|
|
64
|
-
* rule changes. Module-local: read it via `envelopeExtras().scoringSemantics`.
|
|
65
|
-
*/
|
|
66
|
-
const SCORING_SEMANTICS = 'method-identity-v3';
|
|
67
|
-
|
|
68
56
|
/**
|
|
69
57
|
* Envelope stamps this kind adds, consumed by `writer.write`. A transpiler
|
|
70
|
-
* change can
|
|
71
|
-
* `tsTranspilerVersion` is stamped for the `ts-transpiler-drift` axis.
|
|
72
|
-
* `
|
|
73
|
-
*
|
|
74
|
-
* `cwd` / `targetDirs` so the stamp names the compiler the scorer resolved.
|
|
58
|
+
* change can rename or re-nest emitted methods, which moves scope-path keys,
|
|
59
|
+
* so `tsTranspilerVersion` is stamped for the `ts-transpiler-drift` axis.
|
|
60
|
+
* `ctx` carries the scan's `cwd` / `targetDirs` so the stamp names the
|
|
61
|
+
* compiler the scorer resolved.
|
|
75
62
|
*
|
|
76
63
|
* @param {{ cwd?: string, targetDirs?: string[] }} [ctx]
|
|
77
|
-
* @returns {{scoringSemantics: string, tsTranspilerVersion: string
|
|
78
|
-
* provenanceStamped: boolean}}
|
|
64
|
+
* @returns {{scoringSemantics: string, tsTranspilerVersion: string}}
|
|
79
65
|
*/
|
|
80
66
|
export function envelopeExtras(ctx = {}) {
|
|
81
67
|
return {
|
|
82
68
|
scoringSemantics: SCORING_SEMANTICS,
|
|
83
69
|
tsTranspilerVersion: resolveTsTranspilerVersion(ctx),
|
|
84
|
-
provenanceStamped: true,
|
|
85
70
|
};
|
|
86
71
|
}
|
|
87
72
|
|
|
88
|
-
/**
|
|
89
|
-
* Project a scan row onto the persisted row shape. `coordinateSystem` and
|
|
90
|
-
* `anonymous` are written only when non-default, so a plain JS row stays the
|
|
91
|
-
* four-key row and existing baselines stay byte-identical.
|
|
92
|
-
*/
|
|
73
|
+
/** Project a scan row onto the persisted row shape. */
|
|
93
74
|
export function projectRow(row) {
|
|
94
|
-
|
|
75
|
+
return {
|
|
95
76
|
path: canonicalise(row.path ?? row.file),
|
|
96
77
|
method: row.method,
|
|
97
|
-
startLine: row.startLine,
|
|
98
78
|
crap: row.crap,
|
|
99
79
|
};
|
|
100
|
-
if (row.coordinateSystem === COORDINATE_TRANSPILED) {
|
|
101
|
-
projected.coordinateSystem = COORDINATE_TRANSPILED;
|
|
102
|
-
}
|
|
103
|
-
// `anonymous`: `method` is a derived scope-path identity, not a source name.
|
|
104
|
-
if (row.anonymous === true) {
|
|
105
|
-
projected.anonymous = true;
|
|
106
|
-
}
|
|
107
|
-
return projected;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* A row's coordinate provenance. An unstamped row is always an
|
|
112
|
-
* original-source coordinate, so the default is sound, not a guess.
|
|
113
|
-
*
|
|
114
|
-
* @param {{coordinateSystem?: string}|null|undefined} row
|
|
115
|
-
* @returns {string}
|
|
116
|
-
*/
|
|
117
|
-
function coordinateSystemOf(row) {
|
|
118
|
-
return row?.coordinateSystem ?? COORDINATE_ORIGINAL;
|
|
119
80
|
}
|
|
120
81
|
|
|
121
82
|
export function sortRows(rows) {
|
|
122
|
-
return [...rows].sort(
|
|
123
|
-
if (a.path !== b.path) return a.path.localeCompare(b.path);
|
|
124
|
-
if (a.startLine !== b.startLine) return a.startLine - b.startLine;
|
|
125
|
-
return a.method.localeCompare(b.method);
|
|
126
|
-
});
|
|
83
|
+
return [...rows].sort(compareCrapRows);
|
|
127
84
|
}
|
|
128
85
|
|
|
129
86
|
export { percentile };
|
|
@@ -144,35 +101,95 @@ const aggregate = makeAggregate({
|
|
|
144
101
|
export const rollup = makeRollup({ aggregate });
|
|
145
102
|
|
|
146
103
|
/**
|
|
147
|
-
* Pure compare(head, base)
|
|
148
|
-
*
|
|
149
|
-
*
|
|
104
|
+
* Pure compare(head, base); higher CRAP is worse. Rows pair through
|
|
105
|
+
* {@link compareCrap}'s stem-bucket alignment, so an inserted namesake does
|
|
106
|
+
* not mis-pair its siblings by ordinal. New methods are `additions`.
|
|
150
107
|
*/
|
|
151
|
-
export
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
108
|
+
export function compare(head, base) {
|
|
109
|
+
const headRows = rowsOf(head);
|
|
110
|
+
const baseRows = rowsOf(base);
|
|
111
|
+
const pairs = pairByStem(headRows, baseRows);
|
|
112
|
+
const out = {
|
|
113
|
+
regressions: [],
|
|
114
|
+
improvements: [],
|
|
115
|
+
unchanged: [],
|
|
116
|
+
additions: [],
|
|
117
|
+
};
|
|
118
|
+
for (const row of headRows) binHeadRow(out, row, pairs.get(row));
|
|
119
|
+
const claimed = new Set(pairs.values());
|
|
120
|
+
for (const b of baseRows) {
|
|
121
|
+
if (!claimed.has(b)) binRemovedRow(out, b);
|
|
122
|
+
}
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function rowsOf(snapshot) {
|
|
127
|
+
return Array.isArray(snapshot?.rows) ? snapshot.rows : [];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Head rows grouped with base rows by `[path, method stem]`. */
|
|
131
|
+
function stemBuckets(headRows, baseRows) {
|
|
132
|
+
const buckets = new Map();
|
|
133
|
+
const bucketOf = (r) => {
|
|
134
|
+
const key = JSON.stringify([r.path, methodStem(r.method)]);
|
|
135
|
+
if (!buckets.has(key)) buckets.set(key, { cur: [], base: [] });
|
|
136
|
+
return buckets.get(key);
|
|
137
|
+
};
|
|
138
|
+
for (const b of baseRows) bucketOf(b).base.push(b);
|
|
139
|
+
for (const row of headRows) bucketOf(row).cur.push({ row });
|
|
140
|
+
return buckets.values();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function pairByStem(headRows, baseRows) {
|
|
144
|
+
const pairs = new Map();
|
|
145
|
+
for (const { cur, base } of stemBuckets(headRows, baseRows)) {
|
|
146
|
+
const curSorted = cur.sort((a, b) => byKeyOrder(a.row, b.row));
|
|
147
|
+
for (const [e, b] of pairBucket(curSorted, base, 0)) pairs.set(e.row, b);
|
|
148
|
+
}
|
|
149
|
+
return pairs;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function binHeadRow(out, row, b) {
|
|
153
|
+
const key = rowIdentity(row);
|
|
154
|
+
if (!b) {
|
|
155
|
+
out.additions.push({ key, head: row, base: null });
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
out[deltaBin((row.crap ?? 0) - (b.crap ?? 0))].push({
|
|
159
|
+
key,
|
|
160
|
+
head: row,
|
|
161
|
+
base: b,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function deltaBin(delta) {
|
|
166
|
+
if (delta > 0) return 'regressions';
|
|
167
|
+
return delta < 0 ? 'improvements' : 'unchanged';
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** A removed base row is an improvement only when it carried CRAP. */
|
|
171
|
+
function binRemovedRow(out, b) {
|
|
172
|
+
const bin = (b.crap ?? 0) > 0 ? 'improvements' : 'unchanged';
|
|
173
|
+
out[bin].push({ key: rowIdentity(b), head: null, base: b });
|
|
174
|
+
}
|
|
158
175
|
|
|
159
176
|
/**
|
|
160
177
|
* Canonical row identity. Distinct from `keyField` (`'path'`, the rollup
|
|
161
178
|
* grouping): a file has one row per method, so keying a merge on `keyField`
|
|
162
179
|
* would collapse them.
|
|
163
180
|
*
|
|
164
|
-
* @param {{path: string, method: string
|
|
181
|
+
* @param {{path: string, method: string}} row
|
|
165
182
|
* @returns {string}
|
|
166
183
|
*/
|
|
167
184
|
export function rowIdentity(row) {
|
|
168
|
-
return `${row.path}::${row.method}
|
|
185
|
+
return `${row.path}::${row.method}`;
|
|
169
186
|
}
|
|
170
187
|
|
|
171
188
|
/**
|
|
172
189
|
* Sub-epsilon CRAP deltas resolve to the prior row bytes.
|
|
173
190
|
*
|
|
174
|
-
* @param {Array<{path: string, method: string,
|
|
175
|
-
* @param {Array<{path: string, method: string,
|
|
191
|
+
* @param {Array<{path: string, method: string, crap: number}>} prior
|
|
192
|
+
* @param {Array<{path: string, method: string, crap: number}>} regenerated
|
|
176
193
|
* @param {number} epsilon non-negative absolute tolerance on CRAP
|
|
177
194
|
* @returns {Array<object>}
|
|
178
195
|
*/
|
|
@@ -185,8 +202,8 @@ export const applyEpsilon = makeEpsilon({
|
|
|
185
202
|
* Scope-aware merge: identity is per method, but scope filters on `path`
|
|
186
203
|
* alone (a diff names files), so out-of-scope files keep every prior row.
|
|
187
204
|
*
|
|
188
|
-
* @param {Array<{path: string, method: string,
|
|
189
|
-
* @param {Array<{path: string, method: string,
|
|
205
|
+
* @param {Array<{path: string, method: string, crap: number}>} prior
|
|
206
|
+
* @param {Array<{path: string, method: string, crap: number}>} regenerated
|
|
190
207
|
* @param {{mode: 'full'|'diff', files: Set<string>}|null|undefined} scope
|
|
191
208
|
* @returns {Array<object>}
|
|
192
209
|
*/
|
|
@@ -223,7 +240,7 @@ export function filterRowsByFileScope(rows, scopeSet) {
|
|
|
223
240
|
* regression would add branches and lose the exemption anyway.
|
|
224
241
|
*
|
|
225
242
|
* @param {{cyclomatic: number, crap: number}} row
|
|
226
|
-
* @param {{crap: number,
|
|
243
|
+
* @param {{crap: number, method: string}} baseline
|
|
227
244
|
* @param {number} tolerance
|
|
228
245
|
* @param {'regression'|'drifted-regression'} kind
|
|
229
246
|
* @returns {object | null}
|
|
@@ -235,23 +252,19 @@ export function checkCrapRegression(row, baseline, tolerance, kind) {
|
|
|
235
252
|
...row,
|
|
236
253
|
kind,
|
|
237
254
|
baseline: baseline.crap,
|
|
238
|
-
|
|
255
|
+
baselineMethod: baseline.method,
|
|
239
256
|
};
|
|
240
257
|
}
|
|
241
258
|
|
|
242
259
|
/**
|
|
243
|
-
* Compare scanned rows to baseline rows.
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
* `provenanceMismatched` counts any row with at least one mismatched
|
|
252
|
-
* candidate, captured before the filter discards that evidence — it feeds the
|
|
253
|
-
* unsound-basis backstop. Unscorable rows (null crap/coverage) are bucketed
|
|
254
|
-
* and excluded from `comparable` so they cannot dilute a ratio.
|
|
260
|
+
* Compare scanned rows to baseline rows. Both sides bucket by (file, stem) —
|
|
261
|
+
* the key with every `#<n>` stripped — and align in order inside a bucket
|
|
262
|
+
* (see {@link alignBucket}): an exact key pairs first, so an unchanged method
|
|
263
|
+
* is a plain comparison; an insert, remove or reorder re-pairs its namesakes
|
|
264
|
+
* (`drifted`) instead of reporting them new and removed. Unpaired current
|
|
265
|
+
* rows face the new-method ceiling; unpaired baseline rows are `removed`.
|
|
266
|
+
* Unscorable rows (null crap/coverage) are bucketed and excluded from
|
|
267
|
+
* `comparable` so they cannot dilute a ratio.
|
|
255
268
|
*/
|
|
256
269
|
export function compareCrap({
|
|
257
270
|
currentRows,
|
|
@@ -259,207 +272,205 @@ export function compareCrap({
|
|
|
259
272
|
newMethodCeiling,
|
|
260
273
|
tolerance,
|
|
261
274
|
}) {
|
|
262
|
-
const
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
const
|
|
274
|
-
const
|
|
275
|
+
const rows = currentRows ?? [];
|
|
276
|
+
const state = {
|
|
277
|
+
uncoveredFiles: deriveUncoveredFiles(currentRows),
|
|
278
|
+
newMethodCeiling,
|
|
279
|
+
tolerance: Number.isFinite(tolerance) ? tolerance : 0,
|
|
280
|
+
claimed: new Set(),
|
|
281
|
+
verdicts: new Array(rows.length).fill(null),
|
|
282
|
+
regressions: 0,
|
|
283
|
+
newViolations: 0,
|
|
284
|
+
drifted: 0,
|
|
285
|
+
};
|
|
286
|
+
const buckets = new Map();
|
|
287
|
+
const bucketOf = (file, method) => {
|
|
288
|
+
const key = JSON.stringify([file, methodStem(method)]);
|
|
289
|
+
if (!buckets.has(key)) buckets.set(key, { cur: [], base: [] });
|
|
290
|
+
return buckets.get(key);
|
|
291
|
+
};
|
|
292
|
+
for (const b of baselineRows ?? []) bucketOf(b.file, b.method).base.push(b);
|
|
275
293
|
const unscorableRows = [];
|
|
276
|
-
|
|
277
|
-
let newViolations = 0;
|
|
278
|
-
let drifted = 0;
|
|
279
|
-
let provenanceMismatched = 0;
|
|
280
|
-
|
|
281
|
-
for (const row of currentRows ?? []) {
|
|
294
|
+
for (const [idx, row] of rows.entries()) {
|
|
282
295
|
if (isUnscorableRow(row)) {
|
|
283
296
|
unscorableRows.push({ ...row, kind: 'unscorable' });
|
|
284
297
|
continue;
|
|
285
298
|
}
|
|
286
|
-
|
|
287
|
-
const methodKey = `${row.file}::${row.method}`;
|
|
288
|
-
const rowCoords = coordinateSystemOf(row);
|
|
289
|
-
const candidates = methodIndex.get(methodKey) ?? [];
|
|
290
|
-
if (candidates.some((c) => coordinateSystemOf(c) !== rowCoords)) {
|
|
291
|
-
provenanceMismatched += 1;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
const exact = exactIndex.get(exactKey);
|
|
295
|
-
if (exact && coordinateSystemOf(exact) === rowCoords) {
|
|
296
|
-
seenBaselineKeys.add(exactKey);
|
|
297
|
-
const v = checkCrapRegression(row, exact, tolerance, 'regression');
|
|
298
|
-
if (v) {
|
|
299
|
-
regressions += 1;
|
|
300
|
-
violations.push(v);
|
|
301
|
-
}
|
|
302
|
-
continue;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
if (candidates.length > 0) {
|
|
306
|
-
const comparable = candidates.filter(
|
|
307
|
-
(c) => coordinateSystemOf(c) === rowCoords,
|
|
308
|
-
);
|
|
309
|
-
if (comparable.length === 0) {
|
|
310
|
-
incomparableRows.push({
|
|
311
|
-
...row,
|
|
312
|
-
kind: 'incomparable',
|
|
313
|
-
coordinateSystem: rowCoords,
|
|
314
|
-
baselineCoordinateSystem: coordinateSystemOf(candidates[0]),
|
|
315
|
-
});
|
|
316
|
-
for (const c of candidates) {
|
|
317
|
-
seenBaselineKeys.add(`${c.file}::${c.method}@${c.startLine}`);
|
|
318
|
-
}
|
|
319
|
-
continue;
|
|
320
|
-
}
|
|
321
|
-
const pick = pickDriftCandidate(comparable, row, seenBaselineKeys);
|
|
322
|
-
seenBaselineKeys.add(`${pick.file}::${pick.method}@${pick.startLine}`);
|
|
323
|
-
drifted += 1;
|
|
324
|
-
const v = checkCrapRegression(row, pick, tolerance, 'drifted-regression');
|
|
325
|
-
if (v) {
|
|
326
|
-
regressions += 1;
|
|
327
|
-
violations.push(v);
|
|
328
|
-
}
|
|
329
|
-
continue;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
const gateScore = newMethodGateScore(row, uncoveredFiles);
|
|
333
|
-
if (gateScore > newMethodCeiling + tolerance) {
|
|
334
|
-
newViolations += 1;
|
|
335
|
-
violations.push(buildNewViolation(row, newMethodCeiling, gateScore));
|
|
336
|
-
}
|
|
299
|
+
bucketOf(row.file, row.method).cur.push({ idx, row });
|
|
337
300
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
for (const b of baselineRows ?? []) {
|
|
341
|
-
const k = `${b.file}::${b.method}@${b.startLine}`;
|
|
342
|
-
if (!seenBaselineKeys.has(k)) removedRows.push(b);
|
|
301
|
+
for (const { cur, base } of buckets.values()) {
|
|
302
|
+
if (cur.length > 0) alignBucket(state, cur, base);
|
|
343
303
|
}
|
|
344
304
|
|
|
345
|
-
const
|
|
305
|
+
const removedRows = (baselineRows ?? []).filter((b) => !state.claimed.has(b));
|
|
306
|
+
const total = rows.length;
|
|
346
307
|
return {
|
|
347
308
|
total,
|
|
348
309
|
// Denominator of every ratio derived from this result.
|
|
349
310
|
comparable: total - unscorableRows.length,
|
|
350
|
-
regressions,
|
|
351
|
-
newViolations,
|
|
352
|
-
drifted,
|
|
353
|
-
provenanceMismatched,
|
|
354
|
-
incomparable: incomparableRows.length,
|
|
311
|
+
regressions: state.regressions,
|
|
312
|
+
newViolations: state.newViolations,
|
|
313
|
+
drifted: state.drifted,
|
|
355
314
|
unscorable: unscorableRows.length,
|
|
356
315
|
removed: removedRows.length,
|
|
357
|
-
violations,
|
|
358
|
-
incomparableRows,
|
|
316
|
+
violations: state.verdicts.filter((v) => v !== null),
|
|
359
317
|
unscorableRows,
|
|
360
318
|
removedRows,
|
|
361
319
|
};
|
|
362
320
|
}
|
|
363
321
|
|
|
322
|
+
/** Score one (current, baseline) pair into the verdict slot `idx`. */
|
|
323
|
+
function scorePair(state, idx, row, baseline, kind) {
|
|
324
|
+
const v = checkCrapRegression(row, baseline, state.tolerance, kind);
|
|
325
|
+
if (v) {
|
|
326
|
+
state.regressions += 1;
|
|
327
|
+
state.verdicts[idx] = v;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/** A current row with no baseline row: the new-method ceiling. */
|
|
332
|
+
function scoreNewMethod(state, idx, row) {
|
|
333
|
+
const gateScore = newMethodGateScore(row, state.uncoveredFiles);
|
|
334
|
+
if (gateScore > state.newMethodCeiling + state.tolerance) {
|
|
335
|
+
state.newViolations += 1;
|
|
336
|
+
state.verdicts[idx] = buildNewViolation(
|
|
337
|
+
row,
|
|
338
|
+
state.newMethodCeiling,
|
|
339
|
+
gateScore,
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
364
344
|
/**
|
|
365
|
-
*
|
|
366
|
-
*
|
|
345
|
+
* Source order of a persisted key: its per-segment `#<n>` ordinals (a bare
|
|
346
|
+
* segment is 0), compared left to right.
|
|
367
347
|
*
|
|
368
|
-
* @param {{
|
|
369
|
-
* @
|
|
348
|
+
* @param {{method: string}} a
|
|
349
|
+
* @param {{method: string}} b
|
|
350
|
+
* @returns {number}
|
|
370
351
|
*/
|
|
371
|
-
function
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
352
|
+
function byKeyOrder(a, b) {
|
|
353
|
+
const ords = (m) =>
|
|
354
|
+
m
|
|
355
|
+
.split('/')
|
|
356
|
+
.flatMap((seg) =>
|
|
357
|
+
(seg.match(/#\d+/g) ?? ['#0']).map((o) => Number(o.slice(1))),
|
|
358
|
+
);
|
|
359
|
+
const [x, y] = [ords(a.method), ords(b.method)];
|
|
360
|
+
for (let i = 0; i < Math.max(x.length, y.length); i++) {
|
|
361
|
+
const d = (x[i] ?? 0) - (y[i] ?? 0);
|
|
362
|
+
if (d !== 0) return d;
|
|
363
|
+
}
|
|
364
|
+
return a.method.localeCompare(b.method);
|
|
375
365
|
}
|
|
376
366
|
|
|
377
367
|
/**
|
|
378
|
-
*
|
|
379
|
-
*
|
|
368
|
+
* Order-aware pairing inside one stem bucket — current rows by `startLine`,
|
|
369
|
+
* baseline rows by key order: same key within `tolerance` first; then the
|
|
370
|
+
* earliest unclaimed row within `tolerance` (a re-keyed pair — never a
|
|
371
|
+
* regression); then leftovers by key, then order, scored as regressions;
|
|
372
|
+
* surplus current rows are new methods, surplus baseline rows stay removed.
|
|
373
|
+
*/
|
|
374
|
+
function alignBucket(state, cur, base) {
|
|
375
|
+
const curSorted = [...cur].sort((a, b) => a.row.startLine - b.row.startLine);
|
|
376
|
+
const pairs = pairBucket(curSorted, base, state.tolerance);
|
|
377
|
+
for (const e of curSorted) scoreAligned(state, e, pairs.get(e));
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** Score one current entry against the baseline row it paired with, if any. */
|
|
381
|
+
function scoreAligned(state, e, b) {
|
|
382
|
+
if (!b) {
|
|
383
|
+
scoreNewMethod(state, e.idx, e.row);
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
state.claimed.add(b);
|
|
387
|
+
if (b.method === e.row.method) {
|
|
388
|
+
scorePair(state, e.idx, e.row, b, 'regression');
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
state.drifted += 1;
|
|
392
|
+
scorePair(state, e.idx, e.row, b, 'drifted-regression');
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* The pairing core of {@link alignBucket}: maps each entry of `curSorted`
|
|
397
|
+
* (source order) to its baseline row; an unpaired entry has no mapping.
|
|
380
398
|
*
|
|
381
|
-
* @param {Array<{
|
|
382
|
-
* @param {{
|
|
383
|
-
* @param {
|
|
384
|
-
* @returns {object}
|
|
399
|
+
* @param {Array<{row: {method: string, crap: number}}>} curSorted
|
|
400
|
+
* @param {Array<{method: string, crap: number}>} base
|
|
401
|
+
* @param {number} tol
|
|
402
|
+
* @returns {Map<object, object>}
|
|
385
403
|
*/
|
|
386
|
-
function
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
404
|
+
function pairBucket(curSorted, base, tol) {
|
|
405
|
+
const free = [...base].sort(byKeyOrder);
|
|
406
|
+
const near = (row) => (b) => Math.abs(row.crap - b.crap) <= tol;
|
|
407
|
+
const sameKey = (row) => (b) => b.method === row.method;
|
|
408
|
+
const passes = [
|
|
409
|
+
(row) => (b) => sameKey(row)(b) && near(row)(b),
|
|
410
|
+
near,
|
|
411
|
+
sameKey,
|
|
412
|
+
() => () => true,
|
|
413
|
+
];
|
|
414
|
+
const pairs = new Map();
|
|
415
|
+
for (const matches of passes) {
|
|
416
|
+
for (const e of curSorted) {
|
|
417
|
+
if (pairs.has(e)) continue;
|
|
418
|
+
const at = free.findIndex(matches(e.row));
|
|
419
|
+
if (at >= 0) pairs.set(e, free.splice(at, 1)[0]);
|
|
396
420
|
}
|
|
397
421
|
}
|
|
398
|
-
|
|
422
|
+
reclaimOwnRows(pairs, free, tol, curSorted);
|
|
423
|
+
return pairs;
|
|
399
424
|
}
|
|
400
425
|
|
|
401
426
|
/**
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
427
|
+
* A re-keyed pair must not hide an increase: a row that scored higher than
|
|
428
|
+
* its own exact-key baseline row takes it back when that row went unpaired
|
|
429
|
+
* (a sibling removed alongside an increase), or when the row itself went
|
|
430
|
+
* unpaired because a namesake re-keyed onto it (a later namesake added
|
|
431
|
+
* alongside an increase; that namesake becomes the new method). Fails safe:
|
|
432
|
+
* an earlier namesake inserted more complex than the existing one reads as
|
|
433
|
+
* the existing method's regression.
|
|
406
434
|
*/
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
435
|
+
function reclaimOwnRows(pairs, free, tol, curSorted) {
|
|
436
|
+
for (const e of curSorted) {
|
|
437
|
+
const mine = pairs.get(e);
|
|
438
|
+
if (mine?.method === e.row.method) continue;
|
|
439
|
+
const isOwnIncrease = (b) =>
|
|
440
|
+
b.method === e.row.method && e.row.crap > b.crap + tol;
|
|
441
|
+
const at = free.findIndex(isOwnIncrease);
|
|
442
|
+
if (at >= 0) {
|
|
443
|
+
pairs.set(e, free.splice(at, 1)[0]);
|
|
444
|
+
if (mine) free.push(mine);
|
|
445
|
+
continue;
|
|
446
|
+
}
|
|
447
|
+
const holder = mine
|
|
448
|
+
? undefined
|
|
449
|
+
: [...pairs.keys()].find((o) => isOwnIncrease(pairs.get(o)));
|
|
450
|
+
if (holder) {
|
|
451
|
+
pairs.set(e, pairs.get(holder));
|
|
452
|
+
pairs.delete(holder);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
415
456
|
|
|
416
457
|
/**
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
* verdicts come from a mis-keyed join and must be suppressed.
|
|
420
|
-
* Returns `{ sound: true }` or `{ sound: false, diagnostic: {name, message} }`.
|
|
458
|
+
* Strict on `null` (the scorer's "unresolved" value); a row merely omitting
|
|
459
|
+
* `coverage` stays scorable.
|
|
421
460
|
*
|
|
422
|
-
* @param {{
|
|
423
|
-
*
|
|
424
|
-
* @param {{ratio?: number, minSample?: number, captureScript?: string}} [opts]
|
|
461
|
+
* @param {{crap?: number|null, coverage?: number|null, unscorable?: boolean}} row
|
|
462
|
+
* @returns {boolean}
|
|
425
463
|
*/
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
: UNSOUND_BASIS_MISMATCH_RATIO;
|
|
430
|
-
const minSample = Number.isFinite(opts.minSample)
|
|
431
|
-
? opts.minSample
|
|
432
|
-
: UNSOUND_BASIS_MIN_SAMPLE;
|
|
433
|
-
const comparable = compareResult?.comparable ?? compareResult?.total ?? 0;
|
|
434
|
-
if (comparable < minSample) return { sound: true };
|
|
435
|
-
// `incomparable` is a subset; max guards a caller supplying only one.
|
|
436
|
-
const mismatched = Math.max(
|
|
437
|
-
compareResult?.provenanceMismatched ?? 0,
|
|
438
|
-
compareResult?.incomparable ?? 0,
|
|
464
|
+
function isUnscorableRow(row) {
|
|
465
|
+
return (
|
|
466
|
+
row?.unscorable === true || row?.crap === null || row?.coverage === null
|
|
439
467
|
);
|
|
440
|
-
const observed = mismatched / comparable;
|
|
441
|
-
if (observed <= ratio) return { sound: true };
|
|
442
|
-
return {
|
|
443
|
-
sound: false,
|
|
444
|
-
diagnostic: {
|
|
445
|
-
name: UNSOUND_BASIS_DIAGNOSTIC,
|
|
446
|
-
message:
|
|
447
|
-
`[CRAP] ⚠ Comparison basis is unsound: ${mismatched}/${comparable} ` +
|
|
448
|
-
`(${(observed * 100).toFixed(1)}%) of comparable methods matched a ` +
|
|
449
|
-
'baseline row expressed in a DIFFERENT line coordinate system — ' +
|
|
450
|
-
`above the ${(ratio * 100).toFixed(0)}% threshold.\n` +
|
|
451
|
-
' At this ratio the baseline and the scan are not describing ' +
|
|
452
|
-
'the same line coordinates, so every per-method verdict below would ' +
|
|
453
|
-
'be derived from a mis-keyed join rather than from your change. ' +
|
|
454
|
-
'They are suppressed.\n' +
|
|
455
|
-
` Re-seed the baseline: run 'npm run ${captureScriptOf(opts)}' then ` +
|
|
456
|
-
"'npm run crap:update -- --full-scope' and commit the result with a " +
|
|
457
|
-
"'baseline-refresh:' subject. The authoritative check-baselines gate " +
|
|
458
|
-
'still gates the merge.',
|
|
459
|
-
},
|
|
460
|
-
};
|
|
461
468
|
}
|
|
462
469
|
|
|
470
|
+
export const INCOMPATIBLE_BASELINE_DIAGNOSTIC = 'crap-baseline-incompatible';
|
|
471
|
+
|
|
472
|
+
export const AHEAD_BASELINE_DIAGNOSTIC = 'crap-baseline-ahead';
|
|
473
|
+
|
|
463
474
|
/**
|
|
464
475
|
* The CRAP capture script an operator hint names — the resolved
|
|
465
476
|
* `gates.crap.captureScript` when the caller passes it, else the coverage
|
|
@@ -487,8 +498,8 @@ function reseedRemedy(ctx) {
|
|
|
487
498
|
* Compat axes for `evaluateBaselineCompatibility`: `{ name, severity, check }`,
|
|
488
499
|
* where `check(ctx)` returns null or a failure message. The first `fatal`
|
|
489
500
|
* match fails; `warn` matches accumulate. Kernel drift only warns; a
|
|
490
|
-
* transpiler change is fatal because it
|
|
491
|
-
*
|
|
501
|
+
* transpiler change is fatal because it can rename or re-nest emitted
|
|
502
|
+
* methods, which moves their scope-path keys.
|
|
492
503
|
*/
|
|
493
504
|
export const CRAP_COMPAT_AXES = [
|
|
494
505
|
missingBaselineAxis('CRAP'),
|
|
@@ -499,12 +510,14 @@ export const CRAP_COMPAT_AXES = [
|
|
|
499
510
|
check: ({ baseline, captureScript }) => {
|
|
500
511
|
if (!baseline) return null;
|
|
501
512
|
const stamped = baseline.scoringSemantics ?? null;
|
|
502
|
-
|
|
513
|
+
// `ahead` is a skip, not a failure: see `aheadStampOf`.
|
|
514
|
+
if (classifyScoringSemantics(stamped) !== 'behind') return null;
|
|
503
515
|
return (
|
|
504
516
|
`[CRAP] scoring semantics changed: baseline=${stamped ?? '<unstamped>'} ` +
|
|
505
|
-
`running=${SCORING_SEMANTICS}. Rows
|
|
506
|
-
'
|
|
507
|
-
|
|
517
|
+
`running=${SCORING_SEMANTICS}. Rows keyed or scored under other ` +
|
|
518
|
+
'semantics (or in the previous rows[] layout) are not comparable to ' +
|
|
519
|
+
'rows scored now, so this baseline cannot be compared. ' +
|
|
520
|
+
reseedRemedy({ captureScript })
|
|
508
521
|
);
|
|
509
522
|
},
|
|
510
523
|
},
|
|
@@ -515,64 +528,22 @@ export const CRAP_COMPAT_AXES = [
|
|
|
515
528
|
if (!baseline) return null;
|
|
516
529
|
if (!isKnownVersion(runningTsTranspilerVersion)) return null;
|
|
517
530
|
const baselineTs = baseline.tsTranspilerVersion;
|
|
518
|
-
// Unstamped: no evidence either way
|
|
531
|
+
// Unstamped: no evidence either way.
|
|
519
532
|
if (!isKnownVersion(baselineTs)) return null;
|
|
520
533
|
if (baselineTs === runningTsTranspilerVersion) return null;
|
|
521
|
-
// A pure-JS baseline has no transpiled
|
|
534
|
+
// A pure-JS baseline has no transpiled method to re-key.
|
|
522
535
|
if (!hasTranspiledRows(baseline)) return null;
|
|
523
536
|
return (
|
|
524
537
|
`[CRAP] tsTranspilerVersion changed: baseline=${baselineTs} running=${runningTsTranspilerVersion}. ` +
|
|
525
|
-
|
|
526
|
-
'
|
|
527
|
-
`
|
|
528
|
-
);
|
|
529
|
-
},
|
|
530
|
-
},
|
|
531
|
-
{
|
|
532
|
-
// Closes the unstamped exemption above. Keyed on a positive marker, since
|
|
533
|
-
// absence can't separate "no provenance" from "typescript unresolvable";
|
|
534
|
-
// scoped to transpiled rows because pure-JS coordinates coincide.
|
|
535
|
-
name: 'provenance-unstamped',
|
|
536
|
-
severity: 'fatal',
|
|
537
|
-
check: ({ baseline, captureScript }) =>
|
|
538
|
-
baseline &&
|
|
539
|
-
baseline.provenanceStamped !== true &&
|
|
540
|
-
hasTranspiledRows(baseline)
|
|
541
|
-
? '[CRAP] baseline predates coordinate-provenance stamping: it carries ' +
|
|
542
|
-
'transpiled-source rows but no `provenanceStamped` marker, so it ' +
|
|
543
|
-
'asserts by omission that every row is an original-source coordinate. ' +
|
|
544
|
-
'`startLine` is half the row identity key, so the comparator would ' +
|
|
545
|
-
'key those rows against a coordinate space they are not in and ' +
|
|
546
|
-
`report regressions no edit can satisfy. ${reseedRemedy({ captureScript })}`
|
|
547
|
-
: null,
|
|
548
|
-
},
|
|
549
|
-
{
|
|
550
|
-
// Catches a half-migrated baseline: a diff-scoped refresh keeps
|
|
551
|
-
// out-of-scope ordinal-keyed anonymous rows under a current-semantics
|
|
552
|
-
// stamp, and those rows pair with nothing. Keyed on the positive
|
|
553
|
-
// `anonymous` marker.
|
|
554
|
-
name: 'anon-identity-unstamped',
|
|
555
|
-
severity: 'fatal',
|
|
556
|
-
check: ({ baseline, captureScript }) => {
|
|
557
|
-
if (!baseline) return null;
|
|
558
|
-
const stale = (baseline.rows ?? []).filter(
|
|
559
|
-
(row) => isAnonymousMethodLabel(row?.method) && row?.anonymous !== true,
|
|
560
|
-
);
|
|
561
|
-
if (stale.length === 0) return null;
|
|
562
|
-
return (
|
|
563
|
-
`[CRAP] baseline carries ${stale.length} anonymous row(s) keyed by the ` +
|
|
564
|
-
'superseded `<anon method-N>` ordinal (e.g. ' +
|
|
565
|
-
`${stale[0].path ?? stale[0].file}::${stale[0].method}) while the ` +
|
|
566
|
-
'envelope claims the current scoring semantics. Those ordinals ' +
|
|
567
|
-
'renumber whenever any anonymous function is added or removed, so the ' +
|
|
568
|
-
'comparator would score the live methods against the new-method ' +
|
|
569
|
-
`ceiling instead of their own baseline. ${reseedRemedy({ captureScript })}`
|
|
538
|
+
'A transpiler change can rename or re-nest the methods it emits, which moves their ' +
|
|
539
|
+
'scope-path keys — so rows scored under the previous transpiler are not comparable ' +
|
|
540
|
+
`to rows scored under this one. ${reseedRemedy({ captureScript })}`
|
|
570
541
|
);
|
|
571
542
|
},
|
|
572
543
|
},
|
|
573
544
|
];
|
|
574
545
|
|
|
575
|
-
/** Sources
|
|
546
|
+
/** Sources escomplex scores through the TypeScript transpiler. */
|
|
576
547
|
const TRANSPILED_SOURCE_RE = /\.(?:ts|tsx|mts|cts)$/i;
|
|
577
548
|
|
|
578
549
|
/**
|
|
@@ -603,12 +574,7 @@ export function evaluateBaselineCompatibility(ctx) {
|
|
|
603
574
|
* Axes a loaded envelope can be judged on alone. `kernel-drift` is excluded:
|
|
604
575
|
* it only warns, and this pass fails closed on any message.
|
|
605
576
|
*/
|
|
606
|
-
const LOADED_ENVELOPE_AXES = [
|
|
607
|
-
'scoring-semantics-drift',
|
|
608
|
-
'ts-transpiler-drift',
|
|
609
|
-
'provenance-unstamped',
|
|
610
|
-
'anon-identity-unstamped',
|
|
611
|
-
];
|
|
577
|
+
const LOADED_ENVELOPE_AXES = ['scoring-semantics-drift', 'ts-transpiler-drift'];
|
|
612
578
|
|
|
613
579
|
/**
|
|
614
580
|
* Kind-module hook: `check-baselines` calls it after `reader.load` and fails
|
|
@@ -680,8 +646,9 @@ export function buildCrapReport({
|
|
|
680
646
|
regressions: compareResult.regressions,
|
|
681
647
|
newViolations: compareResult.newViolations,
|
|
682
648
|
drifted: compareResult.drifted,
|
|
683
|
-
|
|
684
|
-
|
|
649
|
+
// Kept for report-schema stability; no coordinate arm remains.
|
|
650
|
+
incomparable: 0,
|
|
651
|
+
provenanceMismatched: 0,
|
|
685
652
|
// Never scored from an assumed zero coverage.
|
|
686
653
|
unscorable: (compareResult.unscorable ?? 0) + skippedNoCoverage,
|
|
687
654
|
removed: compareResult.removed,
|
|
@@ -695,7 +662,7 @@ export function buildCrapReport({
|
|
|
695
662
|
|
|
696
663
|
/**
|
|
697
664
|
* Replace per-method verdicts with one diagnostic, keeping the counts as
|
|
698
|
-
* evidence. Used when the baseline is incompatible or
|
|
665
|
+
* evidence. Used when the baseline is incompatible or stamped ahead.
|
|
699
666
|
*
|
|
700
667
|
* @param {object} envelope
|
|
701
668
|
* @param {{name: string, message: string}} diagnostic
|
|
@@ -719,8 +686,7 @@ export function printSummaryHeader(result, scanSummary) {
|
|
|
719
686
|
Logger.info(`Total methods scanned: ${result.total}`);
|
|
720
687
|
Logger.info(`Regressions: ${result.regressions}`);
|
|
721
688
|
Logger.info(`New-method violations: ${result.newViolations}`);
|
|
722
|
-
Logger.info(`
|
|
723
|
-
Logger.info(`Provenance mismatched: ${result.provenanceMismatched ?? 0}`);
|
|
689
|
+
Logger.info(`Re-keyed (matched): ${result.drifted}`);
|
|
724
690
|
Logger.info(`Unscorable (no cov): ${result.unscorable ?? 0}`);
|
|
725
691
|
Logger.info(`Removed from baseline: ${result.removed}`);
|
|
726
692
|
if (scanSummary?.skippedFilesNoCoverage) {
|
|
@@ -742,7 +708,7 @@ export function printViolation(v) {
|
|
|
742
708
|
return;
|
|
743
709
|
}
|
|
744
710
|
Logger.error(
|
|
745
|
-
`[CRAP] ❌ REGRESSION: ${v.file}::${v.method} (line ${v.startLine}${v.kind === 'drifted-regression' ? `, baseline
|
|
711
|
+
`[CRAP] ❌ REGRESSION: ${v.file}::${v.method} (line ${v.startLine}${v.kind === 'drifted-regression' ? `, baseline key ${v.baselineMethod}` : ''})`,
|
|
746
712
|
);
|
|
747
713
|
Logger.error(
|
|
748
714
|
` crap=${v.crap.toFixed(2)} > baseline=${v.baseline.toFixed(2)} (c=${v.cyclomatic}, cov=${v.coverage.toFixed(2)})`,
|
|
@@ -755,8 +721,6 @@ export function printRemovedRows(result) {
|
|
|
755
721
|
`[CRAP] ℹ ${result.removed} baseline row(s) absent from current scan (deleted or moved):`,
|
|
756
722
|
);
|
|
757
723
|
for (const r of result.removedRows) {
|
|
758
|
-
Logger.info(
|
|
759
|
-
` - ${r.file}::${r.method} (baseline line ${r.startLine})`,
|
|
760
|
-
);
|
|
724
|
+
Logger.info(` - ${r.file}::${r.method}`);
|
|
761
725
|
}
|
|
762
726
|
}
|