@nodii/dev 0.6.166 → 0.6.169
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/README.md +1 -0
- package/dist/cli.js +13 -0
- package/dist/core.js +1 -1
- package/dist/red-run.js +307 -0
- package/dist/review.js +32 -23
- package/dist/surface.js +17 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -105,6 +105,7 @@ nodii-dev lane check KEY --gate 'pnpm typecheck' --gate 'pnpm lint' --gate 'nodi
|
|
|
105
105
|
- Each package runs its tests with its own `test` script's runner and flags, and the selected files replace the script's paths. A script that is not one runner call (`bun run gate && bun test`) runs whole.
|
|
106
106
|
- `lane check` refuses a full-suite gate (`GATE_FULL_SUITE`) unless `--full-suite` is passed. A whole suite also means one workspace's or project's whole suite (`npm test -w X`, `pnpm --filter X test`, `jest --selectProjects web`), a runner given no path (`node --test`, `npx playwright test`, `pytest`, `go test ./...`), and any of these inside `sh -c`. From a lane's own config, `--full-suite` is refused too (`FULL_SUITE_LANE_REFUSED`, hub-485).
|
|
107
107
|
- The review body carries the gates receipt (`gates`): each gate's command, exit code and commit for this head and base, so Dev can refuse a whole-suite gate itself (hub-485). A `gates` field in a hand-written review file is never sent.
|
|
108
|
+
- Red, then green (hub-485). Before the change, `nodii-dev lane test KEY --red -- 'node --test test/a.test.js'` records the tests for it failing at a clean commit, as a signed red `test` receipt on the lane (`--check NAME` for work with no behaviour to test). Each green gate in the receipt names the repo-relative `files` it ran, so Dev can check that every red test is green at the head; a named check is green when a gate runs its exact command.
|
|
108
109
|
|
|
109
110
|
## Heavy work: one machine-wide slot queue
|
|
110
111
|
|
package/dist/cli.js
CHANGED
|
@@ -116,6 +116,7 @@ import {
|
|
|
116
116
|
nextCommand,
|
|
117
117
|
peopleCommand,
|
|
118
118
|
} from "./lanes.js";
|
|
119
|
+
import { laneTestCommand } from "./red-run.js";
|
|
119
120
|
import {
|
|
120
121
|
amendmentGuard,
|
|
121
122
|
amendLaneCommand,
|
|
@@ -480,6 +481,11 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
480
481
|
# locked decision that settles it (MW4-27), deferred an open issue. Records the
|
|
481
482
|
# round once nothing blocks; Dev checks each citation and refuses code-check
|
|
482
483
|
# findings, blockers, and security, tenancy, PII and money findings (MW2-41)
|
|
484
|
+
lane test <key> --red [--check NAME] -- <command>
|
|
485
|
+
# hub-485: before the change, record the tests for it failing at a clean
|
|
486
|
+
# commit; attaches a signed red test receipt. Names the test files
|
|
487
|
+
# (or --check NAME for work with no behaviour to test); refuses a whole
|
|
488
|
+
# suite, a masked exit status and a run that passes
|
|
483
489
|
lane check <key> [--gate CMD ...] [--critical] [--max-iterations N] [--picker agent]
|
|
484
490
|
# from the lane's worktree: the rules, Figma and code checks over the
|
|
485
491
|
# diff against origin/main (DEV-REV); --gate runs gates 1-5 in order
|
|
@@ -936,6 +942,13 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
936
942
|
process.exitCode = exitCode;
|
|
937
943
|
return;
|
|
938
944
|
}
|
|
945
|
+
// hub-485: lane test reads its own words (its --check takes a value, and the command follows `--`).
|
|
946
|
+
if (argv[0] === "lane" && argv[1] === "test") {
|
|
947
|
+
const result = await laneTestCommand(argv.slice(2));
|
|
948
|
+
emit(result.payload, argv.slice(0, argv.includes("--") ? argv.indexOf("--") : argv.length).includes("--json"), result.human);
|
|
949
|
+
if (result.exitCode) process.exitCode = result.exitCode;
|
|
950
|
+
return;
|
|
951
|
+
}
|
|
939
952
|
const { args, flags: f } = parseArgs(argv);
|
|
940
953
|
const json = Boolean(f.json);
|
|
941
954
|
const [command, action, ...rest] = args;
|
package/dist/core.js
CHANGED
|
@@ -4,7 +4,7 @@ import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
|
4
4
|
import { homedir, platform } from "node:os";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
6
|
|
|
7
|
-
export const VERSION = "0.6.
|
|
7
|
+
export const VERSION = "0.6.169";
|
|
8
8
|
export const configPath = () =>
|
|
9
9
|
process.env.NODII_DEV_CONFIG_PATH ??
|
|
10
10
|
join(homedir(), ".config/nodii-dev/config.json");
|
package/dist/red-run.js
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hub-485, the red-run half (MW2-20; the operator, 15 Nov 2026: "the lanes starts with red tests and to pass must make
|
|
3
|
+
* a test green"). A lane declares the tests for its change by recording them failing before it builds:
|
|
4
|
+
* `nodii-dev lane test <key> --red -- <command>` attaches a signed `test` receipt with `red: true`, the
|
|
5
|
+
* commit, and the repo-relative files it ran. lane check's gates receipt then says which red files and
|
|
6
|
+
* named checks each gate ran green at the head, and Dev refuses a passing review that leaves one uncovered.
|
|
7
|
+
* The shape is agreed with the hub on the issue; Dev classifies and checks every command itself.
|
|
8
|
+
*/
|
|
9
|
+
import { posix } from "node:path";
|
|
10
|
+
import { CliError, devRequest, encode } from "./core.js";
|
|
11
|
+
import { inferGitContext } from "./lanes.js";
|
|
12
|
+
import { readPolicy as readRepoPolicy } from "./repo-policy.js";
|
|
13
|
+
import { devDown, queuePending, receiptEvidenceBody, redactCommand, writeReceipt as writeSignedReceipt } from "./receipt.js";
|
|
14
|
+
import { fullSuiteGate, operandsOf, privateStore, runnerWords, selfSizedGate, shellCommands, shellScript, worktreeCommitted } from "./review.js";
|
|
15
|
+
|
|
16
|
+
/** The lane's red runs in this worktree's git dir, by lane: a local record; Dev holds the signed receipts. */
|
|
17
|
+
export const RED_RUNS = "nodii-red-runs.json";
|
|
18
|
+
export const LANE_TEST_USAGE = "nodii-dev lane test <key> --red [--check NAME] -- <command>";
|
|
19
|
+
|
|
20
|
+
const PACKAGE_MANAGERS = new Set(["npm", "pnpm", "yarn", "bun"]);
|
|
21
|
+
// A path names a file or a directory (`test/a.test.js`, `internal/billing`); a bare word is a name filter.
|
|
22
|
+
const pathLike = (word) => word.includes("/") || /\.[A-Za-z0-9]+$/.test(word);
|
|
23
|
+
|
|
24
|
+
/** The paths one simple command (already unwrapped) hands a test runner, as it wrote them. */
|
|
25
|
+
function handed(words) {
|
|
26
|
+
const [tool, ...args] = words;
|
|
27
|
+
const name = (tool ?? "").split("/").pop();
|
|
28
|
+
const operands = operandsOf(args, { pm: PACKAGE_MANAGERS.has(name) });
|
|
29
|
+
if (name === "bun" && operands[0] === "test") return operands.slice(1);
|
|
30
|
+
if (PACKAGE_MANAGERS.has(name)) {
|
|
31
|
+
// `npm test -- a.test.js`, `npm run test:unit -- a.test.js`: the script gets the paths.
|
|
32
|
+
if (["run", "run-script"].includes(operands[0])) return operands.slice(2);
|
|
33
|
+
return operands[0] === "test" || operands[0] === "t" ? operands.slice(1) : [];
|
|
34
|
+
}
|
|
35
|
+
if (name === "node") return args.includes("--test") ? operands : [];
|
|
36
|
+
if (["vitest", "jest"].includes(name)) return operands.filter((word) => !["run", "watch"].includes(word));
|
|
37
|
+
if (name === "playwright" || name === "go") return operands[0] === "test" ? operands.slice(1) : [];
|
|
38
|
+
if (name === "pytest") return operands;
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// A package manager's flags that run the script in another directory (not a workspace name).
|
|
43
|
+
const DIRECTORY_FLAGS = new Set(["--prefix", "-C", "--dir", "--cwd"]);
|
|
44
|
+
/** DIR joined with a `cd` or directory-flag TARGET, or null when it leaves the repository or cannot be placed. */
|
|
45
|
+
function placeDir(dir, target) {
|
|
46
|
+
if (dir === null || !target || /^[/~-]/.test(target) || /[$`]/.test(target)) return null;
|
|
47
|
+
const joined = posix.normalize(posix.join(dir, target)).replace(/\/+$/, "");
|
|
48
|
+
if (joined === ".." || joined.startsWith("../")) return null;
|
|
49
|
+
return joined === "." ? "" : joined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The repo-relative paths a command hands a test runner, and whether any could not be placed in the repository. */
|
|
53
|
+
function runnerScan(command, cwd = "") {
|
|
54
|
+
const paths = [];
|
|
55
|
+
let outside = false;
|
|
56
|
+
let dir = cwd;
|
|
57
|
+
for (const part of shellCommands(String(command ?? "").trim())) {
|
|
58
|
+
const nested = shellScript(part);
|
|
59
|
+
if (nested !== null) { const inner = runnerScan(nested, dir); paths.push(...inner.paths); outside ||= inner.outside; continue; }
|
|
60
|
+
const words = runnerWords(part);
|
|
61
|
+
if (words[0] === "cd") { dir = placeDir(dir, words[1]); outside ||= dir === null; continue; }
|
|
62
|
+
let here = dir;
|
|
63
|
+
const name = (words[0] ?? "").split("/").pop();
|
|
64
|
+
if (PACKAGE_MANAGERS.has(name)) {
|
|
65
|
+
// `npm --prefix packages/dev test -- a.test.js`: the script runs in packages/dev.
|
|
66
|
+
for (const [i, word] of words.entries()) {
|
|
67
|
+
const [flag, inline] = word.split("=");
|
|
68
|
+
if (DIRECTORY_FLAGS.has(flag)) { here = placeDir(here, inline ?? words[i + 1]); outside ||= here === null; }
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
for (const word of handed(words).filter(pathLike)) {
|
|
72
|
+
const path = word.startsWith("/") ? null : placeDir(here, word);
|
|
73
|
+
if (path) paths.push(path); else outside = true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return { paths: [...new Set(paths)], outside };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The repo-relative test paths a command hands a test runner (agreed on the issue: paths read against the `cd`): `cd packages/dev &&
|
|
81
|
+
* node --test test/a.test.js` names `packages/dev/test/a.test.js`. CWD is the command's directory relative
|
|
82
|
+
* to the repository root. A path outside the repository, or under a directory this tool cannot place, is
|
|
83
|
+
* dropped, never sent.
|
|
84
|
+
*/
|
|
85
|
+
export const runnerPaths = (command, cwd = "") => runnerScan(command, cwd).paths;
|
|
86
|
+
|
|
87
|
+
// Governor pass: flags that load code of the agent's own before the tests (`node -r ./boom.js` can fail every run).
|
|
88
|
+
// The hub's parity list adds node's `-e`, `--eval` and `--print`.
|
|
89
|
+
// Kebab-case spellings (jest, vitest), pytest's `-o` ini override, and node's env files, which can set NODE_OPTIONS.
|
|
90
|
+
const CODE_FLAGS = new Set(["-r", "--require", "--import", "--loader", "--experimental-loader", "--preload", "--setupFiles", "--setupFilesAfterEnv", "--globalSetup", "--globalTeardown",
|
|
91
|
+
"--setup-files", "--setup-files-after-env", "--global-setup", "--global-teardown", "-p", "-e", "--eval", "--print", "-o", "--override-ini", "--env-file", "--env-file-if-exists"]);
|
|
92
|
+
// Flags a wrapper (npm, npx) takes before the runner: runnerWords drops some of them, so they are read from the raw words.
|
|
93
|
+
const RAW_CODE_FLAGS = new Set(["--node-options", "--env-file", "--env-file-if-exists"]);
|
|
94
|
+
// go's `-race`, `-run`, `-p N` and `-parallel N` load nothing; `-exec` and `-toolexec` run a program of the agent's choosing.
|
|
95
|
+
const GO_CODE_FLAGS = new Set(["-exec", "-toolexec"]);
|
|
96
|
+
// go reads `--run` as `-run` and `-test.run` as the test binary's own `-run`; `-args` hands the rest to the binary.
|
|
97
|
+
const GO_NO_COVER_FLAGS = new Set(["-run", "-skip", "-list", "-args"]);
|
|
98
|
+
const goFlag = (word) => word.split("=")[0].replace(/^--/, "-").replace(/^-test\./, "-");
|
|
99
|
+
// Environment variables that make a runner load code or take flags before the tests: node, bun, npm, go and pytest.
|
|
100
|
+
const CODE_ENV = /^['"]?(NODE_OPTIONS|BUN_OPTIONS|GOFLAGS|PYTEST_ADDOPTS|PYTEST_PLUGINS|npm_config_node_options)=/i;
|
|
101
|
+
// Governor pass: flags that select or skip tests by name, so a gate that has them may have run no test at all.
|
|
102
|
+
const FILTER_FLAGS = new Set(["-t", "--testNamePattern", "--test-name-pattern", "--test-skip-pattern", "--test-only", "--passWithNoTests", "--pass-with-no-tests", "-k", "-run", "--grep", "-g", "--grep-invert",
|
|
103
|
+
"--testPathIgnorePatterns", "--test-path-ignore-patterns", "--testPathPattern", "--test-path-pattern"]);
|
|
104
|
+
// Parity with the hub: flags that list, shard, pick or skip test files, or print help, so the gate may have run none of its paths.
|
|
105
|
+
const NO_COVER_FLAGS = new Set([...FILTER_FLAGS, "--listTests", "--list-tests", "--list", "--collect-only", "--co", "--help", "-h", "--version", "--shard", "--test-shard", "--only", "--exclude"]);
|
|
106
|
+
|
|
107
|
+
/** The package-manager command's own words: those before its first operand (the script or subcommand name). */
|
|
108
|
+
const ownWords = (words) => { const at = words.findIndex((word, i) => i > 0 && !word.startsWith("-")); return at === -1 ? words.length : at; };
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* What in one simple command (not yet unwrapped) loads code before the tests: a code flag, a joined `-r…`/`-p…`,
|
|
112
|
+
* a wrapper's node options or env file, or a runner's options in the environment (NODE_OPTIONS, GOFLAGS, …).
|
|
113
|
+
*/
|
|
114
|
+
function codeLoads(part) {
|
|
115
|
+
const raw = part.split(/\s+/).map((word) => word.replace(/^['"]+|['"]+$/g, ""));
|
|
116
|
+
const env = raw.map((word) => CODE_ENV.exec(word)?.[1]).filter(Boolean);
|
|
117
|
+
const wrapped = raw.filter((word) => RAW_CODE_FLAGS.has(word.split("=")[0]));
|
|
118
|
+
const words = runnerWords(part);
|
|
119
|
+
const name = (words[0] ?? "").split("/").pop();
|
|
120
|
+
// npm, pnpm and yarn take `-r` (--recursive) before the script; after it, or after `--`, it is the runner's --require.
|
|
121
|
+
const own = ["npm", "pnpm", "yarn"].includes(name) ? ownWords(words) : 0;
|
|
122
|
+
const flags = words.slice(1).filter((word, i) => {
|
|
123
|
+
const flag = word.split("=")[0];
|
|
124
|
+
if (name === "go") return GO_CODE_FLAGS.has(goFlag(word));
|
|
125
|
+
if (word === "-r" && i + 1 < own) return false;
|
|
126
|
+
if (CODE_FLAGS.has(flag)) return true;
|
|
127
|
+
// `-r./boom.js`, `-p./boom.js`: a joined value. pytest's joined `-rA` picks the report.
|
|
128
|
+
return /^-[rp][^-]/.test(word) && !(name === "pytest" && word.startsWith("-r"));
|
|
129
|
+
});
|
|
130
|
+
return [...new Set([...env, ...wrapped, ...flags])];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Whether a green gate may have run none of the paths it names: it filters, lists, shards or loads code first. */
|
|
134
|
+
function coversNothing(command, depth = 0) {
|
|
135
|
+
return shellCommands(String(command ?? "").trim()).some((part) => {
|
|
136
|
+
const nested = shellScript(part);
|
|
137
|
+
if (nested !== null) return depth < 4 && coversNothing(nested, depth + 1);
|
|
138
|
+
const words = runnerWords(part);
|
|
139
|
+
const name = (words[0] ?? "").split("/").pop();
|
|
140
|
+
if (name === "go") { if (words.some((word) => GO_NO_COVER_FLAGS.has(goFlag(word)))) return true; }
|
|
141
|
+
else if (words.some((word) => word.startsWith("-") && (NO_COVER_FLAGS.has(word.split("=")[0]) || /^-[tk][^-]/.test(word)))) return true;
|
|
142
|
+
if (name === "vitest" && words.slice(1).includes("list")) return true;
|
|
143
|
+
return codeLoads(part).length > 0;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Why a red run's command is not one test run of its own, or null. A red run is at most one `cd DIR &&` and
|
|
149
|
+
* then one command, which loads no code of the agent's own: anything chained after it (`&& false`) or
|
|
150
|
+
* loaded before the tests (`-r ./boom.js`) could fail every time, whatever the tests do.
|
|
151
|
+
*/
|
|
152
|
+
function notOneRunner(command, { named }) {
|
|
153
|
+
const text = String(command).trim();
|
|
154
|
+
const parts = shellCommands(text);
|
|
155
|
+
const nested = parts.length === 1 ? shellScript(parts[0]) : null;
|
|
156
|
+
if (nested !== null) return notOneRunner(nested, { named });
|
|
157
|
+
if (parts.length > 2 || (parts.length === 2 && runnerWords(parts[0])[0] !== "cd")) return "it chains more than one `cd DIR &&` and one command";
|
|
158
|
+
const last = runnerWords(parts.at(-1));
|
|
159
|
+
if (last[0] === "cd") return "it runs nothing after `cd`";
|
|
160
|
+
const loads = codeLoads(parts.at(-1));
|
|
161
|
+
if (loads.length) return `${loads.join(", ")} loads code before the tests`;
|
|
162
|
+
if (!named && !handed(last).length) return "it hands no test runner a test path";
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const GIT_VALUE_FLAGS = new Set(["-c", "-C", "--git-dir", "--work-tree", "--namespace"]);
|
|
167
|
+
/**
|
|
168
|
+
* What decides a command's exit status other than the command itself, or null (MW2-16): a pipe, `||`, `;`,
|
|
169
|
+
* a background `&`, a newline, `!`, `eval`, `trap`, a command substitution, a here-doc or here-string, or a
|
|
170
|
+
* chained commit or push. Dev refuses such a gate and ignores such a red run, so this tool refuses it first.
|
|
171
|
+
*/
|
|
172
|
+
export function maskedCommand(command, depth = 0) {
|
|
173
|
+
const text = String(command ?? "").trim();
|
|
174
|
+
let quote = null;
|
|
175
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
176
|
+
const char = text[i];
|
|
177
|
+
if (quote) { if (char === quote) quote = null; else if (quote === '"' && (char === "`" || text.startsWith("$(", i))) return char === "`" ? "`" : "$("; continue; }
|
|
178
|
+
if (char === "'" || char === '"') { quote = char; continue; }
|
|
179
|
+
const two = text.slice(i, i + 2);
|
|
180
|
+
if (two === "&&") { i += 1; continue; }
|
|
181
|
+
if (two === "||") return "||";
|
|
182
|
+
if (two === "$(") return "$(";
|
|
183
|
+
if (two === "<<") return "<<";
|
|
184
|
+
if (char === "`") return "`";
|
|
185
|
+
if (char === ";") return ";";
|
|
186
|
+
if (char === "\n") return "newline";
|
|
187
|
+
if (char === "|" && text[i - 1] !== ">") return "|";
|
|
188
|
+
if (char === "&" && text[i - 1] !== ">" && text[i + 1] !== ">") return "&";
|
|
189
|
+
}
|
|
190
|
+
for (const part of shellCommands(text)) {
|
|
191
|
+
const nested = shellScript(part);
|
|
192
|
+
if (nested !== null) { const inner = depth < 4 ? maskedCommand(nested, depth + 1) : null; if (inner) return inner; continue; }
|
|
193
|
+
const words = part.split(/\s+/);
|
|
194
|
+
if (words[0] === "!") return "!";
|
|
195
|
+
const [tool, ...args] = runnerWords(part);
|
|
196
|
+
const name = (tool ?? "").split("/").pop();
|
|
197
|
+
if (name === "trap") return "trap";
|
|
198
|
+
if (name === "eval") return "eval";
|
|
199
|
+
if (name === "git") {
|
|
200
|
+
const sub = args.find((word, i) => !word.startsWith("-") && !GIT_VALUE_FLAGS.has(args[i - 1] ?? ""));
|
|
201
|
+
if (sub === "commit" || sub === "push") return `git ${sub}`;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* What a gate ran green at the head, for Dev to match against the lane's red runs (agreed on the issue: paths read against the `cd`): the
|
|
209
|
+
* repo-relative files it ran. `nodii-dev test affected --run` works out its files before it runs, so they
|
|
210
|
+
* come from that analysis on the gate's own base, with each package it ran whole. A gate that filters tests
|
|
211
|
+
* by name, lists, shards or picks them, or loads code first, may have run none, so it names no file. Named checks are matched on Dev by the gate's exact
|
|
212
|
+
* command (governor pass: a check name from a local file would be the agent's own say-so).
|
|
213
|
+
*/
|
|
214
|
+
export async function greenFields(command, { exitCode, affectedTests } = {}) {
|
|
215
|
+
if (exitCode !== 0) return {};
|
|
216
|
+
if (coversNothing(command)) return {};
|
|
217
|
+
let files = runnerPaths(command);
|
|
218
|
+
if (selfSizedGate(command) && affectedTests) {
|
|
219
|
+
const words = String(command).trim().split(/\s+/);
|
|
220
|
+
const at = words.findIndex((word) => word === "--base" || word.startsWith("--base="));
|
|
221
|
+
const base = at === -1 ? undefined : words[at].includes("=") ? words[at].slice(7) : words[at + 1];
|
|
222
|
+
const result = await affectedTests(base).catch(() => null);
|
|
223
|
+
files = result ? [...new Set([...(result.tests ?? []), ...(result.jobs ?? []).filter((job) => job.full && job.dir).map((job) => job.dir)])] : [];
|
|
224
|
+
}
|
|
225
|
+
// Dev takes at most 500 files a run.
|
|
226
|
+
return files.length ? { files: files.slice(0, 500) } : {};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const usage = (message) => new CliError("USAGE", `${message}. ${LANE_TEST_USAGE}`, 2);
|
|
230
|
+
|
|
231
|
+
/** `lane test` reads its own words: `--check NAME` here is a value, where elsewhere `--check` is a switch. */
|
|
232
|
+
function parseLaneTest(argv) {
|
|
233
|
+
const boundary = argv.indexOf("--");
|
|
234
|
+
const options = boundary === -1 ? argv : argv.slice(0, boundary);
|
|
235
|
+
const command = boundary === -1 ? "" : argv.slice(boundary + 1).join(" ").trim();
|
|
236
|
+
const parsed = { key: null, red: false, checks: [], count: null, json: false };
|
|
237
|
+
for (let i = 0; i < options.length; i += 1) {
|
|
238
|
+
const word = options[i];
|
|
239
|
+
if (word === "--red") parsed.red = true;
|
|
240
|
+
else if (word === "--json") parsed.json = true;
|
|
241
|
+
else if (word === "--check" || word === "--count") {
|
|
242
|
+
const value = options[i + 1];
|
|
243
|
+
if (!value || value.startsWith("--")) throw usage(`${word} needs a value`);
|
|
244
|
+
if (word === "--check") parsed.checks.push(value); else parsed.count = value;
|
|
245
|
+
i += 1;
|
|
246
|
+
} else if (word.startsWith("-")) throw usage(`lane test does not take ${word}`);
|
|
247
|
+
else if (parsed.key === null) parsed.key = word;
|
|
248
|
+
else throw usage(`lane test takes one <key>, got ${word} too; put the command after \`--\``);
|
|
249
|
+
}
|
|
250
|
+
if (!parsed.key) throw usage("lane test needs <key>");
|
|
251
|
+
if (!parsed.red) throw usage("lane test needs --red: the green run is lane check's --gate");
|
|
252
|
+
if (!command) throw usage("lane test needs the command after `--`");
|
|
253
|
+
return { ...parsed, command };
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** `nodii-dev lane test <key> --red [--check NAME] -- <command>`. */
|
|
257
|
+
export async function laneTestCommand(argv, deps = {}) {
|
|
258
|
+
const {
|
|
259
|
+
gitContext = inferGitContext, committed = worktreeCommitted, store: givenStore, writeReceipt = writeSignedReceipt,
|
|
260
|
+
evidenceBody = receiptEvidenceBody, request = devRequest, readPolicy = readRepoPolicy, queue = queuePending,
|
|
261
|
+
} = deps;
|
|
262
|
+
const { key, checks, count, command } = parseLaneTest(argv);
|
|
263
|
+
if (count !== null)
|
|
264
|
+
throw new CliError("RED_COUNT_NOT_BUILT", `${key}: --count is not built yet. Dev counts a red run only from a failing test receipt, and a count command exits 0, so how a count's red run is marked is still to be agreed with the hub on hub-485. Record the tests or a named check that fails (--check NAME) instead.`, 2);
|
|
265
|
+
const context = await gitContext();
|
|
266
|
+
const cwd = context.worktree;
|
|
267
|
+
if (!(await committed(cwd)))
|
|
268
|
+
throw new CliError("RED_RUN_DIRTY", `${key}: commit the red tests first. A red run names the commit it ran at, so Dev can tell it from the head that makes it green (MW2-20); this worktree has uncommitted or untracked changes.`, 2);
|
|
269
|
+
const fullScript = (await readPolicy(cwd).catch(() => null))?.tests?.full ?? "test";
|
|
270
|
+
if (fullSuiteGate(command, fullScript))
|
|
271
|
+
throw new CliError("GATE_FULL_SUITE", `${key}: \`${command}\` runs the whole test suite, which would declare every test as this change's (MW2-20). Name the test files for this change.`, 2, { command });
|
|
272
|
+
const masked = maskedCommand(command);
|
|
273
|
+
if (masked)
|
|
274
|
+
throw new CliError("GATE_EXIT_MASKED", `${key}: in \`${command}\`, ${masked} decides the exit status, not the tests (MW2-16), so Dev would not count it as red. Run the tests on their own.`, 2, { command, masked });
|
|
275
|
+
const shape = notOneRunner(command, { named: checks.length > 0 });
|
|
276
|
+
if (shape)
|
|
277
|
+
throw new CliError("RED_RUN_NOT_ONE_RUNNER", `${key}: \`${command}\` is not one test run of its own: ${shape}. A red run is at most \`cd DIR &&\` and then the tests, so only they decide that it fails (MW2-20).`, 2, { command });
|
|
278
|
+
const { paths: files, outside } = runnerScan(command);
|
|
279
|
+
if (outside)
|
|
280
|
+
throw new CliError("RED_RUN_PATH_OUTSIDE", `${key}: \`${command}\` runs from or names a path outside this repository, or one this tool cannot place (\`/\`, \`~\`, \`..\`, a variable). Dev reads red files relative to the repository root; run from the root or \`cd\` into a directory below it.`, 2, { command });
|
|
281
|
+
if (checks.length && redactCommand(command) !== command)
|
|
282
|
+
throw new CliError("RED_CHECK_COMMAND_REDACTED", `${key}: Dev matches a named check by its exact command, and \`${command}\` would be stored redacted (it carries a NAME=value, a --flag=value or a secret-shaped word), so no gate could ever match it. Move the value into the environment or a file the command reads.`, 2);
|
|
283
|
+
if (!files.length && !checks.length)
|
|
284
|
+
throw new CliError("RED_RUN_EMPTY", `${key}: \`${command}\` hands a test runner no test file or directory, so it declares nothing. Name the test files (node --test test/a.test.js), or pass --check NAME for work with no behaviour to test.`, 2, { command });
|
|
285
|
+
const details = { red: true, authPosture: "component", scope: { files, testCount: null, checks } };
|
|
286
|
+
const { receipt, path, failed } = await writeReceipt({ kind: "test", lane: key, run: command, details }, { cwd });
|
|
287
|
+
if (!failed)
|
|
288
|
+
throw new CliError("RED_RUN_PASSED", `${key}: \`${command}\` passed at ${receipt.commit ?? "this commit"}, so it is not red and nothing was attached. Write the test first, commit it, and record it failing before the change (MW2-20).`, 1);
|
|
289
|
+
const body = await evidenceBody(path, key);
|
|
290
|
+
const url = `/api/v1/lanes/${encode(key)}/evidence`;
|
|
291
|
+
let queued = null;
|
|
292
|
+
try {
|
|
293
|
+
await request("POST", url, body);
|
|
294
|
+
} catch (error) {
|
|
295
|
+
if (!devDown(error)) throw error;
|
|
296
|
+
queued = await queue(url, body, { lane: key });
|
|
297
|
+
}
|
|
298
|
+
const store = givenStore ?? privateStore(cwd);
|
|
299
|
+
const kept = (await store.read(RED_RUNS).catch(() => null)) ?? {};
|
|
300
|
+
await store.write(RED_RUNS, { ...kept, [key]: [...(kept[key] ?? []), { commit: receipt.commit, command, files, checks }] });
|
|
301
|
+
const named = [...files, ...checks.map((check) => `check ${check}`)].join(", ");
|
|
302
|
+
return {
|
|
303
|
+
payload: { data: { red: true, commit: receipt.commit, files, checks, receipt: path, ...(queued ? { queued } : {}) } },
|
|
304
|
+
human: `${key}: red at ${receipt.commit}: ${named}.${queued ? ` Dev is unreachable; the receipt waits at ${queued} for nodii-dev sync pending (MW1-64).` : " Recorded on Dev."} Make them green and pass them as lane check gates.`,
|
|
305
|
+
exitCode: 0,
|
|
306
|
+
};
|
|
307
|
+
}
|
package/dist/review.js
CHANGED
|
@@ -15,7 +15,8 @@ import { componentSetsIn, designCatalogSets } from "./figma-scope.js";
|
|
|
15
15
|
import { holdsSet, scopeText } from "./figma.js";
|
|
16
16
|
import { gitPrivatePath } from "./safety.js";
|
|
17
17
|
import { GENERATED_PAGE_GLOB, GENERATED_SUFFIX, hasGeneratedPageStamp } from "./surface.js";
|
|
18
|
-
import { VALUE_FLAGS } from "./impact.js";
|
|
18
|
+
import { VALUE_FLAGS, affected } from "./impact.js";
|
|
19
|
+
import { greenFields } from "./red-run.js";
|
|
19
20
|
import { heavySlotArgv } from "./heavy.js";
|
|
20
21
|
|
|
21
22
|
const execFileAsync = promisify(execFile);
|
|
@@ -119,22 +120,7 @@ export function fullSuiteGate(command, fullScript = "test") {
|
|
|
119
120
|
for (const part of shellCommands(text)) {
|
|
120
121
|
const nested = shellScript(part);
|
|
121
122
|
if (nested !== null) { if (fullSuiteGate(nested, fullScript)) return true; continue; }
|
|
122
|
-
|
|
123
|
-
// `npx vitest`, `bunx jest`, `pnpm exec vitest run`, `python -m pytest`: the tool they start.
|
|
124
|
-
for (;;) {
|
|
125
|
-
const first = (words[0] ?? "").split("/").pop();
|
|
126
|
-
if (["npx", "bunx", "pnpx"].includes(first)) words = words.slice(1).filter((word, i) => i > 0 || !word.startsWith("-"));
|
|
127
|
-
else if (["npm", "pnpm", "yarn"].includes(first) && ["exec", "dlx"].includes(words.find((word, i) => i > 0 && !word.startsWith("-")))) words = words.slice(words.findIndex((word) => ["exec", "dlx"].includes(word)) + 1);
|
|
128
|
-
else if (/^python[0-9.]*$/.test(first) && words[1] === "-m") words = words.slice(2);
|
|
129
|
-
// `env CI=1 npm test`, `timeout 600 npm test`, `nice -n 10 jest`: the command they wrap.
|
|
130
|
-
else if (["env", "time", "nohup", "exec"].includes(first)) words = words.slice(1);
|
|
131
|
-
// `nodii-dev heavy run -- CMD`: the queue runs CMD.
|
|
132
|
-
else if (/^nodii-dev(?:\.js)?$/.test(first) && words[1] === "heavy" && words[2] === "run") words = words.slice(words.includes("--") ? words.indexOf("--") + 1 : 3);
|
|
133
|
-
else if (first === "timeout") { words = words.slice(1); while (words[0]?.startsWith("-")) words = words.slice(1); words = words.slice(1); }
|
|
134
|
-
else if (first === "nice") { words = words.slice(1); if (words[0] === "-n") words = words.slice(2); }
|
|
135
|
-
else break;
|
|
136
|
-
while (words[0]?.startsWith("-")) words = words.slice(1);
|
|
137
|
-
}
|
|
123
|
+
const words = runnerWords(part);
|
|
138
124
|
const [tool, ...args] = words;
|
|
139
125
|
const name = (tool ?? "").split("/").pop();
|
|
140
126
|
// A package manager's `-r` is --recursive, not node's --require: it takes no value.
|
|
@@ -160,11 +146,32 @@ export function fullSuiteGate(command, fullScript = "test") {
|
|
|
160
146
|
return false;
|
|
161
147
|
}
|
|
162
148
|
|
|
149
|
+
/** The words of one simple command, from the tool it starts: `npx vitest`, `env CI=1 npm test`, `nodii-dev heavy run -- CMD`. */
|
|
150
|
+
export function runnerWords(part) {
|
|
151
|
+
let words = part.split(/\s+/).map((word) => word.replace(/^['"]+|['"]+$/g, "")).filter((word) => word && !/^[A-Z_][A-Z0-9_]*=/.test(word) && !/^(?:[0-9]?>|\|)/.test(word));
|
|
152
|
+
// `npx vitest`, `bunx jest`, `pnpm exec vitest run`, `python -m pytest`: the tool they start.
|
|
153
|
+
for (;;) {
|
|
154
|
+
const first = (words[0] ?? "").split("/").pop();
|
|
155
|
+
if (["npx", "bunx", "pnpx"].includes(first)) words = words.slice(1).filter((word, i) => i > 0 || !word.startsWith("-"));
|
|
156
|
+
else if (["npm", "pnpm", "yarn"].includes(first) && ["exec", "dlx"].includes(words.find((word, i) => i > 0 && !word.startsWith("-")))) words = words.slice(words.findIndex((word) => ["exec", "dlx"].includes(word)) + 1);
|
|
157
|
+
else if (/^python[0-9.]*$/.test(first) && words[1] === "-m") words = words.slice(2);
|
|
158
|
+
// `env CI=1 npm test`, `timeout 600 npm test`, `nice -n 10 jest`: the command they wrap.
|
|
159
|
+
else if (["env", "time", "nohup", "exec"].includes(first)) words = words.slice(1);
|
|
160
|
+
// `nodii-dev heavy run -- CMD`: the queue runs CMD.
|
|
161
|
+
else if (/^nodii-dev(?:\.js)?$/.test(first) && words[1] === "heavy" && words[2] === "run") words = words.slice(words.includes("--") ? words.indexOf("--") + 1 : 3);
|
|
162
|
+
else if (first === "timeout") { words = words.slice(1); while (words[0]?.startsWith("-")) words = words.slice(1); words = words.slice(1); }
|
|
163
|
+
else if (first === "nice") { words = words.slice(1); if (words[0] === "-n") words = words.slice(2); }
|
|
164
|
+
else break;
|
|
165
|
+
while (words[0]?.startsWith("-")) words = words.slice(1);
|
|
166
|
+
}
|
|
167
|
+
return words;
|
|
168
|
+
}
|
|
169
|
+
|
|
163
170
|
/**
|
|
164
171
|
* The simple commands of a shell line: split on `&&`, `||`, `;` and `|` outside quotes, so
|
|
165
172
|
* `sh -c 'a && b' && sh -c 'npm test'` is two commands, each with its own script.
|
|
166
173
|
*/
|
|
167
|
-
function shellCommands(text) {
|
|
174
|
+
export function shellCommands(text) {
|
|
168
175
|
const parts = [];
|
|
169
176
|
let current = "";
|
|
170
177
|
let quote = null;
|
|
@@ -185,13 +192,13 @@ function shellCommands(text) {
|
|
|
185
192
|
// jest's and vitest's own changed-files modes already run only the tests a change reaches.
|
|
186
193
|
const CHANGED_FLAGS = new Set(["--onlyChanged", "-o", "--changedSince", "--findRelatedTests", "--changed", "--related"]);
|
|
187
194
|
// `sh -c 'npm test'`, `bash -lc "…"`: the script the shell runs, or null.
|
|
188
|
-
const shellScript = (text) => text.match(/^(?:\S*\/)?(?:ba|z|da)?sh\s+-[a-z]*c[a-z]*\s+(['"])([\s\S]*)\1$/)?.[2] ?? null;
|
|
195
|
+
export const shellScript = (text) => text.match(/^(?:\S*\/)?(?:ba|z|da)?sh\s+-[a-z]*c[a-z]*\s+(['"])([\s\S]*)\1$/)?.[2] ?? null;
|
|
189
196
|
// A package manager's own flags that take a value: the workspace, filter or directory it runs in.
|
|
190
197
|
const SCOPE_FLAGS = new Set(["--workspace", "-w", "--filter", "-F", "--dir", "-C", "--prefix", "--cwd"]);
|
|
191
198
|
// jest's --selectProjects takes every word after it, up to the next flag.
|
|
192
199
|
const VARIADIC_FLAGS = new Set(["--selectProjects"]);
|
|
193
200
|
/** Operands: not a flag, and not the value of one (`--timeout 30000`, `--config ./jest.config.mjs`, `--filter web`). */
|
|
194
|
-
function operandsOf(args, { pm = false } = {}) {
|
|
201
|
+
export function operandsOf(args, { pm = false } = {}) {
|
|
195
202
|
const operands = [];
|
|
196
203
|
let variadic = false;
|
|
197
204
|
for (const [i, word] of args.entries()) {
|
|
@@ -226,14 +233,15 @@ export const diffDigest = (text) => createHash("sha256").update(text).digest("he
|
|
|
226
233
|
* writes the receipt; without --gate only a receipt for this head, base and
|
|
227
234
|
* diff counts. Returns the diff the receipt covers, which is the one reviewed.
|
|
228
235
|
*/
|
|
229
|
-
export async function gatesReceipt(commands, { cwd, current, store, diff, run = runGate, now = () => new Date().toISOString(), fullSuite = false }) {
|
|
236
|
+
export async function gatesReceipt(commands, { cwd, current, store, diff, run = runGate, now = () => new Date().toISOString(), fullSuite = false, affectedTests = (base) => affected(cwd, base ? { base } : {}) }) {
|
|
230
237
|
const changed = await diff(cwd);
|
|
231
238
|
const digest = diffDigest(changed.text);
|
|
232
239
|
if (commands.length) {
|
|
233
240
|
const runs = [];
|
|
234
241
|
for (const command of commands) {
|
|
235
242
|
const { code, tail } = await run(command, cwd);
|
|
236
|
-
|
|
243
|
+
// hub-485, red runs: what the gate ran green, for Dev to match against the lane's red runs.
|
|
244
|
+
runs.push({ command, exitCode: code, ...(await greenFields(command, { exitCode: code, affectedTests })) });
|
|
237
245
|
if (code !== 0)
|
|
238
246
|
throw new CliError("GATES_NOT_GREEN", `Gate \`${command}\` exited ${code}; nothing was reviewed or recorded. Make it green and rerun lane check.${tail ? `\n${tail.trimEnd().split("\n").slice(-20).join("\n")}` : ""}`, 1, { command, exitCode: code });
|
|
239
247
|
}
|
|
@@ -257,7 +265,8 @@ export async function gatesReceipt(commands, { cwd, current, store, diff, run =
|
|
|
257
265
|
export function reviewGates(receipt) {
|
|
258
266
|
if (!receipt || !Array.isArray(receipt.runs ?? receipt.commands)) return null;
|
|
259
267
|
const runs = receipt.runs ?? receipt.commands.map((command) => ({ command, exitCode: 0 }));
|
|
260
|
-
|
|
268
|
+
// hub-485, red runs: the files a run made green go with it, when it names any.
|
|
269
|
+
return { base: receipt.base, diff: receipt.diff, runs: runs.map(({ command, exitCode, files }) => ({ command, exitCode, commit: receipt.commit, ...(files?.length ? { files } : {}) })) };
|
|
261
270
|
}
|
|
262
271
|
|
|
263
272
|
/**
|
package/dist/surface.js
CHANGED
|
@@ -32,7 +32,7 @@ import { CliError, VERSION, devRequest, readConfig } from "./core.js";
|
|
|
32
32
|
import { createRenderer } from "./vendor/render-templates.mjs";
|
|
33
33
|
|
|
34
34
|
/** Bumped whenever the emitted code changes shape for the same inputs. */
|
|
35
|
-
export const GENERATOR_FORMAT =
|
|
35
|
+
export const GENERATOR_FORMAT = 37;
|
|
36
36
|
export const TREE_DIR = "docs/figma-ux-ds/figma/surface-trees";
|
|
37
37
|
export const GENERATED_SUFFIX = ".surface.generated.tsx";
|
|
38
38
|
/** Where every generated product page lives, as a git glob (NODII-DEV-CLI-77). */
|
|
@@ -1016,6 +1016,15 @@ function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
|
|
|
1016
1016
|
const scope = nameOf(label ? literalText(label[1]) : node.name, node.name);
|
|
1017
1017
|
return `<DescriptionItem${attrs.replace(value[0], `value={${lift(scope, "value")}}`)}/>`;
|
|
1018
1018
|
});
|
|
1019
|
+
out = rewriteTags(out, "RightPaneIdentity", (attrs) => {
|
|
1020
|
+
const parsed = tagAttributes(`${attrs}>`, 0);
|
|
1021
|
+
if (!parsed) return attrs;
|
|
1022
|
+
const flat = maskStrings(attrs);
|
|
1023
|
+
return attrs.replace(new RegExp(String.raw`\b(number|name)=${LITERAL}`, "g"), (value, prop, at) => {
|
|
1024
|
+
const depth = [...flat.slice(0, at)].reduce((d, c) => d + (c === "{") - (c === "}"), 0);
|
|
1025
|
+
return depth === 0 && parsed.literals.has(prop) ? `${prop}={${lift(scope, prop)}}` : value;
|
|
1026
|
+
});
|
|
1027
|
+
});
|
|
1019
1028
|
out = rewriteTags(out, "DetailFact|RightPaneRow", (attrs) => {
|
|
1020
1029
|
const parsed = tagAttributes(`${attrs}>`, 0);
|
|
1021
1030
|
if (!parsed?.literals.has("value")) return attrs;
|
|
@@ -2360,6 +2369,13 @@ function emitNode(node, ctx) {
|
|
|
2360
2369
|
else for (const child of current.children ?? []) collect(child);
|
|
2361
2370
|
};
|
|
2362
2371
|
if (tableSlot) collect(tableSlot);
|
|
2372
|
+
if (tableSlot && /\bcolumns=\{(?:__s\d+_)?columns\}/.test(own)) {
|
|
2373
|
+
const containsTable = (current) => current.visible !== false && (
|
|
2374
|
+
(current.instance?.remote && ["Table", "Table Rich Cell"].includes(current.instance.set)) ||
|
|
2375
|
+
(current.children ?? []).some(containsTable)
|
|
2376
|
+
);
|
|
2377
|
+
if (containsTable(tableSlot)) note(`${path} › table`, "table", "drawn toolbar columns remain caller-owned: column labels, presentation and person-cell contracts are not generated");
|
|
2378
|
+
}
|
|
2363
2379
|
if (states.length === 1) {
|
|
2364
2380
|
const error = states[0].instance.set === "Error State Page" || /(?:^|-)error(?:$|-)/.test(ctx.state ?? "");
|
|
2365
2381
|
const prop = error ? "errorState" : "emptyState";
|