@webpieces/pr-gate 0.4.975 → 0.4.977

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) 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/cleanup-command.js +12 -12
  12. package/src/scripts/commands/cleanup-command.js.map +1 -1
  13. package/src/scripts/commands/finish-push-dev-command.js +3 -4
  14. package/src/scripts/commands/finish-push-dev-command.js.map +1 -1
  15. package/src/scripts/commands/finish-update-command.js +1 -1
  16. package/src/scripts/commands/finish-update-command.js.map +1 -1
  17. package/src/scripts/commands/finish-upsert-pr-command.d.ts +4 -1
  18. package/src/scripts/commands/finish-upsert-pr-command.js +65 -62
  19. package/src/scripts/commands/finish-upsert-pr-command.js.map +1 -1
  20. package/src/scripts/commands/human-post-pr-command.d.ts +8 -6
  21. package/src/scripts/commands/human-post-pr-command.js +33 -32
  22. package/src/scripts/commands/human-post-pr-command.js.map +1 -1
  23. package/src/scripts/commands/land-pr-command.d.ts +5 -1
  24. package/src/scripts/commands/land-pr-command.js +37 -23
  25. package/src/scripts/commands/land-pr-command.js.map +1 -1
  26. package/src/scripts/commands/main-checkout.d.ts +4 -1
  27. package/src/scripts/commands/main-checkout.js +22 -22
  28. package/src/scripts/commands/main-checkout.js.map +1 -1
  29. package/src/scripts/commands/push-dev-command.js +28 -29
  30. package/src/scripts/commands/push-dev-command.js.map +1 -1
  31. package/src/scripts/commands/reap-worktree-command.js +4 -5
  32. package/src/scripts/commands/reap-worktree-command.js.map +1 -1
  33. package/src/scripts/commands/review-upsert-pr-command.js +10 -10
  34. package/src/scripts/commands/review-upsert-pr-command.js.map +1 -1
  35. package/src/scripts/commands/start-update-command.d.ts +1 -1
  36. package/src/scripts/commands/start-update-command.js +3 -3
  37. package/src/scripts/commands/start-update-command.js.map +1 -1
  38. package/src/scripts/commands/start-upsert-pr-command.js +4 -4
  39. package/src/scripts/commands/start-upsert-pr-command.js.map +1 -1
  40. package/src/scripts/commands/sync-main-command.js +6 -6
  41. package/src/scripts/commands/sync-main-command.js.map +1 -1
  42. package/src/scripts/commands/upsert-hotfix-pr-command.d.ts +6 -4
  43. package/src/scripts/commands/upsert-hotfix-pr-command.js +46 -43
  44. package/src/scripts/commands/upsert-hotfix-pr-command.js.map +1 -1
  45. package/src/scripts/commands/working-tree-gate.d.ts +4 -1
  46. package/src/scripts/commands/working-tree-gate.js +14 -11
  47. package/src/scripts/commands/working-tree-gate.js.map +1 -1
  48. package/src/scripts/commands/worktree-cleanup.d.ts +4 -4
  49. package/src/scripts/commands/worktree-cleanup.js +4 -4
  50. package/src/scripts/commands/worktree-cleanup.js.map +1 -1
  51. package/src/scripts/commands/write-review-command.js +4 -6
  52. package/src/scripts/commands/write-review-command.js.map +1 -1
  53. package/src/scripts/commands/write-review-fixes-command.js +3 -4
  54. package/src/scripts/commands/write-review-fixes-command.js.map +1 -1
  55. package/src/scripts/git-finishUpsertPr.js +2 -2
  56. package/src/scripts/git-finishUpsertPr.js.map +1 -1
  57. package/src/scripts/git-gatherInfo.js +6 -7
  58. package/src/scripts/git-gatherInfo.js.map +1 -1
  59. package/src/scripts/pr-gate-container.d.ts +9 -0
  60. package/src/scripts/pr-gate-container.js +19 -0
  61. package/src/scripts/pr-gate-container.js.map +1 -0
  62. package/src/scripts/workflow/await-loop.d.ts +1 -1
  63. package/src/scripts/workflow/await-loop.js +1 -1
  64. package/src/scripts/workflow/await-loop.js.map +1 -1
  65. package/src/scripts/workflow/build-affected.js +1 -1
  66. package/src/scripts/workflow/build-affected.js.map +1 -1
  67. package/src/scripts/workflow/build-artifact-gate.d.ts +1 -1
  68. package/src/scripts/workflow/build-artifact-gate.js +3 -3
  69. package/src/scripts/workflow/build-artifact-gate.js.map +1 -1
  70. package/src/scripts/workflow/build-gate-log.d.ts +9 -6
  71. package/src/scripts/workflow/build-gate-log.js +34 -40
  72. package/src/scripts/workflow/build-gate-log.js.map +1 -1
  73. package/src/scripts/workflow/checklist-detector.d.ts +2 -2
  74. package/src/scripts/workflow/checklist-detector.js +4 -4
  75. package/src/scripts/workflow/checklist-detector.js.map +1 -1
  76. package/src/scripts/workflow/checklist-scanner.d.ts +1 -1
  77. package/src/scripts/workflow/checklist-scanner.js +11 -11
  78. package/src/scripts/workflow/checklist-scanner.js.map +1 -1
  79. package/src/scripts/workflow/checklist-scope-hasher.d.ts +1 -1
  80. package/src/scripts/workflow/checklist-scope-hasher.js +2 -2
  81. package/src/scripts/workflow/checklist-scope-hasher.js.map +1 -1
  82. package/src/scripts/workflow/dev-deploy-refs.d.ts +5 -5
  83. package/src/scripts/workflow/dev-deploy-refs.js +8 -8
  84. package/src/scripts/workflow/dev-deploy-refs.js.map +1 -1
  85. package/src/scripts/workflow/dev-resolve-runner.d.ts +3 -3
  86. package/src/scripts/workflow/dev-resolve-runner.js +30 -30
  87. package/src/scripts/workflow/dev-resolve-runner.js.map +1 -1
  88. package/src/scripts/workflow/diff-basis.d.ts +4 -2
  89. package/src/scripts/workflow/diff-basis.js +18 -15
  90. package/src/scripts/workflow/diff-basis.js.map +1 -1
  91. package/src/scripts/workflow/diff-materializer.d.ts +5 -3
  92. package/src/scripts/workflow/diff-materializer.js +18 -15
  93. package/src/scripts/workflow/diff-materializer.js.map +1 -1
  94. package/src/scripts/workflow/gated-pr-publisher.d.ts +8 -6
  95. package/src/scripts/workflow/gated-pr-publisher.js +23 -22
  96. package/src/scripts/workflow/gated-pr-publisher.js.map +1 -1
  97. package/src/scripts/workflow/generated-artifact-registry.d.ts +4 -2
  98. package/src/scripts/workflow/generated-artifact-registry.js +11 -8
  99. package/src/scripts/workflow/generated-artifact-registry.js.map +1 -1
  100. package/src/scripts/workflow/git-exec.d.ts +22 -12
  101. package/src/scripts/workflow/git-exec.js +45 -29
  102. package/src/scripts/workflow/git-exec.js.map +1 -1
  103. package/src/scripts/workflow/git-findForkPoint.d.ts +6 -2
  104. package/src/scripts/workflow/git-findForkPoint.js +31 -23
  105. package/src/scripts/workflow/git-findForkPoint.js.map +1 -1
  106. package/src/scripts/workflow/git-readAiBranchName.d.ts +4 -2
  107. package/src/scripts/workflow/git-readAiBranchName.js +8 -5
  108. package/src/scripts/workflow/git-readAiBranchName.js.map +1 -1
  109. package/src/scripts/workflow/hotfix-pr-publisher.d.ts +4 -3
  110. package/src/scripts/workflow/hotfix-pr-publisher.js +7 -6
  111. package/src/scripts/workflow/hotfix-pr-publisher.js.map +1 -1
  112. package/src/scripts/workflow/landed-tree-resolver.d.ts +4 -2
  113. package/src/scripts/workflow/landed-tree-resolver.js +11 -8
  114. package/src/scripts/workflow/landed-tree-resolver.js.map +1 -1
  115. package/src/scripts/workflow/landed-worktree-reaper.d.ts +4 -2
  116. package/src/scripts/workflow/landed-worktree-reaper.js +12 -9
  117. package/src/scripts/workflow/landed-worktree-reaper.js.map +1 -1
  118. package/src/scripts/workflow/merge-end.d.ts +5 -4
  119. package/src/scripts/workflow/merge-end.js +28 -27
  120. package/src/scripts/workflow/merge-end.js.map +1 -1
  121. package/src/scripts/workflow/merge-start.d.ts +5 -1
  122. package/src/scripts/workflow/merge-start.js +56 -49
  123. package/src/scripts/workflow/merge-start.js.map +1 -1
  124. package/src/scripts/workflow/open-pr-check.d.ts +4 -2
  125. package/src/scripts/workflow/open-pr-check.js +11 -8
  126. package/src/scripts/workflow/open-pr-check.js.map +1 -1
  127. package/src/scripts/workflow/pr-comment-upserter.d.ts +5 -3
  128. package/src/scripts/workflow/pr-comment-upserter.js +15 -14
  129. package/src/scripts/workflow/pr-comment-upserter.js.map +1 -1
  130. package/src/scripts/workflow/pr-context-writer.d.ts +1 -1
  131. package/src/scripts/workflow/pr-context-writer.js +3 -3
  132. package/src/scripts/workflow/pr-context-writer.js.map +1 -1
  133. package/src/scripts/workflow/pr-merger.d.ts +8 -5
  134. package/src/scripts/workflow/pr-merger.js +32 -27
  135. package/src/scripts/workflow/pr-merger.js.map +1 -1
  136. package/src/scripts/workflow/provenance-enforcer.d.ts +4 -2
  137. package/src/scripts/workflow/provenance-enforcer.js +19 -17
  138. package/src/scripts/workflow/provenance-enforcer.js.map +1 -1
  139. package/src/scripts/workflow/review-round-state.d.ts +7 -6
  140. package/src/scripts/workflow/review-round-state.js +33 -38
  141. package/src/scripts/workflow/review-round-state.js.map +1 -1
  142. package/src/scripts/workflow/run-update.js +1 -1
  143. package/src/scripts/workflow/run-update.js.map +1 -1
  144. package/src/scripts/workflow/squash-settings-enforcer.d.ts +6 -3
  145. package/src/scripts/workflow/squash-settings-enforcer.js +19 -14
  146. package/src/scripts/workflow/squash-settings-enforcer.js.map +1 -1
  147. package/src/scripts/wp-await-checks.js +2 -2
  148. package/src/scripts/wp-await-checks.js.map +1 -1
  149. package/src/scripts/wp-await-reviews.js +2 -2
  150. package/src/scripts/wp-await-reviews.js.map +1 -1
  151. package/src/scripts/wp-build.js +2 -2
  152. package/src/scripts/wp-build.js.map +1 -1
  153. package/src/scripts/wp-check-pr.js +2 -2
  154. package/src/scripts/wp-check-pr.js.map +1 -1
  155. package/src/scripts/wp-cleanup.js +2 -2
  156. package/src/scripts/wp-cleanup.js.map +1 -1
  157. package/src/scripts/wp-finish-push-dev.js +2 -2
  158. package/src/scripts/wp-finish-push-dev.js.map +1 -1
  159. package/src/scripts/wp-finish-update.js +2 -2
  160. package/src/scripts/wp-finish-update.js.map +1 -1
  161. package/src/scripts/wp-human-post-pr.js +2 -2
  162. package/src/scripts/wp-human-post-pr.js.map +1 -1
  163. package/src/scripts/wp-land-pr.js +2 -2
  164. package/src/scripts/wp-land-pr.js.map +1 -1
  165. package/src/scripts/wp-push-dev.js +2 -2
  166. package/src/scripts/wp-push-dev.js.map +1 -1
  167. package/src/scripts/wp-reap-worktree.js +2 -2
  168. package/src/scripts/wp-reap-worktree.js.map +1 -1
  169. package/src/scripts/wp-review-upsert-pr.js +2 -2
  170. package/src/scripts/wp-review-upsert-pr.js.map +1 -1
  171. package/src/scripts/wp-start-update.js +2 -2
  172. package/src/scripts/wp-start-update.js.map +1 -1
  173. package/src/scripts/wp-start-upsert-pr.js +2 -2
  174. package/src/scripts/wp-start-upsert-pr.js.map +1 -1
  175. package/src/scripts/wp-sync-main.js +2 -2
  176. package/src/scripts/wp-sync-main.js.map +1 -1
  177. package/src/scripts/wp-upsert-hotfix-pr.js +2 -2
  178. package/src/scripts/wp-upsert-hotfix-pr.js.map +1 -1
  179. package/src/scripts/wp-write-review-fixes.js +2 -2
  180. package/src/scripts/wp-write-review-fixes.js.map +1 -1
  181. package/src/scripts/wp-write-review.js +2 -2
  182. package/src/scripts/wp-write-review.js.map +1 -1
@@ -1,12 +1,16 @@
1
1
  import { RepoRootFinder } from '@webpieces/rules-config';
2
+ import { GitProcessApi } from '@webpieces/tooling-common';
2
3
  import { AiBranchName } from './git-readAiBranchName';
4
+ import { GitExec } from './git-exec';
3
5
  import { MergeState } from './merge-state';
4
6
  /** Computes the 3-point fork point and guards against improper merges-from-main. */
5
7
  export declare class ForkPoint {
6
8
  private readonly repoRootFinder;
7
9
  private readonly aiBranchName;
8
10
  private readonly mergeState;
9
- constructor(repoRootFinder: RepoRootFinder, aiBranchName: AiBranchName, mergeState: MergeState);
11
+ private readonly gitExec;
12
+ private readonly git;
13
+ constructor(repoRootFinder: RepoRootFinder, aiBranchName: AiBranchName, mergeState: MergeState, gitExec: GitExec, git: GitProcessApi);
10
14
  forkPointOutputDir(repoRoot: string, featureName: string, workflow: string): string;
11
15
  /**
12
16
  * The 3-point FORK POINT: where this branch diverged from main. `git merge-base origin/main HEAD`,
@@ -22,7 +26,7 @@ export declare class ForkPoint {
22
26
  * Also writes no files and runs no merge-commit scan, so it cannot throw: `wp-review-upsert-pr` must always
23
27
  * succeed, and a raw merge-from-main is the merge flow's problem to report, not the checklist's.
24
28
  */
25
- resolveForkPoint(repoRoot: string): string;
29
+ resolveForkPoint(repoRoot: string): Promise<string>;
26
30
  findForkPoint(workflow: string): Promise<void>;
27
31
  private checkMergeCommits;
28
32
  private printMergeFromMainError;
@@ -2,12 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ForkPoint = 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 inversify_1 = require("inversify");
10
10
  const git_readAiBranchName_1 = require("./git-readAiBranchName");
11
+ const git_exec_1 = require("./git-exec");
11
12
  const merge_state_1 = require("./merge-state");
12
13
  const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
13
14
  /** Computes the 3-point fork point and guards against improper merges-from-main. */
@@ -15,10 +16,14 @@ let ForkPoint = class ForkPoint {
15
16
  repoRootFinder;
16
17
  aiBranchName;
17
18
  mergeState;
18
- constructor(repoRootFinder, aiBranchName, mergeState) {
19
+ gitExec;
20
+ git;
21
+ constructor(repoRootFinder, aiBranchName, mergeState, gitExec, git) {
19
22
  this.repoRootFinder = repoRootFinder;
20
23
  this.aiBranchName = aiBranchName;
21
24
  this.mergeState = mergeState;
25
+ this.gitExec = gitExec;
26
+ this.git = git;
22
27
  }
23
28
  // Single source of truth for the per-feature dir fork-point output is written to — the SAME nested
24
29
  // home the readers use (git-gatherInfo / merge-start read updatemain-hashes.json from mergeDirFor;
@@ -41,11 +46,11 @@ let ForkPoint = class ForkPoint {
41
46
  * Also writes no files and runs no merge-commit scan, so it cannot throw: `wp-review-upsert-pr` must always
42
47
  * succeed, and a raw merge-from-main is the merge flow's problem to report, not the checklist's.
43
48
  */
44
- resolveForkPoint(repoRoot) {
49
+ async resolveForkPoint(repoRoot) {
45
50
  for (const ref of ['origin/main', 'main']) {
46
- const result = (0, child_process_1.spawnSync)('git', ['merge-base', ref, 'HEAD'], { cwd: repoRoot, encoding: 'utf8' });
47
- const sha = (result.stdout ?? '').trim();
48
- if (result.status === 0 && sha !== '')
51
+ const result = await this.git.run(['merge-base', ref, 'HEAD'], repoRoot);
52
+ const sha = result.stdout.trim();
53
+ if (result.ok && sha !== '')
49
54
  return sha;
50
55
  }
51
56
  return '';
@@ -56,29 +61,30 @@ let ForkPoint = class ForkPoint {
56
61
  'Usage: git-findForkPoint <workflow>\n' +
57
62
  " workflow: 'review' or 'merge'");
58
63
  }
59
- const featureName = this.aiBranchName.getFeatureName();
60
- const currentBranch = (0, child_process_1.execSync)('git branch --show-current', { encoding: 'utf8' }).trim();
61
- const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());
64
+ const cwd = process.cwd();
65
+ const featureName = await this.aiBranchName.getFeatureName();
66
+ const currentBranch = await this.gitExec.currentBranch(cwd);
67
+ const repoRoot = this.repoRootFinder.resolveRepoRoot(cwd);
62
68
  const outputDir = this.forkPointOutputDir(repoRoot, featureName, workflow);
63
69
  const prefix = workflow === 'review' ? 'review-' : 'updatemain-';
64
70
  fs.mkdirSync(outputDir, { recursive: true });
65
- (0, child_process_1.spawnSync)('git', ['fetch', 'origin', 'main'], { stdio: 'ignore' });
66
- const featureHead = (0, child_process_1.execSync)('git rev-parse HEAD', { encoding: 'utf8' }).trim();
67
- const originMain = (0, child_process_1.execSync)('git rev-parse origin/main', { encoding: 'utf8' }).trim();
71
+ await this.git.run(['fetch', 'origin', 'main']);
72
+ const featureHead = await this.gitExec.gitQuery(['rev-parse', 'HEAD'], cwd, 'Failed to read HEAD (git rev-parse HEAD).');
73
+ const originMain = await this.gitExec.gitQuery(['rev-parse', 'origin/main'], cwd, 'Failed to read origin/main (git rev-parse origin/main).');
68
74
  process.stderr.write('Finding fork point using git merge-base...\n');
69
75
  // ONE implementation of the fork-point computation, shared with ChecklistScanner. The fetch above is
70
76
  // what this flow needs beyond it (hash point C = main's current head), not the fork point itself.
71
- const forkPoint = this.resolveForkPoint(repoRoot);
77
+ const forkPoint = await this.resolveForkPoint(repoRoot);
72
78
  if (!forkPoint) {
73
79
  throw new rules_config_1.CliExitError(1, 'ERROR: Could not find common ancestor with origin/main');
74
80
  }
75
81
  process.stderr.write(`✅ Fork point found: ${forkPoint.slice(0, 7)}\n`);
76
82
  process.stderr.write('Checking for improper merges from main...\n');
77
- const mergeCommitsResult = (0, child_process_1.spawnSync)('git', ['log', `${forkPoint}..HEAD`, '--merges', '--format=%H'], { encoding: 'utf8' });
78
- const mergeCommitsRaw = (mergeCommitsResult.stdout ?? '').trim();
83
+ const mergeCommitsResult = await this.git.run(['log', `${forkPoint}..HEAD`, '--merges', '--format=%H']);
84
+ const mergeCommitsRaw = mergeCommitsResult.stdout.trim();
79
85
  const mergeCommits = mergeCommitsRaw ? mergeCommitsRaw.split('\n') : [];
80
86
  if (mergeCommits.length > 0) {
81
- this.checkMergeCommits(mergeCommits, outputDir, prefix, featureName, currentBranch);
87
+ await this.checkMergeCommits(mergeCommits, outputDir, prefix, featureName, currentBranch);
82
88
  }
83
89
  else {
84
90
  process.stderr.write('✅ No merge commits found (clean history)\n');
@@ -92,15 +98,15 @@ let ForkPoint = class ForkPoint {
92
98
  fs.writeFileSync(path.join(outputDir, `${prefix}hashes.json`), hashesJson + '\n');
93
99
  process.stderr.write(`✅ Hash points written to: ${outputDir}/${prefix}hashes.json\n`);
94
100
  }
95
- checkMergeCommits(mergeCommits, outputDir, prefix, featureName, currentBranch) {
101
+ async checkMergeCommits(mergeCommits, outputDir, prefix, featureName, currentBranch) {
96
102
  process.stderr.write(`Found ${mergeCommits.length} merge commit(s) to check...\n`);
97
103
  for (const commit of mergeCommits) {
98
- const parentsResult = (0, child_process_1.spawnSync)('git', ['rev-list', '--parents', '-n', '1', commit], { encoding: 'utf8' });
99
- const parents = (parentsResult.stdout ?? '').trim().split(' ').slice(1);
104
+ const parentsResult = await this.git.run(['rev-list', '--parents', '-n', '1', commit]);
105
+ const parents = parentsResult.stdout.trim().split(' ').slice(1);
100
106
  for (const parent of parents) {
101
- const ancestorCheck = (0, child_process_1.spawnSync)('git', ['merge-base', '--is-ancestor', parent, 'origin/main']);
102
- const reverseCheck = (0, child_process_1.spawnSync)('git', ['merge-base', '--is-ancestor', 'origin/main', parent]);
103
- if (ancestorCheck.status === 0 && reverseCheck.status === 0) {
107
+ const ancestorCheck = await this.git.run(['merge-base', '--is-ancestor', parent, 'origin/main']);
108
+ const reverseCheck = await this.git.run(['merge-base', '--is-ancestor', 'origin/main', parent]);
109
+ if (ancestorCheck.ok && reverseCheck.ok) {
104
110
  const errorJson = JSON.stringify({
105
111
  error: 'Merge from main detected',
106
112
  mergeCommit: commit,
@@ -166,6 +172,8 @@ exports.ForkPoint = ForkPoint = tslib_1.__decorate([
166
172
  (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
167
173
  tslib_1.__metadata("design:paramtypes", [rules_config_1.RepoRootFinder,
168
174
  git_readAiBranchName_1.AiBranchName,
169
- merge_state_1.MergeState])
175
+ merge_state_1.MergeState,
176
+ git_exec_1.GitExec,
177
+ tooling_common_1.GitProcessApi])
170
178
  ], ForkPoint);
171
179
  //# sourceMappingURL=git-findForkPoint.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"git-findForkPoint.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/git-findForkPoint.ts"],"names":[],"mappings":";;;;AAAA,iDAAoD;AACpD,+CAAyB;AACzB,mDAA6B;AAC7B,0DAAiF;AACjF,yCAA2D;AAC3D,iEAAsD;AACtD,+CAA2C;AAE3C,MAAM,GAAG,GAAG,0DAA0D,CAAC;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CAAC,iDAAiD,aAAa,KAAK,CAAC,CAAC;QAC1F,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,kCAAkC,CAAC,CAAC;QACzD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,4BAA4B,WAAW,OAAO,CAAC,CAAC;QACrE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA6B,aAAa,IAAI,CAAC,CAAC;QACrE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC1B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;CACJ,CAAA;AAvKY,8BAAS;oBAAT,SAAS;IADrB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QAChB,mCAAY;QACd,wBAAU;GAJlC,SAAS,CAuKrB","sourcesContent":["import { execSync, spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { prDirFor, CliExitError, RepoRootFinder } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from './git-readAiBranchName';\nimport { MergeState } from './merge-state';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/** Computes the 3-point fork point and guards against improper merges-from-main. */\n@injectable(bindingScopeValues.Singleton)\nexport class ForkPoint {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly mergeState: MergeState,\n ) {}\n\n // Single source of truth for the per-feature dir fork-point output is written to — the SAME nested\n // home the readers use (git-gatherInfo / merge-start read updatemain-hashes.json from mergeDirFor;\n // the review flow reads from prDirFor). Routing the writer through these same helpers is what keeps\n // them from diverging again — guarded by git-findForkPoint.spec.ts.\n forkPointOutputDir(repoRoot: string, featureName: string, workflow: string): string {\n return workflow === 'review' ? prDirFor(repoRoot, featureName) : this.mergeState.mergeDirFor(repoRoot, featureName);\n }\n\n /**\n * The 3-point FORK POINT: where this branch diverged from main. `git merge-base origin/main HEAD`,\n * falling back to a local `main`, and '' when neither ref resolves.\n *\n * Deliberately does NOT fetch. The fork point is ABSOLUTE — advancing main cannot move it, because\n * merge-base is the most recent common ancestor and main's new commits are not on this branch. (Verified\n * on this repo: main went f415456 → ba8f674 → 61432d6 while merge-base with one branch stayed f415456\n * throughout.) So a caller that needs only the fork point — see ChecklistScanner — pays no network cost\n * and works offline. `findForkPoint` below still fetches, because the MERGE flow additionally needs\n * main's CURRENT head as hash point C, which genuinely does require a fetch.\n *\n * Also writes no files and runs no merge-commit scan, so it cannot throw: `wp-review-upsert-pr` must always\n * succeed, and a raw merge-from-main is the merge flow's problem to report, not the checklist's.\n */\n resolveForkPoint(repoRoot: string): string {\n for (const ref of ['origin/main', 'main']) {\n const result = spawnSync('git', ['merge-base', ref, 'HEAD'], { cwd: repoRoot, encoding: 'utf8' });\n const sha = (result.stdout ?? '').trim();\n if (result.status === 0 && sha !== '') return sha;\n }\n return '';\n }\n\n async findForkPoint(workflow: string): Promise<void> {\n if (workflow !== 'review' && workflow !== 'merge') {\n throw new CliExitError(1,\n 'ERROR: Workflow argument required\\n' +\n 'Usage: git-findForkPoint <workflow>\\n' +\n \" workflow: 'review' or 'merge'\",\n );\n }\n\n const featureName = this.aiBranchName.getFeatureName();\n const currentBranch = execSync('git branch --show-current', { encoding: 'utf8' }).trim();\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n\n const outputDir = this.forkPointOutputDir(repoRoot, featureName, workflow);\n const prefix = workflow === 'review' ? 'review-' : 'updatemain-';\n fs.mkdirSync(outputDir, { recursive: true });\n\n spawnSync('git', ['fetch', 'origin', 'main'], { stdio: 'ignore' });\n\n const featureHead = execSync('git rev-parse HEAD', { encoding: 'utf8' }).trim();\n const originMain = execSync('git rev-parse origin/main', { encoding: 'utf8' }).trim();\n\n process.stderr.write('Finding fork point using git merge-base...\\n');\n\n // ONE implementation of the fork-point computation, shared with ChecklistScanner. The fetch above is\n // what this flow needs beyond it (hash point C = main's current head), not the fork point itself.\n const forkPoint = this.resolveForkPoint(repoRoot);\n\n if (!forkPoint) {\n throw new CliExitError(1, 'ERROR: Could not find common ancestor with origin/main');\n }\n\n process.stderr.write(`✅ Fork point found: ${forkPoint.slice(0, 7)}\\n`);\n process.stderr.write('Checking for improper merges from main...\\n');\n\n const mergeCommitsResult = spawnSync('git', ['log', `${forkPoint}..HEAD`, '--merges', '--format=%H'], { encoding: 'utf8' });\n const mergeCommitsRaw = (mergeCommitsResult.stdout ?? '').trim();\n const mergeCommits = mergeCommitsRaw ? mergeCommitsRaw.split('\\n') : [];\n\n if (mergeCommits.length > 0) {\n this.checkMergeCommits(mergeCommits, outputDir, prefix, featureName, currentBranch);\n } else {\n process.stderr.write('✅ No merge commits found (clean history)\\n');\n }\n\n const hashesJson = JSON.stringify({\n hashForkPoint: forkPoint,\n hashFeatureHead: featureHead,\n hashMainHead: originMain,\n timestamp: new Date().toISOString(),\n }, null, 2);\n\n fs.writeFileSync(path.join(outputDir, `${prefix}hashes.json`), hashesJson + '\\n');\n process.stderr.write(`✅ Hash points written to: ${outputDir}/${prefix}hashes.json\\n`);\n }\n\n private checkMergeCommits(mergeCommits: string[], outputDir: string, prefix: string, featureName: string, currentBranch: string): void {\n process.stderr.write(`Found ${mergeCommits.length} merge commit(s) to check...\\n`);\n\n for (const commit of mergeCommits) {\n const parentsResult = spawnSync('git', ['rev-list', '--parents', '-n', '1', commit], { encoding: 'utf8' });\n const parents = (parentsResult.stdout ?? '').trim().split(' ').slice(1);\n\n for (const parent of parents) {\n const ancestorCheck = spawnSync('git', ['merge-base', '--is-ancestor', parent, 'origin/main']);\n const reverseCheck = spawnSync('git', ['merge-base', '--is-ancestor', 'origin/main', parent]);\n\n if (ancestorCheck.status === 0 && reverseCheck.status === 0) {\n const errorJson = JSON.stringify({\n error: 'Merge from main detected',\n mergeCommit: commit,\n parentFromMain: parent,\n timestamp: new Date().toISOString(),\n }, null, 2);\n\n fs.writeFileSync(path.join(outputDir, `${prefix}forkpoint-error.json`), errorJson + '\\n');\n this.printMergeFromMainError(commit, parent, featureName, currentBranch);\n throw new CliExitError(1, '');\n }\n }\n }\n process.stderr.write('✅ No improper merges from main detected\\n');\n }\n\n private printMergeFromMainError(commit: string, parent: string, featureName: string, currentBranch: string): void {\n process.stderr.write('\\n');\n process.stderr.write(SEP);\n process.stderr.write('❌ This branch merged main without the gated update (pnpm wp-start-update, or\\n');\n process.stderr.write(' pnpm wp-start-upsert-pr when a PR is open)\\n');\n process.stderr.write(SEP);\n process.stderr.write('\\n');\n process.stderr.write(`Merge commit detected: ${commit}\\n`);\n process.stderr.write(`Parent from main: ${parent}\\n`);\n process.stderr.write('\\n');\n process.stderr.write('This prevents clean squash-merge. To recover, follow these steps:\\n');\n process.stderr.write('\\n');\n process.stderr.write('1. Fetch the latest main (works on the primary repo AND in a worktree):\\n');\n process.stderr.write(' git fetch origin main\\n');\n process.stderr.write('\\n');\n // The \"do NOT `git checkout main`\" caveat is scoped to the WORKTREE case, where it is true.\n // Stated unconditionally it forbids a command that is perfectly good in the primary clone —\n // and that `.claude/rules/finishing-a-feature.md`'s own post-merge cleanup recipe uses\n // — which is how an agent talked\n // itself into believing a new branch was its only exit.\n process.stderr.write('2. Create a new branch OFF origin/main (this form works from ANY tree; inside a\\n');\n process.stderr.write(' worktree do NOT `git checkout main` first — it fatals with \"main is already\\n');\n process.stderr.write(' checked out at <primary>\"):\\n');\n process.stderr.write(` git checkout -b ${featureName}-v2 origin/main\\n`);\n process.stderr.write('\\n');\n process.stderr.write('3. Squash merge your old branch — THIS STEP IS FOR THE HUMAN TO RUN:\\n');\n process.stderr.write(` git merge --squash ${currentBranch}\\n`);\n process.stderr.write(' AI: `git merge` is blocked for you (redirect-how-to-merge-main) and you must NOT\\n');\n process.stderr.write(' work around it. Ask the human to run that one command, and warn them:\\n');\n process.stderr.write(' \"This is a raw git merge. It is only correct here because the branch is already\\n');\n process.stderr.write(' broken and is being rebuilt onto origin/main. For a NORMAL update from main,\\n');\n process.stderr.write(' push back and tell me to use the gated 3-point merge instead: `pnpm wp-start-update`\\n');\n process.stderr.write(' (paired with `pnpm wp-finish-update`) when no PR is open, or `pnpm wp-start-upsert-pr`\\n');\n process.stderr.write(' (paired with `pnpm wp-finish-upsert-pr`) when one is.\"\\n');\n process.stderr.write('\\n');\n process.stderr.write('4. Commit the squashed changes:\\n');\n process.stderr.write(` git add -A && git commit -m \"Squashed from ${currentBranch}\"\\n`);\n process.stderr.write('\\n');\n process.stderr.write('5. If you have an existing PR:\\n');\n process.stderr.write(` - Create a NEW PR for ${featureName}-v2\\n`);\n process.stderr.write(` - Close the old PR for ${currentBranch}\\n`);\n process.stderr.write('\\n');\n process.stderr.write(SEP);\n process.stderr.write('\\n');\n }\n}\n"]}
1
+ {"version":3,"file":"git-findForkPoint.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/git-findForkPoint.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAC7B,0DAAiF;AACjF,8DAA0D;AAC1D,yCAA2D;AAC3D,iEAAsD;AACtD,yCAAqC;AACrC,+CAA2C;AAE3C,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,oFAAoF;AAE7E,IAAM,SAAS,GAAf,MAAM,SAAS;IAEG;IACA;IACA;IACA;IACA;IALrB,YACqB,cAA8B,EAC9B,YAA0B,EAC1B,UAAsB,EACtB,OAAgB,EAChB,GAAkB;QAJlB,mBAAc,GAAd,cAAc,CAAgB;QAC9B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,eAAU,GAAV,UAAU,CAAY;QACtB,YAAO,GAAP,OAAO,CAAS;QAChB,QAAG,GAAH,GAAG,C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KAAK,CAAC,IAAI,CAAC,CAAC;QAC3B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC1B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;CACJ,CAAA;AA1KY,8BAAS;oBAAT,SAAS;IADrB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QAChB,mCAAY;QACd,wBAAU;QACb,kBAAO;QACX,8BAAa;GAN9B,SAAS,CA0KrB","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport { prDirFor, CliExitError, RepoRootFinder } from '@webpieces/rules-config';\nimport { GitProcessApi } from '@webpieces/tooling-common';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from './git-readAiBranchName';\nimport { GitExec } from './git-exec';\nimport { MergeState } from './merge-state';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/** Computes the 3-point fork point and guards against improper merges-from-main. */\n@injectable(bindingScopeValues.Singleton)\nexport class ForkPoint {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly mergeState: MergeState,\n private readonly gitExec: GitExec,\n private readonly git: GitProcessApi,\n ) {}\n\n // Single source of truth for the per-feature dir fork-point output is written to — the SAME nested\n // home the readers use (git-gatherInfo / merge-start read updatemain-hashes.json from mergeDirFor;\n // the review flow reads from prDirFor). Routing the writer through these same helpers is what keeps\n // them from diverging again — guarded by git-findForkPoint.spec.ts.\n forkPointOutputDir(repoRoot: string, featureName: string, workflow: string): string {\n return workflow === 'review' ? prDirFor(repoRoot, featureName) : this.mergeState.mergeDirFor(repoRoot, featureName);\n }\n\n /**\n * The 3-point FORK POINT: where this branch diverged from main. `git merge-base origin/main HEAD`,\n * falling back to a local `main`, and '' when neither ref resolves.\n *\n * Deliberately does NOT fetch. The fork point is ABSOLUTE — advancing main cannot move it, because\n * merge-base is the most recent common ancestor and main's new commits are not on this branch. (Verified\n * on this repo: main went f415456 → ba8f674 → 61432d6 while merge-base with one branch stayed f415456\n * throughout.) So a caller that needs only the fork point — see ChecklistScanner — pays no network cost\n * and works offline. `findForkPoint` below still fetches, because the MERGE flow additionally needs\n * main's CURRENT head as hash point C, which genuinely does require a fetch.\n *\n * Also writes no files and runs no merge-commit scan, so it cannot throw: `wp-review-upsert-pr` must always\n * succeed, and a raw merge-from-main is the merge flow's problem to report, not the checklist's.\n */\n async resolveForkPoint(repoRoot: string): Promise<string> {\n for (const ref of ['origin/main', 'main']) {\n const result = await this.git.run(['merge-base', ref, 'HEAD'], repoRoot);\n const sha = result.stdout.trim();\n if (result.ok && sha !== '') return sha;\n }\n return '';\n }\n\n async findForkPoint(workflow: string): Promise<void> {\n if (workflow !== 'review' && workflow !== 'merge') {\n throw new CliExitError(1,\n 'ERROR: Workflow argument required\\n' +\n 'Usage: git-findForkPoint <workflow>\\n' +\n \" workflow: 'review' or 'merge'\",\n );\n }\n\n const cwd = process.cwd();\n const featureName = await this.aiBranchName.getFeatureName();\n const currentBranch = await this.gitExec.currentBranch(cwd);\n const repoRoot = this.repoRootFinder.resolveRepoRoot(cwd);\n\n const outputDir = this.forkPointOutputDir(repoRoot, featureName, workflow);\n const prefix = workflow === 'review' ? 'review-' : 'updatemain-';\n fs.mkdirSync(outputDir, { recursive: true });\n\n await this.git.run(['fetch', 'origin', 'main']);\n\n const featureHead = await this.gitExec.gitQuery(['rev-parse', 'HEAD'], cwd, 'Failed to read HEAD (git rev-parse HEAD).');\n const originMain = await this.gitExec.gitQuery(['rev-parse', 'origin/main'], cwd, 'Failed to read origin/main (git rev-parse origin/main).');\n\n process.stderr.write('Finding fork point using git merge-base...\\n');\n\n // ONE implementation of the fork-point computation, shared with ChecklistScanner. The fetch above is\n // what this flow needs beyond it (hash point C = main's current head), not the fork point itself.\n const forkPoint = await this.resolveForkPoint(repoRoot);\n\n if (!forkPoint) {\n throw new CliExitError(1, 'ERROR: Could not find common ancestor with origin/main');\n }\n\n process.stderr.write(`✅ Fork point found: ${forkPoint.slice(0, 7)}\\n`);\n process.stderr.write('Checking for improper merges from main...\\n');\n\n const mergeCommitsResult = await this.git.run(['log', `${forkPoint}..HEAD`, '--merges', '--format=%H']);\n const mergeCommitsRaw = mergeCommitsResult.stdout.trim();\n const mergeCommits = mergeCommitsRaw ? mergeCommitsRaw.split('\\n') : [];\n\n if (mergeCommits.length > 0) {\n await this.checkMergeCommits(mergeCommits, outputDir, prefix, featureName, currentBranch);\n } else {\n process.stderr.write('✅ No merge commits found (clean history)\\n');\n }\n\n const hashesJson = JSON.stringify({\n hashForkPoint: forkPoint,\n hashFeatureHead: featureHead,\n hashMainHead: originMain,\n timestamp: new Date().toISOString(),\n }, null, 2);\n\n fs.writeFileSync(path.join(outputDir, `${prefix}hashes.json`), hashesJson + '\\n');\n process.stderr.write(`✅ Hash points written to: ${outputDir}/${prefix}hashes.json\\n`);\n }\n\n private async checkMergeCommits(mergeCommits: string[], outputDir: string, prefix: string, featureName: string, currentBranch: string): Promise<void> {\n process.stderr.write(`Found ${mergeCommits.length} merge commit(s) to check...\\n`);\n\n for (const commit of mergeCommits) {\n const parentsResult = await this.git.run(['rev-list', '--parents', '-n', '1', commit]);\n const parents = parentsResult.stdout.trim().split(' ').slice(1);\n\n for (const parent of parents) {\n const ancestorCheck = await this.git.run(['merge-base', '--is-ancestor', parent, 'origin/main']);\n const reverseCheck = await this.git.run(['merge-base', '--is-ancestor', 'origin/main', parent]);\n\n if (ancestorCheck.ok && reverseCheck.ok) {\n const errorJson = JSON.stringify({\n error: 'Merge from main detected',\n mergeCommit: commit,\n parentFromMain: parent,\n timestamp: new Date().toISOString(),\n }, null, 2);\n\n fs.writeFileSync(path.join(outputDir, `${prefix}forkpoint-error.json`), errorJson + '\\n');\n this.printMergeFromMainError(commit, parent, featureName, currentBranch);\n throw new CliExitError(1, '');\n }\n }\n }\n process.stderr.write('✅ No improper merges from main detected\\n');\n }\n\n private printMergeFromMainError(commit: string, parent: string, featureName: string, currentBranch: string): void {\n process.stderr.write('\\n');\n process.stderr.write(SEP);\n process.stderr.write('❌ This branch merged main without the gated update (pnpm wp-start-update, or\\n');\n process.stderr.write(' pnpm wp-start-upsert-pr when a PR is open)\\n');\n process.stderr.write(SEP);\n process.stderr.write('\\n');\n process.stderr.write(`Merge commit detected: ${commit}\\n`);\n process.stderr.write(`Parent from main: ${parent}\\n`);\n process.stderr.write('\\n');\n process.stderr.write('This prevents clean squash-merge. To recover, follow these steps:\\n');\n process.stderr.write('\\n');\n process.stderr.write('1. Fetch the latest main (works on the primary repo AND in a worktree):\\n');\n process.stderr.write(' git fetch origin main\\n');\n process.stderr.write('\\n');\n // The \"do NOT `git checkout main`\" caveat is scoped to the WORKTREE case, where it is true.\n // Stated unconditionally it forbids a command that is perfectly good in the primary clone —\n // and that `.claude/rules/finishing-a-feature.md`'s own post-merge cleanup recipe uses\n // — which is how an agent talked\n // itself into believing a new branch was its only exit.\n process.stderr.write('2. Create a new branch OFF origin/main (this form works from ANY tree; inside a\\n');\n process.stderr.write(' worktree do NOT `git checkout main` first — it fatals with \"main is already\\n');\n process.stderr.write(' checked out at <primary>\"):\\n');\n process.stderr.write(` git checkout -b ${featureName}-v2 origin/main\\n`);\n process.stderr.write('\\n');\n process.stderr.write('3. Squash merge your old branch — THIS STEP IS FOR THE HUMAN TO RUN:\\n');\n process.stderr.write(` git merge --squash ${currentBranch}\\n`);\n process.stderr.write(' AI: `git merge` is blocked for you (redirect-how-to-merge-main) and you must NOT\\n');\n process.stderr.write(' work around it. Ask the human to run that one command, and warn them:\\n');\n process.stderr.write(' \"This is a raw git merge. It is only correct here because the branch is already\\n');\n process.stderr.write(' broken and is being rebuilt onto origin/main. For a NORMAL update from main,\\n');\n process.stderr.write(' push back and tell me to use the gated 3-point merge instead: `pnpm wp-start-update`\\n');\n process.stderr.write(' (paired with `pnpm wp-finish-update`) when no PR is open, or `pnpm wp-start-upsert-pr`\\n');\n process.stderr.write(' (paired with `pnpm wp-finish-upsert-pr`) when one is.\"\\n');\n process.stderr.write('\\n');\n process.stderr.write('4. Commit the squashed changes:\\n');\n process.stderr.write(` git add -A && git commit -m \"Squashed from ${currentBranch}\"\\n`);\n process.stderr.write('\\n');\n process.stderr.write('5. If you have an existing PR:\\n');\n process.stderr.write(` - Create a NEW PR for ${featureName}-v2\\n`);\n process.stderr.write(` - Close the old PR for ${currentBranch}\\n`);\n process.stderr.write('\\n');\n process.stderr.write(SEP);\n process.stderr.write('\\n');\n }\n}\n"]}
@@ -1,7 +1,9 @@
1
1
  import { BranchNaming } from './branch-naming';
2
+ import { GitExec } from './git-exec';
2
3
  /** The stable feature identity used to key the merge-context + PR-body dirs. */
3
4
  export declare class AiBranchName {
4
5
  private readonly branchNaming;
5
- constructor(branchNaming: BranchNaming);
6
- getFeatureName(): string;
6
+ private readonly gitExec;
7
+ constructor(branchNaming: BranchNaming, gitExec: GitExec);
8
+ getFeatureName(): Promise<string>;
7
9
  }
@@ -2,26 +2,29 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AiBranchName = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const child_process_1 = require("child_process");
6
5
  const inversify_1 = require("inversify");
7
6
  const branch_naming_1 = require("./branch-naming");
7
+ const git_exec_1 = require("./git-exec");
8
8
  /** The stable feature identity used to key the merge-context + PR-body dirs. */
9
9
  let AiBranchName = class AiBranchName {
10
10
  branchNaming;
11
- constructor(branchNaming) {
11
+ gitExec;
12
+ constructor(branchNaming, gitExec) {
12
13
  this.branchNaming = branchNaming;
14
+ this.gitExec = gitExec;
13
15
  }
14
16
  // Stable feature identity used to key the merge-context dir and PR-body dir. It MUST stay constant
15
17
  // across a sync's transient `<feature>Squash` temp branch (and any leftover `…wpN` from the old
16
18
  // scheme), so derive it from baseBranchName (strips `Squash` + a legacy `wpN`) before slugifying.
17
- getFeatureName() {
18
- const branch = (0, child_process_1.execSync)('git branch --show-current', { encoding: 'utf8' }).trim();
19
+ async getFeatureName() {
20
+ const branch = await this.gitExec.currentBranch(process.cwd());
19
21
  return this.branchNaming.baseBranchName(branch).replace(/\//g, '-');
20
22
  }
21
23
  };
22
24
  exports.AiBranchName = AiBranchName;
23
25
  exports.AiBranchName = AiBranchName = tslib_1.__decorate([
24
26
  (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
25
- tslib_1.__metadata("design:paramtypes", [branch_naming_1.BranchNaming])
27
+ tslib_1.__metadata("design:paramtypes", [branch_naming_1.BranchNaming,
28
+ git_exec_1.GitExec])
26
29
  ], AiBranchName);
27
30
  //# sourceMappingURL=git-readAiBranchName.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"git-readAiBranchName.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/git-readAiBranchName.ts"],"names":[],"mappings":";;;;AAAA,iDAAyC;AACzC,yCAA2D;AAC3D,mDAA+C;AAE/C,gFAAgF;AAEzE,IAAM,YAAY,GAAlB,MAAM,YAAY;IACQ;IAA7B,YAA6B,YAA0B;QAA1B,iBAAY,GAAZ,YAAY,CAAc;IAAG,CAAC;IAE3D,mGAAmG;IACnG,gGAAgG;IAChG,kGAAkG;IAClG,cAAc;QACV,MAAM,MAAM,GAAG,IAAA,wBAAQ,EAAC,2BAA2B,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAClF,OAAO,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACxE,CAAC;CACJ,CAAA;AAVY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEM,4BAAY;GAD9C,YAAY,CAUxB","sourcesContent":["import { execSync } from 'child_process';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { BranchNaming } from './branch-naming';\n\n/** The stable feature identity used to key the merge-context + PR-body dirs. */\n@injectable(bindingScopeValues.Singleton)\nexport class AiBranchName {\n constructor(private readonly branchNaming: BranchNaming) {}\n\n // Stable feature identity used to key the merge-context dir and PR-body dir. It MUST stay constant\n // across a sync's transient `<feature>Squash` temp branch (and any leftover `…wpN` from the old\n // scheme), so derive it from baseBranchName (strips `Squash` + a legacy `wpN`) before slugifying.\n getFeatureName(): string {\n const branch = execSync('git branch --show-current', { encoding: 'utf8' }).trim();\n return this.branchNaming.baseBranchName(branch).replace(/\\//g, '-');\n }\n}\n"]}
1
+ {"version":3,"file":"git-readAiBranchName.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/git-readAiBranchName.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,mDAA+C;AAC/C,yCAAqC;AAErC,gFAAgF;AAEzE,IAAM,YAAY,GAAlB,MAAM,YAAY;IAEA;IACA;IAFrB,YACqB,YAA0B,EAC1B,OAAgB;QADhB,iBAAY,GAAZ,YAAY,CAAc;QAC1B,YAAO,GAAP,OAAO,CAAS;IAClC,CAAC;IAEJ,mGAAmG;IACnG,gGAAgG;IAChG,kGAAkG;IAClG,KAAK,CAAC,cAAc;QAChB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QAC/D,OAAO,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACxE,CAAC;CACJ,CAAA;AAbY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGF,4BAAY;QACjB,kBAAO;GAH5B,YAAY,CAaxB","sourcesContent":["import { injectable, bindingScopeValues } from 'inversify';\nimport { BranchNaming } from './branch-naming';\nimport { GitExec } from './git-exec';\n\n/** The stable feature identity used to key the merge-context + PR-body dirs. */\n@injectable(bindingScopeValues.Singleton)\nexport class AiBranchName {\n constructor(\n private readonly branchNaming: BranchNaming,\n private readonly gitExec: GitExec,\n ) {}\n\n // Stable feature identity used to key the merge-context dir and PR-body dir. It MUST stay constant\n // across a sync's transient `<feature>Squash` temp branch (and any leftover `…wpN` from the old\n // scheme), so derive it from baseBranchName (strips `Squash` + a legacy `wpN`) before slugifying.\n async getFeatureName(): Promise<string> {\n const branch = await this.gitExec.currentBranch(process.cwd());\n return this.branchNaming.baseBranchName(branch).replace(/\\//g, '-');\n }\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import { NativeProcessApi } from '@webpieces/tooling-common';
1
2
  import { GatedPrPublisher } from './gated-pr-publisher';
2
3
  import { GitExec } from './git-exec';
3
4
  /**
@@ -14,8 +15,8 @@ import { GitExec } from './git-exec';
14
15
  */
15
16
  export declare class HotfixPrPublisher extends GatedPrPublisher {
16
17
  private readonly hotfixGit;
17
- constructor(hotfixGit: GitExec);
18
+ constructor(hotfixGit: GitExec, processes: NativeProcessApi);
18
19
  /** Fast-forward-only push of HEAD to origin/<branch>, run in `cwd`. Throws on any failure. */
19
- pushFastForward(cwd: string, branch: string): void;
20
- protected push(baseBranch: string): void;
20
+ pushFastForward(cwd: string, branch: string): Promise<void>;
21
+ protected push(baseBranch: string): Promise<void>;
21
22
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HotfixPrPublisher = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const rules_config_1 = require("@webpieces/rules-config");
6
+ const tooling_common_1 = require("@webpieces/tooling-common");
6
7
  const inversify_1 = require("inversify");
7
8
  const gated_pr_publisher_1 = require("./gated-pr-publisher");
8
9
  const git_exec_1 = require("./git-exec");
@@ -20,13 +21,13 @@ const git_exec_1 = require("./git-exec");
20
21
  */
21
22
  let HotfixPrPublisher = class HotfixPrPublisher extends gated_pr_publisher_1.GatedPrPublisher {
22
23
  hotfixGit;
23
- constructor(hotfixGit) {
24
- super(hotfixGit);
24
+ constructor(hotfixGit, processes) {
25
+ super(hotfixGit, processes);
25
26
  this.hotfixGit = hotfixGit;
26
27
  }
27
28
  /** Fast-forward-only push of HEAD to origin/<branch>, run in `cwd`. Throws on any failure. */
28
- pushFastForward(cwd, branch) {
29
- const out = this.hotfixGit.tryGit(['push', '-u', 'origin', `HEAD:${branch}`], cwd);
29
+ async pushFastForward(cwd, branch) {
30
+ const out = await this.hotfixGit.tryGit(['push', '-u', 'origin', `HEAD:${branch}`], cwd);
30
31
  if (out.ok)
31
32
  return;
32
33
  throw new rules_config_1.CliExitError(1, `❌ git push of the hotfix branch '${branch}' failed (exit ${String(out.status)}). A hotfix push is\n` +
@@ -35,12 +36,12 @@ let HotfixPrPublisher = class HotfixPrPublisher extends gated_pr_publisher_1.Gat
35
36
  ` git said: ${out.stderr === '' ? '(nothing)' : out.stderr}`);
36
37
  }
37
38
  push(baseBranch) {
38
- this.pushFastForward(process.cwd(), baseBranch);
39
+ return this.pushFastForward(process.cwd(), baseBranch);
39
40
  }
40
41
  };
41
42
  exports.HotfixPrPublisher = HotfixPrPublisher;
42
43
  exports.HotfixPrPublisher = HotfixPrPublisher = tslib_1.__decorate([
43
44
  (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
44
- tslib_1.__metadata("design:paramtypes", [git_exec_1.GitExec])
45
+ tslib_1.__metadata("design:paramtypes", [git_exec_1.GitExec, tooling_common_1.NativeProcessApi])
45
46
  ], HotfixPrPublisher);
46
47
  //# sourceMappingURL=hotfix-pr-publisher.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hotfix-pr-publisher.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/hotfix-pr-publisher.ts"],"names":[],"mappings":";;;;AAAA,0DAAuD;AACvD,yCAA2D;AAC3D,6DAAwD;AACxD,yCAAqC;AAErC;;;;;;;;;;;GAWG;AAEI,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,qCAAgB;IACtB;IAA7B,YAA6B,SAAkB;QAC3C,KAAK,CAAC,SAAS,CAAC,CAAC;QADQ,cAAS,GAAT,SAAS,CAAS;IAE/C,CAAC;IAED,8FAA8F;IAC9F,eAAe,CAAC,GAAW,EAAE,MAAc;QACvC,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,MAAM,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;QACnF,IAAI,GAAG,CAAC,EAAE;YAAE,OAAO;QACnB,MAAM,IAAI,2BAAY,CAClB,CAAC,EACD,oCAAoC,MAAM,kBAAkB,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,uBAAuB;YACjG,mGAAmG;YACnG,wBAAwB;YACxB,gBAAgB,GAAG,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,CACrE,CAAC;IACN,CAAC;IAEkB,IAAI,CAAC,UAAkB;QACtC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,CAAC,CAAC;IACpD,CAAC;CACJ,CAAA;AArBY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEG,kBAAO;GADtC,iBAAiB,CAqB7B","sourcesContent":["import { CliExitError } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { GatedPrPublisher } from './gated-pr-publisher';\nimport { GitExec } from './git-exec';\n\n/**\n * The gated publisher for a `/hotfix/` branch: the same body-before-push ordering, with a push that can\n * NEVER rewrite the remote branch.\n *\n * The normal flow pushes with `--force-with-lease`, because its 3-point squash rewrites history on every\n * update. A hotfix branch is never rewritten — it only ever grows by the fix commits added on top of the\n * production sha — so its push is a plain fast-forward. If the remote branch has diverged (somebody else\n * pushed to it), the push FAILS instead of overwriting their commits, and nothing is lost.\n *\n * The push runs as a CHILD PROCESS of `wp-upsert-hotfix-pr`, which the PreToolUse hook never sees, so\n * `pr-creation-or-push-guard` keeps refusing every hand-typed `git push` exactly as before.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class HotfixPrPublisher extends GatedPrPublisher {\n constructor(private readonly hotfixGit: GitExec) {\n super(hotfixGit);\n }\n\n /** Fast-forward-only push of HEAD to origin/<branch>, run in `cwd`. Throws on any failure. */\n pushFastForward(cwd: string, branch: string): void {\n const out = this.hotfixGit.tryGit(['push', '-u', 'origin', `HEAD:${branch}`], cwd);\n if (out.ok) return;\n throw new CliExitError(\n 1,\n `❌ git push of the hotfix branch '${branch}' failed (exit ${String(out.status)}). A hotfix push is\\n` +\n ' fast-forward only — it never forces — so a remote branch that has diverged is refused rather\\n' +\n ' than overwritten.\\n' +\n ` git said: ${out.stderr === '' ? '(nothing)' : out.stderr}`,\n );\n }\n\n protected override push(baseBranch: string): void {\n this.pushFastForward(process.cwd(), baseBranch);\n }\n}\n"]}
1
+ {"version":3,"file":"hotfix-pr-publisher.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/hotfix-pr-publisher.ts"],"names":[],"mappings":";;;;AAAA,0DAAuD;AACvD,8DAA6D;AAC7D,yCAA2D;AAC3D,6DAAwD;AACxD,yCAAqC;AAErC;;;;;;;;;;;GAWG;AAEI,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,qCAAgB;IACtB;IAA7B,YAA6B,SAAkB,EAAE,SAA2B;QACxE,KAAK,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QADH,cAAS,GAAT,SAAS,CAAS;IAE/C,CAAC;IAED,8FAA8F;IAC9F,KAAK,CAAC,eAAe,CAAC,GAAW,EAAE,MAAc;QAC7C,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,MAAM,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;QACzF,IAAI,GAAG,CAAC,EAAE;YAAE,OAAO;QACnB,MAAM,IAAI,2BAAY,CAClB,CAAC,EACD,oCAAoC,MAAM,kBAAkB,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,uBAAuB;YACjG,mGAAmG;YACnG,wBAAwB;YACxB,gBAAgB,GAAG,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,CACrE,CAAC;IACN,CAAC;IAEkB,IAAI,CAAC,UAAkB;QACtC,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,UAAU,CAAC,CAAC;IAC3D,CAAC;CACJ,CAAA;AArBY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEG,kBAAO,EAAa,iCAAgB;GADnE,iBAAiB,CAqB7B","sourcesContent":["import { CliExitError } from '@webpieces/rules-config';\nimport { NativeProcessApi } from '@webpieces/tooling-common';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { GatedPrPublisher } from './gated-pr-publisher';\nimport { GitExec } from './git-exec';\n\n/**\n * The gated publisher for a `/hotfix/` branch: the same body-before-push ordering, with a push that can\n * NEVER rewrite the remote branch.\n *\n * The normal flow pushes with `--force-with-lease`, because its 3-point squash rewrites history on every\n * update. A hotfix branch is never rewritten — it only ever grows by the fix commits added on top of the\n * production sha — so its push is a plain fast-forward. If the remote branch has diverged (somebody else\n * pushed to it), the push FAILS instead of overwriting their commits, and nothing is lost.\n *\n * The push runs as a CHILD PROCESS of `wp-upsert-hotfix-pr`, which the PreToolUse hook never sees, so\n * `pr-creation-or-push-guard` keeps refusing every hand-typed `git push` exactly as before.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class HotfixPrPublisher extends GatedPrPublisher {\n constructor(private readonly hotfixGit: GitExec, processes: NativeProcessApi) {\n super(hotfixGit, processes);\n }\n\n /** Fast-forward-only push of HEAD to origin/<branch>, run in `cwd`. Throws on any failure. */\n async pushFastForward(cwd: string, branch: string): Promise<void> {\n const out = await this.hotfixGit.tryGit(['push', '-u', 'origin', `HEAD:${branch}`], cwd);\n if (out.ok) return;\n throw new CliExitError(\n 1,\n `❌ git push of the hotfix branch '${branch}' failed (exit ${String(out.status)}). A hotfix push is\\n` +\n ' fast-forward only — it never forces — so a remote branch that has diverged is refused rather\\n' +\n ' than overwritten.\\n' +\n ` git said: ${out.stderr === '' ? '(nothing)' : out.stderr}`,\n );\n }\n\n protected override push(baseBranch: string): Promise<void> {\n return this.pushFastForward(process.cwd(), baseBranch);\n }\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import { Worktree, WorktreeService } from '@webpieces/repo-workflow-core';
2
+ import { GitProcessApi } from '@webpieces/tooling-common';
2
3
  /**
3
4
  * WHICH LOCAL TREE HOLDS THE COMMIT GITHUB JUST SQUASHED — asked as a fact, answered from anywhere.
4
5
  *
@@ -62,7 +63,8 @@ export declare class LandedTree {
62
63
  }
63
64
  export declare class LandedTreeResolver {
64
65
  private readonly worktrees;
65
- constructor(worktrees: WorktreeService);
66
+ private readonly git;
67
+ constructor(worktrees: WorktreeService, git: GitProcessApi);
66
68
  /**
67
69
  * The four-row table this whole design exists to implement, in order of what it can prove.
68
70
  *
@@ -70,6 +72,6 @@ export declare class LandedTreeResolver {
70
72
  * into a mismatch — a fact we do not have is not evidence of disagreement — so the local tip is taken
71
73
  * as the landed one, which is exactly what the old `ref.headRefOid !== ''` guard did.
72
74
  */
73
- resolve(repoRoot: string, branch: string, headRefOid: string): LandedTree;
75
+ resolve(repoRoot: string, branch: string, headRefOid: string): Promise<LandedTree>;
74
76
  private revParse;
75
77
  }
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LandedTreeResolver = exports.LandedTree = exports.LANDED_TREE_ABSENT = exports.LANDED_TREE_WRONG_TIP = exports.LANDED_TREE_BRANCH_ONLY = exports.LANDED_TREE_WORKTREE = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const child_process_1 = require("child_process");
6
5
  const repo_workflow_core_1 = require("@webpieces/repo-workflow-core");
6
+ const tooling_common_1 = require("@webpieces/tooling-common");
7
7
  const inversify_1 = require("inversify");
8
8
  /**
9
9
  * WHICH LOCAL TREE HOLDS THE COMMIT GITHUB JUST SQUASHED — asked as a fact, answered from anywhere.
@@ -74,8 +74,10 @@ class LandedTree {
74
74
  exports.LandedTree = LandedTree;
75
75
  let LandedTreeResolver = class LandedTreeResolver {
76
76
  worktrees;
77
- constructor(worktrees) {
77
+ git;
78
+ constructor(worktrees, git) {
78
79
  this.worktrees = worktrees;
80
+ this.git = git;
79
81
  }
80
82
  /**
81
83
  * The four-row table this whole design exists to implement, in order of what it can prove.
@@ -84,11 +86,11 @@ let LandedTreeResolver = class LandedTreeResolver {
84
86
  * into a mismatch — a fact we do not have is not evidence of disagreement — so the local tip is taken
85
87
  * as the landed one, which is exactly what the old `ref.headRefOid !== ''` guard did.
86
88
  */
87
- resolve(repoRoot, branch, headRefOid) {
89
+ async resolve(repoRoot, branch, headRefOid) {
88
90
  // Only LINKED worktrees are reapable; the primary clone is the thing reaped FROM, never a target.
89
91
  const holder = this.worktrees.linkedWorktrees(repoRoot)
90
92
  .find((tree) => tree.branch === branch) ?? null;
91
- const local = holder !== null ? holder.head : this.revParse(repoRoot, branch);
93
+ const local = holder !== null ? holder.head : await this.revParse(repoRoot, branch);
92
94
  if (local === '')
93
95
  return new LandedTree(exports.LANDED_TREE_ABSENT, null, '');
94
96
  if (headRefOid !== '' && local !== headRefOid) {
@@ -99,14 +101,15 @@ let LandedTreeResolver = class LandedTreeResolver {
99
101
  : new LandedTree(exports.LANDED_TREE_BRANCH_ONLY, null, local);
100
102
  }
101
103
  // Best-effort sha of a ref — '' when it cannot resolve, which reads as "the branch is not here".
102
- revParse(repoRoot, ref) {
103
- const result = (0, child_process_1.spawnSync)('git', ['rev-parse', ref], { cwd: repoRoot, encoding: 'utf8' });
104
- return result.status === 0 ? (result.stdout ?? '').trim() : '';
104
+ async revParse(repoRoot, ref) {
105
+ const result = await this.git.run(['rev-parse', ref], repoRoot);
106
+ return result.ok ? result.stdout.trim() : '';
105
107
  }
106
108
  };
107
109
  exports.LandedTreeResolver = LandedTreeResolver;
108
110
  exports.LandedTreeResolver = LandedTreeResolver = tslib_1.__decorate([
109
111
  (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
110
- tslib_1.__metadata("design:paramtypes", [repo_workflow_core_1.WorktreeService])
112
+ tslib_1.__metadata("design:paramtypes", [repo_workflow_core_1.WorktreeService,
113
+ tooling_common_1.GitProcessApi])
111
114
  ], LandedTreeResolver);
112
115
  //# sourceMappingURL=landed-tree-resolver.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"landed-tree-resolver.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/landed-tree-resolver.ts"],"names":[],"mappings":";;;;AAAA,iDAA0C;AAC1C,sEAA0E;AAC1E,yCAA2D;AAE3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,wGAAwG;AAC3F,QAAA,oBAAoB,GAAG,UAAU,CAAC;AAC/C,8GAA8G;AACjG,QAAA,uBAAuB,GAAG,aAAa,CAAC;AACrD,2FAA2F;AAC9E,QAAA,qBAAqB,GAAG,WAAW,CAAC;AACjD,wFAAwF;AAC3E,QAAA,kBAAkB,GAAG,QAAQ,CAAC;AAE3C;;;;;;;GAOG;AACH,MAAa,UAAU;IACV,IAAI,CAAS;IACtB,oFAAoF;IAC3E,QAAQ,CAAkB;IACnC,yGAAyG;IAChG,QAAQ,CAAS;IACjB,kBAAkB,CAAU;IAErC,YAAY,IAAY,EAAE,QAAyB,EAAE,QAAgB;QACjE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAA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AC1C,MAAM,MAAM,GAAG,IAAA,yBAAS,EAAC,KAAK,EAAE,CAAC,WAAW,EAAE,GAAG,CAAC,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;QACzF,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACnE,CAAC;CACJ,CAAA;AA9BY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEG,oCAAe;GAD9C,kBAAkB,CA8B9B","sourcesContent":["import { spawnSync } from 'child_process';\nimport { Worktree, WorktreeService } from '@webpieces/repo-workflow-core';\nimport { injectable, bindingScopeValues } from 'inversify';\n\n/**\n * WHICH LOCAL TREE HOLDS THE COMMIT GITHUB JUST SQUASHED — asked as a fact, answered from anywhere.\n *\n * `wp-land-pr` does two things with different scopes: the MERGE belongs to the PR and is reachable from\n * any directory, while the BOOKKEEPING (archive the pre-squash tip, promote merge-info, reap the landed\n * worktree) belongs to the tree that really holds those objects. Until now the second half was resolved\n * from `process.cwd()` — and `pnpm` hoists a bin's cwd to the workspace root, so a command run inside\n * `<primary>/.claude/worktrees/agent-<id>` executed in the PRIMARY CLONE. Every agent worktree is nested\n * like that, so the answer was wrong in exactly the case the mechanism was built for.\n *\n * The fix is to stop asking \"where am I\" and start asking \"where is it\". Both halves of that question are\n * facts nobody has to record:\n *\n * `gh pr view <n> --json headRefName,headRefOid` → the branch, and the exact commit being squashed\n * `git worktree list --porcelain` → every (path, branch, HEAD sha) in this repo\n *\n * The worktree list lives in the COMMON dir, so it reads identically from the primary clone, from any\n * linked worktree, and from a coordinator that never saw the agent that built the branch. That is what\n * makes `wp-land-pr --pr <n>` able to finish a dead agent's work.\n *\n * ─── WHY THE PAIR, AND NEVER THE NAME ALONE ───────────────────────────────────────────────────────\n * A branch NAME does not identify a tree. A second clone, or a worktree somebody has since committed to,\n * holds the same name at a different commit, and archiving `archive/<date>/<branch>` from there tags the\n * wrong objects under the right name. So the selection key is `(headRefName, headRefOid)` together, and a\n * name-only match is never enough to remove or archive anything — in this process or in the child that\n * re-verifies it (see ReapWorktreeCommand).\n *\n * ─── WHY NOT A `.webpieces/**` RECEIPT ────────────────────────────────────────────────────────────\n * The obvious alternative is for `wp-finish-upsert-pr` to write `{ pr, branch, worktreePath, headRefOid }`\n * to a sidecar and for landing to read it back. `decisions/0005-the-pr-description-is-the-merge-body.md`\n * already deleted that pattern once: a recorded claim can only ever be missing, stale, or on the wrong\n * computer — and a worktree PATH is more volatile than the commit body that argument was made about,\n * since the directory is moved, reaped, or recreated under a new agent id between finish and land.\n * `(headRefOid, git worktree list)` is a pair of facts, needs no stored state, and works from a fresh\n * clone. Nothing here reads state.\n */\n\n/** A linked worktree holds the branch AT the squashed commit: archive here, and reap THAT directory. */\nexport const LANDED_TREE_WORKTREE = 'worktree';\n/** No worktree holds it, but the branch ref in this repo IS the squashed commit: archive, nothing to reap. */\nexport const LANDED_TREE_BRANCH_ONLY = 'branch-only';\n/** The name is here, the commit is not. Merge stands; bookkeeping is declined out loud. */\nexport const LANDED_TREE_WRONG_TIP = 'wrong-tip';\n/** The branch is not in this repo at all — landed from a tree that does not hold it. */\nexport const LANDED_TREE_ABSENT = 'absent';\n\n/**\n * Data-only (per CLAUDE.md, classes for data). Where the landed commit lives locally, and therefore\n * whether the bookkeeping half may run at all.\n *\n * `bookkeepingAllowed` is PRECOMPUTED rather than re-derived by the caller, for the same reason\n * `EffectiveTree.redirected` and `WorktreeReapHandoff.canReap` are: a deletion rule spelled out twice is\n * a deletion rule that eventually disagrees with itself.\n */\nexport class LandedTree {\n readonly kind: string;\n /** The linked worktree to reap — non-null ONLY for {@link LANDED_TREE_WORKTREE}. */\n readonly worktree: Worktree | null;\n /** The sha found locally under that branch name, '' when the branch is absent. Printed on a mismatch. */\n readonly localSha: string;\n readonly bookkeepingAllowed: boolean;\n\n constructor(kind: string, worktree: Worktree | null, localSha: string) {\n this.kind = kind;\n this.worktree = worktree;\n this.localSha = localSha;\n this.bookkeepingAllowed = kind === LANDED_TREE_WORKTREE || kind === LANDED_TREE_BRANCH_ONLY;\n }\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class LandedTreeResolver {\n constructor(private readonly worktrees: WorktreeService) {}\n\n /**\n * The four-row table this whole design exists to implement, in order of what it can prove.\n *\n * `headRefOid === ''` means `gh` did not tell us which commit it is squashing. That cannot be turned\n * into a mismatch — a fact we do not have is not evidence of disagreement — so the local tip is taken\n * as the landed one, which is exactly what the old `ref.headRefOid !== ''` guard did.\n */\n resolve(repoRoot: string, branch: string, headRefOid: string): LandedTree {\n // Only LINKED worktrees are reapable; the primary clone is the thing reaped FROM, never a target.\n const holder = this.worktrees.linkedWorktrees(repoRoot)\n .find((tree: Worktree): boolean => tree.branch === branch) ?? null;\n const local = holder !== null ? holder.head : this.revParse(repoRoot, branch);\n\n if (local === '') return new LandedTree(LANDED_TREE_ABSENT, null, '');\n if (headRefOid !== '' && local !== headRefOid) {\n return new LandedTree(LANDED_TREE_WRONG_TIP, null, local);\n }\n return holder !== null\n ? new LandedTree(LANDED_TREE_WORKTREE, holder, local)\n : new LandedTree(LANDED_TREE_BRANCH_ONLY, null, local);\n }\n\n // Best-effort sha of a ref — '' when it cannot resolve, which reads as \"the branch is not here\".\n private revParse(repoRoot: string, ref: string): string {\n const result = spawnSync('git', ['rev-parse', ref], { cwd: repoRoot, encoding: 'utf8' });\n return result.status === 0 ? (result.stdout ?? '').trim() : '';\n }\n}\n"]}
1
+ {"version":3,"file":"landed-tree-resolver.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/landed-tree-resolver.ts"],"names":[],"mappings":";;;;AAAA,sEAA0E;AAC1E,8DAA0D;AAC1D,yCAA2D;AAE3D;;;;;;;;;;;;;;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AC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAEpF,IAAI,KAAK,KAAK,EAAE;YAAE,OAAO,IAAI,UAAU,CAAC,0BAAkB,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QACtE,IAAI,UAAU,KAAK,EAAE,IAAI,KAAK,KAAK,UAAU,EAAE,CAAC;YAC5C,OAAO,IAAI,UAAU,CAAC,6BAAqB,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QAC9D,CAAC;QACD,OAAO,MAAM,KAAK,IAAI;YAClB,CAAC,CAAC,IAAI,UAAU,CAAC,4BAAoB,EAAE,MAAM,EAAE,KAAK,CAAC;YACrD,CAAC,CAAC,IAAI,UAAU,CAAC,+BAAuB,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IAC/D,CAAC;IAED,iGAAiG;IACzF,KAAK,CAAC,QAAQ,CAAC,QAAgB,EAAE,GAAW;QAChD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC;QAChE,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACjD,CAAC;CACJ,CAAA;AAjCY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGL,oCAAe;QACrB,8BAAa;GAH9B,kBAAkB,CAiC9B","sourcesContent":["import { Worktree, WorktreeService } from '@webpieces/repo-workflow-core';\nimport { GitProcessApi } from '@webpieces/tooling-common';\nimport { injectable, bindingScopeValues } from 'inversify';\n\n/**\n * WHICH LOCAL TREE HOLDS THE COMMIT GITHUB JUST SQUASHED — asked as a fact, answered from anywhere.\n *\n * `wp-land-pr` does two things with different scopes: the MERGE belongs to the PR and is reachable from\n * any directory, while the BOOKKEEPING (archive the pre-squash tip, promote merge-info, reap the landed\n * worktree) belongs to the tree that really holds those objects. Until now the second half was resolved\n * from `process.cwd()` — and `pnpm` hoists a bin's cwd to the workspace root, so a command run inside\n * `<primary>/.claude/worktrees/agent-<id>` executed in the PRIMARY CLONE. Every agent worktree is nested\n * like that, so the answer was wrong in exactly the case the mechanism was built for.\n *\n * The fix is to stop asking \"where am I\" and start asking \"where is it\". Both halves of that question are\n * facts nobody has to record:\n *\n * `gh pr view <n> --json headRefName,headRefOid` → the branch, and the exact commit being squashed\n * `git worktree list --porcelain` → every (path, branch, HEAD sha) in this repo\n *\n * The worktree list lives in the COMMON dir, so it reads identically from the primary clone, from any\n * linked worktree, and from a coordinator that never saw the agent that built the branch. That is what\n * makes `wp-land-pr --pr <n>` able to finish a dead agent's work.\n *\n * ─── WHY THE PAIR, AND NEVER THE NAME ALONE ───────────────────────────────────────────────────────\n * A branch NAME does not identify a tree. A second clone, or a worktree somebody has since committed to,\n * holds the same name at a different commit, and archiving `archive/<date>/<branch>` from there tags the\n * wrong objects under the right name. So the selection key is `(headRefName, headRefOid)` together, and a\n * name-only match is never enough to remove or archive anything — in this process or in the child that\n * re-verifies it (see ReapWorktreeCommand).\n *\n * ─── WHY NOT A `.webpieces/**` RECEIPT ────────────────────────────────────────────────────────────\n * The obvious alternative is for `wp-finish-upsert-pr` to write `{ pr, branch, worktreePath, headRefOid }`\n * to a sidecar and for landing to read it back. `decisions/0005-the-pr-description-is-the-merge-body.md`\n * already deleted that pattern once: a recorded claim can only ever be missing, stale, or on the wrong\n * computer — and a worktree PATH is more volatile than the commit body that argument was made about,\n * since the directory is moved, reaped, or recreated under a new agent id between finish and land.\n * `(headRefOid, git worktree list)` is a pair of facts, needs no stored state, and works from a fresh\n * clone. Nothing here reads state.\n */\n\n/** A linked worktree holds the branch AT the squashed commit: archive here, and reap THAT directory. */\nexport const LANDED_TREE_WORKTREE = 'worktree';\n/** No worktree holds it, but the branch ref in this repo IS the squashed commit: archive, nothing to reap. */\nexport const LANDED_TREE_BRANCH_ONLY = 'branch-only';\n/** The name is here, the commit is not. Merge stands; bookkeeping is declined out loud. */\nexport const LANDED_TREE_WRONG_TIP = 'wrong-tip';\n/** The branch is not in this repo at all — landed from a tree that does not hold it. */\nexport const LANDED_TREE_ABSENT = 'absent';\n\n/**\n * Data-only (per CLAUDE.md, classes for data). Where the landed commit lives locally, and therefore\n * whether the bookkeeping half may run at all.\n *\n * `bookkeepingAllowed` is PRECOMPUTED rather than re-derived by the caller, for the same reason\n * `EffectiveTree.redirected` and `WorktreeReapHandoff.canReap` are: a deletion rule spelled out twice is\n * a deletion rule that eventually disagrees with itself.\n */\nexport class LandedTree {\n readonly kind: string;\n /** The linked worktree to reap — non-null ONLY for {@link LANDED_TREE_WORKTREE}. */\n readonly worktree: Worktree | null;\n /** The sha found locally under that branch name, '' when the branch is absent. Printed on a mismatch. */\n readonly localSha: string;\n readonly bookkeepingAllowed: boolean;\n\n constructor(kind: string, worktree: Worktree | null, localSha: string) {\n this.kind = kind;\n this.worktree = worktree;\n this.localSha = localSha;\n this.bookkeepingAllowed = kind === LANDED_TREE_WORKTREE || kind === LANDED_TREE_BRANCH_ONLY;\n }\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class LandedTreeResolver {\n constructor(\n private readonly worktrees: WorktreeService,\n private readonly git: GitProcessApi,\n ) {}\n\n /**\n * The four-row table this whole design exists to implement, in order of what it can prove.\n *\n * `headRefOid === ''` means `gh` did not tell us which commit it is squashing. That cannot be turned\n * into a mismatch — a fact we do not have is not evidence of disagreement — so the local tip is taken\n * as the landed one, which is exactly what the old `ref.headRefOid !== ''` guard did.\n */\n async resolve(repoRoot: string, branch: string, headRefOid: string): Promise<LandedTree> {\n // Only LINKED worktrees are reapable; the primary clone is the thing reaped FROM, never a target.\n const holder = this.worktrees.linkedWorktrees(repoRoot)\n .find((tree: Worktree): boolean => tree.branch === branch) ?? null;\n const local = holder !== null ? holder.head : await this.revParse(repoRoot, branch);\n\n if (local === '') return new LandedTree(LANDED_TREE_ABSENT, null, '');\n if (headRefOid !== '' && local !== headRefOid) {\n return new LandedTree(LANDED_TREE_WRONG_TIP, null, local);\n }\n return holder !== null\n ? new LandedTree(LANDED_TREE_WORKTREE, holder, local)\n : new LandedTree(LANDED_TREE_BRANCH_ONLY, null, local);\n }\n\n // Best-effort sha of a ref — '' when it cannot resolve, which reads as \"the branch is not here\".\n private async revParse(repoRoot: string, ref: string): Promise<string> {\n const result = await this.git.run(['rev-parse', ref], repoRoot);\n return result.ok ? result.stdout.trim() : '';\n }\n}\n"]}
@@ -1,4 +1,5 @@
1
1
  import { Worktree, WorktreeService } from '@webpieces/repo-workflow-core';
2
+ import { NativeProcessApi } from '@webpieces/tooling-common';
2
3
  import { ReapOutcomeSignal } from './reap-outcome';
3
4
  /**
4
5
  * Data-only (per CLAUDE.md, classes for data). The decision about the just-landed worktree: which
@@ -36,7 +37,8 @@ export declare class WorktreeReapHandoff {
36
37
  export declare class LandedWorktreeReaper {
37
38
  private readonly worktrees;
38
39
  private readonly signal;
39
- constructor(worktrees: WorktreeService, signal: ReapOutcomeSignal);
40
+ private readonly processes;
41
+ constructor(worktrees: WorktreeService, signal: ReapOutcomeSignal, processes: NativeProcessApi);
40
42
  /**
41
43
  * Is there a worktree to reap at all, and can the hand-off run?
42
44
  *
@@ -73,7 +75,7 @@ export declare class LandedWorktreeReaper {
73
75
  * only means "the child ran"; whether the DIRECTORY is gone is a separate statement it makes through
74
76
  * ReapOutcomeSignal, and that is the one that gates the "your cwd no longer exists" notice.
75
77
  */
76
- handOff(handoff: WorktreeReapHandoff): string;
78
+ handOff(handoff: WorktreeReapHandoff): Promise<string>;
77
79
  /**
78
80
  * WHY the directory is still there, distinguishing the two cases a single exit code conflated: the
79
81
  * child broke (non-zero), versus the child worked perfectly and DECLINED (exit 0, outcome refused).
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LandedWorktreeReaper = exports.WorktreeReapHandoff = 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 repo_workflow_core_1 = require("@webpieces/repo-workflow-core");
9
8
  const rules_config_1 = require("@webpieces/rules-config");
9
+ const tooling_common_1 = require("@webpieces/tooling-common");
10
10
  const inversify_1 = require("inversify");
11
11
  const reap_outcome_1 = require("./reap-outcome");
12
12
  /**
@@ -87,9 +87,11 @@ exports.WorktreeReapHandoff = WorktreeReapHandoff;
87
87
  let LandedWorktreeReaper = class LandedWorktreeReaper {
88
88
  worktrees;
89
89
  signal;
90
- constructor(worktrees, signal) {
90
+ processes;
91
+ constructor(worktrees, signal, processes) {
91
92
  this.worktrees = worktrees;
92
93
  this.signal = signal;
94
+ this.processes = processes;
93
95
  }
94
96
  /**
95
97
  * Is there a worktree to reap at all, and can the hand-off run?
@@ -145,16 +147,16 @@ let LandedWorktreeReaper = class LandedWorktreeReaper {
145
147
  * only means "the child ran"; whether the DIRECTORY is gone is a separate statement it makes through
146
148
  * ReapOutcomeSignal, and that is the one that gates the "your cwd no longer exists" notice.
147
149
  */
148
- handOff(handoff) {
149
- const result = (0, child_process_1.spawnSync)(process.execPath, [handoff.entryScript, handoff.worktreePath, handoff.branch, handoff.head], { cwd: handoff.primaryPath, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
150
- const report = this.signal.read(`${result.stdout ?? ''}${result.stderr ?? ''}`);
150
+ async handOff(handoff) {
151
+ const result = await this.processes.run(process.execPath, [handoff.entryScript, handoff.worktreePath, handoff.branch, handoff.head], handoff.primaryPath);
152
+ const report = this.signal.read(`${result.stdout}${result.stderr}`);
151
153
  const output = report.text.trimEnd();
152
154
  const head = '\n' + SEP + `🌲 Reaping ${handoff.worktreePath} from ${handoff.primaryPath}\n` + SEP + '\n'
153
155
  + ` The branch just landed, so that directory is dead. The reap runs in a child process\n`
154
156
  + ` whose cwd is the primary clone — nothing deletes the directory it is standing in.\n\n`;
155
157
  const body = head + (output !== '' ? output + '\n' : '');
156
- if (result.status !== 0 || !report.removed) {
157
- return body + this.notRemoved(result.status, report) + this.manualNotice(handoff);
158
+ if (result.code !== 0 || !report.removed) {
159
+ return body + this.notRemoved(result.code, report) + this.manualNotice(handoff);
158
160
  }
159
161
  return body + this.afterReap(handoff);
160
162
  }
@@ -166,7 +168,7 @@ let LandedWorktreeReaper = class LandedWorktreeReaper {
166
168
  */
167
169
  notRemoved(status, report) {
168
170
  if (status !== 0) {
169
- return `\n ⚠️ The reap did not complete (exit ${String(status ?? -1)}). Nothing was forced.\n`;
171
+ return `\n ⚠️ The reap did not complete (exit ${String(status)}). Nothing was forced.\n`;
170
172
  }
171
173
  const why = report.outcome === reap_outcome_1.REAP_OUTCOME_MISSING
172
174
  ? 'the child ended without reporting an outcome'
@@ -222,6 +224,7 @@ exports.LandedWorktreeReaper = LandedWorktreeReaper;
222
224
  exports.LandedWorktreeReaper = LandedWorktreeReaper = tslib_1.__decorate([
223
225
  (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
224
226
  tslib_1.__metadata("design:paramtypes", [repo_workflow_core_1.WorktreeService,
225
- reap_outcome_1.ReapOutcomeSignal])
227
+ reap_outcome_1.ReapOutcomeSignal,
228
+ tooling_common_1.NativeProcessApi])
226
229
  ], LandedWorktreeReaper);
227
230
  //# sourceMappingURL=landed-worktree-reaper.js.map