@vaultcompass/conductor 0.2.3 → 0.2.4
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/dist/cli.js +5 -1
- package/dist/init.d.ts +15 -1
- package/dist/init.js +215 -33
- package/dist/output-text.js +32 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -125,7 +125,11 @@ export function buildProgram() {
|
|
|
125
125
|
const cwd = process.cwd();
|
|
126
126
|
const shared = { cwd, pathValue: process.env.PATH ?? '' };
|
|
127
127
|
if (options.revert) {
|
|
128
|
-
const result = revertInit({
|
|
128
|
+
const result = revertInit({
|
|
129
|
+
...shared,
|
|
130
|
+
force: Boolean(options.force),
|
|
131
|
+
dryRun: Boolean(options.dryRun),
|
|
132
|
+
});
|
|
129
133
|
const rendered = `${renderRevertHuman(result)}\n`;
|
|
130
134
|
if (options.json) {
|
|
131
135
|
process.stdout.write(`${JSON.stringify(result)}\n`);
|
package/dist/init.d.ts
CHANGED
|
@@ -40,7 +40,14 @@ export type ConflictReason = 'not-a-git-repository' | 'foreign-hook' | 'gate-hoo
|
|
|
40
40
|
* remedy is different -- there is no config file of the manager's own to
|
|
41
41
|
* point at, only a key in package.json that conductor will not write.
|
|
42
42
|
*/
|
|
43
|
-
| 'managed-hooks' | 'hooks-path-outside-repository'
|
|
43
|
+
| 'managed-hooks' | 'hooks-path-outside-repository'
|
|
44
|
+
/**
|
|
45
|
+
* A path recorded in the manifest resolves outside the repository. The
|
|
46
|
+
* manifest is a committed, untrusted file, so revert and apply refuse any
|
|
47
|
+
* path in it that is not contained rather than writing or deleting where it
|
|
48
|
+
* points.
|
|
49
|
+
*/
|
|
50
|
+
| 'manifest-path-outside-repository' | 'no-manifest' | 'manifest-unreadable' | 'changed-since-init' | 'write-failed';
|
|
44
51
|
export interface InitConflict {
|
|
45
52
|
path: string;
|
|
46
53
|
reason: ConflictReason;
|
|
@@ -121,6 +128,13 @@ export interface RevertResult {
|
|
|
121
128
|
ok: boolean;
|
|
122
129
|
actions: InitAction[];
|
|
123
130
|
conflicts: InitConflict[];
|
|
131
|
+
/**
|
|
132
|
+
* A dry run planned the revert and touched nothing. The actions describe
|
|
133
|
+
* what it WOULD have removed or restored, and `ok` is what the same revert
|
|
134
|
+
* would have returned for real, so `--revert --dry-run` exits the way the
|
|
135
|
+
* revert it previews would.
|
|
136
|
+
*/
|
|
137
|
+
dryRun: boolean;
|
|
124
138
|
}
|
|
125
139
|
/**
|
|
126
140
|
* Removes exactly what init wrote, and nothing else.
|
package/dist/init.js
CHANGED
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
// as installed. See detectManagedHook and declaredManagedHooks.
|
|
66
66
|
import { createHash } from 'node:crypto';
|
|
67
67
|
import { execFileSync } from 'node:child_process';
|
|
68
|
-
import { chmodSync, existsSync, mkdirSync, readFileSync, realpathSync, rmSync, rmdirSync, statSync, writeFileSync, } from 'node:fs';
|
|
68
|
+
import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync, rmdirSync, statSync, writeFileSync, } from 'node:fs';
|
|
69
69
|
import path from 'node:path';
|
|
70
70
|
import { DEFAULT_STAGE_FOR_ROLE, GATE_ROLES, POLICY_FILE_NAME, PRODUCT_FOR_ROLE } from './policy.js';
|
|
71
71
|
import { CANDIDATES } from './resolve.js';
|
|
@@ -436,6 +436,93 @@ exit "$conductor_status"
|
|
|
436
436
|
function sha256(content) {
|
|
437
437
|
return createHash('sha256').update(content).digest('hex');
|
|
438
438
|
}
|
|
439
|
+
/**
|
|
440
|
+
* Whether a path the manifest names is contained to the repository.
|
|
441
|
+
*
|
|
442
|
+
* The manifest is committed input, so a path in it is whatever a commit put
|
|
443
|
+
* there. Revert and apply run this over every path they would write to or
|
|
444
|
+
* delete before touching anything, and refuse the whole operation if any one
|
|
445
|
+
* of them is not contained.
|
|
446
|
+
*
|
|
447
|
+
* Two conditions, because a path can escape two ways. The resolved path,
|
|
448
|
+
* treated as plain strings, must be inside the root: this refuses an absolute
|
|
449
|
+
* path and one that climbs out with ../. And no component of the path may be a
|
|
450
|
+
* SYMLINK. A committed dangling symlink (its target does not exist) is the case
|
|
451
|
+
* that broke an earlier version of this: existsSync FOLLOWS the link, finds the
|
|
452
|
+
* missing target, and reports the link absent, so a walk that resolved only the
|
|
453
|
+
* deepest existing ancestor judged the link a plain not-yet-existing leaf and
|
|
454
|
+
* let writeFileSync and chmodSync, which DO follow the final link, land the
|
|
455
|
+
* write on the outside target. lstatSync does not follow, so it catches a
|
|
456
|
+
* symlink component even when its target is gone. init never writes through a
|
|
457
|
+
* symlink, so a symlink anywhere along the path means this is not a path init
|
|
458
|
+
* wrote, and it is refused whatever it points at.
|
|
459
|
+
*
|
|
460
|
+
* Paths here need not exist yet: an adopted hook is restored to a path revert
|
|
461
|
+
* has just removed, and a recorded file may be legitimately gone. The scan
|
|
462
|
+
* stops at the first component that does not exist, because nothing below a
|
|
463
|
+
* missing component exists either, so there is no symlink left to find. A
|
|
464
|
+
* relative candidate is taken against the repository root, which is how the
|
|
465
|
+
* real attack lands: a person running revert has cd'd into the checkout.
|
|
466
|
+
*/
|
|
467
|
+
function manifestPathInsideRepo(repoRoot, candidate) {
|
|
468
|
+
try {
|
|
469
|
+
const root = realpathSync(repoRoot);
|
|
470
|
+
const abs = path.resolve(root, candidate);
|
|
471
|
+
// Deepest ancestor of abs that exists on disk. realpathSync on the whole
|
|
472
|
+
// path throws when the leaf is not there, so resolve the part that exists
|
|
473
|
+
// and keep the rest as a tail. existsSync FOLLOWS symlinks, which is why a
|
|
474
|
+
// dangling symlink is not trusted here; the tail is scanned with lstatSync
|
|
475
|
+
// below.
|
|
476
|
+
let ancestor = abs;
|
|
477
|
+
while (!existsSync(ancestor)) {
|
|
478
|
+
const parent = path.dirname(ancestor);
|
|
479
|
+
if (parent === ancestor) {
|
|
480
|
+
break;
|
|
481
|
+
}
|
|
482
|
+
ancestor = parent;
|
|
483
|
+
}
|
|
484
|
+
const realAncestor = realpathSync(ancestor);
|
|
485
|
+
const tail = path.relative(ancestor, abs);
|
|
486
|
+
// Containment, on resolved paths so a macOS temp dir reached through
|
|
487
|
+
// /var -> /private/var does not read as an escape, and so an existing
|
|
488
|
+
// symlink directory that points outside is caught by its resolved target.
|
|
489
|
+
const resolved = tail === '' ? realAncestor : path.join(realAncestor, tail);
|
|
490
|
+
const inside = path.relative(root, resolved);
|
|
491
|
+
if (inside === '' ||
|
|
492
|
+
inside === '..' ||
|
|
493
|
+
inside.startsWith(`..${path.sep}`) ||
|
|
494
|
+
path.isAbsolute(inside)) {
|
|
495
|
+
return false;
|
|
496
|
+
}
|
|
497
|
+
// No component of the tail may be a symlink. lstatSync does not follow, so
|
|
498
|
+
// a committed DANGLING symlink is caught even though existsSync reported it
|
|
499
|
+
// absent: existsSync followed the link to its missing target, which let an
|
|
500
|
+
// earlier version treat the link as a plain not-yet-existing leaf and then
|
|
501
|
+
// let writeFileSync and chmodSync, which DO follow the final link, land the
|
|
502
|
+
// write on the outside target. init never writes through a symlink, so any
|
|
503
|
+
// symlink component means this is not a path init wrote. The scan starts at
|
|
504
|
+
// the resolved ancestor, whose own components are already real, and walks
|
|
505
|
+
// to the leaf, stopping at the first component that does not exist.
|
|
506
|
+
let current = realAncestor;
|
|
507
|
+
for (const segment of tail === '' ? [] : tail.split(path.sep)) {
|
|
508
|
+
current = path.join(current, segment);
|
|
509
|
+
let entry;
|
|
510
|
+
try {
|
|
511
|
+
entry = lstatSync(current);
|
|
512
|
+
}
|
|
513
|
+
catch {
|
|
514
|
+
break;
|
|
515
|
+
}
|
|
516
|
+
if (entry.isSymbolicLink()) {
|
|
517
|
+
return false;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return true;
|
|
521
|
+
}
|
|
522
|
+
catch {
|
|
523
|
+
return false;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
439
526
|
function gitOutput(cwd, args) {
|
|
440
527
|
try {
|
|
441
528
|
return execFileSync('git', args, {
|
|
@@ -942,6 +1029,30 @@ export function applyInit(plan, options) {
|
|
|
942
1029
|
product: plan.adoptedFrom.product,
|
|
943
1030
|
},
|
|
944
1031
|
};
|
|
1032
|
+
// Contain every path before writing, the same rule revert applies. These
|
|
1033
|
+
// paths are computed by planning rather than read straight from the manifest,
|
|
1034
|
+
// but the adopted record is carried forward from the committed manifest, and
|
|
1035
|
+
// a write that lands outside the repository is a write apply should refuse
|
|
1036
|
+
// whatever produced the path.
|
|
1037
|
+
const escaping = [
|
|
1038
|
+
...plan.writes.map((write) => write.path),
|
|
1039
|
+
...(manifest.adopted === null ? [] : [manifest.adopted.path]),
|
|
1040
|
+
].filter((candidate) => !manifestPathInsideRepo(plan.repoRoot, candidate));
|
|
1041
|
+
if (escaping.length > 0) {
|
|
1042
|
+
return {
|
|
1043
|
+
...plan,
|
|
1044
|
+
ok: false,
|
|
1045
|
+
conflicts: [
|
|
1046
|
+
...plan.conflicts,
|
|
1047
|
+
...escaping.map((candidate) => ({
|
|
1048
|
+
path: candidate,
|
|
1049
|
+
reason: 'manifest-path-outside-repository',
|
|
1050
|
+
guidance: `${candidate} resolves outside this repository, so nothing was written. Apply ` +
|
|
1051
|
+
'contains every path it writes to the repository.',
|
|
1052
|
+
})),
|
|
1053
|
+
],
|
|
1054
|
+
};
|
|
1055
|
+
}
|
|
945
1056
|
try {
|
|
946
1057
|
for (const write of plan.writes) {
|
|
947
1058
|
mkdirSync(path.dirname(write.path), { recursive: true });
|
|
@@ -1028,6 +1139,12 @@ export function revertInit(options) {
|
|
|
1028
1139
|
const actions = [];
|
|
1029
1140
|
const conflicts = [];
|
|
1030
1141
|
const force = Boolean(options.force);
|
|
1142
|
+
// A dry run runs every read and every decision and skips only the writes,
|
|
1143
|
+
// so what it reports is exactly what a real revert from the same state would
|
|
1144
|
+
// do. The CLI routed --revert past --dry-run and revertInit had no branch
|
|
1145
|
+
// for it, so the flag whose help promised it would write nothing performed a
|
|
1146
|
+
// real destructive revert.
|
|
1147
|
+
const dryRun = Boolean(options.dryRun);
|
|
1031
1148
|
const root = repoRootOf(options.cwd);
|
|
1032
1149
|
if (root === null) {
|
|
1033
1150
|
conflicts.push({
|
|
@@ -1035,7 +1152,7 @@ export function revertInit(options) {
|
|
|
1035
1152
|
reason: 'not-a-git-repository',
|
|
1036
1153
|
guidance: 'Nothing to revert: this is not a git repository.',
|
|
1037
1154
|
});
|
|
1038
|
-
return { ok: false, actions, conflicts };
|
|
1155
|
+
return { ok: false, actions, conflicts, dryRun };
|
|
1039
1156
|
}
|
|
1040
1157
|
const manifestPath = path.join(root, MANIFEST_RELATIVE_PATH);
|
|
1041
1158
|
const raw = readIfExists(manifestPath);
|
|
@@ -1046,7 +1163,7 @@ export function revertInit(options) {
|
|
|
1046
1163
|
guidance: `No ${MANIFEST_RELATIVE_PATH}, so there is no record of what init wrote. Nothing was ` +
|
|
1047
1164
|
"removed: guessing which files were ours is how a revert deletes somebody's work.",
|
|
1048
1165
|
});
|
|
1049
|
-
return { ok: false, actions, conflicts };
|
|
1166
|
+
return { ok: false, actions, conflicts, dryRun };
|
|
1050
1167
|
}
|
|
1051
1168
|
// Not routed through readManifest, which answers null for both a missing
|
|
1052
1169
|
// file and an unparseable one. Revert has to tell those apart: a missing
|
|
@@ -1068,9 +1185,32 @@ export function revertInit(options) {
|
|
|
1068
1185
|
'anything. Only then delete it and remove the hook and the policy file yourself, and ' +
|
|
1069
1186
|
're-run init.',
|
|
1070
1187
|
});
|
|
1071
|
-
return { ok: false, actions, conflicts };
|
|
1188
|
+
return { ok: false, actions, conflicts, dryRun };
|
|
1072
1189
|
}
|
|
1073
1190
|
const relative = (file) => path.relative(root, file).split(path.sep).join('/');
|
|
1191
|
+
// The manifest is committed input, so every path it names is contained to
|
|
1192
|
+
// the repository before anything is written or deleted. A crafted manifest
|
|
1193
|
+
// could otherwise make revert delete a file anywhere on disk, or, through
|
|
1194
|
+
// adopted.path, write an executable one anywhere, and exit 0. Refused as a
|
|
1195
|
+
// whole rather than skipped one path at a time: a manifest with a path that
|
|
1196
|
+
// escapes is a manifest nothing should act on.
|
|
1197
|
+
const escaping = [
|
|
1198
|
+
...manifest.files.map((file) => file.path),
|
|
1199
|
+
...(manifest.adopted === null ? [] : [manifest.adopted.path]),
|
|
1200
|
+
].filter((candidate) => !manifestPathInsideRepo(root, candidate));
|
|
1201
|
+
if (escaping.length > 0) {
|
|
1202
|
+
for (const candidate of escaping) {
|
|
1203
|
+
conflicts.push({
|
|
1204
|
+
path: relative(candidate),
|
|
1205
|
+
reason: 'manifest-path-outside-repository',
|
|
1206
|
+
guidance: `${candidate} is recorded in ${MANIFEST_RELATIVE_PATH} but resolves outside this ` +
|
|
1207
|
+
'repository, so nothing was written or removed. The manifest is a committed file, and ' +
|
|
1208
|
+
'a path in it that points out of the repository is not one revert will act on. Repair ' +
|
|
1209
|
+
'or delete the manifest by hand.',
|
|
1210
|
+
});
|
|
1211
|
+
}
|
|
1212
|
+
return { ok: false, actions, conflicts, dryRun };
|
|
1213
|
+
}
|
|
1074
1214
|
const planned = manifest.files.map((file) => {
|
|
1075
1215
|
const current = readIfExists(file.path);
|
|
1076
1216
|
const state = current === undefined ? 'gone' : sha256(current) === file.sha256 ? 'match' : 'changed';
|
|
@@ -1094,7 +1234,7 @@ export function revertInit(options) {
|
|
|
1094
1234
|
detail: entry.state === 'changed' ? 'changed since init, left alone' : 'left alone',
|
|
1095
1235
|
});
|
|
1096
1236
|
}
|
|
1097
|
-
return { ok: false, actions, conflicts };
|
|
1237
|
+
return { ok: false, actions, conflicts, dryRun };
|
|
1098
1238
|
}
|
|
1099
1239
|
const remaining = [];
|
|
1100
1240
|
for (const { file, state } of planned) {
|
|
@@ -1113,7 +1253,9 @@ export function revertInit(options) {
|
|
|
1113
1253
|
remaining.push(file);
|
|
1114
1254
|
continue;
|
|
1115
1255
|
}
|
|
1116
|
-
|
|
1256
|
+
if (!dryRun) {
|
|
1257
|
+
rmSync(file.path, { force: true });
|
|
1258
|
+
}
|
|
1117
1259
|
actions.push({
|
|
1118
1260
|
kind: 'remove',
|
|
1119
1261
|
path: rel,
|
|
@@ -1134,12 +1276,24 @@ export function revertInit(options) {
|
|
|
1134
1276
|
// the flag and restore a hook next to a surviving one. existsSync says what
|
|
1135
1277
|
// is there, which is the thing the rule is about.
|
|
1136
1278
|
const recordedHooks = planned.filter((entry) => entry.file.kind === 'hook');
|
|
1137
|
-
const umbrellaHookGone = recordedHooks.length > 0 &&
|
|
1279
|
+
const umbrellaHookGone = recordedHooks.length > 0 &&
|
|
1280
|
+
recordedHooks.every((entry) =>
|
|
1281
|
+
// A dry run left the hook on disk, so existsSync would say it is still
|
|
1282
|
+
// there and the restore would be mispredicted. Ask the plan instead:
|
|
1283
|
+
// every recorded hook that reached this point is either already gone or
|
|
1284
|
+
// slated for removal, because a changed hook with no --force returns at
|
|
1285
|
+
// the blocked-hook check far above, so by here a 'changed' state means
|
|
1286
|
+
// --force is on.
|
|
1287
|
+
dryRun
|
|
1288
|
+
? entry.state === 'gone' || entry.state === 'match' || force
|
|
1289
|
+
: !existsSync(entry.file.path));
|
|
1138
1290
|
let adopted = manifest.adopted;
|
|
1139
1291
|
if (adopted !== null && umbrellaHookGone) {
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1292
|
+
if (!dryRun) {
|
|
1293
|
+
mkdirSync(path.dirname(adopted.path), { recursive: true });
|
|
1294
|
+
writeFileSync(adopted.path, adopted.content, 'utf8');
|
|
1295
|
+
chmodSync(adopted.path, 0o755);
|
|
1296
|
+
}
|
|
1143
1297
|
actions.push({
|
|
1144
1298
|
kind: 'restore',
|
|
1145
1299
|
path: relative(adopted.path),
|
|
@@ -1148,39 +1302,57 @@ export function revertInit(options) {
|
|
|
1148
1302
|
adopted = null;
|
|
1149
1303
|
}
|
|
1150
1304
|
if (remaining.length === 0 && adopted === null) {
|
|
1151
|
-
|
|
1305
|
+
if (!dryRun) {
|
|
1306
|
+
rmSync(manifestPath, { force: true });
|
|
1307
|
+
}
|
|
1152
1308
|
actions.push({ kind: 'remove', path: MANIFEST_RELATIVE_PATH, detail: 'removed' });
|
|
1153
1309
|
const manifestDir = path.dirname(MANIFEST_RELATIVE_PATH);
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
//
|
|
1157
|
-
//
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1310
|
+
const dirWouldBeEmpty = () => readdirSync(path.dirname(manifestPath)).every((entry) => path.join(path.dirname(manifestPath), entry) === manifestPath);
|
|
1311
|
+
if (dryRun) {
|
|
1312
|
+
// A dry run cannot rmdir to find out whether the directory would be
|
|
1313
|
+
// empty, so it looks: with the manifest gone, is anything else left?
|
|
1314
|
+
actions.push(dirWouldBeEmpty()
|
|
1315
|
+
? { kind: 'remove', path: manifestDir, detail: 'removed, it was empty' }
|
|
1316
|
+
: {
|
|
1317
|
+
kind: 'skip',
|
|
1318
|
+
path: manifestDir,
|
|
1319
|
+
detail: 'kept: it holds something else, which is not ours to remove',
|
|
1320
|
+
});
|
|
1162
1321
|
}
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
path
|
|
1171
|
-
|
|
1172
|
-
}
|
|
1322
|
+
else {
|
|
1323
|
+
try {
|
|
1324
|
+
// rmdirSync, not rmSync: rmSync on a directory without recursive: true
|
|
1325
|
+
// throws before it removes anything, so this swallowed its own error
|
|
1326
|
+
// every time and left an empty .guardrails behind after a revert that
|
|
1327
|
+
// said it had removed everything. rmdirSync removes an empty directory
|
|
1328
|
+
// and refuses a non-empty one, which is exactly the rule wanted here.
|
|
1329
|
+
rmdirSync(path.dirname(manifestPath));
|
|
1330
|
+
actions.push({ kind: 'remove', path: manifestDir, detail: 'removed, it was empty' });
|
|
1331
|
+
}
|
|
1332
|
+
catch {
|
|
1333
|
+
// The directory holds something else, so it stays. Reported rather
|
|
1334
|
+
// than passed over: a directory this tool created and then left
|
|
1335
|
+
// behind, with nothing said about it, reads as something revert
|
|
1336
|
+
// forgot rather than as something it decided.
|
|
1337
|
+
actions.push({
|
|
1338
|
+
kind: 'skip',
|
|
1339
|
+
path: manifestDir,
|
|
1340
|
+
detail: 'kept: it holds something else, which is not ours to remove',
|
|
1341
|
+
});
|
|
1342
|
+
}
|
|
1173
1343
|
}
|
|
1174
|
-
return { ok: true, actions, conflicts };
|
|
1344
|
+
return { ok: true, actions, conflicts, dryRun };
|
|
1175
1345
|
}
|
|
1176
1346
|
// Something is left, so the manifest stays and keeps describing it.
|
|
1177
|
-
|
|
1347
|
+
if (!dryRun) {
|
|
1348
|
+
writeFileSync(manifestPath, `${JSON.stringify({ ...manifest, files: remaining, adopted }, null, 2)}\n`, 'utf8');
|
|
1349
|
+
}
|
|
1178
1350
|
actions.push({
|
|
1179
1351
|
kind: 'skip',
|
|
1180
1352
|
path: MANIFEST_RELATIVE_PATH,
|
|
1181
1353
|
detail: 'kept: it still records what was left behind',
|
|
1182
1354
|
});
|
|
1183
|
-
return { ok: false, actions, conflicts };
|
|
1355
|
+
return { ok: false, actions, conflicts, dryRun };
|
|
1184
1356
|
}
|
|
1185
1357
|
export function renderInitHuman(result) {
|
|
1186
1358
|
const lines = [];
|
|
@@ -1214,8 +1386,18 @@ export function renderRevertHuman(result) {
|
|
|
1214
1386
|
if (result.ok) {
|
|
1215
1387
|
lines[0] = 'conductor init --revert:';
|
|
1216
1388
|
}
|
|
1389
|
+
if (result.dryRun) {
|
|
1390
|
+
// Every action here is what a real revert WOULD do, so the header and the
|
|
1391
|
+
// verbs say so, and the summary above is rewritten: nothing was removed
|
|
1392
|
+
// because nothing is ever removed on a dry run.
|
|
1393
|
+
lines[0] =
|
|
1394
|
+
removed === 0
|
|
1395
|
+
? 'conductor init --revert (dry run): would remove nothing.'
|
|
1396
|
+
: 'conductor init --revert (dry run): would change the files below, and write nothing now.';
|
|
1397
|
+
}
|
|
1217
1398
|
for (const action of result.actions) {
|
|
1218
|
-
|
|
1399
|
+
const verb = result.dryRun && action.kind !== 'skip' ? `would ${action.kind}` : action.kind;
|
|
1400
|
+
lines.push(` ${verb} ${action.path} (${action.detail})`);
|
|
1219
1401
|
}
|
|
1220
1402
|
// The conflicts go LAST rather than first, so the thing the user has to
|
|
1221
1403
|
// act on is the last line on their terminal rather than scrolled off the
|
package/dist/output-text.js
CHANGED
|
@@ -417,9 +417,15 @@ function summaryLine(result) {
|
|
|
417
417
|
// is the easiest of the three to lose: a --gate run is usually somebody
|
|
418
418
|
// narrowing a run on purpose, and a log of it that says nothing about the
|
|
419
419
|
// narrowing is the log that gets uploaded and read as a full run later.
|
|
420
|
+
// Counted even at zero for the same suppression reason as the enforcement
|
|
421
|
+
// count above: a gate the command line dropped had no vote, and "0 gate(s)
|
|
422
|
+
// left out by --gate" says the run was not narrowed.
|
|
420
423
|
if (result.excluded.length > 0) {
|
|
421
424
|
const names = result.excluded.map((gate) => `${gate.role} (${gate.product})`).join(', ');
|
|
422
|
-
parts.push(
|
|
425
|
+
parts.push(`${result.excluded.length} gate(s) left out by --gate: ${names}.`);
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
parts.push('0 gate(s) left out by --gate.');
|
|
423
429
|
}
|
|
424
430
|
// A gate that ran with enforce: false could not have failed this run
|
|
425
431
|
// whatever it found. Naming it among the gates that ran and then saying
|
|
@@ -428,10 +434,19 @@ function summaryLine(result) {
|
|
|
428
434
|
// full report says this in the line under that gate's findings; on a clean
|
|
429
435
|
// run there are no findings, so the summary line is the only place left to
|
|
430
436
|
// say it.
|
|
437
|
+
//
|
|
438
|
+
// Printed as a count even when it is zero. This is the family suppression
|
|
439
|
+
// rule: a gate that can be turned off is the user's decision, and a clean
|
|
440
|
+
// line that says nothing about enforcement lets a repository read as fully
|
|
441
|
+
// gated when a gate's result did not move the exit code. "0 gate(s) not
|
|
442
|
+
// enforced" is the umbrella saying every gate that ran had a vote.
|
|
431
443
|
const unenforced = result.gates.filter((gate) => !gate.enforce);
|
|
432
444
|
if (unenforced.length > 0) {
|
|
433
445
|
const names = unenforced.map((gate) => `${gate.role} (${gate.product})`).join(', ');
|
|
434
|
-
parts.push(
|
|
446
|
+
parts.push(`${unenforced.length} gate(s) not enforced, could not have blocked, enforce: false in .guardrails.yaml: ${names}.`);
|
|
447
|
+
}
|
|
448
|
+
else {
|
|
449
|
+
parts.push('0 gate(s) not enforced.');
|
|
435
450
|
}
|
|
436
451
|
// Non-blocking findings are counted rather than hidden, for the same reason
|
|
437
452
|
// the full report prints the suppressed and ignored counts at zero: they
|
|
@@ -448,6 +463,21 @@ function summaryLine(result) {
|
|
|
448
463
|
if (counts.length > 0) {
|
|
449
464
|
parts.push(`${counts.join(', ')}.`);
|
|
450
465
|
}
|
|
466
|
+
// The suppressed and ignored counts the gates reported, summed across them
|
|
467
|
+
// and printed even at zero. The full report prints these per gate for the
|
|
468
|
+
// same reason, so a quiet report is not mistaken for a clean one; the clean
|
|
469
|
+
// summary line is the one a hook and a pull request comment actually print,
|
|
470
|
+
// and it is where a repository baselining findings without saying so would
|
|
471
|
+
// otherwise read as clean. Suppressed always shows because it is always a
|
|
472
|
+
// number the gate reported. Ignored shows only when every gate that ran
|
|
473
|
+
// reported it: a gate that drops ignored files before its own output has no
|
|
474
|
+
// count to give, and "0 ignored" there would state a fact no gate stated.
|
|
475
|
+
const suppressed = result.gates.reduce((total, gate) => total + gate.run.suppressed, 0);
|
|
476
|
+
const gatesReportingIgnored = result.gates.filter((gate) => gate.run.details.ignoredReported !== false);
|
|
477
|
+
const ignored = gatesReportingIgnored.reduce((total, gate) => total + gate.run.ignored, 0);
|
|
478
|
+
parts.push(gatesReportingIgnored.length === result.gates.length
|
|
479
|
+
? `${suppressed} suppressed, ${ignored} ignored across all gates.`
|
|
480
|
+
: `${suppressed} suppressed across all gates.`);
|
|
451
481
|
parts.push('Re-run with --verbose for the full report.');
|
|
452
482
|
return parts.join(' ');
|
|
453
483
|
}
|