@webpieces/pr-gate 0.4.974 → 0.4.976

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.
Files changed (169) hide show
  1. package/package.json +6 -6
  2. package/src/scripts/commands/await-checks-command.d.ts +6 -3
  3. package/src/scripts/commands/await-checks-command.js +17 -12
  4. package/src/scripts/commands/await-checks-command.js.map +1 -1
  5. package/src/scripts/commands/await-reviews-command.d.ts +1 -1
  6. package/src/scripts/commands/await-reviews-command.js +3 -3
  7. package/src/scripts/commands/await-reviews-command.js.map +1 -1
  8. package/src/scripts/commands/check-pr-command.d.ts +3 -1
  9. package/src/scripts/commands/check-pr-command.js +12 -9
  10. package/src/scripts/commands/check-pr-command.js.map +1 -1
  11. package/src/scripts/commands/finish-push-dev-command.js +3 -4
  12. package/src/scripts/commands/finish-push-dev-command.js.map +1 -1
  13. package/src/scripts/commands/finish-update-command.js +1 -1
  14. package/src/scripts/commands/finish-update-command.js.map +1 -1
  15. package/src/scripts/commands/finish-upsert-pr-command.d.ts +4 -1
  16. package/src/scripts/commands/finish-upsert-pr-command.js +65 -62
  17. package/src/scripts/commands/finish-upsert-pr-command.js.map +1 -1
  18. package/src/scripts/commands/human-post-pr-command.d.ts +8 -6
  19. package/src/scripts/commands/human-post-pr-command.js +32 -31
  20. package/src/scripts/commands/human-post-pr-command.js.map +1 -1
  21. package/src/scripts/commands/land-pr-command.d.ts +5 -1
  22. package/src/scripts/commands/land-pr-command.js +36 -22
  23. package/src/scripts/commands/land-pr-command.js.map +1 -1
  24. package/src/scripts/commands/main-checkout.d.ts +4 -1
  25. package/src/scripts/commands/main-checkout.js +22 -22
  26. package/src/scripts/commands/main-checkout.js.map +1 -1
  27. package/src/scripts/commands/push-dev-command.js +28 -29
  28. package/src/scripts/commands/push-dev-command.js.map +1 -1
  29. package/src/scripts/commands/review-upsert-pr-command.js +9 -9
  30. package/src/scripts/commands/review-upsert-pr-command.js.map +1 -1
  31. package/src/scripts/commands/start-update-command.d.ts +1 -1
  32. package/src/scripts/commands/start-update-command.js +3 -3
  33. package/src/scripts/commands/start-update-command.js.map +1 -1
  34. package/src/scripts/commands/start-upsert-pr-command.js +4 -4
  35. package/src/scripts/commands/start-upsert-pr-command.js.map +1 -1
  36. package/src/scripts/commands/sync-main-command.js +2 -2
  37. package/src/scripts/commands/sync-main-command.js.map +1 -1
  38. package/src/scripts/commands/upsert-hotfix-pr-command.d.ts +6 -4
  39. package/src/scripts/commands/upsert-hotfix-pr-command.js +46 -43
  40. package/src/scripts/commands/upsert-hotfix-pr-command.js.map +1 -1
  41. package/src/scripts/commands/working-tree-gate.d.ts +4 -1
  42. package/src/scripts/commands/working-tree-gate.js +14 -11
  43. package/src/scripts/commands/working-tree-gate.js.map +1 -1
  44. package/src/scripts/commands/write-review-command.js +4 -6
  45. package/src/scripts/commands/write-review-command.js.map +1 -1
  46. package/src/scripts/commands/write-review-fixes-command.js +3 -4
  47. package/src/scripts/commands/write-review-fixes-command.js.map +1 -1
  48. package/src/scripts/git-finishUpsertPr.js +2 -2
  49. package/src/scripts/git-finishUpsertPr.js.map +1 -1
  50. package/src/scripts/git-gatherInfo.js +6 -7
  51. package/src/scripts/git-gatherInfo.js.map +1 -1
  52. package/src/scripts/pr-gate-container.d.ts +9 -0
  53. package/src/scripts/pr-gate-container.js +19 -0
  54. package/src/scripts/pr-gate-container.js.map +1 -0
  55. package/src/scripts/workflow/await-loop.d.ts +1 -1
  56. package/src/scripts/workflow/await-loop.js +1 -1
  57. package/src/scripts/workflow/await-loop.js.map +1 -1
  58. package/src/scripts/workflow/build-affected.js +1 -1
  59. package/src/scripts/workflow/build-affected.js.map +1 -1
  60. package/src/scripts/workflow/build-artifact-gate.d.ts +1 -1
  61. package/src/scripts/workflow/build-artifact-gate.js +3 -3
  62. package/src/scripts/workflow/build-artifact-gate.js.map +1 -1
  63. package/src/scripts/workflow/build-gate-log.d.ts +9 -6
  64. package/src/scripts/workflow/build-gate-log.js +34 -40
  65. package/src/scripts/workflow/build-gate-log.js.map +1 -1
  66. package/src/scripts/workflow/checklist-scanner.d.ts +1 -1
  67. package/src/scripts/workflow/checklist-scanner.js +8 -8
  68. package/src/scripts/workflow/checklist-scanner.js.map +1 -1
  69. package/src/scripts/workflow/checklist-scope-hasher.d.ts +1 -1
  70. package/src/scripts/workflow/checklist-scope-hasher.js +2 -2
  71. package/src/scripts/workflow/checklist-scope-hasher.js.map +1 -1
  72. package/src/scripts/workflow/dev-deploy-refs.d.ts +5 -5
  73. package/src/scripts/workflow/dev-deploy-refs.js +8 -8
  74. package/src/scripts/workflow/dev-deploy-refs.js.map +1 -1
  75. package/src/scripts/workflow/dev-resolve-runner.d.ts +3 -3
  76. package/src/scripts/workflow/dev-resolve-runner.js +30 -30
  77. package/src/scripts/workflow/dev-resolve-runner.js.map +1 -1
  78. package/src/scripts/workflow/diff-basis.d.ts +4 -2
  79. package/src/scripts/workflow/diff-basis.js +18 -15
  80. package/src/scripts/workflow/diff-basis.js.map +1 -1
  81. package/src/scripts/workflow/diff-materializer.d.ts +5 -3
  82. package/src/scripts/workflow/diff-materializer.js +18 -15
  83. package/src/scripts/workflow/diff-materializer.js.map +1 -1
  84. package/src/scripts/workflow/gated-pr-publisher.d.ts +8 -6
  85. package/src/scripts/workflow/gated-pr-publisher.js +23 -22
  86. package/src/scripts/workflow/gated-pr-publisher.js.map +1 -1
  87. package/src/scripts/workflow/generated-artifact-registry.d.ts +4 -2
  88. package/src/scripts/workflow/generated-artifact-registry.js +11 -8
  89. package/src/scripts/workflow/generated-artifact-registry.js.map +1 -1
  90. package/src/scripts/workflow/git-exec.d.ts +22 -12
  91. package/src/scripts/workflow/git-exec.js +45 -29
  92. package/src/scripts/workflow/git-exec.js.map +1 -1
  93. package/src/scripts/workflow/git-findForkPoint.d.ts +6 -2
  94. package/src/scripts/workflow/git-findForkPoint.js +31 -23
  95. package/src/scripts/workflow/git-findForkPoint.js.map +1 -1
  96. package/src/scripts/workflow/git-readAiBranchName.d.ts +4 -2
  97. package/src/scripts/workflow/git-readAiBranchName.js +8 -5
  98. package/src/scripts/workflow/git-readAiBranchName.js.map +1 -1
  99. package/src/scripts/workflow/hotfix-pr-publisher.d.ts +4 -3
  100. package/src/scripts/workflow/hotfix-pr-publisher.js +7 -6
  101. package/src/scripts/workflow/hotfix-pr-publisher.js.map +1 -1
  102. package/src/scripts/workflow/landed-tree-resolver.d.ts +4 -2
  103. package/src/scripts/workflow/landed-tree-resolver.js +11 -8
  104. package/src/scripts/workflow/landed-tree-resolver.js.map +1 -1
  105. package/src/scripts/workflow/landed-worktree-reaper.d.ts +4 -2
  106. package/src/scripts/workflow/landed-worktree-reaper.js +12 -9
  107. package/src/scripts/workflow/landed-worktree-reaper.js.map +1 -1
  108. package/src/scripts/workflow/merge-end.d.ts +2 -2
  109. package/src/scripts/workflow/merge-end.js +22 -24
  110. package/src/scripts/workflow/merge-end.js.map +1 -1
  111. package/src/scripts/workflow/merge-start.d.ts +5 -1
  112. package/src/scripts/workflow/merge-start.js +56 -49
  113. package/src/scripts/workflow/merge-start.js.map +1 -1
  114. package/src/scripts/workflow/open-pr-check.d.ts +4 -2
  115. package/src/scripts/workflow/open-pr-check.js +11 -8
  116. package/src/scripts/workflow/open-pr-check.js.map +1 -1
  117. package/src/scripts/workflow/pr-comment-upserter.d.ts +5 -3
  118. package/src/scripts/workflow/pr-comment-upserter.js +15 -14
  119. package/src/scripts/workflow/pr-comment-upserter.js.map +1 -1
  120. package/src/scripts/workflow/pr-merger.d.ts +8 -5
  121. package/src/scripts/workflow/pr-merger.js +32 -27
  122. package/src/scripts/workflow/pr-merger.js.map +1 -1
  123. package/src/scripts/workflow/provenance-enforcer.d.ts +4 -2
  124. package/src/scripts/workflow/provenance-enforcer.js +19 -17
  125. package/src/scripts/workflow/provenance-enforcer.js.map +1 -1
  126. package/src/scripts/workflow/review-round-state.d.ts +7 -6
  127. package/src/scripts/workflow/review-round-state.js +33 -38
  128. package/src/scripts/workflow/review-round-state.js.map +1 -1
  129. package/src/scripts/workflow/run-update.js +1 -1
  130. package/src/scripts/workflow/run-update.js.map +1 -1
  131. package/src/scripts/workflow/squash-settings-enforcer.d.ts +6 -3
  132. package/src/scripts/workflow/squash-settings-enforcer.js +19 -14
  133. package/src/scripts/workflow/squash-settings-enforcer.js.map +1 -1
  134. package/src/scripts/wp-await-checks.js +2 -2
  135. package/src/scripts/wp-await-checks.js.map +1 -1
  136. package/src/scripts/wp-await-reviews.js +2 -2
  137. package/src/scripts/wp-await-reviews.js.map +1 -1
  138. package/src/scripts/wp-build.js +2 -2
  139. package/src/scripts/wp-build.js.map +1 -1
  140. package/src/scripts/wp-check-pr.js +2 -2
  141. package/src/scripts/wp-check-pr.js.map +1 -1
  142. package/src/scripts/wp-cleanup.js +2 -2
  143. package/src/scripts/wp-cleanup.js.map +1 -1
  144. package/src/scripts/wp-finish-push-dev.js +2 -2
  145. package/src/scripts/wp-finish-push-dev.js.map +1 -1
  146. package/src/scripts/wp-finish-update.js +2 -2
  147. package/src/scripts/wp-finish-update.js.map +1 -1
  148. package/src/scripts/wp-human-post-pr.js +2 -2
  149. package/src/scripts/wp-human-post-pr.js.map +1 -1
  150. package/src/scripts/wp-land-pr.js +2 -2
  151. package/src/scripts/wp-land-pr.js.map +1 -1
  152. package/src/scripts/wp-push-dev.js +2 -2
  153. package/src/scripts/wp-push-dev.js.map +1 -1
  154. package/src/scripts/wp-reap-worktree.js +2 -2
  155. package/src/scripts/wp-reap-worktree.js.map +1 -1
  156. package/src/scripts/wp-review-upsert-pr.js +2 -2
  157. package/src/scripts/wp-review-upsert-pr.js.map +1 -1
  158. package/src/scripts/wp-start-update.js +2 -2
  159. package/src/scripts/wp-start-update.js.map +1 -1
  160. package/src/scripts/wp-start-upsert-pr.js +2 -2
  161. package/src/scripts/wp-start-upsert-pr.js.map +1 -1
  162. package/src/scripts/wp-sync-main.js +2 -2
  163. package/src/scripts/wp-sync-main.js.map +1 -1
  164. package/src/scripts/wp-upsert-hotfix-pr.js +2 -2
  165. package/src/scripts/wp-upsert-hotfix-pr.js.map +1 -1
  166. package/src/scripts/wp-write-review-fixes.js +2 -2
  167. package/src/scripts/wp-write-review-fixes.js.map +1 -1
  168. package/src/scripts/wp-write-review.js +2 -2
  169. package/src/scripts/wp-write-review.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"dev-deploy-refs.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/dev-deploy-refs.ts"],"names":[],"mappings":";;;;AAAA,0DAAsG;AACtG,yCAA2D;AAC3D,8DAAwD;AAExD,yCAAqC;AAErC,MAAM,GAAG,GAAG,0DAA0D,CAAC;AACvE,MAAM,IAAI,GAAG,MAAM,CAAC;AACpB,MAAM,QAAQ,GAAG,MAAM,CAAC;AAExB;;;;GAIG;AACH,MAAa,OAAO;IAChB,iFAAiF;IACjF,GAAG,CAAS;IACZ,GAAG,CAAS;IACZ,uFAAuF;IACvF,YAAY,CAAS;IAErB,YAAY,GAAW,EAAE,GAAW,EAAE,YAAoB;QACtD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACrC,CAAC;CACJ;AAZD,0BAYC;AAED;;;;;;;;;;GAUG;AAEI,IAAM,aAAa,GAAnB,MAAM,aAAa;IACO;IAA7B,YAA6B,OAAgB;QAAhB,YAAO,GAAP,OAAO,CAAS;IAAG,CAAC;IAEjD,6FAA6F;IAC7F,MAAM,CAAC,QAAgB;QACnB,OAAO,IAAA,8BAAe,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC;IACtD,CAAC;IAED,0GAA0G;IAC1G,aAAa,CAAC,QAAgB;QAC1B,OAAO,4BAAW,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC/C,CAAC;IAED;;;;;;;;;;OAUG;IACH,cAAc,CAAC,GAAoB,EAAE,MAAc;QAC/C,IAAI,M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yC,GAAG,0BAA0B,CAAC,CAAC;QAC5E,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1B,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/C,CAAC;IAEO,OAAO,CAAC,QAAgB,EAAE,IAAY;QAC1C,OAAO,IAAI,GAAG,GAAG,GAAG,KAAK,QAAQ,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,GAAG,WAAW,0BAAW,mCAAmC,CAAC;IAC1H,CAAC;CACJ,CAAA;AA1HY,sCAAa;wBAAb,aAAa;IADzB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEC,kBAAO;GADpC,aAAa,CA0HzB","sourcesContent":["import { CliExitError, DevDeployConfig, loadAndValidate, WP_PUSH_DEV } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { gitCheckout } from '@webpieces/tooling-common';\n\nimport { GitExec } from './git-exec';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\nconst MAIN = 'main';\nconst DETACHED = 'HEAD';\n\n/**\n * One live copy in the dev namespace: the remote ref and the sha it points at. Data-only per CLAUDE.md —\n * `--list` prints it and the clobber guard compares against `sha`, and neither should be re-parsing\n * `ls-remote` output.\n */\nexport class DevCopy {\n /** The full ref name WITHOUT `refs/heads/`, e.g. `dev-include/dean/ONE-2275`. */\n ref: string;\n sha: string;\n /** The feature branch this is a copy OF — `ref` with the namespace prefix stripped. */\n sourceBranch: string;\n\n constructor(ref: string, sha: string, sourceBranch: string) {\n this.ref = ref;\n this.sha = sha;\n this.sourceBranch = sourceBranch;\n }\n}\n\n/**\n * Ref derivation and preconditions for the dev-deploy flow — the half of `wp-push-dev` that decides WHICH\n * refs are in play, kept out of the commands so both `wp-push-dev` and `wp-finish-push-dev` answer those\n * questions identically.\n *\n * THE INVARIANT THIS FILE EXISTS TO PROTECT: the feature branch is the PR head, so it must never acquire\n * another developer's commits — landing that PR would ship their unreviewed work to production. Every\n * write this flow performs therefore targets either the `<namespace>/<feature>` copy or a local throwaway\n * branch, and NOTHING here ever moves `<feature>` itself. That is why a conflict resolution needs the copy\n * to live in: it is the only place the resolution can be recorded without contaminating the PR.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class DevDeployRefs {\n constructor(private readonly gitExec: GitExec) {}\n\n /** The `pr-gate.devDeploy` block — `dev-include` / `dev` unless the consumer overrode it. */\n config(repoRoot: string): DevDeployConfig {\n return loadAndValidate(repoRoot).prGate.devDeploy;\n }\n\n /** The checked-out branch name, or `'HEAD'` on a detached HEAD (which {@link assertPushable} refuses). */\n currentBranch(repoRoot: string): string {\n return gitCheckout.requireBranch(repoRoot);\n }\n\n /**\n * Refuse every branch that must never be the SOURCE of a dev copy, before anything is fetched or\n * pushed.\n *\n * `main` and the composed dev branch are refused for the same reason from opposite ends: `main` is the\n * trunk (whatever is on it already deploys, so copying it is meaningless), and the dev branch is a\n * BUILD ARTIFACT that CI recomputes from `origin/main` on every run — copying it would publish a\n * composition of everyone's work under one developer's name, and it would be wiped on the next CI run\n * anyway. A branch already inside the namespace is refused because publishing a copy of a copy nests\n * the prefix (`dev-include/dev-include/…`) and nothing would ever clean it up.\n */\n assertPushable(cfg: DevDeployConfig, branch: string): void {\n if (branch === DETACHED || branch === '') {\n throw new CliExitError(2, this.refusal(\n 'Detached HEAD',\n 'There is no branch name to derive the dev copy from. Check out your feature branch first:\\n'\n + ' git checkout <your-feature-branch>\\n'));\n }\n if (branch === MAIN) {\n throw new CliExitError(2, this.refusal(\n `Refusing to publish a dev copy of \\`${MAIN}\\``,\n `\\`${MAIN}\\` is the trunk — whatever is on it already deploys, so a dev copy of it means nothing.\\n`\n + 'Check out the feature branch you actually want on the dev server and re-run.\\n'));\n }\n if (branch === cfg.devBranch) {\n throw new CliExitError(2, this.refusal(\n `Refusing to publish a dev copy of \\`${cfg.devBranch}\\``,\n `\\`${cfg.devBranch}\\` is a BUILD ARTIFACT, not a source branch: your CI resets it to origin/${MAIN},\\n`\n + `merges every \\`${cfg.copyRefGlob()}\\` ref into it, and force-pushes — every run. Copying it would\\n`\n + \"publish a composition of everybody's work under your branch's name, and the next CI run would\\n\"\n + 'wipe it. Check out your own feature branch and re-run.\\n'));\n }\n if (branch === cfg.branchNamespace || branch.startsWith(`${cfg.branchNamespace}/`)) {\n throw new CliExitError(2, this.refusal(\n `Refusing to publish a dev copy of a dev copy (\\`${branch}\\`)`,\n `\\`${cfg.branchNamespace}/\\` holds the disposable copies this command WRITES; you are standing on one.\\n`\n + `Publishing from here would nest the prefix (\\`${cfg.branchNamespace}/${branch}\\`) and nothing ever\\n`\n + 'cleans that up. Check out the real feature branch and re-run.\\n'));\n }\n }\n\n /**\n * Every live copy in the namespace, sorted by ref name.\n *\n * The sort is not cosmetic: `--resolve` with no argument queues these in exactly this order, and the\n * consumer's CI composes `dev` in the same order, so what a developer resolves locally is the\n * composition CI will actually build. A different order can produce a different (still valid) merge\n * result, which would make the local resolution a guess about CI rather than a rehearsal of it.\n */\n liveCopies(repoRoot: string, cfg: DevDeployConfig): DevCopy[] {\n const out = this.gitExec.gitQuery(['ls-remote', '--heads', 'origin', cfg.copyRefGlob()], repoRoot,\n `Failed to list the dev copies (git ls-remote --heads origin '${cfg.copyRefGlob()}').`);\n const copies: DevCopy[] = [];\n for (const line of out.split('\\n')) {\n if (line.trim() === '') continue;\n const fields = line.split(/\\s+/);\n const sha = fields[0];\n const ref = fields[1];\n if (sha === undefined || ref === undefined || !ref.startsWith('refs/heads/')) continue;\n const shortRef = ref.slice('refs/heads/'.length);\n copies.push(new DevCopy(shortRef, sha, shortRef.slice(cfg.branchNamespace.length + 1)));\n }\n return copies.sort((a: DevCopy, b: DevCopy): number => (a.ref < b.ref ? -1 : a.ref > b.ref ? 1 : 0));\n }\n\n /**\n * The sha of a local ref (default HEAD).\n *\n * Read AFTER a push so the watch hints quote the sha that is provably published. Quoting the copy\n * REF instead would be a moving target — it advances the next time anybody publishes — and the whole\n * value of the \"did my code land in dev\" check is that it is a claim about one specific commit.\n */\n headSha(repoRoot: string, ref = 'HEAD'): string {\n return this.gitExec.gitQuery(['-C', repoRoot, 'rev-parse', ref], repoRoot,\n `Failed to read the sha of ${ref} (git rev-parse).`);\n }\n\n /** The remote sha of one copy, or '' when that copy does not exist yet. */\n remoteSha(repoRoot: string, ref: string): string {\n const out = this.gitExec.gitQuery(['ls-remote', '--heads', 'origin', ref], repoRoot,\n `Failed to look up origin/${ref} (git ls-remote).`);\n const line = out.split('\\n').find((l: string): boolean => l.trim() !== '');\n if (line === undefined) return '';\n return line.split(/\\s+/)[0] ?? '';\n }\n\n /**\n * Fetch the named copy refs into `refs/remotes/origin/<ref>` so the local merges below run against\n * fresh state. A no-op for an empty list, and a hard failure otherwise: a resolve queued against\n * stale refs rehearses a composition CI will not build.\n */\n fetchCopies(repoRoot: string, refs: string[]): void {\n if (refs.length === 0) return;\n const specs = refs.map((r: string): string => `+refs/heads/${r}:refs/remotes/origin/${r}`);\n this.gitExec.runGitChecked(['-C', repoRoot, 'fetch', 'origin', ...specs],\n 'Failed to fetch the dev copy refs from origin');\n }\n\n /** How many commits `origin/<ref>` has that `HEAD` does not — the clobber signal. 0 = safe to publish. */\n commitsOnlyOnRemote(repoRoot: string, ref: string): number {\n const out = this.gitExec.gitQuery(['rev-list', '--count', `HEAD..refs/remotes/origin/${ref}`], repoRoot,\n `Failed to compare HEAD against origin/${ref} (git rev-list --count).`);\n const count = Number(out);\n return Number.isInteger(count) ? count : 0;\n }\n\n private refusal(headline: string, body: string): string {\n return '\\n' + SEP + `⛔ ${headline}\\n` + SEP + '\\n' + body + `\\nRun \\`${WP_PUSH_DEV} --help\\` for the full command.\\n`;\n }\n}\n"]}
1
+ {"version":3,"file":"dev-deploy-refs.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/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C,CAAC;IAEO,OAAO,CAAC,QAAgB,EAAE,IAAY;QAC1C,OAAO,IAAI,GAAG,GAAG,GAAG,KAAK,QAAQ,IAAI,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,GAAG,WAAW,0BAAW,mCAAmC,CAAC;IAC1H,CAAC;CACJ,CAAA;AA1HY,sCAAa;wBAAb,aAAa;IADzB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEC,kBAAO;GADpC,aAAa,CA0HzB","sourcesContent":["import { CliExitError, DevDeployConfig, loadAndValidate, WP_PUSH_DEV } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { gitCheckout } from '@webpieces/tooling-common';\n\nimport { GitExec } from './git-exec';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\nconst MAIN = 'main';\nconst DETACHED = 'HEAD';\n\n/**\n * One live copy in the dev namespace: the remote ref and the sha it points at. Data-only per CLAUDE.md —\n * `--list` prints it and the clobber guard compares against `sha`, and neither should be re-parsing\n * `ls-remote` output.\n */\nexport class DevCopy {\n /** The full ref name WITHOUT `refs/heads/`, e.g. `dev-include/dean/ONE-2275`. */\n ref: string;\n sha: string;\n /** The feature branch this is a copy OF — `ref` with the namespace prefix stripped. */\n sourceBranch: string;\n\n constructor(ref: string, sha: string, sourceBranch: string) {\n this.ref = ref;\n this.sha = sha;\n this.sourceBranch = sourceBranch;\n }\n}\n\n/**\n * Ref derivation and preconditions for the dev-deploy flow — the half of `wp-push-dev` that decides WHICH\n * refs are in play, kept out of the commands so both `wp-push-dev` and `wp-finish-push-dev` answer those\n * questions identically.\n *\n * THE INVARIANT THIS FILE EXISTS TO PROTECT: the feature branch is the PR head, so it must never acquire\n * another developer's commits — landing that PR would ship their unreviewed work to production. Every\n * write this flow performs therefore targets either the `<namespace>/<feature>` copy or a local throwaway\n * branch, and NOTHING here ever moves `<feature>` itself. That is why a conflict resolution needs the copy\n * to live in: it is the only place the resolution can be recorded without contaminating the PR.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class DevDeployRefs {\n constructor(private readonly gitExec: GitExec) {}\n\n /** The `pr-gate.devDeploy` block — `dev-include` / `dev` unless the consumer overrode it. */\n config(repoRoot: string): DevDeployConfig {\n return loadAndValidate(repoRoot).prGate.devDeploy;\n }\n\n /** The checked-out branch name, or `'HEAD'` on a detached HEAD (which {@link assertPushable} refuses). */\n currentBranch(repoRoot: string): string {\n return gitCheckout.requireBranch(repoRoot);\n }\n\n /**\n * Refuse every branch that must never be the SOURCE of a dev copy, before anything is fetched or\n * pushed.\n *\n * `main` and the composed dev branch are refused for the same reason from opposite ends: `main` is the\n * trunk (whatever is on it already deploys, so copying it is meaningless), and the dev branch is a\n * BUILD ARTIFACT that CI recomputes from `origin/main` on every run — copying it would publish a\n * composition of everyone's work under one developer's name, and it would be wiped on the next CI run\n * anyway. A branch already inside the namespace is refused because publishing a copy of a copy nests\n * the prefix (`dev-include/dev-include/…`) and nothing would ever clean it up.\n */\n assertPushable(cfg: DevDeployConfig, branch: string): void {\n if (branch === DETACHED || branch === '') {\n throw new CliExitError(2, this.refusal(\n 'Detached HEAD',\n 'There is no branch name to derive the dev copy from. Check out your feature branch first:\\n'\n + ' git checkout <your-feature-branch>\\n'));\n }\n if (branch === MAIN) {\n throw new CliExitError(2, this.refusal(\n `Refusing to publish a dev copy of \\`${MAIN}\\``,\n `\\`${MAIN}\\` is the trunk — whatever is on it already deploys, so a dev copy of it means nothing.\\n`\n + 'Check out the feature branch you actually want on the dev server and re-run.\\n'));\n }\n if (branch === cfg.devBranch) {\n throw new CliExitError(2, this.refusal(\n `Refusing to publish a dev copy of \\`${cfg.devBranch}\\``,\n `\\`${cfg.devBranch}\\` is a BUILD ARTIFACT, not a source branch: your CI resets it to origin/${MAIN},\\n`\n + `merges every \\`${cfg.copyRefGlob()}\\` ref into it, and force-pushes — every run. Copying it would\\n`\n + \"publish a composition of everybody's work under your branch's name, and the next CI run would\\n\"\n + 'wipe it. Check out your own feature branch and re-run.\\n'));\n }\n if (branch === cfg.branchNamespace || branch.startsWith(`${cfg.branchNamespace}/`)) {\n throw new CliExitError(2, this.refusal(\n `Refusing to publish a dev copy of a dev copy (\\`${branch}\\`)`,\n `\\`${cfg.branchNamespace}/\\` holds the disposable copies this command WRITES; you are standing on one.\\n`\n + `Publishing from here would nest the prefix (\\`${cfg.branchNamespace}/${branch}\\`) and nothing ever\\n`\n + 'cleans that up. Check out the real feature branch and re-run.\\n'));\n }\n }\n\n /**\n * Every live copy in the namespace, sorted by ref name.\n *\n * The sort is not cosmetic: `--resolve` with no argument queues these in exactly this order, and the\n * consumer's CI composes `dev` in the same order, so what a developer resolves locally is the\n * composition CI will actually build. A different order can produce a different (still valid) merge\n * result, which would make the local resolution a guess about CI rather than a rehearsal of it.\n */\n async liveCopies(repoRoot: string, cfg: DevDeployConfig): Promise<DevCopy[]> {\n const out = await this.gitExec.gitQuery(['ls-remote', '--heads', 'origin', cfg.copyRefGlob()], repoRoot,\n `Failed to list the dev copies (git ls-remote --heads origin '${cfg.copyRefGlob()}').`);\n const copies: DevCopy[] = [];\n for (const line of out.split('\\n')) {\n if (line.trim() === '') continue;\n const fields = line.split(/\\s+/);\n const sha = fields[0];\n const ref = fields[1];\n if (sha === undefined || ref === undefined || !ref.startsWith('refs/heads/')) continue;\n const shortRef = ref.slice('refs/heads/'.length);\n copies.push(new DevCopy(shortRef, sha, shortRef.slice(cfg.branchNamespace.length + 1)));\n }\n return copies.sort((a: DevCopy, b: DevCopy): number => (a.ref < b.ref ? -1 : a.ref > b.ref ? 1 : 0));\n }\n\n /**\n * The sha of a local ref (default HEAD).\n *\n * Read AFTER a push so the watch hints quote the sha that is provably published. Quoting the copy\n * REF instead would be a moving target — it advances the next time anybody publishes — and the whole\n * value of the \"did my code land in dev\" check is that it is a claim about one specific commit.\n */\n headSha(repoRoot: string, ref = 'HEAD'): Promise<string> {\n return this.gitExec.gitQuery(['-C', repoRoot, 'rev-parse', ref], repoRoot,\n `Failed to read the sha of ${ref} (git rev-parse).`);\n }\n\n /** The remote sha of one copy, or '' when that copy does not exist yet. */\n async remoteSha(repoRoot: string, ref: string): Promise<string> {\n const out = await this.gitExec.gitQuery(['ls-remote', '--heads', 'origin', ref], repoRoot,\n `Failed to look up origin/${ref} (git ls-remote).`);\n const line = out.split('\\n').find((l: string): boolean => l.trim() !== '');\n if (line === undefined) return '';\n return line.split(/\\s+/)[0] ?? '';\n }\n\n /**\n * Fetch the named copy refs into `refs/remotes/origin/<ref>` so the local merges below run against\n * fresh state. A no-op for an empty list, and a hard failure otherwise: a resolve queued against\n * stale refs rehearses a composition CI will not build.\n */\n async fetchCopies(repoRoot: string, refs: string[]): Promise<void> {\n if (refs.length === 0) return;\n const specs = refs.map((r: string): string => `+refs/heads/${r}:refs/remotes/origin/${r}`);\n await this.gitExec.runGitChecked(['-C', repoRoot, 'fetch', 'origin', ...specs],\n 'Failed to fetch the dev copy refs from origin');\n }\n\n /** How many commits `origin/<ref>` has that `HEAD` does not — the clobber signal. 0 = safe to publish. */\n async commitsOnlyOnRemote(repoRoot: string, ref: string): Promise<number> {\n const out = await this.gitExec.gitQuery(['rev-list', '--count', `HEAD..refs/remotes/origin/${ref}`], repoRoot,\n `Failed to compare HEAD against origin/${ref} (git rev-list --count).`);\n const count = Number(out);\n return Number.isInteger(count) ? count : 0;\n }\n\n private refusal(headline: string, body: string): string {\n return '\\n' + SEP + `⛔ ${headline}\\n` + SEP + '\\n' + body + `\\nRun \\`${WP_PUSH_DEV} --help\\` for the full command.\\n`;\n }\n}\n"]}
@@ -34,7 +34,7 @@ export declare class DevResolveRunner {
34
34
  * `fetchRefs` is passed separately from the queue because `--rebase-resolution` merges a ref that is
35
35
  * also its push destination, so "everything to fetch" and "everything to merge" are not the same list.
36
36
  */
37
- start(repoRoot: string, state: PushDevState, base: string, fetchRefs: string[]): void;
37
+ start(repoRoot: string, state: PushDevState, base: string, fetchRefs: string[]): Promise<void>;
38
38
  /**
39
39
  * Resume after the human/AI has resolved the halted merge: commit it, then keep draining.
40
40
  *
@@ -42,12 +42,12 @@ export declare class DevResolveRunner {
42
42
  * fetched an hour ago rehearses a composition CI will not build — the one freshness gap the sibling
43
43
  * update flow is still known to have (only its stage ① ever fetches).
44
44
  */
45
- resume(repoRoot: string, state: PushDevState): void;
45
+ resume(repoRoot: string, state: PushDevState): Promise<void>;
46
46
  /**
47
47
  * Throw the whole resolve away: undo any halted merge, go back to the original branch, delete the
48
48
  * throwaway branch and the state file. Nothing published, nothing on the feature branch.
49
49
  */
50
- abort(repoRoot: string, state: PushDevState): void;
50
+ abort(repoRoot: string, state: PushDevState): Promise<void>;
51
51
  /**
52
52
  * Merge queued refs until one conflicts (HALT, hand the tree over) or the queue empties (PUBLISH).
53
53
  *
@@ -45,11 +45,11 @@ let DevResolveRunner = class DevResolveRunner {
45
45
  * `fetchRefs` is passed separately from the queue because `--rebase-resolution` merges a ref that is
46
46
  * also its push destination, so "everything to fetch" and "everything to merge" are not the same list.
47
47
  */
48
- start(repoRoot, state, base, fetchRefs) {
49
- this.refs.fetchCopies(repoRoot, fetchRefs);
48
+ async start(repoRoot, state, base, fetchRefs) {
49
+ await this.refs.fetchCopies(repoRoot, fetchRefs);
50
50
  this.store.write(repoRoot, state);
51
- this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', '-B', state.tmpBranch, base], `Failed to create the throwaway resolve branch ${state.tmpBranch}`);
52
- this.drain(repoRoot, state);
51
+ await this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', '-B', state.tmpBranch, base], `Failed to create the throwaway resolve branch ${state.tmpBranch}`);
52
+ await this.drain(repoRoot, state);
53
53
  }
54
54
  /**
55
55
  * Resume after the human/AI has resolved the halted merge: commit it, then keep draining.
@@ -58,26 +58,26 @@ let DevResolveRunner = class DevResolveRunner {
58
58
  * fetched an hour ago rehearses a composition CI will not build — the one freshness gap the sibling
59
59
  * update flow is still known to have (only its stage ① ever fetches).
60
60
  */
61
- resume(repoRoot, state) {
62
- this.assertNoUnmergedPaths(repoRoot, state);
63
- this.gitExec.assertNoUntracked(repoRoot);
64
- this.gitExec.runGitChecked(['-C', repoRoot, 'add', '-u'], 'Failed to stage the resolved files (git add -u)');
65
- this.gitExec.runGitChecked(['-C', repoRoot, 'commit', '--no-edit'], `Failed to commit the resolution of ${state.current}`);
61
+ async resume(repoRoot, state) {
62
+ await this.assertNoUnmergedPaths(repoRoot, state);
63
+ await this.gitExec.assertNoUntracked(repoRoot);
64
+ await this.gitExec.runGitChecked(['-C', repoRoot, 'add', '-u'], 'Failed to stage the resolved files (git add -u)');
65
+ await this.gitExec.runGitChecked(['-C', repoRoot, 'commit', '--no-edit'], `Failed to commit the resolution of ${state.current}`);
66
66
  process.stdout.write(`✅ Committed the resolution of ${state.current}.\n`);
67
67
  state.current = '';
68
- this.refs.fetchCopies(repoRoot, state.queue);
69
- this.drain(repoRoot, state);
68
+ await this.refs.fetchCopies(repoRoot, state.queue);
69
+ await this.drain(repoRoot, state);
70
70
  }
71
71
  /**
72
72
  * Throw the whole resolve away: undo any halted merge, go back to the original branch, delete the
73
73
  * throwaway branch and the state file. Nothing published, nothing on the feature branch.
74
74
  */
75
- abort(repoRoot, state) {
75
+ async abort(repoRoot, state) {
76
76
  // Allowed to fail: there is no merge to abort when the resolve halted between merges, and that is
77
77
  // not an error condition — the rest of the teardown must still run.
78
- this.gitExec.tryGit(['-C', repoRoot, 'merge', '--abort'], repoRoot);
79
- this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', state.originalBranch], `Failed to return to ${state.originalBranch}`);
80
- this.gitExec.tryGit(['-C', repoRoot, 'branch', '-D', state.tmpBranch], repoRoot);
78
+ await this.gitExec.tryGit(['-C', repoRoot, 'merge', '--abort'], repoRoot);
79
+ await this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', state.originalBranch], `Failed to return to ${state.originalBranch}`);
80
+ await this.gitExec.tryGit(['-C', repoRoot, 'branch', '-D', state.tmpBranch], repoRoot);
81
81
  this.store.clear(repoRoot);
82
82
  process.stdout.write('\n' + SEP + '🛑 Dev-deploy resolve aborted\n' + SEP + '\n'
83
83
  + `You are back on \`${state.originalBranch}\`; \`${state.tmpBranch}\` and the state file are gone.\n`
@@ -89,11 +89,11 @@ let DevResolveRunner = class DevResolveRunner {
89
89
  * A LATER ref can conflict too, which is why this is a loop resumed from a state file rather than a
90
90
  * single pass: `wp-finish-push-dev` can legitimately stop again on the next ref in the queue.
91
91
  */
92
- drain(repoRoot, state) {
92
+ async drain(repoRoot, state) {
93
93
  while (state.queue.length > 0) {
94
94
  const ref = state.queue[0];
95
95
  state.queue = state.queue.slice(1);
96
- const outcome = this.gitExec.tryGit(['-C', repoRoot, 'merge', '--no-ff', '--no-edit', '-m',
96
+ const outcome = await this.gitExec.tryGit(['-C', repoRoot, 'merge', '--no-ff', '--no-edit', '-m',
97
97
  `Dev-deploy: merge ${ref} into ${state.targetRef}`, `refs/remotes/origin/${ref}`], repoRoot);
98
98
  if (outcome.ok) {
99
99
  process.stdout.write(` ✓ merged ${ref}\n`);
@@ -101,14 +101,14 @@ let DevResolveRunner = class DevResolveRunner {
101
101
  }
102
102
  state.current = ref;
103
103
  this.store.write(repoRoot, state);
104
- this.halt(repoRoot, state);
104
+ await this.halt(repoRoot, state);
105
105
  return;
106
106
  }
107
- this.publish(repoRoot, state);
107
+ await this.publish(repoRoot, state);
108
108
  }
109
109
  /** Stop with the conflicted files listed and the ONE command that continues. Exit 2 = "your turn". */
110
- halt(repoRoot, state) {
111
- const conflicted = this.unmergedPaths(repoRoot);
110
+ async halt(repoRoot, state) {
111
+ const conflicted = await this.unmergedPaths(repoRoot);
112
112
  const remaining = state.queue.length > 0
113
113
  ? `\nStill queued after this one: ${state.queue.join(', ')}\n`
114
114
  + `\`${rules_config_1.WP_FINISH_PUSH_DEV}\` resumes the queue, so it may stop again on a later ref.\n`
@@ -126,13 +126,13 @@ let DevResolveRunner = class DevResolveRunner {
126
126
  + 'the finish command above does all three for you.\n');
127
127
  }
128
128
  /** Queue empty: force-push the composed result over the copy, then restore the original checkout. */
129
- publish(repoRoot, state) {
130
- this.gitExec.runGitChecked(['-C', repoRoot, 'push', '--force', 'origin', `${state.tmpBranch}:refs/heads/${state.targetRef}`], `Failed to publish the dev copy ${state.targetRef}`);
129
+ async publish(repoRoot, state) {
130
+ await this.gitExec.runGitChecked(['-C', repoRoot, 'push', '--force', 'origin', `${state.tmpBranch}:refs/heads/${state.targetRef}`], `Failed to publish the dev copy ${state.targetRef}`);
131
131
  // Captured BEFORE the tmp branch is deleted — it is the composed sha the watch hints are about,
132
132
  // and after the checkout below HEAD is the feature branch, which is a different commit entirely.
133
- const published = this.refs.headSha(repoRoot, state.tmpBranch);
134
- this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', state.originalBranch], `Failed to return to ${state.originalBranch}`);
135
- this.gitExec.tryGit(['-C', repoRoot, 'branch', '-D', state.tmpBranch], repoRoot);
133
+ const published = await this.refs.headSha(repoRoot, state.tmpBranch);
134
+ await this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', state.originalBranch], `Failed to return to ${state.originalBranch}`);
135
+ await this.gitExec.tryGit(['-C', repoRoot, 'branch', '-D', state.tmpBranch], repoRoot);
136
136
  this.store.clear(repoRoot);
137
137
  process.stdout.write('\n' + SEP + `✅ Published ${state.targetRef} with the resolutions\n` + SEP + '\n'
138
138
  + `You are back on \`${state.originalBranch}\`, which was never modified — verify with:\n`
@@ -141,13 +141,13 @@ let DevResolveRunner = class DevResolveRunner {
141
141
  + this.watchHints.render(this.refs.config(repoRoot), state.targetRef, published));
142
142
  }
143
143
  /** Conflicted (unmerged-in-index) paths. Empty once every one has been resolved and `git add`ed. */
144
- unmergedPaths(repoRoot) {
145
- const out = this.gitExec.gitQuery(['-C', repoRoot, 'diff', '--name-only', '--diff-filter=U'], repoRoot, 'Failed to list the conflicted files (git diff --name-only --diff-filter=U).');
144
+ async unmergedPaths(repoRoot) {
145
+ const out = await this.gitExec.gitQuery(['-C', repoRoot, 'diff', '--name-only', '--diff-filter=U'], repoRoot, 'Failed to list the conflicted files (git diff --name-only --diff-filter=U).');
146
146
  return out.split('\n').filter((l) => l.trim() !== '');
147
147
  }
148
148
  // The gate on `wp-finish-push-dev`: refuse (and re-print the list) while anything is still unmerged.
149
- assertNoUnmergedPaths(repoRoot, state) {
150
- const conflicted = this.unmergedPaths(repoRoot);
149
+ async assertNoUnmergedPaths(repoRoot, state) {
150
+ const conflicted = await this.unmergedPaths(repoRoot);
151
151
  if (conflicted.length === 0)
152
152
  return;
153
153
  throw new rules_config_1.CliExitError(2, '\n' + SEP + '⛔ Conflicts are NOT resolved yet\n' + SEP + '\n'
@@ -1 +1 @@
1
- {"version":3,"file":"dev-resolve-runner.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/dev-resolve-runner.ts"],"names":[],"mappings":";;;;AAAA,0DAA4F;AAC5F,yCAA2D;AAE3D,yCAAqC;AACrC,uDAAkD;AAClD,qDAAmE;AACnE,qEAA+D;AAE/D,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;;;;;;GASG;AAEI,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAEJ;IACA;IACA;IACA;IAJrB,YACqB,OAAgB,EAChB,IAAmB,EACnB,KAAwB,EACxB,UAA+B;QAH/B,YAAO,GAAP,OAAO,CAAS;QAChB,SAAI,GAAJ,IAAI,CAAe;QACnB,UAAK,GAAL,KAAK,CAAmB;QACxB,eAAU,GAAV,UAAU,CAAqB;IACjD,CAAC;IAEJ;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,QAAgB,EAAE,KAAmB,EAAE,IAAY,EAAE,SAAmB;QAC1E,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QAC3C,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAClC,IAAI,CAAC,O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AC3G,KAAK,KAAK,CAAC,SAAS,OAAO;cAC3B,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAS,EAAU,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,MAAM;cACpE,yBAAyB,KAAK,CAAC,cAAc,qCAAqC;cAClF,2CAA2C,iCAAkB,uCAAuC,CAAC;IAC/G,CAAC;CACJ,CAAA;AAhLY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGP,kBAAO;QACV,+BAAa;QACZ,kCAAiB;QACZ,4CAAmB;GAL3C,gBAAgB,CAgL5B","sourcesContent":["import { CliExitError, DevDeployConfig, WP_FINISH_PUSH_DEV } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { GitExec } from './git-exec';\nimport { DevDeployRefs } from './dev-deploy-refs';\nimport { PushDevState, PushDevStateStore } from './push-dev-state';\nimport { DevDeployWatchHints } from './dev-deploy-watch-hints';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * The queue-draining engine behind `wp-push-dev --resolve` and `wp-finish-push-dev`.\n *\n * ONE class owns every git WRITE in the resolve flow, and that is a hard requirement rather than tidiness:\n * `redirect-how-to-merge-main` blocks `git merge` in every form INCLUDING `--continue`, and\n * `pr-creation-or-push-guard` blocks every `git push`. So an AI cannot be told \"now run `git commit`\" or\n * \"`git merge --continue`\" — those instructions are unrunnable by the only party reading them. The command\n * owns the merges, the commit and the push (as child processes the hooks never see); the AI's entire job is\n * editing the conflicted files and `git add`-ing them, neither of which is blocked.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class DevResolveRunner {\n constructor(\n private readonly gitExec: GitExec,\n private readonly refs: DevDeployRefs,\n private readonly store: PushDevStateStore,\n private readonly watchHints: DevDeployWatchHints,\n ) {}\n\n /**\n * Start a resolve: park on a throwaway branch at the current copy, then drain the queue.\n *\n * The checkout is `-B <tmp> <base>` and NEVER the feature branch, which is the cardinal constraint made\n * mechanical — every merge below lands on a branch that is deleted at the end, so no other developer's\n * commits can reach the PR head even if the resolve is abandoned halfway.\n *\n * `base` differs between the two callers and the difference IS the semantics. `--resolve` starts at the\n * published copy and merges the other copies in (compose what CI will build). `--rebase-resolution`\n * starts at the LOCAL HEAD and merges the published copy in (replay an existing resolution on top of\n * the new commits, instead of force-pushing over it).\n *\n * `fetchRefs` is passed separately from the queue because `--rebase-resolution` merges a ref that is\n * also its push destination, so \"everything to fetch\" and \"everything to merge\" are not the same list.\n */\n start(repoRoot: string, state: PushDevState, base: string, fetchRefs: string[]): void {\n this.refs.fetchCopies(repoRoot, fetchRefs);\n this.store.write(repoRoot, state);\n this.gitExec.runGitChecked(\n ['-C', repoRoot, 'checkout', '-B', state.tmpBranch, base],\n `Failed to create the throwaway resolve branch ${state.tmpBranch}`);\n this.drain(repoRoot, state);\n }\n\n /**\n * Resume after the human/AI has resolved the halted merge: commit it, then keep draining.\n *\n * REFETCHES the remaining queue first. A resolution session can run long, and queuing against refs\n * fetched an hour ago rehearses a composition CI will not build — the one freshness gap the sibling\n * update flow is still known to have (only its stage ① ever fetches).\n */\n resume(repoRoot: string, state: PushDevState): void {\n this.assertNoUnmergedPaths(repoRoot, state);\n this.gitExec.assertNoUntracked(repoRoot);\n this.gitExec.runGitChecked(['-C', repoRoot, 'add', '-u'], 'Failed to stage the resolved files (git add -u)');\n this.gitExec.runGitChecked(['-C', repoRoot, 'commit', '--no-edit'],\n `Failed to commit the resolution of ${state.current}`);\n process.stdout.write(`✅ Committed the resolution of ${state.current}.\\n`);\n state.current = '';\n this.refs.fetchCopies(repoRoot, state.queue);\n this.drain(repoRoot, state);\n }\n\n /**\n * Throw the whole resolve away: undo any halted merge, go back to the original branch, delete the\n * throwaway branch and the state file. Nothing published, nothing on the feature branch.\n */\n abort(repoRoot: string, state: PushDevState): void {\n // Allowed to fail: there is no merge to abort when the resolve halted between merges, and that is\n // not an error condition — the rest of the teardown must still run.\n this.gitExec.tryGit(['-C', repoRoot, 'merge', '--abort'], repoRoot);\n this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', state.originalBranch],\n `Failed to return to ${state.originalBranch}`);\n this.gitExec.tryGit(['-C', repoRoot, 'branch', '-D', state.tmpBranch], repoRoot);\n this.store.clear(repoRoot);\n process.stdout.write(\n '\\n' + SEP + '🛑 Dev-deploy resolve aborted\\n' + SEP + '\\n'\n + `You are back on \\`${state.originalBranch}\\`; \\`${state.tmpBranch}\\` and the state file are gone.\\n`\n + `The remote copy \\`${state.targetRef}\\` is untouched, and so is your feature branch.\\n`);\n }\n\n /**\n * Merge queued refs until one conflicts (HALT, hand the tree over) or the queue empties (PUBLISH).\n *\n * A LATER ref can conflict too, which is why this is a loop resumed from a state file rather than a\n * single pass: `wp-finish-push-dev` can legitimately stop again on the next ref in the queue.\n */\n private drain(repoRoot: string, state: PushDevState): void {\n while (state.queue.length > 0) {\n const ref = state.queue[0];\n state.queue = state.queue.slice(1);\n const outcome = this.gitExec.tryGit(\n ['-C', repoRoot, 'merge', '--no-ff', '--no-edit', '-m',\n `Dev-deploy: merge ${ref} into ${state.targetRef}`, `refs/remotes/origin/${ref}`],\n repoRoot);\n if (outcome.ok) {\n process.stdout.write(` ✓ merged ${ref}\\n`);\n continue;\n }\n state.current = ref;\n this.store.write(repoRoot, state);\n this.halt(repoRoot, state);\n return;\n }\n this.publish(repoRoot, state);\n }\n\n /** Stop with the conflicted files listed and the ONE command that continues. Exit 2 = \"your turn\". */\n private halt(repoRoot: string, state: PushDevState): never {\n const conflicted = this.unmergedPaths(repoRoot);\n const remaining = state.queue.length > 0\n ? `\\nStill queued after this one: ${state.queue.join(', ')}\\n`\n + `\\`${WP_FINISH_PUSH_DEV}\\` resumes the queue, so it may stop again on a later ref.\\n`\n : '';\n throw new CliExitError(2,\n '\\n' + SEP + `⚠️ CONFLICT merging ${state.current}\\n` + SEP + '\\n'\n + `You are on the throwaway branch \\`${state.tmpBranch}\\` — NOT \\`${state.originalBranch}\\`. Nothing here\\n`\n + 'can reach your feature branch or your PR, which is exactly why the resolution happens over here.\\n\\n'\n + 'Resolve these files (edit until no conflict markers remain, then `git add` each one):\\n'\n + conflicted.map((f: string): string => ` ${f}`).join('\\n') + '\\n'\n + remaining\n + '\\nThen run ONE of:\\n'\n + ` ${WP_FINISH_PUSH_DEV} ← commit, resume the queue, publish the copy\\n`\n + ` ${WP_FINISH_PUSH_DEV} --abort ← throw it away and go back to \\`${state.originalBranch}\\`\\n\\n`\n + 'Do NOT run `git merge --continue`, `git commit` or `git push` yourself — they are blocked, and\\n'\n + 'the finish command above does all three for you.\\n');\n }\n\n /** Queue empty: force-push the composed result over the copy, then restore the original checkout. */\n private publish(repoRoot: string, state: PushDevState): void {\n this.gitExec.runGitChecked(\n ['-C', repoRoot, 'push', '--force', 'origin', `${state.tmpBranch}:refs/heads/${state.targetRef}`],\n `Failed to publish the dev copy ${state.targetRef}`);\n // Captured BEFORE the tmp branch is deleted — it is the composed sha the watch hints are about,\n // and after the checkout below HEAD is the feature branch, which is a different commit entirely.\n const published = this.refs.headSha(repoRoot, state.tmpBranch);\n this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', state.originalBranch],\n `Failed to return to ${state.originalBranch}`);\n this.gitExec.tryGit(['-C', repoRoot, 'branch', '-D', state.tmpBranch], repoRoot);\n this.store.clear(repoRoot);\n process.stdout.write(\n '\\n' + SEP + `✅ Published ${state.targetRef} with the resolutions\\n` + SEP + '\\n'\n + `You are back on \\`${state.originalBranch}\\`, which was never modified — verify with:\\n`\n + ` git log --oneline ${state.originalBranch}\\n`\n + 'Your CI will pick the copy up on its next composition run.\\n'\n + this.watchHints.render(this.refs.config(repoRoot), state.targetRef, published));\n }\n\n /** Conflicted (unmerged-in-index) paths. Empty once every one has been resolved and `git add`ed. */\n private unmergedPaths(repoRoot: string): string[] {\n const out = this.gitExec.gitQuery(['-C', repoRoot, 'diff', '--name-only', '--diff-filter=U'], repoRoot,\n 'Failed to list the conflicted files (git diff --name-only --diff-filter=U).');\n return out.split('\\n').filter((l: string): boolean => l.trim() !== '');\n }\n\n // The gate on `wp-finish-push-dev`: refuse (and re-print the list) while anything is still unmerged.\n private assertNoUnmergedPaths(repoRoot: string, state: PushDevState): void {\n const conflicted = this.unmergedPaths(repoRoot);\n if (conflicted.length === 0) return;\n throw new CliExitError(2,\n '\\n' + SEP + '⛔ Conflicts are NOT resolved yet\\n' + SEP + '\\n'\n + `${WP_FINISH_PUSH_DEV} commits the resolution — it cannot write one for you. These files are still\\n`\n + 'unmerged (edit until no conflict markers remain, then `git add` each one):\\n'\n + conflicted.map((f: string): string => ` ${f}`).join('\\n') + '\\n\\n'\n + `Merging: ${state.current === '' ? '(none)' : state.current}\\n`\n + `Give up instead with: ${WP_FINISH_PUSH_DEV} --abort\\n`);\n }\n\n /**\n * The name of the throwaway branch for a resolve of `branch`.\n *\n * Suffixed rather than prefixed, matching the existing `<feature>Squash` / `<feature>PreMerge<n>`\n * convention — and deliberately NOT inside the dev namespace, which holds REMOTE copies only.\n */\n tmpBranchFor(branch: string): string {\n return `${branch}DevResolve`;\n }\n\n /** The banner `--resolve` prints before the first merge, so the queue is visible before it halts. */\n announce(cfg: DevDeployConfig, state: PushDevState): string {\n return '\\n' + SEP + `🔀 Resolving the dev composition for ${state.targetRef}\\n` + SEP + '\\n'\n + `Merging ${String(state.queue.length)} other cop${state.queue.length === 1 ? 'y' : 'ies'} from `\n + `\\`${cfg.copyRefGlob()}\\`, in the order your CI composes\\n\\`${cfg.devBranch}\\`, onto the throwaway branch `\n + `\\`${state.tmpBranch}\\`:\\n`\n + state.queue.map((r: string): string => ` ${r}`).join('\\n') + '\\n\\n'\n + `Your feature branch \\`${state.originalBranch}\\` is not touched by any of this.\\n`\n + `A clean run publishes the copy itself — ${WP_FINISH_PUSH_DEV} is only needed if a merge stops.\\n\\n`;\n }\n}\n"]}
1
+ {"version":3,"file":"dev-resolve-runner.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/dev-resolve-runner.ts"],"names":[],"mappings":";;;;AAAA,0DAA4F;AAC5F,yCAA2D;AAE3D,yCAAqC;AACrC,uDAAkD;AAClD,qDAAmE;AACnE,qEAA+D;AAE/D,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;;;;;;GASG;AAEI,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAEJ;IACA;IACA;IACA;IAJrB,YACqB,OAAgB,EAChB,IAAmB,EACnB,KAAwB,EACxB,UAA+B;QAH/B,YAAO,GAAP,OAAO,CAAS;QAChB,SAAI,GAAJ,IAAI,CAAe;QACnB,UAAK,GAAL,KAAK,CAAmB;QACxB,eAAU,GAAV,UAAU,CAAqB;IACjD,CAAC;IAEJ;;;;;;;;;;;;;;OAcG;IACH,KAAK,CAAC,KAAK,CAAC,QAAgB,EAAE,KAAmB,EAAE,IAAY,EAAE,SAAmB;QAChF,MAAM,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QACjD,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAClC,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAC5B,CAAC,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,EACzD,iDAAiD,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;QACxE,MAAM,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,MAAM,CAAC,QAAgB,EAAE,KAAmB;QAC9C,MAAM,IAAI,CAAC,qBAAqB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAClD,MAAM,IAAI,CAAC,OAAO,CAA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C;cAClF,2CAA2C,iCAAkB,uCAAuC,CAAC;IAC/G,CAAC;CACJ,CAAA;AAhLY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGP,kBAAO;QACV,+BAAa;QACZ,kCAAiB;QACZ,4CAAmB;GAL3C,gBAAgB,CAgL5B","sourcesContent":["import { CliExitError, DevDeployConfig, WP_FINISH_PUSH_DEV } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { GitExec } from './git-exec';\nimport { DevDeployRefs } from './dev-deploy-refs';\nimport { PushDevState, PushDevStateStore } from './push-dev-state';\nimport { DevDeployWatchHints } from './dev-deploy-watch-hints';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * The queue-draining engine behind `wp-push-dev --resolve` and `wp-finish-push-dev`.\n *\n * ONE class owns every git WRITE in the resolve flow, and that is a hard requirement rather than tidiness:\n * `redirect-how-to-merge-main` blocks `git merge` in every form INCLUDING `--continue`, and\n * `pr-creation-or-push-guard` blocks every `git push`. So an AI cannot be told \"now run `git commit`\" or\n * \"`git merge --continue`\" — those instructions are unrunnable by the only party reading them. The command\n * owns the merges, the commit and the push (as child processes the hooks never see); the AI's entire job is\n * editing the conflicted files and `git add`-ing them, neither of which is blocked.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class DevResolveRunner {\n constructor(\n private readonly gitExec: GitExec,\n private readonly refs: DevDeployRefs,\n private readonly store: PushDevStateStore,\n private readonly watchHints: DevDeployWatchHints,\n ) {}\n\n /**\n * Start a resolve: park on a throwaway branch at the current copy, then drain the queue.\n *\n * The checkout is `-B <tmp> <base>` and NEVER the feature branch, which is the cardinal constraint made\n * mechanical — every merge below lands on a branch that is deleted at the end, so no other developer's\n * commits can reach the PR head even if the resolve is abandoned halfway.\n *\n * `base` differs between the two callers and the difference IS the semantics. `--resolve` starts at the\n * published copy and merges the other copies in (compose what CI will build). `--rebase-resolution`\n * starts at the LOCAL HEAD and merges the published copy in (replay an existing resolution on top of\n * the new commits, instead of force-pushing over it).\n *\n * `fetchRefs` is passed separately from the queue because `--rebase-resolution` merges a ref that is\n * also its push destination, so \"everything to fetch\" and \"everything to merge\" are not the same list.\n */\n async start(repoRoot: string, state: PushDevState, base: string, fetchRefs: string[]): Promise<void> {\n await this.refs.fetchCopies(repoRoot, fetchRefs);\n this.store.write(repoRoot, state);\n await this.gitExec.runGitChecked(\n ['-C', repoRoot, 'checkout', '-B', state.tmpBranch, base],\n `Failed to create the throwaway resolve branch ${state.tmpBranch}`);\n await this.drain(repoRoot, state);\n }\n\n /**\n * Resume after the human/AI has resolved the halted merge: commit it, then keep draining.\n *\n * REFETCHES the remaining queue first. A resolution session can run long, and queuing against refs\n * fetched an hour ago rehearses a composition CI will not build — the one freshness gap the sibling\n * update flow is still known to have (only its stage ① ever fetches).\n */\n async resume(repoRoot: string, state: PushDevState): Promise<void> {\n await this.assertNoUnmergedPaths(repoRoot, state);\n await this.gitExec.assertNoUntracked(repoRoot);\n await this.gitExec.runGitChecked(['-C', repoRoot, 'add', '-u'], 'Failed to stage the resolved files (git add -u)');\n await this.gitExec.runGitChecked(['-C', repoRoot, 'commit', '--no-edit'],\n `Failed to commit the resolution of ${state.current}`);\n process.stdout.write(`✅ Committed the resolution of ${state.current}.\\n`);\n state.current = '';\n await this.refs.fetchCopies(repoRoot, state.queue);\n await this.drain(repoRoot, state);\n }\n\n /**\n * Throw the whole resolve away: undo any halted merge, go back to the original branch, delete the\n * throwaway branch and the state file. Nothing published, nothing on the feature branch.\n */\n async abort(repoRoot: string, state: PushDevState): Promise<void> {\n // Allowed to fail: there is no merge to abort when the resolve halted between merges, and that is\n // not an error condition — the rest of the teardown must still run.\n await this.gitExec.tryGit(['-C', repoRoot, 'merge', '--abort'], repoRoot);\n await this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', state.originalBranch],\n `Failed to return to ${state.originalBranch}`);\n await this.gitExec.tryGit(['-C', repoRoot, 'branch', '-D', state.tmpBranch], repoRoot);\n this.store.clear(repoRoot);\n process.stdout.write(\n '\\n' + SEP + '🛑 Dev-deploy resolve aborted\\n' + SEP + '\\n'\n + `You are back on \\`${state.originalBranch}\\`; \\`${state.tmpBranch}\\` and the state file are gone.\\n`\n + `The remote copy \\`${state.targetRef}\\` is untouched, and so is your feature branch.\\n`);\n }\n\n /**\n * Merge queued refs until one conflicts (HALT, hand the tree over) or the queue empties (PUBLISH).\n *\n * A LATER ref can conflict too, which is why this is a loop resumed from a state file rather than a\n * single pass: `wp-finish-push-dev` can legitimately stop again on the next ref in the queue.\n */\n private async drain(repoRoot: string, state: PushDevState): Promise<void> {\n while (state.queue.length > 0) {\n const ref = state.queue[0];\n state.queue = state.queue.slice(1);\n const outcome = await this.gitExec.tryGit(\n ['-C', repoRoot, 'merge', '--no-ff', '--no-edit', '-m',\n `Dev-deploy: merge ${ref} into ${state.targetRef}`, `refs/remotes/origin/${ref}`],\n repoRoot);\n if (outcome.ok) {\n process.stdout.write(` ✓ merged ${ref}\\n`);\n continue;\n }\n state.current = ref;\n this.store.write(repoRoot, state);\n await this.halt(repoRoot, state);\n return;\n }\n await this.publish(repoRoot, state);\n }\n\n /** Stop with the conflicted files listed and the ONE command that continues. Exit 2 = \"your turn\". */\n private async halt(repoRoot: string, state: PushDevState): Promise<never> {\n const conflicted = await this.unmergedPaths(repoRoot);\n const remaining = state.queue.length > 0\n ? `\\nStill queued after this one: ${state.queue.join(', ')}\\n`\n + `\\`${WP_FINISH_PUSH_DEV}\\` resumes the queue, so it may stop again on a later ref.\\n`\n : '';\n throw new CliExitError(2,\n '\\n' + SEP + `⚠️ CONFLICT merging ${state.current}\\n` + SEP + '\\n'\n + `You are on the throwaway branch \\`${state.tmpBranch}\\` — NOT \\`${state.originalBranch}\\`. Nothing here\\n`\n + 'can reach your feature branch or your PR, which is exactly why the resolution happens over here.\\n\\n'\n + 'Resolve these files (edit until no conflict markers remain, then `git add` each one):\\n'\n + conflicted.map((f: string): string => ` ${f}`).join('\\n') + '\\n'\n + remaining\n + '\\nThen run ONE of:\\n'\n + ` ${WP_FINISH_PUSH_DEV} ← commit, resume the queue, publish the copy\\n`\n + ` ${WP_FINISH_PUSH_DEV} --abort ← throw it away and go back to \\`${state.originalBranch}\\`\\n\\n`\n + 'Do NOT run `git merge --continue`, `git commit` or `git push` yourself — they are blocked, and\\n'\n + 'the finish command above does all three for you.\\n');\n }\n\n /** Queue empty: force-push the composed result over the copy, then restore the original checkout. */\n private async publish(repoRoot: string, state: PushDevState): Promise<void> {\n await this.gitExec.runGitChecked(\n ['-C', repoRoot, 'push', '--force', 'origin', `${state.tmpBranch}:refs/heads/${state.targetRef}`],\n `Failed to publish the dev copy ${state.targetRef}`);\n // Captured BEFORE the tmp branch is deleted — it is the composed sha the watch hints are about,\n // and after the checkout below HEAD is the feature branch, which is a different commit entirely.\n const published = await this.refs.headSha(repoRoot, state.tmpBranch);\n await this.gitExec.runGitChecked(['-C', repoRoot, 'checkout', state.originalBranch],\n `Failed to return to ${state.originalBranch}`);\n await this.gitExec.tryGit(['-C', repoRoot, 'branch', '-D', state.tmpBranch], repoRoot);\n this.store.clear(repoRoot);\n process.stdout.write(\n '\\n' + SEP + `✅ Published ${state.targetRef} with the resolutions\\n` + SEP + '\\n'\n + `You are back on \\`${state.originalBranch}\\`, which was never modified — verify with:\\n`\n + ` git log --oneline ${state.originalBranch}\\n`\n + 'Your CI will pick the copy up on its next composition run.\\n'\n + this.watchHints.render(this.refs.config(repoRoot), state.targetRef, published));\n }\n\n /** Conflicted (unmerged-in-index) paths. Empty once every one has been resolved and `git add`ed. */\n private async unmergedPaths(repoRoot: string): Promise<string[]> {\n const out = await this.gitExec.gitQuery(['-C', repoRoot, 'diff', '--name-only', '--diff-filter=U'], repoRoot,\n 'Failed to list the conflicted files (git diff --name-only --diff-filter=U).');\n return out.split('\\n').filter((l: string): boolean => l.trim() !== '');\n }\n\n // The gate on `wp-finish-push-dev`: refuse (and re-print the list) while anything is still unmerged.\n private async assertNoUnmergedPaths(repoRoot: string, state: PushDevState): Promise<void> {\n const conflicted = await this.unmergedPaths(repoRoot);\n if (conflicted.length === 0) return;\n throw new CliExitError(2,\n '\\n' + SEP + '⛔ Conflicts are NOT resolved yet\\n' + SEP + '\\n'\n + `${WP_FINISH_PUSH_DEV} commits the resolution — it cannot write one for you. These files are still\\n`\n + 'unmerged (edit until no conflict markers remain, then `git add` each one):\\n'\n + conflicted.map((f: string): string => ` ${f}`).join('\\n') + '\\n\\n'\n + `Merging: ${state.current === '' ? '(none)' : state.current}\\n`\n + `Give up instead with: ${WP_FINISH_PUSH_DEV} --abort\\n`);\n }\n\n /**\n * The name of the throwaway branch for a resolve of `branch`.\n *\n * Suffixed rather than prefixed, matching the existing `<feature>Squash` / `<feature>PreMerge<n>`\n * convention — and deliberately NOT inside the dev namespace, which holds REMOTE copies only.\n */\n tmpBranchFor(branch: string): string {\n return `${branch}DevResolve`;\n }\n\n /** The banner `--resolve` prints before the first merge, so the queue is visible before it halts. */\n announce(cfg: DevDeployConfig, state: PushDevState): string {\n return '\\n' + SEP + `🔀 Resolving the dev composition for ${state.targetRef}\\n` + SEP + '\\n'\n + `Merging ${String(state.queue.length)} other cop${state.queue.length === 1 ? 'y' : 'ies'} from `\n + `\\`${cfg.copyRefGlob()}\\`, in the order your CI composes\\n\\`${cfg.devBranch}\\`, onto the throwaway branch `\n + `\\`${state.tmpBranch}\\`:\\n`\n + state.queue.map((r: string): string => ` ${r}`).join('\\n') + '\\n\\n'\n + `Your feature branch \\`${state.originalBranch}\\` is not touched by any of this.\\n`\n + `A clean run publishes the copy itself — ${WP_FINISH_PUSH_DEV} is only needed if a merge stops.\\n\\n`;\n }\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import { GitProcessApi } from '@webpieces/tooling-common';
1
2
  import { ForkPoint } from './git-findForkPoint';
2
3
  import { GitStatusParser } from './git-status';
3
4
  /**
@@ -49,7 +50,8 @@ export declare class DiffBasis {
49
50
  export declare class DiffBasisResolver {
50
51
  private readonly forkPoint;
51
52
  private readonly statusParser;
52
- constructor(forkPoint: ForkPoint, statusParser: GitStatusParser);
53
+ private readonly git;
54
+ constructor(forkPoint: ForkPoint, statusParser: GitStatusParser, git: GitProcessApi);
53
55
  /**
54
56
  * Resolve the basis. The command shape is the whole point:
55
57
  *
@@ -59,7 +61,7 @@ export declare class DiffBasisResolver {
59
61
  * Omitting the head on a dirty tree is not a shortcut, it is the only form that shows uncommitted work,
60
62
  * and supplying `HEAD` there is precisely the bug this class exists to make unrepresentable.
61
63
  */
62
- resolve(repoRoot: string): DiffBasis;
64
+ resolve(repoRoot: string): Promise<DiffBasis>;
63
65
  /**
64
66
  * Every path that makes the tree dirty: tracked modifications/staged changes PLUS untracked files.
65
67
  * Untracked must be included — `git status --porcelain` reports them as `??`, and they are exactly the
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DiffBasisResolver = exports.DiffBasis = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const child_process_1 = require("child_process");
5
+ const tooling_common_1 = require("@webpieces/tooling-common");
6
6
  const inversify_1 = require("inversify");
7
7
  const git_findForkPoint_1 = require("./git-findForkPoint");
8
8
  const git_status_1 = require("./git-status");
@@ -81,9 +81,11 @@ exports.DiffBasis = DiffBasis;
81
81
  let DiffBasisResolver = class DiffBasisResolver {
82
82
  forkPoint;
83
83
  statusParser;
84
- constructor(forkPoint, statusParser) {
84
+ git;
85
+ constructor(forkPoint, statusParser, git) {
85
86
  this.forkPoint = forkPoint;
86
87
  this.statusParser = statusParser;
88
+ this.git = git;
87
89
  }
88
90
  /**
89
91
  * Resolve the basis. The command shape is the whole point:
@@ -94,14 +96,14 @@ let DiffBasisResolver = class DiffBasisResolver {
94
96
  * Omitting the head on a dirty tree is not a shortcut, it is the only form that shows uncommitted work,
95
97
  * and supplying `HEAD` there is precisely the bug this class exists to make unrepresentable.
96
98
  */
97
- resolve(repoRoot) {
98
- const base = this.forkPoint.resolveForkPoint(repoRoot);
99
- const headSha = this.gitOut(repoRoot, ['rev-parse', 'HEAD']);
99
+ async resolve(repoRoot) {
100
+ const base = await this.forkPoint.resolveForkPoint(repoRoot);
101
+ const headSha = await this.gitOut(repoRoot, ['rev-parse', 'HEAD']);
100
102
  // Point C. Deliberately does NOT fetch — this must work offline, like resolveForkPoint. So it is
101
103
  // main as this clone last saw it, which is the honest answer to "has main moved under me?" that a
102
104
  // local command can give. '' when origin/main is unknown (no remote yet).
103
- const mainHead = this.gitOut(repoRoot, ['rev-parse', 'origin/main']);
104
- const dirtyFiles = this.dirtyPaths(repoRoot);
105
+ const mainHead = await this.gitOut(repoRoot, ['rev-parse', 'origin/main']);
106
+ const dirtyFiles = await this.dirtyPaths(repoRoot);
105
107
  const dirty = dirtyFiles.length > 0;
106
108
  if (base === '')
107
109
  return new DiffBasis('', headSha, dirty, dirtyFiles, '', '', mainHead);
@@ -119,23 +121,24 @@ let DiffBasisResolver = class DiffBasisResolver {
119
121
  * character off the front of its path. It also left git's quoting on, so `"a b.txt"` was reported
120
122
  * with the quotes still attached and matched no checklist glob.
121
123
  */
122
- dirtyPaths(repoRoot) {
123
- const out = this.rawGitOut(repoRoot, ['status', '--porcelain', '--untracked-files=all']);
124
+ async dirtyPaths(repoRoot) {
125
+ const out = await this.rawGitOut(repoRoot, ['status', '--porcelain', '--untracked-files=all']);
124
126
  return this.statusParser.parse(out).map((entry) => entry.path);
125
127
  }
126
- gitOut(repoRoot, args) {
127
- return this.rawGitOut(repoRoot, args).trim();
128
+ async gitOut(repoRoot, args) {
129
+ return (await this.rawGitOut(repoRoot, args)).trim();
128
130
  }
129
131
  // Untrimmed — mandatory for `git status --porcelain`, where leading whitespace carries meaning.
130
- rawGitOut(repoRoot, args) {
131
- const result = (0, child_process_1.spawnSync)('git', args, { cwd: repoRoot, encoding: 'utf8' });
132
- return result.status === 0 ? (result.stdout ?? '') : '';
132
+ async rawGitOut(repoRoot, args) {
133
+ const result = await this.git.run(args, repoRoot);
134
+ return result.ok ? result.stdout : '';
133
135
  }
134
136
  };
135
137
  exports.DiffBasisResolver = DiffBasisResolver;
136
138
  exports.DiffBasisResolver = DiffBasisResolver = tslib_1.__decorate([
137
139
  (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
138
140
  tslib_1.__metadata("design:paramtypes", [git_findForkPoint_1.ForkPoint,
139
- git_status_1.GitStatusParser])
141
+ git_status_1.GitStatusParser,
142
+ tooling_common_1.GitProcessApi])
140
143
  ], DiffBasisResolver);
141
144
  //# sourceMappingURL=diff-basis.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"diff-basis.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/diff-basis.ts"],"names":[],"mappings":";;;;AAAA,iDAA0C;AAC1C,yCAA2D;AAC3D,2DAAgD;AAChD,6CAA+D;AAE/D;;;;;;;;;;;;;GAaG;AACH,MAAa,SAAS;IAClB,iFAAiF;IACjF,kEAAkE;IAClE,IAAI,CAAS;IACb,oGAAoG;IACpG,uGAAuG;IACvG,oCAAoC;IACpC,OAAO,CAAS;IAChB;;;;;;;;;;;OAWG;IACH,aAAa,CAAS;IACtB,eAAe,CAAS;IACxB,YAAY,CAAS;IACrB,mGAAmG;IACnG,KAAK,CAAU;IACf,gGAAgG;IAChG,UAAU,CAAW;IACrB,uGAAuG;IACvG,WAAW,CAAS;IACpB,qFAAqF;IACrF,eAAe,CAAS;IAExB,yDAAyD;IACzD,YAAY,IAAI,GAAG,EAAE,EAAE,OAAO,GAAG,EAAE,EAAE,KAAK,GAAG,KAAK,EAAE,aAAuB,EAAE,EAAE,WAAW,GAAG,EAAE,EAAE,eAAe,GAAG,EAAE,EAAE,YAAY,GAAG,EAAE;QACpI,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAA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;GAHzC,iBAAiB,CAsD7B","sourcesContent":["import { spawnSync } from 'child_process';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { ForkPoint } from './git-findForkPoint';\nimport { GitStatusEntry, GitStatusParser } from './git-status';\n\n/**\n * The ONE resolved answer to \"what exactly is this branch's diff, and what command reproduces it?\"\n *\n * It exists because the two halves of the review flow used to disagree. `ChecklistScanner` computes the\n * changed-FILE set by calling `getChangedFiles` with NO head — base→WORKING TREE, unioning in untracked\n * files — while `ChecklistInstructionsService` printed `git diff <base> HEAD -- <file>` to every\n * reviewer. On a dirty tree those are different ranges, and the printed command returns NOTHING: a reviewer\n * is handed a file list and a command that shows it nothing. That is not hypothetical — a reviewer subagent\n * on consumer-monorepo2 ran the printed command, got empty output, and had to guess its way to `git diff HEAD`.\n *\n * So the command is DERIVED from the same basis the file set is, and no caller writes one by hand.\n *\n * Data-only (per CLAUDE.md).\n */\nexport class DiffBasis {\n // The 3-point fork point of main. '' when neither origin/main nor main resolves.\n // Alias of {@link hashForkPoint} — see the hash-point trio below.\n base: string;\n // The REAL sha, never the literal string 'HEAD'. A recorded 'HEAD' is worthless the moment a commit\n // lands on top of it, and the stage receipt has to compare shas to know the tree moved under a review.\n // Alias of {@link hashFeatureHead}.\n headSha: string;\n /**\n * The SAME three hash points the 3-point merge records, under the SAME names\n * (`merge-info/<branch>/updatemain-hashes.json` → hashForkPoint / hashFeatureHead / hashMainHead).\n *\n * Two reasons this matters. First, vocabulary: the merge half of the system said \"hashForkPoint\"\n * while the review half said \"base\" for the identical sha, so nothing could be grepped across both.\n * Second, and the real gap: the review side recorded only TWO of the three. Without `hashMainHead`\n * nothing downstream can answer \"did main move while this branch was under review?\" — which is\n * exactly what you want to know when a review looks stale or a merge is about to surprise you.\n *\n * `hashMainHead` is '' when origin/main cannot be resolved offline; it is a REPORT, never a gate.\n */\n hashForkPoint: string;\n hashFeatureHead: string;\n hashMainHead: string;\n // True when the diff includes staged/unstaged/untracked work, i.e. the range is base→working tree.\n dirty: boolean;\n // Exactly WHICH paths make it dirty, so a message can name them instead of asserting dirtiness.\n dirtyFiles: string[];\n // The command that reproduces the WHOLE diff. Correct for both clean and dirty; see DiffBasisResolver.\n diffCommand: string;\n // The same command with a `-- <file>` tail — what every reviewer instruction prints.\n fileDiffCommand: string;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(base = '', headSha = '', dirty = false, dirtyFiles: string[] = [], diffCommand = '', fileDiffCommand = '', hashMainHead = '') {\n this.base = base;\n this.headSha = headSha;\n this.dirty = dirty;\n this.dirtyFiles = dirtyFiles;\n this.diffCommand = diffCommand;\n this.fileDiffCommand = fileDiffCommand;\n // The trio is DERIVED from base/headSha rather than passed separately, so the two names for one\n // sha cannot drift apart into disagreeing values.\n this.hashForkPoint = base;\n this.hashFeatureHead = headSha;\n this.hashMainHead = hashMainHead;\n }\n\n // True when there is no usable base — callers must SAY so rather than print a command that cannot work.\n get unresolved(): boolean {\n return this.base.trim() === '';\n }\n}\n\n/**\n * Resolves {@link DiffBasis} for a repo. Injects {@link ForkPoint} so the base is the SAME fork-point\n * computation the checklist matching uses — never `DiffScope.resolveBase`, which overlays NX_BASE/NX_HEAD\n * from the environment and would make review coverage depend on an env var.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class DiffBasisResolver {\n constructor(\n private readonly forkPoint: ForkPoint,\n private readonly statusParser: GitStatusParser,\n ) {}\n\n /**\n * Resolve the basis. The command shape is the whole point:\n *\n * clean tree → `git diff <base> <headSha>` (commit-to-commit; reproducible later, unlike 'HEAD')\n * dirty tree → `git diff <base>` (NO head — this is what includes the working tree)\n *\n * Omitting the head on a dirty tree is not a shortcut, it is the only form that shows uncommitted work,\n * and supplying `HEAD` there is precisely the bug this class exists to make unrepresentable.\n */\n resolve(repoRoot: string): DiffBasis {\n const base = this.forkPoint.resolveForkPoint(repoRoot);\n const headSha = this.gitOut(repoRoot, ['rev-parse', 'HEAD']);\n // Point C. Deliberately does NOT fetch — this must work offline, like resolveForkPoint. So it is\n // main as this clone last saw it, which is the honest answer to \"has main moved under me?\" that a\n // local command can give. '' when origin/main is unknown (no remote yet).\n const mainHead = this.gitOut(repoRoot, ['rev-parse', 'origin/main']);\n const dirtyFiles = this.dirtyPaths(repoRoot);\n const dirty = dirtyFiles.length > 0;\n if (base === '') return new DiffBasis('', headSha, dirty, dirtyFiles, '', '', mainHead);\n const whole = dirty ? `git diff ${base}` : `git diff ${base} ${headSha}`;\n return new DiffBasis(base, headSha, dirty, dirtyFiles, whole, `${whole} -- <file>`, mainHead);\n }\n\n /**\n * Every path that makes the tree dirty: tracked modifications/staged changes PLUS untracked files.\n * Untracked must be included — `git status --porcelain` reports them as `??`, and they are exactly the\n * files a brand-new migration or terraform rule arrives as, which is when a checklist most wants to fire.\n *\n * Parsed by {@link GitStatusParser} off the RAW (untrimmed) output. This used to hand-roll\n * `line.slice(3).trim()` over `gitOut(...)`, which trims — and on a porcelain line the leading space\n * IS the index column, so trimming shifted the FIRST line left by one and `slice(3)` then cut a\n * character off the front of its path. It also left git's quoting on, so `\"a b.txt\"` was reported\n * with the quotes still attached and matched no checklist glob.\n */\n private dirtyPaths(repoRoot: string): string[] {\n const out = this.rawGitOut(repoRoot, ['status', '--porcelain', '--untracked-files=all']);\n return this.statusParser.parse(out).map((entry: GitStatusEntry): string => entry.path);\n }\n\n private gitOut(repoRoot: string, args: string[]): string {\n return this.rawGitOut(repoRoot, args).trim();\n }\n\n // Untrimmed — mandatory for `git status --porcelain`, where leading whitespace carries meaning.\n private rawGitOut(repoRoot: string, args: string[]): string {\n const result = spawnSync('git', args, { cwd: repoRoot, encoding: 'utf8' });\n return result.status === 0 ? (result.stdout ?? '') : '';\n }\n}\n"]}
1
+ {"version":3,"file":"diff-basis.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/diff-basis.ts"],"names":[],"mappings":";;;;AAAA,8DAA0D;AAC1D,yCAA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EAAE,aAAa,EAAE,uBAAuB,CAAC,CAAC,CAAC;QAC/F,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAqB,EAAU,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3F,CAAC;IAEO,KAAK,CAAC,MAAM,CAAC,QAAgB,EAAE,IAAc;QACjD,OAAO,CAAC,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACzD,CAAC;IAED,gGAAgG;IACxF,KAAK,CAAC,SAAS,CAAC,QAAgB,EAAE,IAAc;QACpD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAClD,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1C,CAAC;CACJ,CAAA;AAvDY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGL,6BAAS;QACN,4BAAe;QACxB,8BAAa;GAJ9B,iBAAiB,CAuD7B","sourcesContent":["import { GitProcessApi } from '@webpieces/tooling-common';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { ForkPoint } from './git-findForkPoint';\nimport { GitStatusEntry, GitStatusParser } from './git-status';\n\n/**\n * The ONE resolved answer to \"what exactly is this branch's diff, and what command reproduces it?\"\n *\n * It exists because the two halves of the review flow used to disagree. `ChecklistScanner` computes the\n * changed-FILE set by calling `getChangedFiles` with NO head — base→WORKING TREE, unioning in untracked\n * files — while `ChecklistInstructionsService` printed `git diff <base> HEAD -- <file>` to every\n * reviewer. On a dirty tree those are different ranges, and the printed command returns NOTHING: a reviewer\n * is handed a file list and a command that shows it nothing. That is not hypothetical — a reviewer subagent\n * on consumer-monorepo2 ran the printed command, got empty output, and had to guess its way to `git diff HEAD`.\n *\n * So the command is DERIVED from the same basis the file set is, and no caller writes one by hand.\n *\n * Data-only (per CLAUDE.md).\n */\nexport class DiffBasis {\n // The 3-point fork point of main. '' when neither origin/main nor main resolves.\n // Alias of {@link hashForkPoint} — see the hash-point trio below.\n base: string;\n // The REAL sha, never the literal string 'HEAD'. A recorded 'HEAD' is worthless the moment a commit\n // lands on top of it, and the stage receipt has to compare shas to know the tree moved under a review.\n // Alias of {@link hashFeatureHead}.\n headSha: string;\n /**\n * The SAME three hash points the 3-point merge records, under the SAME names\n * (`merge-info/<branch>/updatemain-hashes.json` → hashForkPoint / hashFeatureHead / hashMainHead).\n *\n * Two reasons this matters. First, vocabulary: the merge half of the system said \"hashForkPoint\"\n * while the review half said \"base\" for the identical sha, so nothing could be grepped across both.\n * Second, and the real gap: the review side recorded only TWO of the three. Without `hashMainHead`\n * nothing downstream can answer \"did main move while this branch was under review?\" — which is\n * exactly what you want to know when a review looks stale or a merge is about to surprise you.\n *\n * `hashMainHead` is '' when origin/main cannot be resolved offline; it is a REPORT, never a gate.\n */\n hashForkPoint: string;\n hashFeatureHead: string;\n hashMainHead: string;\n // True when the diff includes staged/unstaged/untracked work, i.e. the range is base→working tree.\n dirty: boolean;\n // Exactly WHICH paths make it dirty, so a message can name them instead of asserting dirtiness.\n dirtyFiles: string[];\n // The command that reproduces the WHOLE diff. Correct for both clean and dirty; see DiffBasisResolver.\n diffCommand: string;\n // The same command with a `-- <file>` tail — what every reviewer instruction prints.\n fileDiffCommand: string;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(base = '', headSha = '', dirty = false, dirtyFiles: string[] = [], diffCommand = '', fileDiffCommand = '', hashMainHead = '') {\n this.base = base;\n this.headSha = headSha;\n this.dirty = dirty;\n this.dirtyFiles = dirtyFiles;\n this.diffCommand = diffCommand;\n this.fileDiffCommand = fileDiffCommand;\n // The trio is DERIVED from base/headSha rather than passed separately, so the two names for one\n // sha cannot drift apart into disagreeing values.\n this.hashForkPoint = base;\n this.hashFeatureHead = headSha;\n this.hashMainHead = hashMainHead;\n }\n\n // True when there is no usable base — callers must SAY so rather than print a command that cannot work.\n get unresolved(): boolean {\n return this.base.trim() === '';\n }\n}\n\n/**\n * Resolves {@link DiffBasis} for a repo. Injects {@link ForkPoint} so the base is the SAME fork-point\n * computation the checklist matching uses — never `DiffScope.resolveBase`, which overlays NX_BASE/NX_HEAD\n * from the environment and would make review coverage depend on an env var.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class DiffBasisResolver {\n constructor(\n private readonly forkPoint: ForkPoint,\n private readonly statusParser: GitStatusParser,\n private readonly git: GitProcessApi,\n ) {}\n\n /**\n * Resolve the basis. The command shape is the whole point:\n *\n * clean tree → `git diff <base> <headSha>` (commit-to-commit; reproducible later, unlike 'HEAD')\n * dirty tree → `git diff <base>` (NO head — this is what includes the working tree)\n *\n * Omitting the head on a dirty tree is not a shortcut, it is the only form that shows uncommitted work,\n * and supplying `HEAD` there is precisely the bug this class exists to make unrepresentable.\n */\n async resolve(repoRoot: string): Promise<DiffBasis> {\n const base = await this.forkPoint.resolveForkPoint(repoRoot);\n const headSha = await this.gitOut(repoRoot, ['rev-parse', 'HEAD']);\n // Point C. Deliberately does NOT fetch — this must work offline, like resolveForkPoint. So it is\n // main as this clone last saw it, which is the honest answer to \"has main moved under me?\" that a\n // local command can give. '' when origin/main is unknown (no remote yet).\n const mainHead = await this.gitOut(repoRoot, ['rev-parse', 'origin/main']);\n const dirtyFiles = await this.dirtyPaths(repoRoot);\n const dirty = dirtyFiles.length > 0;\n if (base === '') return new DiffBasis('', headSha, dirty, dirtyFiles, '', '', mainHead);\n const whole = dirty ? `git diff ${base}` : `git diff ${base} ${headSha}`;\n return new DiffBasis(base, headSha, dirty, dirtyFiles, whole, `${whole} -- <file>`, mainHead);\n }\n\n /**\n * Every path that makes the tree dirty: tracked modifications/staged changes PLUS untracked files.\n * Untracked must be included — `git status --porcelain` reports them as `??`, and they are exactly the\n * files a brand-new migration or terraform rule arrives as, which is when a checklist most wants to fire.\n *\n * Parsed by {@link GitStatusParser} off the RAW (untrimmed) output. This used to hand-roll\n * `line.slice(3).trim()` over `gitOut(...)`, which trims — and on a porcelain line the leading space\n * IS the index column, so trimming shifted the FIRST line left by one and `slice(3)` then cut a\n * character off the front of its path. It also left git's quoting on, so `\"a b.txt\"` was reported\n * with the quotes still attached and matched no checklist glob.\n */\n private async dirtyPaths(repoRoot: string): Promise<string[]> {\n const out = await this.rawGitOut(repoRoot, ['status', '--porcelain', '--untracked-files=all']);\n return this.statusParser.parse(out).map((entry: GitStatusEntry): string => entry.path);\n }\n\n private async gitOut(repoRoot: string, args: string[]): Promise<string> {\n return (await this.rawGitOut(repoRoot, args)).trim();\n }\n\n // Untrimmed — mandatory for `git status --porcelain`, where leading whitespace carries meaning.\n private async rawGitOut(repoRoot: string, args: string[]): Promise<string> {\n const result = await this.git.run(args, repoRoot);\n return result.ok ? result.stdout : '';\n }\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import { ReviewJsonService } from '@webpieces/rules-config';
2
+ import { GitProcessApi } from '@webpieces/tooling-common';
2
3
  import { DiffBasis } from './diff-basis';
3
4
  export declare const FILE_DIFF_MAX_BYTES: number;
4
5
  export declare const ALL_DIFF_MAX_BYTES: number;
@@ -51,7 +52,8 @@ export declare class DiffManifest {
51
52
  */
52
53
  export declare class DiffMaterializer {
53
54
  private readonly reviewJsonService;
54
- constructor(reviewJsonService: ReviewJsonService);
55
+ private readonly git;
56
+ constructor(reviewJsonService: ReviewJsonService, git: GitProcessApi);
55
57
  /** The dir this writes into: `.webpieces/pr-review/<feature>/diff`. */
56
58
  diffDirFor(repoRoot: string, featureName: string): string;
57
59
  /**
@@ -61,13 +63,13 @@ export declare class DiffMaterializer {
61
63
  * a reviewer reads covers exactly the files its checklist matched on. Recomputing here is how the two
62
64
  * would drift apart again.
63
65
  */
64
- materialize(repoRoot: string, featureName: string, basis: DiffBasis, changedFiles: readonly string[], excludeGlobs: readonly string[]): DiffManifest;
66
+ materialize(repoRoot: string, featureName: string, basis: DiffBasis, changedFiles: readonly string[], excludeGlobs: readonly string[]): Promise<DiffManifest>;
65
67
  /**
66
68
  * ONE `git diff` for the whole branch, split into per-file patches keyed by repo-relative path.
67
69
  * Untracked files never appear in `git diff`, so they are synthesized as all-added patches — the same
68
70
  * treatment DiffScope.getFileDiff already gives them, kept consistent so a reviewer sees one format.
69
71
  */
70
- diffByFile(repoRoot: string, basis: DiffBasis): Map<string, string>;
72
+ diffByFile(repoRoot: string, basis: DiffBasis): Promise<Map<string, string>>;
71
73
  /**
72
74
  * The b-side path out of a `diff --git a/x b/x` header. The b-side is the right one: for a rename it is
73
75
  * the name that exists on disk, which is the file a reviewer can actually open.
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DiffMaterializer = exports.DiffManifest = exports.DiffManifestEntry = exports.ALL_DIFF_MAX_BYTES = exports.FILE_DIFF_MAX_BYTES = 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");
8
+ const tooling_common_1 = require("@webpieces/tooling-common");
9
9
  const to_error_1 = require("@webpieces/tooling-common/to-error");
10
10
  const inversify_1 = require("inversify");
11
11
  // Per-file cap. Over it, the file's diff is truncated WITH a footer naming the command that gets the rest.
@@ -94,8 +94,10 @@ exports.DiffManifest = DiffManifest;
94
94
  */
95
95
  let DiffMaterializer = class DiffMaterializer {
96
96
  reviewJsonService;
97
- constructor(reviewJsonService) {
97
+ git;
98
+ constructor(reviewJsonService, git) {
98
99
  this.reviewJsonService = reviewJsonService;
100
+ this.git = git;
99
101
  }
100
102
  /** The dir this writes into: `.webpieces/pr-review/<feature>/diff`. */
101
103
  diffDirFor(repoRoot, featureName) {
@@ -108,7 +110,7 @@ let DiffMaterializer = class DiffMaterializer {
108
110
  * a reviewer reads covers exactly the files its checklist matched on. Recomputing here is how the two
109
111
  * would drift apart again.
110
112
  */
111
- materialize(repoRoot, featureName, basis, changedFiles, excludeGlobs) {
113
+ async materialize(repoRoot, featureName, basis, changedFiles, excludeGlobs) {
112
114
  const dir = this.diffDirFor(repoRoot, featureName);
113
115
  const filesDir = path.join(dir, 'files');
114
116
  fs.rmSync(dir, { recursive: true, force: true }); // a stale diff read as current is worse than none
@@ -116,7 +118,7 @@ let DiffMaterializer = class DiffMaterializer {
116
118
  const manifest = new DiffManifest(basis.base, basis.headSha, basis.dirty, basis.diffCommand, [], [], [], basis.hashMainHead);
117
119
  if (basis.unresolved)
118
120
  return this.writeManifest(dir, manifest);
119
- const byFile = this.diffByFile(repoRoot, basis);
121
+ const byFile = await this.diffByFile(repoRoot, basis);
120
122
  const used = new Set();
121
123
  for (const file of [...changedFiles].sort()) {
122
124
  this.writeOne(repoRoot, filesDir, file, byFile, used, excludeGlobs, manifest);
@@ -129,9 +131,9 @@ let DiffMaterializer = class DiffMaterializer {
129
131
  * Untracked files never appear in `git diff`, so they are synthesized as all-added patches — the same
130
132
  * treatment DiffScope.getFileDiff already gives them, kept consistent so a reviewer sees one format.
131
133
  */
132
- diffByFile(repoRoot, basis) {
134
+ async diffByFile(repoRoot, basis) {
133
135
  const args = basis.dirty ? ['diff', basis.base] : ['diff', basis.base, basis.headSha];
134
- const out = this.gitOut(repoRoot, args);
136
+ const out = await this.gitOut(repoRoot, args);
135
137
  const byFile = new Map();
136
138
  // Split BEFORE each `diff --git` header while keeping the header on its chunk.
137
139
  for (const chunk of out.split(/\n(?=diff --git )/)) {
@@ -141,7 +143,7 @@ let DiffMaterializer = class DiffMaterializer {
141
143
  if (file !== '')
142
144
  byFile.set(file, chunk.endsWith('\n') ? chunk : `${chunk}\n`);
143
145
  }
144
- for (const file of this.untrackedFiles(repoRoot, basis)) {
146
+ for (const file of await this.untrackedFiles(repoRoot, basis)) {
145
147
  if (!byFile.has(file))
146
148
  byFile.set(file, this.syntheticAddedDiff(repoRoot, file));
147
149
  }
@@ -156,10 +158,10 @@ let DiffMaterializer = class DiffMaterializer {
156
158
  const match = header.match(/^diff --git a\/(.+) b\/(.+)$/);
157
159
  return match ? match[2] : '';
158
160
  }
159
- untrackedFiles(repoRoot, basis) {
161
+ async untrackedFiles(repoRoot, basis) {
160
162
  if (!basis.dirty)
161
163
  return [];
162
- const out = this.gitOut(repoRoot, ['ls-files', '--others', '--exclude-standard']);
164
+ const out = await this.gitOut(repoRoot, ['ls-files', '--others', '--exclude-standard']);
163
165
  return out === '' ? [] : out.split('\n').filter((f) => f.trim() !== '');
164
166
  }
165
167
  syntheticAddedDiff(repoRoot, file) {
@@ -295,16 +297,17 @@ let DiffMaterializer = class DiffMaterializer {
295
297
  fs.writeFileSync(path.join(dir, 'manifest.json'), JSON.stringify(manifest, null, 2) + '\n');
296
298
  return manifest;
297
299
  }
298
- gitOut(repoRoot, args) {
299
- // maxBuffer: a monorepo diff routinely exceeds node's 1MB default, and the failure mode is a
300
- // truncated capture that looks like a complete one.
301
- const result = (0, child_process_1.spawnSync)('git', args, { cwd: repoRoot, encoding: 'utf8', maxBuffer: 256 * 1024 * 1024 });
302
- return result.status === 0 ? (result.stdout ?? '') : '';
300
+ // A monorepo diff routinely exceeds node's 1MB default buffer; the GitProcessApi edge captures up to
301
+ // 256 MiB and reports a truncated capture as a FAILED command, never as a complete one.
302
+ async gitOut(repoRoot, args) {
303
+ const result = await this.git.run(args, repoRoot);
304
+ return result.ok ? result.stdout : '';
303
305
  }
304
306
  };
305
307
  exports.DiffMaterializer = DiffMaterializer;
306
308
  exports.DiffMaterializer = DiffMaterializer = tslib_1.__decorate([
307
309
  (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
308
- tslib_1.__metadata("design:paramtypes", [rules_config_1.ReviewJsonService])
310
+ tslib_1.__metadata("design:paramtypes", [rules_config_1.ReviewJsonService,
311
+ tooling_common_1.GitProcessApi])
309
312
  ], DiffMaterializer);
310
313
  //# sourceMappingURL=diff-materializer.js.map