bivium 0.5.1 → 0.6.1

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
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  version,
4
4
  githubOutputPath,
5
- BiviumError,
5
+ BiviumError2,
6
6
  didYouMean,
7
7
  globToRegExp,
8
8
  inRoot,
@@ -1253,10 +1253,12 @@ function unselected(config, computed, suite, from) {
1253
1253
  }
1254
1254
  async function explain(root, config, computed, test, from, { all = false } = {}) {
1255
1255
  const suite = config.suites.find((candidate) => candidate.isTest(test));
1256
- if (!suite)
1257
- throw new Error(`bivium why: ${test} is no suite's test`);
1258
- if (!computed.graph.has(test))
1259
- throw new Error(`bivium why: no file ${test}`);
1256
+ if (!suite) {
1257
+ throw new BiviumError2("BV_UNKNOWN_TEST", `bivium why: ${test} is no suite's test`);
1258
+ }
1259
+ if (!computed.graph.has(test)) {
1260
+ throw new BiviumError2("BV_UNKNOWN_FILE", `bivium why: no file ${test}`);
1261
+ }
1260
1262
  if (from === undefined && computed.plan.full.includes(suite.name)) {
1261
1263
  return { kind: "full", suite: suite.name, reasons: computed.plan.reasons };
1262
1264
  }
@@ -1542,14 +1544,14 @@ var POSITIONAL = {
1542
1544
  graph: 0
1543
1545
  };
1544
1546
  var SCHEMA_VERSION = 1;
1545
- function usageError(message) {
1546
- return new BiviumError("usage", message);
1547
+ function usageError(code, message) {
1548
+ return new BiviumError2(code, message);
1547
1549
  }
1548
1550
  function unknownOption(command, flag) {
1549
1551
  const known = FLAGS[command] ?? [];
1550
1552
  const others = Object.keys(FLAGS).filter((other) => other !== command && FLAGS[other]?.includes(flag));
1551
1553
  const hint = others.length > 0 ? ` (${others.join(" and ")} ${others.length === 1 ? "takes" : "take"} it)` : didYouMean(flag, known);
1552
- return usageError(`bivium ${command}: unknown option ${flag}${hint}`);
1554
+ return usageError("BV_UNKNOWN_OPTION", `bivium ${command}: unknown option ${flag}${hint}`);
1553
1555
  }
1554
1556
  function parseArgs(command, argv) {
1555
1557
  const known = FLAGS[command] ?? [];
@@ -1570,7 +1572,7 @@ function parseArgs(command, argv) {
1570
1572
  if (!VALUED.has(flag)) {
1571
1573
  const on = equals === -1 ? "true" : arg.slice(equals + 1);
1572
1574
  if (on !== "true" && on !== "false") {
1573
- throw usageError(`bivium ${command}: ${flag} is a switch: give it alone, or as ${flag}=true or ${flag}=false`);
1575
+ throw usageError("BV_BAD_OPTION_VALUE", `bivium ${command}: ${flag} is a switch: give it alone, or as ${flag}=true or ${flag}=false`);
1574
1576
  }
1575
1577
  if (on === "true")
1576
1578
  flags.set(flag, "");
@@ -1578,12 +1580,12 @@ function parseArgs(command, argv) {
1578
1580
  }
1579
1581
  const value = equals === -1 ? argv[++i] : arg.slice(equals + 1);
1580
1582
  if (value === undefined || value === "" || value.startsWith("--")) {
1581
- throw usageError(`bivium: ${flag} needs a value`);
1583
+ throw usageError("BV_BAD_OPTION_VALUE", `bivium: ${flag} needs a value`);
1582
1584
  }
1583
1585
  flags.set(flag, value);
1584
1586
  }
1585
1587
  if (positional.length > (POSITIONAL[command] ?? 0)) {
1586
- throw usageError(`bivium ${command}: unexpected ${positional.at(-1)}`);
1588
+ throw usageError("BV_UNEXPECTED_ARGUMENT", `bivium ${command}: unexpected ${positional.at(-1)}`);
1587
1589
  }
1588
1590
  return { flags, positional };
1589
1591
  }
@@ -1638,7 +1640,7 @@ function logPlan({ plan, narrowed }) {
1638
1640
  function githubOutput() {
1639
1641
  const output = githubOutputPath();
1640
1642
  if (!output) {
1641
- throw usageError("bivium plan: --github writes to $GITHUB_OUTPUT, which is not set (it is in a GitHub Actions step)");
1643
+ throw usageError("BV_NO_GITHUB_OUTPUT", "bivium plan: --github writes to $GITHUB_OUTPUT, which is not set (it is in a GitHub Actions step)");
1642
1644
  }
1643
1645
  return output;
1644
1646
  }
@@ -1646,7 +1648,7 @@ function writeOutputs(output, config, { plan }) {
1646
1648
  const lines = config.suites.map((suite) => {
1647
1649
  const selection = plan.suites[suite.name];
1648
1650
  if (selection === undefined) {
1649
- throw new Error(`bivium: plan: no selection for suite "${suite.name}".`);
1651
+ throw new BiviumError2("BV_INTERNAL", `bivium: plan: no selection for suite "${suite.name}".`);
1650
1652
  }
1651
1653
  return `${suite.output}=${formatSelection(selection)}
1652
1654
  `;
@@ -1663,7 +1665,7 @@ function findSuite(config, name) {
1663
1665
  if (suite)
1664
1666
  return suite;
1665
1667
  const names = config.suites.map((candidate) => candidate.name);
1666
- throw usageError(`bivium: no suite "${name}"${didYouMean(name, names)}; the config has ${names.join(", ")}`);
1668
+ throw usageError("BV_UNKNOWN_SUITE", `bivium: no suite "${name}"${didYouMean(name, names)}; the config has ${names.join(", ")}`);
1667
1669
  }
1668
1670
  function real(path) {
1669
1671
  try {
@@ -1692,16 +1694,16 @@ function repoPath(root, arg, known) {
1692
1694
  async function inspect(command, { flags, positional }) {
1693
1695
  const format = flags.get("--format") ?? "tree";
1694
1696
  if (format !== "json" && !isFormat(format)) {
1695
- throw usageError(`bivium why: --format takes tree, chain, source or json${didYouMean(format, ["tree", "chain", "source", "json"])}`);
1697
+ throw usageError("BV_BAD_OPTION_VALUE", `bivium why: --format takes tree, chain, source or json${didYouMean(format, ["tree", "chain", "source", "json"])}`);
1696
1698
  }
1697
1699
  const maxFlag = flags.get("--max-unknown");
1698
1700
  const max = maxFlag === undefined ? undefined : Number(maxFlag);
1699
1701
  if (max !== undefined && !Number.isInteger(max)) {
1700
- throw usageError("bivium check: --max-unknown takes a whole number");
1702
+ throw usageError("BV_BAD_OPTION_VALUE", "bivium check: --max-unknown takes a whole number");
1701
1703
  }
1702
1704
  const [testArg, fileArg] = positional;
1703
1705
  if (command === "why" && testArg === undefined) {
1704
- throw usageError("bivium why: which test? bivium why <test> [file]");
1706
+ throw usageError("BV_MISSING_ARGUMENT", "bivium why: which test? bivium why <test> [file]");
1705
1707
  }
1706
1708
  const { root, base, config } = await prepare({
1707
1709
  cwd: flags.get("--cwd"),
@@ -1723,10 +1725,10 @@ async function inspect(command, { flags, positional }) {
1723
1725
  const file = fileArg === undefined ? undefined : repoPath(root, fileArg, inGraph);
1724
1726
  if (!isTest(test) || !inGraph(test)) {
1725
1727
  const tests = [...computed.graph.keys()].filter(isTest);
1726
- throw usageError(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)}`);
1728
+ 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)}`);
1727
1729
  }
1728
1730
  if (file !== undefined && !inGraph(file)) {
1729
- throw usageError(`bivium why: no file ${file}${didYouMean(file, computed.graph.keys())}`);
1731
+ throw usageError("BV_UNKNOWN_FILE", `bivium why: no file ${file}${didYouMean(file, computed.graph.keys())}`);
1730
1732
  }
1731
1733
  const explanation = await explain(root, config, computed, test, file, {
1732
1734
  all: flags.has("--all")
@@ -1737,7 +1739,7 @@ async function inspect(command, { flags, positional }) {
1737
1739
  async function graphCommand({ flags }) {
1738
1740
  const top = Number(flags.get("--top") ?? "10");
1739
1741
  if (!Number.isInteger(top) || top < 0) {
1740
- throw usageError("bivium graph: --top takes a whole number");
1742
+ throw usageError("BV_BAD_OPTION_VALUE", "bivium graph: --top takes a whole number");
1741
1743
  }
1742
1744
  const { root, base, config } = await prepare({
1743
1745
  cwd: flags.get("--cwd"),
@@ -1761,10 +1763,11 @@ async function runCommand(command, { flags, positional }) {
1761
1763
  configFile: flags.get("--config")
1762
1764
  });
1763
1765
  const suite = findSuite(config, flags.get("--suite")) ?? config.suites[0];
1764
- if (suite === undefined)
1765
- throw new BiviumError("config", "bivium: no suites");
1766
+ if (suite === undefined) {
1767
+ throw new BiviumError2("BV_CONFIG_INVALID", "bivium config: no suites");
1768
+ }
1766
1769
  if (command === "run" && !suite.run) {
1767
- throw usageError(`bivium run: suite "${suite.name}" has no run command: add suites.${suite.name}.run to the config`);
1770
+ throw usageError("BV_NO_RUN_COMMAND", `bivium run: suite "${suite.name}" has no run command: add suites.${suite.name}.run to the config`);
1768
1771
  }
1769
1772
  const computed = await computePlan(root, base, config, {
1770
1773
  ...flags.has("--no-cache") && { cache: false },
@@ -1807,7 +1810,7 @@ async function runCommand(command, { flags, positional }) {
1807
1810
  }
1808
1811
  const [program, ...args] = commandFor(suite.run ?? "", selection.mode === "some" ? selection.files : []);
1809
1812
  if (program === undefined) {
1810
- throw usageError(`bivium run: suite "${suite.name}" has no run command: add suites.${suite.name}.run to the config`);
1813
+ throw usageError("BV_NO_RUN_COMMAND", `bivium run: suite "${suite.name}" has no run command: add suites.${suite.name}.run to the config`);
1811
1814
  }
1812
1815
  const result = spawnSync(program, args, { cwd: root, stdio: "inherit" });
1813
1816
  return result.status ?? 1;
@@ -1828,10 +1831,12 @@ var COMMANDS = Object.keys(FLAGS);
1828
1831
  function wantsJson(argv) {
1829
1832
  return argv.some((arg, i) => arg === "--json" || arg === "--json=true" || arg === "--format=json" || arg === "--format" && argv[i + 1] === "json");
1830
1833
  }
1831
- function fail(argv, kind, message) {
1832
- console.error(message);
1833
- if (wantsJson(argv))
1834
- console.log(json({ error: { kind, message } }));
1834
+ function fail(argv, error) {
1835
+ console.error(error.message);
1836
+ if (wantsJson(argv)) {
1837
+ const { kind, code, message } = error;
1838
+ console.log(json({ error: { kind, code, message } }));
1839
+ }
1835
1840
  return 2;
1836
1841
  }
1837
1842
  async function main(argv) {
@@ -1850,10 +1855,10 @@ async function main(argv) {
1850
1855
  return 0;
1851
1856
  }
1852
1857
  if (command === undefined) {
1853
- return fail(argv, "usage", `bivium: which command? ${COMMANDS.join(", ")} (bivium --help for usage)`);
1858
+ return fail(argv, usageError("BV_MISSING_ARGUMENT", `bivium: which command? ${COMMANDS.join(", ")} (bivium --help for usage)`));
1854
1859
  }
1855
1860
  if (!(command in FLAGS)) {
1856
- return fail(argv, "usage", `bivium: unknown command "${command}"${didYouMean(command, COMMANDS)}; the commands are ${COMMANDS.join(", ")} (bivium --help for usage)`);
1861
+ return fail(argv, usageError("BV_UNKNOWN_COMMAND", `bivium: unknown command "${command}"${didYouMean(command, COMMANDS)}; the commands are ${COMMANDS.join(", ")} (bivium --help for usage)`));
1857
1862
  }
1858
1863
  const rest = [...argv.slice(0, at), ...argv.slice(at + 1)];
1859
1864
  try {
@@ -1864,11 +1869,10 @@ async function main(argv) {
1864
1869
  return await graphCommand(args);
1865
1870
  return await runCommand(command, args);
1866
1871
  } catch (error) {
1867
- if (error instanceof BiviumError) {
1868
- return fail(argv, error.kind, error.message);
1869
- }
1872
+ if (error instanceof BiviumError2)
1873
+ return fail(argv, error);
1870
1874
  const message = error instanceof Error ? error.message : String(error);
1871
- return fail(argv, "other", message);
1875
+ return fail(argv, new BiviumError2("BV_INTERNAL", message, { cause: error }));
1872
1876
  }
1873
1877
  }
1874
1878
 
package/docs/api.md ADDED
@@ -0,0 +1,69 @@
1
+ # API
2
+
3
+ `plan()` returns what `bivium plan --json` prints, typed by your config;
4
+ narrowers refine a plan from a semantic diff.
5
+
6
+ ## plan()
7
+
8
+ ```ts
9
+ import { defineConfig, plan } from "bivium";
10
+
11
+ const config = defineConfig({ suites: { unit: { tests: "tests/**/*.test.ts" } } });
12
+ const result = await plan({ config, base: "origin/main" });
13
+ result.suites.unit; // { mode: "some", files: [...] }; result.suites.e2e is a type error
14
+ ```
15
+
16
+ `plan(options?)`
17
+ takes `cwd`, `base`, `config` (default: the config file in `cwd`)
18
+ and `cache`, and returns each suite's selection, its test count,
19
+ the reasons as sentences and as data,
20
+ the packages a lockfile change seeded or found inert, the base,
21
+ merge base and changed files, and what each narrower returned.
22
+ Given a config, the suite names carry through to the result's type.
23
+ The package exports only `plan`, `defineConfig` and their types.
24
+
25
+ ## Narrowers
26
+
27
+ Some changes reach every test through a generated file:
28
+ every page loads the compiled stylesheet,
29
+ so any style edit selects every e2e test.
30
+ A narrower replaces such a change's coarse seeds with finer ones from a
31
+ semantic diff, such as the sources that render a changed CSS rule.
32
+
33
+ ```ts
34
+ narrowers: [
35
+ {
36
+ name: "css",
37
+ match: "styles/**", // the changed files it narrows
38
+ opaque: "dist/*.css", // the generated nodes its seeds stand in for
39
+ suites: ["e2e"],
40
+ async narrow({ base, head, changed, graph }) {
41
+ const rules = diffRules(await compile(base.commit), await compile(head.commit));
42
+ if (!rules) return { all: "a rule that requires no class changed" };
43
+ return { seeds: sourcesSpelling(rules), note: `${rules.length} rules changed` };
44
+ },
45
+ },
46
+ ],
47
+ ```
48
+
49
+ The matched files still seed the walk,
50
+ but it stops at the `opaque` nodes, and the seeds stand in for them.
51
+ A narrower can only narrow: its suites' selection is cut to what the
52
+ walk without it selects.
53
+ One that returns `{ all: reason }`, throws,
54
+ or returns anything else runs its suites in full with the reason.
55
+ `narrow()` gets:
56
+
57
+ - `root`, the repository;
58
+ - `base` and `head`, the merge base and the working tree,
59
+ each with `commit` and `read(path)`;
60
+ - `changed`, the matched files;
61
+ - `graph`, read-only: `nodes()`, `importers(node)`,
62
+ `dependents(nodes)` and `tests(suite)`.
63
+
64
+ carbon-components-svelte runs one over crassus.
65
+
66
+ ## Related
67
+
68
+ - [Config](config.md): `defineConfig` and every key
69
+ - [CLI](cli.md): the same plan from the command line
package/docs/ci.md ADDED
@@ -0,0 +1,112 @@
1
+ # CI
2
+
3
+ Plan in a job of its own, before any install,
4
+ and skip the test jobs whose selection is `none`.
5
+
6
+ Plan in a job of its own, before any install,
7
+ and feed each suite's job its selection:
8
+
9
+ ```yaml
10
+ jobs:
11
+ plan:
12
+ runs-on: ubuntu-latest
13
+ outputs:
14
+ unit: ${{ steps.plan.outputs.unit-tests }}
15
+ e2e: ${{ steps.plan.outputs.e2e-tests }}
16
+ steps:
17
+ - uses: actions/checkout@v7
18
+ with:
19
+ # History back to the merge base; see "The checkout" below.
20
+ fetch-depth: 0
21
+ filter: blob:none
22
+ - uses: oven-sh/setup-bun@v2
23
+ - id: merge-base
24
+ run: echo "sha=$(git merge-base origin/main HEAD)" >> "$GITHUB_OUTPUT"
25
+ - uses: actions/cache@v6
26
+ with:
27
+ path: .bivium/cache
28
+ key: bivium-${{ steps.merge-base.outputs.sha }}
29
+ restore-keys: bivium-
30
+ - id: plan
31
+ # --bun: run on Bun, which loads a TypeScript config whatever Node
32
+ # the runner has.
33
+ run: bunx --bun bivium plan origin/main --github
34
+ unit:
35
+ needs: plan
36
+ if: needs.plan.outputs.unit != 'none'
37
+ steps:
38
+ # …install, then run all tests or the selected files:
39
+ - run: bunx vitest run ${{ needs.plan.outputs.unit != 'all' && needs.plan.outputs.unit || '' }}
40
+ ```
41
+
42
+ ## The checkout
43
+
44
+ A plan compares the branch with its merge base:
45
+ the commit where it forked from the base branch.
46
+ So the job needs the history back to that commit,
47
+ not only the commit under test.
48
+ `actions/checkout` fetches one commit by default (`fetch-depth: 1`),
49
+ with no base branch, and the plan stops with what's missing:
50
+
51
+ ```text
52
+ bivium: origin/main and HEAD share no commit here, so there's no merge base to diff against. The clone is shallow: fetch the history (actions/checkout: `fetch-depth: 0`).
53
+ ```
54
+
55
+ `fetch-depth: 0` fetches every commit.
56
+ Only a job that plans needs it; one that runs every test anyway,
57
+ such as a push to the default branch, can keep the default:
58
+ `fetch-depth: ${{ github.event_name == 'pull_request' && '0' || '1' }}`.
59
+
60
+ The history git fetches is three kinds of object: commits;
61
+ trees, each directory's file names with the ID of each one's content;
62
+ and blobs, the contents.
63
+ A plan needs the commits, to find the merge base, and the trees,
64
+ to list what changed.
65
+ Of the blobs it needs the working tree's, which the checkout has,
66
+ and the merge base's version of a few changed files only:
67
+ a lockfile, a `package.json`, a `tsconfig.json`, a barrel,
68
+ and what a narrower reads.
69
+ So pick the clone by how big the history is:
70
+
71
+ | History | Checkout | What a plan pays |
72
+ | :--- | :--- | :--- |
73
+ | Small: a full clone takes a second or two | `fetch-depth: 0` | Nothing more: every old version is already on disk |
74
+ | Large: years of commits, big files | `fetch-depth: 0` and `filter: blob:none` | A fetch from the remote for the old versions it reads, when a change needs any: about a second, sometimes several |
75
+
76
+ `filter: blob:none` makes a partial clone: every commit and tree,
77
+ and only the blobs the checkout needs.
78
+ Git fetches any other blob when something reads it,
79
+ and fetches for reads made at once run in parallel.
80
+ Without the filter, a large history's old contents are most of the
81
+ download; with it, a small repository pays a round trip to the remote
82
+ for contents it could have had for free.
83
+
84
+ ## The cache
85
+
86
+ The cache holds what bivium extracted from each file, keyed by git blob,
87
+ so a warm plan reads only the files a branch changed.
88
+ Key it on the merge base: a pull request can restore caches from the
89
+ default branch, whose run at that commit is the one to hit.
90
+ Without `node_modules`, the cache lives in `.bivium/cache`;
91
+ it writes a `.gitignore` so it never shows up as a change.
92
+
93
+ ## What a plan costs
94
+
95
+ Measured on an Apple M-series laptop under load
96
+ (median of five, wall time):
97
+
98
+ | Repository | Files | Bun, no cache | Bun, warm | Node 24, no cache | Node 24, warm | Cache |
99
+ |:---|---:|---:|---:|---:|---:|---:|
100
+ | carbon-components-svelte | 4,680 | 0.15 s | 0.09 s | 0.27 s | 0.13 s | 452 KB |
101
+ | generated TypeScript, 23 MB | 7,000 | 0.14 s | 0.08 s | 0.30 s | 0.12 s | 896 KB |
102
+
103
+ So the cache is optional at this size, `bunx --bun` is worth it,
104
+ and planning inside a test job (no extra job, no install) costs well
105
+ under a second.
106
+ A cold plan of the generated repository peaks at 88 MB of RSS on Bun
107
+ and 124 MB on Node.
108
+
109
+ ## Related
110
+
111
+ - [CLI](cli.md): `plan --github` and the other commands
112
+ - [How it works](how-it-works.md): what a plan reads
package/docs/cli.md ADDED
@@ -0,0 +1,133 @@
1
+ # CLI
2
+
3
+ Five commands: `plan` picks the tests, `run` runs them,
4
+ `why` explains one, `check` finds what widens plans,
5
+ and `graph` shows where they fan out.
6
+
7
+ | Command | Does |
8
+ |:---|:---|
9
+ | `bivium plan [base] [--json] [--github]` | Prints what it planned against (the base, its merge base, how many files changed, the config file), then each suite's selection (`none`, the files out of how many, `all` files when each reaches a change, or `all (full run)`) and why a suite runs in full. `--json` adds the base, merge base, config file, changed files, narrower results, changed packages, each suite's test count (`totals`), and the reasons as data (`causes`, each a `FullRunCause`: `{ kind, suites, file?, package?, narrower?, message }`). `--github` also writes each suite's selection to `$GITHUB_OUTPUT` |
10
+ | `bivium run [base] [--suite <name>]` | Runs the suite's `run` command with its selection (default: the first suite), or skips it when nothing is affected |
11
+ | `bivium why <test> [file] [--format tree\|chain\|source\|json] [--all]` | The shortest chain of edges from a changed file, or from `file`, to the test, with what spells each edge and the line it's on, and how many other changes reach the test. `--format tree` (the default) draws it from the test; `chain` reads from the change to the test; `source` prints each hop's line of source; `json` (or `--json`) prints the chain as data. `--all` shows every change's chain. For a test that isn't selected, it says what the file's chains reach instead |
12
+ | `bivium check [--max-unknown <n>] [--json]` | Counts what it found by cause first, then lists every node with unknown dependencies, with where and how to fix each cause, and fails when more than `n` of them reach a test, or on one `knownUnknowns` doesn't list. A node no test depends on is listed apart and not counted: plans only run tests, so it widens nothing. Also lists the files under a suite's `root` that no test reaches, each with a fix (a change to one runs the whole suite; see [A change no test reaches](tuning.md#a-change-no-test-reaches)), `tsconfig.json` files that don't parse, and [dead globs](tuning.md#dead-globs), and fails on one `deadGlobs` doesn't allow or on an entry that matches none. Fails on a repository path a test spells that nothing declares (see [A change no test reaches](tuning.md#a-change-no-test-reaches)). `--json` prints the report as data, with `ok` (what the exit status says) and `summary` (the counts the text leads with) |
13
+ | `bivium graph [--suite <name>] [--top <n>] [--json]` | How many of each suite's tests a change to each file selects through the graph (leaving out the tests that run on any change, which it counts apart): the `n` files that reach the most, and how files spread from none to every test. A few hub files that reach most tests are what make plans wide. `--json` prints each suite's `total` and `everyChange` tests, and every node with its `imports` and `importers` (file edges), `fanIn` per suite and whether it's `unknown` |
14
+
15
+ `--config`, `--cwd` and `--no-cache` work with every command,
16
+ before or after it, and `why` and `check` take `--base <ref>`.
17
+ An option takes its value as `--flag value` or `--flag=value`,
18
+ and a switch such as `--json` also takes `=true` or `=false`.
19
+ A path may be repo-relative, relative to the current directory
20
+ (`./tests/a.test.ts`) or absolute.
21
+ `--help` (or `-h`) prints usage.
22
+ An unknown command, option, suite, test or `--format` is an error,
23
+ which names what's close when something is
24
+ (`unknown option --jsno (did you mean --json?)`).
25
+ Exit status: 0 when done, 1 when `check` finds problems, 2 for a usage,
26
+ configuration or git error; `run` exits with its command's status.
27
+
28
+ Every JSON output carries `schemaVersion`, which is `1`;
29
+ a change that drops or retypes a field bumps it, and new fields don't.
30
+ With `--json`, an error is also printed to stdout as JSON,
31
+ so a pipeline that parses stdout gets an object either way:
32
+
33
+ ```json
34
+ { "schemaVersion": 1, "error": { "kind": "git", "code": "BV_GIT_NO_BASE", "message": "bivium: no commit nosuchref here to diff against: fetch it." } }
35
+ ```
36
+
37
+ | `kind` | Means |
38
+ | --- | --- |
39
+ | `usage` | bivium was called wrong |
40
+ | `config` | the config can't be read or is invalid; the message names the file and lists every unknown key at once |
41
+ | `git` | the base or its history is missing, or git refused, in its own words |
42
+ | `other` | a failure bivium didn't name |
43
+
44
+ `code` names the failure, such as `BV_UNKNOWN_OPTION`
45
+ or `BV_CONFIG_INVALID`, and never changes meaning:
46
+ the `BiviumErrorCode` type lists them all, each with what it means.
47
+ From the library, `plan()` throws a `BiviumError` with the same `code`
48
+ and `kind`.
49
+
50
+ ## From an agent
51
+
52
+ - `bivium plan --json` gives the selection per suite and why:
53
+ `causes` (typed) for each full run, `totals` for the scale, `changed`,
54
+ `base` and `mergeBase`.
55
+ - `bivium why <test> --format json` gives the chain from a change to a
56
+ test, with each link's `kind`, such as `import` or `goto`, and `at`,
57
+ as `file:line`.
58
+ - `bivium check --json` gives `ok` and a `summary` of what widens plans,
59
+ then each node with a `fix`.
60
+ - Read the exit status first: 0 done, 1 `check` found problems,
61
+ 2 an error, with `error.kind` and `error.code` in the JSON.
62
+
63
+ ## Reading `why`
64
+
65
+ `why` names each edge by what spells it:
66
+
67
+ | Edge | Spelled by |
68
+ | --- | --- |
69
+ | `import` | any other import: static, dynamic, `require()` or `vi.mock()` |
70
+ | `type` | an `import type`, `export type … from`, a JSDoc type, or an edge to or from a declaration file |
71
+ | `setup` | a suite's setup file |
72
+ | `goto` | a page `page.goto()` opens |
73
+ | `html` | a module an HTML page loads: `script[src]`, `link[href]`, `iframe[src]` or an inline script's import |
74
+ | `name`, `export` | a named import bound to a barrel name, and the file that exports it |
75
+ | `glob` | `import.meta.glob` |
76
+ | `depends-on`, `reads`, `lists` | the annotations |
77
+ | `edges` | the config's `edges` |
78
+
79
+ ```console
80
+ $ bunx bivium why e2e/accordion.test.ts
81
+ e2e/accordion.test.ts
82
+ └─ goto e2e/fixtures/accordion.html e2e/accordion.test.ts:13
83
+ └─ html e2e/fixtures/accordion.ts e2e/fixtures/accordion.html:10
84
+ └─ import e2e/fixtures/Fixture.svelte e2e/fixtures/accordion.ts:1
85
+ └─ name src/index.js#AccordionItem e2e/fixtures/Fixture.svelte:2
86
+ └─ export src/AccordionItem.svelte src/index.js:2
87
+ ● changed
88
+ + 1 more change reaches this test: css/_accordion.scss (--all shows each chain)
89
+
90
+ $ bunx bivium why e2e/accordion.test.ts --format chain
91
+ src/AccordionItem.svelte changed
92
+ exported as AccordionItem src/index.js:2
93
+ imported by e2e/fixtures/Fixture.svelte:2
94
+ imported by e2e/fixtures/accordion.ts:1
95
+ loaded by page e2e/fixtures/accordion.html:10
96
+ opened by e2e/accordion.test.ts:13 ← selected
97
+ + 1 more change reaches this test: css/_accordion.scss (--all shows each chain)
98
+
99
+ $ bunx bivium why e2e/accordion.test.ts --format source
100
+ selected: e2e/accordion.test.ts ← src/AccordionItem.svelte (5 hops)
101
+
102
+ --> e2e/accordion.test.ts:13 goto
103
+ 13 | await page.goto("/accordion.html");
104
+ --> e2e/fixtures/accordion.html:10 html
105
+ 10 | <script type="module" src="./accordion.ts"></script>
106
+ --> e2e/fixtures/accordion.ts:1 import
107
+ 1 | import Fixture from "./Fixture.svelte";
108
+ --> e2e/fixtures/Fixture.svelte:2 name
109
+ 2 | import { Accordion, AccordionItem } from "carbon-components-svelte";
110
+ --> src/index.js:2 export
111
+ 2 | export { default as AccordionItem } from "./AccordionItem.svelte";
112
+ ● src/AccordionItem.svelte: changed
113
+ + 1 more change reaches this test: css/_accordion.scss (--all shows each chain)
114
+ ```
115
+
116
+ For a test that depends on every change, `chain` says why, where,
117
+ and how to fix it, as `check` does:
118
+
119
+ ```console
120
+ $ bunx bivium why tests/e2e.test.ts --format chain
121
+ tests/e2e.test.ts runs on every change
122
+ because scripts/launcher.js:10 unresolved "./cli-entry.js"
123
+ fix: no file at that path: fix the import, or add an `edges` entry if a build generates it
124
+ reached via scripts/launcher.js
125
+ depended on by scripts/build.ts:1
126
+ depended on by tests/e2e.test.ts:2 ← selected
127
+ ```
128
+
129
+ ## Related
130
+
131
+ - [CI](ci.md): planning in GitHub Actions
132
+ - [Tuning a plan](tuning.md): fixing what `check` reports
133
+ - [API](api.md): the same plan from code
package/docs/config.md ADDED
@@ -0,0 +1,59 @@
1
+ # Config
2
+
3
+ bivium reads `bivium.config.ts` from the repository root;
4
+ every key, and the comments a file can carry, are below.
5
+
6
+ `bivium.config.ts` (or `.mts`, `.mjs`, `.js`, `.json`) in the repository
7
+ root, or `--config <file>`.
8
+ A `.ts` config needs Bun or Node ≥ 22.18.
9
+ Every glob key takes one glob or a list.
10
+ An unknown key is an error, since a misspelled one would quietly select
11
+ less.
12
+
13
+ | Key | Meaning |
14
+ |:---|:---|
15
+ | `suites.<name>.tests` | The suite's test files |
16
+ | `suites.<name>.run` | The command `bivium run` runs. `{files}` is replaced by the selection (nothing for `all`); without it, the files are appended |
17
+ | `suites.<name>.root` | Where the orphan rule applies: a changed file here that no test of the suite reaches is wired some other way (a setup file, a runner config), so the whole suite runs. Paths, not globs (`e2e`, not `e2e/**`): a glob is an error. Default: the whole repository |
18
+ | `suites.<name>.urls` | URL pattern → file pattern, for `page.goto()` calls under `root`. A list names the page first, then what else it loads that no import says, such as a router's layouts: `{ "/*": ["app/(site)/*/page.tsx", "app/(site)/layout.tsx", "app/layout.tsx"] }`. The page must exist; the rest are edges where they do |
19
+ | `suites.<name>.pages` | Pages only a `goto()` opens; files only they load are wired to no test |
20
+ | `suites.<name>.setup` | Files the runner loads before every test (Vitest and Jest `setupFiles`, Mocha `--require`, Playwright `globalSetup`): every test of the suite depends on them and what they import. bivium doesn't read the runner's config, so name them here |
21
+ | `suites.<name>.wiring` | Files whose change runs the whole suite: another harness, a runner config |
22
+ | `suites.<name>.nonInputs` | Files under `root` the runner never reads, such as type-check inputs |
23
+ | `suites.<name>.types` | `false` when the suite runs code and can't observe types (Vitest, Jest, Playwright, `bun test`): a change that reaches its tests only through `import type`, `export type … from`, JSDoc types or a declaration file selects none of them. For the orphan rule a type-only reach counts only for a declaration file, since the runner may load any other file by name: list a types-only module under `root` in `nonInputs`. Default: `true`, which a type-checking suite (`tsc`, `vitest --typecheck`) needs. An inline `import { type A }` is always an edge: under `verbatimModuleSyntax` it still loads the module |
24
+ | `suites.<name>.output` | The step output `plan --github` writes. Default: `<name>-tests` |
25
+ | `roots` | Paths (not globs) the graph reads. A changed file outside them that isn't ignored runs everything. Default: the whole repository |
26
+ | `ignore` | Files no test can observe except through an edge (docs, stories). A change to one selects only the tests that reach it, never runs a suite by the orphan rule, and doesn't select the tests whose dependencies are unknown |
27
+ | `alias` | Specifier prefix → path, as the bundler aliases it. Tried before tsconfig `paths` and `package.json` `exports`. A key ending in `/` is the prefix, as Vite reads it: `{ "@/": "src/" }` maps `@/x` to `src/x` |
28
+ | `edges` | Generated file glob → its inputs, which it depends on transitively, as with `@depends-on`: `{ "dist/*.css": "styles/**" }`. A key may name files git doesn't list, such as a gitignored generator output (`{ ".velite/*": "content/**" }`): an import that resolves under it, by extension or as an index, lands on that file instead of being unresolved. In a value, `$1`, `$2`… are what the key's wildcards matched, counted from the left: `{ "examples/*/package.json": "examples/$1/**" }` |
29
+ | `reads` | File glob → the files it reads as text, as with `@reads`: only a direct change to one counts, so their imports and unknowns don't spread to it. An `edges` or `reads` key that names one file (no wildcard) declares what it reads, as its own `@depends-on` or `@reads` would, so its disk reads aren't unknown. Values take `$1`… as in `edges`: `{ "tests/*.test.ts": "tests/__snapshots__/$1.test.ts.snap" }` |
30
+ | `self` | The selector's own files: a change to one runs everything. The config file is always one |
31
+ | `importOnly` | Files only an import reaches: deleting one never orphans a suite |
32
+ | `hermetic` | Files whose disk reads and non-literal imports reach no file of the repository: a library's `fs` calls on its caller's paths, a test that reads only the temporary files it writes. They add no unknown, and `check` still flags a repository path one spells that nothing declares |
33
+ | `barrels` | Modules that may bind named imports. Default: every module made only of re-exports |
34
+ | `external` | Packages a dependency installs that your code imports without declaring |
35
+ | `inert` | Packages no test uses except by importing them: linters, formatters, type packages (`["@biomejs/biome", "knip", "@types/*"]`). A [lockfile change](how-it-works.md#lockfiles) that only they reach selects nothing. With `loadedByName` set, only packages with a `bin` need listing. bivium itself always is |
36
+ | `loadedByName` | Packages a test may load other than by an import: a test environment or a plugin a config names by string (`["jsdom", "ts-jest"]`). Setting it, even to `[]`, says every other package without a `bin` is loaded only by imports, so a [lockfile change](how-it-works.md#lockfiles) that reaches one no test imports selects only its importers. A package with a `bin` always counts as one a test may run |
37
+ | `extensions` | Suffixes tried after a specifier |
38
+ | `deadGlobs` | Dead globs `check` allows, each `{ file, glob, reason }`, the glob as `file` spells it |
39
+ | `knownUnknowns` | Nodes `check` allows to have unknown dependencies, each `{ file, reason }`. With it set, even to `[]` (which is `--max-unknown 0`), `check` fails on an unknown node some test reaches that it doesn't list, and on an entry that's no longer unknown, so a new unknown can't replace one that went away |
40
+ | `narrowers` | See [Narrowers](api.md#narrowers) |
41
+ | `base` | The default base ref. Otherwise the upstream default branch (`origin/HEAD`, then `origin/main`, `origin/master`, `main`, `master`) |
42
+ | `cache` | The cache's directory, or `false`. Default: `node_modules/.cache/bivium`, or `.bivium/cache` |
43
+
44
+ ## Annotations
45
+
46
+ | Comment | Meaning |
47
+ |:---|:---|
48
+ | `// @depends-on <glob> [glob…]` | Inputs that aren't imports: files a script reads, a tool it spawns, the pages a `goto()` the graph can't read opens (a loop over a list of URLs). Transitive. A file that reads the disk without one (or `@reads`, or `@lists`), or calls `goto()` with a URL it can't read, is unknown, unless it's `hermetic` |
49
+ | `// @reads <glob> [glob…]` | Files read as text. Only a direct change to one counts, not a change to what it imports. The config's `reads` says the same for files that can't hold a comment |
50
+ | `// @lists <glob> [glob…]` | Files whose names it lists, not their contents: a convention test that checks every route has a handler. Only adding, deleting or renaming one counts; an edit doesn't select it, and doesn't run its suite by the orphan rule either |
51
+ | `// @glob-registry` | This file's `import.meta.glob` is a lookup table and adds no edges: whatever loads an entry names it itself |
52
+
53
+ ## Related
54
+
55
+ - [Tuning a plan](tuning.md): which key to reach for
56
+ when a change runs too much
57
+ - [Recipes](recipes.md): Vitest, Jest, Playwright, pnpm workspaces,
58
+ generated code
59
+ - [How it works](how-it-works.md): what the graph follows