architecture-harness 0.25.0 → 0.26.0
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 +3 -22
- package/src/cli/ask.mjs +42 -0
- package/src/cli/ask.test.mjs +40 -0
- package/src/cli/branch-sync.mjs +126 -0
- package/src/cli/branch-sync.test.mjs +428 -0
- package/src/cli/budget-guard.mjs +74 -5
- package/src/cli/budget-guard.test.mjs +185 -2
- package/src/cli/budget-report.mjs +85 -0
- package/src/cli/budget-report.test.mjs +173 -0
- package/src/cli/budget.mjs +8 -5
- package/src/cli/check-commands.mjs +123 -11
- package/src/cli/check-commands.test.mjs +360 -6
- package/src/cli/check-feature-switches.test.mjs +110 -0
- package/src/cli/check-full.test.mjs +152 -0
- package/src/cli/check-verdict.mjs +46 -0
- package/src/cli/check-verdict.test.mjs +32 -0
- package/src/cli/check.mjs +137 -4
- package/src/cli/check.test.mjs +45 -0
- package/src/cli/checkpoint.mjs +143 -0
- package/src/cli/checkpoint.test.mjs +146 -0
- package/src/cli/child-run.mjs +7 -2
- package/src/cli/child-run.test.mjs +17 -2
- package/src/cli/ci-failures.mjs +304 -0
- package/src/cli/ci-failures.test.mjs +615 -0
- package/src/cli/ci-preview.mjs +62 -0
- package/src/cli/ci-preview.test.mjs +85 -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 +86 -0
- package/src/cli/claude-core.test.mjs +37 -0
- package/src/cli/codex-implement.mjs +580 -47
- package/src/cli/codex-implement.test.mjs +1946 -29
- 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/codex-verify.mjs +230 -0
- package/src/cli/codex-verify.test.mjs +402 -0
- package/src/cli/comment-watch.mjs +391 -0
- package/src/cli/comment-watch.test.mjs +392 -0
- package/src/cli/commit-guard.mjs +219 -0
- package/src/cli/commit-guard.test.mjs +809 -0
- 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/diff-shape.mjs +162 -0
- package/src/cli/diff-shape.test.mjs +200 -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 +145 -10
- package/src/cli/dispatch-reminder.mjs +23 -10
- package/src/cli/dispatch-reminder.test.mjs +63 -11
- package/src/cli/dispatch-route.mjs +54 -0
- package/src/cli/dispatch-route.test.mjs +101 -0
- package/src/cli/dispatch-slot.mjs +2 -2
- package/src/cli/dispatch-slot.test.mjs +18 -19
- package/src/cli/dispatch.test.mjs +3 -3
- package/src/cli/e2e-affected.mjs +15 -0
- package/src/cli/e2e-affected.test.mjs +73 -0
- package/src/cli/fleet.mjs +180 -0
- package/src/cli/fleet.test.mjs +213 -0
- package/src/cli/gate-slot.mjs +2 -1
- package/src/cli/gh-merge-command.mjs +96 -31
- package/src/cli/gh-merge-command.test.mjs +74 -0
- package/src/cli/gh-run.mjs +64 -3
- package/src/cli/gh-run.test.mjs +66 -1
- package/src/cli/git-hooks.test.mjs +25 -3
- package/src/cli/git-read.mjs +2 -1
- package/src/cli/integrate-tree.mjs +47 -0
- package/src/cli/integrate.mjs +143 -40
- package/src/cli/integrate.test.mjs +347 -1
- package/src/cli/integration-lane.mjs +62 -0
- package/src/cli/integration-lane.test.mjs +213 -0
- package/src/cli/ledger.mjs +4 -2
- package/src/cli/ledger.test.mjs +12 -3
- package/src/cli/legs.mjs +53 -0
- package/src/cli/legs.test.mjs +70 -0
- package/src/cli/lint-changed.mjs +59 -10
- package/src/cli/lint-changed.test.mjs +112 -1
- package/src/cli/locked-tests.mjs +134 -0
- package/src/cli/locked-tests.test.mjs +188 -0
- package/src/cli/merge-guard.mjs +234 -62
- package/src/cli/merge-guard.test.mjs +768 -39
- package/src/cli/metrics.mjs +53 -0
- package/src/cli/metrics.test.mjs +73 -0
- package/src/cli/milestone.mjs +297 -0
- package/src/cli/milestone.test.mjs +294 -0
- package/src/cli/mutate.mjs +203 -0
- package/src/cli/mutate.test.mjs +134 -0
- package/src/cli/output-redaction.mjs +26 -0
- package/src/cli/output-redaction.test.mjs +117 -0
- package/src/cli/overview.mjs +131 -0
- package/src/cli/overview.test.mjs +137 -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/platform-risk.mjs +46 -0
- package/src/cli/platform-risk.test.mjs +38 -0
- package/src/cli/plugin-skills.test.mjs +25 -0
- package/src/cli/pr-guard.mjs +128 -0
- package/src/cli/pr-guard.test.mjs +154 -0
- package/src/cli/promotion-branch.mjs +2 -0
- package/src/cli/qc.mjs +160 -27
- package/src/cli/qc.test.mjs +93 -0
- package/src/cli/report-stop.mjs +5 -0
- package/src/cli/report-stop.test.mjs +23 -1
- package/src/cli/retry-failed.mjs +3 -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/run-log.mjs +73 -0
- package/src/cli/run-log.test.mjs +121 -0
- 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/skill-length.test.mjs +8 -0
- package/src/cli/spawn-command.mjs +47 -0
- package/src/cli/spawn-command.test.mjs +64 -0
- 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/tokens.mjs +46 -3
- package/src/cli/tokens.test.mjs +103 -3
- package/src/cli/tools.mjs +49 -0
- package/src/cli/tools.test.mjs +89 -0
- package/src/cli/transcript-usage.mjs +27 -0
- package/src/cli/transcript-usage.test.mjs +34 -0
- package/src/cli/user-config-package.mjs +1 -1
- package/src/cli/user-config-toml.mjs +63 -7
- package/src/cli/user-config.mjs +39 -7
- package/src/cli/user-config.test.mjs +238 -5
- package/src/cli/watch-arm.mjs +39 -0
- package/src/cli/watch-arm.test.mjs +87 -0
- package/src/cli/watch.mjs +80 -35
- package/src/cli/watch.test.mjs +233 -27
- package/src/cli/work-order-guard.mjs +2 -1
- package/src/cli/workflow-hooks.test.mjs +18 -4
- package/src/cli/workflow-settings.mjs +44 -8
- package/src/cli/workflow-settings.test.mjs +124 -1
- package/src/cli/worktree.mjs +14 -1
- package/src/cli/worktree.test.mjs +20 -1
- package/src/config.mjs +174 -7
- package/src/config.test.mjs +327 -5
- package/src/consumer-package.mjs +31 -0
- package/src/consumer-package.test.mjs +54 -0
- package/src/descriptions.mjs +2 -0
- package/src/eslint/index.mjs +12 -0
- package/src/eslint/jsx.mjs +20 -0
- package/src/eslint/preset.mjs +26 -2
- package/src/eslint/preset.test.mjs +104 -2
- 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/timeless-comment.mjs +92 -0
- package/src/eslint/rules.test.mjs +189 -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/plain-language.mjs +396 -0
- package/src/gates/plain-language.test.mjs +210 -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 +53 -0
- package/src/plugin.test.mjs +3 -2
- 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/templates/docs/enforcement.md +12 -2
- package/templates/docs/ui.md +33 -0
- package/templates/githooks/pre-commit +1 -0
- package/templates/githooks/pre-push +11 -2
- package/templates/github/workflows/ci.yml +57 -3
- package/user-config/claude/CLAUDE.core.md +28 -0
- package/user-config/claude/settings.shared.json +41 -1
- package/src/cli/screens-discovery.mjs +0 -60
- package/src/cli/screens.mjs +0 -84
- package/src/cli/stack.mjs +0 -14
- package/src/cli/throwaway-db.mjs +0 -127
- package/src/cli/throwaway-db.test.mjs +0 -83
- package/src/screens/auth-context.test.mjs +0 -41
- package/src/screens/auth-run.test.mjs +0 -147
- package/src/screens/auth.mjs +0 -223
- package/src/screens/auth.test.mjs +0 -76
- package/src/screens/capture-idle.test.mjs +0 -27
- package/src/screens/capture.browser-test.mjs +0 -73
- package/src/screens/capture.mjs +0 -175
- package/src/screens/capture.test.mjs +0 -28
- package/src/screens/catalog.browser-test.mjs +0 -32
- package/src/screens/catalog.mjs +0 -72
- package/src/screens/catalog.test.mjs +0 -36
- package/src/screens/chrome.mjs +0 -21
- package/src/screens/compare.mjs +0 -40
- package/src/screens/compare.test.mjs +0 -30
- package/src/screens/discovery.browser-test.mjs +0 -29
- package/src/screens/discovery.mjs +0 -158
- package/src/screens/discovery.test.mjs +0 -27
- package/src/screens/inventory.mjs +0 -69
- package/src/screens/inventory.test.mjs +0 -10
- package/src/screens/map.mjs +0 -63
- package/src/screens/map.test.mjs +0 -35
- package/src/screens/open.browser-test.mjs +0 -50
- package/src/screens/regions.mjs +0 -137
- package/src/screens/regions.test.mjs +0 -38
- package/src/screens/session-files.mjs +0 -39
- package/src/screens/session-files.test.mjs +0 -39
- package/src/screens/setup.browser-test.mjs +0 -49
- package/src/screens/setup.mjs +0 -78
- package/src/screens/stack-auth.browser-test.mjs +0 -30
- package/src/screens/stack-auth.mjs +0 -106
- package/src/screens/stack-auth.test.mjs +0 -65
- package/src/screens/write-guard.mjs +0 -26
- package/src/stack/stack.mjs +0 -131
- package/src/stack/stack.test.mjs +0 -40
- package/src/stack/supervisor.mjs +0 -30
|
@@ -4,7 +4,7 @@ import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpath
|
|
|
4
4
|
import os from "node:os";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { test } from "node:test";
|
|
7
|
-
import { integrationBranch, runIntegrate } from "./integrate.mjs";
|
|
7
|
+
import { integrationBranch, runIntegrate, USAGE } from "./integrate.mjs";
|
|
8
8
|
|
|
9
9
|
const git = (cwd, ...args) => execFileSync("git", args, { cwd, stdio: "pipe", encoding: "utf8" }).trim();
|
|
10
10
|
const quiet = (lines) => (line) => lines.push(line);
|
|
@@ -34,6 +34,18 @@ function batch(t) {
|
|
|
34
34
|
return dir;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
function batchWithOrigin(t) {
|
|
38
|
+
const dir = batch(t);
|
|
39
|
+
const origin = realpathSync.native(mkdtempSync(path.join(os.tmpdir(), "qc-integrate-origin-")));
|
|
40
|
+
t.after(() => rmSync(origin, { recursive: true, force: true }));
|
|
41
|
+
git(origin, "init", "-q", "--bare");
|
|
42
|
+
git(dir, "remote", "add", "origin", origin);
|
|
43
|
+
git(dir, "switch", "-q", "-c", "feat/3-c", "main");
|
|
44
|
+
commitFile(dir, "db/0002_c.sql", "select 'c';\n");
|
|
45
|
+
git(dir, "switch", "-q", "main");
|
|
46
|
+
return dir;
|
|
47
|
+
}
|
|
48
|
+
|
|
37
49
|
const config = (dir, command = "node gen.mjs") => ({
|
|
38
50
|
root: dir,
|
|
39
51
|
paths: { migrations: "db" },
|
|
@@ -42,6 +54,285 @@ const config = (dir, command = "node gen.mjs") => ({
|
|
|
42
54
|
worktree: { base: "main" },
|
|
43
55
|
});
|
|
44
56
|
|
|
57
|
+
function pullRequestIo(dir, { view = null, create = " https://github.com/example/repo/pull/9\n" } = {}) {
|
|
58
|
+
const events = [];
|
|
59
|
+
return {
|
|
60
|
+
events,
|
|
61
|
+
say: quiet(events),
|
|
62
|
+
run,
|
|
63
|
+
gh(args, { cwd }) {
|
|
64
|
+
assert.equal(cwd, dir);
|
|
65
|
+
events.push(args);
|
|
66
|
+
return args[1] === "view" ? view : create;
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const pullRequestCalls = [
|
|
72
|
+
["pr", "view", "feat/7-integration", "--json", "number"],
|
|
73
|
+
["pr", "create", "--draft", "--head", "feat/7-integration", "--base", "main", "--title", "feat: integrate the batch for #7", "--body", "Refs #7\n\nWritten by an AI agent with architecture-kit."],
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
for (const aiLabel of [undefined, true, false]) {
|
|
77
|
+
test(`--pr applies the public body attribution setting ${aiLabel}`, async (t) => {
|
|
78
|
+
const dir = batchWithOrigin(t);
|
|
79
|
+
const settings = config(dir, null);
|
|
80
|
+
if (aiLabel !== undefined) settings.post = { aiLabel };
|
|
81
|
+
const io = pullRequestIo(dir);
|
|
82
|
+
assert.equal(await runIntegrate(settings, ["--issue", "7", "--pr", "feat/1-a"], io), 0);
|
|
83
|
+
const create = io.events.find((event) => Array.isArray(event) && event[1] === "create");
|
|
84
|
+
assert.equal(create[create.indexOf("--title") + 1], "feat: integrate the batch for #7");
|
|
85
|
+
assert.equal(create[create.indexOf("--body") + 1], aiLabel === false
|
|
86
|
+
? "Refs #7"
|
|
87
|
+
: "Refs #7\n\nWritten by an AI agent with architecture-kit.");
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
test("an operator pause refuses integration before any branch changes", async (t) => {
|
|
92
|
+
const dir = batch(t);
|
|
93
|
+
const before = git(dir, "rev-parse", "HEAD");
|
|
94
|
+
mkdirSync(path.join(dir, ".git", "qc"));
|
|
95
|
+
writeFileSync(path.join(dir, ".git", "qc", "pause"), "inspect the batch\n");
|
|
96
|
+
const lines = [];
|
|
97
|
+
assert.equal(await runIntegrate(config(dir), ["--issue", "7", "feat/1-a"], {
|
|
98
|
+
say: quiet(lines),
|
|
99
|
+
run: () => assert.fail("the generator must stay idle"),
|
|
100
|
+
gh: () => assert.fail("GitHub must stay idle"),
|
|
101
|
+
}), 5);
|
|
102
|
+
assert.match(lines.join("\n"), /inspect the batch.*qc resume/);
|
|
103
|
+
assert.match(lines.join("\n"), /An operator paused the kit: inspect the batch\. Wait for the operator to run `qc resume`\./);
|
|
104
|
+
assert.equal(git(dir, "branch", "--show-current"), "main");
|
|
105
|
+
assert.equal(git(dir, "rev-parse", "HEAD"), before);
|
|
106
|
+
assert.equal(git(dir, "branch", "--list", "feat/7-integration"), "");
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("integrate usage states the effective author rule", () => {
|
|
110
|
+
assert.match(USAGE, /refuses.*branch.*author email.*effective Git author email/i);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("integrate usage documents exit 5 for an operator pause", () => {
|
|
114
|
+
assert.match(USAGE, /exit 5.*operator pause/);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
function authorEnvironment(t, values) {
|
|
118
|
+
for (const [key, value] of Object.entries(values)) {
|
|
119
|
+
const previous = process.env[key];
|
|
120
|
+
process.env[key] = value;
|
|
121
|
+
t.after(() => {
|
|
122
|
+
if (previous === undefined) delete process.env[key];
|
|
123
|
+
else process.env[key] = previous;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
for (const setting of ["different", "absent local"]) {
|
|
129
|
+
test(`integrate uses GIT_AUTHOR_EMAIL with ${setting} user.email`, async (t) => {
|
|
130
|
+
const dir = batch(t);
|
|
131
|
+
if (setting === "different") git(dir, "config", "user.email", "other@example.com");
|
|
132
|
+
else git(dir, "config", "--unset", "user.email");
|
|
133
|
+
authorEnvironment(t, {
|
|
134
|
+
GIT_AUTHOR_NAME: "qc",
|
|
135
|
+
GIT_AUTHOR_EMAIL: "qc@example.com",
|
|
136
|
+
GIT_COMMITTER_NAME: "qc",
|
|
137
|
+
GIT_COMMITTER_EMAIL: "qc@example.com",
|
|
138
|
+
});
|
|
139
|
+
const errors = [];
|
|
140
|
+
t.mock.method(console, "error", quiet(errors));
|
|
141
|
+
assert.equal(await runIntegrate(config(dir, null), ["--issue", "7", "feat/1-a"], { say: () => {}, run }), 0, errors.join("\n"));
|
|
142
|
+
git(dir, "merge-base", "--is-ancestor", "feat/1-a", "HEAD");
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
test("integrate rejects a branch whose authors differ from GIT_AUTHOR_EMAIL", async (t) => {
|
|
147
|
+
const dir = batch(t);
|
|
148
|
+
authorEnvironment(t, { GIT_AUTHOR_NAME: "other", GIT_AUTHOR_EMAIL: "other@example.com" });
|
|
149
|
+
const errors = [];
|
|
150
|
+
t.mock.method(console, "error", quiet(errors));
|
|
151
|
+
assert.equal(await runIntegrate(config(dir, null), ["--issue", "7", "feat/1-a"], { say: () => {}, run }), 1);
|
|
152
|
+
assert.match(errors.join("\n"), /feat\/1-a.*other@example\.com.*qc@example\.com/);
|
|
153
|
+
assert.throws(() => git(dir, "merge-base", "--is-ancestor", "feat/1-a", "HEAD"));
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
for (const exists of [false, true]) {
|
|
157
|
+
test(`an invalid author identity stops before switching to an ${exists ? "existing" : "absent"} integration branch`, async (t) => {
|
|
158
|
+
const dir = batch(t);
|
|
159
|
+
if (exists) git(dir, "branch", "feat/7-integration", "main");
|
|
160
|
+
const before = git(dir, "rev-parse", "HEAD");
|
|
161
|
+
authorEnvironment(t, { GIT_AUTHOR_NAME: "", GIT_AUTHOR_EMAIL: "" });
|
|
162
|
+
const errors = [];
|
|
163
|
+
t.mock.method(console, "error", quiet(errors));
|
|
164
|
+
assert.equal(await runIntegrate(config(dir, null), ["--issue", "7", "feat/1-a"], { say: () => {}, run }), 1);
|
|
165
|
+
assert.match(errors.join("\n"), /git var GIT_AUTHOR_IDENT/);
|
|
166
|
+
assert.equal(git(dir, "branch", "--show-current"), "main");
|
|
167
|
+
assert.equal(git(dir, "rev-parse", "HEAD"), before);
|
|
168
|
+
assert.equal(git(dir, "status", "--porcelain"), "");
|
|
169
|
+
if (!exists) assert.throws(() => git(dir, "show-ref", "--verify", "refs/heads/feat/7-integration"));
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
for (const [committerName, exists] of [["", false], ["", true], ["qc", false], ["qc", true]]) {
|
|
174
|
+
test(`an invalid committer identity (${committerName || "empty name"}) stops before fetching or switching to an ${exists ? "existing" : "absent"} integration branch`, async (t) => {
|
|
175
|
+
const dir = batchWithOrigin(t);
|
|
176
|
+
if (exists) git(dir, "branch", "feat/7-integration", "main");
|
|
177
|
+
const before = git(dir, "rev-parse", "HEAD");
|
|
178
|
+
authorEnvironment(t, {
|
|
179
|
+
GIT_AUTHOR_NAME: "qc",
|
|
180
|
+
GIT_AUTHOR_EMAIL: "qc@example.com",
|
|
181
|
+
GIT_COMMITTER_NAME: committerName,
|
|
182
|
+
GIT_COMMITTER_EMAIL: "",
|
|
183
|
+
});
|
|
184
|
+
const errors = [];
|
|
185
|
+
t.mock.method(console, "error", quiet(errors));
|
|
186
|
+
assert.equal(await runIntegrate(config(dir, null), ["--issue", "7", "feat/1-a"], { say: () => {}, run }), 1);
|
|
187
|
+
assert.match(errors.join("\n"), /git var GIT_COMMITTER_IDENT/);
|
|
188
|
+
if (committerName) assert.match(errors.join("\n"), /no committer email/);
|
|
189
|
+
assert.equal(existsSync(path.join(dir, ".git", "FETCH_HEAD")), false);
|
|
190
|
+
assert.equal(git(dir, "branch", "--show-current"), "main");
|
|
191
|
+
assert.equal(git(dir, "rev-parse", "HEAD"), before);
|
|
192
|
+
assert.equal(git(dir, "status", "--porcelain"), "");
|
|
193
|
+
if (!exists) assert.throws(() => git(dir, "show-ref", "--verify", "refs/heads/feat/7-integration"));
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
test("--pr opens a draft pull request and strips origin from the base", async (t) => {
|
|
198
|
+
const dir = batchWithOrigin(t);
|
|
199
|
+
git(dir, "push", "origin", "main");
|
|
200
|
+
const io = pullRequestIo(dir);
|
|
201
|
+
const argv = ["--pr", "--issue", "7", "--from", "origin/main", "feat/1-a", "feat/2-b"];
|
|
202
|
+
assert.equal(await runIntegrate(config(dir), argv, io), 0);
|
|
203
|
+
assert.deepEqual(io.events.filter(Array.isArray), pullRequestCalls);
|
|
204
|
+
assert.ok(io.events.includes("pr https://github.com/example/repo/pull/9"));
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test("--pr strips another remote from the base", async (t) => {
|
|
208
|
+
const dir = batchWithOrigin(t);
|
|
209
|
+
git(dir, "remote", "add", "upstream", git(dir, "remote", "get-url", "origin"));
|
|
210
|
+
git(dir, "push", "origin", "main");
|
|
211
|
+
git(dir, "fetch", "upstream");
|
|
212
|
+
const io = pullRequestIo(dir);
|
|
213
|
+
assert.equal(await runIntegrate(config(dir), ["--pr", "--issue", "7", "--from", "upstream/main", "feat/1-a"], io), 0);
|
|
214
|
+
assert.deepEqual(io.events.filter(Array.isArray), pullRequestCalls);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test("--pr from a sha uses integrate.base or main", async (t) => {
|
|
218
|
+
for (const base of [undefined, "origin/release"]) {
|
|
219
|
+
await t.test(String(base), async (t) => {
|
|
220
|
+
const dir = batchWithOrigin(t);
|
|
221
|
+
git(dir, "branch", "release", "main");
|
|
222
|
+
git(dir, "push", "origin", "release");
|
|
223
|
+
const settings = { ...config(dir), integrate: { base } };
|
|
224
|
+
const io = pullRequestIo(dir);
|
|
225
|
+
assert.equal(await runIntegrate(settings, ["--pr", "--issue", "7", "--from", git(dir, "rev-parse", "main"), "feat/1-a"], io), 0);
|
|
226
|
+
const calls = structuredClone(pullRequestCalls);
|
|
227
|
+
calls[1][calls[1].indexOf("--base") + 1] = base ? "release" : "main";
|
|
228
|
+
assert.deepEqual(io.events.filter(Array.isArray), calls);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test("--pr rejects a base that is not a branch before any gh call", async (t) => {
|
|
234
|
+
for (const base of ["HEAD~1", "HEAD", "v1", "bad..branch", "sha"]) {
|
|
235
|
+
await t.test(base, async (t) => {
|
|
236
|
+
const dir = batchWithOrigin(t);
|
|
237
|
+
git(dir, "tag", "v1", "main");
|
|
238
|
+
const settings = { ...config(dir), integrate: { base: base === "sha" ? git(dir, "rev-parse", "main") : base } };
|
|
239
|
+
const errors = [];
|
|
240
|
+
t.mock.method(console, "error", quiet(errors));
|
|
241
|
+
const io = pullRequestIo(dir);
|
|
242
|
+
const before = git(dir, "rev-parse", "HEAD");
|
|
243
|
+
assert.equal(await runIntegrate(settings, ["--pr", "--issue", "7", "--from", git(dir, "rev-parse", "main"), "feat/1-a"], io), 1);
|
|
244
|
+
assert.match(errors.join("\n"), /base.*branch/i);
|
|
245
|
+
assert.deepEqual(io.events, []);
|
|
246
|
+
assert.equal(git(dir, "rev-parse", "HEAD"), before);
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test("integrate refuses every other author before merging that branch", async (t) => {
|
|
252
|
+
const dir = batch(t);
|
|
253
|
+
git(dir, "switch", "-q", "feat/2-b");
|
|
254
|
+
for (const email of ["first@example.com", "second@example.com"]) {
|
|
255
|
+
git(dir, "config", "user.email", email);
|
|
256
|
+
commitFile(dir, `${email}.txt`, `${email}\n`);
|
|
257
|
+
}
|
|
258
|
+
git(dir, "config", "user.email", "qc@example.com");
|
|
259
|
+
git(dir, "switch", "-q", "main");
|
|
260
|
+
const errors = [];
|
|
261
|
+
t.mock.method(console, "error", quiet(errors));
|
|
262
|
+
assert.equal(await runIntegrate(config(dir, null), ["--issue", "7", "--from", "main", "feat/1-a", "feat/2-b"], { say: () => {}, run }), 1);
|
|
263
|
+
for (const value of ["feat/2-b", "first@example.com", "second@example.com"]) assert.ok(errors.join("\n").includes(value));
|
|
264
|
+
git(dir, "merge-base", "--is-ancestor", "feat/1-a", "HEAD");
|
|
265
|
+
assert.throws(() => git(dir, "merge-base", "--is-ancestor", "feat/2-b", "HEAD"));
|
|
266
|
+
assert.equal(existsSync(path.join(dir, "first@example.com.txt")), false);
|
|
267
|
+
assert.equal(git(dir, "status", "--porcelain"), "");
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test("--pr reports an existing pull request without creating another", async (t) => {
|
|
271
|
+
const dir = batchWithOrigin(t);
|
|
272
|
+
const io = pullRequestIo(dir, { view: '{"number":9}' });
|
|
273
|
+
assert.equal(await runIntegrate(config(dir), ["--pr", "--issue", "7", "--from", "main", "feat/1-a"], io), 0);
|
|
274
|
+
assert.deepEqual(io.events.filter(Array.isArray), [pullRequestCalls[0]]);
|
|
275
|
+
assert.ok(io.events.includes("pr exists"));
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
test("integrate without --pr never calls gh", async (t) => {
|
|
279
|
+
const dir = batchWithOrigin(t);
|
|
280
|
+
const io = pullRequestIo(dir);
|
|
281
|
+
assert.equal(await runIntegrate(config(dir), ["--issue", "7", "--from", "main", "feat/1-a"], io), 0);
|
|
282
|
+
assert.deepEqual(io.events.filter(Array.isArray), []);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
test("--pr needs a pushed branch before any merge", async (t) => {
|
|
286
|
+
for (const reason of ["push disabled", "origin absent"]) {
|
|
287
|
+
await t.test(reason, async (t) => {
|
|
288
|
+
const dir = reason === "push disabled" ? batchWithOrigin(t) : batch(t);
|
|
289
|
+
const settings = { ...config(dir), integrate: { push: reason !== "push disabled" } };
|
|
290
|
+
const before = git(dir, "rev-parse", "HEAD");
|
|
291
|
+
const errors = [];
|
|
292
|
+
t.mock.method(console, "error", quiet(errors));
|
|
293
|
+
const io = pullRequestIo(dir);
|
|
294
|
+
assert.equal(await runIntegrate(settings, ["--pr", "--issue", "7", "--from", "main", "feat/1-a"], io), 1);
|
|
295
|
+
assert.match(errors.join("\n"), /pull request needs a pushed branch/i);
|
|
296
|
+
assert.equal(git(dir, "rev-parse", "HEAD"), before);
|
|
297
|
+
assert.equal(git(dir, "branch", "--show-current"), "main");
|
|
298
|
+
assert.deepEqual(io.events, []);
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test("--pr creates the pull request before the second cadence push", async (t) => {
|
|
304
|
+
const dir = batchWithOrigin(t);
|
|
305
|
+
const io = pullRequestIo(dir);
|
|
306
|
+
const settings = { ...config(dir), integrate: { ciEvery: 2 } };
|
|
307
|
+
const argv = ["--pr", "--issue", "7", "--from", "main", "feat/1-a", "feat/2-b", "feat/3-c"];
|
|
308
|
+
assert.equal(await runIntegrate(settings, argv, io), 0);
|
|
309
|
+
assert.deepEqual(io.events.filter(Array.isArray), pullRequestCalls);
|
|
310
|
+
const pushes = io.events.flatMap((event, i) => typeof event === "string" && event.startsWith("push") ? [i] : []);
|
|
311
|
+
assert.equal(pushes.length, 2);
|
|
312
|
+
const created = io.events.findIndex((event) => Array.isArray(event) && event[1] === "create");
|
|
313
|
+
assert.ok(pushes[0] < created && created < pushes[1]);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
test("--pr reports gh pr create when creation fails", async (t) => {
|
|
317
|
+
const dir = batchWithOrigin(t);
|
|
318
|
+
const io = pullRequestIo(dir, { create: null });
|
|
319
|
+
const errors = [];
|
|
320
|
+
t.mock.method(console, "error", quiet(errors));
|
|
321
|
+
assert.equal(await runIntegrate(config(dir), ["--pr", "--issue", "7", "--from", "main", "feat/1-a"], io), 1);
|
|
322
|
+
assert.match(errors.join("\n"), /gh pr create/);
|
|
323
|
+
assert.deepEqual(io.events.filter(Array.isArray), pullRequestCalls);
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
test("--pr opens the pull request for an existing remote branch without another push", async (t) => {
|
|
327
|
+
const dir = batchWithOrigin(t);
|
|
328
|
+
const argv = ["--issue", "7", "--from", "main", "feat/1-a"];
|
|
329
|
+
assert.equal(await runIntegrate(config(dir), argv, { say: () => {}, run }), 0);
|
|
330
|
+
const io = pullRequestIo(dir);
|
|
331
|
+
assert.equal(await runIntegrate(config(dir), ["--pr", ...argv], io), 0);
|
|
332
|
+
assert.deepEqual(io.events.filter(Array.isArray), pullRequestCalls);
|
|
333
|
+
assert.equal(io.events.filter((event) => typeof event === "string" && event.startsWith("push")).length, 0);
|
|
334
|
+
});
|
|
335
|
+
|
|
45
336
|
test("the integration branch names its issue, and an issue that is no number is refused", () => {
|
|
46
337
|
assert.equal(integrationBranch({ issue: "7" }), "feat/7-integration");
|
|
47
338
|
assert.equal(integrationBranch({ issue: "7", type: "fix", slug: "Desktop Round" }), "fix/7-desktop-round");
|
|
@@ -57,6 +348,61 @@ test("integrate merges each branch in order and renumbers the later branch's mig
|
|
|
57
348
|
assert.deepEqual(readdirSync(path.join(dir, "db")).sort(), ["0001_init.sql", "0002_a.sql", "0003_b.sql"]);
|
|
58
349
|
assert.equal(readFileSync(path.join(dir, "out.generated.txt"), "utf8"), "regenerated\n");
|
|
59
350
|
assert.equal(git(dir, "status", "--porcelain"), "");
|
|
351
|
+
assert.equal(said.filter((line) => line.startsWith("push")).length, 0);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
test("integrate pushes every two merges and pushes the remaining merge", async (t) => {
|
|
355
|
+
const dir = batchWithOrigin(t);
|
|
356
|
+
const said = [];
|
|
357
|
+
const settings = { ...config(dir), integrate: { ciEvery: 2 } };
|
|
358
|
+
const argv = ["--issue", "7", "--from", "main", "feat/1-a", "feat/2-b", "feat/3-c"];
|
|
359
|
+
assert.equal(await runIntegrate(settings, argv, { say: quiet(said), run }), 0, said.join("\n"));
|
|
360
|
+
assert.equal(said.filter((line) => line.startsWith("push")).length, 2);
|
|
361
|
+
assert.equal(git(dir, "ls-remote", "origin", "refs/heads/feat/7-integration").split(/\s+/)[0], git(dir, "rev-parse", "HEAD"));
|
|
362
|
+
assert.ok(!said.find((line) => line.startsWith("OK")).includes("Push it:"));
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
test("integrate pushes once for three merges at a cadence of three", async (t) => {
|
|
366
|
+
const dir = batchWithOrigin(t);
|
|
367
|
+
const said = [];
|
|
368
|
+
const settings = { ...config(dir), integrate: { ciEvery: 3 } };
|
|
369
|
+
assert.equal(await runIntegrate(settings, ["--issue", "7", "--from", "main", "feat/1-a", "feat/2-b", "feat/3-c"], { say: quiet(said), run }), 0, said.join("\n"));
|
|
370
|
+
assert.equal(said.filter((line) => line.startsWith("push")).length, 1);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
test("integrate can disable pushes and shows the manual push command", async (t) => {
|
|
374
|
+
const dir = batchWithOrigin(t);
|
|
375
|
+
const said = [];
|
|
376
|
+
const settings = { ...config(dir), integrate: { push: false } };
|
|
377
|
+
assert.equal(await runIntegrate(settings, ["--issue", "7", "--from", "main", "feat/1-a", "feat/2-b", "feat/3-c"], { say: quiet(said), run }), 0, said.join("\n"));
|
|
378
|
+
assert.equal(said.filter((line) => line.startsWith("push")).length, 0);
|
|
379
|
+
assert.match(said.find((line) => line.startsWith("OK")), /Push it: git push -u origin feat\/7-integration$/);
|
|
380
|
+
assert.equal(git(dir, "ls-remote", "origin", "refs/heads/feat/7-integration"), "");
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
test("integrate skips pushes on a second run with nothing new", async (t) => {
|
|
384
|
+
const dir = batchWithOrigin(t);
|
|
385
|
+
const settings = config(dir);
|
|
386
|
+
const argv = ["--issue", "7", "--from", "main", "feat/1-a", "feat/2-b", "feat/3-c"];
|
|
387
|
+
const first = [];
|
|
388
|
+
assert.equal(await runIntegrate(settings, argv, { say: quiet(first), run }), 0, first.join("\n"));
|
|
389
|
+
assert.equal(first.filter((line) => line.startsWith("push")).length, 1);
|
|
390
|
+
const said = [];
|
|
391
|
+
assert.equal(await runIntegrate(settings, argv, { say: quiet(said), run }), 0, said.join("\n"));
|
|
392
|
+
assert.equal(said.filter((line) => line.startsWith("push")).length, 0);
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
test("a failed push reports git push and keeps the local merges", async (t) => {
|
|
396
|
+
const dir = batchWithOrigin(t);
|
|
397
|
+
git(dir, "remote", "set-url", "origin", path.join(dir, "missing-origin.git"));
|
|
398
|
+
const said = [];
|
|
399
|
+
const errors = [];
|
|
400
|
+
t.mock.method(console, "error", quiet(errors));
|
|
401
|
+
assert.equal(await runIntegrate(config(dir), ["--issue", "7", "--from", "main", "feat/1-a", "feat/2-b", "feat/3-c"], { say: quiet(said), run }), 1);
|
|
402
|
+
assert.match(errors.join("\n"), /git push/);
|
|
403
|
+
assert.equal(git(dir, "branch", "--show-current"), "feat/7-integration");
|
|
404
|
+
for (const branch of ["feat/1-a", "feat/2-b", "feat/3-c"]) git(dir, "merge-base", "--is-ancestor", branch, "HEAD");
|
|
405
|
+
assert.equal(git(dir, "status", "--porcelain"), "");
|
|
60
406
|
});
|
|
61
407
|
|
|
62
408
|
test("a conflict stops the run with the file list, and a second run after the resolution continues", async (t) => {
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { defaults, merge } from "../config.mjs";
|
|
2
|
+
import { globMatcher } from "../glob.mjs";
|
|
3
|
+
import { configAtBase, gitBy, gitFailed, LANE_BUDGET_MS } from "./direct-lane.mjs";
|
|
4
|
+
import { decidingVerdictFor, shaMatches } from "./ledger.mjs";
|
|
5
|
+
import { checkMergeTrees } from "./integrate-tree.mjs";
|
|
6
|
+
|
|
7
|
+
export const REGENERATE_SUBJECT = "chore: regenerate the generated files";
|
|
8
|
+
|
|
9
|
+
/** The integration review pipeline checks scoped verdicts and the commits their heads cover. */
|
|
10
|
+
export function integrationLane({ root, baseOid, headBranch, sha, records, kinds, budgetMs = LANE_BUDGET_MS }) {
|
|
11
|
+
const git = gitBy(budgetMs);
|
|
12
|
+
const policy = configAtBase(root, baseOid, git, "the PR base");
|
|
13
|
+
if (policy.problem) return { applies: false };
|
|
14
|
+
const settings = merge(defaults.integrate, policy.config?.integrate ?? {});
|
|
15
|
+
if (settings.review !== true || !new RegExp(settings.branchPattern).test(headBranch)) return { applies: false };
|
|
16
|
+
|
|
17
|
+
const failure = (what) => ({ applies: true, problem: gitFailed(git, what) });
|
|
18
|
+
const historyText = git(root, "log", "--format=%H", sha, "--not", baseOid);
|
|
19
|
+
if (historyText === null) return failure("git cannot read the integration history");
|
|
20
|
+
const history = historyText.split("\n").filter(Boolean);
|
|
21
|
+
const scopes = new Set(records.filter((record) => record.type === "dispatch" && record.branch === headBranch && typeof record.scope === "string").map((record) => record.scope));
|
|
22
|
+
const newest = new Map();
|
|
23
|
+
for (const record of records) {
|
|
24
|
+
if (record.type === "verdict" && kinds.includes(record.kind) && history.some((commit) => shaMatches(record.sha, commit))) newest.set(record.scope ?? null, record);
|
|
25
|
+
}
|
|
26
|
+
for (const scope of scopes) {
|
|
27
|
+
if (!newest.has(scope)) return { applies: true, problem: `scope ${JSON.stringify(scope)} holds no APPROVED review (no verdict)` };
|
|
28
|
+
}
|
|
29
|
+
for (const [scope, record] of newest) {
|
|
30
|
+
if (record.verdict !== "APPROVED") return { applies: true, problem: `scope ${JSON.stringify(scope)} holds no APPROVED review (${record.verdict})` };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const heads = history.filter((commit) => decidingVerdictFor(records, commit, kinds)?.verdict === "APPROVED");
|
|
34
|
+
if (heads.length === 0) return { applies: true, problem: "the integration history holds no APPROVED review" };
|
|
35
|
+
const uncovered = git(root, "log", "--no-merges", "--format=%H%x09%s", sha, "--not", baseOid, ...heads);
|
|
36
|
+
if (uncovered === null) return failure("git cannot read the commits after the integration reviews");
|
|
37
|
+
const commits = uncovered.split("\n").filter(Boolean).map((line) => {
|
|
38
|
+
const tab = line.indexOf("\t");
|
|
39
|
+
return { sha: line.slice(0, tab), subject: line.slice(tab + 1) };
|
|
40
|
+
});
|
|
41
|
+
const generated = globMatcher(policy.config?.generated?.globs ?? defaults.generated.globs);
|
|
42
|
+
const needsReview = [];
|
|
43
|
+
for (const commit of commits) {
|
|
44
|
+
if (commit.subject === REGENERATE_SUBJECT) {
|
|
45
|
+
// Raw metadata protects path whitespace from the Git reader's trim; paths occupy odd fields.
|
|
46
|
+
const files = git(root, "diff-tree", "--root", "-r", "--no-commit-id", "--raw", "-z", "--no-renames", commit.sha);
|
|
47
|
+
if (files === null) return failure(`git cannot read regenerate commit ${commit.sha.slice(0, 7)}`);
|
|
48
|
+
if (files.split("\0").filter((_, index) => index % 2 === 1).every(generated)) continue;
|
|
49
|
+
}
|
|
50
|
+
needsReview.push(commit);
|
|
51
|
+
}
|
|
52
|
+
if (needsReview.length > 0) {
|
|
53
|
+
const first = needsReview[0];
|
|
54
|
+
return { applies: true, problem: `${needsReview.length} commit(s) hold no APPROVED review, such as ${first.sha.slice(0, 7)} "${first.subject}"` };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const merges = git(root, "log", "--merges", "--format=%H", sha, "--not", baseOid, ...heads);
|
|
58
|
+
if (merges === null) return failure("git cannot read the merges after the integration reviews");
|
|
59
|
+
const problem = checkMergeTrees(root, merges.split("\n").filter(Boolean).reverse(), merge(defaults, policy.config ?? {}), git);
|
|
60
|
+
if (problem) return { applies: true, problem };
|
|
61
|
+
return { applies: true, problem: null, heads: heads.length };
|
|
62
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { execFileSync } from "node:child_process";
|
|
4
|
+
import { mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { integrationLane, REGENERATE_SUBJECT } from "./integration-lane.mjs";
|
|
8
|
+
import { mergeVerdict } from "./merge-guard.mjs";
|
|
9
|
+
|
|
10
|
+
function integrationRepo(t, { config = { generated: { globs: ["generated.txt"] } }, conflict = false } = {}) {
|
|
11
|
+
const root = realpathSync.native(mkdtempSync(path.join(tmpdir(), "qc-integration-lane-")));
|
|
12
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
13
|
+
const git = (...args) => execFileSync("git", args, { cwd: root, stdio: "pipe", encoding: "utf8" }).trim();
|
|
14
|
+
const commit = (file, content, subject) => {
|
|
15
|
+
writeFileSync(path.join(root, file), content);
|
|
16
|
+
git("add", file);
|
|
17
|
+
git("commit", "-q", "-m", subject);
|
|
18
|
+
return git("rev-parse", "HEAD");
|
|
19
|
+
};
|
|
20
|
+
git("init", "-q", "-b", "main");
|
|
21
|
+
for (const [key, value] of [["user.name", "qc"], ["user.email", "qc@example.com"], ["commit.gpgsign", "false"]]) git("config", key, value);
|
|
22
|
+
writeFileSync(path.join(root, "qc.config.json"), JSON.stringify(config));
|
|
23
|
+
git("add", "qc.config.json");
|
|
24
|
+
const baseOid = commit("shared.txt", "base\n", "base");
|
|
25
|
+
git("switch", "-q", "-c", "feat/7-integration");
|
|
26
|
+
const taskHeads = [];
|
|
27
|
+
const mergeHeads = [];
|
|
28
|
+
for (const feature of ["api", "ui"]) {
|
|
29
|
+
git("switch", "-q", "-c", `task/7-${feature}`, baseOid);
|
|
30
|
+
taskHeads.push(commit(conflict ? "shared.txt" : `${feature}.txt`, `${feature}\n`, `add ${feature} feature`));
|
|
31
|
+
git("switch", "-q", "feat/7-integration");
|
|
32
|
+
const merge = () => git("merge", "--no-ff", "-m", `merge ${feature}`, `task/7-${feature}`);
|
|
33
|
+
if (conflict && feature === "ui") {
|
|
34
|
+
assert.throws(merge);
|
|
35
|
+
commit("shared.txt", "api and ui\n", "resolve feature conflict");
|
|
36
|
+
assert.notEqual(git("diff-tree", "--cc", "-r", "--no-commit-id", "--name-only", "HEAD"), "");
|
|
37
|
+
} else {
|
|
38
|
+
merge();
|
|
39
|
+
}
|
|
40
|
+
mergeHeads.push(git("rev-parse", "HEAD"));
|
|
41
|
+
}
|
|
42
|
+
const sha = commit("generated.txt", "generated\n", REGENERATE_SUBJECT);
|
|
43
|
+
return { root, baseOid, headBranch: "feat/7-integration", sha, taskHeads, mergeHeads, git, commit };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const approved = (sha, scope, kind = "branch") => ({ type: "verdict", kind, verdict: "APPROVED", sha, scope });
|
|
47
|
+
const judge = (repo, records, options = {}) => integrationLane({ ...repo, records, kinds: ["branch"], ...options });
|
|
48
|
+
|
|
49
|
+
test("approved task heads cover clean merges and the regenerate commit", (t) => {
|
|
50
|
+
const repo = integrationRepo(t);
|
|
51
|
+
assert.equal(REGENERATE_SUBJECT, "chore: regenerate the generated files");
|
|
52
|
+
assert.deepEqual(judge(repo, repo.taskHeads.map((sha) => approved(sha))), { applies: true, problem: null, heads: 2 });
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("a task head without a review names its subject", (t) => {
|
|
56
|
+
const repo = integrationRepo(t);
|
|
57
|
+
const result = judge(repo, [approved(repo.taskHeads[0])]);
|
|
58
|
+
assert.equal(result.applies, true);
|
|
59
|
+
assert.match(result.problem, /1 commit\(s\) hold no APPROVED review/);
|
|
60
|
+
assert.ok(result.problem.includes(`${repo.taskHeads[1].slice(0, 7)} "add ui feature"`));
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("a fix after the last approved head needs a review", (t) => {
|
|
64
|
+
const repo = integrationRepo(t);
|
|
65
|
+
const sha = repo.commit("fix.txt", "fix\n", "fix the integrated API");
|
|
66
|
+
const result = judge(repo, repo.taskHeads.map((head) => approved(head)), { sha });
|
|
67
|
+
assert.match(result.problem, /hold no APPROVED review/);
|
|
68
|
+
assert.ok(result.problem.includes(`${sha.slice(0, 7)} "fix the integrated API"`));
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("a rejected scope blocks an approved later head in another scope", (t) => {
|
|
72
|
+
const repo = integrationRepo(t);
|
|
73
|
+
const records = [
|
|
74
|
+
approved(repo.taskHeads[0], "api"),
|
|
75
|
+
{ ...approved(repo.mergeHeads[0], "api"), verdict: "CHANGES_REQUIRED" },
|
|
76
|
+
approved(repo.sha, "ui"),
|
|
77
|
+
];
|
|
78
|
+
assert.match(judge(repo, records).problem, /scope "api"/);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("separate scopes can approve successive integration merge heads", (t) => {
|
|
82
|
+
const repo = integrationRepo(t);
|
|
83
|
+
const result = judge(repo, [approved(repo.mergeHeads[0], "a"), approved(repo.mergeHeads[1], "b")]);
|
|
84
|
+
assert.deepEqual(result, { applies: true, problem: null, heads: 2 });
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("the newest verdict of a scope supersedes its rejection", (t) => {
|
|
88
|
+
const repo = integrationRepo(t);
|
|
89
|
+
const records = [
|
|
90
|
+
{ ...approved(repo.taskHeads[0], "api"), verdict: "CHANGES_REQUIRED" },
|
|
91
|
+
approved(repo.sha, "api"),
|
|
92
|
+
];
|
|
93
|
+
assert.equal(judge(repo, records).problem, null);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("hand-resolved merges need an approved head at or after the merge", (t) => {
|
|
97
|
+
const repo = integrationRepo(t, { conflict: true });
|
|
98
|
+
const records = repo.taskHeads.map((sha) => approved(sha));
|
|
99
|
+
assert.match(judge(repo, records).problem, /hand-resolved/);
|
|
100
|
+
assert.ok(judge(repo, records).problem.includes(repo.mergeHeads[1].slice(0, 7)));
|
|
101
|
+
assert.equal(judge(repo, [...records, approved(repo.mergeHeads[1])]).problem, null);
|
|
102
|
+
assert.equal(judge(repo, [...records, approved(repo.sha)]).problem, null);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("other branches bypass the integration lane", (t) => {
|
|
106
|
+
const repo = integrationRepo(t);
|
|
107
|
+
assert.deepEqual(judge(repo, [], { headBranch: "feat/8-other" }), { applies: false });
|
|
108
|
+
assert.deepEqual(judge(repo, [], { headBranch: "fix/12-integration-tests" }), { applies: false });
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("the base configuration can disable integration reviews", (t) => {
|
|
112
|
+
const repo = integrationRepo(t, { config: { integrate: { review: false } } });
|
|
113
|
+
assert.deepEqual(judge(repo, []), { applies: false });
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("the base configuration controls the branch pattern", (t) => {
|
|
117
|
+
const repo = integrationRepo(t, { config: { integrate: { branchPattern: "^release/" } } });
|
|
118
|
+
assert.deepEqual(judge(repo, []), { applies: false });
|
|
119
|
+
assert.equal(judge(repo, [approved(repo.sha)], { headBranch: "release/7" }).problem, null);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("a lane with no approved verdict reports the missing review", (t) => {
|
|
123
|
+
const repo = integrationRepo(t);
|
|
124
|
+
assert.match(judge(repo, []).problem, /no APPROVED review/);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test("task verdicts count only when the caller includes their kind", (t) => {
|
|
128
|
+
const repo = integrationRepo(t);
|
|
129
|
+
const records = repo.taskHeads.map((sha) => approved(sha, undefined, "task"));
|
|
130
|
+
assert.match(judge(repo, records).problem, /no APPROVED review/);
|
|
131
|
+
assert.equal(judge(repo, records, { kinds: ["task"] }).problem, null);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test("verdicts outside the integration history and other kinds do not block", (t) => {
|
|
135
|
+
const repo = integrationRepo(t);
|
|
136
|
+
const records = [
|
|
137
|
+
...repo.taskHeads.map((sha) => approved(sha)),
|
|
138
|
+
{ ...approved(repo.baseOid, "api"), verdict: "CHANGES_REQUIRED" },
|
|
139
|
+
{ ...approved(repo.sha, "api", "task"), verdict: "CHANGES_REQUIRED" },
|
|
140
|
+
];
|
|
141
|
+
assert.equal(judge(repo, records).problem, null);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("an unreadable base policy bypasses the lane", (t) => {
|
|
145
|
+
const repo = integrationRepo(t);
|
|
146
|
+
assert.deepEqual(judge(repo, [], { baseOid: "invalid" }), { applies: false });
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test("a failed history read reports a git problem", (t) => {
|
|
150
|
+
const repo = integrationRepo(t);
|
|
151
|
+
const result = judge(repo, [], { sha: "invalid" });
|
|
152
|
+
assert.equal(result.applies, true);
|
|
153
|
+
assert.match(result.problem, /git cannot/);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test("a dispatched scope without a verdict does not block an approved head across head changes", (t) => {
|
|
157
|
+
const repo = integrationRepo(t);
|
|
158
|
+
const head = repo.mergeHeads[1];
|
|
159
|
+
const records = [
|
|
160
|
+
...["a", "b"].map((scope) => ({ type: "dispatch", branch: repo.headBranch, head, scope })),
|
|
161
|
+
approved(head, "a"),
|
|
162
|
+
];
|
|
163
|
+
const lane = (merge) => {
|
|
164
|
+
const result = judge(repo, records, { sha: merge.sha });
|
|
165
|
+
return result.applies ? { problem: result.problem, note: "lane" } : null;
|
|
166
|
+
};
|
|
167
|
+
const refusal = (sha) => mergeVerdict([{ sha }], records, "branch", lane).refusal;
|
|
168
|
+
assert.equal(refusal(head), null);
|
|
169
|
+
assert.match(refusal(repo.sha) ?? "", /scope "b"/);
|
|
170
|
+
repo.git("switch", "-q", "main");
|
|
171
|
+
repo.baseOid = repo.commit("base-change.txt", "base update\n", "update the base");
|
|
172
|
+
repo.git("switch", "-q", repo.headBranch);
|
|
173
|
+
repo.git("merge", "--no-ff", "-q", "-m", "merge the base", "main");
|
|
174
|
+
const sha = repo.git("rev-parse", "HEAD");
|
|
175
|
+
assert.match(refusal(sha) ?? "", /scope "b"/);
|
|
176
|
+
assert.match(judge(repo, [...records, approved(head, "b", "task")], { sha }).problem ?? "", /scope "b"/);
|
|
177
|
+
assert.match(judge(repo, [...records, approved(repo.baseOid, "b")], { sha }).problem ?? "", /scope "b"/);
|
|
178
|
+
assert.equal(judge(repo, [...records, approved(head, "b")], { sha }).problem, null);
|
|
179
|
+
assert.match(judge(repo, [...records, approved(head, "b"), { ...approved(sha, "b"), verdict: "CHANGES_REQUIRED" }], { sha }).problem, /scope "b"/);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test("dispatches on other branches do not require their scopes", (t) => {
|
|
183
|
+
const repo = integrationRepo(t);
|
|
184
|
+
const records = [approved(repo.sha, "a"), { type: "dispatch", branch: "feat/8-integration", head: repo.sha, scope: "b" }];
|
|
185
|
+
assert.equal(judge(repo, records).problem, null);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test("a regenerate title needs coverage when any changed file is outside the base globs", (t) => {
|
|
189
|
+
const repo = integrationRepo(t);
|
|
190
|
+
const records = repo.taskHeads.map((sha) => approved(sha));
|
|
191
|
+
repo.commit("generated.txt", "new generated output\n", "prepare generated output");
|
|
192
|
+
repo.git("reset", "--soft", "HEAD^");
|
|
193
|
+
const sha = repo.commit("x.js", "unreviewed code\n", REGENERATE_SUBJECT);
|
|
194
|
+
assert.match(judge(repo, records, { sha }).problem ?? "", /hold no APPROVED review/);
|
|
195
|
+
assert.equal(judge(repo, [...records, approved(sha)], { sha }).problem, null);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test("short shas count for approvals and newer scope rejections", (t) => {
|
|
199
|
+
const repo = integrationRepo(t);
|
|
200
|
+
const records = [
|
|
201
|
+
approved(repo.taskHeads[0].slice(0, 7), "api"),
|
|
202
|
+
{ ...approved(repo.mergeHeads[0].slice(0, 7), "api"), verdict: "CHANGES_REQUIRED" },
|
|
203
|
+
approved(repo.sha.slice(0, 7), "ui"),
|
|
204
|
+
];
|
|
205
|
+
assert.match(judge(repo, records).problem ?? "", /scope "api"/);
|
|
206
|
+
assert.equal(judge(repo, [...records, approved(repo.sha.slice(0, 7), "api")]).problem, null);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test("regenerate paths keep leading whitespace when the lane checks the globs", (t) => {
|
|
210
|
+
const repo = integrationRepo(t);
|
|
211
|
+
const sha = repo.commit(" generated.txt", "source outside the generated globs\n", REGENERATE_SUBJECT);
|
|
212
|
+
assert.match(judge(repo, repo.taskHeads.map((head) => approved(head)), { sha }).problem ?? "", /hold no APPROVED review/);
|
|
213
|
+
});
|