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
|
@@ -1,20 +1,123 @@
|
|
|
1
1
|
import test from "node:test";
|
|
2
2
|
import assert from "node:assert/strict";
|
|
3
3
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
4
|
-
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { tmpdir } from "node:os";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { defaults } from "../config.mjs";
|
|
9
|
+
import { testsCovering } from "./check-commands.mjs";
|
|
9
10
|
|
|
10
11
|
const qc = fileURLToPath(new URL("./qc.mjs", import.meta.url));
|
|
11
|
-
const
|
|
12
|
-
|
|
12
|
+
const scripts = mkdtempSync(path.join(tmpdir(), "qc-check-scripts-"));
|
|
13
|
+
test.after(() => rmSync(scripts, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }));
|
|
14
|
+
let scriptId = 0;
|
|
15
|
+
const node = (source) => {
|
|
16
|
+
const file = path.join(scripts, `${scriptId++}.cjs`);
|
|
17
|
+
writeFileSync(file, source);
|
|
18
|
+
return `"${process.execPath}" "${file}"`;
|
|
19
|
+
};
|
|
20
|
+
const record = node('require("node:fs").writeFileSync("args.json", JSON.stringify(process.argv.slice(2)))');
|
|
13
21
|
const git = (root, ...args) => execFileSync("git", args, { cwd: root, encoding: "utf8", stdio: "pipe" });
|
|
14
22
|
|
|
23
|
+
test("testsCovering finds sibling and reader-chain tests without basename-only matches for files and folders", async (t) => {
|
|
24
|
+
const root = fixture(t);
|
|
25
|
+
const base = "packages/qc-harness/src";
|
|
26
|
+
const source = `${base}/feature/source.mjs`;
|
|
27
|
+
const sibling = `${base}/feature/source.test.mjs`;
|
|
28
|
+
const reader = `${base}/reader.test.mjs`;
|
|
29
|
+
const named = `${base}/named.test.mjs`;
|
|
30
|
+
const data = `${base}/feature/data.json`;
|
|
31
|
+
const files = {
|
|
32
|
+
[source]: "export const value = 1;",
|
|
33
|
+
[sibling]: "export {};",
|
|
34
|
+
[`${base}/bridge.mjs`]: "export { value } from './feature/source.mjs';",
|
|
35
|
+
[reader]: "import './bridge.mjs';",
|
|
36
|
+
[named]: "// source.mjs and data.json are exercised by a command fixture",
|
|
37
|
+
[data]: "{}",
|
|
38
|
+
[`${base}/uncertain.test.mjs`]: "import(process.env.MODULE);",
|
|
39
|
+
"outside.test.mjs": "import './packages/qc-harness/src/feature/source.mjs';",
|
|
40
|
+
};
|
|
41
|
+
for (const [file, text] of Object.entries(files)) {
|
|
42
|
+
mkdirSync(path.dirname(path.join(root, file)), { recursive: true });
|
|
43
|
+
writeFileSync(path.join(root, file), text);
|
|
44
|
+
}
|
|
45
|
+
git(root, "add", ".");
|
|
46
|
+
const expected = [sibling, reader].sort();
|
|
47
|
+
const covered = await testsCovering(root, [source, `${base}/feature/`]);
|
|
48
|
+
assert.deepEqual(covered.get(source), expected);
|
|
49
|
+
assert.deepEqual(covered.get(sibling), [sibling]);
|
|
50
|
+
assert.deepEqual(covered.get(data), []);
|
|
51
|
+
assert.deepEqual([...covered.keys()].sort(), [source, sibling, data].sort());
|
|
52
|
+
assert.deepEqual(await testsCovering(root, [`${base}/feature`]), covered);
|
|
53
|
+
assert.deepEqual(await testsCovering(root, [source.replace(/\//g, "\\")]), new Map([[source, expected]]));
|
|
54
|
+
assert.deepEqual(await testsCovering(root, [`${base}/feature/`.replace(/\//g, "\\")]), covered);
|
|
55
|
+
for (const entry of [".", "./"]) {
|
|
56
|
+
const all = await testsCovering(root, [entry]);
|
|
57
|
+
assert.ok(all.has(source));
|
|
58
|
+
assert.ok(all.has("committed.mjs"));
|
|
59
|
+
assert.ok(!all.has("."));
|
|
60
|
+
assert.deepEqual(all.get(source), expected);
|
|
61
|
+
}
|
|
62
|
+
assert.deepEqual(await testsCovering(root, [`${base}/missing.mjs`]), new Map([[`${base}/missing.mjs`, []]]));
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
for (const [kind, text] of [
|
|
66
|
+
["regex apostrophe", "const apostrophe = /'/; import './source.mjs';"],
|
|
67
|
+
["template substitution", 'export const module = `${await import("./source.mjs")}`;'],
|
|
68
|
+
]) test(`testsCovering finds imports with a ${kind}`, async (t) => {
|
|
69
|
+
const root = fixture(t);
|
|
70
|
+
const base = "packages/qc-harness/src";
|
|
71
|
+
mkdirSync(path.join(root, base), { recursive: true });
|
|
72
|
+
writeFileSync(path.join(root, base, "source.mjs"), "export {};\n");
|
|
73
|
+
writeFileSync(path.join(root, base, "reader.test.mjs"), text);
|
|
74
|
+
git(root, "add", ".");
|
|
75
|
+
assert.deepEqual(await testsCovering(root, [`${base}/source.mjs`]), new Map([
|
|
76
|
+
[`${base}/source.mjs`, [`${base}/reader.test.mjs`]],
|
|
77
|
+
]));
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("testsCovering normalizes config file and folder backslashes", async (t) => {
|
|
81
|
+
const root = fixture(t);
|
|
82
|
+
const source = "packages/qc-harness/src/config.mjs";
|
|
83
|
+
const sibling = "packages/qc-harness/src/config.test.mjs";
|
|
84
|
+
mkdirSync(path.dirname(path.join(root, source)), { recursive: true });
|
|
85
|
+
writeFileSync(path.join(root, source), "export {};\n");
|
|
86
|
+
writeFileSync(path.join(root, sibling), "export {};\n");
|
|
87
|
+
git(root, "add", ".");
|
|
88
|
+
for (const entry of [source, "packages/qc-harness/src/"]) {
|
|
89
|
+
const expected = await testsCovering(root, [entry]);
|
|
90
|
+
assert.deepEqual(expected.get(source), [sibling]);
|
|
91
|
+
assert.deepEqual(await testsCovering(root, [entry.replace(/\//g, "\\")]), expected);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test("the e2e warning names qc e2e when the merge base is unavailable", (t) => {
|
|
96
|
+
const root = fixture(t, { e2e: record, base: "missing-ref" });
|
|
97
|
+
const run = spawnSync(process.execPath, [qc, "e2e"], { cwd: root, encoding: "utf8" });
|
|
98
|
+
assert.equal(run.status, 0, run.stderr);
|
|
99
|
+
const warnings = run.stdout.split("\n").filter((line) => /WARN.*merge base/.test(line));
|
|
100
|
+
assert.equal(warnings.length, 1);
|
|
101
|
+
assert.match(warnings[0], /running qc e2e without file arguments/);
|
|
102
|
+
assert.doesNotMatch(warnings[0], /related tests/);
|
|
103
|
+
assert.deepEqual(JSON.parse(readFileSync(path.join(root, "args.json"), "utf8")), []);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("an invalid feature switch pattern prints a config error without a stack trace", (t) => {
|
|
107
|
+
const root = fixture(t);
|
|
108
|
+
const file = path.join(root, "qc.config.json");
|
|
109
|
+
const config = JSON.parse(readFileSync(file, "utf8"));
|
|
110
|
+
config.featureSwitches = { patterns: ["["] };
|
|
111
|
+
writeFileSync(file, JSON.stringify(config));
|
|
112
|
+
const run = check(root);
|
|
113
|
+
assert.equal(run.status, 1);
|
|
114
|
+
assert.equal(run.stderr, 'qc: invalid qc.config.json: featureSwitches.patterns contains an invalid regular expression: "["\n');
|
|
115
|
+
assert.doesNotMatch(run.stderr, /SyntaxError|^\s+at /m);
|
|
116
|
+
});
|
|
117
|
+
|
|
15
118
|
function fixture(t, check = {}) {
|
|
16
119
|
const root = mkdtempSync(path.join(tmpdir(), "qc-check-commands-"));
|
|
17
|
-
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
120
|
+
t.after(() => rmSync(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }));
|
|
18
121
|
git(root, "init", "-q", "-b", "main");
|
|
19
122
|
git(root, "config", "user.name", "QC test");
|
|
20
123
|
git(root, "config", "user.email", "qc@example.test");
|
|
@@ -33,9 +136,66 @@ function fixture(t, check = {}) {
|
|
|
33
136
|
}
|
|
34
137
|
|
|
35
138
|
function check(root, args = [], input, env = process.env) {
|
|
36
|
-
return spawnSync(process.execPath, [qc, "check", ...args], { cwd: root, encoding: "utf8", input, env });
|
|
139
|
+
return spawnSync(process.execPath, [qc, "check", ...args], { cwd: root, encoding: "utf8", input, env: { ...env, NODE_TEST_CONTEXT: undefined } });
|
|
37
140
|
}
|
|
38
141
|
|
|
142
|
+
// Fixture fragment with commits before and after the push.
|
|
143
|
+
function sincePushFixture(t, config, { push = true, changes = true } = {}) {
|
|
144
|
+
const root = fixture(t, config);
|
|
145
|
+
const origin = mkdtempSync(path.join(tmpdir(), "qc-check-origin-"));
|
|
146
|
+
t.after(() => rmSync(origin, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }));
|
|
147
|
+
git(origin, "init", "-q", "--bare");
|
|
148
|
+
git(root, "remote", "add", "origin", origin);
|
|
149
|
+
writeFileSync(path.join(root, "early.mjs"), "export {};\n");
|
|
150
|
+
git(root, "add", "early.mjs");
|
|
151
|
+
git(root, "commit", "-q", "-m", "test(qc): add early module");
|
|
152
|
+
if (push) git(root, "push", "-u", "origin", "feat/170-related");
|
|
153
|
+
if (changes) {
|
|
154
|
+
writeFileSync(path.join(root, "late.mjs"), "export {};\n");
|
|
155
|
+
git(root, "add", "late.mjs");
|
|
156
|
+
git(root, "commit", "-q", "-m", "test(qc): add late module");
|
|
157
|
+
writeFileSync(path.join(root, "staged.mjs"), "export {};\n");
|
|
158
|
+
git(root, "add", "staged.mjs");
|
|
159
|
+
}
|
|
160
|
+
return root;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
test("--since-push runs sincePush with committed and staged files after the push", (t) => {
|
|
164
|
+
const root = sincePushFixture(t, { sincePush: record, related: node("process.exit(9)") });
|
|
165
|
+
const run = check(root, ["--since-push"]);
|
|
166
|
+
assert.equal(run.status, 0, run.stderr);
|
|
167
|
+
assert.deepEqual(JSON.parse(readFileSync(path.join(root, "args.json"), "utf8")), ["late.mjs", "staged.mjs"]);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test("a check without --since-push runs related with all branch changes", (t) => {
|
|
171
|
+
const root = sincePushFixture(t, { related: record, sincePush: node("process.exit(9)") });
|
|
172
|
+
const run = check(root);
|
|
173
|
+
assert.equal(run.status, 0, run.stderr);
|
|
174
|
+
assert.deepEqual(JSON.parse(readFileSync(path.join(root, "args.json"), "utf8")), ["early.mjs", "late.mjs", "staged.mjs"]);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test("--since-push warns and uses the base merge base when the branch has no upstream", (t) => {
|
|
178
|
+
const root = sincePushFixture(t, { sincePush: record }, { push: false });
|
|
179
|
+
const run = check(root, ["--since-push"]);
|
|
180
|
+
assert.equal(run.status, 0, run.stderr);
|
|
181
|
+
assert.match(run.stdout, /no upstream/);
|
|
182
|
+
assert.deepEqual(JSON.parse(readFileSync(path.join(root, "args.json"), "utf8")), ["early.mjs", "late.mjs", "staged.mjs"]);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test("--since-push uses related with the narrow list when sincePush is null", (t) => {
|
|
186
|
+
const root = sincePushFixture(t, { sincePush: null, related: record });
|
|
187
|
+
const run = check(root, ["--since-push"]);
|
|
188
|
+
assert.equal(run.status, 0, run.stderr);
|
|
189
|
+
assert.deepEqual(JSON.parse(readFileSync(path.join(root, "args.json"), "utf8")), ["late.mjs", "staged.mjs"]);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test("--since-push skips sincePush when nothing changed after the push", (t) => {
|
|
193
|
+
const root = sincePushFixture(t, { sincePush: node("process.exit(9)") }, { changes: false });
|
|
194
|
+
const run = check(root, ["--since-push"]);
|
|
195
|
+
assert.equal(run.status, 0, run.stderr);
|
|
196
|
+
assert.doesNotMatch(run.stdout, /RUN /);
|
|
197
|
+
});
|
|
198
|
+
|
|
39
199
|
test("related receives committed and staged paths once, without unstaged or untracked files", (t) => {
|
|
40
200
|
const root = fixture(t, { related: record });
|
|
41
201
|
writeFileSync(path.join(root, "committed.mjs"), "export const value = 2;\n");
|
|
@@ -99,7 +259,7 @@ test("repository commands run in order and stop with the failing command's exit
|
|
|
99
259
|
|
|
100
260
|
test("commands resolve PATH shims and preserve literal arguments and exit codes", (t) => {
|
|
101
261
|
const bin = mkdtempSync(path.join(tmpdir(), "qc command shims "));
|
|
102
|
-
t.after(() => rmSync(bin, { recursive: true, force: true }));
|
|
262
|
+
t.after(() => rmSync(bin, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }));
|
|
103
263
|
const source = 'require("node:fs").writeFileSync("args.json", JSON.stringify(process.argv.slice(3))); console.log("shim output"); process.exit(Number(process.argv[2]));\n';
|
|
104
264
|
if (process.platform === "win32") {
|
|
105
265
|
writeFileSync(path.join(bin, "shim.cjs"), source);
|
|
@@ -188,3 +348,197 @@ test("related excludes staged deletions and receives the new path of a staged re
|
|
|
188
348
|
assert.equal(run.status, 0, run.stderr);
|
|
189
349
|
assert.deepEqual(JSON.parse(readFileSync(path.join(root, "args.json"), "utf8")), ["renamed file.mjs"]);
|
|
190
350
|
});
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
test("--affected runs a test that spawns a CLI importing the changed module", (t) => {
|
|
354
|
+
const root = fixture(t);
|
|
355
|
+
const dir = "packages/qc-harness/src/cli";
|
|
356
|
+
mkdirSync(path.join(root, dir), { recursive: true });
|
|
357
|
+
const put = (file, text) => writeFileSync(path.join(root, dir, file), text);
|
|
358
|
+
put("lib.mjs", "export const value = 1;\n");
|
|
359
|
+
put("tool.mjs", "import { value } from './lib.mjs'; console.log(value);\n");
|
|
360
|
+
put("tool-spawn.test.mjs", `import { spawnSync } from 'node:child_process';
|
|
361
|
+
import assert from 'node:assert/strict';
|
|
362
|
+
import { fileURLToPath } from 'node:url';
|
|
363
|
+
const run = spawnSync(process.execPath, [fileURLToPath(new URL('./tool.mjs', import.meta.url))], { encoding: 'utf8' });
|
|
364
|
+
assert.equal(run.status, 0, run.stderr);
|
|
365
|
+
assert.equal(run.stdout.trim(), '2');
|
|
366
|
+
console.log('SPAWN TEST RAN');
|
|
367
|
+
`);
|
|
368
|
+
put("unrelated.test.mjs", "throw Error('UNRELATED TEST RAN');\n");
|
|
369
|
+
writeFileSync(path.join(root, "package.json"), JSON.stringify({ scripts: { test: "echo FULL SUITE" } }));
|
|
370
|
+
git(root, "add", "."); git(root, "commit", "-qm", "test: seed spawned CLI");
|
|
371
|
+
const base = git(root, "rev-parse", "HEAD").trim();
|
|
372
|
+
put("lib.mjs", "export const value = 2;\n");
|
|
373
|
+
git(root, "add", ".");
|
|
374
|
+
const run = check(root, ["--affected", "--base", base]);
|
|
375
|
+
assert.equal(run.status, 0, run.stdout + run.stderr);
|
|
376
|
+
assert.match(run.stdout, /tool-spawn\.test\.mjs/);
|
|
377
|
+
assert.match(run.stdout, /SPAWN TEST RAN/);
|
|
378
|
+
assert.doesNotMatch(run.stdout + run.stderr, /unrelated\.test\.mjs|UNRELATED TEST RAN|FULL SUITE/);
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
test("--affected runs a changed test and the wrapper that spawns it", (t) => {
|
|
382
|
+
const root = fixture(t);
|
|
383
|
+
const dir = "packages/qc-harness/src/cli";
|
|
384
|
+
mkdirSync(path.join(root, dir), { recursive: true });
|
|
385
|
+
const put = (file, text) => writeFileSync(path.join(root, dir, file), text);
|
|
386
|
+
put("child.test.mjs", "console.log('CHILD BEFORE');\n");
|
|
387
|
+
put("wrapper.test.mjs", `import { spawnSync } from 'node:child_process';
|
|
388
|
+
import assert from 'node:assert/strict';
|
|
389
|
+
import { fileURLToPath } from 'node:url';
|
|
390
|
+
const run = spawnSync(process.execPath, ['--test', fileURLToPath(new URL('./child.test.mjs', import.meta.url))], { encoding: 'utf8', env: { ...process.env, NODE_TEST_CONTEXT: undefined } });
|
|
391
|
+
assert.equal(run.status, 0, run.stderr);
|
|
392
|
+
assert.match(run.stdout, /CHILD AFTER/);
|
|
393
|
+
console.log('WRAPPER RAN');
|
|
394
|
+
`);
|
|
395
|
+
put("unrelated.test.mjs", "throw Error('UNRELATED TEST RAN');\n");
|
|
396
|
+
writeFileSync(path.join(root, "package.json"), JSON.stringify({ scripts: { test: "echo FULL SUITE" } }));
|
|
397
|
+
git(root, "add", "."); git(root, "commit", "-qm", "test: seed spawned test");
|
|
398
|
+
const base = git(root, "rev-parse", "HEAD").trim();
|
|
399
|
+
put("child.test.mjs", "console.log('CHILD AFTER');\n");
|
|
400
|
+
git(root, "add", ".");
|
|
401
|
+
const run = check(root, ["--affected", "--base", base]);
|
|
402
|
+
assert.equal(run.status, 0, run.stdout + run.stderr);
|
|
403
|
+
assert.match(run.stdout, /child\.test\.mjs/);
|
|
404
|
+
assert.match(run.stdout, /CHILD AFTER/);
|
|
405
|
+
assert.match(run.stdout, /wrapper\.test\.mjs/);
|
|
406
|
+
assert.match(run.stdout, /WRAPPER RAN/);
|
|
407
|
+
assert.doesNotMatch(run.stdout + run.stderr, /unrelated\.test\.mjs|UNRELATED TEST RAN|FULL SUITE/);
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
test("--affected selects only tests included in the full suite", (t) => {
|
|
411
|
+
const root = fixture(t);
|
|
412
|
+
const dir = "packages/qc-harness/src/cli";
|
|
413
|
+
mkdirSync(path.join(root, dir), { recursive: true });
|
|
414
|
+
mkdirSync(path.join(root, "evals/agents/tasks/x"), { recursive: true });
|
|
415
|
+
writeFileSync(path.join(root, dir, "module.mjs"), "export const value = 1;\n");
|
|
416
|
+
writeFileSync(path.join(root, dir, "module.test.mjs"), "import './module.mjs'; console.log('SUITE TEST RAN');\n");
|
|
417
|
+
writeFileSync(path.join(root, "evals/agents/run.test.mjs"), "// module.mjs\nconsole.log('EVAL RUNNER RAN');\n");
|
|
418
|
+
writeFileSync(path.join(root, "evals/agents/tasks/x/hidden.test.ts"), "// module.mjs\nthrow Error('HIDDEN TEST RAN');\n");
|
|
419
|
+
writeFileSync(path.join(root, "package.json"), JSON.stringify({ scripts: { test: "echo FULL SUITE" } }));
|
|
420
|
+
git(root, "add", "."); git(root, "commit", "-qm", "test: seed suite selection");
|
|
421
|
+
const base = git(root, "rev-parse", "HEAD").trim();
|
|
422
|
+
writeFileSync(path.join(root, dir, "module.mjs"), "export const value = 2;\n");
|
|
423
|
+
git(root, "add", ".");
|
|
424
|
+
const run = check(root, ["--affected", "--base", base]);
|
|
425
|
+
assert.equal(run.status, 0, run.stdout + run.stderr);
|
|
426
|
+
assert.match(run.stdout, /SUITE TEST RAN/);
|
|
427
|
+
assert.match(run.stdout, /EVAL RUNNER RAN/);
|
|
428
|
+
assert.doesNotMatch(run.stdout + run.stderr, /hidden\.test\.ts|HIDDEN TEST RAN|FULL SUITE/);
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
test("--affected with one changed gate file runs that gate's test file and not an unrelated one", (t) => {
|
|
432
|
+
const root = fixture(t);
|
|
433
|
+
const dir = "packages/qc-harness/src/cli";
|
|
434
|
+
mkdirSync(path.join(root, dir), { recursive: true });
|
|
435
|
+
const put = (file, text) => writeFileSync(path.join(root, dir, file), text);
|
|
436
|
+
const gates = path.join(root, "packages/qc-harness/src/gates");
|
|
437
|
+
mkdirSync(gates, { recursive: true });
|
|
438
|
+
writeFileSync(path.join(gates, "tree-scan.test.mjs"), "console.log('TREE SCAN');\n");
|
|
439
|
+
put("gate.mjs", "export const value = 1;\n");
|
|
440
|
+
put("bridge.mjs", "export { value, value as default } from './gate.mjs';\n");
|
|
441
|
+
for (const extension of ["js", "mjs", "cjs", "jsx", "ts", "mts", "cts", "tsx"]) {
|
|
442
|
+
put(`reader.${extension}`, "export { value } from './gate.mjs';\n");
|
|
443
|
+
put(`reader-${extension}.test.mjs`, `if (false) import('./reader.${extension}'); console.log('GRAPH ${extension}');\n`);
|
|
444
|
+
}
|
|
445
|
+
const forms = [
|
|
446
|
+
"import value from './bridge.mjs';",
|
|
447
|
+
'import { value }\nfrom "./bridge.mjs";',
|
|
448
|
+
"import * as values from './bridge.mjs';",
|
|
449
|
+
"export { value } from './bridge.mjs';",
|
|
450
|
+
'export * from "./bridge.mjs";',
|
|
451
|
+
"import './bridge.mjs';",
|
|
452
|
+
'await import("./bridge.mjs");',
|
|
453
|
+
"if (false) require('./bridge.mjs');",
|
|
454
|
+
"await import(`./bridge.mjs`);",
|
|
455
|
+
'// import "node:comment\nimport "./bridge.mjs";',
|
|
456
|
+
'export { value } from /* comment */ "./gate.mjs";',
|
|
457
|
+
'export const { value } = await import /* comment */ ("./gate.mjs");',
|
|
458
|
+
'const target = "./" + "gate" + ".mjs"; export const { value } = await import /* comment */ (target);',
|
|
459
|
+
'import /* comment */ "./bridge.mjs";',
|
|
460
|
+
'export { value } from // comment\n "./bridge.mjs";',
|
|
461
|
+
'await import // comment\n ( /* comment */ "./bridge.mjs" /* comment */ );',
|
|
462
|
+
'if (false) require /* comment */ ( "./bridge.mjs" );',
|
|
463
|
+
'const target = "./" + "bridge" + ".mjs"; if (false) require // comment\n (target);',
|
|
464
|
+
'const url = "http://x"; await import("./bridge.mjs");',
|
|
465
|
+
"const text = '/* literal */'; await import('./bridge.mjs');",
|
|
466
|
+
'const text = `http://x /* literal */`; await import("./bridge.mjs");',
|
|
467
|
+
'const pattern = /[//]/; export { value } from "./gate.mjs";',
|
|
468
|
+
'const text = `${`//`}`; export { value } from "./gate.mjs";',
|
|
469
|
+
'const text = "escaped \\" // literal"; await import("./bridge.mjs");',
|
|
470
|
+
"const target = './bridge' + '.mjs'; await import(target);",
|
|
471
|
+
"const target = './bridge' + '.mjs'; if (false) require(target);",
|
|
472
|
+
"if (false) require('package');",
|
|
473
|
+
];
|
|
474
|
+
for (const [index, source] of forms.entries()) {
|
|
475
|
+
put(`form-${index}.mjs`, source);
|
|
476
|
+
put(`form-${index}.test.mjs`, `import './form-${index}.mjs'; console.log('FORM ${index}');\n`);
|
|
477
|
+
}
|
|
478
|
+
for (const [name, source] of [["gate", ""], ["consumer", "import './bridge.mjs';"], ["unrelated", "throw Error('unrelated ran');"]]) {
|
|
479
|
+
put(`${name}.test.mjs`, `${source} console.log("${name}.test.mjs");\n`);
|
|
480
|
+
}
|
|
481
|
+
writeFileSync(path.join(root, "package.json"), JSON.stringify({ scripts: { test: "echo FULL SUITE" } }));
|
|
482
|
+
git(root, "add", "."); git(root, "commit", "-qm", "test: seed affected graph");
|
|
483
|
+
const base = git(root, "rev-parse", "HEAD").trim();
|
|
484
|
+
put("gate.mjs", "export const value = 2;\n");
|
|
485
|
+
git(root, "add", "."); git(root, "commit", "-qm", "test: change gate");
|
|
486
|
+
let run = check(root, ["--affected", "--base", base]);
|
|
487
|
+
assert.equal(run.status, 0, run.stdout + run.stderr);
|
|
488
|
+
assert.match(run.stdout, /gate\.test\.mjs/);
|
|
489
|
+
assert.match(run.stdout, /consumer\.test\.mjs/);
|
|
490
|
+
assert.match(run.stdout, /TREE SCAN/);
|
|
491
|
+
assert.deepEqual([...forms.keys()].filter((index) => !new RegExp(`FORM ${index}\\b`).test(run.stdout)), [], run.stdout);
|
|
492
|
+
for (const extension of ["js", "mjs", "cjs", "jsx", "ts", "mts", "cts", "tsx"]) assert.match(run.stdout, new RegExp(`GRAPH ${extension}\\b`));
|
|
493
|
+
assert.doesNotMatch(run.stdout, /unrelated\.test\.mjs|FULL SUITE/);
|
|
494
|
+
const omittedReaders = [
|
|
495
|
+
["consumer.test.js", "import { value } from './gate.mjs'; if (value !== 1) throw Error('JS READER');"],
|
|
496
|
+
["runtime.test.mjs", "import { spawnSync } from 'node:child_process'; const run = spawnSync(process.execPath, ['--input-type=module', '-e', `import { value } from ${JSON.stringify(new URL('./gate.mjs', import.meta.url).href)}; process.exit(value === 1 ? 0 : 1)`]); if (run.status !== 0) throw Error('RUNTIME READER');"],
|
|
497
|
+
];
|
|
498
|
+
const omittedRuns = omittedReaders.map(([file, source]) => {
|
|
499
|
+
put(file, source);
|
|
500
|
+
const result = check(root, ["--affected", "--base", base]);
|
|
501
|
+
rmSync(path.join(root, dir, file), { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
502
|
+
return result;
|
|
503
|
+
});
|
|
504
|
+
assert.deepEqual(omittedRuns.map(({ status }) => status), [0, 1], omittedRuns.map(({ stdout, stderr }) => stdout + stderr).join("\n"));
|
|
505
|
+
assert.doesNotMatch(omittedRuns[0].stdout + omittedRuns[0].stderr, /consumer\.test\.js|JS READER/);
|
|
506
|
+
for (const result of omittedRuns) assert.doesNotMatch(result.stdout, /unrelated\.test\.mjs|FULL SUITE/);
|
|
507
|
+
put("dynamic.test.mjs", "const target = './' + 'gate' + '.mjs'; await import(target); if (false) require(target); console.log('DYNAMIC COVERED');\n");
|
|
508
|
+
git(root, "add", ".");
|
|
509
|
+
run = check(root, ["--affected", "--base", base]);
|
|
510
|
+
assert.equal(run.status, 0, run.stderr); assert.match(run.stdout, /DYNAMIC COVERED/);
|
|
511
|
+
git(root, "reset", "--hard", "HEAD");
|
|
512
|
+
for (const args of [["--affected", "--full"], ["--affected", "--since-push"], ["--affected", "--os", "linux"], ["--affected", "gate.mjs"], ["--affected", "--base"], ["--base", base]]) {
|
|
513
|
+
run = check(root, args);
|
|
514
|
+
assert.equal(run.status, 1, JSON.stringify(args));
|
|
515
|
+
assert.match(run.stderr, /qc check:/);
|
|
516
|
+
}
|
|
517
|
+
for (const file of ["shared.json", `${dir}/orphan.mjs`]) {
|
|
518
|
+
writeFileSync(path.join(root, file), "{}\n"); git(root, "add", file);
|
|
519
|
+
run = check(root, ["--affected", "--base", base]);
|
|
520
|
+
assert.equal(run.status, 0, run.stderr); assert.match(run.stdout, /FULL SUITE/);
|
|
521
|
+
git(root, "reset", "--hard", "HEAD");
|
|
522
|
+
}
|
|
523
|
+
git(root, "mv", `${dir}/gate.mjs`, `${dir}/renamed.mjs`);
|
|
524
|
+
run = check(root, ["--affected", "--base", base]);
|
|
525
|
+
assert.equal(run.status, 0, run.stderr); assert.match(run.stdout, /FULL SUITE/);
|
|
526
|
+
git(root, "reset", "--hard", "HEAD");
|
|
527
|
+
git(root, "rm", `${dir}/gate.mjs`);
|
|
528
|
+
run = check(root, ["--affected", "--base", base]);
|
|
529
|
+
assert.equal(run.status, 0, run.stderr); assert.match(run.stdout, /FULL SUITE/);
|
|
530
|
+
git(root, "reset", "--hard", "HEAD");
|
|
531
|
+
run = check(root, ["--affected", "--base", "missing-ref"]);
|
|
532
|
+
assert.equal(run.status, 0, run.stderr); assert.match(run.stdout, /FULL SUITE/);
|
|
533
|
+
const configFile = path.join(root, "qc.config.json");
|
|
534
|
+
const settings = JSON.parse(readFileSync(configFile, "utf8"));
|
|
535
|
+
settings.check.related = record;
|
|
536
|
+
writeFileSync(configFile, JSON.stringify(settings));
|
|
537
|
+
run = check(root, ["--affected", "--base", base]);
|
|
538
|
+
assert.equal(run.status, 0, run.stderr);
|
|
539
|
+
assert.deepEqual(JSON.parse(readFileSync(path.join(root, "args.json"))), [`${dir}/gate.mjs`]);
|
|
540
|
+
assert.doesNotMatch(run.stdout, /FULL SUITE/);
|
|
541
|
+
settings.check.related = node("process.exit(7)");
|
|
542
|
+
writeFileSync(configFile, JSON.stringify(settings));
|
|
543
|
+
assert.equal(check(root, ["--affected", "--base", base]).status, 7);
|
|
544
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { execFileSync } from "node:child_process";
|
|
4
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { load } from "../config.mjs";
|
|
8
|
+
import { checkFeatureSwitches } from "../gates/feature-switches.mjs";
|
|
9
|
+
import { runCheck } from "./check.mjs";
|
|
10
|
+
|
|
11
|
+
const view = { path: "src/features/pins/view.tsx", contents: "const SHOW_DELETE = false;" };
|
|
12
|
+
|
|
13
|
+
function fixture(gates, featureRoots = ["src/features"]) {
|
|
14
|
+
const dir = mkdtempSync(path.join(tmpdir(), "qc-feature-switches-"));
|
|
15
|
+
execFileSync("git", ["init", "-q"], { cwd: dir });
|
|
16
|
+
const files = {
|
|
17
|
+
"package.json": '{"name":"t","private":true,"type":"module"}',
|
|
18
|
+
"quality-thresholds.json": '{"gates":{}}',
|
|
19
|
+
"versions.json": '{"libraries":{}}',
|
|
20
|
+
"qc.config.json": JSON.stringify({ featureRoots, gates }),
|
|
21
|
+
[view.path]: view.contents,
|
|
22
|
+
"src/features/pins/feature-switches.ts": "export const PIN_UNWIRED = true;",
|
|
23
|
+
"src/features/pins/view.test.tsx": "const SHOW_TEST = false;",
|
|
24
|
+
"src/features/pins/dist/view.tsx": "const SHOW_DIST = false;",
|
|
25
|
+
"src/features/pins/node_modules/vendor.ts": "const SHOW_VENDOR = false;",
|
|
26
|
+
"src/features/pins/notes.md": "const SHOW_DOC = false;",
|
|
27
|
+
"src/features/root.ts": "const SHOW_ROOT = false;",
|
|
28
|
+
"src/elsewhere/view.tsx": "const SHOW_OTHER = false;",
|
|
29
|
+
};
|
|
30
|
+
for (const [file, contents] of Object.entries(files)) {
|
|
31
|
+
mkdirSync(path.dirname(path.join(dir, file)), { recursive: true });
|
|
32
|
+
writeFileSync(path.join(dir, file), contents);
|
|
33
|
+
}
|
|
34
|
+
return dir;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
test("runCheck finds declarations in feature source files when the gate is on", async () => {
|
|
38
|
+
const dir = fixture({ "feature-switches": true });
|
|
39
|
+
try {
|
|
40
|
+
const config = load(dir);
|
|
41
|
+
const { problems, lines } = await runCheck(config);
|
|
42
|
+
assert.deepEqual(
|
|
43
|
+
problems.filter((problem) => problem.rule === "unwire-constant-outside-switch-file"),
|
|
44
|
+
checkFeatureSwitches([view], config.featureSwitches, "src/features/pins"),
|
|
45
|
+
);
|
|
46
|
+
assert.equal(problems.filter((problem) => problem.rule === "unwire-constant-outside-switch-file").length, 1);
|
|
47
|
+
assert.ok(lines.includes("FAIL switches 2 file(s), 1 unwire constant(s) outside feature-switches.ts"));
|
|
48
|
+
} finally {
|
|
49
|
+
rmSync(dir, { recursive: true, force: true });
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
for (const featureRoot of ["./src/features", "src/features/"]) {
|
|
54
|
+
test(`the root switch exemption normalizes featureRoots: ${featureRoot}`, async (t) => {
|
|
55
|
+
const dir = fixture({ "feature-switches": true }, [featureRoot]);
|
|
56
|
+
t.after(() => rmSync(dir, { recursive: true, force: true }));
|
|
57
|
+
writeFileSync(path.join(dir, view.path), "export const title = 'Pins';");
|
|
58
|
+
writeFileSync(path.join(dir, "src/features/pins/feature-switches.ts"), "export const SHOW_DELETE = false;");
|
|
59
|
+
const { problems, lines } = await runCheck(load(dir));
|
|
60
|
+
assert.deepEqual(problems.filter((problem) => problem.rule === "unwire-constant-outside-switch-file"), []);
|
|
61
|
+
assert.ok(lines.includes("OK switches 2 file(s) hold no unwire constant outside feature-switches.ts"));
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
test("runCheck leaves the feature-switches gate off when it is unset", async () => {
|
|
66
|
+
const dir = fixture({});
|
|
67
|
+
try {
|
|
68
|
+
const { problems, lines } = await runCheck(load(dir));
|
|
69
|
+
assert.deepEqual(problems.filter((problem) => problem.rule === "unwire-constant-outside-switch-file"), []);
|
|
70
|
+
assert.ok(lines.every((line) => !line.startsWith("OK switches")));
|
|
71
|
+
} finally {
|
|
72
|
+
rmSync(dir, { recursive: true, force: true });
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("the gate prints one summary across features and reports failure truthfully", async (t) => {
|
|
77
|
+
const dir = fixture({ "feature-switches": true });
|
|
78
|
+
t.after(() => rmSync(dir, { recursive: true, force: true }));
|
|
79
|
+
mkdirSync(path.join(dir, "src/features/photos"));
|
|
80
|
+
writeFileSync(path.join(dir, "src/features/photos/view.tsx"), "export const title = 'Photos';");
|
|
81
|
+
const failed = await runCheck(load(dir));
|
|
82
|
+
const summaries = failed.lines.filter((line) => /switches\s/.test(line));
|
|
83
|
+
assert.equal(summaries.length, 1);
|
|
84
|
+
assert.match(summaries[0], /^FAIL\s+switches\s+3 file\(s\)/);
|
|
85
|
+
writeFileSync(path.join(dir, view.path), "export const title = 'Pins';");
|
|
86
|
+
const passed = await runCheck(load(dir));
|
|
87
|
+
assert.deepEqual(passed.lines.filter((line) => /switches\s/.test(line)), ["OK switches 3 file(s) hold no unwire constant outside feature-switches.ts"]);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("the feature switch gate skips spec files in every source extension", async (t) => {
|
|
91
|
+
const dir = fixture({ "feature-switches": true });
|
|
92
|
+
t.after(() => rmSync(dir, { recursive: true, force: true }));
|
|
93
|
+
writeFileSync(path.join(dir, view.path), "export const title = 'Pins';");
|
|
94
|
+
for (const extension of ["ts", "tsx", "mts", "cts", "js", "jsx", "mjs", "cjs"]) {
|
|
95
|
+
writeFileSync(path.join(dir, `src/features/pins/view.spec.${extension}`), "const SHOW_SPEC = false;");
|
|
96
|
+
}
|
|
97
|
+
const { problems } = await runCheck(load(dir));
|
|
98
|
+
assert.deepEqual(problems.filter((problem) => problem.rule === "unwire-constant-outside-switch-file"), []);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("a nested switch file receives no root switch exemption", async (t) => {
|
|
102
|
+
const dir = fixture({ "feature-switches": true });
|
|
103
|
+
t.after(() => rmSync(dir, { recursive: true, force: true }));
|
|
104
|
+
const nested = "src/features/pins/nested/feature-switches.ts";
|
|
105
|
+
mkdirSync(path.dirname(path.join(dir, nested)));
|
|
106
|
+
writeFileSync(path.join(dir, nested), "const SHOW_NESTED = false;");
|
|
107
|
+
const { problems } = await runCheck(load(dir));
|
|
108
|
+
const switches = problems.filter((problem) => problem.rule === "unwire-constant-outside-switch-file");
|
|
109
|
+
assert.deepEqual(switches.map(({ path }) => path).sort(), [nested, view.path].sort());
|
|
110
|
+
});
|