bivium 0.7.0 → 0.9.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/cli.js CHANGED
@@ -1,15 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
- version,
3
+ BiviumError2,
4
+ didYouMean2
5
+ } from "./shared-211m8fjt.js";
6
+ import {
7
+ globToRegExp,
8
+ inRoot2
9
+ } from "./shared-550cvwt2.js";
10
+ import {
4
11
  githubOutputPath,
5
12
  nowMs,
6
13
  environment,
7
14
  agentVariable,
8
- BiviumError2,
9
- didYouMean,
10
- globToRegExp,
11
- inRoot,
12
- sorted,
15
+ version,
13
16
  QUERY,
14
17
  UNDECLARED_READS,
15
18
  RELATIVE,
@@ -24,11 +27,11 @@ import {
24
27
  walksByTypes,
25
28
  importersOf,
26
29
  affectedBy,
27
- formatSelection,
28
- orphanOf,
30
+ sorted,
29
31
  PLAIN,
30
32
  createPaint,
31
33
  wantsColor,
34
+ isDumb,
32
35
  SEPARATOR,
33
36
  branch,
34
37
  NOTE_INDENT,
@@ -38,15 +41,18 @@ import {
38
41
  truncatePath,
39
42
  textWidth,
40
43
  MEASURE,
44
+ fitTerminal,
41
45
  RULE,
42
46
  aligned,
43
47
  headerRow,
44
48
  plural,
45
49
  SILENT,
46
50
  createProgress,
47
- computePlan,
48
- prepare
49
- } from "./shared.js";
51
+ formatSelection,
52
+ orphanOf,
53
+ computePlan2,
54
+ prepare2
55
+ } from "./shared-07rt4zr7.js";
50
56
 
51
57
  // src/main.ts
52
58
  import { spawnSync } from "node:child_process";
@@ -439,7 +445,7 @@ function spellers(config, { graph }) {
439
445
  continue;
440
446
  if (node.startsWith("pkg:") || node.includes("#"))
441
447
  continue;
442
- if (suite.isTest(node) || (reached.get(node) ?? 0) > 0 && suite.roots.some((root) => inRoot(node, root))) {
448
+ if (suite.isTest(node) || (reached.get(node) ?? 0) > 0 && suite.roots.some((root) => inRoot2(node, root))) {
443
449
  const suites = found.get(node);
444
450
  suites ? suites.push(suite) : found.set(node, [suite]);
445
451
  }
@@ -1731,7 +1737,7 @@ function usageError(code, message) {
1731
1737
  function unknownOption(command, flag) {
1732
1738
  const known = FLAGS[command] ?? [];
1733
1739
  const others = Object.keys(FLAGS).filter((other) => other !== command && FLAGS[other]?.includes(flag));
1734
- const hint = others.length > 0 ? ` (${others.join(" and ")} ${others.length === 1 ? "takes" : "take"} it)` : didYouMean(flag, known);
1740
+ const hint = others.length > 0 ? ` (${others.join(" and ")} ${others.length === 1 ? "takes" : "take"} it)` : didYouMean2(flag, known);
1735
1741
  return usageError("BV_UNKNOWN_OPTION", `bivium ${command}: unknown option ${flag}${hint}`);
1736
1742
  }
1737
1743
  function parseArgs(command, argv) {
@@ -1940,7 +1946,7 @@ function findSuite(config, name) {
1940
1946
  if (suite)
1941
1947
  return suite;
1942
1948
  const names = config.suites.map((candidate) => candidate.name);
1943
- throw usageError("BV_UNKNOWN_SUITE", `bivium: no suite "${name}"${didYouMean(name, names)}; the config has ${names.join(", ")}`);
1949
+ throw usageError("BV_UNKNOWN_SUITE", `bivium: no suite "${name}"${didYouMean2(name, names)}; the config has ${names.join(", ")}`);
1944
1950
  }
1945
1951
  function real(path) {
1946
1952
  try {
@@ -1969,7 +1975,7 @@ function repoPath(root, arg, known) {
1969
1975
  async function inspect(command, { flags, positional }, out) {
1970
1976
  const format = flags.get("--format") ?? "tree";
1971
1977
  if (format !== "json" && !isFormat(format)) {
1972
- throw usageError("BV_BAD_OPTION_VALUE", `bivium why: --format takes tree, chain, source or json${didYouMean(format, ["tree", "chain", "source", "json"])}`);
1978
+ throw usageError("BV_BAD_OPTION_VALUE", `bivium why: --format takes tree, chain, source or json${didYouMean2(format, ["tree", "chain", "source", "json"])}`);
1973
1979
  }
1974
1980
  const maxFlag = flags.get("--max-unknown");
1975
1981
  const max = maxFlag === undefined ? undefined : Number(maxFlag);
@@ -1980,15 +1986,15 @@ async function inspect(command, { flags, positional }, out) {
1980
1986
  if (command === "why" && testArg === undefined) {
1981
1987
  throw usageError("BV_MISSING_ARGUMENT", "bivium why: which test? bivium why <test> [file]");
1982
1988
  }
1983
- const progress = command === "check" && out.io.stderr && !out.agent && !flags.has("--json") ? createProgress(out.io.writeError, out.errorPaint, nowMs) : SILENT;
1989
+ const progress = command === "check" && out.io.stderr && !isDumb(out.io.env) && !out.agent && !flags.has("--json") ? createProgress(out.io.writeError, out.errorPaint, nowMs) : SILENT;
1984
1990
  progress.step("building the graph", 0);
1985
1991
  try {
1986
- const { root, base, config } = await prepare({
1992
+ const { root, base, config } = await prepare2({
1987
1993
  cwd: flags.get("--cwd"),
1988
1994
  base: flags.get("--base") ?? (command === "check" ? "HEAD" : undefined),
1989
1995
  configFile: flags.get("--config")
1990
1996
  });
1991
- const computed = await computePlan(root, base, config, {
1997
+ const computed = await computePlan2(root, base, config, {
1992
1998
  ...flags.has("--no-cache") && { cache: false }
1993
1999
  });
1994
2000
  if (command === "check") {
@@ -2016,10 +2022,10 @@ async function whyCommand(root, config, computed, flags, [testArg, fileArg], out
2016
2022
  const file = fileArg === undefined ? undefined : repoPath(root, fileArg, inGraph);
2017
2023
  if (!isTest(test) || !inGraph(test)) {
2018
2024
  const tests = [...computed.graph.keys()].filter(isTest);
2019
- throw usageError(inGraph(test) ? "BV_UNKNOWN_TEST" : "BV_UNKNOWN_FILE", inGraph(test) ? `bivium why: ${test} is no suite's test: name a test first, as in bivium why <test> ${test}` : `bivium why: no test ${test}${didYouMean(test, tests)}`);
2025
+ throw usageError(inGraph(test) ? "BV_UNKNOWN_TEST" : "BV_UNKNOWN_FILE", inGraph(test) ? `bivium why: ${test} is no suite's test: name a test first, as in bivium why <test> ${test}` : `bivium why: no test ${test}${didYouMean2(test, tests)}`);
2020
2026
  }
2021
2027
  if (file !== undefined && !inGraph(file)) {
2022
- throw usageError("BV_UNKNOWN_FILE", `bivium why: no file ${file}${didYouMean(file, computed.graph.keys())}`);
2028
+ throw usageError("BV_UNKNOWN_FILE", `bivium why: no file ${file}${didYouMean2(file, computed.graph.keys())}`);
2023
2029
  }
2024
2030
  const explanation = await explain(root, config, computed, test, file, {
2025
2031
  all: flags.has("--all")
@@ -2032,14 +2038,14 @@ async function graphCommand({ flags }) {
2032
2038
  if (!Number.isInteger(top) || top < 0) {
2033
2039
  throw usageError("BV_BAD_OPTION_VALUE", "bivium graph: --top takes a whole number");
2034
2040
  }
2035
- const { root, base, config } = await prepare({
2041
+ const { root, base, config } = await prepare2({
2036
2042
  cwd: flags.get("--cwd"),
2037
2043
  base: "HEAD",
2038
2044
  configFile: flags.get("--config")
2039
2045
  });
2040
2046
  const one = findSuite(config, flags.get("--suite"));
2041
2047
  const suites = one ? [one] : config.suites;
2042
- const { graph } = await computePlan(root, base, config, {
2048
+ const { graph } = await computePlan2(root, base, config, {
2043
2049
  ...flags.has("--no-cache") && { cache: false }
2044
2050
  });
2045
2051
  const report = graphReport(graph, suites);
@@ -2048,7 +2054,7 @@ async function graphCommand({ flags }) {
2048
2054
  }
2049
2055
  async function runCommand(command, { flags, positional }, out) {
2050
2056
  const output = flags.has("--github") ? githubOutput() : undefined;
2051
- const { root, base, config } = await prepare({
2057
+ const { root, base, config } = await prepare2({
2052
2058
  cwd: flags.get("--cwd"),
2053
2059
  base: positional[0],
2054
2060
  configFile: flags.get("--config")
@@ -2060,7 +2066,7 @@ async function runCommand(command, { flags, positional }, out) {
2060
2066
  if (command === "run" && !suite.run) {
2061
2067
  throw usageError("BV_NO_RUN_COMMAND", `bivium run: suite "${suite.name}" has no run command: add suites.${suite.name}.run to the config`);
2062
2068
  }
2063
- const computed = await computePlan(root, base, config, {
2069
+ const computed = await computePlan2(root, base, config, {
2064
2070
  ...flags.has("--no-cache") && { cache: false },
2065
2071
  ...command === "run" && { suites: [suite.name] },
2066
2072
  mergeBase: true
@@ -2094,19 +2100,68 @@ async function runCommand(command, { flags, positional }, out) {
2094
2100
  writeOutputs(output, config, computed);
2095
2101
  return 0;
2096
2102
  }
2097
- await logContext(base, config, computed);
2098
- logPlan(computed);
2103
+ const human = out.io.stdout && !out.agent;
2104
+ const others = flags.has("--suite") ? [] : config.suites.slice(1).map((s) => `--suite=${s.name}`);
2105
+ if (human)
2106
+ await showRun(out, base, config, computed, suite.name, others);
2107
+ else {
2108
+ await logContext(base, config, computed);
2109
+ logPlan(computed);
2110
+ }
2099
2111
  const selection = computed.plan.suites[suite.name];
2100
2112
  if (selection === undefined || selection.mode === "none") {
2101
- console.log(`No ${suite.name} tests affected against ${base}; skipping.`);
2113
+ if (human) {
2114
+ console.log(closingLine(out.paint, `Nothing to run for ${suite.name}`));
2115
+ } else {
2116
+ console.log(`No ${suite.name} tests affected against ${base}; skipping.`);
2117
+ }
2102
2118
  return 0;
2103
2119
  }
2104
- const [program, ...args] = commandFor(suite.run ?? "", selection.mode === "some" ? selection.files : []);
2120
+ const [program, ...args] = selection.mode === "some" ? commandFor(suite.run ?? "", selection.files) : suite.runAll !== undefined ? commandFor(suite.runAll, []) : commandFor(suite.run ?? "", suite.roots.filter((root) => root !== "."));
2105
2121
  if (program === undefined) {
2106
2122
  throw usageError("BV_NO_RUN_COMMAND", `bivium run: suite "${suite.name}" has no run command: add suites.${suite.name}.run to the config`);
2107
2123
  }
2124
+ if (human) {
2125
+ const files = selection.mode === "some" ? selection.files.length : 0;
2126
+ const bare = commandFor(suite.run ?? "", []);
2127
+ console.log(`${out.paint.dim(shownCommand([program, ...args], bare, files))}
2128
+ `);
2129
+ }
2130
+ const started = nowMs();
2108
2131
  const result = spawnSync(program, args, { cwd: root, stdio: "inherit" });
2109
- return result.status ?? 1;
2132
+ const interrupted = result.signal === "SIGINT";
2133
+ const status = interrupted ? 130 : result.status ?? 1;
2134
+ if (human) {
2135
+ const took = duration(nowMs() - started);
2136
+ const name = suite.name;
2137
+ console.log(`
2138
+ ${interrupted ? failLine(out.paint, `${name} interrupted`, took) : status === 0 ? closingLine(out.paint, `${name} passed`, took) : failLine(out.paint, `${name} failed`, `${result.signal ?? `exit ${status}`}${SEPARATOR}${took}`)}`);
2139
+ }
2140
+ return status;
2141
+ }
2142
+ function shownCommand(whole, bare, files) {
2143
+ const line = `$ ${whole.join(" ")}`;
2144
+ if (textWidth(line) <= MEASURE)
2145
+ return line;
2146
+ return `$ ${bare.join(" ")} ${SEPARATOR.trim()} ${plural(files, "file")}, as bivium plan --list names them`;
2147
+ }
2148
+ async function showRun(out, base, config, computed, name, others) {
2149
+ const { paint } = out;
2150
+ const selection = computed.plan.suites[name];
2151
+ const total = computed.plan.totals[name] ?? 0;
2152
+ const used = new Set;
2153
+ const verdict = selection === undefined ? `no ${name} tests` : verdictOf(name, selection, total, computed, used, paint);
2154
+ const mergeBase = (await computed.mergeBase()).slice(0, 7);
2155
+ const context = [
2156
+ `since ${base} (merge base ${mergeBase})`,
2157
+ ...config.file ? [`config ${config.file}`] : []
2158
+ ].join(SEPARATOR);
2159
+ const lines = [verdict, paint.dim(context)];
2160
+ if (others.length > 0) {
2161
+ lines.push(paint.dim(`running ${name}${SEPARATOR}${plural(others.length, "more suite")}: ${others.join(", ")}`));
2162
+ }
2163
+ console.log(lines.join(`
2164
+ `));
2110
2165
  }
2111
2166
  function commandAt(argv) {
2112
2167
  for (let i = 0;i < argv.length; i++) {
@@ -2135,7 +2190,7 @@ function fail(argv, error) {
2135
2190
  async function main(argv, io = PIPED) {
2136
2191
  const out = outFor(io, argv, nowMs());
2137
2192
  if (argv.includes("--help") || argv.includes("-h")) {
2138
- console.log(usage(out.paint));
2193
+ console.log(fitTerminal(usage(out.paint), out.io.stdout, process.stdout.columns));
2139
2194
  return 0;
2140
2195
  }
2141
2196
  if (argv.includes("--version") || argv.includes("-v")) {
@@ -2145,14 +2200,14 @@ async function main(argv, io = PIPED) {
2145
2200
  const at = commandAt(argv);
2146
2201
  const command = at === -1 ? undefined : argv[at];
2147
2202
  if (command === "help") {
2148
- console.log(usage(out.paint));
2203
+ console.log(fitTerminal(usage(out.paint), out.io.stdout, process.stdout.columns));
2149
2204
  return 0;
2150
2205
  }
2151
2206
  if (command === undefined) {
2152
2207
  return fail(argv, usageError("BV_MISSING_ARGUMENT", `bivium: which command? ${COMMANDS.join(", ")} (bivium --help for usage)`));
2153
2208
  }
2154
2209
  if (!(command in FLAGS)) {
2155
- return fail(argv, usageError("BV_UNKNOWN_COMMAND", `bivium: unknown command "${command}"${didYouMean(command, COMMANDS)}; the commands are ${COMMANDS.join(", ")} (bivium --help for usage)`));
2210
+ return fail(argv, usageError("BV_UNKNOWN_COMMAND", `bivium: unknown command "${command}"${didYouMean2(command, COMMANDS)}; the commands are ${COMMANDS.join(", ")} (bivium --help for usage)`));
2156
2211
  }
2157
2212
  const rest = [...argv.slice(0, at), ...argv.slice(at + 1)];
2158
2213
  try {
package/compute.js ADDED
@@ -0,0 +1,20 @@
1
+ import {
2
+ readSources2,
3
+ collectPackages2,
4
+ extractRevision2,
5
+ graphView2,
6
+ computePlan2,
7
+ prepare2,
8
+ plan2
9
+ } from "./shared-07rt4zr7.js";
10
+ import"./shared-550cvwt2.js";
11
+ import"./shared-211m8fjt.js";
12
+ export {
13
+ collectPackages2 as collectPackages,
14
+ computePlan2 as computePlan,
15
+ extractRevision2 as extractRevision,
16
+ graphView2 as graphView,
17
+ plan2 as plan,
18
+ prepare2 as prepare,
19
+ readSources2 as readSources
20
+ };
package/config.js ADDED
@@ -0,0 +1,15 @@
1
+ import {
2
+ defineConfig2,
3
+ resolveConfig2,
4
+ inRoot2,
5
+ checkConfig2,
6
+ loadConfig2
7
+ } from "./shared-550cvwt2.js";
8
+ import"./shared-211m8fjt.js";
9
+ export {
10
+ checkConfig2 as checkConfig,
11
+ defineConfig2 as defineConfig,
12
+ inRoot2 as inRoot,
13
+ loadConfig2 as loadConfig,
14
+ resolveConfig2 as resolveConfig
15
+ };
package/docs/cli.md CHANGED
@@ -103,12 +103,31 @@ bivium run [base] [--suite <name>]
103
103
  - `--suite <name>` picks the suite.
104
104
  Default: the first one in the config.
105
105
 
106
- It prints the plan first, as `plan` does.
107
106
  The selected files go where the command says `{files}`, or at its end.
108
- When every test is selected, no files are passed,
109
- so the runner runs them all.
110
- When none is, `run` skips the command and exits 0.
111
- Otherwise it exits with the command's status.
107
+ When every test is selected, the suite's `root` goes there instead,
108
+ so a runner that would run every suite's tests runs only this one's;
109
+ `runAll` in the config replaces the command for that case.
110
+ When no test is selected, `run` skips the command and exits 0.
111
+ Otherwise it exits with the command's status,
112
+ or 130 when Ctrl-C interrupted it.
113
+
114
+ On a terminal, it opens as `plan` does, names the suites it didn't run,
115
+ echoes the command, then closes with the result:
116
+
117
+ ```console
118
+ $ bivium run main
119
+ 1 of 2 tests run for 1 changed file (unit)
120
+ since main (merge base f601cb4) · config bivium.config.ts
121
+ running unit · 2 more suites: --suite=e2e, --suite=visual
122
+ $ bun test tests/unit/name.test.ts
123
+
124
+ …the runner's output…
125
+
126
+ ✓ unit passed · 247 ms
127
+ ```
128
+
129
+ Piped, or for a coding agent, it prints the plan as text,
130
+ then the runner's output.
112
131
 
113
132
  ```sh
114
133
  bivium run --suite e2e
package/docs/config.md CHANGED
@@ -44,6 +44,7 @@ a set of test files and the command that runs them.
44
44
  |:---|:---|:---|
45
45
  | `tests` | The suite's test files | required |
46
46
  | `run` | The command `bivium run` runs | none; `bivium run` needs one |
47
+ | `runAll` | The command for a full run, when every test is selected | `run`, with `root` for `{files}` |
47
48
  | `root` | Where the orphan rule applies | the whole repository |
48
49
  | `urls` | URL pattern → the page a `page.goto()` opens | none |
49
50
  | `pages` | Pages only a `goto()` opens | none |
@@ -57,9 +58,12 @@ a set of test files and the command that runs them.
57
58
 
58
59
  `bivium run` puts the selected files where `{files}` is:
59
60
  `vitest run {files}` runs `vitest run tests/a.test.ts tests/b.test.ts`.
60
- When the whole suite is selected, `{files}` becomes nothing,
61
- and the command runs with no files.
61
+ When the whole suite is selected, `{files}` becomes the suite's `root`,
62
+ `vitest run tests`, since a bare `vitest run` or `bun test` would run
63
+ every suite's tests; without a `root`, it becomes nothing.
62
64
  Without `{files}`, the files go at the end of the command.
65
+ When the runner needs another command for a full run,
66
+ set `runAll`: `runAll: "playwright test --project=e2e"`.
63
67
 
64
68
  ### `root` and the orphan rule
65
69
 
package/errors.js ADDED
@@ -0,0 +1,8 @@
1
+ import {
2
+ BiviumError2,
3
+ didYouMean2
4
+ } from "./shared-211m8fjt.js";
5
+ export {
6
+ BiviumError2 as BiviumError,
7
+ didYouMean2 as didYouMean
8
+ };
package/index.d.ts CHANGED
@@ -144,9 +144,16 @@ export interface SuiteConfig {
144
144
  tests: Globs;
145
145
  /**
146
146
  * The command `bivium run` runs. `{files}` is replaced by the selected
147
- * files, or nothing for all of them; without it, they're appended.
147
+ * files; without it, they're appended. When every test is selected,
148
+ * `{files}` is the suite's `root`, or nothing without one.
148
149
  */
149
150
  run?: string;
151
+ /**
152
+ * The command for a full run of the suite, when every test is selected
153
+ * and `run` with the suite's root wouldn't run exactly this suite.
154
+ * Default: `run`, with the root for `{files}`.
155
+ */
156
+ runAll?: string;
150
157
  /**
151
158
  * Where the orphan rule applies: a changed file under one of these paths
152
159
  * that no test of the suite reaches is wired some other way (a setup
package/index.js CHANGED
@@ -1,10 +1,11 @@
1
+ // src/index.ts
2
+ import { plan } from "./compute.js";
3
+ import { defineConfig } from "./config.js";
1
4
  import {
2
- BiviumError2,
3
- defineConfig2,
4
- plan2
5
- } from "./shared.js";
5
+ BiviumError
6
+ } from "./errors.js";
6
7
  export {
7
- BiviumError2 as BiviumError,
8
- defineConfig2 as defineConfig,
9
- plan2 as plan
8
+ BiviumError,
9
+ defineConfig,
10
+ plan
10
11
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bivium",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "Run only the tests your change can reach.",
5
5
  "license": "MIT",
6
6
  "author": "Eric Liu (https://github.com/metonym)",