@vaultcompass/conductor 0.5.0 → 0.7.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/README.md +305 -32
- package/dist/cli.js +214 -50
- package/dist/gate-runner.js +12 -2
- package/dist/normalize.d.ts +13 -2
- package/dist/normalize.js +137 -8
- package/dist/output-sarif.js +58 -0
- package/dist/output-text.d.ts +33 -0
- package/dist/output-text.js +139 -22
- package/dist/products.d.ts +16 -0
- package/dist/products.js +9 -0
- package/dist/run.d.ts +40 -0
- package/dist/run.js +39 -1
- package/dist/trust-base.d.ts +68 -0
- package/dist/trust-base.js +152 -0
- package/package.json +4 -3
package/dist/cli.js
CHANGED
|
@@ -7,16 +7,16 @@
|
|
|
7
7
|
// decisions be tested without a subprocess.
|
|
8
8
|
import { Command, CommanderError } from 'commander';
|
|
9
9
|
import { execFileSync } from 'node:child_process';
|
|
10
|
-
import { readFileSync, realpathSync, writeFileSync } from 'node:fs';
|
|
10
|
+
import { readFileSync, realpathSync, statSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
11
11
|
import path from 'node:path';
|
|
12
12
|
import { fileURLToPath } from 'node:url';
|
|
13
13
|
import { EXIT_BLOCKED, EXIT_COULD_NOT_RUN, EXIT_OK } from './exit-codes.js';
|
|
14
14
|
import { applyInit, planInit, renderInitHuman, renderRevertHuman, revertInit, } from './init.js';
|
|
15
15
|
import { renderSarif } from './output-sarif.js';
|
|
16
|
-
import { jobLogSummary, renderText } from './output-text.js';
|
|
16
|
+
import { jobLogSummary, renderText, verdictToken } from './output-text.js';
|
|
17
17
|
import { GATE_ROLES, GATE_STAGES, POLICY_FILE_NAME, PolicyError, applyCliOverrides, loadPolicy, parsePolicy, } from './policy.js';
|
|
18
18
|
import { refusedTrustBase, runAll } from './run.js';
|
|
19
|
-
import { policyDiffers, readPolicyAtRef, refuseTrustBaseRef } from './trust-base.js';
|
|
19
|
+
import { headTreeEqualsBase, policyDiffers, readPolicyAtRef, refuseTrustBaseForPullRequest, refuseTrustBaseRef, } from './trust-base.js';
|
|
20
20
|
const pkgPath = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'package.json');
|
|
21
21
|
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
|
|
22
22
|
/**
|
|
@@ -39,6 +39,30 @@ const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
|
|
|
39
39
|
* one line on stderr with no stack and the could-not-run exit code, so
|
|
40
40
|
* nothing here has to know about either.
|
|
41
41
|
*/
|
|
42
|
+
/**
|
|
43
|
+
* True when `cwd` is itself a `.git` directory (or another directory git
|
|
44
|
+
* manages as one, such as a worktree's own git dir), rather than a working
|
|
45
|
+
* tree with no repository at all.
|
|
46
|
+
*
|
|
47
|
+
* Only consulted once `--show-toplevel` has already failed, so the extra
|
|
48
|
+
* spawn is on an error path already about to fail the whole command, never
|
|
49
|
+
* on the path every ordinary run takes. Both failure shapes exit non-zero,
|
|
50
|
+
* so this is what tells "point conductor at a .git directory" apart from
|
|
51
|
+
* "point conductor at a plain, ungoverned directory" without guessing from
|
|
52
|
+
* the path's spelling.
|
|
53
|
+
*/
|
|
54
|
+
function isGitDirectory(cwd) {
|
|
55
|
+
try {
|
|
56
|
+
return (execFileSync('git', ['rev-parse', '--is-inside-git-dir'], {
|
|
57
|
+
cwd,
|
|
58
|
+
encoding: 'utf8',
|
|
59
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
60
|
+
}).trim() === 'true');
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
42
66
|
function repoRoot(cwd) {
|
|
43
67
|
try {
|
|
44
68
|
return execFileSync('git', ['rev-parse', '--show-toplevel'], {
|
|
@@ -56,6 +80,10 @@ function repoRoot(cwd) {
|
|
|
56
80
|
// git ran and refused. The directory is named because it is the one
|
|
57
81
|
// thing the reader has to check, and it is the directory they typed
|
|
58
82
|
// the command in rather than anything internal to this tool.
|
|
83
|
+
if (isGitDirectory(cwd)) {
|
|
84
|
+
throw new Error(`${cwd} is a git directory, not a working tree. Point conductor at the repository's ` +
|
|
85
|
+
'working tree instead of at its .git directory.');
|
|
86
|
+
}
|
|
59
87
|
throw new Error(`not a git repository: ${cwd}. conductor anchors every gate at the working-tree ` +
|
|
60
88
|
'root, so run it inside a checkout.');
|
|
61
89
|
}
|
|
@@ -65,6 +93,54 @@ function repoRoot(cwd) {
|
|
|
65
93
|
throw new Error(`git could not be run to find the repository root: ${err.message}`);
|
|
66
94
|
}
|
|
67
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* The repository root for one command, from --project when it was given and
|
|
98
|
+
* from the working directory otherwise (issue #55).
|
|
99
|
+
*
|
|
100
|
+
* --project changes WHERE the repository is, never WHAT is trusted: once
|
|
101
|
+
* resolved, the root it names goes through the exact same discovery as the
|
|
102
|
+
* working directory always has, `repoRoot`'s own `git rev-parse
|
|
103
|
+
* --show-toplevel`, so a subdirectory of a repository resolves to that
|
|
104
|
+
* repository's top level exactly as a bare `conductor init` or `conductor
|
|
105
|
+
* run` from that subdirectory already does. Nothing downstream of this
|
|
106
|
+
* function -- the trust-base checks, the node_modules/.bin skip on a
|
|
107
|
+
* pull-request run, the program-vetting rules -- reads the working directory
|
|
108
|
+
* again; every one of them takes this root explicitly.
|
|
109
|
+
*
|
|
110
|
+
* A relative value resolves against the working directory, never against
|
|
111
|
+
* anything already discovered, so this has to run before any git call. A
|
|
112
|
+
* path that does not exist, is not a directory, or is not inside a git
|
|
113
|
+
* repository is a usage error naming the path, never a silent fall back to
|
|
114
|
+
* the working directory: guessing which repository a scripted caller meant
|
|
115
|
+
* is how a CI job ends up gating the wrong tree while reporting a clean run
|
|
116
|
+
* of nothing.
|
|
117
|
+
*/
|
|
118
|
+
function resolveProjectRoot(cwd, project) {
|
|
119
|
+
if (project === undefined) {
|
|
120
|
+
return repoRoot(cwd);
|
|
121
|
+
}
|
|
122
|
+
const resolved = path.resolve(cwd, project);
|
|
123
|
+
let stat;
|
|
124
|
+
try {
|
|
125
|
+
stat = statSync(resolved);
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
throw new Error(`--project ${project}: no such directory (resolved to ${resolved}).`);
|
|
129
|
+
}
|
|
130
|
+
if (!stat.isDirectory()) {
|
|
131
|
+
throw new Error(`--project ${project}: not a directory (resolved to ${resolved}).`);
|
|
132
|
+
}
|
|
133
|
+
// repoRoot names `resolved` in its own "not a git repository" sentence,
|
|
134
|
+
// which is what makes that refusal name the path here too, without a
|
|
135
|
+
// second, separately-worded check that could drift from the one bare `cwd`
|
|
136
|
+
// already goes through.
|
|
137
|
+
return repoRoot(resolved);
|
|
138
|
+
}
|
|
139
|
+
const PROJECT_OPTION_HELP = 'run against this directory instead of the current one, resolved to its repository root ' +
|
|
140
|
+
'the same way the current directory already is: a subdirectory resolves to the top of that ' +
|
|
141
|
+
'repository. Relative values resolve against the current directory. A path that does not ' +
|
|
142
|
+
'exist, is not a directory, or is not inside a git repository is a usage error (exit 2) ' +
|
|
143
|
+
'naming the path, never a silent fall back to the current directory.';
|
|
68
144
|
/**
|
|
69
145
|
* The process exit code for a run, with --advisory applied.
|
|
70
146
|
*
|
|
@@ -127,11 +203,22 @@ function inventoryFromHead(root, overrides) {
|
|
|
127
203
|
return { version: 1, gates: {}, report: { format: 'text' } };
|
|
128
204
|
}
|
|
129
205
|
}
|
|
130
|
-
function policyForRun(root, trustBase, overrides) {
|
|
206
|
+
function policyForRun(root, trustBase, overrides, githubBaseRef) {
|
|
131
207
|
if (trustBase === undefined) {
|
|
132
208
|
return { kind: 'policy', policy: applyCliOverrides(loadPolicy(root), overrides) };
|
|
133
209
|
}
|
|
134
|
-
|
|
210
|
+
// DEFENCE IN DEPTH, ISSUE #58. action.yml's validate step already refuses
|
|
211
|
+
// an explicit trust-base input outright on a pull_request event; this is
|
|
212
|
+
// the same rule for anyone invoking the CLI directly in CI, bypassing that
|
|
213
|
+
// step. Checked BEFORE refuseTrustBaseRef and deliberately narrower than
|
|
214
|
+
// it: it says nothing about HEAD or about tree equality, only about
|
|
215
|
+
// whether the given ref agrees with origin/<GITHUB_BASE_REF>, which is
|
|
216
|
+
// exactly what the composite action itself always passes. So on an
|
|
217
|
+
// ordinary pull-request run this returns null immediately and
|
|
218
|
+
// refuseTrustBaseRef runs its own checks unchanged, the equal-tree
|
|
219
|
+
// first-parent exception (issue #69/#73) included.
|
|
220
|
+
const pullRequestRefusal = refuseTrustBaseForPullRequest(root, trustBase, githubBaseRef);
|
|
221
|
+
const refusal = pullRequestRefusal ?? refuseTrustBaseRef(root, trustBase);
|
|
135
222
|
if (refusal !== null) {
|
|
136
223
|
return {
|
|
137
224
|
kind: 'refused',
|
|
@@ -191,6 +278,12 @@ function policyForRun(root, trustBase, overrides) {
|
|
|
191
278
|
ref: trustBase,
|
|
192
279
|
policyChanged: policyDiffers(baseText, headText),
|
|
193
280
|
refusal: null,
|
|
281
|
+
// Computed AFTER refuseTrustBaseRef has already returned null, on the
|
|
282
|
+
// one shape that check accepts despite an identical tree: a merge
|
|
283
|
+
// commit whose first parent is this ref (issue #69). runAll reads this
|
|
284
|
+
// to run only the gates whose profile says readsHistory and to report
|
|
285
|
+
// every other enabled gate as tree-unchanged instead of spawning it.
|
|
286
|
+
treeUnchanged: headTreeEqualsBase(root, trustBase),
|
|
194
287
|
},
|
|
195
288
|
};
|
|
196
289
|
}
|
|
@@ -254,50 +347,84 @@ export function buildProgram() {
|
|
|
254
347
|
.option('--force', 'act on a file that has changed since init wrote it: replace a managed hook somebody has ' +
|
|
255
348
|
'edited (needs --hook), or with --revert remove one and restore any adopted hook')
|
|
256
349
|
.option('--json', 'print the result as JSON')
|
|
350
|
+
.option('--project <dir>', PROJECT_OPTION_HELP)
|
|
257
351
|
.exitOverride()
|
|
258
352
|
.action((options) => {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
353
|
+
try {
|
|
354
|
+
// options.project === undefined takes the EXACT path main always
|
|
355
|
+
// did: process.cwd() straight through, with no resolveProjectRoot
|
|
356
|
+
// call at all. planInit and revertInit already do their own
|
|
357
|
+
// repoRootOf(options.cwd) and report a non-repository as a
|
|
358
|
+
// structured conflict (not-a-git-repository, JSON under --json,
|
|
359
|
+
// exit 2 through the ordinary result.ok branch below) rather than
|
|
360
|
+
// throwing, and planInit checks flag-requires-hook (--adopt or
|
|
361
|
+
// --force without --hook) BEFORE it ever asks whether it is in a
|
|
362
|
+
// repository at all. Calling resolveProjectRoot unconditionally
|
|
363
|
+
// here used to short-circuit both of those: it threw its own
|
|
364
|
+
// differently-worded, JSON-less error before planInit ever ran, so
|
|
365
|
+
// a plain "conductor init" outside a repository stopped matching
|
|
366
|
+
// main, and "--adopt" without "--hook" outside a repository
|
|
367
|
+
// reported the wrong conflict. Only an EXPLICIT --project goes
|
|
368
|
+
// through resolveProjectRoot, whose own usage errors (a path that
|
|
369
|
+
// does not exist, is not a directory, or is not inside a git
|
|
370
|
+
// repository) are new behaviour this flag introduces on purpose.
|
|
371
|
+
const cwd = options.project === undefined
|
|
372
|
+
? process.cwd()
|
|
373
|
+
: resolveProjectRoot(process.cwd(), options.project);
|
|
374
|
+
const shared = { cwd, pathValue: process.env.PATH ?? '' };
|
|
375
|
+
if (options.revert) {
|
|
376
|
+
const result = revertInit({
|
|
377
|
+
...shared,
|
|
378
|
+
force: Boolean(options.force),
|
|
379
|
+
dryRun: Boolean(options.dryRun),
|
|
380
|
+
});
|
|
381
|
+
const rendered = `${renderRevertHuman(result)}\n`;
|
|
382
|
+
if (options.json) {
|
|
383
|
+
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
384
|
+
}
|
|
385
|
+
else if (result.ok) {
|
|
386
|
+
process.stdout.write(rendered);
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
// A partial revert left something behind, so it is not success
|
|
390
|
+
// output. Writing it to stdout would let a script pipe it past a
|
|
391
|
+
// reader who needed to see it.
|
|
392
|
+
process.stderr.write(rendered);
|
|
393
|
+
}
|
|
394
|
+
process.exitCode = result.ok ? 0 : EXIT_COULD_NOT_RUN;
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
const initOptions = {
|
|
263
398
|
...shared,
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
399
|
+
...(options.dryRun === undefined ? {} : { dryRun: options.dryRun }),
|
|
400
|
+
...(options.hook === undefined ? {} : { hook: options.hook }),
|
|
401
|
+
...(options.adopt === undefined ? {} : { adopt: options.adopt }),
|
|
402
|
+
...(options.force === undefined ? {} : { force: options.force }),
|
|
403
|
+
};
|
|
404
|
+
const result = applyInit(planInit(initOptions), initOptions);
|
|
268
405
|
if (options.json) {
|
|
269
406
|
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
270
407
|
}
|
|
271
408
|
else if (result.ok) {
|
|
272
|
-
process.stdout.write(
|
|
409
|
+
process.stdout.write(`${renderInitHuman(result)}\n`);
|
|
273
410
|
}
|
|
274
411
|
else {
|
|
275
|
-
|
|
276
|
-
// output. Writing it to stdout would let a script pipe it past a
|
|
277
|
-
// reader who needed to see it.
|
|
278
|
-
process.stderr.write(rendered);
|
|
412
|
+
process.stderr.write(`${renderInitHuman(result)}\n`);
|
|
279
413
|
}
|
|
280
414
|
process.exitCode = result.ok ? 0 : EXIT_COULD_NOT_RUN;
|
|
281
|
-
return;
|
|
282
415
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
else if (result.ok) {
|
|
295
|
-
process.stdout.write(`${renderInitHuman(result)}\n`);
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
process.stderr.write(`${renderInitHuman(result)}\n`);
|
|
416
|
+
catch (err) {
|
|
417
|
+
// planInit, applyInit and revertInit report every ordinary
|
|
418
|
+
// conflict as a structured result rather than throwing, exactly as
|
|
419
|
+
// they did before this flag existed, so in practice only an
|
|
420
|
+
// explicit --project's own usage error reaches here. But this is
|
|
421
|
+
// not narrowed to that: any throw from this block lands here and
|
|
422
|
+
// gets the same one-line, no-stack treatment main's own outer catch
|
|
423
|
+
// gives an uncaught error, which is what this local catch replaces
|
|
424
|
+
// for the init command, the same shape "run"'s own catch below
|
|
425
|
+
// uses for the same kind of failure.
|
|
426
|
+
process.exitCode = fail(`conductor: ${err instanceof Error ? err.message : String(err)}`);
|
|
299
427
|
}
|
|
300
|
-
process.exitCode = result.ok ? 0 : EXIT_COULD_NOT_RUN;
|
|
301
428
|
});
|
|
302
429
|
program
|
|
303
430
|
.command('run')
|
|
@@ -308,28 +435,40 @@ export function buildProgram() {
|
|
|
308
435
|
.option('--base <ref>', 'measure the intent gate against what this branch changed since <ref>, rather than against the index. In Actions this defaults to origin/<GITHUB_BASE_REF> when it is set.')
|
|
309
436
|
.option('--trust-base <ref>', 'pull-request mode: read .guardrails.yaml from this ref instead of from the tree being judged, and pass the same ref to every gate that supports it. A policy change in the pull request is reported as a proposal and never takes effect for the run, so a pull request cannot change the rules it is judged by. In Actions the composite action passes origin/<GITHUB_BASE_REF> on a pull_request event.')
|
|
310
437
|
.option('--output <path>', 'write the report to this file instead of to stdout, for a CI step that uploads it')
|
|
438
|
+
.option('--text-report <path>', 'with --format sarif, also write the text report to this file, from the same run: exactly what --format text would have rendered for this result, --verbose, --compact-on-refusal and --advisory respected, and no gate is run a second time. In a full report (any run that is not fully clean, or any run with --verbose) the second line is "verdict-token: <token>"; the one-line summary of a clean run without --verbose has none. The token is a label for this run\'s own exit decision: pass, advisory-blocked (N), unenforced-findings (N), blocked (N) or could-not-run. Only meaningful with --format sarif: with --format text the text report is already the output, so the combination is a usage error (exit 2).')
|
|
311
439
|
.option('--spec <path>', 'the spec the intent gate imports its contract from, outranking a Spec: line in the pull request body and the branch-name convention')
|
|
312
440
|
.option('--verbose', 'print the full per-gate report even when the run is clean. A clean run prints one summary line by default, because a pre-commit hook that prints a screenful on every commit is a hook a team switches off. Text output only; SARIF is unaffected.')
|
|
313
441
|
.option('--compact-on-refusal', 'when the trust base was refused and no gate ran, print a short body instead of the full refusal report: the version, the verdict, and the refusal reason (with its remedy, when one applies), never the full per-gate report. Built for the pull-request-comment step; every other run is unaffected, whatever --verbose says. Text output only; SARIF is unaffected.')
|
|
314
442
|
.option('--gate <role>', 'restrict the run to this role; repeatable', (value, previous = []) => [...previous, value])
|
|
315
443
|
.option('--advisory', 'maps exit 1 (every enabled gate ran and at least one blocked) to exit 0, so a blocking finding never fails this run. A gate that could not run is unaffected and still exits 2: advisory changes what a FINDING does, never what a broken gate does. The report is unchanged and a blocking finding still prints as BLOCKING; only the process exit code and the verdict line, which says findings were advisory, are different.')
|
|
444
|
+
.option('--project <dir>', PROJECT_OPTION_HELP)
|
|
316
445
|
.exitOverride()
|
|
317
446
|
.action((options) => {
|
|
318
447
|
const cwd = process.cwd();
|
|
448
|
+
let textReportPath;
|
|
319
449
|
try {
|
|
320
|
-
// Inside the try, because
|
|
321
|
-
// and the catch below is what turns
|
|
322
|
-
// one line on stderr and the could-not-run
|
|
323
|
-
|
|
450
|
+
// Inside the try, because resolveProjectRoot (like repoRoot before
|
|
451
|
+
// it) reports rather than guesses, and the catch below is what turns
|
|
452
|
+
// any of its sentences into one line on stderr and the could-not-run
|
|
453
|
+
// exit code.
|
|
454
|
+
const root = resolveProjectRoot(cwd, options.project);
|
|
324
455
|
const overrides = {
|
|
325
456
|
...(parseRoles(options.gate) === undefined
|
|
326
457
|
? {}
|
|
327
458
|
: { gates: parseRoles(options.gate) }),
|
|
328
459
|
};
|
|
329
460
|
const stage = parseStage(options.stage);
|
|
330
|
-
const source = policyForRun(root, options.trustBase, overrides);
|
|
461
|
+
const source = policyForRun(root, options.trustBase, overrides, process.env.GITHUB_BASE_REF);
|
|
331
462
|
const policy = source.kind === 'policy' ? source.policy : source.inventory;
|
|
332
463
|
const format = parseFormat(options.format ?? policy.report.format);
|
|
464
|
+
// BEFORE ANY GATE RUNS. With --format text the text report already is
|
|
465
|
+
// the run's output, so a second copy of it in a file is not something
|
|
466
|
+
// this option can add: refused as a usage error rather than accepted
|
|
467
|
+
// and ignored, which would leave a caller reading a file that was
|
|
468
|
+
// never written, or one that duplicates stdout.
|
|
469
|
+
if (options.textReport !== undefined && format !== 'sarif') {
|
|
470
|
+
throw new PolicyError('--text-report is only meaningful with --format sarif: with --format text the text report is the output already.');
|
|
471
|
+
}
|
|
333
472
|
const result = source.kind === 'refused'
|
|
334
473
|
? refusedTrustBase(source.inventory, source.ref, source.detail, {
|
|
335
474
|
...(stage === undefined ? {} : { stage }),
|
|
@@ -349,14 +488,16 @@ export function buildProgram() {
|
|
|
349
488
|
// there: each finding's `properties.blocking` is the gate's own
|
|
350
489
|
// decision (see output-sarif.ts) and is unaffected by this flag,
|
|
351
490
|
// exactly as the text report's per-finding BLOCKING marker is.
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
:
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
491
|
+
const renderTextReport = () => renderText(result, {
|
|
492
|
+
verbose: Boolean(options.verbose),
|
|
493
|
+
version: pkg.version,
|
|
494
|
+
compact: Boolean(options.compactOnRefusal),
|
|
495
|
+
advisory,
|
|
496
|
+
});
|
|
497
|
+
const rendered = format === 'sarif' ? `${renderSarif(result, pkg.version)}\n` : renderTextReport();
|
|
498
|
+
// The SAME result, rendered a second time, never a second run: the
|
|
499
|
+
// token in this file is for the run that set the exit code below.
|
|
500
|
+
const textReport = options.textReport === undefined ? undefined : renderTextReport();
|
|
360
501
|
if (options.output === undefined) {
|
|
361
502
|
process.stdout.write(rendered);
|
|
362
503
|
}
|
|
@@ -367,6 +508,18 @@ export function buildProgram() {
|
|
|
367
508
|
// worst of the available answers: the upload step downstream would
|
|
368
509
|
// fail on a missing file with no explanation here.
|
|
369
510
|
writeFileSync(options.output, rendered);
|
|
511
|
+
}
|
|
512
|
+
// WRITTEN LAST, after the SARIF log or stdout, and removed again in
|
|
513
|
+
// the catch below if anything after it throws. A run that exits 2
|
|
514
|
+
// because a write failed must never leave a finished text report on
|
|
515
|
+
// disk: the action would read a clean report and publish a pass, and
|
|
516
|
+
// post it as a comment, beside a red job. A text report that cannot
|
|
517
|
+
// be written takes the could-not-run code, like an unwritable --output.
|
|
518
|
+
if (options.textReport !== undefined && textReport !== undefined) {
|
|
519
|
+
textReportPath = options.textReport;
|
|
520
|
+
writeFileSync(options.textReport, textReport);
|
|
521
|
+
}
|
|
522
|
+
if (options.output !== undefined) {
|
|
370
523
|
// One line, so a CI job whose only product is an uploaded artifact
|
|
371
524
|
// does not read as a job that did nothing. jobLogSummary carries
|
|
372
525
|
// its own "N gate(s), N finding(s)" on an ordinary run, unchanged,
|
|
@@ -375,11 +528,22 @@ export function buildProgram() {
|
|
|
375
528
|
// outcome per enabled gate, so the plain count used to read as
|
|
376
529
|
// "N gate(s), N finding(s)" on a run where nothing ran and nothing
|
|
377
530
|
// was found (issue #46).
|
|
378
|
-
process.stdout.write(`conductor run: ${jobLogSummary(result)}; ${
|
|
531
|
+
process.stdout.write(`conductor run: ${jobLogSummary(result)}; verdict-token ${verdictToken(result, advisory)}; ` +
|
|
532
|
+
`${format} report written to ${options.output}\n`);
|
|
379
533
|
}
|
|
380
534
|
process.exitCode = applyAdvisory(result.exitCode, advisory);
|
|
381
535
|
}
|
|
382
536
|
catch (err) {
|
|
537
|
+
// A text report this run already wrote (or half wrote) is removed:
|
|
538
|
+
// this run exits 2, and no report may say otherwise.
|
|
539
|
+
if (textReportPath !== undefined) {
|
|
540
|
+
try {
|
|
541
|
+
unlinkSync(textReportPath);
|
|
542
|
+
}
|
|
543
|
+
catch {
|
|
544
|
+
// Nothing to remove, or not removable; the exit code stands.
|
|
545
|
+
}
|
|
546
|
+
}
|
|
383
547
|
// One line, never a stack. runGate is total, so nothing from a gate
|
|
384
548
|
// reaches here; anything that does is the umbrella's own problem and
|
|
385
549
|
// still must not put a local filesystem path in front of a user who
|
package/dist/gate-runner.js
CHANGED
|
@@ -409,11 +409,17 @@ function probeVersion(binary, product, repoRoot, timeoutMs) {
|
|
|
409
409
|
* `context.blocked` is whether the gate's exit said it blocked. The npm gates
|
|
410
410
|
* carry that in their own JSON and ignore it; the external tools' reports do
|
|
411
411
|
* not, so their normalizers take it from here.
|
|
412
|
+
*
|
|
413
|
+
* `context.online` and `context.lockfiles` are read from the umbrella's OWN
|
|
414
|
+
* constructed argv, never from a gate's JSON (issue #72): whether --online
|
|
415
|
+
* was passed and which lockfiles were handed over with --lockfile are
|
|
416
|
+
* questions about what this run asked for, which the umbrella already knows
|
|
417
|
+
* before the child ever answers.
|
|
412
418
|
*/
|
|
413
419
|
function normalizeFor(product, parsed, version, context) {
|
|
414
420
|
switch (product) {
|
|
415
421
|
case 'dep-guard':
|
|
416
|
-
return normalizeDepGuard(parsed, version);
|
|
422
|
+
return normalizeDepGuard(parsed, version, context.online);
|
|
417
423
|
case 'vault-guard':
|
|
418
424
|
return normalizeVaultGuard(parsed, version);
|
|
419
425
|
case 'intent-guard':
|
|
@@ -421,7 +427,7 @@ function normalizeFor(product, parsed, version, context) {
|
|
|
421
427
|
case 'gitleaks':
|
|
422
428
|
return normalizeGitleaks(parsed, version, context.blocked);
|
|
423
429
|
case 'osv-scanner':
|
|
424
|
-
return normalizeOsvScanner(parsed, version, context.blocked, context.roots);
|
|
430
|
+
return normalizeOsvScanner(parsed, version, context.blocked, context.roots, context.lockfiles);
|
|
425
431
|
}
|
|
426
432
|
}
|
|
427
433
|
/**
|
|
@@ -1046,6 +1052,10 @@ function spawnAndRead(ctx) {
|
|
|
1046
1052
|
const normalized = normalizeFor(gate.product, parsed, version, {
|
|
1047
1053
|
blocked,
|
|
1048
1054
|
roots: rootSpellings(options.repoRoot),
|
|
1055
|
+
// The literal flag, read off the argv this run actually spawned with,
|
|
1056
|
+
// not off gate.options: the argv is what dep-guard was actually told.
|
|
1057
|
+
online: argv.includes('--online'),
|
|
1058
|
+
lockfiles: external.lockfiles ?? [],
|
|
1049
1059
|
});
|
|
1050
1060
|
return {
|
|
1051
1061
|
...withRun,
|
package/dist/normalize.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { type Finding, type NormalizedGateOutput, type Severity } from './envelope.js';
|
|
2
2
|
import type { GateRole, Product } from './policy.js';
|
|
3
|
-
export declare function normalizeDepGuard(raw: unknown, version: string | null
|
|
3
|
+
export declare function normalizeDepGuard(raw: unknown, version: string | null,
|
|
4
|
+
/** Whether the umbrella passed --online to dep-guard, read from its own argv. */
|
|
5
|
+
onlineRequested?: boolean): NormalizedGateOutput;
|
|
4
6
|
export declare function normalizeVaultGuard(raw: unknown, version: string | null): NormalizedGateOutput;
|
|
7
|
+
/**
|
|
8
|
+
* intent-guard's own namespace for its advance-notice warnings, not the
|
|
9
|
+
* umbrella's: the umbrella never mints a `conductor/` id for this, because
|
|
10
|
+
* the statement being relayed is entirely intent-guard's own (see AGENTS.md
|
|
11
|
+
* on the umbrella's fixed set of ids).
|
|
12
|
+
*/
|
|
13
|
+
export declare const INTENT_WARNING = "intent-guard/warning";
|
|
5
14
|
/**
|
|
6
15
|
* The three ways the intent gate can block on the STATE of the contract
|
|
7
16
|
* rather than on anything in the diff.
|
|
@@ -41,7 +50,9 @@ export declare function normalizeGitleaks(raw: unknown, version: string | null,
|
|
|
41
50
|
export declare function cvssToSeverity(score: number | null): Severity;
|
|
42
51
|
export declare function normalizeOsvScanner(raw: unknown, version: string | null, blocked: boolean,
|
|
43
52
|
/** The scan root as a path osv-scanner may have printed it, in any spelling. */
|
|
44
|
-
roots?: readonly string[]
|
|
53
|
+
roots?: readonly string[],
|
|
54
|
+
/** The lockfiles the umbrella passed with --lockfile, repository-relative. */
|
|
55
|
+
lockfiles?: readonly string[]): NormalizedGateOutput;
|
|
45
56
|
export type GateProblemRule = 'conductor/gate-missing' | 'conductor/gate-output-unparseable' | 'conductor/gate-failed';
|
|
46
57
|
/**
|
|
47
58
|
* The finding raised when an ENABLED gate's binary cannot be found.
|