mandrel 2.74.0 → 2.76.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/audit-checklists/exceptions.md +24 -0
- package/.agents/docs/runbooks/mods.md +78 -16
- package/.agents/docs/workflows.md +2 -1
- package/.agents/mods/mandrel-status/hooks/register.tsx +942 -108
- package/.agents/mods/mandrel-status/types/index.d.ts +67 -11
- package/.agents/schemas/audit-exceptions-envelope.schema.json +268 -0
- package/.agents/schemas/audit-rules.json +43 -0
- package/.agents/schemas/story-progress.schema.json +48 -0
- package/.agents/scripts/audit-exceptions.js +145 -0
- package/.agents/scripts/lib/audit-exceptions/adapters/ci-gates.js +65 -0
- package/.agents/scripts/lib/audit-exceptions/adapters/code-allowlists.js +143 -0
- package/.agents/scripts/lib/audit-exceptions/adapters/dependency-audit.js +160 -0
- package/.agents/scripts/lib/audit-exceptions/adapters/dependency-patches.js +124 -0
- package/.agents/scripts/lib/audit-exceptions/adapters/dependency-pins.js +177 -0
- package/.agents/scripts/lib/audit-exceptions/adapters/dependency-policy.js +243 -0
- package/.agents/scripts/lib/audit-exceptions/adapters/index.js +30 -0
- package/.agents/scripts/lib/audit-exceptions/adapters/inline-suppressions.js +107 -0
- package/.agents/scripts/lib/audit-exceptions/adapters/sca-exceptions.js +55 -0
- package/.agents/scripts/lib/audit-exceptions/adapters/test-skips.js +96 -0
- package/.agents/scripts/lib/audit-exceptions/adapters/tool-config.js +273 -0
- package/.agents/scripts/lib/audit-exceptions/classify.js +64 -0
- package/.agents/scripts/lib/audit-exceptions/dependency-index.js +266 -0
- package/.agents/scripts/lib/audit-exceptions/engine.js +249 -0
- package/.agents/scripts/lib/audit-exceptions/globs.js +106 -0
- package/.agents/scripts/lib/audit-exceptions/history.js +126 -0
- package/.agents/scripts/lib/audit-exceptions/locate.js +59 -0
- package/.agents/scripts/lib/audit-exceptions/probe.js +196 -0
- package/.agents/scripts/lib/audit-exceptions/range-subset.js +153 -0
- package/.agents/scripts/lib/audit-exceptions/read.js +101 -0
- package/.agents/scripts/lib/audit-exceptions/record.js +102 -0
- package/.agents/scripts/lib/audit-exceptions/scope.js +131 -0
- package/.agents/scripts/lib/audit-exceptions/tickets.js +98 -0
- package/.agents/scripts/lib/audit-to-stories/audit-lenses.js +1 -0
- package/.agents/scripts/lib/config/temp-paths.js +15 -0
- package/.agents/scripts/lib/observability/source-classifier.js +1 -0
- package/.agents/scripts/lib/orchestration/single-story-close/runner.js +24 -3
- package/.agents/scripts/lib/orchestration/story-handoff.js +7 -0
- package/.agents/scripts/lib/orchestration/story-progress.js +127 -0
- package/.agents/workflows/audit-exceptions.md +235 -0
- package/docs/CHANGELOG.md +20 -0
- package/package.json +1 -1
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dependency policy exemptions: pnpm peer-dependency rules and allowed
|
|
3
|
+
* deprecations, Renovate ignores and disabled rules, and knip dependency
|
|
4
|
+
* ignores. Each names packages; an entry naming a package that is neither
|
|
5
|
+
* declared, nor in the tree, nor invoked by a script or CI workflow is `dead`.
|
|
6
|
+
*
|
|
7
|
+
* @module lib/audit-exceptions/adapters/dependency-policy
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { lineOfName } from '../locate.js';
|
|
11
|
+
import { readJsonc, readText } from '../read.js';
|
|
12
|
+
import { makeRecord } from '../record.js';
|
|
13
|
+
|
|
14
|
+
const RENOVATE_FILES = Object.freeze([
|
|
15
|
+
'renovate.json',
|
|
16
|
+
'renovate.jsonc',
|
|
17
|
+
'.renovaterc',
|
|
18
|
+
'.renovaterc.json',
|
|
19
|
+
'.github/renovate.json',
|
|
20
|
+
'.github/renovate.jsonc',
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
const KNIP_FILES = Object.freeze([
|
|
24
|
+
'knip.json',
|
|
25
|
+
'knip.jsonc',
|
|
26
|
+
'.knip.json',
|
|
27
|
+
'.knip.jsonc',
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
const PLAIN_NAME_RE = /^(?:@[\w.-]+\/)?[\w.-]+$/;
|
|
31
|
+
|
|
32
|
+
/** Text a package can be invoked from without being declared: scripts, CI, Dockerfiles. */
|
|
33
|
+
function invocationText(ctx) {
|
|
34
|
+
if (ctx.cache.invocationText === undefined) {
|
|
35
|
+
const scripts = ctx.scope.manifests.map((m) =>
|
|
36
|
+
JSON.stringify(m.pkg.scripts ?? {}),
|
|
37
|
+
);
|
|
38
|
+
const ci = ctx.scope.files
|
|
39
|
+
.filter(
|
|
40
|
+
(f) => f.startsWith('.github/workflows/') || /(^|\/)Dockerfile/.test(f),
|
|
41
|
+
)
|
|
42
|
+
.map((f) => readText(ctx.root, f) ?? '');
|
|
43
|
+
ctx.cache.invocationText = [...scripts, ...ci].join('\n');
|
|
44
|
+
}
|
|
45
|
+
return ctx.cache.invocationText;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param {object} ctx
|
|
50
|
+
* @param {string} name
|
|
51
|
+
* @returns {{ verdict: string, basis: string }}
|
|
52
|
+
*/
|
|
53
|
+
export function nameProbe(ctx, name) {
|
|
54
|
+
if (!PLAIN_NAME_RE.test(name))
|
|
55
|
+
return { verdict: 'unknown', basis: 'pattern-entry' };
|
|
56
|
+
const index = ctx.deps();
|
|
57
|
+
if (index.declared.has(name) || index.present?.has(name)) {
|
|
58
|
+
return { verdict: 'live', basis: 'package-in-tree' };
|
|
59
|
+
}
|
|
60
|
+
if (index.present === null)
|
|
61
|
+
return { verdict: 'unknown', basis: 'no-lockfile' };
|
|
62
|
+
if (invocationText(ctx).includes(name))
|
|
63
|
+
return { verdict: 'live', basis: 'invoked' };
|
|
64
|
+
return { verdict: 'dead', basis: 'package-not-in-tree' };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @param {object} ctx
|
|
69
|
+
* @param {object} opts - `anchors` are the section keys a name is searched
|
|
70
|
+
* after (see `lineOf`).
|
|
71
|
+
*/
|
|
72
|
+
function namesRecords(
|
|
73
|
+
ctx,
|
|
74
|
+
{ adapter, surface, file, text, names, justification, anchors },
|
|
75
|
+
) {
|
|
76
|
+
return names
|
|
77
|
+
.filter((n) => typeof n === 'string' && n.length > 0)
|
|
78
|
+
.map((name) =>
|
|
79
|
+
makeRecord({
|
|
80
|
+
adapter,
|
|
81
|
+
category: 'dependency',
|
|
82
|
+
surface,
|
|
83
|
+
file,
|
|
84
|
+
line: lineOfName(text, name, anchors),
|
|
85
|
+
target: name,
|
|
86
|
+
rule: surface,
|
|
87
|
+
justification,
|
|
88
|
+
probe: nameProbe(ctx, name),
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function peerRuleRecords(ctx, file, block, text, prefix = []) {
|
|
94
|
+
if (!block) return [];
|
|
95
|
+
const rules = block.peerDependencyRules ?? {};
|
|
96
|
+
const groups = [
|
|
97
|
+
['peerDependencyRules.ignoreMissing', rules.ignoreMissing ?? []],
|
|
98
|
+
['peerDependencyRules.allowAny', rules.allowAny ?? []],
|
|
99
|
+
[
|
|
100
|
+
'peerDependencyRules.allowedVersions',
|
|
101
|
+
Object.keys(rules.allowedVersions ?? {}),
|
|
102
|
+
],
|
|
103
|
+
[
|
|
104
|
+
'allowedDeprecatedVersions',
|
|
105
|
+
Object.keys(block.allowedDeprecatedVersions ?? {}),
|
|
106
|
+
],
|
|
107
|
+
];
|
|
108
|
+
return groups.flatMap(([surface, names]) =>
|
|
109
|
+
namesRecords(ctx, {
|
|
110
|
+
adapter: 'dependency-policy',
|
|
111
|
+
surface: `pnpm-${surface}`,
|
|
112
|
+
file,
|
|
113
|
+
text,
|
|
114
|
+
anchors: [...prefix, surface.split('.').pop()],
|
|
115
|
+
names: names.map((n) =>
|
|
116
|
+
String(n)
|
|
117
|
+
.split('>')
|
|
118
|
+
.pop()
|
|
119
|
+
.replace(/(.)@.*$/, '$1'),
|
|
120
|
+
),
|
|
121
|
+
justification: null,
|
|
122
|
+
}),
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function renovateRuleNames(rule) {
|
|
127
|
+
return [rule.matchPackageNames, rule.matchDepNames, rule.packageNames]
|
|
128
|
+
.flat()
|
|
129
|
+
.filter(
|
|
130
|
+
(n) => typeof n === 'string' && !n.startsWith('/') && !n.includes('*'),
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function renovateRecords(ctx, file, config, prefix = []) {
|
|
135
|
+
const text = readText(ctx.root, file);
|
|
136
|
+
const base = { adapter: 'dependency-policy', file, text };
|
|
137
|
+
const records = namesRecords(ctx, {
|
|
138
|
+
...base,
|
|
139
|
+
anchors: [...prefix, 'ignoreDeps'],
|
|
140
|
+
surface: 'renovate-ignoreDeps',
|
|
141
|
+
names: config.ignoreDeps ?? [],
|
|
142
|
+
justification: null,
|
|
143
|
+
});
|
|
144
|
+
for (const rule of config.packageRules ?? []) {
|
|
145
|
+
const surface =
|
|
146
|
+
rule.enabled === false
|
|
147
|
+
? 'renovate-disabled-rule'
|
|
148
|
+
: rule.allowedVersions
|
|
149
|
+
? 'renovate-allowedVersions'
|
|
150
|
+
: null;
|
|
151
|
+
if (!surface) continue;
|
|
152
|
+
records.push(
|
|
153
|
+
...namesRecords(ctx, {
|
|
154
|
+
...base,
|
|
155
|
+
anchors: [...prefix, 'packageRules'],
|
|
156
|
+
surface,
|
|
157
|
+
names: renovateRuleNames(rule),
|
|
158
|
+
justification: rule.description ?? null,
|
|
159
|
+
}),
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
return records;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function knipRecords(ctx, file, config, prefix = []) {
|
|
166
|
+
const text = readText(ctx.root, file);
|
|
167
|
+
return namesRecords(ctx, {
|
|
168
|
+
anchors: [...prefix, 'ignoreDependencies'],
|
|
169
|
+
adapter: 'dependency-policy',
|
|
170
|
+
surface: 'knip-ignoreDependencies',
|
|
171
|
+
file,
|
|
172
|
+
text,
|
|
173
|
+
names: (config.ignoreDependencies ?? []).filter(
|
|
174
|
+
(n) => typeof n === 'string',
|
|
175
|
+
),
|
|
176
|
+
justification: null,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function configFiles(ctx, candidates) {
|
|
181
|
+
return candidates
|
|
182
|
+
.filter((f) => ctx.scope.fileSet.has(f))
|
|
183
|
+
.map((f) => ({ file: f, config: readJsonc(ctx.root, f) }));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function readableConfigs(ctx, candidates, label) {
|
|
187
|
+
const found = configFiles(ctx, candidates);
|
|
188
|
+
for (const { file, config } of found) {
|
|
189
|
+
if (config === null)
|
|
190
|
+
ctx.degrade('config-not-statically-readable', `${label}: ${file}`);
|
|
191
|
+
}
|
|
192
|
+
return found.filter((f) => f.config !== null);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function extract(ctx) {
|
|
196
|
+
const records = [];
|
|
197
|
+
for (const m of ctx.scope.manifests) {
|
|
198
|
+
const text = readText(ctx.root, m.rel);
|
|
199
|
+
records.push(...peerRuleRecords(ctx, m.rel, m.pkg.pnpm, text, ['"pnpm"']));
|
|
200
|
+
if (m.pkg.renovate)
|
|
201
|
+
records.push(
|
|
202
|
+
...renovateRecords(ctx, m.rel, m.pkg.renovate, ['"renovate"']),
|
|
203
|
+
);
|
|
204
|
+
if (m.pkg.knip)
|
|
205
|
+
records.push(...knipRecords(ctx, m.rel, m.pkg.knip, ['"knip"']));
|
|
206
|
+
}
|
|
207
|
+
const yamlText = readText(ctx.root, 'pnpm-workspace.yaml');
|
|
208
|
+
records.push(
|
|
209
|
+
...peerRuleRecords(
|
|
210
|
+
ctx,
|
|
211
|
+
'pnpm-workspace.yaml',
|
|
212
|
+
ctx.scope.pnpmWorkspace,
|
|
213
|
+
yamlText,
|
|
214
|
+
),
|
|
215
|
+
);
|
|
216
|
+
if (ctx.scope.files.some((f) => f.endsWith('renovate.json5'))) {
|
|
217
|
+
ctx.degrade(
|
|
218
|
+
'config-not-statically-readable',
|
|
219
|
+
'renovate: json5 is not parsed',
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
for (const { file, config } of readableConfigs(
|
|
223
|
+
ctx,
|
|
224
|
+
RENOVATE_FILES,
|
|
225
|
+
'renovate',
|
|
226
|
+
)) {
|
|
227
|
+
records.push(...renovateRecords(ctx, file, config));
|
|
228
|
+
}
|
|
229
|
+
for (const { file, config } of readableConfigs(ctx, KNIP_FILES, 'knip')) {
|
|
230
|
+
records.push(...knipRecords(ctx, file, config));
|
|
231
|
+
}
|
|
232
|
+
return records;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export const dependencyPolicy = Object.freeze({
|
|
236
|
+
id: 'dependency-policy',
|
|
237
|
+
category: 'dependency',
|
|
238
|
+
applies: (ctx) =>
|
|
239
|
+
ctx.scope.manifests.length > 0
|
|
240
|
+
? { applies: true, reason: 'package manifests present' }
|
|
241
|
+
: { applies: false, reason: 'no package.json' },
|
|
242
|
+
extract,
|
|
243
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The adapter registry. Each adapter is `{ id, category, applies(ctx),
|
|
3
|
+
* extract(ctx) }`; adding a surface is one module plus one line here.
|
|
4
|
+
*
|
|
5
|
+
* @module lib/audit-exceptions/adapters
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { ciGates } from './ci-gates.js';
|
|
9
|
+
import { codeAllowlists } from './code-allowlists.js';
|
|
10
|
+
import { dependencyAudit } from './dependency-audit.js';
|
|
11
|
+
import { dependencyPatches } from './dependency-patches.js';
|
|
12
|
+
import { dependencyPins } from './dependency-pins.js';
|
|
13
|
+
import { dependencyPolicy } from './dependency-policy.js';
|
|
14
|
+
import { inlineSuppressions } from './inline-suppressions.js';
|
|
15
|
+
import { scaExceptions } from './sca-exceptions.js';
|
|
16
|
+
import { testSkips } from './test-skips.js';
|
|
17
|
+
import { toolConfig } from './tool-config.js';
|
|
18
|
+
|
|
19
|
+
export const ADAPTERS = Object.freeze([
|
|
20
|
+
inlineSuppressions,
|
|
21
|
+
toolConfig,
|
|
22
|
+
dependencyPins,
|
|
23
|
+
dependencyPatches,
|
|
24
|
+
dependencyPolicy,
|
|
25
|
+
dependencyAudit,
|
|
26
|
+
scaExceptions,
|
|
27
|
+
ciGates,
|
|
28
|
+
testSkips,
|
|
29
|
+
codeAllowlists,
|
|
30
|
+
]);
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline suppression comments: biome, eslint, TypeScript, coverage, markdownlint
|
|
3
|
+
* and prettier directives. Static reading cannot prove a suppression unused, so
|
|
4
|
+
* these records settle on their justification; `--probe` asks each tool which
|
|
5
|
+
* of them suppress nothing.
|
|
6
|
+
*
|
|
7
|
+
* @module lib/audit-exceptions/adapters/inline-suppressions
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { insideString } from '../locate.js';
|
|
11
|
+
import { readText } from '../read.js';
|
|
12
|
+
import { makeRecord } from '../record.js';
|
|
13
|
+
|
|
14
|
+
const SCANNED_EXT_RE =
|
|
15
|
+
/\.(?:[cm]?[jt]sx?|vue|svelte|astro|mdx?|css|scss|html)$/;
|
|
16
|
+
|
|
17
|
+
/** A directive only counts directly after a comment opener. */
|
|
18
|
+
const OPENER = String.raw`(?:\/\/+|\/\*+|<!--|^\s*\*)\s*`;
|
|
19
|
+
|
|
20
|
+
/** Each matcher: `re` over the text after the opener → `{ tool, rule, reason }`. */
|
|
21
|
+
const MATCHERS = Object.freeze([
|
|
22
|
+
{
|
|
23
|
+
re: /^biome-ignore(?:-all|-start)?\s+([^\s:]+)?\s*:?\s*(.*)$/,
|
|
24
|
+
parse: (m) => ({ tool: 'biome', rule: m[1] ?? '*', reason: m[2] }),
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
re: /^eslint-disable(?:-next-line|-line)?\b(.*?)(?:\s--\s(.*?))?\s*(?:\*\/.*)?$/,
|
|
28
|
+
parse: (m) => ({ tool: 'eslint', rule: m[1].trim() || '*', reason: m[2] }),
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
re: /^@ts-(expect-error|ignore|nocheck)\b\s*:?\s*(.*)$/,
|
|
32
|
+
parse: (m) => ({ tool: 'typescript', rule: `@ts-${m[1]}`, reason: m[2] }),
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
re: /^(c8|istanbul|node:coverage) ignore\s+(next|start|else|if|file)\b\s*(.*)$/,
|
|
36
|
+
parse: (m) => ({
|
|
37
|
+
tool: 'coverage',
|
|
38
|
+
rule: `${m[1]}-ignore-${m[2]}`,
|
|
39
|
+
reason: m[3],
|
|
40
|
+
}),
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
re: /^markdownlint-disable(?:-next-line|-line|-file)?\b\s*(.*?)\s*-->(.*)$/,
|
|
44
|
+
parse: (m) => ({ tool: 'markdownlint', rule: m[1] || '*', reason: m[2] }),
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
re: /^prettier-ignore\b(.*)$/,
|
|
48
|
+
parse: (m) => ({ tool: 'prettier', rule: 'prettier-ignore', reason: m[1] }),
|
|
49
|
+
},
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
const OPENER_RE = new RegExp(OPENER, 'g');
|
|
53
|
+
|
|
54
|
+
function matchLine(line) {
|
|
55
|
+
for (const opener of line.matchAll(OPENER_RE)) {
|
|
56
|
+
const rest = line.slice(opener.index + opener[0].length);
|
|
57
|
+
const hit = MATCHERS.find((m) => m.re.test(rest));
|
|
58
|
+
if (!hit) continue;
|
|
59
|
+
if (insideString(line, opener.index)) return null;
|
|
60
|
+
return hit.parse(hit.re.exec(rest));
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** A pure comment line directly above, used when the directive carries no reason. */
|
|
66
|
+
function reasonAbove(lines, i) {
|
|
67
|
+
const prev = lines[i - 1]?.trim() ?? '';
|
|
68
|
+
if (!/^(?:\/\/|\/\*|\*|<!--)/.test(prev) || matchLine(prev)) return null;
|
|
69
|
+
return prev.replace(/^(?:\/\/+|\/\*+|\*+|<!--)\s*|\s*(?:\*\/|-->)$/g, '');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function fileRecords(ctx, file) {
|
|
73
|
+
const lines = (readText(ctx.root, file) ?? '').split('\n');
|
|
74
|
+
const records = [];
|
|
75
|
+
lines.forEach((line, i) => {
|
|
76
|
+
const hit = matchLine(line);
|
|
77
|
+
if (!hit) return;
|
|
78
|
+
const reason =
|
|
79
|
+
hit.reason?.replace(/\s*(?:\*\/|-->)\s*$/, '') || reasonAbove(lines, i);
|
|
80
|
+
records.push(
|
|
81
|
+
makeRecord({
|
|
82
|
+
adapter: 'inline-suppressions',
|
|
83
|
+
category: 'inline',
|
|
84
|
+
surface: hit.tool,
|
|
85
|
+
file,
|
|
86
|
+
line: i + 1,
|
|
87
|
+
target: hit.rule,
|
|
88
|
+
rule: `${hit.tool}:${hit.rule}`,
|
|
89
|
+
justification: reason,
|
|
90
|
+
}),
|
|
91
|
+
);
|
|
92
|
+
});
|
|
93
|
+
return records;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export const inlineSuppressions = Object.freeze({
|
|
97
|
+
id: 'inline-suppressions',
|
|
98
|
+
category: 'inline',
|
|
99
|
+
applies: (ctx) =>
|
|
100
|
+
ctx.scope.files.some((f) => SCANNED_EXT_RE.test(f))
|
|
101
|
+
? { applies: true, reason: 'source files present' }
|
|
102
|
+
: { applies: false, reason: 'no scannable source files' },
|
|
103
|
+
extract: (ctx) =>
|
|
104
|
+
ctx.scope.files
|
|
105
|
+
.filter((f) => SCANNED_EXT_RE.test(f))
|
|
106
|
+
.flatMap((f) => fileRecords(ctx, f)),
|
|
107
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SCA gate's committed exceptions file (`audit-exceptions.json`):
|
|
3
|
+
* `{ exceptions: [{ id, package, reason, reviewBy }] }` — reviewed, dated
|
|
4
|
+
* suppressions of advisories that have no patched release. `reviewBy` is the
|
|
5
|
+
* entry's expiry; a package-scoped entry whose package left the tree is `dead`.
|
|
6
|
+
*
|
|
7
|
+
* @module lib/audit-exceptions/adapters/sca-exceptions
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { lineOf } from '../locate.js';
|
|
11
|
+
import { readJsonc, readText } from '../read.js';
|
|
12
|
+
import { makeRecord } from '../record.js';
|
|
13
|
+
import { nameProbe } from './dependency-policy.js';
|
|
14
|
+
|
|
15
|
+
const SCA_EXCEPTIONS_FILE = 'audit-exceptions.json';
|
|
16
|
+
|
|
17
|
+
function entryRecord(ctx, text, entry) {
|
|
18
|
+
const review =
|
|
19
|
+
typeof entry.reviewBy === 'string' ? ` expires: ${entry.reviewBy}` : '';
|
|
20
|
+
return makeRecord({
|
|
21
|
+
adapter: 'sca-exceptions',
|
|
22
|
+
category: 'dependency',
|
|
23
|
+
surface: 'sca-exceptions',
|
|
24
|
+
file: SCA_EXCEPTIONS_FILE,
|
|
25
|
+
line: lineOf(text, entry.id),
|
|
26
|
+
target: entry.package ? `${entry.id}|${entry.package}` : entry.id,
|
|
27
|
+
rule: 'sca-exceptions',
|
|
28
|
+
justification: entry.reason ? `${entry.reason}${review}` : null,
|
|
29
|
+
probe: entry.package
|
|
30
|
+
? nameProbe(ctx, entry.package)
|
|
31
|
+
: { verdict: 'live', basis: 'advisory-unprobed' },
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function extract(ctx) {
|
|
36
|
+
const config = readJsonc(ctx.root, SCA_EXCEPTIONS_FILE);
|
|
37
|
+
if (config === null) {
|
|
38
|
+
ctx.degrade('config-not-statically-readable', SCA_EXCEPTIONS_FILE);
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
const text = readText(ctx.root, SCA_EXCEPTIONS_FILE);
|
|
42
|
+
return (config.exceptions ?? [])
|
|
43
|
+
.filter((e) => typeof e?.id === 'string')
|
|
44
|
+
.map((e) => entryRecord(ctx, text, e));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const scaExceptions = Object.freeze({
|
|
48
|
+
id: 'sca-exceptions',
|
|
49
|
+
category: 'dependency',
|
|
50
|
+
applies: (ctx) =>
|
|
51
|
+
ctx.scope.fileSet.has(SCA_EXCEPTIONS_FILE)
|
|
52
|
+
? { applies: true, reason: `${SCA_EXCEPTIONS_FILE} present` }
|
|
53
|
+
: { applies: false, reason: `no ${SCA_EXCEPTIONS_FILE}` },
|
|
54
|
+
extract,
|
|
55
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test exemptions: `.skip` / `.todo` / `.fixme`, `x`-prefixed suites, and the
|
|
3
|
+
* `node:test` `{ skip }` / `{ todo }` option. A skip conditioned on the
|
|
4
|
+
* platform is legitimately forever and carries a `permanentHint`; a string
|
|
5
|
+
* skip value is its own justification.
|
|
6
|
+
*
|
|
7
|
+
* @module lib/audit-exceptions/adapters/test-skips
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { insideString } from '../locate.js';
|
|
11
|
+
import { readText } from '../read.js';
|
|
12
|
+
import { makeRecord } from '../record.js';
|
|
13
|
+
|
|
14
|
+
const TEST_FILE_RE =
|
|
15
|
+
/(?:^|\/)(?:__tests__|tests?|spec|e2e)\/.*\.[cm]?[jt]sx?$|\.(?:test|spec)\.[cm]?[jt]sx?$/;
|
|
16
|
+
|
|
17
|
+
const CALL_RE =
|
|
18
|
+
/\b(?:(?:it|test|describe|suite)\.(skip|todo|fixme)|(x)(?:it|describe|test))\s*\(\s*(['"`])((?:(?!\3).)*)\3/;
|
|
19
|
+
/**
|
|
20
|
+
* The `node:test` options object — as the second argument of a test call, or
|
|
21
|
+
* bound to a constant (`const POSIX_ONLY = { skip: … }`) — never an arbitrary
|
|
22
|
+
* object literal that happens to carry a `skip` key.
|
|
23
|
+
*/
|
|
24
|
+
const OPTION_RE =
|
|
25
|
+
/(?:\b(?:it|test|describe|suite)\s*\(\s*(['"`])(?:(?!\1).)*\1\s*,\s*|^\s*(?:export\s+)?(?:const|let|var)\s+\w+\s*=\s*)\{[^{}]*\b(skip|todo)\s*:\s*([^,}]+)/;
|
|
26
|
+
const PLATFORM_RE =
|
|
27
|
+
/process\.platform|os\.platform\(\)|\bisWindows\b|\bIS_WINDOWS\b|win32|darwin/;
|
|
28
|
+
|
|
29
|
+
function optionHit(line) {
|
|
30
|
+
const m = OPTION_RE.exec(line);
|
|
31
|
+
if (!m || insideString(line, m.index)) return null;
|
|
32
|
+
const value = m[3].trim();
|
|
33
|
+
if (/^(?:false|undefined|null)$/.test(value)) return null;
|
|
34
|
+
const literal = /^(['"`])(.*)\1$/.exec(value)?.[2];
|
|
35
|
+
const platform = PLATFORM_RE.test(value);
|
|
36
|
+
// A condition states its own reason: the test cannot run where it holds.
|
|
37
|
+
const conditional = value === 'true' ? null : `conditional: ${value}`;
|
|
38
|
+
return {
|
|
39
|
+
kind: m[2],
|
|
40
|
+
reason: literal ?? conditional,
|
|
41
|
+
permanentHint: platform ? 'platform-conditional' : null,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function matchLine(line) {
|
|
46
|
+
const call = CALL_RE.exec(line);
|
|
47
|
+
if (call && insideString(line, call.index)) return null;
|
|
48
|
+
if (call) {
|
|
49
|
+
const kind = call[1] ?? 'skip';
|
|
50
|
+
return {
|
|
51
|
+
kind,
|
|
52
|
+
reason: kind === 'skip' ? null : call[4],
|
|
53
|
+
permanentHint: null,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return optionHit(line);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function fileRecords(ctx, file) {
|
|
60
|
+
const lines = (readText(ctx.root, file) ?? '').split('\n');
|
|
61
|
+
const records = [];
|
|
62
|
+
lines.forEach((line, i) => {
|
|
63
|
+
const hit = matchLine(line);
|
|
64
|
+
if (!hit) return;
|
|
65
|
+
const prev = lines[i - 1]?.trim() ?? '';
|
|
66
|
+
records.push(
|
|
67
|
+
makeRecord({
|
|
68
|
+
adapter: 'test-skips',
|
|
69
|
+
category: 'test',
|
|
70
|
+
surface: 'test-runner',
|
|
71
|
+
file,
|
|
72
|
+
line: i + 1,
|
|
73
|
+
target: hit.kind,
|
|
74
|
+
rule: hit.kind,
|
|
75
|
+
justification:
|
|
76
|
+
hit.reason ??
|
|
77
|
+
(prev.startsWith('//') ? prev.replace(/^\/+\s*/, '') : null),
|
|
78
|
+
permanentHint: hit.permanentHint,
|
|
79
|
+
}),
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
return records;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const testSkips = Object.freeze({
|
|
86
|
+
id: 'test-skips',
|
|
87
|
+
category: 'test',
|
|
88
|
+
applies: (ctx) =>
|
|
89
|
+
ctx.scope.files.some((f) => TEST_FILE_RE.test(f))
|
|
90
|
+
? { applies: true, reason: 'test files present' }
|
|
91
|
+
: { applies: false, reason: 'no test files' },
|
|
92
|
+
extract: (ctx) =>
|
|
93
|
+
ctx.scope.files
|
|
94
|
+
.filter((f) => TEST_FILE_RE.test(f))
|
|
95
|
+
.flatMap((f) => fileRecords(ctx, f)),
|
|
96
|
+
});
|