mandrel 2.88.0 → 2.90.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 +3 -1
- package/.agents/docs/configuration.md +9 -0
- package/.agents/schemas/agentrc.schema.json +13 -0
- package/.agents/scripts/board-backfill.js +253 -0
- package/.agents/scripts/coverage-capture.js +32 -49
- package/.agents/scripts/lib/audit-baselines/gate-surface.js +24 -11
- package/.agents/scripts/lib/audit-baselines/read.js +4 -2
- package/.agents/scripts/lib/audit-baselines/surface-entry.js +95 -11
- package/.agents/scripts/lib/baselines/crap-preview-scan.js +3 -1
- package/.agents/scripts/lib/baselines/crap-updater-cli.js +2 -0
- package/.agents/scripts/lib/baselines/kinds/crap.js +37 -16
- package/.agents/scripts/lib/baselines/preview-gates.js +1 -0
- package/.agents/scripts/lib/close-validation/gates.js +40 -9
- package/.agents/scripts/lib/close-validation/process.js +5 -1
- package/.agents/scripts/lib/config/gates/crap.schema.js +15 -0
- package/.agents/scripts/lib/config/quality.js +49 -1
- package/.agents/scripts/lib/coverage-capture-affected.js +2 -1
- package/.agents/scripts/lib/coverage-capture-fullscope.js +2 -2
- package/.agents/scripts/lib/coverage-capture-incremental.js +1 -1
- package/.agents/scripts/lib/coverage-capture-passes.js +143 -0
- package/.agents/scripts/lib/coverage-capture-usage.js +1 -1
- package/.agents/scripts/lib/coverage-capture.js +79 -38
- package/.agents/scripts/lib/crap-utils.js +6 -2
- package/.agents/scripts/lib/generated/agentrc-validator.js +1 -1
- package/.agents/scripts/lib/maintainability-utils.js +6 -1
- package/.agents/scripts/lib/observability/source-classifier.js +1 -0
- package/.agents/scripts/lib/orchestration/board-access-latch.js +101 -0
- package/.agents/scripts/lib/orchestration/check-baselines/phases/evaluate.js +1 -1
- package/.agents/scripts/lib/orchestration/column-sync.js +107 -52
- package/.agents/scripts/lib/orchestration/project-meta-resolver.js +44 -17
- package/.agents/scripts/lib/orchestration/story-handoff.js +14 -1
- package/.agents/scripts/lib/orchestration/verify-credit.js +4 -1
- package/.agents/scripts/providers/github/board-add.js +18 -9
- package/.agents/scripts/providers/github/projects-v2-graphql.js +15 -3
- package/.agents/scripts/update-crap-baseline.js +2 -2
- package/.agents/workflows/audit-baselines.md +7 -2
- package/docs/CHANGELOG.md +26 -0
- package/lib/cli/doctor-checks/project-access.js +114 -0
- package/lib/cli/registry.js +6 -0
- package/package.json +1 -1
|
@@ -191,6 +191,8 @@ Everything `/mandrel-deliver` and `single-story-close` consume: worktree isolati
|
|
|
191
191
|
| `quality.gates.crap.incrementalCoverage.skipWhenUnchanged` | No | `boolean` | `true` | Skip the capture entirely when no changed file under `crap.targetDirs` versus `baseRef` was touched. The only measured saving, and gate-semantics-neutral. Defaults to true. |
|
|
192
192
|
| `quality.gates.crap.incrementalCoverage.baselineJoin` | No | `boolean` | `false` | Let the CRAP join resolve a method in a file the diff did not touch from its committed baseline row instead of requiring fresh coverage for it. A gate loosening, not a saving — defaults to false. |
|
|
193
193
|
| `quality.gates.crap.incrementalCoverage.baseRef` | No | `string` | — | Default git ref the changed-file set is computed against, for a caller that passes no `--ref`. A `--ref` the caller named wins over this value, so a caller that anchors another gate on the same ref — `.husky/pre-push`, which passes `--ref origin/main` and then previews `--changed-since origin/main` — resolves ONE scope for both steps (Story #5365). Omitted and unpassed, the gate’s own default `main` applies. |
|
|
194
|
+
| `quality.gates.crap.coveragePath` | No | `string` \| `null` | `null` | Repo-relative Istanbul `coverage-final.json` the CRAP gate joins against (Story #5717). `null` or unset falls back to `delivery.quality.gates.coverage.coveragePath`. When it differs from that path the CRAP gate has its OWN coverage source: `coverage-capture.js` refreshes it full-scope via `captureScript`, and the handoff seat, close preview and `update-crap-baseline.js` read it. It must live in a different directory from the coverage gate's artifact (the capture stamp is per directory); a same-directory path is refused at config resolution. |
|
|
195
|
+
| `quality.gates.crap.captureScript` | No | `string` | `"test:coverage"` | npm script name (run as `npm run <script>`, never a shell command) that writes the CRAP coverage artifact. Close registers the coverage-capture gate, and the capture refusal and credited-run probe key, on this script. |
|
|
194
196
|
| `quality.gates.maintainability` | No | `object` | — | Maintainability-index ratchet. Scores per file as the average over its methods, so deleting a small high-MI method can legitimately lower a file’s score. |
|
|
195
197
|
| `quality.gates.maintainability.enabled` | No | `boolean` | `true` | When false, the checker exits 0 with a skip line and the gate is reported as `skipped`, never omitted. |
|
|
196
198
|
| `quality.gates.maintainability.baselinePath` | No | `string` | `"baselines/maintainability.json"` | Repo-root-relative path to the gate's committed baseline artifact. |
|
|
@@ -322,6 +324,13 @@ names or defaults.
|
|
|
322
324
|
- **`branchProtection.requiredChecks`.** Each `{ name, cmd[] }` entry is used
|
|
323
325
|
**both** as a required-status-check expectation on the PR and as a local
|
|
324
326
|
close-validation gate invocation.
|
|
327
|
+
- **`projectNumber`.** Board sync needs a token with the `project` scope. A
|
|
328
|
+
token without it never aborts a run (labels stay authoritative): the first
|
|
329
|
+
board add or Status flip that fails on scope emits one warning per process
|
|
330
|
+
naming the remedy, `gh auth refresh -h github.com -s project`, and
|
|
331
|
+
`mandrel doctor` fails its `github-project-access` check. After refreshing
|
|
332
|
+
the token, `node .agents/scripts/board-backfill.js` (`--dry-run` to preview)
|
|
333
|
+
adds the open Stories and Epics the board missed and syncs their Status.
|
|
325
334
|
- **`notifications`.** Both event allowlists filter their channel
|
|
326
335
|
independently; their enums are pinned in the schema. Set an array to `[]` to
|
|
327
336
|
suppress a channel. The severity vocabulary and shipped default allowlists
|
|
@@ -807,6 +807,19 @@
|
|
|
807
807
|
}
|
|
808
808
|
},
|
|
809
809
|
"additionalProperties": false
|
|
810
|
+
},
|
|
811
|
+
"coveragePath": {
|
|
812
|
+
"type": ["string", "null"],
|
|
813
|
+
"minLength": 1,
|
|
814
|
+
"description": "Repo-relative Istanbul `coverage-final.json` the CRAP gate joins against (Story #5717). `null` or unset falls back to `delivery.quality.gates.coverage.coveragePath`. When it differs from that path the CRAP gate has its OWN coverage source: `coverage-capture.js` refreshes it full-scope via `captureScript`, and the handoff seat, close preview and `update-crap-baseline.js` read it. It must live in a different directory from the coverage gate's artifact (the capture stamp is per directory); a same-directory path is refused at config resolution.",
|
|
815
|
+
"default": null
|
|
816
|
+
},
|
|
817
|
+
"captureScript": {
|
|
818
|
+
"type": "string",
|
|
819
|
+
"minLength": 1,
|
|
820
|
+
"pattern": "^[A-Za-z0-9@:._/-]+$",
|
|
821
|
+
"description": "npm script name (run as `npm run <script>`, never a shell command) that writes the CRAP coverage artifact. Close registers the coverage-capture gate, and the capture refusal and credited-run probe key, on this script.",
|
|
822
|
+
"default": "test:coverage"
|
|
810
823
|
}
|
|
811
824
|
},
|
|
812
825
|
"additionalProperties": false
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* board-backfill.js — add open Stories/Epics missing from the Projects v2
|
|
5
|
+
* board and sync each Story's Status from its `agent::*` label. Idempotent.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { parseArgs } from 'node:util';
|
|
9
|
+
|
|
10
|
+
import { runAsCli } from './lib/cli-utils.js';
|
|
11
|
+
import { resolveConfig } from './lib/config-resolver.js';
|
|
12
|
+
import { Logger, routeAllOutputToStderr } from './lib/Logger.js';
|
|
13
|
+
import {
|
|
14
|
+
isProjectAccessFailure,
|
|
15
|
+
toProjectAccessError,
|
|
16
|
+
} from './lib/orchestration/board-access-latch.js';
|
|
17
|
+
import {
|
|
18
|
+
ColumnSync,
|
|
19
|
+
columnForLabels,
|
|
20
|
+
} from './lib/orchestration/column-sync.js';
|
|
21
|
+
import {
|
|
22
|
+
ProjectAccessError,
|
|
23
|
+
resolveProjectMeta,
|
|
24
|
+
} from './lib/orchestration/project-meta-resolver.js';
|
|
25
|
+
import { createProvider } from './lib/provider-factory.js';
|
|
26
|
+
|
|
27
|
+
const BOARD_TYPE_LABELS = Object.freeze(['type::story', 'type::epic']);
|
|
28
|
+
|
|
29
|
+
const OPEN_ISSUES_QUERY = `
|
|
30
|
+
query($owner: String!, $repo: String!, $label: String!, $after: String) {
|
|
31
|
+
repository(owner: $owner, name: $repo) {
|
|
32
|
+
issues(states: OPEN, labels: [$label], first: 100, after: $after) {
|
|
33
|
+
pageInfo { hasNextPage endCursor }
|
|
34
|
+
nodes {
|
|
35
|
+
number
|
|
36
|
+
id
|
|
37
|
+
labels(first: 50) { nodes { name } }
|
|
38
|
+
projectItems(first: 20) {
|
|
39
|
+
nodes {
|
|
40
|
+
id
|
|
41
|
+
project { id }
|
|
42
|
+
fieldValueByName(name: "Status") {
|
|
43
|
+
... on ProjectV2ItemFieldSingleSelectValue { name }
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}`;
|
|
51
|
+
|
|
52
|
+
const ADD_ITEM_MUTATION = `
|
|
53
|
+
mutation($projectId: ID!, $contentId: ID!) {
|
|
54
|
+
addProjectV2ItemById(input: { projectId: $projectId, contentId: $contentId }) {
|
|
55
|
+
item { id }
|
|
56
|
+
}
|
|
57
|
+
}`;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Raise a scope/auth refusal as the typed error; return anything else.
|
|
61
|
+
*
|
|
62
|
+
* @param {unknown} err
|
|
63
|
+
* @returns {unknown}
|
|
64
|
+
*/
|
|
65
|
+
function classify(err) {
|
|
66
|
+
if (isProjectAccessFailure(err)) throw toProjectAccessError(err);
|
|
67
|
+
return err;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Open issues carrying any board type label, deduped by number.
|
|
72
|
+
*
|
|
73
|
+
* @param {{ graphql: Function, owner: string, repo: string }} provider
|
|
74
|
+
* @returns {Promise<Array<{ number: number, nodeId: string, labels: string[], items: object[] }>>}
|
|
75
|
+
*/
|
|
76
|
+
export async function listBoardCandidates(provider) {
|
|
77
|
+
const byNumber = new Map();
|
|
78
|
+
for (const label of BOARD_TYPE_LABELS) {
|
|
79
|
+
let after = null;
|
|
80
|
+
do {
|
|
81
|
+
let data;
|
|
82
|
+
try {
|
|
83
|
+
data = await provider.graphql(OPEN_ISSUES_QUERY, {
|
|
84
|
+
owner: provider.owner,
|
|
85
|
+
repo: provider.repo,
|
|
86
|
+
label,
|
|
87
|
+
after,
|
|
88
|
+
});
|
|
89
|
+
} catch (err) {
|
|
90
|
+
throw classify(err);
|
|
91
|
+
}
|
|
92
|
+
const page = data?.repository?.issues;
|
|
93
|
+
for (const node of page?.nodes ?? []) {
|
|
94
|
+
if (!node || byNumber.has(node.number)) continue;
|
|
95
|
+
byNumber.set(node.number, {
|
|
96
|
+
number: node.number,
|
|
97
|
+
nodeId: node.id,
|
|
98
|
+
labels: (node.labels?.nodes ?? []).map((l) => l.name),
|
|
99
|
+
items: node.projectItems?.nodes ?? [],
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
after = page?.pageInfo?.hasNextPage ? page.pageInfo.endCursor : null;
|
|
103
|
+
} while (after);
|
|
104
|
+
}
|
|
105
|
+
return [...byNumber.values()].sort((a, b) => a.number - b.number);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* What the board needs for one issue: an add, a Status sync, both, or
|
|
110
|
+
* nothing. Epics never get a Status target here.
|
|
111
|
+
*
|
|
112
|
+
* @param {{ labels: string[], items: object[] }} issue
|
|
113
|
+
* @param {string} projectId
|
|
114
|
+
*/
|
|
115
|
+
export function planIssue(issue, projectId) {
|
|
116
|
+
const isEpic = issue.labels.includes('type::epic');
|
|
117
|
+
const target = isEpic ? null : columnForLabels(issue.labels);
|
|
118
|
+
const item = issue.items.find((n) => n?.project?.id === projectId);
|
|
119
|
+
const current = item?.fieldValueByName?.name ?? null;
|
|
120
|
+
return {
|
|
121
|
+
number: issue.number,
|
|
122
|
+
type: isEpic ? 'epic' : 'story',
|
|
123
|
+
add: !item,
|
|
124
|
+
status: target && target !== current ? target : null,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @param {{
|
|
130
|
+
* provider: { graphql: Function, owner: string, repo: string, projectNumber?: number|null, projectOwner?: string|null },
|
|
131
|
+
* config?: object,
|
|
132
|
+
* dryRun?: boolean,
|
|
133
|
+
* columnSync?: { sync: Function },
|
|
134
|
+
* }} args
|
|
135
|
+
* @returns {Promise<{ dryRun: boolean, added: number, synced: number, skipped: number, failed: number, planned: object[] }>}
|
|
136
|
+
* @throws {ProjectAccessError} when the token cannot read or write the board.
|
|
137
|
+
*/
|
|
138
|
+
export async function runBackfill({
|
|
139
|
+
provider,
|
|
140
|
+
config,
|
|
141
|
+
dryRun = false,
|
|
142
|
+
columnSync,
|
|
143
|
+
}) {
|
|
144
|
+
const projectNumber =
|
|
145
|
+
config?.github?.projectNumber ?? provider.projectNumber ?? null;
|
|
146
|
+
if (!projectNumber) {
|
|
147
|
+
throw new Error(
|
|
148
|
+
'No github.projectNumber configured — nothing to backfill.',
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
const project = await resolveProjectMeta({
|
|
152
|
+
provider,
|
|
153
|
+
owner: provider.projectOwner ?? provider.owner ?? null,
|
|
154
|
+
projectNumber,
|
|
155
|
+
projectFields: 'id',
|
|
156
|
+
});
|
|
157
|
+
if (!project) {
|
|
158
|
+
throw new Error(`Project #${projectNumber} not found.`);
|
|
159
|
+
}
|
|
160
|
+
const sync =
|
|
161
|
+
columnSync ??
|
|
162
|
+
new ColumnSync({ provider, projectNumber, logger: Logger, config });
|
|
163
|
+
const summary = { dryRun, added: 0, synced: 0, skipped: 0, failed: 0 };
|
|
164
|
+
const planned = [];
|
|
165
|
+
for (const issue of await listBoardCandidates(provider)) {
|
|
166
|
+
const plan = planIssue(issue, project.id);
|
|
167
|
+
if (!plan.add && !plan.status) {
|
|
168
|
+
summary.skipped += 1;
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
planned.push(plan);
|
|
172
|
+
if (dryRun) continue;
|
|
173
|
+
await applyPlan({
|
|
174
|
+
plan,
|
|
175
|
+
issue,
|
|
176
|
+
provider,
|
|
177
|
+
projectId: project.id,
|
|
178
|
+
sync,
|
|
179
|
+
summary,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
return { ...summary, planned };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
async function applyPlan({ plan, issue, provider, projectId, sync, summary }) {
|
|
186
|
+
if (plan.add) {
|
|
187
|
+
try {
|
|
188
|
+
await provider.graphql(ADD_ITEM_MUTATION, {
|
|
189
|
+
projectId,
|
|
190
|
+
contentId: issue.nodeId,
|
|
191
|
+
});
|
|
192
|
+
summary.added += 1;
|
|
193
|
+
} catch (err) {
|
|
194
|
+
classify(err);
|
|
195
|
+
Logger.warn(
|
|
196
|
+
`[board-backfill] could not add #${issue.number}: ${err?.message ?? err}`,
|
|
197
|
+
);
|
|
198
|
+
summary.failed += 1;
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (!plan.status) return;
|
|
203
|
+
const result = await sync
|
|
204
|
+
.sync(issue.number, issue.labels)
|
|
205
|
+
.catch((err) => ({ status: 'failed', error: classify(err) }));
|
|
206
|
+
if (result?.reason === 'insufficient-scope') {
|
|
207
|
+
throw toProjectAccessError(new Error('Status update refused'));
|
|
208
|
+
}
|
|
209
|
+
if (result?.status === 'synced') summary.synced += 1;
|
|
210
|
+
else summary.failed += 1;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/* node:coverage ignore next */
|
|
214
|
+
export async function main(argv = process.argv.slice(2)) {
|
|
215
|
+
const { values } = parseArgs({
|
|
216
|
+
args: argv,
|
|
217
|
+
options: { 'dry-run': { type: 'boolean', default: false } },
|
|
218
|
+
strict: true,
|
|
219
|
+
});
|
|
220
|
+
routeAllOutputToStderr();
|
|
221
|
+
const config = resolveConfig();
|
|
222
|
+
const provider = createProvider(config);
|
|
223
|
+
try {
|
|
224
|
+
const result = await runBackfill({
|
|
225
|
+
provider,
|
|
226
|
+
config,
|
|
227
|
+
dryRun: values['dry-run'],
|
|
228
|
+
});
|
|
229
|
+
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
230
|
+
} catch (err) {
|
|
231
|
+
if (err instanceof ProjectAccessError) {
|
|
232
|
+
process.stderr.write(
|
|
233
|
+
`[board-backfill] ${err.message}\nRemedy: ${err.remedy}\n`,
|
|
234
|
+
);
|
|
235
|
+
process.exitCode = 1;
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
throw err;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
runAsCli(import.meta.url, main, {
|
|
243
|
+
source: 'board-backfill',
|
|
244
|
+
usage: {
|
|
245
|
+
invocation: 'node .agents/scripts/board-backfill.js [--dry-run]',
|
|
246
|
+
summary:
|
|
247
|
+
"Add open type::story / type::epic issues missing from the configured Projects v2 board and sync each Story's Status from its agent::* label. Idempotent; prints a JSON summary { added, synced, skipped, failed } on stdout.",
|
|
248
|
+
flags: [
|
|
249
|
+
['--dry-run', 'List what would be added or synced; change nothing.'],
|
|
250
|
+
['--help', 'Show this message.'],
|
|
251
|
+
],
|
|
252
|
+
},
|
|
253
|
+
});
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* `coverage.captureScope: "affected"`, the consumer's `test:coverage:affected`)
|
|
7
7
|
* behind the host-level full-suite lock and stamp on success. A green run that
|
|
8
8
|
* leaves no artifact at `coveragePath` fails (exit 1) and is never stamped.
|
|
9
|
+
* An own CRAP source gets a second, always full-scope pass via
|
|
10
|
+
* `crap.captureScript` (`lib/coverage-capture-passes.js`).
|
|
9
11
|
*
|
|
10
12
|
* `--require-credited` must stay an argument, never a config read: as policy
|
|
11
13
|
* it also refused the depositing run, leaving no path that could deposit.
|
|
@@ -28,6 +30,10 @@ import {
|
|
|
28
30
|
} from './lib/coverage-capture.js';
|
|
29
31
|
import { tryScopedCapture } from './lib/coverage-capture-affected.js';
|
|
30
32
|
import { runFullScopeCapture } from './lib/coverage-capture-fullscope.js';
|
|
33
|
+
import {
|
|
34
|
+
captureRefusal,
|
|
35
|
+
runCapturePasses,
|
|
36
|
+
} from './lib/coverage-capture-passes.js';
|
|
31
37
|
import { handleCoverageCaptureHelp } from './lib/coverage-capture-usage.js';
|
|
32
38
|
import { lockedCapture } from './lib/full-suite-lock.js';
|
|
33
39
|
import { Logger } from './lib/Logger.js';
|
|
@@ -97,13 +103,8 @@ export async function runCoverageCapture(argv = process.argv, deps = {}) {
|
|
|
97
103
|
const args = parseArgs(argv);
|
|
98
104
|
const config = resolveConfigImpl({ cwd: args.cwd });
|
|
99
105
|
const { crap, coverage } = getQualityImpl(config);
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
cwd: args.cwd,
|
|
103
|
-
readPackageScriptsImpl,
|
|
104
|
-
hasNpmScriptImpl,
|
|
105
|
-
logger,
|
|
106
|
-
});
|
|
106
|
+
const scripts = readPackageScriptsImpl(args.cwd);
|
|
107
|
+
const refused = captureRefusal({ crap, scripts, hasNpmScriptImpl, logger });
|
|
107
108
|
if (refused !== null) return refused;
|
|
108
109
|
|
|
109
110
|
// Outermost first: the credit probe announces or refuses the run, and only
|
|
@@ -114,25 +115,30 @@ export async function runCoverageCapture(argv = process.argv, deps = {}) {
|
|
|
114
115
|
onLockProgress: lockHooks.onLockProgress,
|
|
115
116
|
...lockOptions,
|
|
116
117
|
});
|
|
117
|
-
const credited = artifactCheckedCapture(locked, {
|
|
118
|
-
args,
|
|
119
|
-
crap,
|
|
120
|
-
existsSync: coverageArtifactExistsImpl,
|
|
121
|
-
logger,
|
|
122
|
-
});
|
|
123
118
|
let timings = null;
|
|
124
|
-
const
|
|
125
|
-
credited({
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
119
|
+
const makeCapture = (source) => {
|
|
120
|
+
const credited = artifactCheckedCapture(locked, {
|
|
121
|
+
args,
|
|
122
|
+
source,
|
|
123
|
+
existsSync: coverageArtifactExistsImpl,
|
|
124
|
+
logger,
|
|
130
125
|
});
|
|
131
|
-
|
|
126
|
+
return (captureOpts) =>
|
|
127
|
+
credited({
|
|
128
|
+
...captureOpts,
|
|
129
|
+
onTimings: (t) => {
|
|
130
|
+
timings = t;
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
const code = await runCapturePasses({
|
|
132
135
|
crap,
|
|
133
136
|
coverage,
|
|
134
137
|
args,
|
|
135
|
-
|
|
138
|
+
scripts,
|
|
139
|
+
hasNpmScriptImpl,
|
|
140
|
+
makeCapture,
|
|
141
|
+
runShared: runCaptureScopes,
|
|
136
142
|
deps: {
|
|
137
143
|
getChangedFilesImpl,
|
|
138
144
|
isCoverageFreshImpl,
|
|
@@ -149,41 +155,18 @@ export async function runCoverageCapture(argv = process.argv, deps = {}) {
|
|
|
149
155
|
}
|
|
150
156
|
|
|
151
157
|
/**
|
|
152
|
-
* The credited runner, failing a green run that wrote no artifact
|
|
158
|
+
* The credited runner, failing a green run that wrote no artifact at the
|
|
159
|
+
* pass's source.
|
|
153
160
|
*
|
|
154
161
|
* @param {Function} locked
|
|
155
|
-
* @param {{ args: object,
|
|
162
|
+
* @param {{ args: object, source: { coveragePath: string, script?: string, configKey?: string }, existsSync?: Function, logger: object }} opts
|
|
156
163
|
* @returns {(opts: object) => Promise<number>}
|
|
157
164
|
*/
|
|
158
|
-
function artifactCheckedCapture(locked, { args,
|
|
165
|
+
function artifactCheckedCapture(locked, { args, source, existsSync, logger }) {
|
|
159
166
|
return requireCaptureArtifact(
|
|
160
167
|
creditedCapture(locked, { requireCredited: args.requireCredited, logger }),
|
|
161
|
-
{ cwd: args.cwd,
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/** @returns {number|null} The exit code when no capture may run. */
|
|
166
|
-
function refusal({
|
|
167
|
-
crap,
|
|
168
|
-
cwd,
|
|
169
|
-
readPackageScriptsImpl,
|
|
170
|
-
hasNpmScriptImpl,
|
|
171
|
-
logger,
|
|
172
|
-
}) {
|
|
173
|
-
if (crap.enabled === false) {
|
|
174
|
-
logger.info('[coverage-capture] CRAP gate disabled — skipping capture.');
|
|
175
|
-
return 0;
|
|
176
|
-
}
|
|
177
|
-
if (hasNpmScriptImpl(readPackageScriptsImpl(cwd), 'test:coverage')) {
|
|
178
|
-
return null;
|
|
179
|
-
}
|
|
180
|
-
// Name the fix rather than propagate npm's opaque "Missing script" exit.
|
|
181
|
-
logger.error(
|
|
182
|
-
'[coverage-capture] ✖ No "test:coverage" script in package.json. ' +
|
|
183
|
-
'Add one (e.g. "test:coverage": "node --test --experimental-test-coverage") ' +
|
|
184
|
-
'or disable the CRAP gate via delivery.quality.gates.crap.enabled=false.',
|
|
168
|
+
{ ...source, cwd: args.cwd, existsSync, logger },
|
|
185
169
|
);
|
|
186
|
-
return 1;
|
|
187
170
|
}
|
|
188
171
|
|
|
189
172
|
function reportTimings(timings, logger, lockHooks) {
|
|
@@ -5,41 +5,54 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import path from 'node:path';
|
|
8
|
-
import { ALL_KINDS, baselinePathFor
|
|
8
|
+
import { ALL_KINDS, baselinePathFor } from './kinds.js';
|
|
9
9
|
import { listFilesUnder, readJsonFile } from './read.js';
|
|
10
|
-
import { surfaceEntryFor } from './surface-entry.js';
|
|
10
|
+
import { scannerSkipDirsFor, surfaceEntryFor } from './surface-entry.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* One gate's declared `targetDirs`, deduplicated.
|
|
14
14
|
*
|
|
15
15
|
* @param {object | null | undefined} quality
|
|
16
|
+
* @param {string} kind
|
|
16
17
|
* @returns {string[]}
|
|
17
18
|
*/
|
|
18
|
-
function
|
|
19
|
+
function targetDirsOf(quality, kind) {
|
|
19
20
|
const dirs = new Set();
|
|
20
|
-
for (const
|
|
21
|
-
|
|
22
|
-
if (typeof dir === 'string' && dir.length > 0) dirs.add(dir);
|
|
23
|
-
}
|
|
21
|
+
for (const dir of quality?.gates?.[kind]?.targetDirs ?? []) {
|
|
22
|
+
if (typeof dir === 'string' && dir.length > 0) dirs.add(dir);
|
|
24
23
|
}
|
|
25
24
|
return [...dirs].sort();
|
|
26
25
|
}
|
|
27
26
|
|
|
27
|
+
/**
|
|
28
|
+
* The files one gate's scanner could visit: its own `targetDirs`, walked with
|
|
29
|
+
* its own skip set.
|
|
30
|
+
*
|
|
31
|
+
* @param {string} cwd
|
|
32
|
+
* @param {object | null | undefined} quality
|
|
33
|
+
* @param {string} kind
|
|
34
|
+
* @returns {string[]}
|
|
35
|
+
*/
|
|
36
|
+
function candidateFilesFor(cwd, quality, kind) {
|
|
37
|
+
const skip = scannerSkipDirsFor(kind);
|
|
38
|
+
return targetDirsOf(quality, kind).flatMap((dir) =>
|
|
39
|
+
listFilesUnder(cwd, dir, skip),
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
28
43
|
/**
|
|
29
44
|
* @param {{ cwd: string, quality: object, now?: Date, run?: Function }} args
|
|
30
45
|
* @returns {{ entries: object[], baselines: Map<string, object|null> }}
|
|
31
46
|
* `baselines` is carried forward so later sections never re-read from disk.
|
|
32
47
|
*/
|
|
33
48
|
export function buildGateSurface({ cwd, quality, now = new Date(), run }) {
|
|
34
|
-
const files = declaredTargetDirs(quality).flatMap((dir) =>
|
|
35
|
-
listFilesUnder(cwd, dir),
|
|
36
|
-
);
|
|
37
49
|
const io = { cwd, run };
|
|
38
50
|
const entries = [];
|
|
39
51
|
const baselines = new Map();
|
|
40
52
|
for (const kind of ALL_KINDS) {
|
|
41
53
|
const relPath = baselinePathFor(kind, quality);
|
|
42
54
|
const read = readJsonFile(path.resolve(cwd, relPath));
|
|
55
|
+
const files = candidateFilesFor(cwd, quality, kind);
|
|
43
56
|
entries.push(
|
|
44
57
|
surfaceEntryFor({ kind, quality, read, relPath, files, now, io }),
|
|
45
58
|
);
|
|
@@ -33,10 +33,12 @@ export function readJsonFile(absolutePath) {
|
|
|
33
33
|
/**
|
|
34
34
|
* @param {string} repoRoot
|
|
35
35
|
* @param {string} rootDir repo-relative directory to walk
|
|
36
|
+
* @param {Iterable<string>} [scannerSkip] directory names a gate's scanner
|
|
37
|
+
* never descends into, skipped on top of the lens's own cost guard
|
|
36
38
|
* @returns {string[]} sorted repo-relative posix paths
|
|
37
39
|
*/
|
|
38
|
-
export function listFilesUnder(repoRoot, rootDir) {
|
|
39
|
-
const skip = new Set(['node_modules', '.git', '.worktrees']);
|
|
40
|
+
export function listFilesUnder(repoRoot, rootDir, scannerSkip = []) {
|
|
41
|
+
const skip = new Set(['node_modules', '.git', '.worktrees', ...scannerSkip]);
|
|
40
42
|
const out = [];
|
|
41
43
|
const walk = (abs) => {
|
|
42
44
|
let entries;
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import picomatch from 'picomatch';
|
|
9
|
+
import { IGNORED_DIRS } from '../maintainability-utils.js';
|
|
9
10
|
import { GATE_KINDS, KIND_SPECS, measuredTotalOf, rollupOf } from './kinds.js';
|
|
10
11
|
import { stalenessOf } from './staleness.js';
|
|
11
12
|
|
|
@@ -32,19 +33,98 @@ function isStubInstrument({ rowCount, rollup }) {
|
|
|
32
33
|
return rowCount === 0 && isAllZeroRollup(rollup);
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Directory names each gate's own scanner never descends into. CRAP and
|
|
38
|
+
* maintainability share the `scanDirectory` walk; duplication runs jscpd with
|
|
39
|
+
* `gitignore: false` over its `targetDirs`, so it skips nothing. A kind absent
|
|
40
|
+
* here declares no `ignoreGlobs` and skips nothing.
|
|
41
|
+
*
|
|
42
|
+
* @type {Readonly<Record<string, ReadonlySet<string>>>}
|
|
43
|
+
*/
|
|
44
|
+
const SCANNER_SKIP_DIRS = Object.freeze({
|
|
45
|
+
crap: IGNORED_DIRS,
|
|
46
|
+
maintainability: IGNORED_DIRS,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const NO_SKIP = new Set();
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {string} kind
|
|
53
|
+
* @returns {ReadonlySet<string>}
|
|
54
|
+
*/
|
|
55
|
+
export function scannerSkipDirsFor(kind) {
|
|
56
|
+
return SCANNER_SKIP_DIRS[kind] ?? NO_SKIP;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Generated or installed trees: absent from a fresh checkout, present after an
|
|
61
|
+
* install or build. A glob aimed at one is load-bearing whenever the gate's
|
|
62
|
+
* scanner would descend there, whatever is on disk today.
|
|
63
|
+
*/
|
|
64
|
+
const GENERATED_TREE_DIRS = new Set([
|
|
65
|
+
'node_modules',
|
|
66
|
+
'dist',
|
|
67
|
+
'build',
|
|
68
|
+
'out',
|
|
69
|
+
'coverage',
|
|
70
|
+
'.next',
|
|
71
|
+
]);
|
|
72
|
+
|
|
73
|
+
const GLOB_META = /[*?[\]{}()!+@]/;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A glob is latent when one of its literal segments names a generated tree the
|
|
77
|
+
* scanner would walk into, so an empty match today is not evidence of death.
|
|
78
|
+
*
|
|
79
|
+
* @param {string} glob
|
|
80
|
+
* @param {ReadonlySet<string>} scannerSkipDirs
|
|
81
|
+
* @returns {boolean}
|
|
82
|
+
*/
|
|
83
|
+
function isLatentGlob(glob, scannerSkipDirs) {
|
|
84
|
+
return glob
|
|
85
|
+
.split('/')
|
|
86
|
+
.some(
|
|
87
|
+
(segment) =>
|
|
88
|
+
!GLOB_META.test(segment) &&
|
|
89
|
+
GENERATED_TREE_DIRS.has(segment) &&
|
|
90
|
+
!scannerSkipDirs.has(segment),
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @param {unknown} glob
|
|
96
|
+
* @param {ReadonlySet<string>} scannerSkipDirs
|
|
97
|
+
* @returns {boolean} a non-empty, non-latent glob string
|
|
98
|
+
*/
|
|
99
|
+
function isJudgeableGlob(glob, scannerSkipDirs) {
|
|
100
|
+
return (
|
|
101
|
+
typeof glob === 'string' &&
|
|
102
|
+
glob.length > 0 &&
|
|
103
|
+
!isLatentGlob(glob, scannerSkipDirs)
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @param {string} glob
|
|
109
|
+
* @param {string[]} files
|
|
110
|
+
* @returns {boolean}
|
|
111
|
+
*/
|
|
112
|
+
function matchesNothing(glob, files) {
|
|
113
|
+
const isMatch = picomatch(glob, { dot: true });
|
|
114
|
+
return !files.some((f) => isMatch(f));
|
|
115
|
+
}
|
|
116
|
+
|
|
35
117
|
/**
|
|
36
118
|
* @param {string[]} ignoreGlobs
|
|
37
|
-
* @param {string[]} files repo-relative posix paths
|
|
38
|
-
* @
|
|
119
|
+
* @param {string[]} files repo-relative posix paths the gate's scanner walks
|
|
120
|
+
* @param {ReadonlySet<string>} scannerSkipDirs
|
|
121
|
+
* @returns {string[]} non-latent globs matching zero files
|
|
39
122
|
*/
|
|
40
|
-
function findDeadIgnoreGlobs(ignoreGlobs, files) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (!files.some((f) => isMatch(f))) dead.push(glob);
|
|
46
|
-
}
|
|
47
|
-
return dead;
|
|
123
|
+
function findDeadIgnoreGlobs(ignoreGlobs, files, scannerSkipDirs) {
|
|
124
|
+
return (ignoreGlobs ?? []).filter(
|
|
125
|
+
(glob) =>
|
|
126
|
+
isJudgeableGlob(glob, scannerSkipDirs) && matchesNothing(glob, files),
|
|
127
|
+
);
|
|
48
128
|
}
|
|
49
129
|
|
|
50
130
|
/**
|
|
@@ -79,7 +159,11 @@ export function surfaceEntryFor({
|
|
|
79
159
|
rowCount: rows.length,
|
|
80
160
|
measured: measuredTotalOf(kind, baseline),
|
|
81
161
|
...stalenessOf({ kind, gateBlock, rows, relPath, baseline, now, io }),
|
|
82
|
-
deadIgnoreGlobs: findDeadIgnoreGlobs(
|
|
162
|
+
deadIgnoreGlobs: findDeadIgnoreGlobs(
|
|
163
|
+
gateBlock?.ignoreGlobs,
|
|
164
|
+
files,
|
|
165
|
+
scannerSkipDirsFor(kind),
|
|
166
|
+
),
|
|
83
167
|
parseError,
|
|
84
168
|
};
|
|
85
169
|
}
|
|
@@ -122,7 +122,9 @@ export async function computeCrapPreviewScan({
|
|
|
122
122
|
envelope.cyclomaticAdvisories = listCyclomaticAdvisories(scan.rows);
|
|
123
123
|
// Above the drifted-row ratio every verdict is an artefact of a mis-keyed
|
|
124
124
|
// join: say so once and fail open.
|
|
125
|
-
const basis = assessComparisonBasis(result
|
|
125
|
+
const basis = assessComparisonBasis(result, {
|
|
126
|
+
captureScript: crap.captureScript,
|
|
127
|
+
});
|
|
126
128
|
if (!basis.sound) {
|
|
127
129
|
return {
|
|
128
130
|
exitCode: 0,
|
|
@@ -91,6 +91,7 @@ export function resolveCrapUpdaterOptions(
|
|
|
91
91
|
minMethodResolutionRate:
|
|
92
92
|
crap.minMethodResolutionRate ?? DEFAULT_MIN_RESOLUTION_RATE,
|
|
93
93
|
coveragePath,
|
|
94
|
+
captureScript: crap.captureScript ?? 'test:coverage',
|
|
94
95
|
baselinePath,
|
|
95
96
|
absBaselinePath: path.isAbsolute(baselinePath)
|
|
96
97
|
? baselinePath
|
|
@@ -208,6 +209,7 @@ function buildCrapUpdaterScorer(
|
|
|
208
209
|
const refusal = checkResolutionFloor(
|
|
209
210
|
summary.resolution,
|
|
210
211
|
options.minMethodResolutionRate,
|
|
212
|
+
options.captureScript,
|
|
211
213
|
);
|
|
212
214
|
if (refusal) throw new Error(refusal);
|
|
213
215
|
|