architecture-harness 0.25.1 → 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 +2 -18
- package/src/cli/ask.mjs +42 -0
- package/src/cli/ask.test.mjs +40 -0
- package/src/cli/check-commands.mjs +104 -7
- package/src/cli/check-commands.test.mjs +281 -7
- package/src/cli/check-full.test.mjs +152 -0
- package/src/cli/check.mjs +113 -0
- package/src/cli/check.test.mjs +45 -0
- package/src/cli/child-run.mjs +7 -2
- package/src/cli/child-run.test.mjs +17 -2
- package/src/cli/ci-failures.mjs +47 -9
- package/src/cli/ci-failures.test.mjs +116 -10
- package/src/cli/ci-preview.mjs +62 -0
- package/src/cli/ci-preview.test.mjs +85 -0
- package/src/cli/ci-state.mjs +2 -2
- package/src/cli/ci-state.test.mjs +8 -8
- package/src/cli/ci-template.test.mjs +79 -1
- package/src/cli/codex-implement.mjs +373 -44
- package/src/cli/codex-implement.test.mjs +775 -14
- package/src/cli/codex-limit.test.mjs +1 -1
- 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 +3 -3
- package/src/cli/commit-guard.test.mjs +9 -3
- package/src/cli/diff-shape.mjs +162 -0
- package/src/cli/diff-shape.test.mjs +200 -0
- package/src/cli/dispatch-guard.test.mjs +7 -7
- package/src/cli/dispatch-reminder.mjs +18 -8
- package/src/cli/dispatch-reminder.test.mjs +46 -10
- 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/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 +5 -3
- package/src/cli/gh-merge-command.test.mjs +4 -0
- package/src/cli/gh-run.mjs +50 -7
- package/src/cli/gh-run.test.mjs +35 -5
- package/src/cli/git-read.mjs +2 -1
- package/src/cli/integrate-tree.mjs +47 -0
- package/src/cli/integrate.mjs +35 -26
- package/src/cli/integration-lane.mjs +3 -5
- package/src/cli/integration-lane.test.mjs +2 -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/locked-tests.mjs +134 -0
- package/src/cli/locked-tests.test.mjs +188 -0
- package/src/cli/merge-guard.mjs +96 -43
- package/src/cli/merge-guard.test.mjs +272 -111
- 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/overview.mjs +131 -0
- package/src/cli/overview.test.mjs +137 -0
- package/src/cli/platform-risk.mjs +46 -0
- package/src/cli/platform-risk.test.mjs +38 -0
- package/src/cli/pr-guard.mjs +128 -0
- package/src/cli/pr-guard.test.mjs +154 -0
- package/src/cli/qc.mjs +76 -20
- package/src/cli/qc.test.mjs +35 -1
- package/src/cli/retry-failed.mjs +3 -1
- package/src/cli/run-log.mjs +73 -0
- package/src/cli/run-log.test.mjs +121 -0
- package/src/cli/skill-length.test.mjs +8 -0
- package/src/cli/tools.mjs +49 -0
- package/src/cli/tools.test.mjs +89 -0
- package/src/cli/watch.mjs +21 -8
- package/src/cli/watch.test.mjs +45 -21
- package/src/cli/work-order-guard.mjs +2 -1
- package/src/cli/workflow-hooks.test.mjs +1 -1
- package/src/cli/workflow-settings.mjs +3 -2
- package/src/cli/workflow-settings.test.mjs +11 -1
- package/src/config.mjs +64 -2
- package/src/config.test.mjs +93 -20
- package/src/consumer-package.test.mjs +3 -18
- package/src/descriptions.mjs +1 -0
- package/src/eslint/index.mjs +2 -0
- package/src/eslint/preset.mjs +12 -1
- package/src/eslint/preset.test.mjs +1 -1
- package/src/eslint/rules/timeless-comment.mjs +92 -0
- package/src/eslint/rules.test.mjs +34 -0
- package/src/gates/plain-language.mjs +396 -0
- package/src/gates/plain-language.test.mjs +210 -0
- package/src/global-skills.test.mjs +0 -1
- package/templates/docs/enforcement.md +12 -2
- package/templates/github/workflows/ci.yml +51 -4
- package/src/cli/screens-discovery.mjs +0 -60
- package/src/cli/screens.mjs +0 -85
- package/src/cli/stack.mjs +0 -14
- package/src/cli/throwaway-db.mjs +0 -133
- package/src/cli/throwaway-db.test.mjs +0 -137
- 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 -176
- 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 -41
- 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 -138
- 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 -79
- package/src/screens/stack-auth.browser-test.mjs +0 -30
- package/src/screens/stack-auth.mjs +0 -107
- 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 -60
- package/src/stack/supervisor.mjs +0 -30
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "architecture-harness",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Architecture gates, lint rules and scaffolding for the bounded-vertical-slice architecture",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
"./eslint": "./src/eslint/index.mjs",
|
|
40
40
|
"./preset": "./src/eslint/preset.mjs",
|
|
41
41
|
"./config": "./src/config.mjs",
|
|
42
|
-
"./screens": "./src/screens/catalog.mjs",
|
|
43
42
|
"./gates/*": "./src/gates/*.mjs",
|
|
44
43
|
"./package.json": "./package.json",
|
|
45
44
|
"./ui/*": "./src/ui/*.mjs"
|
|
@@ -64,10 +63,7 @@
|
|
|
64
63
|
"@commitlint/lint": ">=19",
|
|
65
64
|
"@commitlint/config-conventional": ">=19",
|
|
66
65
|
"yaml": ">=2",
|
|
67
|
-
"typescript": ">=5"
|
|
68
|
-
"pixelmatch": ">=8",
|
|
69
|
-
"playwright": ">=1.64",
|
|
70
|
-
"pngjs": ">=7"
|
|
66
|
+
"typescript": ">=5"
|
|
71
67
|
},
|
|
72
68
|
"peerDependenciesMeta": {
|
|
73
69
|
"@typescript-eslint/eslint-plugin": {
|
|
@@ -93,15 +89,6 @@
|
|
|
93
89
|
},
|
|
94
90
|
"typescript": {
|
|
95
91
|
"optional": true
|
|
96
|
-
},
|
|
97
|
-
"pixelmatch": {
|
|
98
|
-
"optional": true
|
|
99
|
-
},
|
|
100
|
-
"playwright": {
|
|
101
|
-
"optional": true
|
|
102
|
-
},
|
|
103
|
-
"pngjs": {
|
|
104
|
-
"optional": true
|
|
105
92
|
}
|
|
106
93
|
},
|
|
107
94
|
"devDependencies": {
|
|
@@ -112,9 +99,6 @@
|
|
|
112
99
|
"eslint": "^9",
|
|
113
100
|
"eslint-plugin-boundaries": "^5",
|
|
114
101
|
"eslint-plugin-sonarjs": "^3",
|
|
115
|
-
"pixelmatch": "^8.0.0",
|
|
116
|
-
"playwright": "^1.64.1",
|
|
117
|
-
"pngjs": "^7.0.0",
|
|
118
102
|
"typescript": "^5",
|
|
119
103
|
"yaml": "^2.9.1"
|
|
120
104
|
}
|
package/src/cli/ask.mjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { runGhResult } from "./gh-run.mjs";
|
|
2
|
+
import { originOf } from "./git-read.mjs";
|
|
3
|
+
|
|
4
|
+
const USAGE = 'Usage: qc ask --issue <n> "<question>"';
|
|
5
|
+
|
|
6
|
+
/** Label an issue and post one question in the checkout's repository. */
|
|
7
|
+
export function askIssue(issue, question, { cwd = process.cwd(), repo = originOf(cwd), gh } = {}) {
|
|
8
|
+
if (!/^[1-9]\d*$/.test(String(issue)) || typeof question !== "string" || !question.trim()) throw new Error(USAGE);
|
|
9
|
+
if (!repo) throw new Error("qc ask: cannot read the repository from origin");
|
|
10
|
+
const invoke = (args) => {
|
|
11
|
+
const command = [...args, "-R", repo];
|
|
12
|
+
if (gh) {
|
|
13
|
+
const answer = gh(command);
|
|
14
|
+
if (answer == null) throw new Error("gh returned no answer");
|
|
15
|
+
return answer;
|
|
16
|
+
}
|
|
17
|
+
const result = runGhResult(command, { cwd });
|
|
18
|
+
if (result.status !== 0) throw new Error((result.stderr?.trim() || result.error?.message || `gh exited ${result.status}`).split(/\r?\n/)[0]);
|
|
19
|
+
return result.stdout;
|
|
20
|
+
};
|
|
21
|
+
const labels = JSON.parse(invoke(["label", "list", "--search", "needs-user", "--json", "name", "--limit", "100"]));
|
|
22
|
+
if (!labels.some((label) => label.name === "needs-user")) {
|
|
23
|
+
invoke(["label", "create", "needs-user", "--color", "D876E3", "--description", "Needs an answer from the user"]);
|
|
24
|
+
}
|
|
25
|
+
invoke(["issue", "edit", String(issue), "--add-label", "needs-user"]);
|
|
26
|
+
invoke(["issue", "comment", String(issue), "--body", question]);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** `qc ask --issue <n> "<question>"`. */
|
|
30
|
+
export function runAsk(args, { warn = console.error, ...deps } = {}) {
|
|
31
|
+
if (args.length !== 3 || args[0] !== "--issue" || !/^[1-9]\d*$/.test(args[1]) || !args[2].trim() || args[2].startsWith("--")) {
|
|
32
|
+
warn(USAGE);
|
|
33
|
+
return 1;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
askIssue(args[1], args[2], deps);
|
|
37
|
+
return 0;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
warn(String(error.message).split(/\r?\n/)[0]);
|
|
40
|
+
return 1;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { askIssue, runAsk } from "./ask.mjs";
|
|
4
|
+
|
|
5
|
+
test("ask creates a missing needs-user label and posts one question on the explicit issue", () => {
|
|
6
|
+
for (const exists of [false, true]) {
|
|
7
|
+
const calls = [];
|
|
8
|
+
const question = "Which option?\nKeep the existing data?";
|
|
9
|
+
assert.equal(runAsk(["--issue", "227", question], {
|
|
10
|
+
repo: "local/repo", say: () => {},
|
|
11
|
+
gh: (args) => { calls.push(args); return args[1] === "list" ? JSON.stringify(exists ? [{ name: "needs-user" }] : []) : ""; },
|
|
12
|
+
}), 0);
|
|
13
|
+
assert.equal(calls.filter((args) => args[0] === "label" && args[1] === "create").length, exists ? 0 : 1);
|
|
14
|
+
assert.ok(calls.every((args) => args[args.indexOf("-R") + 1] === "local/repo"));
|
|
15
|
+
assert.deepEqual(calls.filter((args) => args[0] === "issue"), [
|
|
16
|
+
["issue", "edit", "227", "--add-label", "needs-user", "-R", "local/repo"],
|
|
17
|
+
["issue", "comment", "227", "--body", question, "-R", "local/repo"],
|
|
18
|
+
]);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("ask rejects malformed arguments before calling GitHub", () => {
|
|
23
|
+
for (const args of [[], ["--issue", "0", "why?"], ["--issue", "2x", "why?"], ["--issue", "2", " "], ["--issue", "2", "why?", "extra"], ["--issue", "2", "--unknown"]]) {
|
|
24
|
+
assert.equal(runAsk(args, { gh: () => assert.fail("invalid arguments reached gh"), warn: () => {} }), 1);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("ask exits 1 with the first GitHub error line and stops after the failed call", () => {
|
|
29
|
+
for (let failAt = 0; failAt < 4; failAt++) {
|
|
30
|
+
const warnings = [];
|
|
31
|
+
let calls = 0;
|
|
32
|
+
assert.equal(runAsk(["--issue", "227", "Which option?"], {
|
|
33
|
+
repo: "local/repo", warn: (line) => warnings.push(line),
|
|
34
|
+
gh: () => { if (calls++ === failAt) throw new Error("GitHub unavailable\nprivate details"); return "[]"; },
|
|
35
|
+
}), 1);
|
|
36
|
+
assert.equal(calls, failAt + 1);
|
|
37
|
+
assert.deepEqual(warnings, ["GitHub unavailable"]);
|
|
38
|
+
}
|
|
39
|
+
assert.throws(() => askIssue(227, "Why?", { repo: "local/repo", gh: () => null }), /gh/);
|
|
40
|
+
});
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
// A pipeline that runs repository commands after the architecture checks pass.
|
|
2
2
|
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { repoFiles } from "./repo-files.mjs";
|
|
3
6
|
import { execFileSync } from "node:child_process";
|
|
4
7
|
import { spawnCommand as spawn } from "./spawn-command.mjs";
|
|
5
8
|
|
|
@@ -38,7 +41,7 @@ function commandWords(command) {
|
|
|
38
41
|
return words;
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
export function changedFiles(root, base, sincePush, command = "qc e2e") {
|
|
44
|
+
export function changedFiles(root, base, sincePush, command = "qc e2e", affected = false) {
|
|
42
45
|
const git = (...args) => execFileSync("git", args, { cwd: root, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
|
|
43
46
|
let ref = base;
|
|
44
47
|
if (sincePush) {
|
|
@@ -61,7 +64,7 @@ export function changedFiles(root, base, sincePush, command = "qc e2e") {
|
|
|
61
64
|
console.log(`WARN merge base with ${ref} is unavailable; running ${command} without file arguments`);
|
|
62
65
|
return null;
|
|
63
66
|
}
|
|
64
|
-
return git("diff", "--cached", "--name-only", "-z", "--no-renames", "--diff-filter=d", mergeBase, "--").split("\0").filter(Boolean);
|
|
67
|
+
return git("diff", "--cached", "--name-only", "-z", "--no-renames", ...(affected ? [] : ["--diff-filter=d"]), mergeBase, "--").split("\0").filter(Boolean);
|
|
65
68
|
}
|
|
66
69
|
|
|
67
70
|
export async function runCommand(root, command, files = []) {
|
|
@@ -79,13 +82,13 @@ export async function runCommand(root, command, files = []) {
|
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
84
|
|
|
82
|
-
export async function runCheckCommands(config, { sincePush = false } = {}) {
|
|
83
|
-
const { commands
|
|
85
|
+
export async function runCheckCommands(config, { sincePush = false, affected = false, base = config.check.base } = {}) {
|
|
86
|
+
const { commands } = config.check;
|
|
84
87
|
const related = sincePush ? config.check.sincePush ?? config.check.related : config.check.related;
|
|
85
|
-
if (related !== null) {
|
|
86
|
-
const files = changedFiles(config.root, base, sincePush, "related tests");
|
|
88
|
+
if (affected || related !== null) {
|
|
89
|
+
const files = changedFiles(config.root, base, sincePush, "related tests", affected);
|
|
87
90
|
if (files === null || files.length > 0) {
|
|
88
|
-
const code = await runCommand(config.root, related, files ?? []);
|
|
91
|
+
const code = related !== null ? await runCommand(config.root, related, files ?? []) : await affectedTests(config.root, files);
|
|
89
92
|
if (code !== 0) return code;
|
|
90
93
|
}
|
|
91
94
|
}
|
|
@@ -95,3 +98,97 @@ export async function runCheckCommands(config, { sincePush = false } = {}) {
|
|
|
95
98
|
}
|
|
96
99
|
return 0;
|
|
97
100
|
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
async function affectedTests(root, changed) {
|
|
104
|
+
const selected = changed === null ? null : await importingTests(root, changed);
|
|
105
|
+
if (selected?.length && selected.join(" ").length < 24000) return runCommand(root, `"${process.execPath}" --test`, selected);
|
|
106
|
+
const pkg = JSON.parse(readFileSync(path.join(root, "package.json"), "utf8"));
|
|
107
|
+
if (!pkg.scripts?.test) { console.log("SKIP no test script"); return 0; }
|
|
108
|
+
const manager = existsSync(path.join(root, "pnpm-lock.yaml")) ? "pnpm" : existsSync(path.join(root, "yarn.lock")) ? "yarn" : "npm";
|
|
109
|
+
return runCommand(root, `${manager} test`);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const extension = /\.(?:[cm]?[jt]s|[jt]sx)$/;
|
|
113
|
+
const isTest = (file) => /\.test\.(?:[cm]?[jt]s|[jt]sx)$/.test(file);
|
|
114
|
+
const inSuite = (file) => /^packages\/qc-harness\/src\/.+\.test\.mjs$/.test(file) || file === "evals/agents/run.test.mjs";
|
|
115
|
+
|
|
116
|
+
async function testGraph(root) {
|
|
117
|
+
const allFiles = await repoFiles(root);
|
|
118
|
+
const files = allFiles.filter((file) => extension.test(file));
|
|
119
|
+
const known = new Set(files), readers = new Map(), uncertainFiles = new Set();
|
|
120
|
+
const testTexts = new Map();
|
|
121
|
+
for (const file of files) {
|
|
122
|
+
const text = readFileSync(path.join(root, file), "utf8");
|
|
123
|
+
if (inSuite(file)) testTexts.set(file, text);
|
|
124
|
+
let uncertain = false;
|
|
125
|
+
const add = (value) => {
|
|
126
|
+
if (/\\|\$\{/.test(value)) { uncertain = true; return; }
|
|
127
|
+
if (value.startsWith(".")) {
|
|
128
|
+
const target = path.posix.normalize(path.posix.join(path.posix.dirname(file), value));
|
|
129
|
+
if (!known.has(target)) uncertain = true;
|
|
130
|
+
else readers.set(target, [...(readers.get(target) ?? []), file]);
|
|
131
|
+
} else if (!value.startsWith("node:")) uncertain = true;
|
|
132
|
+
};
|
|
133
|
+
// Retain original matches when comment stripping misreads regexes or nested templates.
|
|
134
|
+
const stripped = text.replace(/(["'`])(?:\\[\s\S]|(?!\1)[^\\])*\1|\/\*[\s\S]*?\*\/|\/\/[^\r\n]*/g, (token) => token.startsWith("/") ? " " : token);
|
|
135
|
+
for (const source of new Set([text, stripped])) {
|
|
136
|
+
for (const match of source.matchAll(/\b(?:import|from)\s*(["'`])((?:\\[\s\S]|(?!\1)[^\\\r\n])*)\1/g)) add(match[2]);
|
|
137
|
+
for (const match of source.matchAll(/\b(?:import|require)\s*\(\s*/g)) {
|
|
138
|
+
const literal = /^(["'`])((?:\\[\s\S]|(?!\1)[^\\\r\n])*)\1\s*(?=[,)])/.exec(source.slice(match.index + match[0].length));
|
|
139
|
+
if (literal) add(literal[2]);
|
|
140
|
+
else uncertain = true;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (uncertain) uncertainFiles.add(file);
|
|
144
|
+
}
|
|
145
|
+
return { allFiles, files, known, readers, testTexts, uncertainFiles };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function coveringTests(file, { known, readers, testTexts }, namedTests) {
|
|
149
|
+
const seen = new Set([file]), queue = [file], covered = new Set();
|
|
150
|
+
const sibling = file.replace(extension, (suffix) => `.test${suffix}`);
|
|
151
|
+
if (known.has(sibling) && inSuite(sibling)) covered.add(sibling);
|
|
152
|
+
for (const next of queue) {
|
|
153
|
+
if (isTest(next) && inSuite(next)) covered.add(next);
|
|
154
|
+
const basename = path.posix.basename(next);
|
|
155
|
+
if (namedTests && !namedTests.has(basename)) {
|
|
156
|
+
const matches = new Set();
|
|
157
|
+
for (const [test, text] of testTexts) if (text.includes(basename)) matches.add(test);
|
|
158
|
+
namedTests.set(basename, matches);
|
|
159
|
+
}
|
|
160
|
+
for (const test of namedTests?.get(basename) ?? []) covered.add(test);
|
|
161
|
+
for (const reader of readers.get(next) ?? []) if (!seen.has(reader)) { seen.add(reader); queue.push(reader); }
|
|
162
|
+
}
|
|
163
|
+
return covered;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Certain coverage only: uncertain loaders belong to the conservative check runner. */
|
|
167
|
+
export async function testsCovering(root, paths) {
|
|
168
|
+
const graph = await testGraph(root);
|
|
169
|
+
const result = new Map();
|
|
170
|
+
for (const entry of paths) {
|
|
171
|
+
const file = path.posix.normalize(entry.replace(/\\/g, "/")).replace(/\/$/, "");
|
|
172
|
+
const children = graph.allFiles.filter((candidate) => file === "." || candidate.startsWith(`${file}/`));
|
|
173
|
+
for (const target of children.length ? children : [file]) {
|
|
174
|
+
result.set(target, [...coveringTests(target, graph)].sort());
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return result;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async function importingTests(root, changed) {
|
|
181
|
+
if (changed.some((file) => !file.startsWith("packages/qc-harness/src/") || !extension.test(file) || !existsSync(path.join(root, file)))) return null;
|
|
182
|
+
try {
|
|
183
|
+
const graph = await testGraph(root);
|
|
184
|
+
const tests = new Set(graph.files.filter((file) => /^packages\/qc-harness\/src\/gates\/[^/]+\.test\.mjs$/.test(file)));
|
|
185
|
+
const namedTests = new Map();
|
|
186
|
+
// Unknown loaders can read any changed module; cover their readers too, or run the full suite.
|
|
187
|
+
for (const file of new Set([...changed, ...graph.uncertainFiles])) {
|
|
188
|
+
const covered = coveringTests(file, graph, namedTests);
|
|
189
|
+
if (!covered.size) return null;
|
|
190
|
+
for (const test of covered) tests.add(test);
|
|
191
|
+
}
|
|
192
|
+
return [...tests].sort();
|
|
193
|
+
} catch { return null; }
|
|
194
|
+
}
|
|
@@ -1,17 +1,97 @@
|
|
|
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
|
+
|
|
15
95
|
test("the e2e warning names qc e2e when the merge base is unavailable", (t) => {
|
|
16
96
|
const root = fixture(t, { e2e: record, base: "missing-ref" });
|
|
17
97
|
const run = spawnSync(process.execPath, [qc, "e2e"], { cwd: root, encoding: "utf8" });
|
|
@@ -37,7 +117,7 @@ test("an invalid feature switch pattern prints a config error without a stack tr
|
|
|
37
117
|
|
|
38
118
|
function fixture(t, check = {}) {
|
|
39
119
|
const root = mkdtempSync(path.join(tmpdir(), "qc-check-commands-"));
|
|
40
|
-
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
120
|
+
t.after(() => rmSync(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }));
|
|
41
121
|
git(root, "init", "-q", "-b", "main");
|
|
42
122
|
git(root, "config", "user.name", "QC test");
|
|
43
123
|
git(root, "config", "user.email", "qc@example.test");
|
|
@@ -56,14 +136,14 @@ function fixture(t, check = {}) {
|
|
|
56
136
|
}
|
|
57
137
|
|
|
58
138
|
function check(root, args = [], input, env = process.env) {
|
|
59
|
-
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 } });
|
|
60
140
|
}
|
|
61
141
|
|
|
62
142
|
// Fixture fragment with commits before and after the push.
|
|
63
143
|
function sincePushFixture(t, config, { push = true, changes = true } = {}) {
|
|
64
144
|
const root = fixture(t, config);
|
|
65
145
|
const origin = mkdtempSync(path.join(tmpdir(), "qc-check-origin-"));
|
|
66
|
-
t.after(() => rmSync(origin, { recursive: true, force: true }));
|
|
146
|
+
t.after(() => rmSync(origin, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }));
|
|
67
147
|
git(origin, "init", "-q", "--bare");
|
|
68
148
|
git(root, "remote", "add", "origin", origin);
|
|
69
149
|
writeFileSync(path.join(root, "early.mjs"), "export {};\n");
|
|
@@ -179,7 +259,7 @@ test("repository commands run in order and stop with the failing command's exit
|
|
|
179
259
|
|
|
180
260
|
test("commands resolve PATH shims and preserve literal arguments and exit codes", (t) => {
|
|
181
261
|
const bin = mkdtempSync(path.join(tmpdir(), "qc command shims "));
|
|
182
|
-
t.after(() => rmSync(bin, { recursive: true, force: true }));
|
|
262
|
+
t.after(() => rmSync(bin, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }));
|
|
183
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';
|
|
184
264
|
if (process.platform === "win32") {
|
|
185
265
|
writeFileSync(path.join(bin, "shim.cjs"), source);
|
|
@@ -268,3 +348,197 @@ test("related excludes staged deletions and receives the new path of a staged re
|
|
|
268
348
|
assert.equal(run.status, 0, run.stderr);
|
|
269
349
|
assert.deepEqual(JSON.parse(readFileSync(path.join(root, "args.json"), "utf8")), ["renamed file.mjs"]);
|
|
270
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
|
+
});
|