@webpieces/pr-gate 0.4.983 → 0.4.984
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -6
- package/src/scripts/commands/push-dev-command.d.ts +19 -3
- package/src/scripts/commands/push-dev-command.js +42 -4
- package/src/scripts/commands/push-dev-command.js.map +1 -1
- package/src/scripts/workflow/dev-copy-on-main.d.ts +49 -0
- package/src/scripts/workflow/dev-copy-on-main.js +99 -0
- package/src/scripts/workflow/dev-copy-on-main.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/pr-gate",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.984",
|
|
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,18 +16,18 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@inversifyjs/binding-decorators": "1.1.5",
|
|
19
|
-
"@webpieces/hook-runtime": "0.4.
|
|
20
|
-
"@webpieces/rules-config": "0.4.
|
|
19
|
+
"@webpieces/hook-runtime": "0.4.984",
|
|
20
|
+
"@webpieces/rules-config": "0.4.984",
|
|
21
21
|
"inversify": "7.10.4",
|
|
22
22
|
"reflect-metadata": "0.2.2",
|
|
23
|
-
"@webpieces/tooling-common": "0.4.
|
|
24
|
-
"@webpieces/repo-workflow-core": "0.4.
|
|
23
|
+
"@webpieces/tooling-common": "0.4.984",
|
|
24
|
+
"@webpieces/repo-workflow-core": "0.4.984"
|
|
25
25
|
},
|
|
26
26
|
"publishConfig": {
|
|
27
27
|
"access": "public"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@webpieces/tooling-testkit": "0.4.
|
|
30
|
+
"@webpieces/tooling-testkit": "0.4.984"
|
|
31
31
|
},
|
|
32
32
|
"types": "./src/index.d.ts",
|
|
33
33
|
"bin": {
|
|
@@ -5,6 +5,7 @@ import { PushDevStateStore } from '../workflow/push-dev-state';
|
|
|
5
5
|
import { DevResolveRunner } from '../workflow/dev-resolve-runner';
|
|
6
6
|
import { DevDeployWatchHints } from '../workflow/dev-deploy-watch-hints';
|
|
7
7
|
import { DevBuild } from '../workflow/dev-build';
|
|
8
|
+
import { DevCopyOnMain } from '../workflow/dev-copy-on-main';
|
|
8
9
|
/**
|
|
9
10
|
* Which of `wp-push-dev`'s modes was asked for. Data-only (per CLAUDE.md) with plain assigned fields
|
|
10
11
|
* rather than a seven-argument constructor — the bin sets what argv carried and nothing else.
|
|
@@ -56,7 +57,8 @@ export declare class PushDevCommand {
|
|
|
56
57
|
private readonly runner;
|
|
57
58
|
private readonly watchHints;
|
|
58
59
|
private readonly devBuild;
|
|
59
|
-
|
|
60
|
+
private readonly copyOnMain;
|
|
61
|
+
constructor(repoRootFinder: RepoRootFinder, gitExec: GitExec, refs: DevDeployRefs, store: PushDevStateStore, runner: DevResolveRunner, watchHints: DevDeployWatchHints, devBuild: DevBuild, copyOnMain: DevCopyOnMain);
|
|
60
62
|
run(opts: PushDevOptions): Promise<void>;
|
|
61
63
|
/** `--list`: exactly the live copies, straight from the remote — never a cached local view. */
|
|
62
64
|
private list;
|
|
@@ -70,11 +72,25 @@ export declare class PushDevCommand {
|
|
|
70
72
|
* workflow still listens on `delete:` keeps working through the rollout window; the marker is purely
|
|
71
73
|
* additive at the transport level.
|
|
72
74
|
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
+
* ALREADY ON MAIN (#1401): before anything is deleted, the copy is compared with `origin/main`. When
|
|
76
|
+
* every file it changes already has the copy's content on main, removing it takes nothing off dev —
|
|
77
|
+
* main keeps the change there — and would only force a pointless full recompose, so it is REFUSED
|
|
78
|
+
* ({@link refuseLanded}). When only some files are, the rest is still a real rollback: it warns, naming
|
|
79
|
+
* the landed files, and removes.
|
|
80
|
+
*
|
|
81
|
+
* ORDER: `origin/main` and the copy are fetched BEFORE anything is deleted, so a network failure there
|
|
82
|
+
* leaves the pool exactly as it was. The marker push is the last step, and the only one that can fail with the
|
|
75
83
|
* copy already gone — that is the state {@link markerPushFailed} names.
|
|
76
84
|
*/
|
|
77
85
|
private remove;
|
|
86
|
+
/**
|
|
87
|
+
* `--remove` of a copy whose every change is already on `origin/main`. Nothing was deleted and no marker
|
|
88
|
+
* was pushed. There is deliberately no override: a remove cannot take back what main already holds, so
|
|
89
|
+
* refusing never blocks a real rollback — that is a revert PR.
|
|
90
|
+
*/
|
|
91
|
+
private refuseLanded;
|
|
92
|
+
/** Some of the copy's files are already on main: the remove proceeds, and says what it does NOT take off. */
|
|
93
|
+
private partlyLandedWarning;
|
|
78
94
|
/**
|
|
79
95
|
* The one half-done state `--remove` can leave: the copy is deleted, the rebuild signal is not sent.
|
|
80
96
|
* Said out loud because it is invisible otherwise — `--list` already looks right, while the deployed
|
|
@@ -10,6 +10,7 @@ const push_dev_state_1 = require("../workflow/push-dev-state");
|
|
|
10
10
|
const dev_resolve_runner_1 = require("../workflow/dev-resolve-runner");
|
|
11
11
|
const dev_deploy_watch_hints_1 = require("../workflow/dev-deploy-watch-hints");
|
|
12
12
|
const dev_build_1 = require("../workflow/dev-build");
|
|
13
|
+
const dev_copy_on_main_1 = require("../workflow/dev-copy-on-main");
|
|
13
14
|
const SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n';
|
|
14
15
|
/**
|
|
15
16
|
* Which of `wp-push-dev`'s modes was asked for. Data-only (per CLAUDE.md) with plain assigned fields
|
|
@@ -63,7 +64,8 @@ let PushDevCommand = class PushDevCommand {
|
|
|
63
64
|
runner;
|
|
64
65
|
watchHints;
|
|
65
66
|
devBuild;
|
|
66
|
-
|
|
67
|
+
copyOnMain;
|
|
68
|
+
constructor(repoRootFinder, gitExec, refs, store, runner, watchHints, devBuild, copyOnMain) {
|
|
67
69
|
this.repoRootFinder = repoRootFinder;
|
|
68
70
|
this.gitExec = gitExec;
|
|
69
71
|
this.refs = refs;
|
|
@@ -71,6 +73,7 @@ let PushDevCommand = class PushDevCommand {
|
|
|
71
73
|
this.runner = runner;
|
|
72
74
|
this.watchHints = watchHints;
|
|
73
75
|
this.devBuild = devBuild;
|
|
76
|
+
this.copyOnMain = copyOnMain;
|
|
74
77
|
}
|
|
75
78
|
async run(opts) {
|
|
76
79
|
const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());
|
|
@@ -126,8 +129,14 @@ let PushDevCommand = class PushDevCommand {
|
|
|
126
129
|
* workflow still listens on `delete:` keeps working through the rollout window; the marker is purely
|
|
127
130
|
* additive at the transport level.
|
|
128
131
|
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
132
|
+
* ALREADY ON MAIN (#1401): before anything is deleted, the copy is compared with `origin/main`. When
|
|
133
|
+
* every file it changes already has the copy's content on main, removing it takes nothing off dev —
|
|
134
|
+
* main keeps the change there — and would only force a pointless full recompose, so it is REFUSED
|
|
135
|
+
* ({@link refuseLanded}). When only some files are, the rest is still a real rollback: it warns, naming
|
|
136
|
+
* the landed files, and removes.
|
|
137
|
+
*
|
|
138
|
+
* ORDER: `origin/main` and the copy are fetched BEFORE anything is deleted, so a network failure there
|
|
139
|
+
* leaves the pool exactly as it was. The marker push is the last step, and the only one that can fail with the
|
|
131
140
|
* copy already gone — that is the state {@link markerPushFailed} names.
|
|
132
141
|
*/
|
|
133
142
|
async remove(repoRoot, cfg, branch, targetRef) {
|
|
@@ -138,6 +147,13 @@ let PushDevCommand = class PushDevCommand {
|
|
|
138
147
|
}
|
|
139
148
|
const markerRef = cfg.removeMarkerRefFor(branch);
|
|
140
149
|
const mainTip = await this.refs.freshMainTip(repoRoot);
|
|
150
|
+
await this.refs.fetchCopies(repoRoot, [targetRef]);
|
|
151
|
+
const landing = await this.copyOnMain.landing(repoRoot, targetRef);
|
|
152
|
+
if (landing.fullyOnMain()) {
|
|
153
|
+
this.refuseLanded(targetRef, await this.copyOnMain.mergedPr(repoRoot, branch));
|
|
154
|
+
}
|
|
155
|
+
if (landing.partlyOnMain())
|
|
156
|
+
process.stdout.write(this.partlyLandedWarning(targetRef, landing));
|
|
141
157
|
await this.gitExec.runGitChecked(['-C', repoRoot, 'push', 'origin', '--delete', `refs/heads/${targetRef}`], `Failed to delete the dev copy ${targetRef}`);
|
|
142
158
|
// --force: the marker carries no content, so whatever an earlier, never-deleted marker pointed at
|
|
143
159
|
// is worthless — and refusing a non-fast-forward here would strand the rollback half-done.
|
|
@@ -149,6 +165,27 @@ let PushDevCommand = class PushDevCommand {
|
|
|
149
165
|
+ `on it, deletes it, and rebuilds \`${cfg.devBranch}\` without \`${branch}\`. Your branch and any PR on it\n`
|
|
150
166
|
+ 'are untouched.\n');
|
|
151
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* `--remove` of a copy whose every change is already on `origin/main`. Nothing was deleted and no marker
|
|
170
|
+
* was pushed. There is deliberately no override: a remove cannot take back what main already holds, so
|
|
171
|
+
* refusing never blocks a real rollback — that is a revert PR.
|
|
172
|
+
*/
|
|
173
|
+
refuseLanded(targetRef, pr) {
|
|
174
|
+
const landedVia = pr === null ? '' : ` (PR #${pr.num} landed ${pr.mergedAt})`;
|
|
175
|
+
throw new rules_config_1.CliExitError(2, '\n' + SEP + `⛔ \`${targetRef}\` is already on origin/main — nothing was removed\n` + SEP + '\n'
|
|
176
|
+
+ `\`${targetRef}\` is already on origin/main${landedVia}, so removing the copy\n`
|
|
177
|
+
+ 'would not take anything off dev — main keeps it there. The nightly reset deletes the copy.\n'
|
|
178
|
+
+ 'Nothing was removed, and no rebuild marker was pushed.\n\n'
|
|
179
|
+
+ 'If that code is what broke dev, it is on main now: the fix is a revert PR against main, not a remove.\n');
|
|
180
|
+
}
|
|
181
|
+
/** Some of the copy's files are already on main: the remove proceeds, and says what it does NOT take off. */
|
|
182
|
+
partlyLandedWarning(targetRef, landing) {
|
|
183
|
+
return '\n' + SEP + `⚠️ Part of \`${targetRef}\` is already on origin/main\n` + SEP + '\n'
|
|
184
|
+
+ `${String(landing.landed.length)} of the ${String(landing.changed.length)} files this copy changes already have the copy's content on\n`
|
|
185
|
+
+ 'origin/main. Removing the copy does NOT take these off dev — main keeps them there:\n'
|
|
186
|
+
+ landing.landed.map((f) => ` ${f}`).join('\n') + '\n'
|
|
187
|
+
+ 'Only the rest of the copy is being removed. If one of the files above broke dev, the fix is a revert PR.\n';
|
|
188
|
+
}
|
|
152
189
|
/**
|
|
153
190
|
* The one half-done state `--remove` can leave: the copy is deleted, the rebuild signal is not sent.
|
|
154
191
|
* Said out loud because it is invisible otherwise — `--list` already looks right, while the deployed
|
|
@@ -313,6 +350,7 @@ exports.PushDevCommand = PushDevCommand = tslib_1.__decorate([
|
|
|
313
350
|
push_dev_state_1.PushDevStateStore,
|
|
314
351
|
dev_resolve_runner_1.DevResolveRunner,
|
|
315
352
|
dev_deploy_watch_hints_1.DevDeployWatchHints,
|
|
316
|
-
dev_build_1.DevBuild
|
|
353
|
+
dev_build_1.DevBuild,
|
|
354
|
+
dev_copy_on_main_1.DevCopyOnMain])
|
|
317
355
|
], PushDevCommand);
|
|
318
356
|
//# sourceMappingURL=push-dev-command.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"push-dev-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/push-dev-command.ts"],"names":[],"mappings":";;;;AAAA,0DAOiC;AACjC,yCAA2D;AAE3D,mDAA+C;AAC/C,iEAAqE;AACrE,+DAA6F;AAC7F,uEAAsF;AACtF,+EAAyE;AACzE,qDAAiD;AAEjD,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;GAGG;AACH,MAAa,cAAc;IACvB,6CAA6C;IAC7C,MAAM,GAAG,KAAK,CAAC;IACf,sFAAsF;IACtF,IAAI,GAAG,KAAK,CAAC;IACb,qFA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BAAyB,SAAS,IAAI,CAAC,CAAC;IACvG,CAAC;IAED,kGAAkG;IAClG,yEAAyE;IACjE,yBAAyB,CAAC,QAAgB;QAC9C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxC,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO;QAC3B,MAAM,IAAI,2BAAY,CAAC,CAAC,EACpB,IAAI,GAAG,GAAG,GAAG,iDAAiD,GAAG,GAAG,GAAG,IAAI;cACzE,qCAAqC,KAAK,CAAC,SAAS,+CAA+C;cACnG,KAAK,iCAAkB,kEAAkE;cACzF,KAAK,iCAAkB,gDAAgD,KAAK,CAAC,cAAc,MAAM,CAAC,CAAC;IAC7G,CAAC;CACJ,CAAA;AA7QY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QACrB,kBAAO;QACV,+BAAa;QACZ,kCAAiB;QAChB,qCAAgB;QACZ,4CAAmB;QACrB,oBAAQ;GAR9B,cAAc,CA6Q1B","sourcesContent":["import {\n CliExitError,\n DevDeployConfig,\n RepoRootFinder,\n WP_FINISH_PUSH_DEV,\n WP_PUSH_DEV,\n writeTemplate,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { GitExec } from '../workflow/git-exec';\nimport { DevCopy, DevDeployRefs } from '../workflow/dev-deploy-refs';\nimport { DevResolveMode, PushDevState, PushDevStateStore } from '../workflow/push-dev-state';\nimport { DevResolveRunner, RESOLUTION_SUBJECT } from '../workflow/dev-resolve-runner';\nimport { DevDeployWatchHints } from '../workflow/dev-deploy-watch-hints';\nimport { DevBuild } from '../workflow/dev-build';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * Which of `wp-push-dev`'s modes was asked for. Data-only (per CLAUDE.md) with plain assigned fields\n * rather than a seven-argument constructor — the bin sets what argv carried and nothing else.\n */\nexport class PushDevOptions {\n /** Delete the remote copy — the rollback. */\n remove = false;\n /** List the live copies and stop. The one mode that needs no branch preconditions. */\n list = false;\n /** Discard a conflict resolution already published on the copy, and overwrite it. */\n force = false;\n /** Replay that resolution on top of the new local commits instead of discarding it. */\n rebaseResolution = false;\n /** Compose the other copies onto this one so the shared environment can build them together. */\n resolve = false;\n /** With `--resolve`: merge ONLY this developer's branch. Empty ⇒ every other copy. */\n resolveTarget = '';\n}\n\n/**\n * `wp-push-dev` — publish a DISPOSABLE copy of this branch so a shared dev environment can build it,\n * without landing anything on `main` and without opening a PR.\n *\n * WHY THIS COMMAND HAS TO EXIST AT ALL: `pr-creation-or-push-guard` blocks every `git push`, no\n * exceptions, by design. Its own fix-hint offers \"ask a human to run the push\" for out-of-band cases —\n * which is the right answer for a genuine exception and the wrong one for a routine daily action. Without\n * a gated command there is simply no legal way for an AI to get a branch onto a dev server, so the\n * feature was undoable rather than merely awkward.\n *\n * WHY IT CHECKS AGAINST `dev` FIRST (#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. So a plain\n * publish now does locally what CI is about to do: merge `origin/<devBranch>` into a THROWAWAY branch,\n * resolve any conflict there (the same halt / `wp-finish-push-dev` state machine `--resolve` uses), and run\n * `commands.push-dev.buildCommand` on the merged tree. A build against `main` alone would prove the wrong\n * thing; a build of only what differs from `dev` proves the right one, quickly.\n *\n * WHAT IS PUBLISHED IS NEVER THAT MERGE: the copy is the feature head plus, when something conflicted, one\n * commit recording the resolved files (DevResolveRunner.recordResolution). A copy that contained `dev`\n * would carry every other copy's history, and a later `--remove` of one of them would leave it on dev\n * through this one.\n *\n * WHAT IT NEVER DOES: touch the feature branch. See DevDeployRefs for the invariant and why the copy\n * exists to hold conflict resolutions that must not reach the PR.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class PushDevCommand {\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 watchHints: DevDeployWatchHints,\n private readonly devBuild: DevBuild,\n ) {}\n\n async run(opts: PushDevOptions): 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 // same reason every other wp-* command opens this way.\n writeTemplate(repoRoot, 'webpieces.git-workflow.md');\n const cfg = this.refs.config(repoRoot);\n\n // A resolve already in flight owns the checkout; starting a second one would strand the first.\n this.assertNoResolveInProgress(repoRoot);\n\n if (opts.list) {\n await this.list(repoRoot, cfg);\n return;\n }\n\n const branch = this.refs.currentBranch(repoRoot);\n this.refs.assertPushable(cfg, branch);\n const targetRef = cfg.copyRefFor(branch);\n\n if (opts.remove) {\n await this.remove(repoRoot, cfg, branch, targetRef);\n return;\n }\n // Every remaining mode commits or merges, so the tree must be the AI's committed work and nothing\n // else. The tooling never commits for you.\n await this.gitExec.assertCleanTree(repoRoot);\n\n if (opts.resolve) {\n await this.startResolve(repoRoot, cfg, branch, targetRef, opts.resolveTarget);\n return;\n }\n await this.publish(repoRoot, cfg, branch, targetRef, opts);\n }\n\n /** `--list`: exactly the live copies, straight from the remote — never a cached local view. */\n private async list(repoRoot: string, cfg: DevDeployConfig): Promise<void> {\n const copies = await this.refs.liveCopies(repoRoot, cfg);\n if (copies.length === 0) {\n process.stdout.write(\n `\\nNo dev copies published — nothing matches \\`${cfg.copyRefGlob()}\\` on origin.\\n`\n + `Publish this branch's with: ${WP_PUSH_DEV}\\n`);\n return;\n }\n let out = '\\n' + SEP + `📋 ${String(copies.length)} dev cop${copies.length === 1 ? 'y' : 'ies'} on origin\\n` + SEP + '\\n';\n for (const copy of copies) out += ` ${copy.sha.slice(0, 8)} ${copy.ref}\\n`;\n out += `\\nYour CI composes \\`${cfg.devBranch}\\` from origin/main plus every ref above, on every run.\\n`\n + `Remove yours with: ${WP_PUSH_DEV} --remove (deletes your copy, then pushes the content-free\\n`\n + `\\`${cfg.removeMarkerRefFor('<your-branch>')}\\` marker your dev workflow triggers on and deletes)\\n`;\n process.stdout.write(out);\n }\n\n /**\n * `--remove`: delete the remote copy, then push the `<removeNamespace>/<branch>` marker (#1395). This\n * IS the rollback — nothing else has to be undone.\n *\n * WHY A MARKER AS WELL AS THE DELETION: a deletion can only be heard by a workflow's `on: delete:`,\n * which GitHub cannot filter by branch, so every branch deletion in the repo started a dev-deploy run.\n * A PUSH to `<removeNamespace>/**` is filterable. The deletion stays, unchanged, so a consumer whose\n * workflow still listens on `delete:` keeps working through the rollout window; the marker is purely\n * additive at the transport level.\n *\n * ORDER: `origin/main` is fetched BEFORE anything is deleted, so a network failure there leaves the\n * pool exactly as it was. The marker push is the last step, and the only one that can fail with the\n * copy already gone — that is the state {@link markerPushFailed} names.\n */\n private async remove(repoRoot: string, cfg: DevDeployConfig, branch: string, targetRef: string): Promise<void> {\n if (await this.refs.remoteSha(repoRoot, targetRef) === '') {\n process.stdout.write(\n `\\nNothing to remove — \\`${targetRef}\\` is not published.\\n`\n + `List what IS published with: ${WP_PUSH_DEV} --list\\n`);\n return;\n }\n const markerRef = cfg.removeMarkerRefFor(branch);\n const mainTip = await this.refs.freshMainTip(repoRoot);\n await this.gitExec.runGitChecked(['-C', repoRoot, 'push', 'origin', '--delete', `refs/heads/${targetRef}`],\n `Failed to delete the dev copy ${targetRef}`);\n // --force: the marker carries no content, so whatever an earlier, never-deleted marker pointed at\n // is worthless — and refusing a non-fast-forward here would strand the rollback half-done.\n const pushed = await this.gitExec.tryGit(\n ['-C', repoRoot, 'push', '--force', 'origin', `${mainTip}:refs/heads/${markerRef}`], repoRoot);\n if (!pushed.ok) this.markerPushFailed(cfg, branch, targetRef, markerRef, pushed.stderr);\n process.stdout.write(\n '\\n' + SEP + `🗑️ Removed ${targetRef}\\n` + SEP + '\\n'\n + `Pushed the marker \\`${markerRef}\\` (at origin/main ${mainTip.slice(0, 8)}) — your dev workflow triggers\\n`\n + `on it, deletes it, and rebuilds \\`${cfg.devBranch}\\` without \\`${branch}\\`. Your branch and any PR on it\\n`\n + 'are untouched.\\n');\n }\n\n /**\n * The one half-done state `--remove` can leave: the copy is deleted, the rebuild signal is not sent.\n * Said out loud because it is invisible otherwise — `--list` already looks right, while the deployed\n * `dev` still runs the removed branch until something else triggers a composition.\n */\n private markerPushFailed(cfg: DevDeployConfig, branch: string, targetRef: string, markerRef: string, stderr: string): never {\n throw new CliExitError(1,\n '\\n' + SEP + `⛔ Removed \\`${targetRef}\\`, but pushing the rebuild marker \\`${markerRef}\\` FAILED\\n` + SEP + '\\n'\n + `Your copy is already GONE from origin, but \\`${cfg.devBranch}\\` was NOT rebuilt: the deployed dev server\\n`\n + `still runs \\`${branch}\\` until the next composition run.\\n\\n`\n + 'git said:\\n' + (stderr === '' ? ' (no output)' : stderr.split('\\n').map((l: string): string => ` ${l}`).join('\\n')) + '\\n\\n'\n + 'Any later composition run drops your branch on its own, because the copy no longer exists — the next\\n'\n + `\\`${WP_PUSH_DEV}\\` by anyone, or a push to main if your workflow composes on that. To force one now,\\n`\n + 'once the cause above is fixed (network, auth, a branch-protection rule on the marker namespace),\\n'\n + 're-publish and remove again; the second remove pushes the marker:\\n\\n'\n + ` ${WP_PUSH_DEV}\\n ${WP_PUSH_DEV} --remove\\n`);\n }\n\n /**\n * The ordinary path: check the copy against `origin/<devBranch>`, build it, then publish it as\n * `<namespace>/<branch>` (#1397). The merge, the conflict halt and the build all happen on a throwaway\n * branch through DevResolveRunner, in DevResolveMode.PREBUILD — so a conflict stops in exactly the\n * same `wp-finish-push-dev` state machine `--resolve` uses, rather than inventing a second way to be\n * stuck.\n *\n * THE CLOBBER GUARD runs first. If the remote copy holds commits the local branch does not, somebody\n * (quite possibly this developer, days ago) put real work there, and a silent force-push destroys it,\n * so the default is refusal with two named ways forward — never a \"use --force\" one-liner, which is how\n * a warning becomes a reflex. The one exception is a commit this flow wrote itself\n * ({@link RESOLUTION_SUBJECT}): the check below re-derives it against today's dev, so replacing it\n * loses nothing.\n */\n private async publish(repoRoot: string, cfg: DevDeployConfig, branch: string, targetRef: string, opts: PushDevOptions): Promise<void> {\n const remoteSha = await this.refs.remoteSha(repoRoot, targetRef);\n if (remoteSha !== '') {\n await this.refs.fetchCopies(repoRoot, [targetRef]);\n const subjects = await this.refs.subjectsOnlyOnRemote(repoRoot, targetRef);\n const ahead = subjects.filter((s: string): boolean => !s.startsWith(RESOLUTION_SUBJECT)).length;\n if (ahead > 0 && opts.rebaseResolution) {\n await this.rebaseResolution(repoRoot, branch, targetRef);\n return;\n }\n if (ahead > 0 && !opts.force) this.refuseClobber(cfg, branch, targetRef, ahead);\n }\n // Before any git write: an unconfigured dev build refuses here, with nothing merged or published.\n this.devBuild.command(repoRoot);\n if (await this.refs.remoteSha(repoRoot, cfg.devBranch) === '') {\n await this.publishWithoutDev(repoRoot, cfg, branch, targetRef, remoteSha, opts.force);\n return;\n }\n const state = new PushDevState(branch, this.runner.tmpBranchFor(branch), targetRef, [cfg.devBranch]);\n state.mode = DevResolveMode.PREBUILD;\n state.leaseSha = remoteSha;\n state.force = opts.force;\n process.stdout.write(this.runner.announcePrebuild(cfg, state));\n await this.runner.start(repoRoot, state, 'HEAD', [cfg.devBranch]);\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 copy is\n * published as it is; refusing here would make the first dev composition impossible to start.\n */\n private async publishWithoutDev(\n repoRoot: string, cfg: DevDeployConfig, branch: string, targetRef: string, remoteSha: string, force: boolean,\n ): Promise<void> {\n const lease = remoteSha === '' ? [] : force ? ['--force'] : [`--force-with-lease=refs/heads/${targetRef}:${remoteSha}`];\n await this.gitExec.runGitChecked(['-C', repoRoot, 'push', ...lease, 'origin', `HEAD:refs/heads/${targetRef}`],\n `Failed to publish the dev copy ${targetRef}`);\n const published = await this.refs.headSha(repoRoot);\n process.stdout.write(\n '\\n' + SEP + `✅ Published ${targetRef}\\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. \\`${branch}\\` is now in the pool your CI composes \\`${cfg.devBranch}\\` from.\\n\\n`\n + ` ${WP_PUSH_DEV} --list ← what else is in the pool\\n`\n + ` ${WP_PUSH_DEV} --remove ← take this branch back out\\n`\n + this.watchHints.render(cfg, targetRef, published));\n }\n\n /**\n * `--rebase-resolution`: keep the published resolution, replay it on top of the new commits.\n *\n * Implemented as a resolve whose BASE is the local HEAD and whose queue is the copy itself, so a\n * replay that conflicts again lands in exactly the same halt/`wp-finish-push-dev` state machine as\n * any other conflict, rather than inventing a second way to be stuck.\n */\n private async rebaseResolution(repoRoot: string, branch: string, targetRef: string): Promise<void> {\n const state = new PushDevState(branch, this.runner.tmpBranchFor(branch), targetRef, [targetRef]);\n state.mode = DevResolveMode.REPLAY;\n process.stdout.write(\n '\\n' + SEP + `♻️ Replaying the published resolution onto \\`${branch}\\`\\n` + SEP + '\\n'\n + `Merging \\`${targetRef}\\` (which holds the resolution) into your new commits on a throwaway branch.\\n`\n + `Your feature branch \\`${branch}\\` is not touched.\\n\\n`);\n await this.runner.start(repoRoot, state, 'HEAD', [targetRef]);\n }\n\n /**\n * `--resolve`: compose the other copies onto this one, so what is published is what CI will build.\n *\n * With no argument the queue is EVERY other copy, in the same sorted order CI composes them — the\n * local resolution is then a rehearsal of the real composition, not a guess at it. With an argument\n * (the branch a CI conflict message names) it is just that one.\n */\n private async startResolve(repoRoot: string, cfg: DevDeployConfig, branch: string, targetRef: string, only: string): Promise<void> {\n if (await this.refs.remoteSha(repoRoot, targetRef) === '') {\n throw new CliExitError(2,\n '\\n' + SEP + `⛔ \\`${targetRef}\\` is not published yet\\n` + SEP + '\\n'\n + 'There is nothing to compose against. Publish your copy first, then resolve:\\n'\n + ` ${WP_PUSH_DEV}\\n ${WP_PUSH_DEV} --resolve\\n`);\n }\n const queue = await this.resolveQueue(repoRoot, cfg, targetRef, only);\n if (queue.length === 0) {\n process.stdout.write(\n `\\nNothing to compose — \\`${targetRef}\\` is the only copy in \\`${cfg.copyRefGlob()}\\`.\\n`\n + `Your CI will merge it onto origin/main by itself; there is no other branch to conflict with.\\n`);\n return;\n }\n const state = new PushDevState(branch, this.runner.tmpBranchFor(branch), targetRef, queue);\n state.mode = DevResolveMode.COMPOSE;\n process.stdout.write(this.runner.announce(cfg, state));\n await this.runner.start(repoRoot, state, `refs/remotes/origin/${targetRef}`, [targetRef, ...queue]);\n }\n\n // The refs to merge: one named copy, or every copy that is not mine. A named branch is accepted with\n // or without the namespace prefix, because the CI message that names it may print either.\n private async resolveQueue(repoRoot: string, cfg: DevDeployConfig, targetRef: string, only: string): Promise<string[]> {\n const copies = await this.refs.liveCopies(repoRoot, cfg);\n if (only === '') {\n return copies.filter((c: DevCopy): boolean => c.ref !== targetRef).map((c: DevCopy): string => c.ref);\n }\n const wanted = only.startsWith(`${cfg.branchNamespace}/`) ? only : cfg.copyRefFor(only);\n if (wanted === targetRef) {\n throw new CliExitError(2, `\\n⛔ \\`${only}\\` is your own copy — there is nothing to compose it with.\\n`);\n }\n if (!copies.some((c: DevCopy): boolean => c.ref === wanted)) {\n throw new CliExitError(2,\n '\\n' + SEP + `⛔ No published copy \\`${wanted}\\`\\n` + SEP + '\\n'\n + `Live copies (${WP_PUSH_DEV} --list):\\n`\n + copies.map((c: DevCopy): string => ` ${c.ref}`).join('\\n') + '\\n');\n }\n return [wanted];\n }\n\n private refuseClobber(cfg: DevDeployConfig, branch: string, targetRef: string, ahead: number): never {\n throw new CliExitError(2,\n '\\n' + SEP + `⛔ \\`${targetRef}\\` holds ${String(ahead)} commit(s) your branch does not\\n` + SEP + '\\n'\n + 'That is what a CONFLICT RESOLUTION looks like: somebody composed this copy against another\\n'\n + `developer's branch so \\`${cfg.devBranch}\\` could build, and that work exists ONLY on the copy —\\n`\n + 'by design, because it must never reach your feature branch or your PR.\\n\\n'\n + 'Publishing now would force-push over it and destroy it, so this command refuses. Pick one:\\n\\n'\n + ` ${WP_PUSH_DEV} --rebase-resolution\\n`\n + ' Replay that resolution on top of your new commits. Keeps the work; may ask you to\\n'\n + ' re-resolve the parts your new commits actually changed.\\n\\n'\n + ` ${WP_PUSH_DEV} --force\\n`\n + ' Discard it and publish your branch as-is. The composition breaks again until someone\\n'\n + ` re-resolves it with \\`${WP_PUSH_DEV} --resolve\\`.\\n\\n`\n + `See what is on the copy: git log --oneline ${branch}..refs/remotes/origin/${targetRef}\\n`);\n }\n\n // A half-finished resolve owns the checkout — it is parked on a throwaway branch, so \"the current\n // branch\" is not the feature branch this command would otherwise act on.\n private assertNoResolveInProgress(repoRoot: string): void {\n const state = this.store.read(repoRoot);\n if (state === null) return;\n throw new CliExitError(2,\n '\\n' + SEP + '⛔ A dev-deploy resolve is already in progress\\n' + SEP + '\\n'\n + `You are on the throwaway branch \\`${state.tmpBranch}\\`, mid-composition. Finish it or bail out:\\n`\n + ` ${WP_FINISH_PUSH_DEV} ← commit the resolution, resume the queue, publish\\n`\n + ` ${WP_FINISH_PUSH_DEV} --abort ← throw it away and go back to \\`${state.originalBranch}\\`\\n`);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"push-dev-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/push-dev-command.ts"],"names":[],"mappings":";;;;AAAA,0DAOiC;AACjC,yCAA2D;AAE3D,mDAA+C;AAC/C,iEAAqE;AACrE,+DAA6F;AAC7F,uEAAsF;AACtF,+EAAyE;AACzE,qDAAiD;AACjD,mEAAuF;AAEvF,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;GAGG;AACH,MAAa,cAAc;IACvB,6CAA6C;IAC7C,MAAM,GAAG,KAAK,CAAC;IACf,sFAAsF;IACtF,IAAI,GAAG,KAAK,CAAC;IACb,qFAAqF;IACrF,KAAK,GAAG,KAAK,CAAC;IACd,uFAAuF;IACvF,gBAAgB,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K,0BAAW,wBAAwB;cACxC,2FAA2F;cAC3F,mEAAmE;cACnE,KAAK,0BAAW,YAAY;cAC5B,8FAA8F;cAC9F,+BAA+B,0BAAW,mBAAmB;cAC7D,+CAA+C,MAAM,yBAAyB,SAAS,IAAI,CAAC,CAAC;IACvG,CAAC;IAED,kGAAkG;IAClG,yEAAyE;IACjE,yBAAyB,CAAC,QAAgB;QAC9C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxC,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO;QAC3B,MAAM,IAAI,2BAAY,CAAC,CAAC,EACpB,IAAI,GAAG,GAAG,GAAG,iDAAiD,GAAG,GAAG,GAAG,IAAI;cACzE,qCAAqC,KAAK,CAAC,SAAS,+CAA+C;cACnG,KAAK,iCAAkB,kEAAkE;cACzF,KAAK,iCAAkB,gDAAgD,KAAK,CAAC,cAAc,MAAM,CAAC,CAAC;IAC7G,CAAC;CACJ,CAAA;AAlTY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QACrB,kBAAO;QACV,+BAAa;QACZ,kCAAiB;QAChB,qCAAgB;QACZ,4CAAmB;QACrB,oBAAQ;QACN,gCAAa;GATrC,cAAc,CAkT1B","sourcesContent":["import {\n CliExitError,\n DevDeployConfig,\n RepoRootFinder,\n WP_FINISH_PUSH_DEV,\n WP_PUSH_DEV,\n writeTemplate,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { GitExec } from '../workflow/git-exec';\nimport { DevCopy, DevDeployRefs } from '../workflow/dev-deploy-refs';\nimport { DevResolveMode, PushDevState, PushDevStateStore } from '../workflow/push-dev-state';\nimport { DevResolveRunner, RESOLUTION_SUBJECT } from '../workflow/dev-resolve-runner';\nimport { DevDeployWatchHints } from '../workflow/dev-deploy-watch-hints';\nimport { DevBuild } from '../workflow/dev-build';\nimport { DevCopyLanding, DevCopyOnMain, MergedPr } from '../workflow/dev-copy-on-main';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * Which of `wp-push-dev`'s modes was asked for. Data-only (per CLAUDE.md) with plain assigned fields\n * rather than a seven-argument constructor — the bin sets what argv carried and nothing else.\n */\nexport class PushDevOptions {\n /** Delete the remote copy — the rollback. */\n remove = false;\n /** List the live copies and stop. The one mode that needs no branch preconditions. */\n list = false;\n /** Discard a conflict resolution already published on the copy, and overwrite it. */\n force = false;\n /** Replay that resolution on top of the new local commits instead of discarding it. */\n rebaseResolution = false;\n /** Compose the other copies onto this one so the shared environment can build them together. */\n resolve = false;\n /** With `--resolve`: merge ONLY this developer's branch. Empty ⇒ every other copy. */\n resolveTarget = '';\n}\n\n/**\n * `wp-push-dev` — publish a DISPOSABLE copy of this branch so a shared dev environment can build it,\n * without landing anything on `main` and without opening a PR.\n *\n * WHY THIS COMMAND HAS TO EXIST AT ALL: `pr-creation-or-push-guard` blocks every `git push`, no\n * exceptions, by design. Its own fix-hint offers \"ask a human to run the push\" for out-of-band cases —\n * which is the right answer for a genuine exception and the wrong one for a routine daily action. Without\n * a gated command there is simply no legal way for an AI to get a branch onto a dev server, so the\n * feature was undoable rather than merely awkward.\n *\n * WHY IT CHECKS AGAINST `dev` FIRST (#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. So a plain\n * publish now does locally what CI is about to do: merge `origin/<devBranch>` into a THROWAWAY branch,\n * resolve any conflict there (the same halt / `wp-finish-push-dev` state machine `--resolve` uses), and run\n * `commands.push-dev.buildCommand` on the merged tree. A build against `main` alone would prove the wrong\n * thing; a build of only what differs from `dev` proves the right one, quickly.\n *\n * WHAT IS PUBLISHED IS NEVER THAT MERGE: the copy is the feature head plus, when something conflicted, one\n * commit recording the resolved files (DevResolveRunner.recordResolution). A copy that contained `dev`\n * would carry every other copy's history, and a later `--remove` of one of them would leave it on dev\n * through this one.\n *\n * WHAT IT NEVER DOES: touch the feature branch. See DevDeployRefs for the invariant and why the copy\n * exists to hold conflict resolutions that must not reach the PR.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class PushDevCommand {\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 watchHints: DevDeployWatchHints,\n private readonly devBuild: DevBuild,\n private readonly copyOnMain: DevCopyOnMain,\n ) {}\n\n async run(opts: PushDevOptions): 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 // same reason every other wp-* command opens this way.\n writeTemplate(repoRoot, 'webpieces.git-workflow.md');\n const cfg = this.refs.config(repoRoot);\n\n // A resolve already in flight owns the checkout; starting a second one would strand the first.\n this.assertNoResolveInProgress(repoRoot);\n\n if (opts.list) {\n await this.list(repoRoot, cfg);\n return;\n }\n\n const branch = this.refs.currentBranch(repoRoot);\n this.refs.assertPushable(cfg, branch);\n const targetRef = cfg.copyRefFor(branch);\n\n if (opts.remove) {\n await this.remove(repoRoot, cfg, branch, targetRef);\n return;\n }\n // Every remaining mode commits or merges, so the tree must be the AI's committed work and nothing\n // else. The tooling never commits for you.\n await this.gitExec.assertCleanTree(repoRoot);\n\n if (opts.resolve) {\n await this.startResolve(repoRoot, cfg, branch, targetRef, opts.resolveTarget);\n return;\n }\n await this.publish(repoRoot, cfg, branch, targetRef, opts);\n }\n\n /** `--list`: exactly the live copies, straight from the remote — never a cached local view. */\n private async list(repoRoot: string, cfg: DevDeployConfig): Promise<void> {\n const copies = await this.refs.liveCopies(repoRoot, cfg);\n if (copies.length === 0) {\n process.stdout.write(\n `\\nNo dev copies published — nothing matches \\`${cfg.copyRefGlob()}\\` on origin.\\n`\n + `Publish this branch's with: ${WP_PUSH_DEV}\\n`);\n return;\n }\n let out = '\\n' + SEP + `📋 ${String(copies.length)} dev cop${copies.length === 1 ? 'y' : 'ies'} on origin\\n` + SEP + '\\n';\n for (const copy of copies) out += ` ${copy.sha.slice(0, 8)} ${copy.ref}\\n`;\n out += `\\nYour CI composes \\`${cfg.devBranch}\\` from origin/main plus every ref above, on every run.\\n`\n + `Remove yours with: ${WP_PUSH_DEV} --remove (deletes your copy, then pushes the content-free\\n`\n + `\\`${cfg.removeMarkerRefFor('<your-branch>')}\\` marker your dev workflow triggers on and deletes)\\n`;\n process.stdout.write(out);\n }\n\n /**\n * `--remove`: delete the remote copy, then push the `<removeNamespace>/<branch>` marker (#1395). This\n * IS the rollback — nothing else has to be undone.\n *\n * WHY A MARKER AS WELL AS THE DELETION: a deletion can only be heard by a workflow's `on: delete:`,\n * which GitHub cannot filter by branch, so every branch deletion in the repo started a dev-deploy run.\n * A PUSH to `<removeNamespace>/**` is filterable. The deletion stays, unchanged, so a consumer whose\n * workflow still listens on `delete:` keeps working through the rollout window; the marker is purely\n * additive at the transport level.\n *\n * ALREADY ON MAIN (#1401): before anything is deleted, the copy is compared with `origin/main`. When\n * every file it changes already has the copy's content on main, removing it takes nothing off dev —\n * main keeps the change there — and would only force a pointless full recompose, so it is REFUSED\n * ({@link refuseLanded}). When only some files are, the rest is still a real rollback: it warns, naming\n * the landed files, and removes.\n *\n * ORDER: `origin/main` and the copy are fetched BEFORE anything is deleted, so a network failure there\n * leaves the pool exactly as it was. The marker push is the last step, and the only one that can fail with the\n * copy already gone — that is the state {@link markerPushFailed} names.\n */\n private async remove(repoRoot: string, cfg: DevDeployConfig, branch: string, targetRef: string): Promise<void> {\n if (await this.refs.remoteSha(repoRoot, targetRef) === '') {\n process.stdout.write(\n `\\nNothing to remove — \\`${targetRef}\\` is not published.\\n`\n + `List what IS published with: ${WP_PUSH_DEV} --list\\n`);\n return;\n }\n const markerRef = cfg.removeMarkerRefFor(branch);\n const mainTip = await this.refs.freshMainTip(repoRoot);\n await this.refs.fetchCopies(repoRoot, [targetRef]);\n const landing = await this.copyOnMain.landing(repoRoot, targetRef);\n if (landing.fullyOnMain()) {\n this.refuseLanded(targetRef, await this.copyOnMain.mergedPr(repoRoot, branch));\n }\n if (landing.partlyOnMain()) process.stdout.write(this.partlyLandedWarning(targetRef, landing));\n await this.gitExec.runGitChecked(['-C', repoRoot, 'push', 'origin', '--delete', `refs/heads/${targetRef}`],\n `Failed to delete the dev copy ${targetRef}`);\n // --force: the marker carries no content, so whatever an earlier, never-deleted marker pointed at\n // is worthless — and refusing a non-fast-forward here would strand the rollback half-done.\n const pushed = await this.gitExec.tryGit(\n ['-C', repoRoot, 'push', '--force', 'origin', `${mainTip}:refs/heads/${markerRef}`], repoRoot);\n if (!pushed.ok) this.markerPushFailed(cfg, branch, targetRef, markerRef, pushed.stderr);\n process.stdout.write(\n '\\n' + SEP + `🗑️ Removed ${targetRef}\\n` + SEP + '\\n'\n + `Pushed the marker \\`${markerRef}\\` (at origin/main ${mainTip.slice(0, 8)}) — your dev workflow triggers\\n`\n + `on it, deletes it, and rebuilds \\`${cfg.devBranch}\\` without \\`${branch}\\`. Your branch and any PR on it\\n`\n + 'are untouched.\\n');\n }\n\n /**\n * `--remove` of a copy whose every change is already on `origin/main`. Nothing was deleted and no marker\n * was pushed. There is deliberately no override: a remove cannot take back what main already holds, so\n * refusing never blocks a real rollback — that is a revert PR.\n */\n private refuseLanded(targetRef: string, pr: MergedPr | null): never {\n const landedVia = pr === null ? '' : ` (PR #${pr.num} landed ${pr.mergedAt})`;\n throw new CliExitError(2,\n '\\n' + SEP + `⛔ \\`${targetRef}\\` is already on origin/main — nothing was removed\\n` + SEP + '\\n'\n + `\\`${targetRef}\\` is already on origin/main${landedVia}, so removing the copy\\n`\n + 'would not take anything off dev — main keeps it there. The nightly reset deletes the copy.\\n'\n + 'Nothing was removed, and no rebuild marker was pushed.\\n\\n'\n + 'If that code is what broke dev, it is on main now: the fix is a revert PR against main, not a remove.\\n');\n }\n\n /** Some of the copy's files are already on main: the remove proceeds, and says what it does NOT take off. */\n private partlyLandedWarning(targetRef: string, landing: DevCopyLanding): string {\n return '\\n' + SEP + `⚠️ Part of \\`${targetRef}\\` is already on origin/main\\n` + SEP + '\\n'\n + `${String(landing.landed.length)} of the ${String(landing.changed.length)} files this copy changes already have the copy's content on\\n`\n + 'origin/main. Removing the copy does NOT take these off dev — main keeps them there:\\n'\n + landing.landed.map((f: string): string => ` ${f}`).join('\\n') + '\\n'\n + 'Only the rest of the copy is being removed. If one of the files above broke dev, the fix is a revert PR.\\n';\n }\n\n /**\n * The one half-done state `--remove` can leave: the copy is deleted, the rebuild signal is not sent.\n * Said out loud because it is invisible otherwise — `--list` already looks right, while the deployed\n * `dev` still runs the removed branch until something else triggers a composition.\n */\n private markerPushFailed(cfg: DevDeployConfig, branch: string, targetRef: string, markerRef: string, stderr: string): never {\n throw new CliExitError(1,\n '\\n' + SEP + `⛔ Removed \\`${targetRef}\\`, but pushing the rebuild marker \\`${markerRef}\\` FAILED\\n` + SEP + '\\n'\n + `Your copy is already GONE from origin, but \\`${cfg.devBranch}\\` was NOT rebuilt: the deployed dev server\\n`\n + `still runs \\`${branch}\\` until the next composition run.\\n\\n`\n + 'git said:\\n' + (stderr === '' ? ' (no output)' : stderr.split('\\n').map((l: string): string => ` ${l}`).join('\\n')) + '\\n\\n'\n + 'Any later composition run drops your branch on its own, because the copy no longer exists — the next\\n'\n + `\\`${WP_PUSH_DEV}\\` by anyone, or a push to main if your workflow composes on that. To force one now,\\n`\n + 'once the cause above is fixed (network, auth, a branch-protection rule on the marker namespace),\\n'\n + 're-publish and remove again; the second remove pushes the marker:\\n\\n'\n + ` ${WP_PUSH_DEV}\\n ${WP_PUSH_DEV} --remove\\n`);\n }\n\n /**\n * The ordinary path: check the copy against `origin/<devBranch>`, build it, then publish it as\n * `<namespace>/<branch>` (#1397). The merge, the conflict halt and the build all happen on a throwaway\n * branch through DevResolveRunner, in DevResolveMode.PREBUILD — so a conflict stops in exactly the\n * same `wp-finish-push-dev` state machine `--resolve` uses, rather than inventing a second way to be\n * stuck.\n *\n * THE CLOBBER GUARD runs first. If the remote copy holds commits the local branch does not, somebody\n * (quite possibly this developer, days ago) put real work there, and a silent force-push destroys it,\n * so the default is refusal with two named ways forward — never a \"use --force\" one-liner, which is how\n * a warning becomes a reflex. The one exception is a commit this flow wrote itself\n * ({@link RESOLUTION_SUBJECT}): the check below re-derives it against today's dev, so replacing it\n * loses nothing.\n */\n private async publish(repoRoot: string, cfg: DevDeployConfig, branch: string, targetRef: string, opts: PushDevOptions): Promise<void> {\n const remoteSha = await this.refs.remoteSha(repoRoot, targetRef);\n if (remoteSha !== '') {\n await this.refs.fetchCopies(repoRoot, [targetRef]);\n const subjects = await this.refs.subjectsOnlyOnRemote(repoRoot, targetRef);\n const ahead = subjects.filter((s: string): boolean => !s.startsWith(RESOLUTION_SUBJECT)).length;\n if (ahead > 0 && opts.rebaseResolution) {\n await this.rebaseResolution(repoRoot, branch, targetRef);\n return;\n }\n if (ahead > 0 && !opts.force) this.refuseClobber(cfg, branch, targetRef, ahead);\n }\n // Before any git write: an unconfigured dev build refuses here, with nothing merged or published.\n this.devBuild.command(repoRoot);\n if (await this.refs.remoteSha(repoRoot, cfg.devBranch) === '') {\n await this.publishWithoutDev(repoRoot, cfg, branch, targetRef, remoteSha, opts.force);\n return;\n }\n const state = new PushDevState(branch, this.runner.tmpBranchFor(branch), targetRef, [cfg.devBranch]);\n state.mode = DevResolveMode.PREBUILD;\n state.leaseSha = remoteSha;\n state.force = opts.force;\n process.stdout.write(this.runner.announcePrebuild(cfg, state));\n await this.runner.start(repoRoot, state, 'HEAD', [cfg.devBranch]);\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 copy is\n * published as it is; refusing here would make the first dev composition impossible to start.\n */\n private async publishWithoutDev(\n repoRoot: string, cfg: DevDeployConfig, branch: string, targetRef: string, remoteSha: string, force: boolean,\n ): Promise<void> {\n const lease = remoteSha === '' ? [] : force ? ['--force'] : [`--force-with-lease=refs/heads/${targetRef}:${remoteSha}`];\n await this.gitExec.runGitChecked(['-C', repoRoot, 'push', ...lease, 'origin', `HEAD:refs/heads/${targetRef}`],\n `Failed to publish the dev copy ${targetRef}`);\n const published = await this.refs.headSha(repoRoot);\n process.stdout.write(\n '\\n' + SEP + `✅ Published ${targetRef}\\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. \\`${branch}\\` is now in the pool your CI composes \\`${cfg.devBranch}\\` from.\\n\\n`\n + ` ${WP_PUSH_DEV} --list ← what else is in the pool\\n`\n + ` ${WP_PUSH_DEV} --remove ← take this branch back out\\n`\n + this.watchHints.render(cfg, targetRef, published));\n }\n\n /**\n * `--rebase-resolution`: keep the published resolution, replay it on top of the new commits.\n *\n * Implemented as a resolve whose BASE is the local HEAD and whose queue is the copy itself, so a\n * replay that conflicts again lands in exactly the same halt/`wp-finish-push-dev` state machine as\n * any other conflict, rather than inventing a second way to be stuck.\n */\n private async rebaseResolution(repoRoot: string, branch: string, targetRef: string): Promise<void> {\n const state = new PushDevState(branch, this.runner.tmpBranchFor(branch), targetRef, [targetRef]);\n state.mode = DevResolveMode.REPLAY;\n process.stdout.write(\n '\\n' + SEP + `♻️ Replaying the published resolution onto \\`${branch}\\`\\n` + SEP + '\\n'\n + `Merging \\`${targetRef}\\` (which holds the resolution) into your new commits on a throwaway branch.\\n`\n + `Your feature branch \\`${branch}\\` is not touched.\\n\\n`);\n await this.runner.start(repoRoot, state, 'HEAD', [targetRef]);\n }\n\n /**\n * `--resolve`: compose the other copies onto this one, so what is published is what CI will build.\n *\n * With no argument the queue is EVERY other copy, in the same sorted order CI composes them — the\n * local resolution is then a rehearsal of the real composition, not a guess at it. With an argument\n * (the branch a CI conflict message names) it is just that one.\n */\n private async startResolve(repoRoot: string, cfg: DevDeployConfig, branch: string, targetRef: string, only: string): Promise<void> {\n if (await this.refs.remoteSha(repoRoot, targetRef) === '') {\n throw new CliExitError(2,\n '\\n' + SEP + `⛔ \\`${targetRef}\\` is not published yet\\n` + SEP + '\\n'\n + 'There is nothing to compose against. Publish your copy first, then resolve:\\n'\n + ` ${WP_PUSH_DEV}\\n ${WP_PUSH_DEV} --resolve\\n`);\n }\n const queue = await this.resolveQueue(repoRoot, cfg, targetRef, only);\n if (queue.length === 0) {\n process.stdout.write(\n `\\nNothing to compose — \\`${targetRef}\\` is the only copy in \\`${cfg.copyRefGlob()}\\`.\\n`\n + `Your CI will merge it onto origin/main by itself; there is no other branch to conflict with.\\n`);\n return;\n }\n const state = new PushDevState(branch, this.runner.tmpBranchFor(branch), targetRef, queue);\n state.mode = DevResolveMode.COMPOSE;\n process.stdout.write(this.runner.announce(cfg, state));\n await this.runner.start(repoRoot, state, `refs/remotes/origin/${targetRef}`, [targetRef, ...queue]);\n }\n\n // The refs to merge: one named copy, or every copy that is not mine. A named branch is accepted with\n // or without the namespace prefix, because the CI message that names it may print either.\n private async resolveQueue(repoRoot: string, cfg: DevDeployConfig, targetRef: string, only: string): Promise<string[]> {\n const copies = await this.refs.liveCopies(repoRoot, cfg);\n if (only === '') {\n return copies.filter((c: DevCopy): boolean => c.ref !== targetRef).map((c: DevCopy): string => c.ref);\n }\n const wanted = only.startsWith(`${cfg.branchNamespace}/`) ? only : cfg.copyRefFor(only);\n if (wanted === targetRef) {\n throw new CliExitError(2, `\\n⛔ \\`${only}\\` is your own copy — there is nothing to compose it with.\\n`);\n }\n if (!copies.some((c: DevCopy): boolean => c.ref === wanted)) {\n throw new CliExitError(2,\n '\\n' + SEP + `⛔ No published copy \\`${wanted}\\`\\n` + SEP + '\\n'\n + `Live copies (${WP_PUSH_DEV} --list):\\n`\n + copies.map((c: DevCopy): string => ` ${c.ref}`).join('\\n') + '\\n');\n }\n return [wanted];\n }\n\n private refuseClobber(cfg: DevDeployConfig, branch: string, targetRef: string, ahead: number): never {\n throw new CliExitError(2,\n '\\n' + SEP + `⛔ \\`${targetRef}\\` holds ${String(ahead)} commit(s) your branch does not\\n` + SEP + '\\n'\n + 'That is what a CONFLICT RESOLUTION looks like: somebody composed this copy against another\\n'\n + `developer's branch so \\`${cfg.devBranch}\\` could build, and that work exists ONLY on the copy —\\n`\n + 'by design, because it must never reach your feature branch or your PR.\\n\\n'\n + 'Publishing now would force-push over it and destroy it, so this command refuses. Pick one:\\n\\n'\n + ` ${WP_PUSH_DEV} --rebase-resolution\\n`\n + ' Replay that resolution on top of your new commits. Keeps the work; may ask you to\\n'\n + ' re-resolve the parts your new commits actually changed.\\n\\n'\n + ` ${WP_PUSH_DEV} --force\\n`\n + ' Discard it and publish your branch as-is. The composition breaks again until someone\\n'\n + ` re-resolves it with \\`${WP_PUSH_DEV} --resolve\\`.\\n\\n`\n + `See what is on the copy: git log --oneline ${branch}..refs/remotes/origin/${targetRef}\\n`);\n }\n\n // A half-finished resolve owns the checkout — it is parked on a throwaway branch, so \"the current\n // branch\" is not the feature branch this command would otherwise act on.\n private assertNoResolveInProgress(repoRoot: string): void {\n const state = this.store.read(repoRoot);\n if (state === null) return;\n throw new CliExitError(2,\n '\\n' + SEP + '⛔ A dev-deploy resolve is already in progress\\n' + SEP + '\\n'\n + `You are on the throwaway branch \\`${state.tmpBranch}\\`, mid-composition. Finish it or bail out:\\n`\n + ` ${WP_FINISH_PUSH_DEV} ← commit the resolution, resume the queue, publish\\n`\n + ` ${WP_FINISH_PUSH_DEV} --abort ← throw it away and go back to \\`${state.originalBranch}\\`\\n`);\n }\n}\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { NativeProcessApi } from '@webpieces/tooling-common';
|
|
2
|
+
import { GitExec } from './git-exec';
|
|
3
|
+
/**
|
|
4
|
+
* How much of one dev copy is already on `origin/main`. Data-only per CLAUDE.md.
|
|
5
|
+
*
|
|
6
|
+
* `changed` is every file the copy changes relative to its merge-base with `origin/main`; `landed` is the
|
|
7
|
+
* subset whose content on `origin/main` is now identical to the copy's.
|
|
8
|
+
*/
|
|
9
|
+
export declare class DevCopyLanding {
|
|
10
|
+
readonly changed: string[];
|
|
11
|
+
readonly landed: string[];
|
|
12
|
+
constructor(changed: string[], landed: string[]);
|
|
13
|
+
/** Every file the copy changes already has the copy's content on main — removing it takes nothing off dev. */
|
|
14
|
+
fullyOnMain(): boolean;
|
|
15
|
+
/** Some, but not all, of the copy's files are already on main. */
|
|
16
|
+
partlyOnMain(): boolean;
|
|
17
|
+
}
|
|
18
|
+
/** The merged PR a copy's branch landed through, for the refusal message. Data-only. */
|
|
19
|
+
export declare class MergedPr {
|
|
20
|
+
readonly num: string;
|
|
21
|
+
readonly mergedAt: string;
|
|
22
|
+
constructor(num: string, mergedAt: string);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Answers "is this dev copy already on `origin/main`?" for `wp-push-dev --remove` (#1401).
|
|
26
|
+
*
|
|
27
|
+
* WHY: developers ran `--remove` after their PR landed, as a "done, clean up" habit. On a repo that composes
|
|
28
|
+
* `dev` = `origin/main` + every copy, that remove takes nothing off dev (main keeps the change there) and
|
|
29
|
+
* still triggers a full recompose that can redeploy every service. Only rolling back a copy that broke dev is
|
|
30
|
+
* a real reason to remove.
|
|
31
|
+
*
|
|
32
|
+
* HOW: a pure content check, no GitHub dependency. The files the copy changes since its merge-base with
|
|
33
|
+
* `origin/main` (`git diff A...B`), minus the files where `origin/main` and the copy still differ
|
|
34
|
+
* (`git diff A B`), are the files already landed. Both refs must already be fetched. `--no-renames` so a
|
|
35
|
+
* rename counts both its old and new path rather than hiding the deletion.
|
|
36
|
+
*/
|
|
37
|
+
export declare class DevCopyOnMain {
|
|
38
|
+
private readonly gitExec;
|
|
39
|
+
private readonly processes;
|
|
40
|
+
constructor(gitExec: GitExec, processes: NativeProcessApi);
|
|
41
|
+
landing(repoRoot: string, copyRef: string): Promise<DevCopyLanding>;
|
|
42
|
+
/**
|
|
43
|
+
* The merged PR whose head was `branch`, or null. It only decorates the refusal message, so a `gh` that
|
|
44
|
+
* is missing, unauthenticated or offline yields null rather than an error: the content check above has
|
|
45
|
+
* already decided.
|
|
46
|
+
*/
|
|
47
|
+
mergedPr(repoRoot: string, branch: string): Promise<MergedPr | null>;
|
|
48
|
+
private names;
|
|
49
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DevCopyOnMain = exports.MergedPr = exports.DevCopyLanding = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
6
|
+
const inversify_1 = require("inversify");
|
|
7
|
+
const git_exec_1 = require("./git-exec");
|
|
8
|
+
const MAIN_REF = 'refs/remotes/origin/main';
|
|
9
|
+
/**
|
|
10
|
+
* How much of one dev copy is already on `origin/main`. Data-only per CLAUDE.md.
|
|
11
|
+
*
|
|
12
|
+
* `changed` is every file the copy changes relative to its merge-base with `origin/main`; `landed` is the
|
|
13
|
+
* subset whose content on `origin/main` is now identical to the copy's.
|
|
14
|
+
*/
|
|
15
|
+
class DevCopyLanding {
|
|
16
|
+
changed;
|
|
17
|
+
landed;
|
|
18
|
+
constructor(changed, landed) {
|
|
19
|
+
this.changed = changed;
|
|
20
|
+
this.landed = landed;
|
|
21
|
+
}
|
|
22
|
+
/** Every file the copy changes already has the copy's content on main — removing it takes nothing off dev. */
|
|
23
|
+
fullyOnMain() {
|
|
24
|
+
return this.landed.length === this.changed.length;
|
|
25
|
+
}
|
|
26
|
+
/** Some, but not all, of the copy's files are already on main. */
|
|
27
|
+
partlyOnMain() {
|
|
28
|
+
return this.landed.length > 0 && !this.fullyOnMain();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.DevCopyLanding = DevCopyLanding;
|
|
32
|
+
/** The merged PR a copy's branch landed through, for the refusal message. Data-only. */
|
|
33
|
+
class MergedPr {
|
|
34
|
+
num;
|
|
35
|
+
mergedAt;
|
|
36
|
+
constructor(num, mergedAt) {
|
|
37
|
+
this.num = num;
|
|
38
|
+
this.mergedAt = mergedAt;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.MergedPr = MergedPr;
|
|
42
|
+
// `<number> <mergedAt>` as the --jq below prints it; an empty list prints `null null`, which does not match.
|
|
43
|
+
const PR_LINE = /^(\d+) (\S+)$/;
|
|
44
|
+
/**
|
|
45
|
+
* Answers "is this dev copy already on `origin/main`?" for `wp-push-dev --remove` (#1401).
|
|
46
|
+
*
|
|
47
|
+
* WHY: developers ran `--remove` after their PR landed, as a "done, clean up" habit. On a repo that composes
|
|
48
|
+
* `dev` = `origin/main` + every copy, that remove takes nothing off dev (main keeps the change there) and
|
|
49
|
+
* still triggers a full recompose that can redeploy every service. Only rolling back a copy that broke dev is
|
|
50
|
+
* a real reason to remove.
|
|
51
|
+
*
|
|
52
|
+
* HOW: a pure content check, no GitHub dependency. The files the copy changes since its merge-base with
|
|
53
|
+
* `origin/main` (`git diff A...B`), minus the files where `origin/main` and the copy still differ
|
|
54
|
+
* (`git diff A B`), are the files already landed. Both refs must already be fetched. `--no-renames` so a
|
|
55
|
+
* rename counts both its old and new path rather than hiding the deletion.
|
|
56
|
+
*/
|
|
57
|
+
let DevCopyOnMain = class DevCopyOnMain {
|
|
58
|
+
gitExec;
|
|
59
|
+
processes;
|
|
60
|
+
constructor(gitExec, processes) {
|
|
61
|
+
this.gitExec = gitExec;
|
|
62
|
+
this.processes = processes;
|
|
63
|
+
}
|
|
64
|
+
async landing(repoRoot, copyRef) {
|
|
65
|
+
const copy = `refs/remotes/origin/${copyRef}`;
|
|
66
|
+
const changed = await this.names(repoRoot, [`${MAIN_REF}...${copy}`], `Failed to list the files ${copyRef} changes since its merge-base with origin/main (git diff ${MAIN_REF}...${copy}). Nothing was removed.`);
|
|
67
|
+
const stillDiffer = new Set(await this.names(repoRoot, [MAIN_REF, copy], `Failed to compare ${copyRef} with origin/main (git diff ${MAIN_REF} ${copy}). Nothing was removed.`));
|
|
68
|
+
const landed = changed.filter((f) => !stillDiffer.has(f));
|
|
69
|
+
return new DevCopyLanding(changed, landed);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The merged PR whose head was `branch`, or null. It only decorates the refusal message, so a `gh` that
|
|
73
|
+
* is missing, unauthenticated or offline yields null rather than an error: the content check above has
|
|
74
|
+
* already decided.
|
|
75
|
+
*/
|
|
76
|
+
async mergedPr(repoRoot, branch) {
|
|
77
|
+
const result = await this.processes.run('gh', [
|
|
78
|
+
'pr', 'list', '--head', branch, '--state', 'merged', '--limit', '1',
|
|
79
|
+
'--json', 'number,mergedAt', '--jq', '.[0] | "\\(.number) \\(.mergedAt)"',
|
|
80
|
+
], repoRoot);
|
|
81
|
+
if (!result.ok)
|
|
82
|
+
return null;
|
|
83
|
+
const match = PR_LINE.exec(result.stdout.trim());
|
|
84
|
+
if (match === null)
|
|
85
|
+
return null;
|
|
86
|
+
return new MergedPr(match[1], match[2]);
|
|
87
|
+
}
|
|
88
|
+
async names(repoRoot, revs, failMsg) {
|
|
89
|
+
const out = await this.gitExec.gitQuery(['-C', repoRoot, 'diff', '--name-only', '--no-renames', ...revs], repoRoot, failMsg);
|
|
90
|
+
return out.split('\n').map((l) => l.trim()).filter((l) => l !== '');
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
exports.DevCopyOnMain = DevCopyOnMain;
|
|
94
|
+
exports.DevCopyOnMain = DevCopyOnMain = tslib_1.__decorate([
|
|
95
|
+
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
96
|
+
tslib_1.__metadata("design:paramtypes", [git_exec_1.GitExec,
|
|
97
|
+
tooling_common_1.NativeProcessApi])
|
|
98
|
+
], DevCopyOnMain);
|
|
99
|
+
//# sourceMappingURL=dev-copy-on-main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-copy-on-main.js","sourceRoot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,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC7H,OAAO,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAS,EAAW,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;IACzG,CAAC;CACJ,CAAA;AApCY,sCAAa;wBAAb,aAAa;IADzB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGP,kBAAO;QACL,iCAAgB;GAHvC,aAAa,CAoCzB","sourcesContent":["import { NativeProcessApi } from '@webpieces/tooling-common';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { GitExec } from './git-exec';\n\nconst MAIN_REF = 'refs/remotes/origin/main';\n\n/**\n * How much of one dev copy is already on `origin/main`. Data-only per CLAUDE.md.\n *\n * `changed` is every file the copy changes relative to its merge-base with `origin/main`; `landed` is the\n * subset whose content on `origin/main` is now identical to the copy's.\n */\nexport class DevCopyLanding {\n constructor(\n readonly changed: string[],\n readonly landed: string[],\n ) {}\n\n /** Every file the copy changes already has the copy's content on main — removing it takes nothing off dev. */\n fullyOnMain(): boolean {\n return this.landed.length === this.changed.length;\n }\n\n /** Some, but not all, of the copy's files are already on main. */\n partlyOnMain(): boolean {\n return this.landed.length > 0 && !this.fullyOnMain();\n }\n}\n\n/** The merged PR a copy's branch landed through, for the refusal message. Data-only. */\nexport class MergedPr {\n constructor(\n readonly num: string,\n readonly mergedAt: string,\n ) {}\n}\n\n// `<number> <mergedAt>` as the --jq below prints it; an empty list prints `null null`, which does not match.\nconst PR_LINE = /^(\\d+) (\\S+)$/;\n\n/**\n * Answers \"is this dev copy already on `origin/main`?\" for `wp-push-dev --remove` (#1401).\n *\n * WHY: developers ran `--remove` after their PR landed, as a \"done, clean up\" habit. On a repo that composes\n * `dev` = `origin/main` + every copy, that remove takes nothing off dev (main keeps the change there) and\n * still triggers a full recompose that can redeploy every service. Only rolling back a copy that broke dev is\n * a real reason to remove.\n *\n * HOW: a pure content check, no GitHub dependency. The files the copy changes since its merge-base with\n * `origin/main` (`git diff A...B`), minus the files where `origin/main` and the copy still differ\n * (`git diff A B`), are the files already landed. Both refs must already be fetched. `--no-renames` so a\n * rename counts both its old and new path rather than hiding the deletion.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class DevCopyOnMain {\n constructor(\n private readonly gitExec: GitExec,\n private readonly processes: NativeProcessApi,\n ) {}\n\n async landing(repoRoot: string, copyRef: string): Promise<DevCopyLanding> {\n const copy = `refs/remotes/origin/${copyRef}`;\n const changed = await this.names(repoRoot, [`${MAIN_REF}...${copy}`],\n `Failed to list the files ${copyRef} changes since its merge-base with origin/main (git diff ${MAIN_REF}...${copy}). Nothing was removed.`);\n const stillDiffer = new Set(await this.names(repoRoot, [MAIN_REF, copy],\n `Failed to compare ${copyRef} with origin/main (git diff ${MAIN_REF} ${copy}). Nothing was removed.`));\n const landed = changed.filter((f: string): boolean => !stillDiffer.has(f));\n return new DevCopyLanding(changed, landed);\n }\n\n /**\n * The merged PR whose head was `branch`, or null. It only decorates the refusal message, so a `gh` that\n * is missing, unauthenticated or offline yields null rather than an error: the content check above has\n * already decided.\n */\n async mergedPr(repoRoot: string, branch: string): Promise<MergedPr | null> {\n const result = await this.processes.run('gh', [\n 'pr', 'list', '--head', branch, '--state', 'merged', '--limit', '1',\n '--json', 'number,mergedAt', '--jq', '.[0] | \"\\\\(.number) \\\\(.mergedAt)\"',\n ], repoRoot);\n if (!result.ok) return null;\n const match = PR_LINE.exec(result.stdout.trim());\n if (match === null) return null;\n return new MergedPr(match[1], match[2]);\n }\n\n private async names(repoRoot: string, revs: string[], failMsg: string): Promise<string[]> {\n const out = await this.gitExec.gitQuery(['-C', repoRoot, 'diff', '--name-only', '--no-renames', ...revs], repoRoot, failMsg);\n return out.split('\\n').map((l: string): string => l.trim()).filter((l: string): boolean => l !== '');\n }\n}\n"]}
|