@webpieces/pr-gate 0.4.823 → 0.4.825
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 +4 -3
- 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/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/pr-gate-app.d.ts +5 -1
- package/src/scripts/pr-gate-app.js +10 -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/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/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/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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/pr-gate",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.825",
|
|
4
4
|
"description": "Gated PR system: 3-point squash-merge, merge validation gate, and red/yellow/green PR dashboard. Standalone scripts, no Nx dependency required.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@inversifyjs/binding-decorators": "1.1.5",
|
|
19
|
-
"@webpieces/ai-hook-rules": "0.4.
|
|
20
|
-
"@webpieces/rules-config": "0.4.
|
|
19
|
+
"@webpieces/ai-hook-rules": "0.4.825",
|
|
20
|
+
"@webpieces/rules-config": "0.4.825",
|
|
21
21
|
"inversify": "7.10.4",
|
|
22
22
|
"reflect-metadata": "0.2.2"
|
|
23
23
|
},
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"bin": {
|
|
29
29
|
"wp-build": "./src/scripts/wp-build.js",
|
|
30
30
|
"wp-finish-upsert-pr": "./src/scripts/git-finishUpsertPr.js",
|
|
31
|
+
"wp-human-post-pr": "./src/scripts/wp-human-post-pr.js",
|
|
31
32
|
"wp-start-upsert-pr": "./src/scripts/wp-start-upsert-pr.js",
|
|
32
33
|
"wp-start-update": "./src/scripts/wp-start-update.js",
|
|
33
34
|
"wp-finish-update": "./src/scripts/wp-finish-update.js",
|
package/src/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { GateResult, DisableCounts, ChecklistRow, DashboardInput, Dashboard, DETAIL_COMMENT_MARKER, } from './dashboard/dashboard';
|
|
2
2
|
export { ChecklistCommentRenderer, CHECKLIST_COMMENT_MARKER, } from './dashboard/checklist-comment-renderer';
|
|
3
|
-
export { PrCommentUpserter, PrCommentRequest, PrCommentResult } from './scripts/workflow/pr-comment-upserter';
|
|
3
|
+
export { PrCommentUpserter, PrCommentRequest, PrCommentResult, } from './scripts/workflow/pr-comment-upserter';
|
|
4
4
|
export { SquashSettingsEnforcer, SquashSettings, SQUASH_TITLE_REQUIRED, SQUASH_MESSAGE_REQUIRED, } from './scripts/workflow/squash-settings-enforcer';
|
|
5
5
|
export { ChecklistDetector, TriggeredChecklist } from './scripts/workflow/checklist-detector';
|
|
6
6
|
export { PrGateApp } from './scripts/pr-gate-app';
|
package/src/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
// Now published to npm via the release workflow (OIDC trusted publishing).
|
|
5
5
|
// Public surface is intentionally small for now. The package mainly ships bin
|
|
6
|
-
// commands (wp-start-update, wp-finish-update, wp-finish-upsert-pr, wp-start-upsert-pr).
|
|
6
|
+
// commands (wp-start-update, wp-finish-update, wp-finish-upsert-pr, wp-human-post-pr, wp-start-upsert-pr).
|
|
7
7
|
// The build gate and 3-point merge-info gathering are internal `workflow/` library functions
|
|
8
8
|
// (BuildAffected.runBuildGate, gatherInfo), not bins. Shared library exports (dashboard gate
|
|
9
9
|
// computation, etc.) back the dashboard those commands render.
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/tooling/pr-gate/src/index.ts"],"names":[],"mappings":";AAAA,wCAAwC;AACxC,EAAE;AACF,2EAA2E;AAC3E,8EAA8E;AAC9E,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/tooling/pr-gate/src/index.ts"],"names":[],"mappings":";AAAA,wCAAwC;AACxC,EAAE;AACF,2EAA2E;AAC3E,8EAA8E;AAC9E,2GAA2G;AAC3G,6FAA6F;AAC7F,6FAA6F;AAC7F,+DAA+D;AAC/D,EAAE;AACF,oGAAoG;AACpG,iGAAiG;AACjG,sGAAsG;AACtG,4CAA4C;;;AAE5C,mDAO+B;AAN3B,uGAAA,UAAU,OAAA;AACV,0GAAA,aAAa,OAAA;AACb,yGAAA,YAAY,OAAA;AACZ,2GAAA,cAAc,OAAA;AACd,sGAAA,SAAS,OAAA;AACT,kHAAA,qBAAqB,OAAA;AAEzB,uGAAuG;AACvG,kFAAkF;AAClF,qFAGgD;AAF5C,sIAAA,wBAAwB,OAAA;AACxB,sIAAA,wBAAwB,OAAA;AAE5B,8EAIgD;AAH5C,wHAAA,iBAAiB,OAAA;AACjB,uHAAA,gBAAgB,OAAA;AAChB,sHAAA,eAAe,OAAA;AAEnB,wGAAwG;AACxG,kGAAkG;AAClG,wFAKqD;AAJjD,kIAAA,sBAAsB,OAAA;AACtB,0HAAA,cAAc,OAAA;AACd,iIAAA,qBAAqB,OAAA;AACrB,mIAAA,uBAAuB,OAAA;AAE3B,4EAA8F;AAArF,uHAAA,iBAAiB,OAAA;AAAE,wHAAA,kBAAkB,OAAA;AAC9C,qDAAkD;AAAzC,wGAAA,SAAS,OAAA","sourcesContent":["// @webpieces/pr-gate — gated PR system.\n//\n// Now published to npm via the release workflow (OIDC trusted publishing).\n// Public surface is intentionally small for now. The package mainly ships bin\n// commands (wp-start-update, wp-finish-update, wp-finish-upsert-pr, wp-human-post-pr, wp-start-upsert-pr).\n// The build gate and 3-point merge-info gathering are internal `workflow/` library functions\n// (BuildAffected.runBuildGate, gatherInfo), not bins. Shared library exports (dashboard gate\n// computation, etc.) back the dashboard those commands render.\n//\n// `runBuildGate` is the ONLY way to run a build — the `runBuildAffected` / `runConfiguredBuildGate`\n// side doors it used to sit beside are gone, folded into one private spawn, because each of them\n// executed `buildCommand` with no caller identity and no `~/.webpieces/builds.log` row. One spelling,\n// and an unlogged build no longer compiles.\n\nexport {\n GateResult,\n DisableCounts,\n ChecklistRow,\n DashboardInput,\n Dashboard,\n DETAIL_COMMENT_MARKER,\n} from './dashboard/dashboard';\n// The 2nd PR comment's renderer — its own surface, its own class. A barrel is the surface too, so this\n// is exported alongside Dashboard rather than left reachable only by deep import.\nexport {\n ChecklistCommentRenderer,\n CHECKLIST_COMMENT_MARKER,\n} from './dashboard/checklist-comment-renderer';\nexport {\n PrCommentUpserter,\n PrCommentRequest,\n PrCommentResult,\n} from './scripts/workflow/pr-comment-upserter';\n// Pins the two server-side GitHub settings the git-log body depends on. Exported because a consumer may\n// want to assert them in its own CI — they are the one part of this design no config can express.\nexport {\n SquashSettingsEnforcer,\n SquashSettings,\n SQUASH_TITLE_REQUIRED,\n SQUASH_MESSAGE_REQUIRED,\n} from './scripts/workflow/squash-settings-enforcer';\nexport { ChecklistDetector, TriggeredChecklist } from './scripts/workflow/checklist-detector';\nexport { PrGateApp } from './scripts/pr-gate-app';\n"]}
|
|
@@ -57,6 +57,9 @@ export declare class BuildCommand {
|
|
|
57
57
|
private readonly homeConfig;
|
|
58
58
|
constructor(buildAffected: BuildAffected, repoRootFinder: RepoRootFinder, buildsLog: BuildsLog, homeConfig: HomeConfigService);
|
|
59
59
|
run(opts: BuildOptions): Promise<void>;
|
|
60
|
+
/** Human-terminal form used by wp-human-post-pr; build.log remains complete while output is live. */
|
|
61
|
+
runStreaming(opts: BuildOptions): Promise<void>;
|
|
62
|
+
private runGate;
|
|
60
63
|
/**
|
|
61
64
|
* Refuse when this MACHINE is already running `maxConcurrentBuilds` builds.
|
|
62
65
|
*
|
|
@@ -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;AA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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,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,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAED,qGAAqG;IACrG,YAAY,CAAC,IAAkB;QAC3B,OAAO,I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,CACN,uEAAuE;gBACnE,0EAA0E,CACjF;YACD,IAAI,qBAAM,CACN,wEAAwE;gBACpE,iFAAiF,CACxF;YACD,IAAI,qBAAM,CACN,iFAAiF;gBAC7E,mCAAmC,CAC1C;SACJ,CACJ,CAAC;IACN,CAAC;IAED,gGAAgG;IAChG,oGAAoG;IAC5F,QAAQ,CAAC,IAA6B;QAC1C,OAAO,IAAI;aACN,GAAG,CAAC,CAAC,KAAmB,EAAU,EAAE;YACjC,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,CACH,OAAO,KAAK,CAAC,IAAI,UAAU,KAAK,CAAC,IAAI,IAAI,SAAS,IAAI;gBACtD,UAAU,KAAK,CAAC,MAAM,IAAI,GAAG,OAAO,KAAK,CAAC,EAAE,QAAQ,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG;gBACxE,eAAe,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,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AAEI,IAAM,cAAc,GAApB,MAAM,cAAc;IAEF;IACA;IAFrB,YACqB,cAA8B,EAC9B,gBAAkC;QADlC,mBAAc,GAAd,cAAc,CAAgB;QAC9B,qBAAgB,GAAhB,gBAAgB,CAAkB;IACpD,CAAC;IAEJ,KAAK,CAAC,GAAG;QACL,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QACpE,MAAM,QAAQ,GAAG,IAAA,8BAAe,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAC3D,IAAI,QAAQ,CAAC,IAAI,EAAE,K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d,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,mBAAc,GAAd,cAAc,CAAgB;QAC9B,qBAAgB,GAAhB,gBAAgB,CAAkB;IACpD,CAAC;IAEJ,KAAK,CAAC,GAAG;QACL,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QACpE,MAAM,QAAQ,GAAG,IAAA,8BAAe,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAC3D,IAAI,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YACzB,MAAM,IAAI,2BAAY,CAClB,CAAC,EACD,mGAAmG;gBAC/F,6FAA6F,CACpG,CAAC;QACN,CAAC;QAED,IAAI,EAAE,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAC1B,IAAI,EAAE,CAAC,OAAO,KAAK,EAAE,EAAE,CAAC;YACpB,MAAM,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cesContent":["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"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { BranchIdentity, GateTokenService, MainSyncStatusService, RepoRootFinder, ReviewJsonService } from '@webpieces/rules-config';
|
|
2
|
+
import { AiBranchName } from '../workflow/git-readAiBranchName';
|
|
3
|
+
import { BranchNaming } from '../workflow/branch-naming';
|
|
4
|
+
import { GatedPrPublisher } from '../workflow/gated-pr-publisher';
|
|
5
|
+
import { GitExec } from '../workflow/git-exec';
|
|
6
|
+
import { MergeState } from '../workflow/merge-state';
|
|
7
|
+
import { SquashSettingsEnforcer } from '../workflow/squash-settings-enforcer';
|
|
8
|
+
import { BuildCommand } from './build-command';
|
|
9
|
+
/** The PR identity returned by GitHub after posting. Data-only, per CLAUDE.md. */
|
|
10
|
+
export declare class HumanPostedPr {
|
|
11
|
+
number: string;
|
|
12
|
+
url: string;
|
|
13
|
+
constructor(number: string, url: string);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Interactive, human-attested PR escape hatch.
|
|
17
|
+
*
|
|
18
|
+
* The first answer is an attestation, not identity detection: a process cannot prove who typed it. The
|
|
19
|
+
* fail-closed ordering is the security property here — every answer except the literal normalized
|
|
20
|
+
* `human` returns before repository discovery, git, GitHub, or any write.
|
|
21
|
+
*/
|
|
22
|
+
export declare class HumanPostPrCommand {
|
|
23
|
+
private readonly repoRootFinder;
|
|
24
|
+
private readonly branchIdentity;
|
|
25
|
+
private readonly branchNaming;
|
|
26
|
+
private readonly aiBranchName;
|
|
27
|
+
private readonly gitExec;
|
|
28
|
+
private readonly mergeState;
|
|
29
|
+
private readonly reviewJsonService;
|
|
30
|
+
private readonly mainSyncStatus;
|
|
31
|
+
private readonly gateTokenService;
|
|
32
|
+
private readonly publisher;
|
|
33
|
+
private readonly squashSettings;
|
|
34
|
+
private readonly buildCommand;
|
|
35
|
+
constructor(repoRootFinder: RepoRootFinder, branchIdentity: BranchIdentity, branchNaming: BranchNaming, aiBranchName: AiBranchName, gitExec: GitExec, mergeState: MergeState, reviewJsonService: ReviewJsonService, mainSyncStatus: MainSyncStatusService, gateTokenService: GateTokenService, publisher: GatedPrPublisher, squashSettings: SquashSettingsEnforcer, buildCommand: BuildCommand);
|
|
36
|
+
run(): Promise<void>;
|
|
37
|
+
/** The safe body-before-push publication shared with the automated flow via GatedPrPublisher. */
|
|
38
|
+
private post;
|
|
39
|
+
private askToBuild;
|
|
40
|
+
private assertNoUnvalidatedMerge;
|
|
41
|
+
protected fetchMain(repoRoot: string): void;
|
|
42
|
+
protected gateSalt(repoRoot: string): string;
|
|
43
|
+
private ensureSummary;
|
|
44
|
+
private assertCurrentMain;
|
|
45
|
+
private renderBody;
|
|
46
|
+
private titleFrom;
|
|
47
|
+
protected resolvePr(branch: string): HumanPostedPr;
|
|
48
|
+
protected backfillBody(prNumber: string, bodyFile: string, body: string): void;
|
|
49
|
+
protected editPrBody(prNumber: string, bodyFile: string): number | null;
|
|
50
|
+
protected git(args: string[], cwd: string, failure: string): string;
|
|
51
|
+
protected question(prompt: string): Promise<string>;
|
|
52
|
+
}
|