@webpieces/pr-gate 0.4.822 → 0.4.824
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/package.json +5 -3
- package/src/dashboard/checklist-comment-renderer.js +6 -4
- package/src/dashboard/checklist-comment-renderer.js.map +1 -1
- package/src/dashboard/dashboard.js +6 -1
- package/src/dashboard/dashboard.js.map +1 -1
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -1
- package/src/index.js.map +1 -1
- package/src/scripts/commands/build-command.d.ts +3 -0
- package/src/scripts/commands/build-command.js +29 -17
- package/src/scripts/commands/build-command.js.map +1 -1
- package/src/scripts/commands/check-pr-command.d.ts +10 -3
- package/src/scripts/commands/check-pr-command.js +31 -10
- package/src/scripts/commands/check-pr-command.js.map +1 -1
- package/src/scripts/commands/finish-upsert-pr-command.d.ts +4 -1
- package/src/scripts/commands/finish-upsert-pr-command.js +26 -5
- package/src/scripts/commands/finish-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/human-post-pr-command.d.ts +52 -0
- package/src/scripts/commands/human-post-pr-command.js +260 -0
- package/src/scripts/commands/human-post-pr-command.js.map +1 -0
- package/src/scripts/commands/review-upsert-pr-command.d.ts +3 -1
- package/src/scripts/commands/review-upsert-pr-command.js +40 -23
- package/src/scripts/commands/review-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/write-review-command.d.ts +3 -1
- package/src/scripts/commands/write-review-command.js +9 -3
- package/src/scripts/commands/write-review-command.js.map +1 -1
- package/src/scripts/commands/write-review-fixes-command.d.ts +21 -0
- package/src/scripts/commands/write-review-fixes-command.js +68 -0
- package/src/scripts/commands/write-review-fixes-command.js.map +1 -0
- package/src/scripts/pr-gate-app.d.ts +9 -1
- package/src/scripts/pr-gate-app.js +18 -1
- package/src/scripts/pr-gate-app.js.map +1 -1
- package/src/scripts/workflow/build-affected.d.ts +3 -0
- package/src/scripts/workflow/build-affected.js +16 -3
- package/src/scripts/workflow/build-affected.js.map +1 -1
- package/src/scripts/workflow/build-gate-log.d.ts +4 -1
- package/src/scripts/workflow/build-gate-log.js +20 -5
- package/src/scripts/workflow/build-gate-log.js.map +1 -1
- package/src/scripts/workflow/build-log-follower.d.ts +13 -0
- package/src/scripts/workflow/build-log-follower.js +48 -0
- package/src/scripts/workflow/build-log-follower.js.map +1 -0
- package/src/scripts/workflow/checklist-scanner.d.ts +1 -3
- package/src/scripts/workflow/checklist-scanner.js +6 -9
- package/src/scripts/workflow/checklist-scanner.js.map +1 -1
- package/src/scripts/workflow/gated-pr-publisher.d.ts +1 -1
- package/src/scripts/workflow/gated-pr-publisher.js +20 -7
- package/src/scripts/workflow/gated-pr-publisher.js.map +1 -1
- package/src/scripts/workflow/push-dev-state.js +30 -17
- package/src/scripts/workflow/push-dev-state.js.map +1 -1
- package/src/scripts/workflow/repo-config-testkit.js +2 -0
- package/src/scripts/workflow/repo-config-testkit.js.map +1 -1
- package/src/scripts/workflow/review-report.d.ts +7 -4
- package/src/scripts/workflow/review-report.js +44 -24
- package/src/scripts/workflow/review-report.js.map +1 -1
- package/src/scripts/workflow/review-round-state.d.ts +58 -0
- package/src/scripts/workflow/review-round-state.js +300 -0
- package/src/scripts/workflow/review-round-state.js.map +1 -0
- package/src/scripts/workflow/review-stage-receipt.d.ts +6 -0
- package/src/scripts/workflow/review-stage-receipt.js +13 -0
- package/src/scripts/workflow/review-stage-receipt.js.map +1 -1
- package/src/scripts/workflow/reviewer-verdict-gate.js +6 -24
- package/src/scripts/workflow/reviewer-verdict-gate.js.map +1 -1
- package/src/scripts/workflow/verdict-provenance.d.ts +3 -8
- package/src/scripts/workflow/verdict-provenance.js +7 -17
- package/src/scripts/workflow/verdict-provenance.js.map +1 -1
- package/src/scripts/wp-human-post-pr.d.ts +2 -0
- package/src/scripts/wp-human-post-pr.js +15 -0
- package/src/scripts/wp-human-post-pr.js.map +1 -0
- package/src/scripts/wp-write-review-fixes.d.ts +2 -0
- package/src/scripts/wp-write-review-fixes.js +16 -0
- package/src/scripts/wp-write-review-fixes.js.map +1 -0
- package/src/scripts/workflow/git-validateUpToDate.d.ts +0 -1
- package/src/scripts/workflow/git-validateUpToDate.js +0 -70
- package/src/scripts/workflow/git-validateUpToDate.js.map +0 -1
|
@@ -76,13 +76,23 @@ let BuildCommand = class BuildCommand {
|
|
|
76
76
|
this.homeConfig = homeConfig;
|
|
77
77
|
}
|
|
78
78
|
run(opts) {
|
|
79
|
+
return this.runGate(opts, false);
|
|
80
|
+
}
|
|
81
|
+
/** Human-terminal form used by wp-human-post-pr; build.log remains complete while output is live. */
|
|
82
|
+
runStreaming(opts) {
|
|
83
|
+
return this.runGate(opts, true);
|
|
84
|
+
}
|
|
85
|
+
runGate(opts, stream) {
|
|
79
86
|
const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());
|
|
80
87
|
if (!opts.force)
|
|
81
88
|
this.assertMachineHasRoom();
|
|
82
89
|
// runBuildGate announces the resolved command, runs it, and throws CliExitError on failure so
|
|
83
90
|
// runMain owns the exit — the same three things it does for stage ② and stage ③. It also writes
|
|
84
91
|
// this build's START/DONE pair to the ledger the check above just read.
|
|
85
|
-
|
|
92
|
+
const gateOptions = new build_affected_1.BuildGateOptions('🛠️ wp-build', 'pnpm wp-build', 'Build failed.', build_gate_log_1.BUILD_STAGE);
|
|
93
|
+
return stream
|
|
94
|
+
? this.buildAffected.runBuildGateStreaming(repoRoot, gateOptions)
|
|
95
|
+
: this.buildAffected.runBuildGate(repoRoot, gateOptions);
|
|
86
96
|
}
|
|
87
97
|
/**
|
|
88
98
|
* Refuse when this MACHINE is already running `maxConcurrentBuilds` builds.
|
|
@@ -105,28 +115,30 @@ let BuildCommand = class BuildCommand {
|
|
|
105
115
|
throw new rules_config_1.RuleFailError(exports.TOO_MANY_CONCURRENT_BUILDS, `This machine is already running ${String(live.length)} build(s), and the limit is ` +
|
|
106
116
|
`${String(max)}. Starting another makes all of them slower — CPU contention between agents ` +
|
|
107
117
|
`building at once was measured at ~3.2x total test time.\n\n${this.describe(live)}`, undefined, undefined, [
|
|
108
|
-
new rules_config_1.Option('Re-use the gate you should be running anyway: `pnpm wp-start-upsert-pr` then\n'
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
new rules_config_1.Option('Wait for one of the builds above to finish and run `pnpm wp-build` again. A build\n'
|
|
112
|
-
|
|
113
|
-
new rules_config_1.Option('Verify only what you are editing instead of the whole affected set:\n'
|
|
114
|
-
|
|
115
|
-
new rules_config_1.Option('Raise the limit for THIS machine, if it genuinely has the cores: put\n'
|
|
116
|
-
|
|
117
|
-
new rules_config_1.Option('If you are really stuck and cannot use a gate and really really need wp-build\n'
|
|
118
|
-
|
|
118
|
+
new rules_config_1.Option('Re-use the gate you should be running anyway: `pnpm wp-start-upsert-pr` then\n' +
|
|
119
|
+
'`pnpm wp-review-upsert-pr`. Stage ② runs the SAME `commands.pr-gate.buildCommand`\n' +
|
|
120
|
+
'this would have run, so its green is the same evidence — and it posts the PR.', true),
|
|
121
|
+
new rules_config_1.Option('Wait for one of the builds above to finish and run `pnpm wp-build` again. A build\n' +
|
|
122
|
+
'that has already died leaves no row: the count only holds live processes.'),
|
|
123
|
+
new rules_config_1.Option('Verify only what you are editing instead of the whole affected set:\n' +
|
|
124
|
+
'`pnpm exec vitest run <one spec file>`, or `pnpm nx run <project>:test`.'),
|
|
125
|
+
new rules_config_1.Option('Raise the limit for THIS machine, if it genuinely has the cores: put\n' +
|
|
126
|
+
'`{"experimental": {"maxConcurrentBuilds": <n>}}` in `~/.webpieces/config.json`.'),
|
|
127
|
+
new rules_config_1.Option('If you are really stuck and cannot use a gate and really really need wp-build\n' +
|
|
128
|
+
'then use `pnpm wp-build --force`.'),
|
|
119
129
|
]);
|
|
120
130
|
}
|
|
121
131
|
// One line per live build: which repo, which worktree, on what branch, and how long it has been
|
|
122
132
|
// going. Age is what tells a reader whether to wait thirty seconds or go and look at a stuck agent.
|
|
123
133
|
describe(live) {
|
|
124
|
-
return live
|
|
134
|
+
return live
|
|
135
|
+
.map((build) => {
|
|
125
136
|
const age = Math.max(0, Math.round((Date.now() - build.startedMs) / 1000));
|
|
126
|
-
return ` • ${build.repo} [tree=${build.tree || 'primary'}] `
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
})
|
|
137
|
+
return (` • ${build.repo} [tree=${build.tree || 'primary'}] ` +
|
|
138
|
+
`branch=${build.branch || '?'} by=${build.by} pid=${String(build.pid)} ` +
|
|
139
|
+
`running for ${String(age)}s`);
|
|
140
|
+
})
|
|
141
|
+
.join('\n');
|
|
130
142
|
}
|
|
131
143
|
};
|
|
132
144
|
exports.BuildCommand = BuildCommand;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/build-command.ts"],"names":[],"mappings":";;;;AAAA,0DAEiC;AACjC,yCAA2D;AAE3D,+DAA6E;AAC7E,+DAAyD;AAEzD,yFAAyF;AAC5E,QAAA,0BAA0B,GAAG,4BAA4B,CAAC;AAEvE;;;;;;;GAOG;AACH,MAAa,YAAY;IACrB,KAAK,CAAU;IAEf,qGAAqG;IACrG,kGAAkG;IAClG,kGAAkG;IAClG,8FAA8F;IAC9F,yDAAyD;IACzD,YAAY,KAAc;QACtB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;CACJ;AAXD,oCAWC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEI,IAAM,YAAY,GAAlB,MAAM,YAAY;IAEA;IACA;IACA;IACA;IAJrB,YACqB,aAA4B,EAC5B,cAA8B,EAC9B,SAAoB,EACpB,UAA6B;QAH7B,kBAAa,GAAb,aAAa,CAAe;QAC5B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,cAAS,GAAT,SAAS,CAAW;QACpB,eAAU,GAAV,UAAU,CAAmB;IAC/C,CAAC;IAEJ,GAAG,CAAC,IAAkB;QAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc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AU,EAAE;YAC5C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;YAC3E,OAAO,OAAO,KAAK,CAAC,IAAI,UAAU,KAAK,CAAC,IAAI,IAAI,SAAS,IAAI;kBACvD,UAAU,KAAK,CAAC,MAAM,IAAI,GAAG,OAAO,KAAK,CAAC,EAAE,QAAQ,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG;kBACxE,eAAe,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;QACxC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClB,CAAC;CACJ,CAAA;AA9EY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGD,8BAAa;QACZ,6BAAc;QACnB,wBAAS;QACR,gCAAiB;GALzC,YAAY,CA8ExB","sourcesContent":["import {\n BuildsLog, HomeConfigService, Option, RepoRootFinder, RuleFailError, RunningBuild,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { BuildAffected, BuildGateOptions } from '../workflow/build-affected';\nimport { BUILD_STAGE } from '../workflow/build-gate-log';\n\n/** The rule name the refusal is reported under, so it is greppable from a transcript. */\nexport const TOO_MANY_CONCURRENT_BUILDS = 'too-many-concurrent-builds';\n\n/**\n * What `wp-build` was asked to do. Data-only (a class, per CLAUDE.md), with exactly one field so far.\n *\n * `force` SKIPS THE CONCURRENCY CHECK AND NOTHING ELSE. It does not touch the command, and it must never\n * grow a field that does: `wp-build` runs `commands.pr-gate.buildCommand` verbatim, and a flag that\n * changed the command would make it a different build from the one the PR gate runs — which is the exact\n * drift this bin exists to delete.\n */\nexport class BuildOptions {\n force: boolean;\n\n // REQUIRED, no default. `new BuildOptions()` and `new BuildOptions(false)` would be two spellings of\n // one decision, and the bare form would keep compiling unchanged if this class ever grew a second\n // field — silently meaning \"not forced\" at a call site that was never revisited. That is the same\n // argument HomeConfig's constructor makes about its own four required parameters; a defaulted\n // parameter is exactly the shim this repo does not ship.\n constructor(force: boolean) {\n this.force = force;\n }\n}\n\n/**\n * `wp-build` — run THE project's build, and nothing else.\n *\n * ─── Why this bin exists ───────────────────────────────────────────────────────────────────────────\n * The correct verification command has lived in `commands.pr-gate.buildCommand` all along, and NOTHING\n * SURFACED IT. So every repo hand-composed its own verify chain, and those chains drifted: one sibling\n * repo's `ci:local` was `prettier --check .` (whole repo) + `wp-ci` (whole monorepo) +\n * `nx affected -t test` with NO `--base` (whole repo again) — three whole-world passes on an inner\n * loop, none of them the command the gate runs. `wp-build` closes that by making the configured value\n * the only thing anyone has to type.\n *\n * ─── It composes NOTHING, deliberately ─────────────────────────────────────────────────────────────\n * This command runs `commands.pr-gate.buildCommand` VERBATIM and adds no leg of its own — no format\n * check, no lint pass, no extra test run. Composition is exactly what drifted. Anything that must run\n * on every build belongs INSIDE `buildCommand`, where the PR gate runs it too; a leg added here would\n * be a leg the gate never sees, which is the same defect one level in.\n *\n * ─── ONE resolver, and ONE gate ────────────────────────────────────────────────────────────────────\n * `BuildAffected.runBuildGate` is the single code path that resolves the command\n * (`resolveBuildCommand`), announces it, runs it, captures its output to a log file, and renders the\n * failure. `wp-build` calls THAT — it does not re-read the config key and does not hand-write a second\n * failure string. A second reader is a second thing that can drift, and a second failure message is a\n * second thing that can teach a command the gate does not run; drift is the entire reason this bin\n * exists, so reproducing it one level in would be self-defeating.\n *\n * Only `BuildGateOptions` differs from stage ② and stage ③ — the label, the command to re-run, the\n * headline, and the log-file stage id.\n *\n * ─── The output goes to a FILE, unconditionally ────────────────────────────────────────────────────\n * Every caller of the gate captures, and there is no flag or config key that selects otherwise. That is\n * the reason this bin is worth running: the build's full stdout+stderr land in `.webpieces/build.log`\n * (previous run kept as `.webpieces/build.log.bak`), and the console gets a heartbeat plus a pointer at\n * that file. A measured session burned ~19 minutes re-running `nx affected` five times with no code\n * change in between, purely to see a different slice of output that had scrolled past. Reading a\n * different slice must cost a `grep`, not a build — see BuildGateLog.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class BuildCommand {\n constructor(\n private readonly buildAffected: BuildAffected,\n private readonly repoRootFinder: RepoRootFinder,\n private readonly buildsLog: BuildsLog,\n private readonly homeConfig: HomeConfigService,\n ) {}\n\n run(opts: BuildOptions): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n if (!opts.force) this.assertMachineHasRoom();\n // runBuildGate announces the resolved command, runs it, and throws CliExitError on failure so\n // runMain owns the exit — the same three things it does for stage ② and stage ③. It also writes\n // this build's START/DONE pair to the ledger the check above just read.\n return this.buildAffected.runBuildGate(repoRoot, new BuildGateOptions(\n '🛠️ wp-build',\n 'pnpm wp-build',\n 'Build failed.',\n BUILD_STAGE,\n ));\n }\n\n /**\n * Refuse when this MACHINE is already running `maxConcurrentBuilds` builds.\n *\n * ─── WHY ONLY HERE, AND NEVER ON THE GATE STAGES ─────────────────────────────────────────────────\n * `wp-review-upsert-pr` and `wp-finish-upsert-pr` are the SANCTIONED path, and a refusal there wedges\n * a PR that has nowhere else to go. So they always run — and their builds still write ledger rows, so\n * they count toward what refuses an ad-hoc `wp-build`. The asymmetry is the whole design: the thing\n * that gets throttled is the extra build, not the one the process needs.\n *\n * The cures are `Option`s handed to `RuleFailError`, which `runMain` renders through\n * `formatFixOptions`. They are never numbered by hand in the message — the framework owns\n * \"Fix Option N:\", and a hand-numbered list in a string literal is an automatic review reject.\n */\n private assertMachineHasRoom(): void {\n const live = this.buildsLog.running();\n const max = this.homeConfig.load().maxConcurrentBuilds;\n if (live.length < max) return;\n throw new RuleFailError(\n TOO_MANY_CONCURRENT_BUILDS,\n `This machine is already running ${String(live.length)} build(s), and the limit is ` +\n `${String(max)}. Starting another makes all of them slower — CPU contention between agents ` +\n `building at once was measured at ~3.2x total test time.\\n\\n${this.describe(live)}`,\n undefined,\n undefined,\n [\n new Option(\n 'Re-use the gate you should be running anyway: `pnpm wp-start-upsert-pr` then\\n'\n + '`pnpm wp-review-upsert-pr`. Stage ② runs the SAME `commands.pr-gate.buildCommand`\\n'\n + 'this would have run, so its green is the same evidence — and it posts the PR.',\n true),\n new Option(\n 'Wait for one of the builds above to finish and run `pnpm wp-build` again. A build\\n'\n + 'that has already died leaves no row: the count only holds live processes.'),\n new Option(\n 'Verify only what you are editing instead of the whole affected set:\\n'\n + '`pnpm exec vitest run <one spec file>`, or `pnpm nx run <project>:test`.'),\n new Option(\n 'Raise the limit for THIS machine, if it genuinely has the cores: put\\n'\n + '`{\"experimental\": {\"maxConcurrentBuilds\": <n>}}` in `~/.webpieces/config.json`.'),\n new Option(\n 'If you are really stuck and cannot use a gate and really really need wp-build\\n'\n + 'then use `pnpm wp-build --force`.'),\n ],\n );\n }\n\n // One line per live build: which repo, which worktree, on what branch, and how long it has been\n // going. Age is what tells a reader whether to wait thirty seconds or go and look at a stuck agent.\n private describe(live: readonly RunningBuild[]): string {\n return live.map((build: RunningBuild): string => {\n const age = Math.max(0, Math.round((Date.now() - build.startedMs) / 1000));\n return ` • ${build.repo} [tree=${build.tree || 'primary'}] `\n + `branch=${build.branch || '?'} by=${build.by} pid=${String(build.pid)} `\n + `running for ${String(age)}s`;\n }).join('\\n');\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"build-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/build-command.ts"],"names":[],"mappings":";;;;AAAA,0DAOiC;AACjC,yCAA2D;AAE3D,+DAA6E;AAC7E,+DAAyD;AAEzD,yFAAyF;AAC5E,QAAA,0BAA0B,GAAG,4BAA4B,CAAC;AAEvE;;;;;;;GAOG;AACH,MAAa,YAAY;IACrB,KAAK,CAAU;IAEf,qGAAqG;IACrG,kGAAkG;IAClG,kGAAkG;IAClG,8FAA8F;IAC9F,yDAAyD;IACzD,Y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Ae,MAAM,CAAC,GAAG,CAAC,GAAG,CAChC,CAAC;QACN,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;CACJ,CAAA;AAnGY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGD,8BAAa;QACZ,6BAAc;QACnB,wBAAS;QACR,gCAAiB;GALzC,YAAY,CAmGxB","sourcesContent":["import {\n BuildsLog,\n HomeConfigService,\n Option,\n RepoRootFinder,\n RuleFailError,\n RunningBuild,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { BuildAffected, BuildGateOptions } from '../workflow/build-affected';\nimport { BUILD_STAGE } from '../workflow/build-gate-log';\n\n/** The rule name the refusal is reported under, so it is greppable from a transcript. */\nexport const TOO_MANY_CONCURRENT_BUILDS = 'too-many-concurrent-builds';\n\n/**\n * What `wp-build` was asked to do. Data-only (a class, per CLAUDE.md), with exactly one field so far.\n *\n * `force` SKIPS THE CONCURRENCY CHECK AND NOTHING ELSE. It does not touch the command, and it must never\n * grow a field that does: `wp-build` runs `commands.pr-gate.buildCommand` verbatim, and a flag that\n * changed the command would make it a different build from the one the PR gate runs — which is the exact\n * drift this bin exists to delete.\n */\nexport class BuildOptions {\n force: boolean;\n\n // REQUIRED, no default. `new BuildOptions()` and `new BuildOptions(false)` would be two spellings of\n // one decision, and the bare form would keep compiling unchanged if this class ever grew a second\n // field — silently meaning \"not forced\" at a call site that was never revisited. That is the same\n // argument HomeConfig's constructor makes about its own four required parameters; a defaulted\n // parameter is exactly the shim this repo does not ship.\n constructor(force: boolean) {\n this.force = force;\n }\n}\n\n/**\n * `wp-build` — run THE project's build, and nothing else.\n *\n * ─── Why this bin exists ───────────────────────────────────────────────────────────────────────────\n * The correct verification command has lived in `commands.pr-gate.buildCommand` all along, and NOTHING\n * SURFACED IT. So every repo hand-composed its own verify chain, and those chains drifted: one sibling\n * repo's `ci:local` was `prettier --check .` (whole repo) + `wp-ci` (whole monorepo) +\n * `nx affected -t test` with NO `--base` (whole repo again) — three whole-world passes on an inner\n * loop, none of them the command the gate runs. `wp-build` closes that by making the configured value\n * the only thing anyone has to type.\n *\n * ─── It composes NOTHING, deliberately ─────────────────────────────────────────────────────────────\n * This command runs `commands.pr-gate.buildCommand` VERBATIM and adds no leg of its own — no format\n * check, no lint pass, no extra test run. Composition is exactly what drifted. Anything that must run\n * on every build belongs INSIDE `buildCommand`, where the PR gate runs it too; a leg added here would\n * be a leg the gate never sees, which is the same defect one level in.\n *\n * ─── ONE resolver, and ONE gate ────────────────────────────────────────────────────────────────────\n * `BuildAffected.runBuildGate` is the single code path that resolves the command\n * (`resolveBuildCommand`), announces it, runs it, captures its output to a log file, and renders the\n * failure. `wp-build` calls THAT — it does not re-read the config key and does not hand-write a second\n * failure string. A second reader is a second thing that can drift, and a second failure message is a\n * second thing that can teach a command the gate does not run; drift is the entire reason this bin\n * exists, so reproducing it one level in would be self-defeating.\n *\n * Only `BuildGateOptions` differs from stage ② and stage ③ — the label, the command to re-run, the\n * headline, and the log-file stage id.\n *\n * ─── The output goes to a FILE, unconditionally ────────────────────────────────────────────────────\n * Every caller of the gate captures, and there is no flag or config key that selects otherwise. That is\n * the reason this bin is worth running: the build's full stdout+stderr land in `.webpieces/build.log`\n * (previous run kept as `.webpieces/build.log.bak`), and the console gets a heartbeat plus a pointer at\n * that file. A measured session burned ~19 minutes re-running `nx affected` five times with no code\n * change in between, purely to see a different slice of output that had scrolled past. Reading a\n * different slice must cost a `grep`, not a build — see BuildGateLog.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class BuildCommand {\n constructor(\n private readonly buildAffected: BuildAffected,\n private readonly repoRootFinder: RepoRootFinder,\n private readonly buildsLog: BuildsLog,\n private readonly homeConfig: HomeConfigService,\n ) {}\n\n run(opts: BuildOptions): Promise<void> {\n return this.runGate(opts, false);\n }\n\n /** Human-terminal form used by wp-human-post-pr; build.log remains complete while output is live. */\n runStreaming(opts: BuildOptions): Promise<void> {\n return this.runGate(opts, true);\n }\n\n private runGate(opts: BuildOptions, stream: boolean): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n if (!opts.force) this.assertMachineHasRoom();\n // runBuildGate announces the resolved command, runs it, and throws CliExitError on failure so\n // runMain owns the exit — the same three things it does for stage ② and stage ③. It also writes\n // this build's START/DONE pair to the ledger the check above just read.\n const gateOptions = new BuildGateOptions(\n '🛠️ wp-build',\n 'pnpm wp-build',\n 'Build failed.',\n BUILD_STAGE,\n );\n return stream\n ? this.buildAffected.runBuildGateStreaming(repoRoot, gateOptions)\n : this.buildAffected.runBuildGate(repoRoot, gateOptions);\n }\n\n /**\n * Refuse when this MACHINE is already running `maxConcurrentBuilds` builds.\n *\n * ─── WHY ONLY HERE, AND NEVER ON THE GATE STAGES ─────────────────────────────────────────────────\n * `wp-review-upsert-pr` and `wp-finish-upsert-pr` are the SANCTIONED path, and a refusal there wedges\n * a PR that has nowhere else to go. So they always run — and their builds still write ledger rows, so\n * they count toward what refuses an ad-hoc `wp-build`. The asymmetry is the whole design: the thing\n * that gets throttled is the extra build, not the one the process needs.\n *\n * The cures are `Option`s handed to `RuleFailError`, which `runMain` renders through\n * `formatFixOptions`. They are never numbered by hand in the message — the framework owns\n * \"Fix Option N:\", and a hand-numbered list in a string literal is an automatic review reject.\n */\n private assertMachineHasRoom(): void {\n const live = this.buildsLog.running();\n const max = this.homeConfig.load().maxConcurrentBuilds;\n if (live.length < max) return;\n throw new RuleFailError(\n TOO_MANY_CONCURRENT_BUILDS,\n `This machine is already running ${String(live.length)} build(s), and the limit is ` +\n `${String(max)}. Starting another makes all of them slower — CPU contention between agents ` +\n `building at once was measured at ~3.2x total test time.\\n\\n${this.describe(live)}`,\n undefined,\n undefined,\n [\n new Option(\n 'Re-use the gate you should be running anyway: `pnpm wp-start-upsert-pr` then\\n' +\n '`pnpm wp-review-upsert-pr`. Stage ② runs the SAME `commands.pr-gate.buildCommand`\\n' +\n 'this would have run, so its green is the same evidence — and it posts the PR.',\n true,\n ),\n new Option(\n 'Wait for one of the builds above to finish and run `pnpm wp-build` again. A build\\n' +\n 'that has already died leaves no row: the count only holds live processes.',\n ),\n new Option(\n 'Verify only what you are editing instead of the whole affected set:\\n' +\n '`pnpm exec vitest run <one spec file>`, or `pnpm nx run <project>:test`.',\n ),\n new Option(\n 'Raise the limit for THIS machine, if it genuinely has the cores: put\\n' +\n '`{\"experimental\": {\"maxConcurrentBuilds\": <n>}}` in `~/.webpieces/config.json`.',\n ),\n new Option(\n 'If you are really stuck and cannot use a gate and really really need wp-build\\n' +\n 'then use `pnpm wp-build --force`.',\n ),\n ],\n );\n }\n\n // One line per live build: which repo, which worktree, on what branch, and how long it has been\n // going. Age is what tells a reader whether to wait thirty seconds or go and look at a stuck agent.\n private describe(live: readonly RunningBuild[]): string {\n return live\n .map((build: RunningBuild): string => {\n const age = Math.max(0, Math.round((Date.now() - build.startedMs) / 1000));\n return (\n ` • ${build.repo} [tree=${build.tree || 'primary'}] ` +\n `branch=${build.branch || '?'} by=${build.by} pid=${String(build.pid)} ` +\n `running for ${String(age)}s`\n );\n })\n .join('\\n');\n }\n}\n"]}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { RepoRootFinder, GateTokenService } from '@webpieces/rules-config';
|
|
2
|
+
export declare class PrUnderCheck {
|
|
3
|
+
number: string;
|
|
4
|
+
headSha: string;
|
|
5
|
+
body: string;
|
|
6
|
+
constructor(number: string, headSha: string, body: string);
|
|
7
|
+
}
|
|
2
8
|
/**
|
|
3
9
|
* `wp-check-pr` — the SERVER-SIDE half of the gate, meant to run as a required CI check. It is READ-ONLY:
|
|
4
10
|
* it never touches git state, never pushes, never calls `gh pr create`. It recomputes
|
|
5
11
|
* `HMAC(prGate.gateSalt, PR_head_sha)` from the committed salt and verifies the PR body carries that
|
|
6
|
-
* token.
|
|
7
|
-
*
|
|
12
|
+
* token. A valid token proves either that the automated gate passed on this exact commit, or that a human
|
|
13
|
+
* explicitly attested and posted it with `wp-human-post-pr`; the visible PR body identifies which path.
|
|
8
14
|
*
|
|
9
15
|
* This is what catches a PR opened OUTSIDE the gated flow — an unhooked teammate who `git push`ed and
|
|
10
16
|
* clicked "Create pull request" in the web UI carries no valid token for its head sha and fails here.
|
|
@@ -27,7 +33,8 @@ export declare class CheckPrCommand {
|
|
|
27
33
|
run(): Promise<void>;
|
|
28
34
|
private verifyWithRetry;
|
|
29
35
|
private delay;
|
|
30
|
-
|
|
36
|
+
protected successMessage(pr: PrUnderCheck): string;
|
|
37
|
+
protected failureMessage(pr: PrUnderCheck): string;
|
|
31
38
|
private resolvePr;
|
|
32
39
|
private prNumber;
|
|
33
40
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CheckPrCommand = void 0;
|
|
3
|
+
exports.CheckPrCommand = exports.PrUnderCheck = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const child_process_1 = require("child_process");
|
|
6
6
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
@@ -16,12 +16,13 @@ class PrUnderCheck {
|
|
|
16
16
|
this.body = body;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
+
exports.PrUnderCheck = PrUnderCheck;
|
|
19
20
|
/**
|
|
20
21
|
* `wp-check-pr` — the SERVER-SIDE half of the gate, meant to run as a required CI check. It is READ-ONLY:
|
|
21
22
|
* it never touches git state, never pushes, never calls `gh pr create`. It recomputes
|
|
22
23
|
* `HMAC(prGate.gateSalt, PR_head_sha)` from the committed salt and verifies the PR body carries that
|
|
23
|
-
* token.
|
|
24
|
-
*
|
|
24
|
+
* token. A valid token proves either that the automated gate passed on this exact commit, or that a human
|
|
25
|
+
* explicitly attested and posted it with `wp-human-post-pr`; the visible PR body identifies which path.
|
|
25
26
|
*
|
|
26
27
|
* This is what catches a PR opened OUTSIDE the gated flow — an unhooked teammate who `git push`ed and
|
|
27
28
|
* clicked "Create pull request" in the web UI carries no valid token for its head sha and fails here.
|
|
@@ -58,7 +59,7 @@ let CheckPrCommand = class CheckPrCommand {
|
|
|
58
59
|
}
|
|
59
60
|
pr = await this.verifyWithRetry(pr, gateSalt);
|
|
60
61
|
if (this.gateTokenService.verifyGateToken(pr.body, gateSalt, pr.headSha)) {
|
|
61
|
-
process.stdout.write(
|
|
62
|
+
process.stdout.write(this.successMessage(pr));
|
|
62
63
|
return;
|
|
63
64
|
}
|
|
64
65
|
// An UNHOOKED push never reaches wp-finish-upsert-pr, so it carries no valid token — fail the job.
|
|
@@ -83,22 +84,42 @@ let CheckPrCommand = class CheckPrCommand {
|
|
|
83
84
|
});
|
|
84
85
|
}
|
|
85
86
|
// The actionable red-check message: this PR did not come through the gated flow (or hooks are missing).
|
|
87
|
+
successMessage(pr) {
|
|
88
|
+
return `✅ wp-check-pr: valid webpieces gate token for PR #${pr.number} @ ${pr.headSha.slice(0, 12)} — automated gate or explicit human escape hatch (see PR body).\n`;
|
|
89
|
+
}
|
|
86
90
|
failureMessage(pr) {
|
|
87
91
|
return (`❌ wp-check-pr: PR #${pr.number} (head ${pr.headSha.slice(0, 12)}) has no valid webpieces gate token.\n\n` +
|
|
88
|
-
`This PR was NOT
|
|
89
|
-
`Every commit that lands here
|
|
92
|
+
`This PR was NOT posted through either supported token-minting path — or was pushed afterwards.\n` +
|
|
93
|
+
`Every commit that lands here needs a current token, so:\n\n` +
|
|
90
94
|
` 1. Install the webpieces hooks if you don't have them.\n` +
|
|
91
95
|
` 2. Recreate/update this PR by running the full gated flow, in order:\n` +
|
|
92
|
-
` pnpm wp-start-upsert-pr → pnpm wp-review-upsert-pr → write summary.json → pnpm wp-finish-upsert-pr\n
|
|
93
|
-
`
|
|
96
|
+
` pnpm wp-start-upsert-pr → pnpm wp-review-upsert-pr → write summary.json → pnpm wp-finish-upsert-pr\n` +
|
|
97
|
+
` A human who personally inspected the work may instead run interactive pnpm wp-human-post-pr.\n` +
|
|
98
|
+
` AI must never answer its human-attestation prompt or run that escape hatch for a human.\n\n` +
|
|
99
|
+
`Either supported path re-stamps the PR title, body, and token for the current head commit.`);
|
|
94
100
|
}
|
|
95
101
|
// Resolve the PR (number, head sha, body) from `gh`. Prefers an explicit WP_PR_NUMBER, then the
|
|
96
102
|
// pull_request number in GITHUB_REF (refs/pull/<n>/merge), then `gh`'s current-branch detection.
|
|
97
103
|
resolvePr() {
|
|
98
104
|
const num = this.prNumber();
|
|
99
105
|
const args = num !== ''
|
|
100
|
-
? [
|
|
101
|
-
|
|
106
|
+
? [
|
|
107
|
+
'pr',
|
|
108
|
+
'view',
|
|
109
|
+
num,
|
|
110
|
+
'--json',
|
|
111
|
+
'number,headRefOid,body',
|
|
112
|
+
'--jq',
|
|
113
|
+
'"\\(.number)\\t\\(.headRefOid)\\t\\(.body)"',
|
|
114
|
+
]
|
|
115
|
+
: [
|
|
116
|
+
'pr',
|
|
117
|
+
'view',
|
|
118
|
+
'--json',
|
|
119
|
+
'number,headRefOid,body',
|
|
120
|
+
'--jq',
|
|
121
|
+
'"\\(.number)\\t\\(.headRefOid)\\t\\(.body)"',
|
|
122
|
+
];
|
|
102
123
|
const result = (0, child_process_1.spawnSync)('gh', args, { encoding: 'utf8', maxBuffer: 1024 * 1024 * 16 });
|
|
103
124
|
if (result.status !== 0)
|
|
104
125
|
return new PrUnderCheck(num, '', '');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/check-pr-command.ts"],"names":[],"mappings":";;;;AAAA,iDAA0C;AAC1C,0DAEiC;AACjC,yCAA2D;AAE3D,4EAA4E;AAC5E,MAAM,YAAY;IACd,MAAM,CAAS;IACf,OAAO,CAAS;IAChB,IAAI,CAAS;IAEb,YAAY,MAAc,EAAE,OAAe,EAAE,IAAY;QACrD,IAAI,CAAC,MAAM,GAAG,MAAM,CA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,OAAO,IAAI,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IACnD,CAAC;IAEO,QAAQ;QACZ,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAC5D,IAAI,QAAQ,KAAK,EAAE;YAAE,OAAO,QAAQ,CAAC;QACrC,gEAAgE;QAChE,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;QAC5C,MAAM,CAAC,GAAG,qBAAqB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC1C,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACzB,CAAC;CACJ,CAAA;AA5FY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QACZ,+BAAgB;GAH9C,cAAc,CA4F1B","sourcesContent":["import { spawnSync } from 'child_process';\nimport {\n loadAndValidate, RepoRootFinder, GateTokenService, CliExitError,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\n// The head sha + body of the PR under check, resolved from `gh`. Data-only.\nclass PrUnderCheck {\n number: string;\n headSha: string;\n body: string;\n\n constructor(number: string, headSha: string, body: string) {\n this.number = number;\n this.headSha = headSha;\n this.body = body;\n }\n}\n\n/**\n * `wp-check-pr` — the SERVER-SIDE half of the gate, meant to run as a required CI check. It is READ-ONLY:\n * it never touches git state, never pushes, never calls `gh pr create`. It recomputes\n * `HMAC(prGate.gateSalt, PR_head_sha)` from the committed salt and verifies the PR body carries that\n * token. Because `wp-finish-upsert-pr` refuses to mint the token unless the build gate + every BLOCK\n * checklist passed, a valid token IS proof the gated flow ran and passed on this exact commit.\n *\n * This is what catches a PR opened OUTSIDE the gated flow — an unhooked teammate who `git push`ed and\n * clicked \"Create pull request\" in the web UI carries no valid token for its head sha and fails here.\n *\n * This job is THE required check — the ONE thing a consumer marks required in branch protection. It used\n * to also post a `webpieces/pr-gate` commit status, because `wp-finish-upsert-pr` pushed BEFORE writing\n * the PR body and a status (newest post wins for a context) could supersede the failure that race caused.\n * GatedPrPublisher now writes the body first, so there is no race to recover from and no second entry to\n * confuse anyone about which one to require. This job's exit code is the whole verdict.\n *\n * A repo with no `gateSalt` configured has not opted in → this is a no-op success (exit 0), so it is safe\n * to add the workflow before turning enforcement on.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is drawn in the DI design and resolved by PrGateApp.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class CheckPrCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly gateTokenService: GateTokenService,\n ) {}\n\n async run(): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n const gateSalt = loadAndValidate(repoRoot).prGate.gateSalt;\n if (gateSalt.trim() === '') {\n throw new CliExitError(0,\n 'ℹ️ wp-check-pr: no prGate.gateSalt configured — server-side gate token enforcement is disabled. ' +\n 'Add a committed \"gateSalt\" under the pr-gate section of webpieces.config.json to enable it.');\n }\n\n let pr = this.resolvePr();\n if (pr.headSha === '') {\n throw new CliExitError(1,\n '❌ wp-check-pr: could not resolve the PR head sha via `gh`. Ensure the workflow runs on a pull_request ' +\n 'event with `gh` authenticated (GH_TOKEN) and the PR number available (WP_PR_NUMBER or GITHUB_REF).');\n }\n\n pr = await this.verifyWithRetry(pr, gateSalt);\n if (this.gateTokenService.verifyGateToken(pr.body, gateSalt, pr.headSha)) {\n process.stdout.write(`✅ wp-check-pr: valid webpieces gate token for PR #${pr.number} @ ${pr.headSha.slice(0, 12)} — created through the gated flow.\\n`);\n return;\n }\n\n // An UNHOOKED push never reaches wp-finish-upsert-pr, so it carries no valid token — fail the job.\n // THIS EXIT CODE IS THE WHOLE SIGNAL: there is no companion commit status any more (see the JSDoc).\n throw new CliExitError(1, this.failureMessage(pr));\n }\n\n // Re-read the PR ONCE after a short delay if the token looks stale. The push-before-body-edit RACE is\n // gone (GatedPrPublisher writes the body first), so this no longer backstops a known ordering bug —\n // it absorbs GitHub's own event/read replication jitter, which matters more now that this job is the\n // single required check. It costs nothing on the success path. Returns the freshest PR.\n private async verifyWithRetry(pr: PrUnderCheck, gateSalt: string): Promise<PrUnderCheck> {\n if (this.gateTokenService.verifyGateToken(pr.body, gateSalt, pr.headSha)) return pr;\n process.stdout.write('… no valid token yet — waiting for the PR body edit to land, then re-checking once…\\n');\n await this.delay(15000);\n const refreshed = this.resolvePr();\n return refreshed.headSha !== '' ? refreshed : pr;\n }\n\n private delay(ms: number): Promise<void> {\n return new Promise((resolve: () => void): void => {\n setTimeout(resolve, ms);\n });\n }\n\n // The actionable red-check message: this PR did not come through the gated flow (or hooks are missing).\n private failureMessage(pr: PrUnderCheck): string {\n return (\n `❌ wp-check-pr: PR #${pr.number} (head ${pr.headSha.slice(0, 12)}) has no valid webpieces gate token.\\n\\n` +\n `This PR was NOT created through the webpieces gated flow — or was pushed after finishing without re-running it.\\n` +\n `Every commit that lands here must go through it, so:\\n\\n` +\n ` 1. Install the webpieces hooks if you don't have them.\\n` +\n ` 2. Recreate/update this PR by running the full gated flow, in order:\\n` +\n ` pnpm wp-start-upsert-pr → pnpm wp-review-upsert-pr → write summary.json → pnpm wp-finish-upsert-pr\\n\\n` +\n `That re-stamps the PR title, body, and the gate token for the current head commit, and this check goes green.`\n );\n }\n\n // Resolve the PR (number, head sha, body) from `gh`. Prefers an explicit WP_PR_NUMBER, then the\n // pull_request number in GITHUB_REF (refs/pull/<n>/merge), then `gh`'s current-branch detection.\n private resolvePr(): PrUnderCheck {\n const num = this.prNumber();\n const args = num !== ''\n ? ['pr', 'view', num, '--json', 'number,headRefOid,body', '--jq', '\"\\\\(.number)\\\\t\\\\(.headRefOid)\\\\t\\\\(.body)\"']\n : ['pr', 'view', '--json', 'number,headRefOid,body', '--jq', '\"\\\\(.number)\\\\t\\\\(.headRefOid)\\\\t\\\\(.body)\"'];\n const result = spawnSync('gh', args, { encoding: 'utf8', maxBuffer: 1024 * 1024 * 16 });\n if (result.status !== 0) return new PrUnderCheck(num, '', '');\n // jq joins body (which may contain tabs/newlines) last, so split on the FIRST two tabs only.\n const out = (result.stdout ?? '').trim();\n const firstTab = out.indexOf('\\t');\n const secondTab = firstTab >= 0 ? out.indexOf('\\t', firstTab + 1) : -1;\n if (firstTab < 0 || secondTab < 0) return new PrUnderCheck(num, '', '');\n const number = out.slice(0, firstTab);\n const headSha = out.slice(firstTab + 1, secondTab);\n const body = out.slice(secondTab + 1);\n return new PrUnderCheck(number, headSha, body);\n }\n\n private prNumber(): string {\n const explicit = (process.env['WP_PR_NUMBER'] ?? '').trim();\n if (explicit !== '') return explicit;\n // GitHub Actions pull_request: GITHUB_REF = refs/pull/<n>/merge\n const ref = process.env['GITHUB_REF'] ?? '';\n const m = /refs\\/pull\\/(\\d+)\\//.exec(ref);\n return m ? m[1] : '';\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"check-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/check-pr-command.ts"],"names":[],"mappings":";;;;AAAA,iDAA0C;AAC1C,0DAKiC;AACjC,yCAA2D;AAE3D,4EAA4E;AAC5E,MAAa,YAAY;IACrB,MAAM,CAAS;IACf,OAAO,CAAS;IAChB,IAAI,CAAS;IAEb,YAAY,MAAc,EAAE,OAAe,EAAE,IAAY;QACrD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ;AAVD,oCAUC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AAEI,IAAM,cAAc,GAApB,MAAM,cAAc;IAEF;IACA;IAFrB,YACqB,cAA8B,EAC9B,gBAAkC;QADlC,mBA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AG,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAC5D,IAAI,QAAQ,KAAK,EAAE;YAAE,OAAO,QAAQ,CAAC;QACrC,gEAAgE;QAChE,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;QAC5C,MAAM,CAAC,GAAG,qBAAqB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC1C,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACzB,CAAC;CACJ,CAAA;AAxHY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QACZ,+BAAgB;GAH9C,cAAc,CAwH1B","sourcesContent":["import { spawnSync } from 'child_process';\nimport {\n loadAndValidate,\n RepoRootFinder,\n GateTokenService,\n CliExitError,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\n// The head sha + body of the PR under check, resolved from `gh`. Data-only.\nexport class PrUnderCheck {\n number: string;\n headSha: string;\n body: string;\n\n constructor(number: string, headSha: string, body: string) {\n this.number = number;\n this.headSha = headSha;\n this.body = body;\n }\n}\n\n/**\n * `wp-check-pr` — the SERVER-SIDE half of the gate, meant to run as a required CI check. It is READ-ONLY:\n * it never touches git state, never pushes, never calls `gh pr create`. It recomputes\n * `HMAC(prGate.gateSalt, PR_head_sha)` from the committed salt and verifies the PR body carries that\n * token. A valid token proves either that the automated gate passed on this exact commit, or that a human\n * explicitly attested and posted it with `wp-human-post-pr`; the visible PR body identifies which path.\n *\n * This is what catches a PR opened OUTSIDE the gated flow — an unhooked teammate who `git push`ed and\n * clicked \"Create pull request\" in the web UI carries no valid token for its head sha and fails here.\n *\n * This job is THE required check — the ONE thing a consumer marks required in branch protection. It used\n * to also post a `webpieces/pr-gate` commit status, because `wp-finish-upsert-pr` pushed BEFORE writing\n * the PR body and a status (newest post wins for a context) could supersede the failure that race caused.\n * GatedPrPublisher now writes the body first, so there is no race to recover from and no second entry to\n * confuse anyone about which one to require. This job's exit code is the whole verdict.\n *\n * A repo with no `gateSalt` configured has not opted in → this is a no-op success (exit 0), so it is safe\n * to add the workflow before turning enforcement on.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is drawn in the DI design and resolved by PrGateApp.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class CheckPrCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly gateTokenService: GateTokenService,\n ) {}\n\n async run(): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n const gateSalt = loadAndValidate(repoRoot).prGate.gateSalt;\n if (gateSalt.trim() === '') {\n throw new CliExitError(\n 0,\n 'ℹ️ wp-check-pr: no prGate.gateSalt configured — server-side gate token enforcement is disabled. ' +\n 'Add a committed \"gateSalt\" under the pr-gate section of webpieces.config.json to enable it.',\n );\n }\n\n let pr = this.resolvePr();\n if (pr.headSha === '') {\n throw new CliExitError(\n 1,\n '❌ wp-check-pr: could not resolve the PR head sha via `gh`. Ensure the workflow runs on a pull_request ' +\n 'event with `gh` authenticated (GH_TOKEN) and the PR number available (WP_PR_NUMBER or GITHUB_REF).',\n );\n }\n\n pr = await this.verifyWithRetry(pr, gateSalt);\n if (this.gateTokenService.verifyGateToken(pr.body, gateSalt, pr.headSha)) {\n process.stdout.write(this.successMessage(pr));\n return;\n }\n\n // An UNHOOKED push never reaches wp-finish-upsert-pr, so it carries no valid token — fail the job.\n // THIS EXIT CODE IS THE WHOLE SIGNAL: there is no companion commit status any more (see the JSDoc).\n throw new CliExitError(1, this.failureMessage(pr));\n }\n\n // Re-read the PR ONCE after a short delay if the token looks stale. The push-before-body-edit RACE is\n // gone (GatedPrPublisher writes the body first), so this no longer backstops a known ordering bug —\n // it absorbs GitHub's own event/read replication jitter, which matters more now that this job is the\n // single required check. It costs nothing on the success path. Returns the freshest PR.\n private async verifyWithRetry(pr: PrUnderCheck, gateSalt: string): Promise<PrUnderCheck> {\n if (this.gateTokenService.verifyGateToken(pr.body, gateSalt, pr.headSha)) return pr;\n process.stdout.write(\n '… no valid token yet — waiting for the PR body edit to land, then re-checking once…\\n',\n );\n await this.delay(15000);\n const refreshed = this.resolvePr();\n return refreshed.headSha !== '' ? refreshed : pr;\n }\n\n private delay(ms: number): Promise<void> {\n return new Promise((resolve: () => void): void => {\n setTimeout(resolve, ms);\n });\n }\n\n // The actionable red-check message: this PR did not come through the gated flow (or hooks are missing).\n protected successMessage(pr: PrUnderCheck): string {\n return `✅ wp-check-pr: valid webpieces gate token for PR #${pr.number} @ ${pr.headSha.slice(0, 12)} — automated gate or explicit human escape hatch (see PR body).\\n`;\n }\n\n protected failureMessage(pr: PrUnderCheck): string {\n return (\n `❌ wp-check-pr: PR #${pr.number} (head ${pr.headSha.slice(0, 12)}) has no valid webpieces gate token.\\n\\n` +\n `This PR was NOT posted through either supported token-minting path — or was pushed afterwards.\\n` +\n `Every commit that lands here needs a current token, so:\\n\\n` +\n ` 1. Install the webpieces hooks if you don't have them.\\n` +\n ` 2. Recreate/update this PR by running the full gated flow, in order:\\n` +\n ` pnpm wp-start-upsert-pr → pnpm wp-review-upsert-pr → write summary.json → pnpm wp-finish-upsert-pr\\n` +\n ` A human who personally inspected the work may instead run interactive pnpm wp-human-post-pr.\\n` +\n ` AI must never answer its human-attestation prompt or run that escape hatch for a human.\\n\\n` +\n `Either supported path re-stamps the PR title, body, and token for the current head commit.`\n );\n }\n\n // Resolve the PR (number, head sha, body) from `gh`. Prefers an explicit WP_PR_NUMBER, then the\n // pull_request number in GITHUB_REF (refs/pull/<n>/merge), then `gh`'s current-branch detection.\n private resolvePr(): PrUnderCheck {\n const num = this.prNumber();\n const args =\n num !== ''\n ? [\n 'pr',\n 'view',\n num,\n '--json',\n 'number,headRefOid,body',\n '--jq',\n '\"\\\\(.number)\\\\t\\\\(.headRefOid)\\\\t\\\\(.body)\"',\n ]\n : [\n 'pr',\n 'view',\n '--json',\n 'number,headRefOid,body',\n '--jq',\n '\"\\\\(.number)\\\\t\\\\(.headRefOid)\\\\t\\\\(.body)\"',\n ];\n const result = spawnSync('gh', args, { encoding: 'utf8', maxBuffer: 1024 * 1024 * 16 });\n if (result.status !== 0) return new PrUnderCheck(num, '', '');\n // jq joins body (which may contain tabs/newlines) last, so split on the FIRST two tabs only.\n const out = (result.stdout ?? '').trim();\n const firstTab = out.indexOf('\\t');\n const secondTab = firstTab >= 0 ? out.indexOf('\\t', firstTab + 1) : -1;\n if (firstTab < 0 || secondTab < 0) return new PrUnderCheck(num, '', '');\n const number = out.slice(0, firstTab);\n const headSha = out.slice(firstTab + 1, secondTab);\n const body = out.slice(secondTab + 1);\n return new PrUnderCheck(number, headSha, body);\n }\n\n private prNumber(): string {\n const explicit = (process.env['WP_PR_NUMBER'] ?? '').trim();\n if (explicit !== '') return explicit;\n // GitHub Actions pull_request: GITHUB_REF = refs/pull/<n>/merge\n const ref = process.env['GITHUB_REF'] ?? '';\n const m = /refs\\/pull\\/(\\d+)\\//.exec(ref);\n return m ? m[1] : '';\n }\n}\n"]}
|
|
@@ -8,6 +8,7 @@ import { BuildAffected } from '../workflow/build-affected';
|
|
|
8
8
|
import { BuildGateLog } from '../workflow/build-gate-log';
|
|
9
9
|
import { MergeState } from '../workflow/merge-state';
|
|
10
10
|
import { ReviewStageReceiptService } from '../workflow/review-stage-receipt';
|
|
11
|
+
import { ReviewRoundStateService } from '../workflow/review-round-state';
|
|
11
12
|
import { StageOutputLog } from '../workflow/stage-output-log';
|
|
12
13
|
import { PrMerger } from '../workflow/pr-merger';
|
|
13
14
|
import { FinishBanner } from '../workflow/finish-banner';
|
|
@@ -46,7 +47,8 @@ export declare class FinishUpsertPrCommand {
|
|
|
46
47
|
private readonly stageConsole;
|
|
47
48
|
private readonly branchIdentity;
|
|
48
49
|
private readonly hotfixFinish;
|
|
49
|
-
|
|
50
|
+
private readonly rounds;
|
|
51
|
+
constructor(repoRootFinder: RepoRootFinder, aiBranchName: AiBranchName, branchNaming: BranchNaming, gitExec: GitExec, buildAffected: BuildAffected, buildLog: BuildGateLog, mergeState: MergeState, prMerger: PrMerger, publisher: GatedPrPublisher, dashboard: Dashboard, authorIdentity: AuthorIdentityResolver, checklistComment: ChecklistCommentRenderer, checklistScanner: ChecklistScanner, verdictGate: ReviewerVerdictGate, reviewJsonService: ReviewJsonService, gateTokenService: GateTokenService, provenanceEnforcer: ProvenanceEnforcer, receipts: ReviewStageReceiptService, banner: FinishBanner, mergeBodyFile: MergeBodyTempFile, commentUpserter: PrCommentUpserter, squashSettings: SquashSettingsEnforcer, stageConsole: StageOutputLog, branchIdentity: BranchIdentity, hotfixFinish: HotfixFinishPreparer, rounds: ReviewRoundStateService);
|
|
50
52
|
/**
|
|
51
53
|
* Runs with this stage's console CAPTURED to a file (see StageOutputLog). What still reaches the
|
|
52
54
|
* terminal is what an agent must act on: the build heartbeat and result, and the closing banner with
|
|
@@ -55,6 +57,7 @@ export declare class FinishUpsertPrCommand {
|
|
|
55
57
|
*/
|
|
56
58
|
run(): Promise<void>;
|
|
57
59
|
private runStage;
|
|
60
|
+
private applyRoundAudits;
|
|
58
61
|
/** Hotfix finish owns every prerequisite normally split between stages ② and ③. */
|
|
59
62
|
private runHotfixStage;
|
|
60
63
|
/**
|
|
@@ -16,6 +16,7 @@ const build_affected_1 = require("../workflow/build-affected");
|
|
|
16
16
|
const build_gate_log_1 = require("../workflow/build-gate-log");
|
|
17
17
|
const merge_state_1 = require("../workflow/merge-state");
|
|
18
18
|
const review_stage_receipt_1 = require("../workflow/review-stage-receipt");
|
|
19
|
+
const review_round_state_1 = require("../workflow/review-round-state");
|
|
19
20
|
const stage_output_log_1 = require("../workflow/stage-output-log");
|
|
20
21
|
const pr_merger_1 = require("../workflow/pr-merger");
|
|
21
22
|
const finish_banner_1 = require("../workflow/finish-banner");
|
|
@@ -124,6 +125,7 @@ let FinishUpsertPrCommand = class FinishUpsertPrCommand {
|
|
|
124
125
|
stageConsole;
|
|
125
126
|
branchIdentity;
|
|
126
127
|
hotfixFinish;
|
|
128
|
+
rounds;
|
|
127
129
|
constructor(repoRootFinder, aiBranchName, branchNaming, gitExec, buildAffected, buildLog, mergeState, prMerger, publisher, dashboard, authorIdentity,
|
|
128
130
|
// The 2nd PR comment. Its own class because it is its own surface — see ChecklistCommentRenderer.
|
|
129
131
|
checklistComment, checklistScanner, verdictGate, reviewJsonService, gateTokenService,
|
|
@@ -140,7 +142,7 @@ let FinishUpsertPrCommand = class FinishUpsertPrCommand {
|
|
|
140
142
|
commentUpserter,
|
|
141
143
|
// Pins the two GitHub repo settings that decide whether a UI merge writes the body we just
|
|
142
144
|
// rendered. Server-side, so no config can express them — see SquashSettingsEnforcer.
|
|
143
|
-
squashSettings, stageConsole, branchIdentity, hotfixFinish) {
|
|
145
|
+
squashSettings, stageConsole, branchIdentity, hotfixFinish, rounds) {
|
|
144
146
|
this.repoRootFinder = repoRootFinder;
|
|
145
147
|
this.aiBranchName = aiBranchName;
|
|
146
148
|
this.branchNaming = branchNaming;
|
|
@@ -166,6 +168,7 @@ let FinishUpsertPrCommand = class FinishUpsertPrCommand {
|
|
|
166
168
|
this.stageConsole = stageConsole;
|
|
167
169
|
this.branchIdentity = branchIdentity;
|
|
168
170
|
this.hotfixFinish = hotfixFinish;
|
|
171
|
+
this.rounds = rounds;
|
|
169
172
|
}
|
|
170
173
|
/**
|
|
171
174
|
* Runs with this stage's console CAPTURED to a file (see StageOutputLog). What still reaches the
|
|
@@ -197,7 +200,13 @@ let FinishUpsertPrCommand = class FinishUpsertPrCommand {
|
|
|
197
200
|
// applicable set for free — an unchanged checklist needs no re-review, a newly-applicable one refuses
|
|
198
201
|
// until its file is written.
|
|
199
202
|
const featureName = this.aiBranchName.getFeatureName();
|
|
200
|
-
const
|
|
203
|
+
const config = (0, rules_config_1.loadAndValidate)(repoRoot).prGate;
|
|
204
|
+
const scan = this.checklistScanner.scan(repoRoot, config.checklists, new checklist_scanner_1.ChecklistScanOptions(true, 'stage3-finish'));
|
|
205
|
+
const receipt = this.receipts.read(repoRoot, featureName);
|
|
206
|
+
const remediations = this.rounds.capRemediations(repoRoot, scan.summaryPath, receipt, config.maxReviewerRounds);
|
|
207
|
+
for (const result of scan.results)
|
|
208
|
+
result.remediation = remediations[result.id] ?? '';
|
|
209
|
+
scan.outstanding = scan.outstanding.filter((req) => remediations[req.id] === undefined);
|
|
201
210
|
const required = scan.applicable;
|
|
202
211
|
// The applicable checklists that are supposed to HAVE a verdict — everything except the optional ones
|
|
203
212
|
// nobody ran. Used for provenance and for the dashboard rows, both of which ask "who reviewed this?"
|
|
@@ -210,12 +219,13 @@ let FinishUpsertPrCommand = class FinishUpsertPrCommand {
|
|
|
210
219
|
// nobody should wait on a build to be told a reviewer never ran. ReviewerVerdictGate owns the
|
|
211
220
|
// distinction between unreadable / REFUSED / never-ran, and retires the red verdicts it acts on.
|
|
212
221
|
this.verdictGate.assertEveryReviewerRan(scan);
|
|
213
|
-
const review = this.reviewJsonService.loadSummaryJson((0, rules_config_1.summaryJsonPath)(repoRoot, featureName), required,
|
|
222
|
+
const review = this.reviewJsonService.loadSummaryJson((0, rules_config_1.summaryJsonPath)(repoRoot, featureName), required, '', remediations);
|
|
223
|
+
this.applyRoundAudits(review, scan, receipt);
|
|
214
224
|
// 2c. For every verdicted checklist, VERIFY (from the harness's own artifacts) that a real reviewer
|
|
215
225
|
// SUBAGENT actually ran on this branch — the coding agent may not self-certify. Its NAME is not
|
|
216
226
|
// checked; see SubagentProvenanceService.isReviewerRun. Absent CLAUDE_CODE_SESSION_ID this skips with a warning (CI / plain terminal).
|
|
217
227
|
const currentBranch = (0, child_process_1.execSync)('git branch --show-current', { encoding: 'utf8' }).trim();
|
|
218
|
-
const provenance = this.provenanceEnforcer.enforce(verdicted, currentBranch, repoRoot,
|
|
228
|
+
const provenance = this.provenanceEnforcer.enforce(verdicted, currentBranch, repoRoot, config);
|
|
219
229
|
// 2b. The build gate validates the WORKING TREE but we push HEAD — so they MUST be identical.
|
|
220
230
|
this.gitExec.assertCleanTree(repoRoot);
|
|
221
231
|
// 3. Build gate, then post the gated body, then push (that ORDER — see GatedPrPublisher).
|
|
@@ -235,6 +245,16 @@ let FinishUpsertPrCommand = class FinishUpsertPrCommand {
|
|
|
235
245
|
this.stageConsole.say(this.banner.render(bannerInput));
|
|
236
246
|
this.stageConsole.say(this.banner.linkDirective(bannerInput));
|
|
237
247
|
}
|
|
248
|
+
applyRoundAudits(review, scan, receipt) {
|
|
249
|
+
for (const result of review.results) {
|
|
250
|
+
const trail = this.rounds.auditTrail(scan.summaryPath, result.id, receipt);
|
|
251
|
+
if (trail === '')
|
|
252
|
+
continue;
|
|
253
|
+
result.output = trail;
|
|
254
|
+
if (result.remediation !== '')
|
|
255
|
+
result.remediation = `${trail}\n\n#### Final state\n${result.remediation}`;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
238
258
|
/** Hotfix finish owns every prerequisite normally split between stages ② and ③. */
|
|
239
259
|
async runHotfixStage(repoRoot) {
|
|
240
260
|
const state = await this.hotfixFinish.prepare(repoRoot);
|
|
@@ -679,6 +699,7 @@ exports.FinishUpsertPrCommand = FinishUpsertPrCommand = tslib_1.__decorate([
|
|
|
679
699
|
squash_settings_enforcer_1.SquashSettingsEnforcer,
|
|
680
700
|
stage_output_log_1.StageOutputLog,
|
|
681
701
|
rules_config_1.BranchIdentity,
|
|
682
|
-
hotfix_finish_preparer_1.HotfixFinishPreparer
|
|
702
|
+
hotfix_finish_preparer_1.HotfixFinishPreparer,
|
|
703
|
+
review_round_state_1.ReviewRoundStateService])
|
|
683
704
|
], FinishUpsertPrCommand);
|
|
684
705
|
//# sourceMappingURL=finish-upsert-pr-command.js.map
|