@webpieces/pr-gate 0.4.983 → 0.4.985

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 (52) hide show
  1. package/package.json +8 -8
  2. package/src/scripts/commands/build-push-dev-command.d.ts +61 -0
  3. package/src/scripts/commands/build-push-dev-command.js +159 -0
  4. package/src/scripts/commands/build-push-dev-command.js.map +1 -0
  5. package/src/scripts/commands/finish-push-dev-command.d.ts +73 -17
  6. package/src/scripts/commands/finish-push-dev-command.js +187 -31
  7. package/src/scripts/commands/finish-push-dev-command.js.map +1 -1
  8. package/src/scripts/commands/start-push-dev-command.d.ts +43 -0
  9. package/src/scripts/commands/start-push-dev-command.js +111 -0
  10. package/src/scripts/commands/start-push-dev-command.js.map +1 -0
  11. package/src/scripts/pr-gate-app.d.ts +18 -18
  12. package/src/scripts/pr-gate-app.js +27 -26
  13. package/src/scripts/pr-gate-app.js.map +1 -1
  14. package/src/scripts/pr-gate-cli-app.d.ts +2 -2
  15. package/src/scripts/pr-gate-cli-app.js +20 -29
  16. package/src/scripts/pr-gate-cli-app.js.map +1 -1
  17. package/src/scripts/workflow/build-gate-log.js +2 -2
  18. package/src/scripts/workflow/build-gate-log.js.map +1 -1
  19. package/src/scripts/workflow/dev-build.js +2 -2
  20. package/src/scripts/workflow/dev-build.js.map +1 -1
  21. package/src/scripts/workflow/dev-copy-on-main.d.ts +49 -0
  22. package/src/scripts/workflow/dev-copy-on-main.js +99 -0
  23. package/src/scripts/workflow/dev-copy-on-main.js.map +1 -0
  24. package/src/scripts/workflow/dev-deploy-refs.d.ts +4 -17
  25. package/src/scripts/workflow/dev-deploy-refs.js +5 -21
  26. package/src/scripts/workflow/dev-deploy-refs.js.map +1 -1
  27. package/src/scripts/workflow/dev-resolve-runner.d.ts +43 -73
  28. package/src/scripts/workflow/dev-resolve-runner.js +117 -181
  29. package/src/scripts/workflow/dev-resolve-runner.js.map +1 -1
  30. package/src/scripts/workflow/main-freshness.d.ts +16 -0
  31. package/src/scripts/workflow/main-freshness.js +33 -0
  32. package/src/scripts/workflow/main-freshness.js.map +1 -0
  33. package/src/scripts/workflow/push-dev-state.d.ts +12 -35
  34. package/src/scripts/workflow/push-dev-state.js +31 -62
  35. package/src/scripts/workflow/push-dev-state.js.map +1 -1
  36. package/src/scripts/workflow/verified-dev-copy.d.ts +46 -0
  37. package/src/scripts/workflow/verified-dev-copy.js +89 -0
  38. package/src/scripts/workflow/verified-dev-copy.js.map +1 -0
  39. package/src/scripts/{wp-build-dev.js → wp-build-push-dev.js} +2 -2
  40. package/src/scripts/wp-build-push-dev.js.map +1 -0
  41. package/src/scripts/{wp-push-dev.js → wp-start-push-dev.js} +2 -2
  42. package/src/scripts/wp-start-push-dev.js.map +1 -0
  43. package/src/scripts/commands/build-dev-command.d.ts +0 -27
  44. package/src/scripts/commands/build-dev-command.js +0 -99
  45. package/src/scripts/commands/build-dev-command.js.map +0 -1
  46. package/src/scripts/commands/push-dev-command.d.ts +0 -124
  47. package/src/scripts/commands/push-dev-command.js +0 -318
  48. package/src/scripts/commands/push-dev-command.js.map +0 -1
  49. package/src/scripts/wp-build-dev.js.map +0 -1
  50. package/src/scripts/wp-push-dev.js.map +0 -1
  51. /package/src/scripts/{wp-build-dev.d.ts → wp-build-push-dev.d.ts} +0 -0
  52. /package/src/scripts/{wp-push-dev.d.ts → wp-start-push-dev.d.ts} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/pr-gate",
3
- "version": "0.4.983",
3
+ "version": "0.4.985",
4
4
  "description": "Gated PR system: 3-point squash-merge, merge validation gate, and red/yellow/green PR dashboard. Standalone scripts, no Nx dependency required.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -16,23 +16,22 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@inversifyjs/binding-decorators": "1.1.5",
19
- "@webpieces/hook-runtime": "0.4.983",
20
- "@webpieces/rules-config": "0.4.983",
19
+ "@webpieces/hook-runtime": "0.4.985",
20
+ "@webpieces/rules-config": "0.4.985",
21
21
  "inversify": "7.10.4",
22
22
  "reflect-metadata": "0.2.2",
23
- "@webpieces/tooling-common": "0.4.983",
24
- "@webpieces/repo-workflow-core": "0.4.983"
23
+ "@webpieces/tooling-common": "0.4.985",
24
+ "@webpieces/repo-workflow-core": "0.4.985"
25
25
  },
26
26
  "publishConfig": {
27
27
  "access": "public"
28
28
  },
29
29
  "devDependencies": {
30
- "@webpieces/tooling-testkit": "0.4.983"
30
+ "@webpieces/tooling-testkit": "0.4.985"
31
31
  },
32
32
  "types": "./src/index.d.ts",
33
33
  "bin": {
34
34
  "wp-build": "./src/scripts/wp-build.js",
35
- "wp-build-dev": "./src/scripts/wp-build-dev.js",
36
35
  "wp-finish-upsert-pr": "./src/scripts/git-finishUpsertPr.js",
37
36
  "wp-human-post-pr": "./src/scripts/wp-human-post-pr.js",
38
37
  "wp-upsert-hotfix-pr": "./src/scripts/wp-upsert-hotfix-pr.js",
@@ -44,7 +43,8 @@
44
43
  "wp-land-pr": "./src/scripts/wp-land-pr.js",
45
44
  "wp-check-pr": "./src/scripts/wp-check-pr.js",
46
45
  "wp-review-upsert-pr": "./src/scripts/wp-review-upsert-pr.js",
47
- "wp-push-dev": "./src/scripts/wp-push-dev.js",
46
+ "wp-start-push-dev": "./src/scripts/wp-start-push-dev.js",
47
+ "wp-build-push-dev": "./src/scripts/wp-build-push-dev.js",
48
48
  "wp-finish-push-dev": "./src/scripts/wp-finish-push-dev.js",
49
49
  "wp-await-reviews": "./src/scripts/wp-await-reviews.js",
50
50
  "wp-write-review": "./src/scripts/wp-write-review.js",
@@ -0,0 +1,61 @@
1
+ import { RepoRootFinder } from '@webpieces/rules-config';
2
+ import { GitExec } from '../workflow/git-exec';
3
+ import { DevDeployRefs } from '../workflow/dev-deploy-refs';
4
+ import { PushDevStateStore } from '../workflow/push-dev-state';
5
+ import { DevResolveRunner } from '../workflow/dev-resolve-runner';
6
+ import { DevBuild } from '../workflow/dev-build';
7
+ import { MainFreshness } from '../workflow/main-freshness';
8
+ import { VerifiedDevCopyStore } from '../workflow/verified-dev-copy';
9
+ import { AiBranchName } from '../workflow/git-readAiBranchName';
10
+ import { MergeState } from '../workflow/merge-state';
11
+ import { MergeEnd } from '../workflow/merge-end';
12
+ /** What `wp-build-push-dev` was asked to do. Data-only (per CLAUDE.md). */
13
+ export declare class BuildPushDevOptions {
14
+ /** Throw a conflict resolution in progress away and restore the original checkout. */
15
+ abort: boolean;
16
+ constructor(abort?: boolean);
17
+ }
18
+ /**
19
+ * `wp-build-push-dev` — stage ② of the dev-deploy flow, the gate (#1403). The twin of
20
+ * `wp-review-upsert-pr`: it validates any 3-point merge stage ① left for `/wp-merge`, refuses a branch that
21
+ * is behind `origin/main`, then checks the branch against `origin/<devBranch>` on a THROWAWAY merge, runs
22
+ * `pnpm install` on the merged tree and `commands.push-dev.buildCommand` on it. Green ⇒ it records the
23
+ * copy for `wp-finish-push-dev` (stage ③) and goes back to the feature branch. It publishes NOTHING.
24
+ *
25
+ * A conflict with dev stops on the throwaway, and RE-RUNNING this command is how the check continues once
26
+ * the files are resolved and `git add`-ed (`--abort` throws it away) — one command per stage, the same way
27
+ * stage ② of the PR flow is re-run after a fix.
28
+ *
29
+ * WHY THE CHECK AGAINST `dev` (#1397): 61 of 73 failed dev publishes on one consumer failed on a git
30
+ * conflict, which the developer only learned about after the server-side composition failed. A build
31
+ * against `main` alone proves the wrong thing; a build of only what differs from `dev` proves the right one,
32
+ * quickly.
33
+ */
34
+ export declare class BuildPushDevCommand {
35
+ private readonly repoRootFinder;
36
+ private readonly gitExec;
37
+ private readonly refs;
38
+ private readonly store;
39
+ private readonly runner;
40
+ private readonly devBuild;
41
+ private readonly mainFreshness;
42
+ private readonly verified;
43
+ private readonly aiBranchName;
44
+ private readonly mergeState;
45
+ private readonly mergeEnd;
46
+ constructor(repoRootFinder: RepoRootFinder, gitExec: GitExec, refs: DevDeployRefs, store: PushDevStateStore, runner: DevResolveRunner, devBuild: DevBuild, mainFreshness: MainFreshness, verified: VerifiedDevCopyStore, aiBranchName: AiBranchName, mergeState: MergeState, mergeEnd: MergeEnd);
47
+ run(opts: BuildPushDevOptions): Promise<void>;
48
+ /**
49
+ * Validate + finalize a 3-point merge with main that stage ① stopped on. The push mirrors stage ①'s:
50
+ * with no PR the rewrite reaches `origin/<feature>` (as `wp-finish-update` does); with a PR open it
51
+ * stays local, for the PR flow's one reviewed push.
52
+ */
53
+ private finalizeAnyInProgressMainMerge;
54
+ private refuseBehindMain;
55
+ /**
56
+ * `origin/<devBranch>` does not exist yet — the very first publish in a repo whose CI has never
57
+ * composed. There is nothing to conflict with and no base for a dev-scoped build, so the branch is
58
+ * recorded as it is; refusing here would make the first dev composition impossible to start.
59
+ */
60
+ private verifyWithoutDev;
61
+ }
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BuildPushDevCommand = exports.BuildPushDevOptions = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const rules_config_1 = require("@webpieces/rules-config");
6
+ const inversify_1 = require("inversify");
7
+ const git_exec_1 = require("../workflow/git-exec");
8
+ const dev_deploy_refs_1 = require("../workflow/dev-deploy-refs");
9
+ const push_dev_state_1 = require("../workflow/push-dev-state");
10
+ const dev_resolve_runner_1 = require("../workflow/dev-resolve-runner");
11
+ const dev_build_1 = require("../workflow/dev-build");
12
+ const main_freshness_1 = require("../workflow/main-freshness");
13
+ const verified_dev_copy_1 = require("../workflow/verified-dev-copy");
14
+ const git_readAiBranchName_1 = require("../workflow/git-readAiBranchName");
15
+ const merge_state_1 = require("../workflow/merge-state");
16
+ const merge_end_1 = require("../workflow/merge-end");
17
+ const merge_start_1 = require("../workflow/merge-start");
18
+ const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
19
+ /** What `wp-build-push-dev` was asked to do. Data-only (per CLAUDE.md). */
20
+ class BuildPushDevOptions {
21
+ /** Throw a conflict resolution in progress away and restore the original checkout. */
22
+ abort = false;
23
+ constructor(abort = false) {
24
+ this.abort = abort;
25
+ }
26
+ }
27
+ exports.BuildPushDevOptions = BuildPushDevOptions;
28
+ /**
29
+ * `wp-build-push-dev` — stage ② of the dev-deploy flow, the gate (#1403). The twin of
30
+ * `wp-review-upsert-pr`: it validates any 3-point merge stage ① left for `/wp-merge`, refuses a branch that
31
+ * is behind `origin/main`, then checks the branch against `origin/<devBranch>` on a THROWAWAY merge, runs
32
+ * `pnpm install` on the merged tree and `commands.push-dev.buildCommand` on it. Green ⇒ it records the
33
+ * copy for `wp-finish-push-dev` (stage ③) and goes back to the feature branch. It publishes NOTHING.
34
+ *
35
+ * A conflict with dev stops on the throwaway, and RE-RUNNING this command is how the check continues once
36
+ * the files are resolved and `git add`-ed (`--abort` throws it away) — one command per stage, the same way
37
+ * stage ② of the PR flow is re-run after a fix.
38
+ *
39
+ * WHY THE CHECK AGAINST `dev` (#1397): 61 of 73 failed dev publishes on one consumer failed on a git
40
+ * conflict, which the developer only learned about after the server-side composition failed. A build
41
+ * against `main` alone proves the wrong thing; a build of only what differs from `dev` proves the right one,
42
+ * quickly.
43
+ */
44
+ let BuildPushDevCommand = class BuildPushDevCommand {
45
+ repoRootFinder;
46
+ gitExec;
47
+ refs;
48
+ store;
49
+ runner;
50
+ devBuild;
51
+ mainFreshness;
52
+ verified;
53
+ aiBranchName;
54
+ mergeState;
55
+ mergeEnd;
56
+ constructor(repoRootFinder, gitExec, refs, store, runner, devBuild, mainFreshness, verified, aiBranchName, mergeState, mergeEnd) {
57
+ this.repoRootFinder = repoRootFinder;
58
+ this.gitExec = gitExec;
59
+ this.refs = refs;
60
+ this.store = store;
61
+ this.runner = runner;
62
+ this.devBuild = devBuild;
63
+ this.mainFreshness = mainFreshness;
64
+ this.verified = verified;
65
+ this.aiBranchName = aiBranchName;
66
+ this.mergeState = mergeState;
67
+ this.mergeEnd = mergeEnd;
68
+ }
69
+ async run(opts) {
70
+ const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());
71
+ // Refresh the AI-facing workflow doc so it is present + current for any failure message to cite.
72
+ (0, rules_config_1.writeTemplate)(repoRoot, 'webpieces.git-workflow.md');
73
+ if (opts.abort) {
74
+ await this.runner.abort(repoRoot, this.store.require(repoRoot));
75
+ return;
76
+ }
77
+ const inFlight = this.store.read(repoRoot);
78
+ if (inFlight !== null) {
79
+ // A conflict with dev was resolved: commit it and carry on with install + build + record.
80
+ await this.runner.resume(repoRoot, inFlight);
81
+ return;
82
+ }
83
+ // Stage ① may have handed a conflicted 3-point merge with main to /wp-merge; it is validated and
84
+ // finalized HERE, before anything else, exactly as wp-review-upsert-pr does for the PR flow.
85
+ await this.finalizeAnyInProgressMainMerge(repoRoot);
86
+ const cfg = this.refs.config(repoRoot);
87
+ const branch = this.refs.currentBranch(repoRoot);
88
+ this.refs.assertPushable(cfg, branch);
89
+ // Before any git write: an unconfigured dev build refuses here, with nothing merged.
90
+ this.devBuild.command(repoRoot);
91
+ // The merge below must be of committed work only, and must not sweep uncommitted edits along.
92
+ await this.gitExec.assertCleanTree(repoRoot);
93
+ if (!await this.mainFreshness.containsLatestMain(repoRoot))
94
+ this.refuseBehindMain(branch);
95
+ // A previous verification is stale the moment a new check starts.
96
+ this.verified.clear(repoRoot);
97
+ const targetRef = cfg.copyRefFor(branch);
98
+ const leaseSha = await this.refs.remoteSha(repoRoot, targetRef);
99
+ if (await this.refs.remoteSha(repoRoot, cfg.devBranch) === '') {
100
+ await this.verifyWithoutDev(repoRoot, cfg, branch, targetRef, leaseSha);
101
+ return;
102
+ }
103
+ const state = new push_dev_state_1.PushDevState(branch, this.runner.tmpBranchFor(branch), targetRef, cfg.devBranch);
104
+ state.leaseSha = leaseSha;
105
+ process.stdout.write(this.runner.announce(cfg, state));
106
+ await this.runner.start(repoRoot, state);
107
+ }
108
+ /**
109
+ * Validate + finalize a 3-point merge with main that stage ① stopped on. The push mirrors stage ①'s:
110
+ * with no PR the rewrite reaches `origin/<feature>` (as `wp-finish-update` does); with a PR open it
111
+ * stays local, for the PR flow's one reviewed push.
112
+ */
113
+ async finalizeAnyInProgressMainMerge(repoRoot) {
114
+ const home = this.mergeState.mergeDirFor(repoRoot, await this.aiBranchName.getFeatureName());
115
+ const activeDir = this.mergeState.findActiveMergeRunDir(home);
116
+ const marker = activeDir ? this.mergeState.readMergeMarker(activeDir) : null;
117
+ if (!activeDir || !marker)
118
+ return;
119
+ process.stdout.write('\n' + SEP + '① Validating your 3-point merge with main\n' + SEP + '\n');
120
+ await this.mergeEnd.mergeEnd(repoRoot, 'wp-build-push-dev', activeDir, new merge_start_1.MergeContext(marker.currentBranch, marker.squashBranch, marker.backupBranch, marker.prNumber), new merge_end_1.MergeEndOptions(marker.validated ? null : marker.conflictedFiles, marker.prNumber === ''));
121
+ }
122
+ refuseBehindMain(branch) {
123
+ throw new rules_config_1.CliExitError(2, '\n' + SEP + `⛔ \`${branch}\` is behind origin/main\n` + SEP + '\n'
124
+ + 'A dev copy must be built from the latest main: a branch forked from an older main builds against a\n'
125
+ + 'node_modules missing whatever main added since, while dev already contains it. Nothing was merged,\n'
126
+ + 'built or recorded. Bring the branch up to date first (it runs the 3-point merge), then re-run this:\n'
127
+ + ` ${rules_config_1.WP_START_PUSH_DEV}\n`);
128
+ }
129
+ /**
130
+ * `origin/<devBranch>` does not exist yet — the very first publish in a repo whose CI has never
131
+ * composed. There is nothing to conflict with and no base for a dev-scoped build, so the branch is
132
+ * recorded as it is; refusing here would make the first dev composition impossible to start.
133
+ */
134
+ async verifyWithoutDev(repoRoot, cfg, branch, targetRef, leaseSha) {
135
+ const head = await this.refs.headSha(repoRoot, 'HEAD');
136
+ await this.gitExec.runGitChecked(['-C', repoRoot, 'update-ref', this.verified.keepRef(branch), head], `Failed to keep the verified copy ${head.slice(0, 8)} reachable`);
137
+ this.verified.write(repoRoot, new verified_dev_copy_1.VerifiedDevCopy(branch, head, head, targetRef, leaseSha, ''));
138
+ process.stdout.write('\n' + SEP + `✅ ${targetRef} is ready to publish — unchecked\n` + SEP + '\n'
139
+ + `\`origin/${cfg.devBranch}\` does not exist yet, so there was nothing to check the copy against and no\n`
140
+ + 'dev build ran. The copy is your branch exactly as it is.\n\n'
141
+ + `▶ NEXT run: ${rules_config_1.WP_FINISH_PUSH_DEV}\n`);
142
+ }
143
+ };
144
+ exports.BuildPushDevCommand = BuildPushDevCommand;
145
+ exports.BuildPushDevCommand = BuildPushDevCommand = tslib_1.__decorate([
146
+ (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
147
+ tslib_1.__metadata("design:paramtypes", [rules_config_1.RepoRootFinder,
148
+ git_exec_1.GitExec,
149
+ dev_deploy_refs_1.DevDeployRefs,
150
+ push_dev_state_1.PushDevStateStore,
151
+ dev_resolve_runner_1.DevResolveRunner,
152
+ dev_build_1.DevBuild,
153
+ main_freshness_1.MainFreshness,
154
+ verified_dev_copy_1.VerifiedDevCopyStore,
155
+ git_readAiBranchName_1.AiBranchName,
156
+ merge_state_1.MergeState,
157
+ merge_end_1.MergeEnd])
158
+ ], BuildPushDevCommand);
159
+ //# sourceMappingURL=build-push-dev-command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-push-dev-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/build-push-dev-command.ts"],"names":[],"mappings":";;;;AAAA,0DAOiC;AACjC,yCAA2D;AAE3D,mDAA+C;AAC/C,iEAA4D;AAC5D,+DAA6E;AAC7E,uEAAkE;AAClE,qDAAiD;AACjD,+DAA2D;AAC3D,qEAAsF;AACtF,2EAAgE;AAChE,yDAAqD;AACrD,qDAAkE;AAClE,yDAAuD;AAEvD,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,2EAA2E;AAC3E,MAAa,mBAAmB;IAC5B,sFAAsF;IACtF,KAAK,GAAG,KAAK,CAAC;IAEd,YAAY,KAAK,GAAG,KAAK;QACrB,IAAI,CAAC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,CAAC;6CAGA,6BAAc;QACrB,kBAAO;QACV,+BAAa;QACZ,kCAAiB;QAChB,qCAAgB;QACd,oBAAQ;QACH,8BAAa;QAClB,wCAAoB;QAChB,mCAAY;QACd,wBAAU;QACZ,oBAAQ;GAZ9B,mBAAmB,CAuG/B","sourcesContent":["import {\n CliExitError,\n DevDeployConfig,\n RepoRootFinder,\n WP_FINISH_PUSH_DEV,\n WP_START_PUSH_DEV,\n writeTemplate,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { GitExec } from '../workflow/git-exec';\nimport { DevDeployRefs } from '../workflow/dev-deploy-refs';\nimport { PushDevState, PushDevStateStore } from '../workflow/push-dev-state';\nimport { DevResolveRunner } from '../workflow/dev-resolve-runner';\nimport { DevBuild } from '../workflow/dev-build';\nimport { MainFreshness } from '../workflow/main-freshness';\nimport { VerifiedDevCopy, VerifiedDevCopyStore } from '../workflow/verified-dev-copy';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { MergeState } from '../workflow/merge-state';\nimport { MergeEnd, MergeEndOptions } from '../workflow/merge-end';\nimport { MergeContext } from '../workflow/merge-start';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/** What `wp-build-push-dev` was asked to do. Data-only (per CLAUDE.md). */\nexport class BuildPushDevOptions {\n /** Throw a conflict resolution in progress away and restore the original checkout. */\n abort = false;\n\n constructor(abort = false) {\n this.abort = abort;\n }\n}\n\n/**\n * `wp-build-push-dev` — stage ② of the dev-deploy flow, the gate (#1403). The twin of\n * `wp-review-upsert-pr`: it validates any 3-point merge stage ① left for `/wp-merge`, refuses a branch that\n * is behind `origin/main`, then checks the branch against `origin/<devBranch>` on a THROWAWAY merge, runs\n * `pnpm install` on the merged tree and `commands.push-dev.buildCommand` on it. Green ⇒ it records the\n * copy for `wp-finish-push-dev` (stage ③) and goes back to the feature branch. It publishes NOTHING.\n *\n * A conflict with dev stops on the throwaway, and RE-RUNNING this command is how the check continues once\n * the files are resolved and `git add`-ed (`--abort` throws it away) — one command per stage, the same way\n * stage ② of the PR flow is re-run after a fix.\n *\n * WHY THE CHECK AGAINST `dev` (#1397): 61 of 73 failed dev publishes on one consumer failed on a git\n * conflict, which the developer only learned about after the server-side composition failed. A build\n * against `main` alone proves the wrong thing; a build of only what differs from `dev` proves the right one,\n * quickly.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class BuildPushDevCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly gitExec: GitExec,\n private readonly refs: DevDeployRefs,\n private readonly store: PushDevStateStore,\n private readonly runner: DevResolveRunner,\n private readonly devBuild: DevBuild,\n private readonly mainFreshness: MainFreshness,\n private readonly verified: VerifiedDevCopyStore,\n private readonly aiBranchName: AiBranchName,\n private readonly mergeState: MergeState,\n private readonly mergeEnd: MergeEnd,\n ) {}\n\n async run(opts: BuildPushDevOptions): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n // Refresh the AI-facing workflow doc so it is present + current for any failure message to cite.\n writeTemplate(repoRoot, 'webpieces.git-workflow.md');\n\n if (opts.abort) {\n await this.runner.abort(repoRoot, this.store.require(repoRoot));\n return;\n }\n const inFlight = this.store.read(repoRoot);\n if (inFlight !== null) {\n // A conflict with dev was resolved: commit it and carry on with install + build + record.\n await this.runner.resume(repoRoot, inFlight);\n return;\n }\n\n // Stage ① may have handed a conflicted 3-point merge with main to /wp-merge; it is validated and\n // finalized HERE, before anything else, exactly as wp-review-upsert-pr does for the PR flow.\n await this.finalizeAnyInProgressMainMerge(repoRoot);\n\n const cfg = this.refs.config(repoRoot);\n const branch = this.refs.currentBranch(repoRoot);\n this.refs.assertPushable(cfg, branch);\n // Before any git write: an unconfigured dev build refuses here, with nothing merged.\n this.devBuild.command(repoRoot);\n // The merge below must be of committed work only, and must not sweep uncommitted edits along.\n await this.gitExec.assertCleanTree(repoRoot);\n if (!await this.mainFreshness.containsLatestMain(repoRoot)) this.refuseBehindMain(branch);\n\n // A previous verification is stale the moment a new check starts.\n this.verified.clear(repoRoot);\n const targetRef = cfg.copyRefFor(branch);\n const leaseSha = await this.refs.remoteSha(repoRoot, targetRef);\n if (await this.refs.remoteSha(repoRoot, cfg.devBranch) === '') {\n await this.verifyWithoutDev(repoRoot, cfg, branch, targetRef, leaseSha);\n return;\n }\n const state = new PushDevState(branch, this.runner.tmpBranchFor(branch), targetRef, cfg.devBranch);\n state.leaseSha = leaseSha;\n process.stdout.write(this.runner.announce(cfg, state));\n await this.runner.start(repoRoot, state);\n }\n\n /**\n * Validate + finalize a 3-point merge with main that stage ① stopped on. The push mirrors stage ①'s:\n * with no PR the rewrite reaches `origin/<feature>` (as `wp-finish-update` does); with a PR open it\n * stays local, for the PR flow's one reviewed push.\n */\n private async finalizeAnyInProgressMainMerge(repoRoot: string): Promise<void> {\n const home = this.mergeState.mergeDirFor(repoRoot, await this.aiBranchName.getFeatureName());\n const activeDir = this.mergeState.findActiveMergeRunDir(home);\n const marker = activeDir ? this.mergeState.readMergeMarker(activeDir) : null;\n if (!activeDir || !marker) return;\n process.stdout.write('\\n' + SEP + '① Validating your 3-point merge with main\\n' + SEP + '\\n');\n await this.mergeEnd.mergeEnd(\n repoRoot, 'wp-build-push-dev', activeDir,\n new MergeContext(marker.currentBranch, marker.squashBranch, marker.backupBranch, marker.prNumber),\n new MergeEndOptions(marker.validated ? null : marker.conflictedFiles, marker.prNumber === ''),\n );\n }\n\n private refuseBehindMain(branch: string): never {\n throw new CliExitError(2,\n '\\n' + SEP + `⛔ \\`${branch}\\` is behind origin/main\\n` + SEP + '\\n'\n + 'A dev copy must be built from the latest main: a branch forked from an older main builds against a\\n'\n + 'node_modules missing whatever main added since, while dev already contains it. Nothing was merged,\\n'\n + 'built or recorded. Bring the branch up to date first (it runs the 3-point merge), then re-run this:\\n'\n + ` ${WP_START_PUSH_DEV}\\n`);\n }\n\n /**\n * `origin/<devBranch>` does not exist yet — the very first publish in a repo whose CI has never\n * composed. There is nothing to conflict with and no base for a dev-scoped build, so the branch is\n * recorded as it is; refusing here would make the first dev composition impossible to start.\n */\n private async verifyWithoutDev(\n repoRoot: string, cfg: DevDeployConfig, branch: string, targetRef: string, leaseSha: string,\n ): Promise<void> {\n const head = await this.refs.headSha(repoRoot, 'HEAD');\n await this.gitExec.runGitChecked(['-C', repoRoot, 'update-ref', this.verified.keepRef(branch), head],\n `Failed to keep the verified copy ${head.slice(0, 8)} reachable`);\n this.verified.write(repoRoot, new VerifiedDevCopy(branch, head, head, targetRef, leaseSha, ''));\n process.stdout.write(\n '\\n' + SEP + `✅ ${targetRef} is ready to publish — unchecked\\n` + SEP + '\\n'\n + `\\`origin/${cfg.devBranch}\\` does not exist yet, so there was nothing to check the copy against and no\\n`\n + 'dev build ran. The copy is your branch exactly as it is.\\n\\n'\n + `▶ NEXT run: ${WP_FINISH_PUSH_DEV}\\n`);\n }\n}\n"]}
@@ -1,28 +1,84 @@
1
1
  import { RepoRootFinder } from '@webpieces/rules-config';
2
- import { PushDevStateStore } from '../workflow/push-dev-state';
3
- import { DevResolveRunner } from '../workflow/dev-resolve-runner';
4
- /** What `wp-finish-push-dev` was asked to do. Data-only (per CLAUDE.md). */
2
+ import { GitExec } from '../workflow/git-exec';
3
+ import { DevDeployRefs } from '../workflow/dev-deploy-refs';
4
+ import { DevDeployWatchHints } from '../workflow/dev-deploy-watch-hints';
5
+ import { DevCopyOnMain } from '../workflow/dev-copy-on-main';
6
+ import { VerifiedDevCopyStore } from '../workflow/verified-dev-copy';
7
+ /**
8
+ * Which of `wp-finish-push-dev`'s modes was asked for. Data-only (per CLAUDE.md) with plain assigned
9
+ * fields — the bin sets what argv carried and nothing else.
10
+ */
5
11
  export declare class FinishPushDevOptions {
6
- /** Throw the whole resolve away and restore the original checkout. */
7
- abort: boolean;
8
- constructor(abort?: boolean);
12
+ /** Delete the remote copy and push the rebuild marker — the rollback. */
13
+ remove: boolean;
14
+ /** List the live copies and stop. */
15
+ list: boolean;
9
16
  }
10
17
  /**
11
- * `wp-finish-push-dev` — stage ② of the dev-deploy flow, needed ONLY when a merge stopped.
18
+ * `wp-finish-push-dev` — stage ③ of the dev-deploy flow (#1403): publish the copy `wp-build-push-dev`
19
+ * verified as `<namespace>/<branch>`, so a shared dev environment can build it, without landing anything
20
+ * on `main` and without opening a PR. Also `--list` (the pool) and `--remove` (the rollback).
21
+ *
22
+ * WHY THIS COMMAND HAS TO EXIST AT ALL: `pr-creation-or-push-guard` blocks every `git push`, no
23
+ * exceptions, by design. Without a gated command there is no legal way for an AI to get a branch onto a
24
+ * dev server.
12
25
  *
13
- * It mirrors `wp-start-update` → `wp-finish-update` on purpose: the repo already has a two-phase
14
- * start/finish idiom for exactly this shape ("the tool merges, you resolve, the tool commits"), and a
15
- * `--continue` idiom invented here would be a second vocabulary for one concept. A clean `wp-push-dev
16
- * --resolve` finalizes itself and this command is never needed.
26
+ * IT PUBLISHES ONLY WHAT WAS VERIFIED: stage ② records the feature head it built and the copy it made; this
27
+ * refuses when HEAD has moved since (a new commit nobody built), exactly as `wp-finish-upsert-pr` trusts
28
+ * only the sha stage ② of the PR flow verified.
17
29
  *
18
- * The command owns the commit because the AI cannot make it: `redirect-how-to-merge-main` blocks
19
- * `git merge --continue` and `merge-in-progress-guard` blocks `git commit`. Editing the conflicted files
20
- * and `git add`-ing them is the AI's whole job, and neither is blocked.
30
+ * IT FORCE-PUSHES, leased against the copy sha stage ② saw. Stage ① rewrites the branch on almost every
31
+ * publish, so the new copy is rarely a fast-forward of the old one, and the push event's `before` is then
32
+ * the previous copy — which is what a consumer's dev CI needs to apply only the difference (#1403).
21
33
  */
22
34
  export declare class FinishPushDevCommand {
23
35
  private readonly repoRootFinder;
24
- private readonly store;
25
- private readonly runner;
26
- constructor(repoRootFinder: RepoRootFinder, store: PushDevStateStore, runner: DevResolveRunner);
36
+ private readonly gitExec;
37
+ private readonly refs;
38
+ private readonly verified;
39
+ private readonly watchHints;
40
+ private readonly copyOnMain;
41
+ constructor(repoRootFinder: RepoRootFinder, gitExec: GitExec, refs: DevDeployRefs, verified: VerifiedDevCopyStore, watchHints: DevDeployWatchHints, copyOnMain: DevCopyOnMain);
27
42
  run(opts: FinishPushDevOptions): Promise<void>;
43
+ /** The publish: the verified copy, force-pushed with a lease, then the watch hints. */
44
+ private publish;
45
+ private refuseUnverified;
46
+ private refuseMoved;
47
+ /** `--list`: exactly the live copies, straight from the remote — never a cached local view. */
48
+ private list;
49
+ /**
50
+ * `--remove`: delete the remote copy, then push the `<removeNamespace>/<branch>` marker (#1395). This
51
+ * IS the rollback — nothing else has to be undone.
52
+ *
53
+ * WHY A MARKER AS WELL AS THE DELETION: a deletion can only be heard by a workflow's `on: delete:`,
54
+ * which GitHub cannot filter by branch, so every branch deletion in the repo started a dev-deploy run.
55
+ * A PUSH to `<removeNamespace>/**` is filterable. The deletion stays, unchanged, so a consumer whose
56
+ * workflow still listens on `delete:` keeps working through the rollout window; the marker is purely
57
+ * additive at the transport level.
58
+ *
59
+ * ALREADY ON MAIN (#1401): before anything is deleted, the copy is compared with `origin/main`. When
60
+ * every file it changes already has the copy's content on main, removing it takes nothing off dev —
61
+ * main keeps the change there — and would only force a pointless full recompose, so it is REFUSED
62
+ * ({@link refuseLanded}). When only some files are, the rest is still a real rollback: it warns, naming
63
+ * the landed files, and removes.
64
+ *
65
+ * ORDER: `origin/main` and the copy are fetched BEFORE anything is deleted, so a network failure there
66
+ * leaves the pool exactly as it was. The marker push is the last step, and the only one that can fail with the
67
+ * copy already gone — that is the state {@link markerPushFailed} names.
68
+ */
69
+ private remove;
70
+ /**
71
+ * `--remove` of a copy whose every change is already on `origin/main`. Nothing was deleted and no marker
72
+ * was pushed. There is deliberately no override: a remove cannot take back what main already holds, so
73
+ * refusing never blocks a real rollback — that is a revert PR.
74
+ */
75
+ private refuseLanded;
76
+ /** Some of the copy's files are already on main: the remove proceeds, and says what it does NOT take off. */
77
+ private partlyLandedWarning;
78
+ /**
79
+ * The one half-done state `--remove` can leave: the copy is deleted, the rebuild signal is not sent.
80
+ * Said out loud because it is invisible otherwise — `--list` already looks right, while the deployed
81
+ * `dev` still runs the removed branch until something else triggers a composition.
82
+ */
83
+ private markerPushFailed;
28
84
  }