architecture-harness 0.23.1 → 0.25.1
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 +4 -5
- package/src/cli/branch-sync.mjs +126 -0
- package/src/cli/branch-sync.test.mjs +428 -0
- package/src/cli/budget-guard.mjs +75 -5
- package/src/cli/budget-guard.test.mjs +192 -3
- package/src/cli/budget-report.mjs +85 -0
- package/src/cli/budget-report.test.mjs +173 -0
- package/src/cli/budget.mjs +11 -9
- package/src/cli/budget.test.mjs +5 -5
- package/src/cli/check-commands.mjs +23 -8
- package/src/cli/check-commands.test.mjs +80 -0
- package/src/cli/check-feature-switches.test.mjs +110 -0
- package/src/cli/check-verdict.mjs +46 -0
- package/src/cli/check-verdict.test.mjs +32 -0
- package/src/cli/check.mjs +24 -4
- package/src/cli/checkpoint.mjs +143 -0
- package/src/cli/checkpoint.test.mjs +146 -0
- package/src/cli/ci-failures.mjs +266 -0
- package/src/cli/ci-failures.test.mjs +509 -0
- package/src/cli/ci-state.mjs +25 -29
- package/src/cli/ci-state.test.mjs +174 -2
- package/src/cli/ci-template.test.mjs +22 -24
- package/src/cli/claude-core.test.mjs +37 -0
- package/src/cli/cli.test.mjs +22 -2
- package/src/cli/codex-implement.mjs +243 -39
- package/src/cli/codex-implement.test.mjs +1184 -28
- package/src/cli/codex-limit.mjs +85 -0
- package/src/cli/codex-limit.test.mjs +179 -0
- package/src/cli/codex-reset.mjs +78 -0
- package/src/cli/codex-reset.test.mjs +192 -0
- package/src/cli/commit-guard.mjs +219 -0
- package/src/cli/commit-guard.test.mjs +803 -0
- package/src/cli/commit-msg.mjs +7 -10
- package/src/cli/commit-msg.test.mjs +10 -7
- package/src/cli/context-budgets.mjs +47 -0
- package/src/cli/context-budgets.test.mjs +96 -0
- package/src/cli/context-watch.mjs +116 -0
- package/src/cli/context-watch.test.mjs +395 -0
- package/src/cli/contract-history.mjs +1 -1
- package/src/cli/controller-guard.mjs +38 -0
- package/src/cli/controller-guard.test.mjs +66 -2
- package/src/cli/cost-stop.mjs +5 -1
- package/src/cli/cost-stop.test.mjs +26 -0
- package/src/cli/direct-lane.mjs +32 -19
- package/src/cli/direct-lane.test.mjs +21 -3
- package/src/cli/dispatch-guard.mjs +11 -0
- package/src/cli/dispatch-guard.test.mjs +138 -3
- package/src/cli/dispatch-reminder.mjs +5 -2
- package/src/cli/dispatch-reminder.test.mjs +17 -1
- package/src/cli/dispatch-route.mjs +54 -0
- package/src/cli/dispatch-route.test.mjs +101 -0
- package/src/cli/e2e-affected.mjs +15 -0
- package/src/cli/e2e-affected.test.mjs +73 -0
- package/src/cli/generated-file-guard.mjs +1 -1
- package/src/cli/generated-file-guard.test.mjs +4 -2
- package/src/cli/gh-merge-command.mjs +91 -28
- package/src/cli/gh-merge-command.test.mjs +70 -0
- package/src/cli/gh-run.mjs +20 -2
- package/src/cli/gh-run.test.mjs +36 -1
- package/src/cli/git-hooks.test.mjs +25 -3
- package/src/cli/init.mjs +70 -25
- package/src/cli/integrate.mjs +114 -20
- package/src/cli/integrate.test.mjs +347 -1
- package/src/cli/integration-lane.mjs +64 -0
- package/src/cli/integration-lane.test.mjs +213 -0
- package/src/cli/ledger.mjs +4 -2
- package/src/cli/lint-changed.mjs +206 -0
- package/src/cli/lint-changed.test.mjs +213 -0
- package/src/cli/merge-guard.mjs +165 -46
- package/src/cli/merge-guard.test.mjs +585 -17
- package/src/cli/output-redaction.mjs +26 -0
- package/src/cli/output-redaction.test.mjs +117 -0
- package/src/cli/pause.mjs +93 -0
- package/src/cli/pause.test.mjs +109 -0
- package/src/cli/plan-check.mjs +84 -12
- package/src/cli/plan-check.test.mjs +152 -2
- package/src/cli/plan-stop.mjs +7 -4
- package/src/cli/plan-stop.test.mjs +87 -0
- package/src/cli/plugin-agents.test.mjs +1 -1
- package/src/cli/plugin-skills.test.mjs +25 -0
- package/src/cli/post-edit-gate.test.mjs +3 -1
- package/src/cli/promotion-branch.mjs +2 -0
- package/src/cli/qc.mjs +109 -12
- package/src/cli/qc.test.mjs +59 -0
- package/src/cli/report-stop.mjs +5 -0
- package/src/cli/report-stop.test.mjs +23 -1
- package/src/cli/review-gate.mjs +24 -6
- package/src/cli/review-gate.test.mjs +116 -0
- package/src/cli/review-promotion.mjs +107 -0
- package/src/cli/review-promotion.test.mjs +251 -0
- package/src/cli/role-budget.mjs +50 -0
- package/src/cli/role-budget.test.mjs +91 -0
- package/src/cli/scaffold.mjs +23 -2
- package/src/cli/scaffold.test.mjs +51 -0
- package/src/cli/screens.mjs +2 -1
- package/src/cli/secret-patterns.mjs +16 -0
- package/src/cli/secret-patterns.test.mjs +73 -0
- package/src/cli/setup-block.mjs +24 -0
- package/src/cli/setup-block.test.mjs +96 -0
- package/src/cli/setup-checks.mjs +65 -0
- package/src/cli/setup-checks.test.mjs +158 -0
- package/src/cli/setup-compaction.mjs +55 -0
- package/src/cli/setup-compaction.test.mjs +115 -0
- package/src/cli/setup-skills.mjs +65 -0
- package/src/cli/setup-skills.test.mjs +171 -0
- package/src/cli/setup.mjs +107 -0
- package/src/cli/setup.test.mjs +275 -0
- package/src/cli/spawn-command.mjs +47 -0
- package/src/cli/spawn-command.test.mjs +64 -0
- package/src/cli/stop-gate.test.mjs +32 -128
- package/src/cli/task-gate-review.test.mjs +21 -2
- package/src/cli/task-gate.mjs +25 -12
- package/src/cli/task-gate.test.mjs +43 -5
- package/src/cli/throwaway-db.mjs +9 -3
- package/src/cli/throwaway-db.test.mjs +54 -0
- package/src/cli/tokens.mjs +46 -3
- package/src/cli/tokens.test.mjs +103 -3
- package/src/cli/transcript-usage.mjs +27 -0
- package/src/cli/transcript-usage.test.mjs +34 -0
- package/src/cli/typecheck.mjs +46 -0
- package/src/cli/typecheck.test.mjs +43 -0
- package/src/cli/user-config-package.mjs +16 -0
- package/src/cli/user-config-toml.mjs +200 -0
- package/src/cli/user-config.mjs +187 -0
- package/src/cli/user-config.test.mjs +507 -0
- package/src/cli/watch-arm.mjs +39 -0
- package/src/cli/watch-arm.test.mjs +87 -0
- package/src/cli/watch.mjs +62 -30
- package/src/cli/watch.test.mjs +203 -21
- package/src/cli/workflow-hooks.test.mjs +17 -3
- package/src/cli/workflow-settings.mjs +43 -8
- package/src/cli/workflow-settings.test.mjs +113 -0
- package/src/cli/worktree-gate.mjs +11 -12
- package/src/cli/worktree-gate.test.mjs +28 -29
- package/src/cli/worktree-isolation.mjs +3 -3
- package/src/cli/worktree-isolation.test.mjs +1 -1
- package/src/cli/worktree.mjs +23 -2
- package/src/cli/worktree.test.mjs +35 -1
- package/src/config.mjs +123 -16
- package/src/config.test.mjs +252 -3
- package/src/consumer-package.mjs +31 -0
- package/src/consumer-package.test.mjs +69 -0
- package/src/descriptions.mjs +1 -0
- package/src/eslint/index.mjs +10 -0
- package/src/eslint/jsx.mjs +20 -0
- package/src/eslint/preset.mjs +22 -4
- package/src/eslint/preset.test.mjs +118 -9
- package/src/eslint/rules/no-arbitrary-class-value.mjs +32 -0
- package/src/eslint/rules/no-literal-color.mjs +94 -0
- package/src/eslint/rules/no-static-inline-style.mjs +41 -0
- package/src/eslint/rules/one-component-per-file.mjs +70 -0
- package/src/eslint/rules/raw-element-in-primitive.mjs +31 -0
- package/src/eslint/rules.test.mjs +155 -0
- package/src/eslint/ui-regressions.test.mjs +39 -0
- package/src/gates/contract-operations.mjs +3 -3
- package/src/gates/contract-operations.test.mjs +28 -0
- package/src/gates/feature-switches.mjs +19 -0
- package/src/gates/feature-switches.test.mjs +55 -0
- package/src/gates/runtime-imports.test.mjs +114 -0
- package/src/gates/saga-key.test.mjs +1 -1
- package/src/global-skills.mjs +9 -0
- package/src/global-skills.test.mjs +54 -0
- package/src/plugin.test.mjs +3 -2
- package/src/screens/capture-idle.test.mjs +3 -3
- package/src/screens/capture.mjs +2 -1
- package/src/screens/compare.mjs +3 -2
- package/src/screens/regions.mjs +3 -2
- package/src/screens/setup.mjs +2 -1
- package/src/screens/stack-auth.mjs +2 -1
- package/src/stack/stack.test.mjs +29 -9
- package/src/ui/class-sites.mjs +38 -6
- package/src/ui/codemod.mjs +4 -1
- package/src/ui/codemod.test.mjs +52 -0
- package/src/ui/components.mjs +5 -3
- package/src/ui/components.test.mjs +8 -0
- package/src/ui/dupes.test.mjs +18 -0
- package/src/vale-style.test.mjs +5 -5
- package/templates/CLAUDE.md +2 -2
- package/templates/docs/ui.md +33 -0
- package/templates/githooks/pre-commit +8 -10
- package/templates/githooks/pre-push +11 -2
- package/templates/github/workflows/ci.yml +30 -90
- package/templates/github/workflows/pr-policy.yml +36 -0
- package/user-config/claude/CLAUDE.core.md +28 -0
- package/user-config/claude/settings.shared.json +114 -0
- package/user-config/claude/statusline.js +323 -0
- package/user-config/codex/config.shared.toml +19 -0
- package/src/cli/edit-batch-guard.mjs +0 -77
- package/src/cli/edit-batch-guard.test.mjs +0 -131
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "architecture-harness",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Architecture gates, lint rules and scaffolding for the bounded-vertical-slice architecture",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,10 +47,12 @@
|
|
|
47
47
|
"files": [
|
|
48
48
|
"src",
|
|
49
49
|
"templates",
|
|
50
|
+
"user-config",
|
|
50
51
|
"README.md"
|
|
51
52
|
],
|
|
52
53
|
"scripts": {
|
|
53
|
-
"
|
|
54
|
+
"prepack": "node src/cli/user-config-package.mjs",
|
|
55
|
+
"test": "node src/eslint/rules.test.mjs && node --test \"src/**/*.test.mjs\" ../../evals/agents/run.test.mjs",
|
|
54
56
|
"test:browser": "node --test \"src/**/*.browser-test.mjs\""
|
|
55
57
|
},
|
|
56
58
|
"peerDependencies": {
|
|
@@ -115,8 +117,5 @@
|
|
|
115
117
|
"pngjs": "^7.0.0",
|
|
116
118
|
"typescript": "^5",
|
|
117
119
|
"yaml": "^2.9.1"
|
|
118
|
-
},
|
|
119
|
-
"dependencies": {
|
|
120
|
-
"cross-spawn": "7.0.6"
|
|
121
120
|
}
|
|
122
121
|
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { realpathSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
import { globMatcher } from "../glob.mjs";
|
|
6
|
+
import { runGateSlot } from "./gate-slot.mjs";
|
|
7
|
+
import { git, lines, runShell, tryGit } from "./integrate.mjs";
|
|
8
|
+
import { posixDir, renumber } from "./migrations.mjs";
|
|
9
|
+
import { pauseRefusal } from "./pause.mjs";
|
|
10
|
+
|
|
11
|
+
export const USAGE = "qc branch sync <worktree> [--base <ref>] [--no-push]\nexit 5 paused or cannot read the operator pause";
|
|
12
|
+
|
|
13
|
+
/** A fragment: hold a machine slot while an action runs in its worktree. */
|
|
14
|
+
const inGateSlot = (words, _cwd, action) => runGateSlot(["--", ...words], { run: action });
|
|
15
|
+
|
|
16
|
+
/** A branch: refuse changes when the operator pause exists or cannot be read. */
|
|
17
|
+
function assertRunning(worktree) {
|
|
18
|
+
let refusal;
|
|
19
|
+
try {
|
|
20
|
+
refusal = pauseRefusal(worktree);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
refusal = `cannot read the operator pause (${error.message}). Wait for the operator to run \`qc resume\`.`;
|
|
23
|
+
}
|
|
24
|
+
if (refusal) throw Object.assign(new Error(refusal), { exitCode: 5 });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** A branch: dispatch a sync and push its changes through a machine gate slot. */
|
|
28
|
+
export async function runBranch(config, argv, deps = {}) {
|
|
29
|
+
const {
|
|
30
|
+
say = (line) => console.log(line),
|
|
31
|
+
run,
|
|
32
|
+
withSlot = inGateSlot,
|
|
33
|
+
runSlot = (words, cwd) => withSlot(words, cwd, () =>
|
|
34
|
+
spawnSync(words[0], words.slice(1), { cwd, stdio: "inherit", windowsHide: true }).status ?? 1),
|
|
35
|
+
} = deps;
|
|
36
|
+
let values;
|
|
37
|
+
let positionals;
|
|
38
|
+
try {
|
|
39
|
+
if (argv[0] !== "sync") throw new Error("expected the sync sub-command");
|
|
40
|
+
({ values, positionals } = parseArgs({
|
|
41
|
+
args: argv.slice(1),
|
|
42
|
+
options: { base: { type: "string" }, "no-push": { type: "boolean" } },
|
|
43
|
+
strict: true,
|
|
44
|
+
allowPositionals: true,
|
|
45
|
+
}));
|
|
46
|
+
if (positionals.length !== 1) throw new Error("name exactly one worktree");
|
|
47
|
+
} catch (error) {
|
|
48
|
+
say(`qc branch: ${error.message}\n\n${USAGE}`);
|
|
49
|
+
return 2;
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const worktree = path.resolve(config.root, positionals[0]);
|
|
53
|
+
const result = await syncBranch(config, worktree, { base: values.base, say, run, withSlot });
|
|
54
|
+
if (result.code !== 0 || !result.changed || values["no-push"]) return result.code;
|
|
55
|
+
assertRunning(config.root);
|
|
56
|
+
say(`push ${result.branch}`);
|
|
57
|
+
return await runSlot(["git", "push", "-u", "origin", result.branch], worktree);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
say(`qc branch: ${error.message}`);
|
|
60
|
+
return error.exitCode === 5 ? 5 : 1;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** A pipeline: merge the base, renumber the branch's migrations, and commit generated files. */
|
|
65
|
+
export async function syncBranch(config, worktree, options = {}) {
|
|
66
|
+
assertRunning(config.root);
|
|
67
|
+
const { say = (line) => console.log(line), run = runShell, withSlot = inGateSlot } = options;
|
|
68
|
+
const base = options.base ?? config.worktree?.base ?? "origin/main";
|
|
69
|
+
if (tryGit(worktree, ["rev-parse", "-q", "--verify", "MERGE_HEAD"]).ok) throw new Error("a merge is in progress: resolve it and commit it first");
|
|
70
|
+
const branch = git(worktree, ["branch", "--show-current"]).trim();
|
|
71
|
+
if (!branch) throw new Error("HEAD is detached: switch to a branch first");
|
|
72
|
+
if ((config.swarm?.isolation?.protectedBranches ?? []).includes(branch)) throw new Error(`cannot sync protected branch ${branch}`);
|
|
73
|
+
if (git(worktree, ["status", "--porcelain"]).trim() !== "") throw new Error("the working tree has changes: commit or stash them first");
|
|
74
|
+
const [targetCommon, rootCommon] = [worktree, config.root].map((directory) => {
|
|
75
|
+
const common = realpathSync.native(git(directory, ["rev-parse", "--path-format=absolute", "--git-common-dir"]).trim());
|
|
76
|
+
return process.platform === "win32" ? common.toLowerCase() : common;
|
|
77
|
+
});
|
|
78
|
+
if (targetCommon !== rootCommon) throw new Error("the target belongs to another repository: choose a worktree of the repository root");
|
|
79
|
+
tryGit(worktree, ["fetch", "--quiet", "origin"]);
|
|
80
|
+
if (!tryGit(worktree, ["rev-parse", "-q", "--verify", `${base}^{commit}`]).ok) throw new Error(`unknown base ${base}`);
|
|
81
|
+
const alreadyMerged = tryGit(worktree, ["merge-base", "--is-ancestor", base, "HEAD"]).ok;
|
|
82
|
+
if (alreadyMerged) {
|
|
83
|
+
say(`OK ${branch} already holds ${base}`);
|
|
84
|
+
const upstream = tryGit(worktree, ["rev-parse", "--verify", "@{upstream}"]);
|
|
85
|
+
if (upstream.ok && git(worktree, ["rev-list", "--count", `${upstream.out.trim()}..HEAD`]).trim() === "0") {
|
|
86
|
+
return { code: 0, changed: false };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (!alreadyMerged) {
|
|
91
|
+
const merged = tryGit(worktree, ["merge", "--no-ff", "--no-commit", base]);
|
|
92
|
+
if (!merged.ok) {
|
|
93
|
+
const conflicts = lines(git(worktree, ["diff", "--name-only", "--diff-filter=U"]));
|
|
94
|
+
if (conflicts.length === 0) throw new Error(`git merge ${base}: ${merged.err}`);
|
|
95
|
+
const generated = globMatcher(config.generated?.globs ?? []);
|
|
96
|
+
const byHand = conflicts.filter((file) => !generated(file) || !config.generated?.command);
|
|
97
|
+
if (byHand.length > 0) {
|
|
98
|
+
say(`CONFLICT merging ${base}; the merge is left in progress. Files:`);
|
|
99
|
+
for (const file of byHand) say(` ${file}`);
|
|
100
|
+
if (!config.generated?.command && conflicts.some(generated)) say("Set generated.command or resolve the generated files by hand.");
|
|
101
|
+
say(`Resolve them, run \`qc migrations renumber --onto ${base}\`, commit, and run qc branch sync again.`);
|
|
102
|
+
return { code: 1 };
|
|
103
|
+
}
|
|
104
|
+
git(worktree, ["checkout", "--ours", "--", ...conflicts]);
|
|
105
|
+
git(worktree, ["add", "--", ...conflicts]);
|
|
106
|
+
}
|
|
107
|
+
const dir = posixDir(config.paths?.migrations);
|
|
108
|
+
if (dir) {
|
|
109
|
+
for (const { from, to } of renumber(worktree, dir, { onto: base, branch: "HEAD" }).plan) say(`rename ${dir}/${from} -> ${to}`);
|
|
110
|
+
}
|
|
111
|
+
const commit = ["commit", "-q", "--no-edit"];
|
|
112
|
+
await withSlot(["git", ...commit], worktree, () => git(worktree, commit));
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const command = config.generated?.command;
|
|
116
|
+
if (command) {
|
|
117
|
+
if (await withSlot([command], worktree, () => run(command, worktree)) !== 0) throw new Error(`generated.command failed: ${command} failed`);
|
|
118
|
+
if (git(worktree, ["status", "--porcelain"]).trim() !== "") {
|
|
119
|
+
git(worktree, ["add", "-A"]);
|
|
120
|
+
const issue = /^[a-z]+\/(\d+)-/.exec(branch)?.[1];
|
|
121
|
+
const commit = ["commit", "-q", "-m", "chore: regenerate the generated files", ...(issue ? ["-m", `Refs #${issue}`] : [])];
|
|
122
|
+
await withSlot(["git", ...commit], worktree, () => git(worktree, commit));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return { code: 0, changed: true, branch };
|
|
126
|
+
}
|
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
import { strict as assert } from "node:assert";
|
|
2
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
3
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { beforeEach, test } from "node:test";
|
|
7
|
+
import { runBranch, syncBranch, USAGE } from "./branch-sync.mjs";
|
|
8
|
+
|
|
9
|
+
const git = (cwd, ...args) => execFileSync("git", args, { cwd, stdio: "pipe", encoding: "utf8" }).trim();
|
|
10
|
+
const quiet = (lines) => (line) => lines.push(line);
|
|
11
|
+
const run = (command, cwd) => spawnSync(command, { cwd, shell: true, stdio: "pipe" }).status ?? 1;
|
|
12
|
+
|
|
13
|
+
beforeEach((t) => {
|
|
14
|
+
const previous = process.env.QC_GATE_SLOT_DIR;
|
|
15
|
+
const directory = mkdtempSync(path.join(os.tmpdir(), "qc-branch-sync-slots-"));
|
|
16
|
+
process.env.QC_GATE_SLOT_DIR = directory;
|
|
17
|
+
t.after(() => {
|
|
18
|
+
if (previous === undefined) delete process.env.QC_GATE_SLOT_DIR;
|
|
19
|
+
else process.env.QC_GATE_SLOT_DIR = previous;
|
|
20
|
+
rmSync(directory, { recursive: true, force: true });
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("branch usage lists the pause refusal exit", () => {
|
|
25
|
+
assert.match(USAGE, /exit 5.*paus/i);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
for (const target of ["does-not-exist", "outside-git"]) test(`a ${target} target reports an input error rather than a pause`, async (t) => {
|
|
29
|
+
const root = batch(t);
|
|
30
|
+
const worktree = path.join(os.tmpdir(), `${path.basename(root)}-${target}`);
|
|
31
|
+
if (target === "outside-git") {
|
|
32
|
+
mkdirSync(worktree);
|
|
33
|
+
t.after(() => rmSync(worktree, { recursive: true, force: true }));
|
|
34
|
+
}
|
|
35
|
+
const lines = [];
|
|
36
|
+
assert.equal(await runBranch(config(root), ["sync", worktree], {
|
|
37
|
+
say: quiet(lines), runSlot: () => assert.fail("an invalid worktree must never push"),
|
|
38
|
+
}), 1);
|
|
39
|
+
assert.equal(lines.length, 1);
|
|
40
|
+
assert.match(lines[0], target === "does-not-exist" ? /git branch --show-current: failed/ : /not a git repository/i);
|
|
41
|
+
assert.doesNotMatch(lines[0], /pause|qc resume/);
|
|
42
|
+
assert.equal(git(root, "status", "--porcelain"), "");
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
for (const paused of [false, true]) test(`a target from another repository is refused when its repository is ${paused ? "paused" : "running"}`, async (t) => {
|
|
46
|
+
const root = batch(t);
|
|
47
|
+
const foreign = batch(t);
|
|
48
|
+
const worktree = path.join(foreign, ".worktree", "run");
|
|
49
|
+
git(foreign, "worktree", "add", "-qb", "foreign-run", worktree);
|
|
50
|
+
if (paused) {
|
|
51
|
+
mkdirSync(path.join(foreign, ".git", "qc"), { recursive: true });
|
|
52
|
+
writeFileSync(path.join(foreign, ".git", "qc", "pause"), "operator investigation\n");
|
|
53
|
+
}
|
|
54
|
+
const head = git(worktree, "rev-parse", "HEAD");
|
|
55
|
+
const lines = [];
|
|
56
|
+
let generated = 0;
|
|
57
|
+
let pushed = 0;
|
|
58
|
+
assert.equal(await runBranch(config(root), ["sync", worktree], {
|
|
59
|
+
say: quiet(lines),
|
|
60
|
+
run: () => { generated += 1; return 0; },
|
|
61
|
+
runSlot: () => { pushed += 1; return 0; },
|
|
62
|
+
}), 1);
|
|
63
|
+
assert.equal(lines.length, 1);
|
|
64
|
+
assert.match(lines[0], /target.*another repository/i);
|
|
65
|
+
assert.equal(generated, 0);
|
|
66
|
+
assert.equal(pushed, 0);
|
|
67
|
+
assert.equal(git(worktree, "rev-parse", "HEAD"), head);
|
|
68
|
+
assert.equal(git(worktree, "status", "--porcelain"), "");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
for (const spelling of ["lowercase drive", "lowercase path", "linked root"]) test(`branch sync accepts the same repository with a ${spelling}`, {
|
|
72
|
+
skip: spelling !== "linked root" && process.platform !== "win32",
|
|
73
|
+
}, async (t) => {
|
|
74
|
+
const root = batch(t);
|
|
75
|
+
const worktree = path.join(root, ".worktree", "run");
|
|
76
|
+
git(root, "worktree", "add", "-qb", "linked-run", worktree);
|
|
77
|
+
const configuredRoot = spelling === "lowercase drive" ? root[0].toLowerCase() + root.slice(1)
|
|
78
|
+
: spelling === "lowercase path" ? root.toLowerCase() : worktree;
|
|
79
|
+
const lines = [];
|
|
80
|
+
assert.equal(await runBranch(config(configuredRoot), ["sync", spelling === "linked root" ? "." : worktree, "--no-push"], {
|
|
81
|
+
say: quiet(lines), run, withSlot: (_words, _cwd, action) => action(),
|
|
82
|
+
runSlot: () => assert.fail("--no-push must never push"),
|
|
83
|
+
}), 0, lines.join("\n"));
|
|
84
|
+
git(worktree, "merge-base", "--is-ancestor", "main", "HEAD");
|
|
85
|
+
assert.equal(git(worktree, "status", "--porcelain"), "");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("a pause refuses sync before branch changes or a push", async (t) => {
|
|
89
|
+
const dir = batch(t);
|
|
90
|
+
const head = git(dir, "rev-parse", "HEAD");
|
|
91
|
+
mkdirSync(path.join(dir, ".git", "qc"), { recursive: true });
|
|
92
|
+
writeFileSync(path.join(dir, ".git", "qc", "pause"), "operator investigation\n");
|
|
93
|
+
const refusal = "An operator paused the kit: operator investigation. Wait for the operator to run `qc resume`.";
|
|
94
|
+
await assert.rejects(() => syncBranch(config(dir), dir), { message: refusal });
|
|
95
|
+
const lines = [];
|
|
96
|
+
assert.equal(await runBranch(config(dir), ["sync", "."], {
|
|
97
|
+
say: quiet(lines), runSlot: () => assert.fail("a paused branch must never push"),
|
|
98
|
+
}), 5);
|
|
99
|
+
assert.deepEqual(lines, [`qc branch: ${refusal}`]);
|
|
100
|
+
assert.equal(git(dir, "rev-parse", "HEAD"), head);
|
|
101
|
+
assert.equal(git(dir, "status", "--porcelain"), "");
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("an unreadable pause refuses sync before branch changes or a push", async (t) => {
|
|
105
|
+
const dir = batch(t);
|
|
106
|
+
const head = git(dir, "rev-parse", "HEAD");
|
|
107
|
+
mkdirSync(path.join(dir, ".git", "qc", "pause"), { recursive: true });
|
|
108
|
+
await assert.rejects(() => syncBranch(config(dir), dir), /cannot read the operator pause .*Wait for the operator to run `qc resume`\./);
|
|
109
|
+
const lines = [];
|
|
110
|
+
assert.equal(await runBranch(config(dir), ["sync", "."], {
|
|
111
|
+
say: quiet(lines), runSlot: () => assert.fail("an unreadable pause must never push"),
|
|
112
|
+
}), 5);
|
|
113
|
+
assert.equal(lines.length, 1);
|
|
114
|
+
assert.match(lines[0], /^qc branch: cannot read the operator pause .*Wait for the operator to run `qc resume`\.$/);
|
|
115
|
+
assert.equal(git(dir, "rev-parse", "HEAD"), head);
|
|
116
|
+
assert.equal(git(dir, "status", "--porcelain"), "");
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
for (const unreadable of [false, true]) {
|
|
120
|
+
test(`branch sync checks ${unreadable ? "an unreadable" : "a new"} pause again before pushing`, async (t) => {
|
|
121
|
+
const dir = batch(t);
|
|
122
|
+
const lines = [];
|
|
123
|
+
let generated = 0;
|
|
124
|
+
assert.equal(await runBranch(config(dir), ["sync", "."], {
|
|
125
|
+
say: quiet(lines),
|
|
126
|
+
runSlot: () => assert.fail("a pause set during sync must prevent the push"),
|
|
127
|
+
run: (command, cwd) => {
|
|
128
|
+
generated += 1;
|
|
129
|
+
const code = run(command, cwd);
|
|
130
|
+
const file = path.join(dir, ".git", "qc", "pause");
|
|
131
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
132
|
+
if (unreadable) mkdirSync(file);
|
|
133
|
+
else writeFileSync(file, "operator investigation\n");
|
|
134
|
+
return code;
|
|
135
|
+
},
|
|
136
|
+
}), 5);
|
|
137
|
+
assert.equal(generated, 1);
|
|
138
|
+
assert.match(lines.at(-1), /Wait for the operator to run `qc resume`\.$/);
|
|
139
|
+
if (unreadable) assert.match(lines.at(-1), /cannot read the operator pause/);
|
|
140
|
+
else assert.match(lines.at(-1), /An operator paused the kit: operator investigation/);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
test("each branch-sync test uses a private gate-slot folder", () => {
|
|
145
|
+
const directory = process.env.QC_GATE_SLOT_DIR;
|
|
146
|
+
assert.ok(directory);
|
|
147
|
+
assert.match(path.basename(directory), /^qc-branch-sync-slots-/);
|
|
148
|
+
assert.ok(existsSync(directory));
|
|
149
|
+
assert.notEqual(directory, path.join(os.tmpdir(), "architecture-kit", "gate-slots"));
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
function commitFile(dir, file, text) {
|
|
153
|
+
mkdirSync(path.dirname(path.join(dir, file)), { recursive: true });
|
|
154
|
+
writeFileSync(path.join(dir, file), text);
|
|
155
|
+
git(dir, "add", ".");
|
|
156
|
+
git(dir, "commit", "-q", "-m", file);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function batch(t, generated = false) {
|
|
160
|
+
const dir = realpathSync.native(mkdtempSync(path.join(os.tmpdir(), "qc-branch-sync-")));
|
|
161
|
+
t.after(() => rmSync(dir, { recursive: true, force: true }));
|
|
162
|
+
git(dir, "init", "-q", "-b", "main");
|
|
163
|
+
for (const [key, value] of [["user.name", "qc"], ["user.email", "qc@example.com"], ["commit.gpgsign", "false"], ["core.autocrlf", "false"]]) git(dir, "config", key, value);
|
|
164
|
+
commitFile(dir, "db/0001_init.sql", "select 1;\n");
|
|
165
|
+
commitFile(dir, "gen.mjs", 'import { writeFileSync } from "node:fs";\nwriteFileSync("out.generated.txt", "regenerated");\n');
|
|
166
|
+
commitFile(dir, "a.txt", "base\n");
|
|
167
|
+
if (generated) commitFile(dir, "out.generated.txt", "base\n");
|
|
168
|
+
git(dir, "switch", "-q", "-c", "feat/5-mine");
|
|
169
|
+
commitFile(dir, "db/0002_mine.sql", "select 'mine';\n");
|
|
170
|
+
git(dir, "switch", "-q", "main");
|
|
171
|
+
commitFile(dir, "db/0002_theirs.sql", "select 'theirs';\n");
|
|
172
|
+
git(dir, "switch", "-q", "feat/5-mine");
|
|
173
|
+
return dir;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const config = (dir, command = "node gen.mjs") => ({
|
|
177
|
+
root: dir,
|
|
178
|
+
paths: { migrations: "db" },
|
|
179
|
+
generated: { globs: ["**/*.generated.*"], command },
|
|
180
|
+
worktree: { base: "main" },
|
|
181
|
+
swarm: { isolation: { protectedBranches: ["main"] } },
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test("sync merges the base, renumbers its own migrations, and commits generated files", async (t) => {
|
|
185
|
+
const dir = batch(t);
|
|
186
|
+
const said = [];
|
|
187
|
+
assert.deepEqual(await syncBranch(config(dir), dir, { say: quiet(said), run }), { code: 0, changed: true, branch: "feat/5-mine" });
|
|
188
|
+
assert.deepEqual(readdirSync(path.join(dir, "db")).sort(), ["0001_init.sql", "0002_theirs.sql", "0003_mine.sql"]);
|
|
189
|
+
git(dir, "merge-base", "--is-ancestor", "main", "HEAD");
|
|
190
|
+
assert.equal(git(dir, "status", "--porcelain"), "");
|
|
191
|
+
assert.equal(readFileSync(path.join(dir, "out.generated.txt"), "utf8"), "regenerated");
|
|
192
|
+
assert.ok(said.includes("rename db/0002_mine.sql -> 0003_mine.sql"));
|
|
193
|
+
assert.match(git(dir, "log", "-1", "--format=%b"), /Refs #5/);
|
|
194
|
+
const head = git(dir, "rev-parse", "HEAD");
|
|
195
|
+
git(dir, "branch", "published", "HEAD");
|
|
196
|
+
git(dir, "branch", "--set-upstream-to=published");
|
|
197
|
+
assert.deepEqual(await syncBranch(config(dir), dir, { say: quiet(said), run }), { code: 0, changed: false });
|
|
198
|
+
assert.equal(git(dir, "rev-parse", "HEAD"), head);
|
|
199
|
+
assert.ok(said.includes("OK feat/5-mine already holds main"));
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test("a source conflict leaves the merge in progress and reports recovery instructions", async (t) => {
|
|
203
|
+
const dir = batch(t);
|
|
204
|
+
commitFile(dir, "a.txt", "mine\n");
|
|
205
|
+
git(dir, "switch", "-q", "main");
|
|
206
|
+
commitFile(dir, "a.txt", "theirs\n");
|
|
207
|
+
git(dir, "switch", "-q", "feat/5-mine");
|
|
208
|
+
const said = [];
|
|
209
|
+
assert.equal((await syncBranch(config(dir), dir, { say: quiet(said), run })).code, 1);
|
|
210
|
+
assert.ok(existsSync(path.join(dir, ".git", "MERGE_HEAD")));
|
|
211
|
+
assert.match(said.join("\n"), /a\.txt/);
|
|
212
|
+
assert.match(said.join("\n"), /qc migrations renumber --onto main/);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test("a generated conflict is resolved and regenerated", async (t) => {
|
|
216
|
+
const dir = batch(t, true);
|
|
217
|
+
commitFile(dir, "out.generated.txt", "mine\n");
|
|
218
|
+
git(dir, "switch", "-q", "main");
|
|
219
|
+
commitFile(dir, "out.generated.txt", "theirs\n");
|
|
220
|
+
git(dir, "switch", "-q", "feat/5-mine");
|
|
221
|
+
assert.equal((await syncBranch(config(dir), dir, { say: quiet([]), run })).code, 0);
|
|
222
|
+
assert.equal(readFileSync(path.join(dir, "out.generated.txt"), "utf8"), "regenerated");
|
|
223
|
+
assert.equal(git(dir, "status", "--porcelain"), "");
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test("sync refuses a protected branch", async (t) => {
|
|
227
|
+
const dir = batch(t);
|
|
228
|
+
git(dir, "switch", "-q", "main");
|
|
229
|
+
await assert.rejects(() => syncBranch(config(dir), dir), /protected.*main|main.*protected/);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test("sync refuses a dirty tree", async (t) => {
|
|
233
|
+
const dir = batch(t);
|
|
234
|
+
writeFileSync(path.join(dir, "a.txt"), "dirty\n");
|
|
235
|
+
await assert.rejects(() => syncBranch(config(dir), dir), /working tree.*changes|dirty/);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
test("sync refuses a detached head", async (t) => {
|
|
239
|
+
const dir = batch(t);
|
|
240
|
+
git(dir, "checkout", "-q", "--detach");
|
|
241
|
+
await assert.rejects(() => syncBranch(config(dir), dir), /detached/i);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test("sync refuses an unknown base", async (t) => {
|
|
245
|
+
const dir = batch(t);
|
|
246
|
+
await assert.rejects(() => syncBranch(config(dir), dir, { base: "missing-base" }), /missing-base/);
|
|
247
|
+
assert.equal(git(dir, "status", "--porcelain"), "");
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
test("sync refuses a merge in progress", async (t) => {
|
|
251
|
+
const dir = batch(t);
|
|
252
|
+
git(dir, "merge", "--no-ff", "--no-commit", "main");
|
|
253
|
+
await assert.rejects(() => syncBranch(config(dir), dir), /merge.*in progress/);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
test("sync throws when the generator fails", async (t) => {
|
|
257
|
+
const dir = batch(t);
|
|
258
|
+
await assert.rejects(() => syncBranch(config(dir, 'node -e "process.exit(1)"'), dir, { say: quiet([]), run }), /generated\.command failed/);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test("branch sync pushes a changed branch through a gate slot in its worktree", async (t) => {
|
|
262
|
+
const dir = batch(t);
|
|
263
|
+
const said = [];
|
|
264
|
+
const calls = [];
|
|
265
|
+
const runSlot = (words, cwd) => { calls.push({ words, cwd }); return 0; };
|
|
266
|
+
assert.equal(await runBranch(config(dir), ["sync", dir], { say: quiet(said), run, runSlot }), 0);
|
|
267
|
+
assert.deepEqual(calls, [{ words: ["git", "push", "-u", "origin", "feat/5-mine"], cwd: dir }]);
|
|
268
|
+
assert.ok(said.includes("push feat/5-mine"));
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
test("branch sync with --no-push skips the gate slot", async (t) => {
|
|
272
|
+
const dir = batch(t);
|
|
273
|
+
const calls = [];
|
|
274
|
+
const runSlot = (words, cwd) => { calls.push({ words, cwd }); return 0; };
|
|
275
|
+
assert.equal(await runBranch(config(dir), ["sync", dir, "--no-push"], { say: quiet([]), run, runSlot }), 0);
|
|
276
|
+
assert.deepEqual(calls, []);
|
|
277
|
+
git(dir, "merge-base", "--is-ancestor", "main", "HEAD");
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
test("branch sync skips the gate slot for an up-to-date branch", async (t) => {
|
|
281
|
+
const dir = batch(t);
|
|
282
|
+
git(dir, "merge", "--no-edit", "main");
|
|
283
|
+
git(dir, "branch", "published", "HEAD");
|
|
284
|
+
git(dir, "branch", "--set-upstream-to=published");
|
|
285
|
+
const calls = [];
|
|
286
|
+
const runSlot = (words, cwd) => { calls.push({ words, cwd }); return 0; };
|
|
287
|
+
assert.equal(await runBranch(config(dir), ["sync", dir], { say: quiet([]), run, runSlot }), 0);
|
|
288
|
+
assert.deepEqual(calls, []);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
test("branch sync pushes a branch containing a semicolon as one argument", async (t) => {
|
|
292
|
+
const dir = batch(t);
|
|
293
|
+
const remote = `${dir}-remote.git`;
|
|
294
|
+
t.after(() => rmSync(remote, { recursive: true, force: true }));
|
|
295
|
+
git(dir, "init", "--bare", "-q", remote);
|
|
296
|
+
git(dir, "remote", "add", "origin", remote);
|
|
297
|
+
const branch = process.platform === "win32" ? "feat/5-mine;&ver" : "feat/5-mine;echo>injected";
|
|
298
|
+
git(dir, "branch", "-m", branch);
|
|
299
|
+
assert.equal(await runBranch(config(dir), ["sync", dir], { say: quiet([]), run }), 0);
|
|
300
|
+
assert.equal(existsSync(path.join(dir, "injected")), false);
|
|
301
|
+
assert.equal(git(remote, "rev-parse", `refs/heads/${branch}`), git(dir, "rev-parse", "HEAD"));
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
test("a resolved source conflict reruns the generator and pushes once", async (t) => {
|
|
305
|
+
const dir = batch(t);
|
|
306
|
+
commitFile(dir, "a.txt", "mine\n");
|
|
307
|
+
git(dir, "switch", "-q", "main");
|
|
308
|
+
commitFile(dir, "a.txt", "theirs\n");
|
|
309
|
+
git(dir, "switch", "-q", "feat/5-mine");
|
|
310
|
+
assert.equal((await syncBranch(config(dir), dir, { say: quiet([]), run })).code, 1);
|
|
311
|
+
commitFile(dir, "a.txt", "resolved\n");
|
|
312
|
+
const calls = [];
|
|
313
|
+
let generated = 0;
|
|
314
|
+
const runSlot = (words, cwd) => { calls.push({ words, cwd }); return 0; };
|
|
315
|
+
assert.equal(await runBranch(config(dir), ["sync", dir], {
|
|
316
|
+
say: quiet([]), runSlot, run: (command, cwd) => { generated += 1; return run(command, cwd); },
|
|
317
|
+
}), 0);
|
|
318
|
+
assert.equal(generated, 1);
|
|
319
|
+
assert.equal(readFileSync(path.join(dir, "out.generated.txt"), "utf8"), "regenerated");
|
|
320
|
+
assert.deepEqual(calls, [{ words: ["git", "push", "-u", "origin", "feat/5-mine"], cwd: dir }]);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
test("sync holds gate slots for the merge commit, generator, and generated commit", async (t) => {
|
|
324
|
+
const dir = batch(t);
|
|
325
|
+
const calls = [];
|
|
326
|
+
let held = false;
|
|
327
|
+
const withSlot = async (words, cwd, action) => {
|
|
328
|
+
calls.push({ words, cwd });
|
|
329
|
+
held = true;
|
|
330
|
+
try { return await action(); } finally { held = false; }
|
|
331
|
+
};
|
|
332
|
+
await syncBranch(config(dir), dir, {
|
|
333
|
+
say: quiet([]), withSlot,
|
|
334
|
+
run: (command, cwd) => { assert.equal(held, true); return run(command, cwd); },
|
|
335
|
+
});
|
|
336
|
+
assert.deepEqual(calls.map(({ words }) => words.slice(0, 3)), [
|
|
337
|
+
["git", "commit", "-q"], ["node gen.mjs"], ["git", "commit", "-q"],
|
|
338
|
+
]);
|
|
339
|
+
assert.ok(calls.every(({ cwd }) => cwd === dir));
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
test("a branch ahead of its upstream retries generation and a failed push", async (t) => {
|
|
343
|
+
const dir = batch(t);
|
|
344
|
+
git(dir, "branch", "published", "HEAD");
|
|
345
|
+
git(dir, "branch", "--set-upstream-to=published");
|
|
346
|
+
let generated = 0;
|
|
347
|
+
let pushed = 0;
|
|
348
|
+
const deps = {
|
|
349
|
+
say: quiet([]),
|
|
350
|
+
run: (command, cwd) => { generated += 1; return generated === 1 ? 1 : run(command, cwd); },
|
|
351
|
+
runSlot: () => { pushed += 1; return pushed === 1 ? 7 : 0; },
|
|
352
|
+
};
|
|
353
|
+
assert.equal(await runBranch(config(dir), ["sync", dir], deps), 1);
|
|
354
|
+
assert.equal(pushed, 0);
|
|
355
|
+
assert.equal(await runBranch(config(dir), ["sync", dir], deps), 7);
|
|
356
|
+
assert.equal(await runBranch(config(dir), ["sync", dir], deps), 0);
|
|
357
|
+
assert.equal(generated, 3);
|
|
358
|
+
assert.equal(pushed, 2);
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
test("a generated conflict without a generator stays unresolved and lists the file", async (t) => {
|
|
362
|
+
const dir = batch(t, true);
|
|
363
|
+
commitFile(dir, "out.generated.txt", "mine\n");
|
|
364
|
+
git(dir, "switch", "-q", "main");
|
|
365
|
+
commitFile(dir, "out.generated.txt", "theirs\n");
|
|
366
|
+
git(dir, "switch", "-q", "feat/5-mine");
|
|
367
|
+
const said = [];
|
|
368
|
+
assert.equal((await syncBranch(config(dir, null), dir, { say: quiet(said), run })).code, 1);
|
|
369
|
+
assert.match(said.join("\n"), /generated\.command/);
|
|
370
|
+
assert.ok(said.includes(" out.generated.txt"));
|
|
371
|
+
assert.equal(git(dir, "diff", "--name-only", "--diff-filter=U"), "out.generated.txt");
|
|
372
|
+
assert.ok(existsSync(path.join(dir, ".git", "MERGE_HEAD")));
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
test("branch sync returns one after a conflict and skips the gate slot", async (t) => {
|
|
376
|
+
const dir = batch(t);
|
|
377
|
+
commitFile(dir, "a.txt", "mine\n");
|
|
378
|
+
git(dir, "switch", "-q", "main");
|
|
379
|
+
commitFile(dir, "a.txt", "theirs\n");
|
|
380
|
+
git(dir, "switch", "-q", "feat/5-mine");
|
|
381
|
+
const calls = [];
|
|
382
|
+
const runSlot = (words, cwd) => { calls.push({ words, cwd }); return 0; };
|
|
383
|
+
assert.equal(await runBranch(config(dir), ["sync", dir], { say: quiet([]), run, runSlot }), 1);
|
|
384
|
+
assert.deepEqual(calls, []);
|
|
385
|
+
assert.ok(existsSync(path.join(dir, ".git", "MERGE_HEAD")));
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
test("branch sync returns the gate slot's failure code", async (t) => {
|
|
389
|
+
const dir = batch(t);
|
|
390
|
+
const calls = [];
|
|
391
|
+
const runSlot = (words, cwd) => { calls.push({ words, cwd }); return 7; };
|
|
392
|
+
assert.equal(await runBranch(config(dir), ["sync", dir], { say: quiet([]), run, runSlot }), 7);
|
|
393
|
+
assert.deepEqual(calls, [{ words: ["git", "push", "-u", "origin", "feat/5-mine"], cwd: dir }]);
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
for (const argv of [["sync"], ["sync", ".", "extra"], ["merge", "."], [], ["sync", ".", "--base"], ["sync", ".", "--unknown"]]) {
|
|
397
|
+
test(`branch rejects invalid arguments ${JSON.stringify(argv)} with usage`, async () => {
|
|
398
|
+
const said = [];
|
|
399
|
+
const calls = [];
|
|
400
|
+
const runSlot = (words, cwd) => { calls.push({ words, cwd }); return 0; };
|
|
401
|
+
assert.equal(await runBranch(config("."), argv, { say: quiet(said), run, runSlot }), 2);
|
|
402
|
+
assert.match(said.join("\n"), /qc branch sync <worktree> \[--base <ref>\] \[--no-push\]/);
|
|
403
|
+
assert.deepEqual(calls, []);
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
test("branch sync resolves its worktree against config.root and accepts --base", async (t) => {
|
|
408
|
+
const root = batch(t);
|
|
409
|
+
git(root, "checkout", "-q", "main");
|
|
410
|
+
const dir = path.join(root, ".worktree", "run");
|
|
411
|
+
git(root, "worktree", "add", "-q", dir, "feat/5-mine");
|
|
412
|
+
const cfg = { ...config(dir), root, worktree: { base: "missing-base" } };
|
|
413
|
+
const calls = [];
|
|
414
|
+
const runSlot = (words, cwd) => { calls.push({ words, cwd }); return 0; };
|
|
415
|
+
assert.equal(await runBranch(cfg, ["sync", path.relative(root, dir), "--base", "main"], { say: quiet([]), run, runSlot }), 0);
|
|
416
|
+
assert.deepEqual(calls, [{ words: ["git", "push", "-u", "origin", "feat/5-mine"], cwd: dir }]);
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
test("branch sync prints a refusal and skips the gate slot", async (t) => {
|
|
420
|
+
const dir = batch(t);
|
|
421
|
+
writeFileSync(path.join(dir, "a.txt"), "dirty\n");
|
|
422
|
+
const said = [];
|
|
423
|
+
const calls = [];
|
|
424
|
+
const runSlot = (words, cwd) => { calls.push({ words, cwd }); return 0; };
|
|
425
|
+
assert.equal(await runBranch(config(dir), ["sync", dir], { say: quiet(said), run, runSlot }), 1);
|
|
426
|
+
assert.match(said.join("\n"), /^qc branch: .*working tree has changes/);
|
|
427
|
+
assert.deepEqual(calls, []);
|
|
428
|
+
});
|