@webpieces/pr-gate 0.4.975 → 0.4.977
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 +6 -6
- package/src/scripts/commands/await-checks-command.d.ts +6 -3
- package/src/scripts/commands/await-checks-command.js +17 -12
- package/src/scripts/commands/await-checks-command.js.map +1 -1
- package/src/scripts/commands/await-reviews-command.d.ts +1 -1
- package/src/scripts/commands/await-reviews-command.js +3 -3
- package/src/scripts/commands/await-reviews-command.js.map +1 -1
- package/src/scripts/commands/check-pr-command.d.ts +3 -1
- package/src/scripts/commands/check-pr-command.js +12 -9
- package/src/scripts/commands/check-pr-command.js.map +1 -1
- package/src/scripts/commands/cleanup-command.js +12 -12
- package/src/scripts/commands/cleanup-command.js.map +1 -1
- package/src/scripts/commands/finish-push-dev-command.js +3 -4
- package/src/scripts/commands/finish-push-dev-command.js.map +1 -1
- package/src/scripts/commands/finish-update-command.js +1 -1
- package/src/scripts/commands/finish-update-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 +65 -62
- package/src/scripts/commands/finish-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/human-post-pr-command.d.ts +8 -6
- package/src/scripts/commands/human-post-pr-command.js +33 -32
- package/src/scripts/commands/human-post-pr-command.js.map +1 -1
- package/src/scripts/commands/land-pr-command.d.ts +5 -1
- package/src/scripts/commands/land-pr-command.js +37 -23
- package/src/scripts/commands/land-pr-command.js.map +1 -1
- package/src/scripts/commands/main-checkout.d.ts +4 -1
- package/src/scripts/commands/main-checkout.js +22 -22
- package/src/scripts/commands/main-checkout.js.map +1 -1
- package/src/scripts/commands/push-dev-command.js +28 -29
- package/src/scripts/commands/push-dev-command.js.map +1 -1
- package/src/scripts/commands/reap-worktree-command.js +4 -5
- package/src/scripts/commands/reap-worktree-command.js.map +1 -1
- package/src/scripts/commands/review-upsert-pr-command.js +10 -10
- package/src/scripts/commands/review-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/start-update-command.d.ts +1 -1
- package/src/scripts/commands/start-update-command.js +3 -3
- package/src/scripts/commands/start-update-command.js.map +1 -1
- package/src/scripts/commands/start-upsert-pr-command.js +4 -4
- package/src/scripts/commands/start-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/sync-main-command.js +6 -6
- package/src/scripts/commands/sync-main-command.js.map +1 -1
- package/src/scripts/commands/upsert-hotfix-pr-command.d.ts +6 -4
- package/src/scripts/commands/upsert-hotfix-pr-command.js +46 -43
- package/src/scripts/commands/upsert-hotfix-pr-command.js.map +1 -1
- package/src/scripts/commands/working-tree-gate.d.ts +4 -1
- package/src/scripts/commands/working-tree-gate.js +14 -11
- package/src/scripts/commands/working-tree-gate.js.map +1 -1
- package/src/scripts/commands/worktree-cleanup.d.ts +4 -4
- package/src/scripts/commands/worktree-cleanup.js +4 -4
- package/src/scripts/commands/worktree-cleanup.js.map +1 -1
- package/src/scripts/commands/write-review-command.js +4 -6
- package/src/scripts/commands/write-review-command.js.map +1 -1
- package/src/scripts/commands/write-review-fixes-command.js +3 -4
- package/src/scripts/commands/write-review-fixes-command.js.map +1 -1
- package/src/scripts/git-finishUpsertPr.js +2 -2
- package/src/scripts/git-finishUpsertPr.js.map +1 -1
- package/src/scripts/git-gatherInfo.js +6 -7
- package/src/scripts/git-gatherInfo.js.map +1 -1
- package/src/scripts/pr-gate-container.d.ts +9 -0
- package/src/scripts/pr-gate-container.js +19 -0
- package/src/scripts/pr-gate-container.js.map +1 -0
- package/src/scripts/workflow/await-loop.d.ts +1 -1
- package/src/scripts/workflow/await-loop.js +1 -1
- package/src/scripts/workflow/await-loop.js.map +1 -1
- package/src/scripts/workflow/build-affected.js +1 -1
- package/src/scripts/workflow/build-affected.js.map +1 -1
- package/src/scripts/workflow/build-artifact-gate.d.ts +1 -1
- package/src/scripts/workflow/build-artifact-gate.js +3 -3
- package/src/scripts/workflow/build-artifact-gate.js.map +1 -1
- package/src/scripts/workflow/build-gate-log.d.ts +9 -6
- package/src/scripts/workflow/build-gate-log.js +34 -40
- package/src/scripts/workflow/build-gate-log.js.map +1 -1
- package/src/scripts/workflow/checklist-detector.d.ts +2 -2
- package/src/scripts/workflow/checklist-detector.js +4 -4
- package/src/scripts/workflow/checklist-detector.js.map +1 -1
- package/src/scripts/workflow/checklist-scanner.d.ts +1 -1
- package/src/scripts/workflow/checklist-scanner.js +11 -11
- package/src/scripts/workflow/checklist-scanner.js.map +1 -1
- package/src/scripts/workflow/checklist-scope-hasher.d.ts +1 -1
- package/src/scripts/workflow/checklist-scope-hasher.js +2 -2
- package/src/scripts/workflow/checklist-scope-hasher.js.map +1 -1
- package/src/scripts/workflow/dev-deploy-refs.d.ts +5 -5
- package/src/scripts/workflow/dev-deploy-refs.js +8 -8
- package/src/scripts/workflow/dev-deploy-refs.js.map +1 -1
- package/src/scripts/workflow/dev-resolve-runner.d.ts +3 -3
- package/src/scripts/workflow/dev-resolve-runner.js +30 -30
- package/src/scripts/workflow/dev-resolve-runner.js.map +1 -1
- package/src/scripts/workflow/diff-basis.d.ts +4 -2
- package/src/scripts/workflow/diff-basis.js +18 -15
- package/src/scripts/workflow/diff-basis.js.map +1 -1
- package/src/scripts/workflow/diff-materializer.d.ts +5 -3
- package/src/scripts/workflow/diff-materializer.js +18 -15
- package/src/scripts/workflow/diff-materializer.js.map +1 -1
- package/src/scripts/workflow/gated-pr-publisher.d.ts +8 -6
- package/src/scripts/workflow/gated-pr-publisher.js +23 -22
- package/src/scripts/workflow/gated-pr-publisher.js.map +1 -1
- package/src/scripts/workflow/generated-artifact-registry.d.ts +4 -2
- package/src/scripts/workflow/generated-artifact-registry.js +11 -8
- package/src/scripts/workflow/generated-artifact-registry.js.map +1 -1
- package/src/scripts/workflow/git-exec.d.ts +22 -12
- package/src/scripts/workflow/git-exec.js +45 -29
- package/src/scripts/workflow/git-exec.js.map +1 -1
- package/src/scripts/workflow/git-findForkPoint.d.ts +6 -2
- package/src/scripts/workflow/git-findForkPoint.js +31 -23
- package/src/scripts/workflow/git-findForkPoint.js.map +1 -1
- package/src/scripts/workflow/git-readAiBranchName.d.ts +4 -2
- package/src/scripts/workflow/git-readAiBranchName.js +8 -5
- package/src/scripts/workflow/git-readAiBranchName.js.map +1 -1
- package/src/scripts/workflow/hotfix-pr-publisher.d.ts +4 -3
- package/src/scripts/workflow/hotfix-pr-publisher.js +7 -6
- package/src/scripts/workflow/hotfix-pr-publisher.js.map +1 -1
- package/src/scripts/workflow/landed-tree-resolver.d.ts +4 -2
- package/src/scripts/workflow/landed-tree-resolver.js +11 -8
- package/src/scripts/workflow/landed-tree-resolver.js.map +1 -1
- package/src/scripts/workflow/landed-worktree-reaper.d.ts +4 -2
- package/src/scripts/workflow/landed-worktree-reaper.js +12 -9
- package/src/scripts/workflow/landed-worktree-reaper.js.map +1 -1
- package/src/scripts/workflow/merge-end.d.ts +5 -4
- package/src/scripts/workflow/merge-end.js +28 -27
- package/src/scripts/workflow/merge-end.js.map +1 -1
- package/src/scripts/workflow/merge-start.d.ts +5 -1
- package/src/scripts/workflow/merge-start.js +56 -49
- package/src/scripts/workflow/merge-start.js.map +1 -1
- package/src/scripts/workflow/open-pr-check.d.ts +4 -2
- package/src/scripts/workflow/open-pr-check.js +11 -8
- package/src/scripts/workflow/open-pr-check.js.map +1 -1
- package/src/scripts/workflow/pr-comment-upserter.d.ts +5 -3
- package/src/scripts/workflow/pr-comment-upserter.js +15 -14
- package/src/scripts/workflow/pr-comment-upserter.js.map +1 -1
- package/src/scripts/workflow/pr-context-writer.d.ts +1 -1
- package/src/scripts/workflow/pr-context-writer.js +3 -3
- package/src/scripts/workflow/pr-context-writer.js.map +1 -1
- package/src/scripts/workflow/pr-merger.d.ts +8 -5
- package/src/scripts/workflow/pr-merger.js +32 -27
- package/src/scripts/workflow/pr-merger.js.map +1 -1
- package/src/scripts/workflow/provenance-enforcer.d.ts +4 -2
- package/src/scripts/workflow/provenance-enforcer.js +19 -17
- package/src/scripts/workflow/provenance-enforcer.js.map +1 -1
- package/src/scripts/workflow/review-round-state.d.ts +7 -6
- package/src/scripts/workflow/review-round-state.js +33 -38
- package/src/scripts/workflow/review-round-state.js.map +1 -1
- package/src/scripts/workflow/run-update.js +1 -1
- package/src/scripts/workflow/run-update.js.map +1 -1
- package/src/scripts/workflow/squash-settings-enforcer.d.ts +6 -3
- package/src/scripts/workflow/squash-settings-enforcer.js +19 -14
- package/src/scripts/workflow/squash-settings-enforcer.js.map +1 -1
- package/src/scripts/wp-await-checks.js +2 -2
- package/src/scripts/wp-await-checks.js.map +1 -1
- package/src/scripts/wp-await-reviews.js +2 -2
- package/src/scripts/wp-await-reviews.js.map +1 -1
- package/src/scripts/wp-build.js +2 -2
- package/src/scripts/wp-build.js.map +1 -1
- package/src/scripts/wp-check-pr.js +2 -2
- package/src/scripts/wp-check-pr.js.map +1 -1
- package/src/scripts/wp-cleanup.js +2 -2
- package/src/scripts/wp-cleanup.js.map +1 -1
- package/src/scripts/wp-finish-push-dev.js +2 -2
- package/src/scripts/wp-finish-push-dev.js.map +1 -1
- package/src/scripts/wp-finish-update.js +2 -2
- package/src/scripts/wp-finish-update.js.map +1 -1
- package/src/scripts/wp-human-post-pr.js +2 -2
- package/src/scripts/wp-human-post-pr.js.map +1 -1
- package/src/scripts/wp-land-pr.js +2 -2
- package/src/scripts/wp-land-pr.js.map +1 -1
- package/src/scripts/wp-push-dev.js +2 -2
- package/src/scripts/wp-push-dev.js.map +1 -1
- package/src/scripts/wp-reap-worktree.js +2 -2
- package/src/scripts/wp-reap-worktree.js.map +1 -1
- package/src/scripts/wp-review-upsert-pr.js +2 -2
- package/src/scripts/wp-review-upsert-pr.js.map +1 -1
- package/src/scripts/wp-start-update.js +2 -2
- package/src/scripts/wp-start-update.js.map +1 -1
- package/src/scripts/wp-start-upsert-pr.js +2 -2
- package/src/scripts/wp-start-upsert-pr.js.map +1 -1
- package/src/scripts/wp-sync-main.js +2 -2
- package/src/scripts/wp-sync-main.js.map +1 -1
- package/src/scripts/wp-upsert-hotfix-pr.js +2 -2
- package/src/scripts/wp-upsert-hotfix-pr.js.map +1 -1
- package/src/scripts/wp-write-review-fixes.js +2 -2
- package/src/scripts/wp-write-review-fixes.js.map +1 -1
- package/src/scripts/wp-write-review.js +2 -2
- package/src/scripts/wp-write-review.js.map +1 -1
|
@@ -79,11 +79,11 @@ let WriteReviewCommand = class WriteReviewCommand {
|
|
|
79
79
|
this.provenance = provenance;
|
|
80
80
|
this.reviewJsonService = reviewJsonService;
|
|
81
81
|
}
|
|
82
|
-
run(opts) {
|
|
82
|
+
async run(opts) {
|
|
83
83
|
const id = opts.checklistId.trim();
|
|
84
84
|
const cwd = opts.cwd;
|
|
85
85
|
const repoRoot = this.repoRootFinder.resolveRepoRoot(cwd);
|
|
86
|
-
const featureName = this.aiBranchName.getFeatureName();
|
|
86
|
+
const featureName = await this.aiBranchName.getFeatureName();
|
|
87
87
|
const receipt = this.briefedReceipt(repoRoot, featureName, id);
|
|
88
88
|
// Identity BEFORE parsing: a coordinator is refused whatever it submitted, and the stamp it
|
|
89
89
|
// consumes must not survive to lend itself to a later call.
|
|
@@ -96,16 +96,15 @@ let WriteReviewCommand = class WriteReviewCommand {
|
|
|
96
96
|
process.stdout.write(`✅ ${verdict.status.toUpperCase()} verdict for "${id}" submitted → ${written}\n`
|
|
97
97
|
+ ` provenance: ${who.harness}${who.agentId === '' ? '' : ` agent ${who.agentId}`}, `
|
|
98
98
|
+ `briefed at ${receipt.headSha.slice(0, 8)}, global round ${receipt.round} of ${receipt.maxReviewerRounds}\n`);
|
|
99
|
-
return Promise.resolve();
|
|
100
99
|
}
|
|
101
100
|
/**
|
|
102
101
|
* `wp-write-review --check`: the reviewer's FIRST step. Refuses exactly when {@link run} would refuse
|
|
103
102
|
* on the budget, so a reviewer past the budget learns it before it reviews rather than after.
|
|
104
103
|
*/
|
|
105
|
-
check(opts) {
|
|
104
|
+
async check(opts) {
|
|
106
105
|
const id = opts.checklistId.trim();
|
|
107
106
|
const repoRoot = this.repoRootFinder.resolveRepoRoot(opts.cwd);
|
|
108
|
-
const featureName = this.aiBranchName.getFeatureName();
|
|
107
|
+
const featureName = await this.aiBranchName.getFeatureName();
|
|
109
108
|
const receipt = this.briefedReceipt(repoRoot, featureName, id);
|
|
110
109
|
this.assertWithinBudget((0, rules_config_1.summaryJsonPath)(repoRoot, featureName), receipt, id);
|
|
111
110
|
const final = this.isFinalRound(receipt)
|
|
@@ -113,7 +112,6 @@ let WriteReviewCommand = class WriteReviewCommand {
|
|
|
113
112
|
: '';
|
|
114
113
|
process.stdout.write(`✅ "${id}" may be reviewed: this is review round ${receipt.round} of at most ${receipt.maxReviewerRounds}.${final} `
|
|
115
114
|
+ `Review it, then submit with pnpm ${repo_workflow_core_1.WRITE_REVIEW_BIN} --checklist ${id}.\n`);
|
|
116
|
-
return Promise.resolve();
|
|
117
115
|
}
|
|
118
116
|
/** The last round `maxReviewerRounds` allows — the one with no red (issue #1053). */
|
|
119
117
|
isFinalRound(receipt) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-review-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/write-review-command.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,8DAA0D;AAC1D,iEAA6D;AAC7D,0DAAsK;AACtK,sEAAiE;AACjE,yCAA2D;AAC3D,2EAAgE;AAChE,2EAAiG;AACjG,qEAA2F;AAC3F,uEAA+G;AAG/G,oFAAoF;AACpF,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAU,CAAC;AAE3E,yDAAyD;AACzD,MAAa,kBAAkB;IAC3B,WAAW,CAAS;IACpB,sGAAsG;IACtG,iEAAiE;IACjE,IAAI,CAAS;IACb,kGAAkG;IAClG,8EAA8E;IAC9E,GAAG,CAAS;IAEZ,YAAY,WAAmB,EAAE,IAAY,EAAE,GAAW;QACtD,IAA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AC;CACJ,CAAA;AArKY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAIA,6BAAc;QAChB,mCAAY;QAChB,gDAAyB;QACzB,4CAAwB;QACtB,6CAAwB;QACjB,gCAAiB;GARhD,kBAAkB,CAqK9B;AAED;;;GAGG;AAEI,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IACzB,IAAI,CAAC,QAAgB,EAAE,KAAqB;QACxC,IAAI,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YACzB,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC;gBAAE,MAAM,IAAI,8BAAa,CAAC,GAAG,qCAAgB,YAAY,QAAQ,kBAAkB,CAAC,CAAC;YACjH,OAAO,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC;IACxB,CAAC;CACJ,CAAA;AARY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,gBAAgB,CAQ5B","sourcesContent":["import * as fs from 'fs';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { RepoRootFinder, ReviewJsonService, VERDICT_ORANGE, VERDICT_RED, VERDICT_STATUSES, checklistOverrideService, summaryJsonPath } from '@webpieces/rules-config';\nimport { WRITE_REVIEW_BIN } from '@webpieces/repo-workflow-core';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { ReviewStageReceipt, ReviewStageReceiptService } from '../workflow/review-stage-receipt';\nimport { ReviewerIdentity, ReviewerIdentityResolver } from '../workflow/reviewer-identity';\nimport { SubmittedVerdict, VerdictProvenance, VerdictProvenanceService } from '../workflow/verdict-provenance';\nimport type { PrGateCliStdin } from '../pr-gate-cli-invocation';\n\n/** The only keys a verdict may carry. Anything else is somebody's second schema. */\nconst VERDICT_KEYS = ['id', 'status', 'agent', 'model', 'output'] as const;\n\n/** What `wp-write-review` was asked to do. Data-only. */\nexport class WriteReviewOptions {\n checklistId: string;\n // The verdict JSON itself — read from `--file` or stdin by the composition root, so this command is a\n // function of its inputs and a spec can drive it without a pipe.\n json: string;\n // Where the caller stands — the tree whose review dir and hook stamp are used. Passed in (the bin\n // passes process.cwd()) rather than read here, for the same reason `json` is.\n cwd: string;\n\n constructor(checklistId: string, json: string, cwd: string) {\n this.checklistId = checklistId;\n this.json = json;\n this.cwd = cwd;\n }\n}\n\n/** What `wp-write-review --check` was asked: may this checklist still be reviewed? Data-only. */\nexport class ReviewBudgetCheckOptions {\n checklistId: string;\n cwd: string;\n\n constructor(checklistId: string, cwd: string) {\n this.checklistId = checklistId;\n this.cwd = cwd;\n }\n}\n\n/**\n * `wp-write-review` — the ONE way any reviewer, Claude or Codex, submits a checklist verdict (issue #863).\n *\n * Before it existed a verdict was \"a file with the right shape at the right path\", and that is exactly what\n * a Codex coordinator produced on two merged PRs: the shared-tree guard blocked its reviewer's write, the\n * guard's own cure said to hand the edit to the coordinator, the coordinator wrote all five verdicts, and\n * `wp-finish-upsert-pr` accepted them. Now:\n * 1. the caller is identified by the harness (ReviewerIdentityResolver) and the COORDINATOR is refused;\n * 2. the checklist must be one stage ② briefed this round (its receipt), so a carried verdict cannot be\n * overwritten and a checklist that does not apply cannot be invented;\n * 3. the verdict is validated strictly — the five fields, nothing else;\n * 4. it is written as `review-round<N>-<id>.json` WITH `review-round<N>-<id>.provenance.json`: who, which\n * commit, which in-scope diff, and a hash of the verdict. `wp-finish-upsert-pr` rejects a verdict\n * without one, or one edited since;\n * 5. the round must be inside the budget (issues #1051, #1053): a round above `maxReviewerRounds` records\n * nothing, and a round's verdict is never overwritten, whoever spawned the reviewer. `--check` asks the\n * same question BEFORE a reviewer spends a review on it;\n * 6. the color must fit the round (issue #1053): the FINAL round has no red — its must-fix color is\n * orange, never re-reviewed — and orange is refused before the final round, where red still means\n * \"fix it and it will be reviewed again\".\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class WriteReviewCommand {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly receipts: ReviewStageReceiptService,\n private readonly identity: ReviewerIdentityResolver,\n private readonly provenance: VerdictProvenanceService,\n private readonly reviewJsonService: ReviewJsonService,\n ) {}\n\n run(opts: WriteReviewOptions): Promise<void> {\n const id = opts.checklistId.trim();\n const cwd = opts.cwd;\n const repoRoot = this.repoRootFinder.resolveRepoRoot(cwd);\n const featureName = this.aiBranchName.getFeatureName();\n const receipt = this.briefedReceipt(repoRoot, featureName, id);\n // Identity BEFORE parsing: a coordinator is refused whatever it submitted, and the stamp it\n // consumes must not survive to lend itself to a later call.\n const who: ReviewerIdentity = this.identity.resolve(cwd, id);\n this.assertWithinBudget(summaryJsonPath(repoRoot, featureName), receipt, id);\n const verdict = this.parse(opts.json, id, receipt);\n const record = new VerdictProvenance(\n id, who.harness, who.sessionId, who.agentId, who.agentType, receipt.headSha, receipt.scopeHashes[id] ?? '');\n record.round = receipt.round;\n const written = this.provenance.write(summaryJsonPath(repoRoot, featureName), verdict, record);\n process.stdout.write(\n `✅ ${verdict.status.toUpperCase()} verdict for \"${id}\" submitted → ${written}\\n`\n + ` provenance: ${who.harness}${who.agentId === '' ? '' : ` agent ${who.agentId}`}, `\n + `briefed at ${receipt.headSha.slice(0, 8)}, global round ${receipt.round} of ${receipt.maxReviewerRounds}\\n`);\n return Promise.resolve();\n }\n\n /**\n * `wp-write-review --check`: the reviewer's FIRST step. Refuses exactly when {@link run} would refuse\n * on the budget, so a reviewer past the budget learns it before it reviews rather than after.\n */\n check(opts: ReviewBudgetCheckOptions): Promise<void> {\n const id = opts.checklistId.trim();\n const repoRoot = this.repoRootFinder.resolveRepoRoot(opts.cwd);\n const featureName = this.aiBranchName.getFeatureName();\n const receipt = this.briefedReceipt(repoRoot, featureName, id);\n this.assertWithinBudget(summaryJsonPath(repoRoot, featureName), receipt, id);\n const final = this.isFinalRound(receipt)\n ? ` This is the FINAL round: there is no re-review, so you may NOT mark ${VERDICT_RED} — mark every must-fix finding ${VERDICT_ORANGE}.`\n : '';\n process.stdout.write(\n `✅ \"${id}\" may be reviewed: this is review round ${receipt.round} of at most ${receipt.maxReviewerRounds}.${final} `\n + `Review it, then submit with pnpm ${WRITE_REVIEW_BIN} --checklist ${id}.\\n`);\n return Promise.resolve();\n }\n\n /** The last round `maxReviewerRounds` allows — the one with no red (issue #1053). */\n private isFinalRound(receipt: ReviewStageReceipt): boolean {\n return receipt.round >= receipt.maxReviewerRounds;\n }\n\n /**\n * THE ROUND CAP, held by the reviewer's own submission path (issues #1051, #1053). The planner already\n * never briefs past the cap, but an author agent could still spawn a reviewer from an old instructions\n * file — the measured deadlock did exactly that. Two refusals make it mechanical: a round above\n * `maxReviewerRounds` records nothing, and a checklist that already has a verdict in this round (or a\n * later one) gets no second one — a round's verdict is never overwritten.\n */\n private assertWithinBudget(summaryPath: string, receipt: ReviewStageReceipt, id: string): void {\n const max = receipt.maxReviewerRounds;\n const latest = this.reviewJsonService.latestVerdictRound(summaryPath, id);\n if (receipt.round <= max && latest < receipt.round) return;\n const why = receipt.round > max\n ? `this briefing is for review round ${receipt.round}, above maxReviewerRounds (${max})`\n : `it already has a verdict for review round ${latest} (maxReviewerRounds is ${max}), and a round's verdict is never overwritten`;\n throw new InformAiError(\n `I am not allowed to review ${id}: ${why}.\\n`\n + `Do not review it and submit nothing for it; report this refusal, verbatim, to the agent that spawned you. `\n + `The verdict already recorded for it stands (${this.reviewJsonService.latestChecklistResultPath(summaryPath, id) || 'none'}), and `\n + 'the author records any fix with pnpm wp-write-review-fixes.');\n }\n\n /** The stage-② receipt, provided it briefed THIS checklist this round. */\n private briefedReceipt(repoRoot: string, featureName: string, id: string): ReviewStageReceipt {\n if (id === '') throw new InformAiError(`${WRITE_REVIEW_BIN} needs the checklist id: pnpm ${WRITE_REVIEW_BIN} --checklist <id>`);\n const receipt = this.receipts.read(repoRoot, featureName);\n if (receipt === null) {\n throw new InformAiError(`${WRITE_REVIEW_BIN}: pnpm wp-review-upsert-pr has not briefed any reviewer on this branch yet, `\n + 'so there is nothing to submit a verdict against.');\n }\n if (!receipt.reviewersBriefed.includes(id) || (receipt.scopeHashes[id] ?? '') === '') {\n const briefed = receipt.reviewersBriefed.length === 0 ? '(none)' : receipt.reviewersBriefed.join(', ');\n throw new InformAiError(`${WRITE_REVIEW_BIN}: checklist \"${id}\" was not briefed by the last pnpm wp-review-upsert-pr `\n + `(briefed this round: ${briefed}). Submit only for a checklist whose instructions file you were handed — `\n + 'a checklist absent here either carries its earlier verdict or does not apply to this diff.');\n }\n return receipt;\n }\n\n /**\n * Strict: an object with exactly the verdict's five fields, every one a string, and a status that fits\n * the round — red only BEFORE the final round, orange only ON it (issue #1053).\n */\n private parse(json: string, id: string, receipt: ReviewStageReceipt): SubmittedVerdict {\n const raw = this.parseObject(json);\n const problems: string[] = [];\n const extra = Object.keys(raw).filter((k: string): boolean => !(VERDICT_KEYS as readonly string[]).includes(k));\n if (extra.includes('override')) {\n problems.push(`\"override\" is not a verdict field — a ship-anyway decision is a HUMAN's, recorded by the coordinating agent in ${checklistOverrideService.overrideFileName(id)}`);\n }\n if (extra.length > 0) problems.push(`unknown field(s) ${extra.map((k: string): string => `\"${k}\"`).join(', ')} — a verdict has exactly: ${VERDICT_KEYS.join(', ')}`);\n if (raw['id'] !== undefined && this.text(raw, 'id') !== id) problems.push(`\"id\" is ${JSON.stringify(raw['id'])} but --checklist is \"${id}\"`);\n const status = this.text(raw, 'status').toLowerCase();\n // webpieces-disable no-any-unknown -- comparing against the readonly literal tuple of valid colors\n if (!(VERDICT_STATUSES as readonly string[]).includes(status)) problems.push(`\"status\" must be one of ${VERDICT_STATUSES.join(', ')}`);\n problems.push(...this.colorForRound(status, receipt));\n for (const key of ['agent', 'model', 'output']) {\n if (this.text(raw, key) === '') problems.push(`\"${key}\" must be a non-empty string${key === 'output' ? '' : ' (use \"unknown\" when unavailable)'}`);\n }\n if (problems.length > 0) {\n throw new InformAiError(`${WRITE_REVIEW_BIN}: the verdict for \"${id}\" was NOT submitted:\\n`\n + problems.map((p: string): string => ` • ${p}`).join('\\n'));\n }\n return new SubmittedVerdict(id, status, this.text(raw, 'agent'), this.text(raw, 'model'), raw['output'] as string);\n }\n\n /**\n * The round decides which blocking color exists. The FINAL round's red would mean \"fix it and it will be\n * reviewed again\", and there is no again — so it is refused and orange named. Orange before the final\n * round would waive a re-review that the budget still pays for — so it is refused and red named.\n */\n private colorForRound(status: string, receipt: ReviewStageReceipt): string[] {\n const round = `review round ${receipt.round} of ${receipt.maxReviewerRounds}`;\n if (status === VERDICT_RED && this.isFinalRound(receipt)) {\n return [`\"status\": \"${VERDICT_RED}\" is not allowed: ${round} is the FINAL round, and there is no re-review. `\n + `Mark anything that must be fixed \"${VERDICT_ORANGE}\", with a concrete, actionable fix in \"output\" — the author applies it `\n + 'best effort and ships without another review.'];\n }\n if (status === VERDICT_ORANGE && !this.isFinalRound(receipt)) {\n return [`\"status\": \"${VERDICT_ORANGE}\" is only for the FINAL review round, and ${round} is not it. `\n + `Use \"${VERDICT_RED}\" for a must-fix finding: the author's fix will be reviewed again next round.`];\n }\n return [];\n }\n\n // webpieces-disable no-any-unknown -- one field of the opaque submitted object, narrowed to a trimmed string\n private text(raw: Record<string, unknown>, key: string): string {\n const value = raw[key];\n return typeof value === 'string' ? value.trim() : '';\n }\n\n // webpieces-disable no-any-unknown -- the submitted JSON is opaque until parse() narrows every field\n private parseObject(json: string): Record<string, unknown> {\n // webpieces-disable no-any-unknown -- parsed JSON is opaque until narrowed\n let parsed: unknown = null;\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: a JSON syntax error becomes the AI-facing refusal\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n parsed = JSON.parse(json);\n } catch (err: unknown) {\n const error = toError(err);\n throw new InformAiError(`${WRITE_REVIEW_BIN}: the verdict is not valid JSON.`, { cause: error });\n }\n if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {\n throw new InformAiError(`${WRITE_REVIEW_BIN}: the verdict must be ONE JSON object.`);\n }\n // webpieces-disable no-any-unknown -- narrowed to a plain object just above\n return parsed as Record<string, unknown>;\n }\n}\n\n/**\n * Reads the verdict JSON for the composition root: `--file <path>`, else stdin. Separate from the command\n * so the command stays a function of its inputs.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class WriteReviewInput {\n read(filePath: string, stdin: PrGateCliStdin): string {\n if (filePath.trim() !== '') {\n if (!fs.existsSync(filePath)) throw new InformAiError(`${WRITE_REVIEW_BIN}: --file ${filePath} does not exist.`);\n return fs.readFileSync(filePath, 'utf8');\n }\n return stdin.read();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"write-review-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/write-review-command.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,8DAA0D;AAC1D,iEAA6D;AAC7D,0DAAsK;AACtK,sEAAiE;AACjE,yCAA2D;AAC3D,2EAAgE;AAChE,2EAAiG;AACjG,qEAA2F;AAC3F,uEAA+G;AAG/G,oFAAoF;AACpF,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAU,CAAC;AAE3E,yDAAyD;AACzD,MAAa,kBAAkB;IAC3B,WAAW,CAAS;IACpB,sGAAsG;IACtG,iEAAiE;IACjE,IAAI,CAAS;IACb,kGAAkG;IAClG,8EAA8E;IAC9E,GAAG,CAAS;IAEZ,YAAY,WAAmB,EAAE,IAAY,EAAE,GAAW;QACtD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC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AkB,CAAC,SAAS,CAAC;6CAIA,6BAAc;QAChB,mCAAY;QAChB,gDAAyB;QACzB,4CAAwB;QACtB,6CAAwB;QACjB,gCAAiB;GARhD,kBAAkB,CAmK9B;AAED;;;GAGG;AAEI,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IACzB,IAAI,CAAC,QAAgB,EAAE,KAAqB;QACxC,IAAI,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YACzB,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC;gBAAE,MAAM,IAAI,8BAAa,CAAC,GAAG,qCAAgB,YAAY,QAAQ,kBAAkB,CAAC,CAAC;YACjH,OAAO,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC;IACxB,CAAC;CACJ,CAAA;AARY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,gBAAgB,CAQ5B","sourcesContent":["import * as fs from 'fs';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { RepoRootFinder, ReviewJsonService, VERDICT_ORANGE, VERDICT_RED, VERDICT_STATUSES, checklistOverrideService, summaryJsonPath } from '@webpieces/rules-config';\nimport { WRITE_REVIEW_BIN } from '@webpieces/repo-workflow-core';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { ReviewStageReceipt, ReviewStageReceiptService } from '../workflow/review-stage-receipt';\nimport { ReviewerIdentity, ReviewerIdentityResolver } from '../workflow/reviewer-identity';\nimport { SubmittedVerdict, VerdictProvenance, VerdictProvenanceService } from '../workflow/verdict-provenance';\nimport type { PrGateCliStdin } from '../pr-gate-cli-invocation';\n\n/** The only keys a verdict may carry. Anything else is somebody's second schema. */\nconst VERDICT_KEYS = ['id', 'status', 'agent', 'model', 'output'] as const;\n\n/** What `wp-write-review` was asked to do. Data-only. */\nexport class WriteReviewOptions {\n checklistId: string;\n // The verdict JSON itself — read from `--file` or stdin by the composition root, so this command is a\n // function of its inputs and a spec can drive it without a pipe.\n json: string;\n // Where the caller stands — the tree whose review dir and hook stamp are used. Passed in (the bin\n // passes process.cwd()) rather than read here, for the same reason `json` is.\n cwd: string;\n\n constructor(checklistId: string, json: string, cwd: string) {\n this.checklistId = checklistId;\n this.json = json;\n this.cwd = cwd;\n }\n}\n\n/** What `wp-write-review --check` was asked: may this checklist still be reviewed? Data-only. */\nexport class ReviewBudgetCheckOptions {\n checklistId: string;\n cwd: string;\n\n constructor(checklistId: string, cwd: string) {\n this.checklistId = checklistId;\n this.cwd = cwd;\n }\n}\n\n/**\n * `wp-write-review` — the ONE way any reviewer, Claude or Codex, submits a checklist verdict (issue #863).\n *\n * Before it existed a verdict was \"a file with the right shape at the right path\", and that is exactly what\n * a Codex coordinator produced on two merged PRs: the shared-tree guard blocked its reviewer's write, the\n * guard's own cure said to hand the edit to the coordinator, the coordinator wrote all five verdicts, and\n * `wp-finish-upsert-pr` accepted them. Now:\n * 1. the caller is identified by the harness (ReviewerIdentityResolver) and the COORDINATOR is refused;\n * 2. the checklist must be one stage ② briefed this round (its receipt), so a carried verdict cannot be\n * overwritten and a checklist that does not apply cannot be invented;\n * 3. the verdict is validated strictly — the five fields, nothing else;\n * 4. it is written as `review-round<N>-<id>.json` WITH `review-round<N>-<id>.provenance.json`: who, which\n * commit, which in-scope diff, and a hash of the verdict. `wp-finish-upsert-pr` rejects a verdict\n * without one, or one edited since;\n * 5. the round must be inside the budget (issues #1051, #1053): a round above `maxReviewerRounds` records\n * nothing, and a round's verdict is never overwritten, whoever spawned the reviewer. `--check` asks the\n * same question BEFORE a reviewer spends a review on it;\n * 6. the color must fit the round (issue #1053): the FINAL round has no red — its must-fix color is\n * orange, never re-reviewed — and orange is refused before the final round, where red still means\n * \"fix it and it will be reviewed again\".\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class WriteReviewCommand {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly receipts: ReviewStageReceiptService,\n private readonly identity: ReviewerIdentityResolver,\n private readonly provenance: VerdictProvenanceService,\n private readonly reviewJsonService: ReviewJsonService,\n ) {}\n\n async run(opts: WriteReviewOptions): Promise<void> {\n const id = opts.checklistId.trim();\n const cwd = opts.cwd;\n const repoRoot = this.repoRootFinder.resolveRepoRoot(cwd);\n const featureName = await this.aiBranchName.getFeatureName();\n const receipt = this.briefedReceipt(repoRoot, featureName, id);\n // Identity BEFORE parsing: a coordinator is refused whatever it submitted, and the stamp it\n // consumes must not survive to lend itself to a later call.\n const who: ReviewerIdentity = this.identity.resolve(cwd, id);\n this.assertWithinBudget(summaryJsonPath(repoRoot, featureName), receipt, id);\n const verdict = this.parse(opts.json, id, receipt);\n const record = new VerdictProvenance(\n id, who.harness, who.sessionId, who.agentId, who.agentType, receipt.headSha, receipt.scopeHashes[id] ?? '');\n record.round = receipt.round;\n const written = this.provenance.write(summaryJsonPath(repoRoot, featureName), verdict, record);\n process.stdout.write(\n `✅ ${verdict.status.toUpperCase()} verdict for \"${id}\" submitted → ${written}\\n`\n + ` provenance: ${who.harness}${who.agentId === '' ? '' : ` agent ${who.agentId}`}, `\n + `briefed at ${receipt.headSha.slice(0, 8)}, global round ${receipt.round} of ${receipt.maxReviewerRounds}\\n`);\n }\n\n /**\n * `wp-write-review --check`: the reviewer's FIRST step. Refuses exactly when {@link run} would refuse\n * on the budget, so a reviewer past the budget learns it before it reviews rather than after.\n */\n async check(opts: ReviewBudgetCheckOptions): Promise<void> {\n const id = opts.checklistId.trim();\n const repoRoot = this.repoRootFinder.resolveRepoRoot(opts.cwd);\n const featureName = await this.aiBranchName.getFeatureName();\n const receipt = this.briefedReceipt(repoRoot, featureName, id);\n this.assertWithinBudget(summaryJsonPath(repoRoot, featureName), receipt, id);\n const final = this.isFinalRound(receipt)\n ? ` This is the FINAL round: there is no re-review, so you may NOT mark ${VERDICT_RED} — mark every must-fix finding ${VERDICT_ORANGE}.`\n : '';\n process.stdout.write(\n `✅ \"${id}\" may be reviewed: this is review round ${receipt.round} of at most ${receipt.maxReviewerRounds}.${final} `\n + `Review it, then submit with pnpm ${WRITE_REVIEW_BIN} --checklist ${id}.\\n`);\n }\n\n /** The last round `maxReviewerRounds` allows — the one with no red (issue #1053). */\n private isFinalRound(receipt: ReviewStageReceipt): boolean {\n return receipt.round >= receipt.maxReviewerRounds;\n }\n\n /**\n * THE ROUND CAP, held by the reviewer's own submission path (issues #1051, #1053). The planner already\n * never briefs past the cap, but an author agent could still spawn a reviewer from an old instructions\n * file — the measured deadlock did exactly that. Two refusals make it mechanical: a round above\n * `maxReviewerRounds` records nothing, and a checklist that already has a verdict in this round (or a\n * later one) gets no second one — a round's verdict is never overwritten.\n */\n private assertWithinBudget(summaryPath: string, receipt: ReviewStageReceipt, id: string): void {\n const max = receipt.maxReviewerRounds;\n const latest = this.reviewJsonService.latestVerdictRound(summaryPath, id);\n if (receipt.round <= max && latest < receipt.round) return;\n const why = receipt.round > max\n ? `this briefing is for review round ${receipt.round}, above maxReviewerRounds (${max})`\n : `it already has a verdict for review round ${latest} (maxReviewerRounds is ${max}), and a round's verdict is never overwritten`;\n throw new InformAiError(\n `I am not allowed to review ${id}: ${why}.\\n`\n + `Do not review it and submit nothing for it; report this refusal, verbatim, to the agent that spawned you. `\n + `The verdict already recorded for it stands (${this.reviewJsonService.latestChecklistResultPath(summaryPath, id) || 'none'}), and `\n + 'the author records any fix with pnpm wp-write-review-fixes.');\n }\n\n /** The stage-② receipt, provided it briefed THIS checklist this round. */\n private briefedReceipt(repoRoot: string, featureName: string, id: string): ReviewStageReceipt {\n if (id === '') throw new InformAiError(`${WRITE_REVIEW_BIN} needs the checklist id: pnpm ${WRITE_REVIEW_BIN} --checklist <id>`);\n const receipt = this.receipts.read(repoRoot, featureName);\n if (receipt === null) {\n throw new InformAiError(`${WRITE_REVIEW_BIN}: pnpm wp-review-upsert-pr has not briefed any reviewer on this branch yet, `\n + 'so there is nothing to submit a verdict against.');\n }\n if (!receipt.reviewersBriefed.includes(id) || (receipt.scopeHashes[id] ?? '') === '') {\n const briefed = receipt.reviewersBriefed.length === 0 ? '(none)' : receipt.reviewersBriefed.join(', ');\n throw new InformAiError(`${WRITE_REVIEW_BIN}: checklist \"${id}\" was not briefed by the last pnpm wp-review-upsert-pr `\n + `(briefed this round: ${briefed}). Submit only for a checklist whose instructions file you were handed — `\n + 'a checklist absent here either carries its earlier verdict or does not apply to this diff.');\n }\n return receipt;\n }\n\n /**\n * Strict: an object with exactly the verdict's five fields, every one a string, and a status that fits\n * the round — red only BEFORE the final round, orange only ON it (issue #1053).\n */\n private parse(json: string, id: string, receipt: ReviewStageReceipt): SubmittedVerdict {\n const raw = this.parseObject(json);\n const problems: string[] = [];\n const extra = Object.keys(raw).filter((k: string): boolean => !(VERDICT_KEYS as readonly string[]).includes(k));\n if (extra.includes('override')) {\n problems.push(`\"override\" is not a verdict field — a ship-anyway decision is a HUMAN's, recorded by the coordinating agent in ${checklistOverrideService.overrideFileName(id)}`);\n }\n if (extra.length > 0) problems.push(`unknown field(s) ${extra.map((k: string): string => `\"${k}\"`).join(', ')} — a verdict has exactly: ${VERDICT_KEYS.join(', ')}`);\n if (raw['id'] !== undefined && this.text(raw, 'id') !== id) problems.push(`\"id\" is ${JSON.stringify(raw['id'])} but --checklist is \"${id}\"`);\n const status = this.text(raw, 'status').toLowerCase();\n // webpieces-disable no-any-unknown -- comparing against the readonly literal tuple of valid colors\n if (!(VERDICT_STATUSES as readonly string[]).includes(status)) problems.push(`\"status\" must be one of ${VERDICT_STATUSES.join(', ')}`);\n problems.push(...this.colorForRound(status, receipt));\n for (const key of ['agent', 'model', 'output']) {\n if (this.text(raw, key) === '') problems.push(`\"${key}\" must be a non-empty string${key === 'output' ? '' : ' (use \"unknown\" when unavailable)'}`);\n }\n if (problems.length > 0) {\n throw new InformAiError(`${WRITE_REVIEW_BIN}: the verdict for \"${id}\" was NOT submitted:\\n`\n + problems.map((p: string): string => ` • ${p}`).join('\\n'));\n }\n return new SubmittedVerdict(id, status, this.text(raw, 'agent'), this.text(raw, 'model'), raw['output'] as string);\n }\n\n /**\n * The round decides which blocking color exists. The FINAL round's red would mean \"fix it and it will be\n * reviewed again\", and there is no again — so it is refused and orange named. Orange before the final\n * round would waive a re-review that the budget still pays for — so it is refused and red named.\n */\n private colorForRound(status: string, receipt: ReviewStageReceipt): string[] {\n const round = `review round ${receipt.round} of ${receipt.maxReviewerRounds}`;\n if (status === VERDICT_RED && this.isFinalRound(receipt)) {\n return [`\"status\": \"${VERDICT_RED}\" is not allowed: ${round} is the FINAL round, and there is no re-review. `\n + `Mark anything that must be fixed \"${VERDICT_ORANGE}\", with a concrete, actionable fix in \"output\" — the author applies it `\n + 'best effort and ships without another review.'];\n }\n if (status === VERDICT_ORANGE && !this.isFinalRound(receipt)) {\n return [`\"status\": \"${VERDICT_ORANGE}\" is only for the FINAL review round, and ${round} is not it. `\n + `Use \"${VERDICT_RED}\" for a must-fix finding: the author's fix will be reviewed again next round.`];\n }\n return [];\n }\n\n // webpieces-disable no-any-unknown -- one field of the opaque submitted object, narrowed to a trimmed string\n private text(raw: Record<string, unknown>, key: string): string {\n const value = raw[key];\n return typeof value === 'string' ? value.trim() : '';\n }\n\n // webpieces-disable no-any-unknown -- the submitted JSON is opaque until parse() narrows every field\n private parseObject(json: string): Record<string, unknown> {\n // webpieces-disable no-any-unknown -- parsed JSON is opaque until narrowed\n let parsed: unknown = null;\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: a JSON syntax error becomes the AI-facing refusal\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n parsed = JSON.parse(json);\n } catch (err: unknown) {\n const error = toError(err);\n throw new InformAiError(`${WRITE_REVIEW_BIN}: the verdict is not valid JSON.`, { cause: error });\n }\n if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {\n throw new InformAiError(`${WRITE_REVIEW_BIN}: the verdict must be ONE JSON object.`);\n }\n // webpieces-disable no-any-unknown -- narrowed to a plain object just above\n return parsed as Record<string, unknown>;\n }\n}\n\n/**\n * Reads the verdict JSON for the composition root: `--file <path>`, else stdin. Separate from the command\n * so the command stays a function of its inputs.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class WriteReviewInput {\n read(filePath: string, stdin: PrGateCliStdin): string {\n if (filePath.trim() !== '') {\n if (!fs.existsSync(filePath)) throw new InformAiError(`${WRITE_REVIEW_BIN}: --file ${filePath} does not exist.`);\n return fs.readFileSync(filePath, 'utf8');\n }\n return stdin.read();\n }\n}\n"]}
|
|
@@ -34,15 +34,14 @@ let WriteReviewFixesCommand = class WriteReviewFixesCommand {
|
|
|
34
34
|
this.receipts = receipts;
|
|
35
35
|
this.rounds = rounds;
|
|
36
36
|
}
|
|
37
|
-
run(opts) {
|
|
37
|
+
async run(opts) {
|
|
38
38
|
const repoRoot = this.repoRootFinder.resolveRepoRoot(opts.cwd);
|
|
39
|
-
const featureName = this.aiBranchName.getFeatureName();
|
|
39
|
+
const featureName = await this.aiBranchName.getFeatureName();
|
|
40
40
|
const receipt = this.receipts.read(repoRoot, featureName);
|
|
41
41
|
if (receipt === null)
|
|
42
42
|
throw new tooling_common_1.InformAiError('wp-write-review-fixes: no reviewer round has started on this branch.');
|
|
43
|
-
const written = this.rounds.writeRemediation(repoRoot, (0, rules_config_1.summaryJsonPath)(repoRoot, featureName), receipt, opts.json);
|
|
43
|
+
const written = await this.rounds.writeRemediation(repoRoot, (0, rules_config_1.summaryJsonPath)(repoRoot, featureName), receipt, opts.json);
|
|
44
44
|
process.stdout.write(`✅ SHA-bound fixes recorded → ${written}\n`);
|
|
45
|
-
return Promise.resolve();
|
|
46
45
|
}
|
|
47
46
|
};
|
|
48
47
|
exports.WriteReviewFixesCommand = WriteReviewFixesCommand;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-review-fixes-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/write-review-fixes-command.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,0DAA0E;AAC1E,8DAA0D;AAC1D,yCAA2D;AAC3D,2EAAgE;AAChE,uEAAyE;AACzE,2EAA6E;AAG7E,MAAa,uBAAuB;IAChC,IAAI,CAAS;IACb,GAAG,CAAS;IAEZ,YAAY,IAAY,EAAE,GAAW;QACjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,CAAC;CACJ;AARD,0DAQC;AAED;;;;GAIG;AAEI,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAEX;IACA;IACA;IACA;IAJrB,YACqB,cAA8B,EAC9B,YAA0B,EAC1B,QAAmC,EACnC,MAA+B;QAH/B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,aAAQ,GAAR,QAAQ,CAA2B;QACnC,WAAM,GAAN,MAAM,CAAyB;IACjD,CAAC;IAEJ,GAAG,CAAC,IAA6B;
|
|
1
|
+
{"version":3,"file":"write-review-fixes-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/write-review-fixes-command.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,0DAA0E;AAC1E,8DAA0D;AAC1D,yCAA2D;AAC3D,2EAAgE;AAChE,uEAAyE;AACzE,2EAA6E;AAG7E,MAAa,uBAAuB;IAChC,IAAI,CAAS;IACb,GAAG,CAAS;IAEZ,YAAY,IAAY,EAAE,GAAW;QACjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,CAAC;CACJ;AARD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KAAK,EAAE,EAAE,CAAC;YACzB,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC;gBAAE,MAAM,IAAI,8BAAa,CAAC,iCAAiC,QAAQ,kBAAkB,CAAC,CAAC;YACnH,OAAO,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC;IACxB,CAAC;CACJ,CAAA;AARY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,qBAAqB,CAQjC","sourcesContent":["import * as fs from 'fs';\nimport { RepoRootFinder, summaryJsonPath } from '@webpieces/rules-config';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { ReviewRoundStateService } from '../workflow/review-round-state';\nimport { ReviewStageReceiptService } from '../workflow/review-stage-receipt';\nimport type { PrGateCliStdin } from '../pr-gate-cli-invocation';\n\nexport class WriteReviewFixesOptions {\n json: string;\n cwd: string;\n\n constructor(json: string, cwd: string) {\n this.json = json;\n this.cwd = cwd;\n }\n}\n\n/**\n * Coordinator-owned writer for the SHA-bound response to a completed reviewer round: one fix per RED (a round\n * that is not the last, re-reviewed next round) or per ORANGE (the final round, never re-reviewed — finish\n * stamps each on the dashboard with its resolution). Written as `review-round<N>-fixes.json`, once.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class WriteReviewFixesCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly receipts: ReviewStageReceiptService,\n private readonly rounds: ReviewRoundStateService,\n ) {}\n\n async run(opts: WriteReviewFixesOptions): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(opts.cwd);\n const featureName = await this.aiBranchName.getFeatureName();\n const receipt = this.receipts.read(repoRoot, featureName);\n if (receipt === null) throw new InformAiError('wp-write-review-fixes: no reviewer round has started on this branch.');\n const written = await this.rounds.writeRemediation(repoRoot, summaryJsonPath(repoRoot, featureName), receipt, opts.json);\n process.stdout.write(`✅ SHA-bound fixes recorded → ${written}\\n`);\n }\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class WriteReviewFixesInput {\n read(filePath: string, stdin: PrGateCliStdin): string {\n if (filePath.trim() !== '') {\n if (!fs.existsSync(filePath)) throw new InformAiError(`wp-write-review-fixes: --file ${filePath} does not exist.`);\n return fs.readFileSync(filePath, 'utf8');\n }\n return stdin.read();\n }\n}\n"]}
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
require("reflect-metadata");
|
|
5
5
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
6
|
-
const
|
|
6
|
+
const pr_gate_container_1 = require("./pr-gate-container");
|
|
7
7
|
const pr_gate_cli_app_1 = require("./pr-gate-cli-app");
|
|
8
8
|
const pr_gate_cli_invocation_1 = require("./pr-gate-cli-invocation");
|
|
9
|
-
const container = new
|
|
9
|
+
const container = new pr_gate_container_1.PrGateContainer().create();
|
|
10
10
|
(0, rules_config_1.runMain)(() => container
|
|
11
11
|
.get(pr_gate_cli_app_1.PrGateCliApp)
|
|
12
12
|
.run(container.get(pr_gate_cli_invocation_1.PrGateCliInvocationFactory).fromProcess('wp-finish-upsert-pr')));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git-finishUpsertPr.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/git-finishUpsertPr.ts"],"names":[],"mappings":";;;AACA,4BAA0B;AAC1B,0DAAkD;AAClD,
|
|
1
|
+
{"version":3,"file":"git-finishUpsertPr.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/git-finishUpsertPr.ts"],"names":[],"mappings":";;;AACA,4BAA0B;AAC1B,0DAAkD;AAClD,2DAAsD;AACtD,uDAAiD;AACjD,qEAAsE;AAEtE,MAAM,SAAS,GAAG,IAAI,mCAAe,EAAE,CAAC,MAAM,EAAE,CAAC;AACjD,IAAA,sBAAO,EACH,GAAkB,EAAE,CAChB,SAAS;KACJ,GAAG,CAAC,8BAAY,CAAC;KACjB,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,mDAA0B,CAAC,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC,CAC7F,CAAC","sourcesContent":["#!/usr/bin/env node\nimport 'reflect-metadata';\nimport { runMain } from '@webpieces/rules-config';\nimport { PrGateContainer } from './pr-gate-container';\nimport { PrGateCliApp } from './pr-gate-cli-app';\nimport { PrGateCliInvocationFactory } from './pr-gate-cli-invocation';\n\nconst container = new PrGateContainer().create();\nrunMain(\n (): Promise<void> =>\n container\n .get(PrGateCliApp)\n .run(container.get(PrGateCliInvocationFactory).fromProcess('wp-finish-upsert-pr')),\n);\n"]}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GatherInfo = exports.GatherInfoResult = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const child_process_1 = require("child_process");
|
|
6
5
|
const fs = tslib_1.__importStar(require("fs"));
|
|
7
6
|
const path = tslib_1.__importStar(require("path"));
|
|
8
7
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
@@ -41,19 +40,19 @@ let GatherInfo = class GatherInfo {
|
|
|
41
40
|
// Gather the 3-point merge context for the current feature branch and RETURN whether the branch is
|
|
42
41
|
// already even with main. NEVER calls process.exit: it is called as a library (from merge-start).
|
|
43
42
|
async gatherInfo() {
|
|
44
|
-
const currentBranch =
|
|
45
|
-
const featureName = this.aiBranchName.getFeatureName();
|
|
43
|
+
const currentBranch = await this.gitExec.currentBranch(process.cwd());
|
|
44
|
+
const featureName = await this.aiBranchName.getFeatureName();
|
|
46
45
|
const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());
|
|
47
46
|
const mergeDir = this.mergeState.mergeDirFor(repoRoot, featureName);
|
|
48
47
|
fs.mkdirSync(mergeDir, { recursive: true });
|
|
49
|
-
this.validateCleanTree(currentBranch, repoRoot);
|
|
48
|
+
await this.validateCleanTree(currentBranch, repoRoot);
|
|
50
49
|
process.stderr.write('\n');
|
|
51
50
|
process.stderr.write(SEP);
|
|
52
51
|
process.stderr.write('📍 Gathering Merge Context\n');
|
|
53
52
|
process.stderr.write(SEP);
|
|
54
53
|
process.stderr.write('\n');
|
|
55
54
|
process.stderr.write('Fetching latest changes from origin/main...\n');
|
|
56
|
-
|
|
55
|
+
await this.gitExec.passThrough(['fetch', 'origin', 'main']);
|
|
57
56
|
await this.forkPoint.findForkPoint('merge');
|
|
58
57
|
const hashesFile = path.join(mergeDir, 'updatemain-hashes.json');
|
|
59
58
|
const hashes = JSON.parse(fs.readFileSync(hashesFile, 'utf8'));
|
|
@@ -75,14 +74,14 @@ let GatherInfo = class GatherInfo {
|
|
|
75
74
|
process.stderr.write('\n');
|
|
76
75
|
return new GatherInfoResult(false, hashes);
|
|
77
76
|
}
|
|
78
|
-
validateCleanTree(currentBranch, repoRoot) {
|
|
77
|
+
async validateCleanTree(currentBranch, repoRoot) {
|
|
79
78
|
if (currentBranch === 'main') {
|
|
80
79
|
throw new rules_config_1.CliExitError(1, '❌ Error: Already on main branch. No need to update from main.');
|
|
81
80
|
}
|
|
82
81
|
process.stderr.write(`Current branch: ${currentBranch}\n`);
|
|
83
82
|
// Require a fully-committed tree (tracked AND untracked). assertCleanTree uses
|
|
84
83
|
// `git status --porcelain` (untracked-aware, gitignore-respecting) and aborts with instructions.
|
|
85
|
-
this.gitExec.assertCleanTree(repoRoot);
|
|
84
|
+
await this.gitExec.assertCleanTree(repoRoot);
|
|
86
85
|
}
|
|
87
86
|
printHashPoints(hashes, currentBranch, mergeDir) {
|
|
88
87
|
process.stderr.write('📍 The 3 Hash Points:\n');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git-gatherInfo.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/git-gatherInfo.ts"],"names":[],"mappings":";;;;AAAA
|
|
1
|
+
{"version":3,"file":"git-gatherInfo.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/git-gatherInfo.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAC7B,0DAAuE;AACvE,yCAA2D;AAC3D,0EAA+D;AAC/D,oEAAyD;AACzD,wDAAoD;AACpD,kDAA8C;AAE9C,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAQvE,sGAAsG;AACtG,sGAAsG;AACtG,iGAAiG;AACjG,MAAa,gBAAgB;IACzB,eAAe,CAAU;IACzB,MAAM,CAAa;IAEnB,YAAY,eAAwB,EAAE,MAAkB;QACpD,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CACJ;AARD,4CAQC;AAED,qGAAqG;AAE9F,IAAM,UAAU,GAAhB,MAAM,UAAU;IAEE;IACA;IACA;IACA;IACA;IALrB,YACqB,cAA8B,EAC9B,YAA0B,EAC1B,SAAoB,EACpB,UAAsB,EACtB,OAAgB;QAJhB,mBAAc,GAAd,cAAc,CAAgB;QAC9B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,cAAS,GAAT,SAAS,CAAW;QACpB,eAAU,GAAV,UAAU,CAAY;QACtB,YAAO,GAAP,OAAO,CAAS;IAClC,CAAC;IAEJ,mGAAmG;IACnG,kGAAkG;IAClG,KAAK,CAAC,UAAU;QACZ,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QACtE,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,CAAC;QAC7D,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,e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AE,QAAgB;QAC/E,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAChD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,0BAA0B,MAAM,CAAC,aAAa,IAAI,CAAC,CAAC;QACzE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,aAAa,wBAAwB,CAAC,CAAC;QAC3E,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,0BAA0B,MAAM,CAAC,eAAe,IAAI,CAAC,CAAC;QAC3E,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,aAAa,KAAK,CAAC,CAAC;QACzD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,0BAA0B,MAAM,CAAC,YAAY,IAAI,CAAC,CAAC;QACxE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;QACrD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,QAAQ,IAAI,CAAC,CAAC;QACvD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;CACJ,CAAA;AA9EY,gCAAU;qBAAV,UAAU;IADtB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QAChB,mCAAY;QACf,6BAAS;QACR,wBAAU;QACb,kBAAO;GAN5B,UAAU,CA8EtB","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { CliExitError, RepoRootFinder } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from './workflow/git-readAiBranchName';\nimport { ForkPoint } from './workflow/git-findForkPoint';\nimport { MergeState } from './workflow/merge-state';\nimport { GitExec } from './workflow/git-exec';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\ninterface HashPoints {\n hashForkPoint: string;\n hashFeatureHead: string;\n hashMainHead: string;\n}\n\n// Result of gathering merge context: whether the branch is already even with main (fork point == main\n// HEAD, so there is nothing to merge) plus the 3 hash points. A class (not an object literal) per the\n// codebase's data-structure convention. gatherInfo RETURNS this instead of calling process.exit.\nexport class GatherInfoResult {\n alreadyUpToDate: boolean;\n hashes: HashPoints;\n\n constructor(alreadyUpToDate: boolean, hashes: HashPoints) {\n this.alreadyUpToDate = alreadyUpToDate;\n this.hashes = hashes;\n }\n}\n\n/** Gathers the 3-point merge context (fetch main, find fork point, write hashes) for merge-start. */\n@injectable(bindingScopeValues.Singleton)\nexport class GatherInfo {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly forkPoint: ForkPoint,\n private readonly mergeState: MergeState,\n private readonly gitExec: GitExec,\n ) {}\n\n // Gather the 3-point merge context for the current feature branch and RETURN whether the branch is\n // already even with main. NEVER calls process.exit: it is called as a library (from merge-start).\n async gatherInfo(): Promise<GatherInfoResult> {\n const currentBranch = await this.gitExec.currentBranch(process.cwd());\n const featureName = await this.aiBranchName.getFeatureName();\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n const mergeDir = this.mergeState.mergeDirFor(repoRoot, featureName);\n fs.mkdirSync(mergeDir, { recursive: true });\n\n await this.validateCleanTree(currentBranch, repoRoot);\n\n process.stderr.write('\\n');\n process.stderr.write(SEP);\n process.stderr.write('📍 Gathering Merge Context\\n');\n process.stderr.write(SEP);\n process.stderr.write('\\n');\n process.stderr.write('Fetching latest changes from origin/main...\\n');\n await this.gitExec.passThrough(['fetch', 'origin', 'main']);\n\n await this.forkPoint.findForkPoint('merge');\n\n const hashesFile = path.join(mergeDir, 'updatemain-hashes.json');\n const hashes = JSON.parse(fs.readFileSync(hashesFile, 'utf8')) as HashPoints;\n\n this.printHashPoints(hashes, currentBranch, mergeDir);\n\n if (hashes.hashForkPoint === hashes.hashMainHead) {\n process.stderr.write(SEP);\n process.stderr.write('✅ Already up to date with main!\\n');\n process.stderr.write(SEP);\n process.stderr.write('\\n');\n process.stderr.write('Your branch has not diverged from main.\\n');\n process.stderr.write('There are no new changes from main to merge.\\n');\n process.stderr.write('\\n');\n process.stderr.write(SEP);\n return new GatherInfoResult(true, hashes);\n }\n\n process.stderr.write('Main has advanced. Merge will be needed.\\n');\n process.stderr.write('\\n');\n process.stderr.write(SEP);\n process.stderr.write('\\n');\n return new GatherInfoResult(false, hashes);\n }\n\n private async validateCleanTree(currentBranch: string, repoRoot: string): Promise<void> {\n if (currentBranch === 'main') {\n throw new CliExitError(1, '❌ Error: Already on main branch. No need to update from main.');\n }\n process.stderr.write(`Current branch: ${currentBranch}\\n`);\n // Require a fully-committed tree (tracked AND untracked). assertCleanTree uses\n // `git status --porcelain` (untracked-aware, gitignore-respecting) and aborts with instructions.\n await this.gitExec.assertCleanTree(repoRoot);\n }\n\n private printHashPoints(hashes: HashPoints, currentBranch: string, mergeDir: string): void {\n process.stderr.write('📍 The 3 Hash Points:\\n');\n process.stderr.write(` 1. Fork point (A): ${hashes.hashForkPoint}\\n`);\n process.stderr.write(` (where ${currentBranch} diverged from main)\\n`);\n process.stderr.write('\\n');\n process.stderr.write(` 2. Feature HEAD (B): ${hashes.hashFeatureHead}\\n`);\n process.stderr.write(` (tip of ${currentBranch})\\n`);\n process.stderr.write('\\n');\n process.stderr.write(` 3. Main HEAD (C): ${hashes.hashMainHead}\\n`);\n process.stderr.write(' (current origin/main)\\n');\n process.stderr.write('\\n');\n process.stderr.write(`Merge directory: ${mergeDir}\\n`);\n process.stderr.write('\\n');\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Container } from 'inversify';
|
|
2
|
+
/**
|
|
3
|
+
* THE container every `wp-*` bin resolves its program from — and the one a feature test builds too,
|
|
4
|
+
* before rebinding the process edges to mocks. One factory, so a test cannot assemble a DAG the shipped
|
|
5
|
+
* bin does not.
|
|
6
|
+
*/
|
|
7
|
+
export declare class PrGateContainer {
|
|
8
|
+
create(): Container;
|
|
9
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PrGateContainer = void 0;
|
|
4
|
+
const inversify_1 = require("inversify");
|
|
5
|
+
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
6
|
+
/**
|
|
7
|
+
* THE container every `wp-*` bin resolves its program from — and the one a feature test builds too,
|
|
8
|
+
* before rebinding the process edges to mocks. One factory, so a test cannot assemble a DAG the shipped
|
|
9
|
+
* bin does not.
|
|
10
|
+
*/
|
|
11
|
+
class PrGateContainer {
|
|
12
|
+
create() {
|
|
13
|
+
const container = new inversify_1.Container({ autobind: true });
|
|
14
|
+
new tooling_common_1.ProcessBindings().bind(container);
|
|
15
|
+
return container;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.PrGateContainer = PrGateContainer;
|
|
19
|
+
//# sourceMappingURL=pr-gate-container.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pr-gate-container.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/pr-gate-container.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AACtC,8DAA4D;AAE5D;;;;GAIG;AACH,MAAa,eAAe;IACxB,MAAM;QACF,MAAM,SAAS,GAAG,IAAI,qBAAS,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;QACpD,IAAI,gCAAe,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACtC,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ;AAND,0CAMC","sourcesContent":["import { Container } from 'inversify';\nimport { ProcessBindings } from '@webpieces/tooling-common';\n\n/**\n * THE container every `wp-*` bin resolves its program from — and the one a feature test builds too,\n * before rebinding the process edges to mocks. One factory, so a test cannot assemble a DAG the shipped\n * bin does not.\n */\nexport class PrGateContainer {\n create(): Container {\n const container = new Container({ autobind: true });\n new ProcessBindings().bind(container);\n return container;\n }\n}\n"]}
|
|
@@ -57,7 +57,7 @@ export interface WaitProbe {
|
|
|
57
57
|
/** How long to sleep between two `done()` calls. A file read polls fast; a `gh` call does not. */
|
|
58
58
|
readonly pollMs: number;
|
|
59
59
|
/** True once the wait is over. Called before the first sleep, so an already-finished wait is free. */
|
|
60
|
-
done(): boolean
|
|
60
|
+
done(): Promise<boolean>;
|
|
61
61
|
/** The current state, in one short phrase, for the heartbeat: `2 of 4 verdicts in`. */
|
|
62
62
|
describe(): string;
|
|
63
63
|
}
|
|
@@ -58,7 +58,7 @@ let AwaitLoop = class AwaitLoop {
|
|
|
58
58
|
// describing the wait before asking it would report a state nobody has measured — and an
|
|
59
59
|
// already-finished wait must cost nothing at all.
|
|
60
60
|
for (let first = true;; first = false) {
|
|
61
|
-
if (probe.done())
|
|
61
|
+
if (await probe.done())
|
|
62
62
|
return new WaitOutcome(true, Date.now() - started);
|
|
63
63
|
const elapsed = Date.now() - started;
|
|
64
64
|
if (elapsed >= exports.CEILING_MS)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"await-loop.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/await-loop.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAE3D,yDAAoD;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEI,IAAM,SAAS,GAAf,MAAM,SAAS;IACW;IAA7B,YAA6B,YAA4B;QAA5B,iBAAY,GAAZ,YAAY,CAAgB;IAAG,CAAC;IAE7D;;;OAGG;IACH,KAAK,CAAC,GAAG,CAAC,KAAgB;QACtB,MAAM,OAAO,GAAG,IA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KING WAIT, and why webpieces owns one (issue #874, scoped by #878).\n *\n * ─── IT IS ONE EFFICIENT WAIT, OFFERED — NEVER A TURN-LEVEL INSTRUCTION (issue #902) ───────────────\n * #874 justified this class by asserting a worktree-isolated subagent cannot end its turn, #878\n * corrected that, and #900 measured that the background re-invocation the correction relied on does not\n * reliably fire. #902 settles the shape of the advice: webpieces names the efficient wait and blocks the\n * wasteful poll, and says NOTHING about when an agent should end its turn. An agent already waits on the\n * subagents it spawns, routinely, without being told; a fixed rule in a string cannot see the situation\n * it is ruling on.\n *\n * What this class is for is the case where an agent has decided to block. There, a Bash call is\n * the only pause it can express: `Monitor` does not block (its own result says \"Keep working — do not\n * poll or sleep\"), and a `Monitor` carrying a real polling loop is refused by the HARNESS, because a\n * `while`/`until` with a redirect cannot be statically proven to stay inside the worktree (178 of 553\n * measured subagent Monitor calls). That refusal is Claude Code's and is not ours to relax.\n *\n * Without either, the agent falls back to `echo .` every three seconds — measured at 920M tokens, 18.3%\n * of every token the fleet spent in the 24h to 2026-09-07, because every turn resends the whole\n * conversation at ~557,000 tokens. This class is the thing that makes that unnecessary, and\n * `wait-spin-guard` is the thing that makes it unused.\n *\n * ─── THREE CONSTRAINTS, all of them the harness's, none of them negotiable ─────────────────────────\n *\n * 1. **What the AGENT TYPES must be a plain command.** No loop, no redirect, no pipe, no command\n * substitution — those are exactly what the isolation check refuses. All the looping is in here,\n * inside one process, behind a bare `pnpm wp-await-reviews`.\n * 2. **It must print something roughly every {@link HEARTBEAT_MS}.** The harness backgrounds and then\n * KILLS a foreground command that has produced no output for 600 seconds, and a killed wait throws\n * away the wait. Same defence `wp-build` already runs, same `still` word for the same reason: a\n * tick that has not moved must be distinguishable from a stalled reporter.\n * 3. **It must RETURN before that ceiling on its own**, saying to run it again. A wait that dies at\n * the watchdog looks like a crash; a wait that returns at {@link CEILING_MS} with \"still waiting\"\n * turns a 100-minute wait into ~11 tool calls instead of the ~2,000 an `echo .` loop costs.\n *\n * `done` is a normal, ZERO exit either way. \"Still waiting\" is not a failure — it is an answer the agent\n * acts on — and making it non-zero would put a red exit code on the healthy path.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class AwaitLoop {\n constructor(private readonly stageConsole: StageOutputLog) {}\n\n /**\n * Block until `probe` says it is done, or until {@link CEILING_MS} elapses, printing a heartbeat\n * throughout. Returns WHICH of those happened; the caller renders the outcome.\n */\n async run(probe: WaitProbe): Promise<WaitOutcome> {\n const started = Date.now();\n const heartbeat = new WaitHeartbeat(probe.label);\n // `done()` FIRST, before anything is printed. It is what establishes the probe's state, so\n // describing the wait before asking it would report a state nobody has measured — and an\n // already-finished wait must cost nothing at all.\n for (let first = true; ; first = false) {\n if (probe.done()) return new WaitOutcome(true, Date.now() - started);\n const elapsed = Date.now() - started;\n if (elapsed >= CEILING_MS) return new WaitOutcome(false, elapsed);\n // One heartbeat per HEARTBEAT_MS of ELAPSED time, whatever the poll interval — a probe that\n // costs a network round trip is polled far more slowly than one reading a file, and the\n // watchdog counts seconds of silence, not polls.\n if (first || heartbeat.isDue(elapsed)) {\n this.stageConsole.say(`${heartbeat.tick(probe.describe(), elapsed)}\\n`);\n }\n await this.sleep(probe.pollMs);\n }\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise<void>((resolve: () => void): void => {\n setTimeout(resolve, ms);\n });\n }\n}\n\n/**\n * WHAT is being waited for. An interface rather than a class because it is business logic — `done()`\n * reads verdict files for one waiter and asks GitHub for the other — and the loop must not know which.\n */\nexport interface WaitProbe {\n /** Names the wait in every heartbeat line, e.g. `reviewers` / `checks`. */\n readonly label: string;\n /** How long to sleep between two `done()` calls. A file read polls fast; a `gh` call does not. */\n readonly pollMs: number;\n /** True once the wait is over. Called before the first sleep, so an already-finished wait is free. */\n done(): boolean;\n /** The current state, in one short phrase, for the heartbeat: `2 of 4 verdicts in`. */\n describe(): string;\n}\n\n/** How the wait ended: satisfied, or out of time. Data-only (a class, per CLAUDE.md). */\nexport class WaitOutcome {\n done: boolean;\n waitedMs: number;\n\n constructor(done: boolean, waitedMs: number) {\n this.done = done;\n this.waitedMs = waitedMs;\n }\n\n /** Whole seconds waited — what every message prints, so nothing formats it twice. */\n get waitedSeconds(): number {\n return Math.round(this.waitedMs / 1000);\n }\n}\n\n/**\n * The heartbeat's state: what the probe said on the PREVIOUS tick, so a tick that has not moved can say\n * so. `still` is the load-bearing word, exactly as it is in `BuildLogHeartbeat`: a wait where nothing\n * has happened for two minutes and a wait whose REPORTER has died look identical without it.\n */\nexport class WaitHeartbeat {\n private previous: string | null = null;\n private nextDueMs = HEARTBEAT_MS;\n\n constructor(private readonly label: string) {}\n\n /** True when `elapsedMs` has passed the next heartbeat slot; consumes the slot when it has. */\n isDue(elapsedMs: number): boolean {\n if (elapsedMs < this.nextDueMs) return false;\n this.nextDueMs = elapsedMs + HEARTBEAT_MS;\n return true;\n }\n\n /** One heartbeat line — `waiting on <label>: <state> (<n>s)`, plus ` still` when it has not moved. */\n tick(state: string, elapsedMs: number): string {\n const still = this.previous !== null && state === this.previous ? ' still' : '';\n this.previous = state;\n return `waiting on ${this.label}: ${state} (${String(Math.round(elapsedMs / 1000))}s)${still}`;\n }\n}\n\n/**\n * How often the wait proves it is alive. Hardcoded, like `wp-build`'s: the number that matters is the\n * harness's 600-second silence watchdog, which no repo configures, so a knob here would only ever be a\n * way to set it wrong.\n */\nexport const HEARTBEAT_MS = 20_000;\n\n/**\n * When the wait gives up and asks to be re-run — comfortably under the harness's 600-second ceiling, so\n * the command always returns its own answer rather than being killed holding one.\n */\nexport const CEILING_MS = 540_000;\n"]}
|
|
1
|
+
{"version":3,"file":"await-loop.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/await-loop.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAE3D,yDAAoD;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEI,IAAM,SAAS,GAAf,MAAM,SAAS;IACW;IAA7B,YAA6B,YAA4B;QAA5B,iBA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GG;AACU,QAAA,UAAU,GAAG,OAAO,CAAC","sourcesContent":["import { injectable, bindingScopeValues } from 'inversify';\n\nimport { StageOutputLog } from './stage-output-log';\n\n/**\n * THE BLOCKING WAIT, and why webpieces owns one (issue #874, scoped by #878).\n *\n * ─── IT IS ONE EFFICIENT WAIT, OFFERED — NEVER A TURN-LEVEL INSTRUCTION (issue #902) ───────────────\n * #874 justified this class by asserting a worktree-isolated subagent cannot end its turn, #878\n * corrected that, and #900 measured that the background re-invocation the correction relied on does not\n * reliably fire. #902 settles the shape of the advice: webpieces names the efficient wait and blocks the\n * wasteful poll, and says NOTHING about when an agent should end its turn. An agent already waits on the\n * subagents it spawns, routinely, without being told; a fixed rule in a string cannot see the situation\n * it is ruling on.\n *\n * What this class is for is the case where an agent has decided to block. There, a Bash call is\n * the only pause it can express: `Monitor` does not block (its own result says \"Keep working — do not\n * poll or sleep\"), and a `Monitor` carrying a real polling loop is refused by the HARNESS, because a\n * `while`/`until` with a redirect cannot be statically proven to stay inside the worktree (178 of 553\n * measured subagent Monitor calls). That refusal is Claude Code's and is not ours to relax.\n *\n * Without either, the agent falls back to `echo .` every three seconds — measured at 920M tokens, 18.3%\n * of every token the fleet spent in the 24h to 2026-09-07, because every turn resends the whole\n * conversation at ~557,000 tokens. This class is the thing that makes that unnecessary, and\n * `wait-spin-guard` is the thing that makes it unused.\n *\n * ─── THREE CONSTRAINTS, all of them the harness's, none of them negotiable ─────────────────────────\n *\n * 1. **What the AGENT TYPES must be a plain command.** No loop, no redirect, no pipe, no command\n * substitution — those are exactly what the isolation check refuses. All the looping is in here,\n * inside one process, behind a bare `pnpm wp-await-reviews`.\n * 2. **It must print something roughly every {@link HEARTBEAT_MS}.** The harness backgrounds and then\n * KILLS a foreground command that has produced no output for 600 seconds, and a killed wait throws\n * away the wait. Same defence `wp-build` already runs, same `still` word for the same reason: a\n * tick that has not moved must be distinguishable from a stalled reporter.\n * 3. **It must RETURN before that ceiling on its own**, saying to run it again. A wait that dies at\n * the watchdog looks like a crash; a wait that returns at {@link CEILING_MS} with \"still waiting\"\n * turns a 100-minute wait into ~11 tool calls instead of the ~2,000 an `echo .` loop costs.\n *\n * `done` is a normal, ZERO exit either way. \"Still waiting\" is not a failure — it is an answer the agent\n * acts on — and making it non-zero would put a red exit code on the healthy path.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class AwaitLoop {\n constructor(private readonly stageConsole: StageOutputLog) {}\n\n /**\n * Block until `probe` says it is done, or until {@link CEILING_MS} elapses, printing a heartbeat\n * throughout. Returns WHICH of those happened; the caller renders the outcome.\n */\n async run(probe: WaitProbe): Promise<WaitOutcome> {\n const started = Date.now();\n const heartbeat = new WaitHeartbeat(probe.label);\n // `done()` FIRST, before anything is printed. It is what establishes the probe's state, so\n // describing the wait before asking it would report a state nobody has measured — and an\n // already-finished wait must cost nothing at all.\n for (let first = true; ; first = false) {\n if (await probe.done()) return new WaitOutcome(true, Date.now() - started);\n const elapsed = Date.now() - started;\n if (elapsed >= CEILING_MS) return new WaitOutcome(false, elapsed);\n // One heartbeat per HEARTBEAT_MS of ELAPSED time, whatever the poll interval — a probe that\n // costs a network round trip is polled far more slowly than one reading a file, and the\n // watchdog counts seconds of silence, not polls.\n if (first || heartbeat.isDue(elapsed)) {\n this.stageConsole.say(`${heartbeat.tick(probe.describe(), elapsed)}\\n`);\n }\n await this.sleep(probe.pollMs);\n }\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise<void>((resolve: () => void): void => {\n setTimeout(resolve, ms);\n });\n }\n}\n\n/**\n * WHAT is being waited for. An interface rather than a class because it is business logic — `done()`\n * reads verdict files for one waiter and asks GitHub for the other — and the loop must not know which.\n */\nexport interface WaitProbe {\n /** Names the wait in every heartbeat line, e.g. `reviewers` / `checks`. */\n readonly label: string;\n /** How long to sleep between two `done()` calls. A file read polls fast; a `gh` call does not. */\n readonly pollMs: number;\n /** True once the wait is over. Called before the first sleep, so an already-finished wait is free. */\n done(): Promise<boolean>;\n /** The current state, in one short phrase, for the heartbeat: `2 of 4 verdicts in`. */\n describe(): string;\n}\n\n/** How the wait ended: satisfied, or out of time. Data-only (a class, per CLAUDE.md). */\nexport class WaitOutcome {\n done: boolean;\n waitedMs: number;\n\n constructor(done: boolean, waitedMs: number) {\n this.done = done;\n this.waitedMs = waitedMs;\n }\n\n /** Whole seconds waited — what every message prints, so nothing formats it twice. */\n get waitedSeconds(): number {\n return Math.round(this.waitedMs / 1000);\n }\n}\n\n/**\n * The heartbeat's state: what the probe said on the PREVIOUS tick, so a tick that has not moved can say\n * so. `still` is the load-bearing word, exactly as it is in `BuildLogHeartbeat`: a wait where nothing\n * has happened for two minutes and a wait whose REPORTER has died look identical without it.\n */\nexport class WaitHeartbeat {\n private previous: string | null = null;\n private nextDueMs = HEARTBEAT_MS;\n\n constructor(private readonly label: string) {}\n\n /** True when `elapsedMs` has passed the next heartbeat slot; consumes the slot when it has. */\n isDue(elapsedMs: number): boolean {\n if (elapsedMs < this.nextDueMs) return false;\n this.nextDueMs = elapsedMs + HEARTBEAT_MS;\n return true;\n }\n\n /** One heartbeat line — `waiting on <label>: <state> (<n>s)`, plus ` still` when it has not moved. */\n tick(state: string, elapsedMs: number): string {\n const still = this.previous !== null && state === this.previous ? ' still' : '';\n this.previous = state;\n return `waiting on ${this.label}: ${state} (${String(Math.round(elapsedMs / 1000))}s)${still}`;\n }\n}\n\n/**\n * How often the wait proves it is alive. Hardcoded, like `wp-build`'s: the number that matters is the\n * harness's 600-second silence watchdog, which no repo configures, so a knob here would only ever be a\n * way to set it wrong.\n */\nexport const HEARTBEAT_MS = 20_000;\n\n/**\n * When the wait gives up and asks to be re-run — comfortably under the harness's 600-second ceiling, so\n * the command always returns its own answer rather than being killed holding one.\n */\nexport const CEILING_MS = 540_000;\n"]}
|
|
@@ -89,7 +89,7 @@ let BuildAffected = class BuildAffected {
|
|
|
89
89
|
// command being run and the result of running it are exactly what a caller watching a long build
|
|
90
90
|
// needs to see live.
|
|
91
91
|
this.stageConsole.say(`\n${opts.label}: ${buildCommand}\n`);
|
|
92
|
-
const logPath = this.buildLog.pathFor(repoRoot, opts.stage);
|
|
92
|
+
const logPath = await this.buildLog.pathFor(repoRoot, opts.stage);
|
|
93
93
|
const ticket = this.buildsLog.start(opts.stage, repoRoot);
|
|
94
94
|
let termination = new rules_config_1.BuildTermination(1, null);
|
|
95
95
|
// webpieces-disable no-unmanaged-exceptions -- chokepoint: the DONE row must be written whether the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-affected.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/build-affected.ts"],"names":[],"mappings":";;;;AAAA,0DAAkJ;AAClJ,sEAA+D;AAC/D,yCAA2D;AAC3D,qDAAgD;AAChD,yDAAoD;AAEpD,iGAAiG;AACjG,8FAA8F;AAC9F,iGAAiG;AACjG,oFAAoF;AACpF,oGAAoG;AACpG,iEAAiE;AAEjE;;;;GAIG;AACH,MAAa,gBAAgB;IACzB,KAAK,CAAS,CAAC,sCAAsC;IACrD,YAAY,CAAS,CAAC,gDAAgD;IACtE,eAAe,CAAS,CAAC,gCAAgC;IACzD,qGAAqG;IACrG,uGAAuG;IACvG,KAAK,CAAS;IAEd,YAAY,KAAa,EAAE,YAAoB,EAAE,eAAuB,EAAE,KAAa;QACnF,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;CACJ;AAdD,4CAcC;AAED,qGAAqG;AAE9F,IAAM,aAAa,GAAnB,MAAM,aAAa;IAED;IACA;IACA;IACA;IAJrB,YACqB,QAAsB,EACtB,SAAoB,EACpB,YAA4B,EAC5B,cAA8B;QAH9B,aAAQ,GAAR,QAAQ,CAAc;QACtB,cAAS,GAAT,SAAS,CAAW;QACpB,iBAAY,GAAZ,YAAY,CAAgB;QAC5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,sCAAa;wBAAb,aAAa;IADzB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGN,6BAAY;QACX,wBAAS;QACN,iCAAc;QACZ,mCAAc;GAL1C,aAAa,CAkGzB","sourcesContent":["import { loadAndValidate, CliExitError, DEFAULT_BUILD_COMMAND, BuildsLog, BuildTermination, HOTFIX_BUILD_COMMAND } from '@webpieces/rules-config';\nimport { BranchIdentity } from '@webpieces/repo-workflow-core';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { BuildGateLog } from './build-gate-log';\nimport { StageOutputLog } from './stage-output-log';\n\n// Single source of truth for RUNNING the build gate. `wp-start-upsert-pr` runs NO build; stage ②\n// (`wp-review-upsert-pr`) runs it authoritatively before any reviewer is spawned, and stage ③\n// (`wp-finish-upsert-pr`) re-runs it only when HEAD has moved since. nx `affected` only rebuilds\n// changed projects. The fallback command itself lives in @webpieces/rules-config as\n// DEFAULT_BUILD_COMMAND — whole-repo-build-guard prints the same string, and one definition is what\n// keeps the refusal message naming the build that actually runs.\n\n/**\n * The caller-supplied framing for the build gate (label, re-run command, failure headline, stage id). Kept\n * as a parameter object so runBuildGate stays agnostic of who invokes it. A class (not an object literal)\n * per the codebase's data-structure convention.\n */\nexport class BuildGateOptions {\n label: string; // section header shown above the gate\n rerunCommand: string; // command the AI re-runs after fixing the build\n failureHeadline: string; // first line printed on failure\n // WHICH stage's gate this is — REVIEW_STAGE, FINISH_STAGE or BUILD_STAGE. Required, with no default:\n // it decides the captured log's filename, and a default would silently make two stages share one file.\n stage: string;\n\n constructor(label: string, rerunCommand: string, failureHeadline: string, stage: string) {\n this.label = label;\n this.rerunCommand = rerunCommand;\n this.failureHeadline = failureHeadline;\n this.stage = stage;\n }\n}\n\n/** Runs the authoritative nx-affected build gate for wp-review-upsert-pr and wp-finish-upsert-pr. */\n@injectable(bindingScopeValues.Singleton)\nexport class BuildAffected {\n constructor(\n private readonly buildLog: BuildGateLog,\n private readonly buildsLog: BuildsLog,\n private readonly stageConsole: StageOutputLog,\n private readonly branchIdentity: BranchIdentity,\n ) {}\n\n /**\n * Resolve the exact build command this gate will run: the project's configured\n * PrGateConfig.buildCommand, or the default affected-ci command when none is set.\n */\n resolveBuildCommand(repoRoot: string): string {\n if (this.branchIdentity.isHotfix()) return HOTFIX_BUILD_COMMAND;\n const configured = loadAndValidate(repoRoot).prGate.buildCommand;\n return configured !== undefined && configured.trim() !== ''\n ? configured\n : DEFAULT_BUILD_COMMAND;\n }\n\n /**\n * Run the configured build gate with consistent framing, throwing CliExitError(buildCode) on\n * failure so the bin's main()/runMain owns the exit. THE single source of truth for running a build:\n * wp-build, wp-review-upsert-pr and wp-finish-upsert-pr all call THIS (only the BuildGateOptions\n * differ), and there is no other way to reach the spawn.\n *\n * ─── EVERY BUILD ON THIS MACHINE IS LEDGERED FROM HERE ───────────────────────────────────────────\n * A START row goes into `~/.webpieces/builds.log` before the spawn and a DONE row after it, in a\n * `finally` so a throw on the failure path still closes the pair. `opts.stage` — `build` | `review` |\n * `finish` — IS the caller id the row records; there is deliberately no second `caller` field, since\n * two spellings of one fact is the shim `.claude/rules/no-backwards-compat.md` rejects.\n *\n * The ledger is best-effort by construction (see BuildsLog): it can never throw, so no build can die\n * because a log file was busy.\n */\n async runBuildGate(repoRoot: string, opts: BuildGateOptions): Promise<void> {\n return this.run(repoRoot, opts, false);\n }\n\n /** The human escape hatch uses the same gate but follows build.log on the terminal while it runs. */\n async runBuildGateStreaming(repoRoot: string, opts: BuildGateOptions): Promise<void> {\n return this.run(repoRoot, opts, true);\n }\n\n private async run(repoRoot: string, opts: BuildGateOptions, stream: boolean): Promise<void> {\n const buildCommand = this.resolveBuildCommand(repoRoot);\n // TWO lines on the happy path — the command, then the result. The old framing spent a banner and a\n // paragraph explaining how to reproduce a build that was about to pass anyway; that explanation is\n // only useful when the build FAILS, so it now lives solely on the failure path below.\n //\n // `say`, so it survives a stage that is capturing its own console (see StageOutputLog): the\n // command being run and the result of running it are exactly what a caller watching a long build\n // needs to see live.\n this.stageConsole.say(`\\n${opts.label}: ${buildCommand}\\n`);\n const logPath = this.buildLog.pathFor(repoRoot, opts.stage);\n const ticket = this.buildsLog.start(opts.stage, repoRoot);\n let termination = new BuildTermination(1, null);\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: the DONE row must be written whether the\n // build passed, failed, or the spawn itself blew up; the throw is re-raised untouched below\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n termination = stream\n ? await this.buildLog.runStreaming(repoRoot, buildCommand, logPath)\n : await this.buildLog.run(repoRoot, buildCommand, logPath);\n } finally {\n this.buildsLog.finish(ticket, termination);\n }\n const buildCode =\n termination.code === null || termination.signal !== null ? 1 : termination.code;\n if (buildCode !== 0) {\n throw new CliExitError(\n buildCode,\n this.failureText(opts, buildCommand, logPath, termination),\n );\n }\n this.stageConsole.say(this.buildLog.successMessage(logPath));\n }\n\n /**\n * The failure text: this gate's own headline, then the pointer at the log the build already wrote.\n *\n * There is no second, streamed variant any more. Capturing used to be behind an EXPERIMENTAL\n * machine-local opt-in, which meant the refusal an agent read depended on a file almost nobody had —\n * and the un-captured branch's advice was \"run the build again yourself\", which is the single most\n * expensive thing an agent can be told. Reading a FILE is now the only answer this gate gives.\n */\n private failureText(\n opts: BuildGateOptions,\n buildCommand: string,\n logPath: string,\n termination: BuildTermination,\n ): string {\n return (\n `\\n❌ ${opts.failureHeadline}\\n` +\n this.buildLog.failureMessage(buildCommand, logPath, termination) +\n `Fix what that log shows, then re-run ${opts.rerunCommand}.\\n`\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"build-affected.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/build-affected.ts"],"names":[],"mappings":";;;;AAAA,0DAAkJ;AAClJ,sEAA+D;AAC/D,yCAA2D;AAC3D,qDAAgD;AAChD,yDAAoD;AAEpD,iGAAiG;AACjG,8FAA8F;AAC9F,iGAAiG;AACjG,oFAAoF;AACpF,oGAAoG;AACpG,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,IAAI,WAAW,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC;QACpF,IAAI,SAAS,KAAK,CAAC,EAAE,CAAC;YAClB,MAAM,IAAI,2BAAY,CAClB,SAAS,EACT,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,CAAC,CAC7D,CAAC;QACN,CAAC;QACD,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;IACjE,CAAC;IAED;;;;;;;OAOG;IACK,WAAW,CACf,IAAsB,EACtB,YAAoB,EACpB,OAAe,EACf,WAA6B;QAE7B,OAAO,CACH,OAAO,IAAI,CAAC,eAAe,IAAI;YAC/B,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,YAAY,EAAE,OAAO,EAAE,WAAW,CAAC;YAChE,wCAAwC,IAAI,CAAC,YAAY,KAAK,CACjE,CAAC;IACN,CAAC;CACJ,CAAA;AAlGY,sCAAa;wBAAb,aAAa;IADzB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGN,6BAAY;QACX,wBAAS;QACN,iCAAc;QACZ,mCAAc;GAL1C,aAAa,CAkGzB","sourcesContent":["import { loadAndValidate, CliExitError, DEFAULT_BUILD_COMMAND, BuildsLog, BuildTermination, HOTFIX_BUILD_COMMAND } from '@webpieces/rules-config';\nimport { BranchIdentity } from '@webpieces/repo-workflow-core';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { BuildGateLog } from './build-gate-log';\nimport { StageOutputLog } from './stage-output-log';\n\n// Single source of truth for RUNNING the build gate. `wp-start-upsert-pr` runs NO build; stage ②\n// (`wp-review-upsert-pr`) runs it authoritatively before any reviewer is spawned, and stage ③\n// (`wp-finish-upsert-pr`) re-runs it only when HEAD has moved since. nx `affected` only rebuilds\n// changed projects. The fallback command itself lives in @webpieces/rules-config as\n// DEFAULT_BUILD_COMMAND — whole-repo-build-guard prints the same string, and one definition is what\n// keeps the refusal message naming the build that actually runs.\n\n/**\n * The caller-supplied framing for the build gate (label, re-run command, failure headline, stage id). Kept\n * as a parameter object so runBuildGate stays agnostic of who invokes it. A class (not an object literal)\n * per the codebase's data-structure convention.\n */\nexport class BuildGateOptions {\n label: string; // section header shown above the gate\n rerunCommand: string; // command the AI re-runs after fixing the build\n failureHeadline: string; // first line printed on failure\n // WHICH stage's gate this is — REVIEW_STAGE, FINISH_STAGE or BUILD_STAGE. Required, with no default:\n // it decides the captured log's filename, and a default would silently make two stages share one file.\n stage: string;\n\n constructor(label: string, rerunCommand: string, failureHeadline: string, stage: string) {\n this.label = label;\n this.rerunCommand = rerunCommand;\n this.failureHeadline = failureHeadline;\n this.stage = stage;\n }\n}\n\n/** Runs the authoritative nx-affected build gate for wp-review-upsert-pr and wp-finish-upsert-pr. */\n@injectable(bindingScopeValues.Singleton)\nexport class BuildAffected {\n constructor(\n private readonly buildLog: BuildGateLog,\n private readonly buildsLog: BuildsLog,\n private readonly stageConsole: StageOutputLog,\n private readonly branchIdentity: BranchIdentity,\n ) {}\n\n /**\n * Resolve the exact build command this gate will run: the project's configured\n * PrGateConfig.buildCommand, or the default affected-ci command when none is set.\n */\n resolveBuildCommand(repoRoot: string): string {\n if (this.branchIdentity.isHotfix()) return HOTFIX_BUILD_COMMAND;\n const configured = loadAndValidate(repoRoot).prGate.buildCommand;\n return configured !== undefined && configured.trim() !== ''\n ? configured\n : DEFAULT_BUILD_COMMAND;\n }\n\n /**\n * Run the configured build gate with consistent framing, throwing CliExitError(buildCode) on\n * failure so the bin's main()/runMain owns the exit. THE single source of truth for running a build:\n * wp-build, wp-review-upsert-pr and wp-finish-upsert-pr all call THIS (only the BuildGateOptions\n * differ), and there is no other way to reach the spawn.\n *\n * ─── EVERY BUILD ON THIS MACHINE IS LEDGERED FROM HERE ───────────────────────────────────────────\n * A START row goes into `~/.webpieces/builds.log` before the spawn and a DONE row after it, in a\n * `finally` so a throw on the failure path still closes the pair. `opts.stage` — `build` | `review` |\n * `finish` — IS the caller id the row records; there is deliberately no second `caller` field, since\n * two spellings of one fact is the shim `.claude/rules/no-backwards-compat.md` rejects.\n *\n * The ledger is best-effort by construction (see BuildsLog): it can never throw, so no build can die\n * because a log file was busy.\n */\n async runBuildGate(repoRoot: string, opts: BuildGateOptions): Promise<void> {\n return this.run(repoRoot, opts, false);\n }\n\n /** The human escape hatch uses the same gate but follows build.log on the terminal while it runs. */\n async runBuildGateStreaming(repoRoot: string, opts: BuildGateOptions): Promise<void> {\n return this.run(repoRoot, opts, true);\n }\n\n private async run(repoRoot: string, opts: BuildGateOptions, stream: boolean): Promise<void> {\n const buildCommand = this.resolveBuildCommand(repoRoot);\n // TWO lines on the happy path — the command, then the result. The old framing spent a banner and a\n // paragraph explaining how to reproduce a build that was about to pass anyway; that explanation is\n // only useful when the build FAILS, so it now lives solely on the failure path below.\n //\n // `say`, so it survives a stage that is capturing its own console (see StageOutputLog): the\n // command being run and the result of running it are exactly what a caller watching a long build\n // needs to see live.\n this.stageConsole.say(`\\n${opts.label}: ${buildCommand}\\n`);\n const logPath = await this.buildLog.pathFor(repoRoot, opts.stage);\n const ticket = this.buildsLog.start(opts.stage, repoRoot);\n let termination = new BuildTermination(1, null);\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: the DONE row must be written whether the\n // build passed, failed, or the spawn itself blew up; the throw is re-raised untouched below\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n termination = stream\n ? await this.buildLog.runStreaming(repoRoot, buildCommand, logPath)\n : await this.buildLog.run(repoRoot, buildCommand, logPath);\n } finally {\n this.buildsLog.finish(ticket, termination);\n }\n const buildCode =\n termination.code === null || termination.signal !== null ? 1 : termination.code;\n if (buildCode !== 0) {\n throw new CliExitError(\n buildCode,\n this.failureText(opts, buildCommand, logPath, termination),\n );\n }\n this.stageConsole.say(this.buildLog.successMessage(logPath));\n }\n\n /**\n * The failure text: this gate's own headline, then the pointer at the log the build already wrote.\n *\n * There is no second, streamed variant any more. Capturing used to be behind an EXPERIMENTAL\n * machine-local opt-in, which meant the refusal an agent read depended on a file almost nobody had —\n * and the un-captured branch's advice was \"run the build again yourself\", which is the single most\n * expensive thing an agent can be told. Reading a FILE is now the only answer this gate gives.\n */\n private failureText(\n opts: BuildGateOptions,\n buildCommand: string,\n logPath: string,\n termination: BuildTermination,\n ): string {\n return (\n `\\n❌ ${opts.failureHeadline}\\n` +\n this.buildLog.failureMessage(buildCommand, logPath, termination) +\n `Fix what that log shows, then re-run ${opts.rerunCommand}.\\n`\n );\n }\n}\n"]}
|
|
@@ -48,7 +48,7 @@ export declare class BuildArtifactGate {
|
|
|
48
48
|
* Run the check and throw CliExitError when the build left the tree dirty. Called immediately after
|
|
49
49
|
* the build gate passes, while the tree still holds exactly what the build produced.
|
|
50
50
|
*/
|
|
51
|
-
assertBuildLeftNothingUncommitted(repoRoot: string): void
|
|
51
|
+
assertBuildLeftNothingUncommitted(repoRoot: string): Promise<void>;
|
|
52
52
|
/**
|
|
53
53
|
* Sort every UNSATISFIED status entry into the two verdicts. Pure, so the specs drive it with
|
|
54
54
|
* literal porcelain text (run through `GitStatusParser`) instead of building repos.
|
|
@@ -64,11 +64,11 @@ let BuildArtifactGate = class BuildArtifactGate {
|
|
|
64
64
|
* Run the check and throw CliExitError when the build left the tree dirty. Called immediately after
|
|
65
65
|
* the build gate passes, while the tree still holds exactly what the build produced.
|
|
66
66
|
*/
|
|
67
|
-
assertBuildLeftNothingUncommitted(repoRoot) {
|
|
68
|
-
const artifacts = this.registry.resolve(repoRoot);
|
|
67
|
+
async assertBuildLeftNothingUncommitted(repoRoot) {
|
|
68
|
+
const artifacts = await this.registry.resolve(repoRoot);
|
|
69
69
|
// statusEntries, never a raw/trimmed string: the staged-vs-unstaged answer arrives as a boolean
|
|
70
70
|
// so no caller can re-derive it from column positions and get it backwards.
|
|
71
|
-
const verdict = this.classify(this.gitExec.statusEntries(repoRoot), artifacts);
|
|
71
|
+
const verdict = this.classify(await this.gitExec.statusEntries(repoRoot), artifacts);
|
|
72
72
|
if (verdict.isClean()) {
|
|
73
73
|
process.stdout.write('\n✅ Build left the tree committed — no uncommitted build artifacts.\n');
|
|
74
74
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-artifact-gate.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/build-artifact-gate.ts"],"names":[],"mappings":";;;;AAAA,0DAAuE;AACvE,yCAA2D;AAC3D,qDAAiD;AACjD,+EAA8F;AAC9F,yCAAqC;AAGrC,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;GAIG;AACH,MAAa,oBAAoB;IAC7B,qGAAqG;IACrG,cAAc,CAAmB;IACjC,iGAAiG;IACjG,cAAc,CAAmB;IAEjC,YAAY,cAAgC,EAAE,cAAgC;QAC1E,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACzC,CAAC;IAED,OAAO;QACH,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,KAAK,CAAC,CAAC;IAChF,CAAC;CACJ;AAdD,oDAcC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEI,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAEL;IACA;IACA;IAHrB,YACqB,OAAgB,EAChB,QAAmC,EACnC,aAA4B;QAF5B,YAAO,GAAP,OAAO,CAAS;QAChB,aAAQ,GAAR,QAAQ,CAA2B;QACnC,kBAAa,GAAb,aAAa,CAAe;IAC9C,CAAC;IAEJ;;;OAGG;IACH,iCAAiC,CAAC,QAAgB;QAC9C,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAClD,gGAAgG;QAChG,4EAA4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liExitError, matchesAnyGlob } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { BuildAffected } from './build-affected';\nimport { GeneratedArtifactRegistry, GeneratedArtifacts } from './generated-artifact-registry';\nimport { GitExec } from './git-exec';\nimport { GitStatusEntry } from './git-status';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * What the repo-wide post-build tree check concluded, split into the ticket's two verdicts. Both lists\n * can be non-empty at once, and when they are BOTH are reported — a stray artifact does not hide a\n * stale design file or vice versa.\n */\nexport class BuildArtifactVerdict {\n /** Verdict 1 — dirty, but the build is SUPPOSED to write it: you did not commit the regeneration. */\n staleGenerated: GitStatusEntry[];\n /** Verdict 2 — dirty and nobody declared it: the build is emitting uncommitted git artifacts. */\n strayArtifacts: GitStatusEntry[];\n\n constructor(staleGenerated: GitStatusEntry[], strayArtifacts: GitStatusEntry[]) {\n this.staleGenerated = staleGenerated;\n this.strayArtifacts = strayArtifacts;\n }\n\n isClean(): boolean {\n return this.staleGenerated.length === 0 && this.strayArtifacts.length === 0;\n }\n}\n\n/**\n * The repo-wide \"did the build leave anything uncommitted?\" gate, run in `wp-review-upsert-pr` right\n * after `buildCommand`.\n *\n * It REPLACES the per-project `validate-di-graph-unchanged` nx target, which asked the same question in\n * the wrong place. That target used `git status --porcelain` as its oracle while itself dirtying the\n * tree, so nx (which hashes by file CONTENTS) saw one hash produce both a pass and a fail and labelled\n * the task \"flaky\" — it was not flaky, it was stateful in a dimension nx cannot see. It also could not\n * pass mid-merge, where `merge-in-progress-guard` blocks the `git commit` it demanded.\n *\n * THE PREDICATE IS \"committed OR staged\", and that is the whole trick:\n *\n * porcelain column 1 = index state, column 2 = working-tree state.\n * Satisfied ⇔ column 2 is ' ' AND the entry is not `??`.\n *\n * A normal branch commits its regenerated design files → clean → passes. Mid-merge `git commit` is\n * blocked but `git add` is expected (and the gate itself commits the resolution) → staged → passes.\n * ONE rule covering both, with no merge special-case and no skip, because a special case is a second\n * rule and two rules for one invariant is how they drift.\n *\n * Coverage is strictly larger than the target it replaces: that one only ever looked at `design.*` in\n * one project, this looks at the WHOLE repo, so a build that quietly writes anywhere else is caught for\n * the first time.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class BuildArtifactGate {\n constructor(\n private readonly gitExec: GitExec,\n private readonly registry: GeneratedArtifactRegistry,\n private readonly buildAffected: BuildAffected,\n ) {}\n\n /**\n * Run the check and throw CliExitError when the build left the tree dirty. Called immediately after\n * the build gate passes, while the tree still holds exactly what the build produced.\n */\n assertBuildLeftNothingUncommitted(repoRoot: string): void {\n const artifacts = this.registry.resolve(repoRoot);\n // statusEntries, never a raw/trimmed string: the staged-vs-unstaged answer arrives as a boolean\n // so no caller can re-derive it from column positions and get it backwards.\n const verdict = this.classify(this.gitExec.statusEntries(repoRoot), artifacts);\n if (verdict.isClean()) {\n process.stdout.write('\\n✅ Build left the tree committed — no uncommitted build artifacts.\\n');\n return;\n }\n throw new CliExitError(1, this.render(repoRoot, verdict, artifacts));\n }\n\n /**\n * Sort every UNSATISFIED status entry into the two verdicts. Pure, so the specs drive it with\n * literal porcelain text (run through `GitStatusParser`) instead of building repos.\n *\n * THE PREDICATE lives in {@link GitStatusEntry.isCommittedOrStaged} — a clean worktree column\n * means the change is committed or staged, and `??` is excluded because its second column is not\n * a worktree state at all.\n */\n classify(entries: readonly GitStatusEntry[], artifacts: GeneratedArtifacts): BuildArtifactVerdict {\n const stale: GitStatusEntry[] = [];\n const stray: GitStatusEntry[] = [];\n for (const entry of entries) {\n if (entry.isCommittedOrStaged()) continue;\n if (matchesAnyGlob(entry.path, artifacts.paths)) stale.push(entry);\n else stray.push(entry);\n }\n return new BuildArtifactVerdict(stale, stray);\n }\n\n /** The full failure message — verdict 1 section, verdict 2 section, or both. */\n private render(repoRoot: string, verdict: BuildArtifactVerdict, artifacts: GeneratedArtifacts): string {\n const buildCommand = this.buildAffected.resolveBuildCommand(repoRoot);\n const parts: string[] = ['\\n' + SEP + '❌ The build left uncommitted changes in the working tree\\n' + SEP];\n if (verdict.staleGenerated.length > 0) parts.push(this.renderStale(verdict, buildCommand));\n if (verdict.strayArtifacts.length > 0) parts.push(this.renderStray(verdict));\n parts.push(\n `\\nThe rule is one line: after the build, every changed path must be COMMITTED **or** STAGED.\\n` +\n `Staged counts, which is why this also works mid-3-point-merge, where \\`git commit\\` is blocked\\n` +\n `by merge-in-progress-guard but \\`git add\\` is exactly what you are supposed to do.\\n\\n` +\n `Known-generated paths came from: ${artifacts.source}\\n` + SEP);\n return parts.join('');\n }\n\n private renderStale(verdict: BuildArtifactVerdict, buildCommand: string): string {\n return `\\nYou did not run \\`${buildCommand}\\` and commit the regenerated design files, so the\\n` +\n `review cannot proceed. These are declared build outputs and the build just rewrote them:\\n\\n` +\n this.listing(verdict.staleGenerated) +\n `\\nFix it by running the build and committing (or staging) the result:\\n\\n` +\n ` ${buildCommand}\\n` +\n ` git add -A && git commit -m \"regenerate design files\"\\n`;\n }\n\n private renderStray(verdict: BuildArtifactVerdict): string {\n return `\\nYour build is generating uncommitted git artifacts, so I cannot continue the PR process.\\n` +\n `Either (1, best) write them to an output directory that is in \\`.gitignore\\`, or (2) add a new\\n` +\n `dir to \\`.gitignore\\`.\\n\\n` +\n `These paths are NOT declared as the output of any build target:\\n\\n` +\n this.listing(verdict.strayArtifacts);\n }\n\n private listing(entries: readonly GitStatusEntry[]): string {\n return entries\n .map((e: GitStatusEntry): string => ` ${e.indexStatus}${e.worktreeStatus} ${e.path}${e.isUntracked() ? ' (untracked — brand new)' : ''}\\n`)\n .join('');\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"build-artifact-gate.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/build-artifact-gate.ts"],"names":[],"mappings":";;;;AAAA,0DAAuE;AACvE,yCAA2D;AAC3D,qDAAiD;AACjD,+EAA8F;AAC9F,yCAAqC;AAGrC,MAAM,GAA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YAAoB;QACnE,OAAO,uBAAuB,YAAY,sDAAsD;YAC5F,8FAA8F;YAC9F,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC;YACpC,2EAA2E;YAC3E,OAAO,YAAY,IAAI;YACvB,6DAA6D,CAAC;IACtE,CAAC;IAEO,WAAW,CAAC,OAA6B;QAC7C,OAAO,8FAA8F;YACjG,kGAAkG;YAClG,4BAA4B;YAC5B,qEAAqE;YACrE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IAC7C,CAAC;IAEO,OAAO,CAAC,OAAkC;QAC9C,OAAO,OAAO;aACT,GAAG,CAAC,CAAC,CAAiB,EAAU,EAAE,CAAC,MAAM,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,cAAc,KAAK,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC;aAC/I,IAAI,CAAC,EAAE,CAAC,CAAC;IAClB,CAAC;CACJ,CAAA;AA9EY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGP,kBAAO;QACN,uDAAyB;QACpB,8BAAa;GAJxC,iBAAiB,CA8E7B","sourcesContent":["import { CliExitError, matchesAnyGlob } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { BuildAffected } from './build-affected';\nimport { GeneratedArtifactRegistry, GeneratedArtifacts } from './generated-artifact-registry';\nimport { GitExec } from './git-exec';\nimport { GitStatusEntry } from './git-status';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * What the repo-wide post-build tree check concluded, split into the ticket's two verdicts. Both lists\n * can be non-empty at once, and when they are BOTH are reported — a stray artifact does not hide a\n * stale design file or vice versa.\n */\nexport class BuildArtifactVerdict {\n /** Verdict 1 — dirty, but the build is SUPPOSED to write it: you did not commit the regeneration. */\n staleGenerated: GitStatusEntry[];\n /** Verdict 2 — dirty and nobody declared it: the build is emitting uncommitted git artifacts. */\n strayArtifacts: GitStatusEntry[];\n\n constructor(staleGenerated: GitStatusEntry[], strayArtifacts: GitStatusEntry[]) {\n this.staleGenerated = staleGenerated;\n this.strayArtifacts = strayArtifacts;\n }\n\n isClean(): boolean {\n return this.staleGenerated.length === 0 && this.strayArtifacts.length === 0;\n }\n}\n\n/**\n * The repo-wide \"did the build leave anything uncommitted?\" gate, run in `wp-review-upsert-pr` right\n * after `buildCommand`.\n *\n * It REPLACES the per-project `validate-di-graph-unchanged` nx target, which asked the same question in\n * the wrong place. That target used `git status --porcelain` as its oracle while itself dirtying the\n * tree, so nx (which hashes by file CONTENTS) saw one hash produce both a pass and a fail and labelled\n * the task \"flaky\" — it was not flaky, it was stateful in a dimension nx cannot see. It also could not\n * pass mid-merge, where `merge-in-progress-guard` blocks the `git commit` it demanded.\n *\n * THE PREDICATE IS \"committed OR staged\", and that is the whole trick:\n *\n * porcelain column 1 = index state, column 2 = working-tree state.\n * Satisfied ⇔ column 2 is ' ' AND the entry is not `??`.\n *\n * A normal branch commits its regenerated design files → clean → passes. Mid-merge `git commit` is\n * blocked but `git add` is expected (and the gate itself commits the resolution) → staged → passes.\n * ONE rule covering both, with no merge special-case and no skip, because a special case is a second\n * rule and two rules for one invariant is how they drift.\n *\n * Coverage is strictly larger than the target it replaces: that one only ever looked at `design.*` in\n * one project, this looks at the WHOLE repo, so a build that quietly writes anywhere else is caught for\n * the first time.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class BuildArtifactGate {\n constructor(\n private readonly gitExec: GitExec,\n private readonly registry: GeneratedArtifactRegistry,\n private readonly buildAffected: BuildAffected,\n ) {}\n\n /**\n * Run the check and throw CliExitError when the build left the tree dirty. Called immediately after\n * the build gate passes, while the tree still holds exactly what the build produced.\n */\n async assertBuildLeftNothingUncommitted(repoRoot: string): Promise<void> {\n const artifacts = await this.registry.resolve(repoRoot);\n // statusEntries, never a raw/trimmed string: the staged-vs-unstaged answer arrives as a boolean\n // so no caller can re-derive it from column positions and get it backwards.\n const verdict = this.classify(await this.gitExec.statusEntries(repoRoot), artifacts);\n if (verdict.isClean()) {\n process.stdout.write('\\n✅ Build left the tree committed — no uncommitted build artifacts.\\n');\n return;\n }\n throw new CliExitError(1, this.render(repoRoot, verdict, artifacts));\n }\n\n /**\n * Sort every UNSATISFIED status entry into the two verdicts. Pure, so the specs drive it with\n * literal porcelain text (run through `GitStatusParser`) instead of building repos.\n *\n * THE PREDICATE lives in {@link GitStatusEntry.isCommittedOrStaged} — a clean worktree column\n * means the change is committed or staged, and `??` is excluded because its second column is not\n * a worktree state at all.\n */\n classify(entries: readonly GitStatusEntry[], artifacts: GeneratedArtifacts): BuildArtifactVerdict {\n const stale: GitStatusEntry[] = [];\n const stray: GitStatusEntry[] = [];\n for (const entry of entries) {\n if (entry.isCommittedOrStaged()) continue;\n if (matchesAnyGlob(entry.path, artifacts.paths)) stale.push(entry);\n else stray.push(entry);\n }\n return new BuildArtifactVerdict(stale, stray);\n }\n\n /** The full failure message — verdict 1 section, verdict 2 section, or both. */\n private render(repoRoot: string, verdict: BuildArtifactVerdict, artifacts: GeneratedArtifacts): string {\n const buildCommand = this.buildAffected.resolveBuildCommand(repoRoot);\n const parts: string[] = ['\\n' + SEP + '❌ The build left uncommitted changes in the working tree\\n' + SEP];\n if (verdict.staleGenerated.length > 0) parts.push(this.renderStale(verdict, buildCommand));\n if (verdict.strayArtifacts.length > 0) parts.push(this.renderStray(verdict));\n parts.push(\n `\\nThe rule is one line: after the build, every changed path must be COMMITTED **or** STAGED.\\n` +\n `Staged counts, which is why this also works mid-3-point-merge, where \\`git commit\\` is blocked\\n` +\n `by merge-in-progress-guard but \\`git add\\` is exactly what you are supposed to do.\\n\\n` +\n `Known-generated paths came from: ${artifacts.source}\\n` + SEP);\n return parts.join('');\n }\n\n private renderStale(verdict: BuildArtifactVerdict, buildCommand: string): string {\n return `\\nYou did not run \\`${buildCommand}\\` and commit the regenerated design files, so the\\n` +\n `review cannot proceed. These are declared build outputs and the build just rewrote them:\\n\\n` +\n this.listing(verdict.staleGenerated) +\n `\\nFix it by running the build and committing (or staging) the result:\\n\\n` +\n ` ${buildCommand}\\n` +\n ` git add -A && git commit -m \"regenerate design files\"\\n`;\n }\n\n private renderStray(verdict: BuildArtifactVerdict): string {\n return `\\nYour build is generating uncommitted git artifacts, so I cannot continue the PR process.\\n` +\n `Either (1, best) write them to an output directory that is in \\`.gitignore\\`, or (2) add a new\\n` +\n `dir to \\`.gitignore\\`.\\n\\n` +\n `These paths are NOT declared as the output of any build target:\\n\\n` +\n this.listing(verdict.strayArtifacts);\n }\n\n private listing(entries: readonly GitStatusEntry[]): string {\n return entries\n .map((e: GitStatusEntry): string => ` ${e.indexStatus}${e.worktreeStatus} ${e.path}${e.isUntracked() ? ' (untracked — brand new)' : ''}\\n`)\n .join('');\n }\n}\n"]}
|