bivium 0.9.0 → 0.11.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/compute.js CHANGED
@@ -6,9 +6,10 @@ import {
6
6
  computePlan2,
7
7
  prepare2,
8
8
  plan2
9
- } from "./shared-07rt4zr7.js";
10
- import"./shared-550cvwt2.js";
11
- import"./shared-211m8fjt.js";
9
+ } from "./shared-wxem8d5w.js";
10
+ import"./shared-qaqjsxsk.js";
11
+ import"./shared-p3qfqmwd.js";
12
+ import"./shared-mpjk8met.js";
12
13
  export {
13
14
  collectPackages2 as collectPackages,
14
15
  computePlan2 as computePlan,
package/config.js CHANGED
@@ -4,8 +4,9 @@ import {
4
4
  inRoot2,
5
5
  checkConfig2,
6
6
  loadConfig2
7
- } from "./shared-550cvwt2.js";
8
- import"./shared-211m8fjt.js";
7
+ } from "./shared-qaqjsxsk.js";
8
+ import"./shared-p3qfqmwd.js";
9
+ import"./shared-mpjk8met.js";
9
10
  export {
10
11
  checkConfig2 as checkConfig,
11
12
  defineConfig2 as defineConfig,
package/docs/api.md CHANGED
@@ -34,6 +34,7 @@ except `schemaVersion` and `config`:
34
34
  | Field | Holds |
35
35
  | --- | --- |
36
36
  | `suites` | each suite's selection: `{ mode: "all" }`, `{ mode: "none" }`, or `{ mode: "some", files }` |
37
+ | `cases` | per suite, each selected test that needs only some of its [`@depends-on-each`](config.md#cases) cases → those cases |
37
38
  | `totals` | how many test files each suite has |
38
39
  | `reasons` | why a suite runs in full, as sentences |
39
40
  | `causes` | the same reasons as data, one `FullRunCause` each, in order |
@@ -41,6 +42,8 @@ except `schemaVersion` and `config`:
41
42
  | `base`, `mergeBase` | the base ref, and the merge base the working tree is compared with |
42
43
  | `changed` | the files changed since the merge base, untracked ones included |
43
44
  | `narrowed` | what each narrower that ran returned, as `{ name, result }` |
45
+ | `shards` | per suite with [`shards`](config.md#shards-and-timings), its selection split: `Shard[]`, each `{ shard, files, estimatedMs }` |
46
+ | `timings` | per suite with `shards`, what balanced them: `{ file, timed, medianMs, problem? }` |
44
47
 
45
48
  On failure, `plan()` throws a `BiviumError`,
46
49
  whose `code` and `kind` are the CLI's
package/docs/ci.md CHANGED
@@ -12,15 +12,15 @@ jobs:
12
12
  unit: ${{ steps.plan.outputs.unit-tests }}
13
13
  e2e: ${{ steps.plan.outputs.e2e-tests }}
14
14
  steps:
15
- - uses: actions/checkout@v7
15
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
16
16
  with:
17
17
  # History back to the merge base; see "The checkout" below.
18
18
  fetch-depth: 0
19
19
  filter: blob:none
20
- - uses: oven-sh/setup-bun@v2
20
+ - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
21
21
  - id: merge-base
22
22
  run: echo "sha=$(git merge-base origin/main HEAD)" >> "$GITHUB_OUTPUT"
23
- - uses: actions/cache@v6
23
+ - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
24
24
  with:
25
25
  path: .bivium/cache
26
26
  key: bivium-${{ steps.merge-base.outputs.sha }}
@@ -45,8 +45,30 @@ The value is `all`, `none`, or the selected files, separated by spaces.
45
45
  The `unit` job skips on `none`, runs every test on `all`,
46
46
  and otherwise passes the files to Vitest.
47
47
 
48
+ A suite whose selected tests need only some of their
49
+ [cases](config.md#cases) also gets `<suite>-cases`: the case paths,
50
+ separated by spaces.
51
+ A job that runs the runner itself writes them to a file, one per line,
52
+ and names it in `BIVIUM_CASES`; when the output is empty,
53
+ it sets nothing, and every case runs:
54
+
55
+ ```yaml
56
+ - run: |
57
+ if [ -n "$CASES" ]; then
58
+ printf '%s\n' $CASES > "$RUNNER_TEMP/cases.txt"
59
+ export BIVIUM_CASES="$RUNNER_TEMP/cases.txt"
60
+ fi
61
+ bunx playwright test ${{ needs.plan.outputs.e2e != 'all' && needs.plan.outputs.e2e || '' }}
62
+ env:
63
+ CASES: ${{ needs.plan.outputs.e2e-cases }}
64
+ ```
65
+
66
+ The `plan` job passes it on as it does the selections,
67
+ under `outputs`: `e2e-cases: ${{ steps.plan.outputs.e2e-cases }}`.
68
+
48
69
  Three decisions shape the workflow: the checkout, the cache,
49
70
  and the cost of a plan.
71
+ A suite too slow for one job can also run in [shards](#shards).
50
72
 
51
73
  ## The checkout
52
74
 
@@ -123,6 +145,117 @@ The plan job runs before any install, so its cache is `.bivium/cache`.
123
145
  bivium writes a `.gitignore` there, so the cache never shows up as
124
146
  a change.
125
147
 
148
+ ## Shards
149
+
150
+ A suite with [`shards`](config.md#shards-and-timings) gets its selection
151
+ split by recorded durations, one shard per job.
152
+ The plan job restores the timings file before it plans,
153
+ and a matrix job runs one shard each:
154
+
155
+ ```yaml
156
+ jobs:
157
+ plan:
158
+ runs-on: ubuntu-latest
159
+ timeout-minutes: 5
160
+ permissions:
161
+ contents: read
162
+ outputs:
163
+ unit-matrix: ${{ steps.plan.outputs.unit-matrix }}
164
+ unit-shards: ${{ steps.plan.outputs.unit-shards }}
165
+ steps:
166
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
167
+ with:
168
+ fetch-depth: 0
169
+ filter: blob:none
170
+ - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
171
+ - uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
172
+ with:
173
+ path: .bivium/timings
174
+ key: bivium-timings-${{ github.run_id }}
175
+ restore-keys: bivium-timings-
176
+ - id: plan
177
+ # A push to master plans its own changes, so it runs, and records,
178
+ # the tests they reach.
179
+ run: bunx --bun bivium plan "$BASE" --github
180
+ env:
181
+ BASE: ${{ github.event_name == 'push' && github.event.before || 'origin/master' }}
182
+ unit:
183
+ needs: plan
184
+ if: needs.plan.outputs.unit-shards != '0'
185
+ runs-on: ubuntu-latest
186
+ timeout-minutes: 15
187
+ permissions:
188
+ contents: read
189
+ strategy:
190
+ fail-fast: false
191
+ matrix:
192
+ include: ${{ fromJSON(needs.plan.outputs.unit-matrix) }}
193
+ name: unit (shard ${{ matrix.shard }})
194
+ steps:
195
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
196
+ - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
197
+ - run: bun ci
198
+ # This shard's durations alone, in a file of its own.
199
+ - run: bun test --parallel --timings="$RUNNER_TEMP/timings.json" --update-timings ${{ matrix.files }}
200
+ - if: github.ref == 'refs/heads/master'
201
+ uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
202
+ with:
203
+ name: timings-unit-${{ matrix.shard }}
204
+ path: ${{ runner.temp }}/timings.json
205
+ timings:
206
+ needs: unit
207
+ if: github.ref == 'refs/heads/master'
208
+ runs-on: ubuntu-latest
209
+ timeout-minutes: 5
210
+ # The cache and artifacts take the runner's own token, not this one.
211
+ permissions: {}
212
+ steps:
213
+ - uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
214
+ with:
215
+ path: .bivium/timings
216
+ key: bivium-timings-${{ github.run_id }}
217
+ restore-keys: bivium-timings-
218
+ - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
219
+ with:
220
+ pattern: timings-unit-*
221
+ path: shards
222
+ # Each shard's durations over the last ones, so a test this run
223
+ # didn't select keeps its entry.
224
+ - run: |
225
+ file=.bivium/timings/unit.json
226
+ mkdir -p .bivium/timings
227
+ [ -f "$file" ] || echo '{"version":1,"files":{}}' > "$file"
228
+ jq -s '{version: 1, files: (map(.files) | add)}' "$file" shards/*/timings.json > merged.json
229
+ mv merged.json "$file"
230
+ - uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
231
+ with:
232
+ path: .bivium/timings
233
+ key: bivium-timings-${{ github.run_id }}
234
+ ```
235
+
236
+ Each action is pinned to a release's commit, with the version beside it:
237
+ a tag can be moved, a commit can't.
238
+ The `unit` job skips when `unit-shards` is `0`:
239
+ GitHub Actions fails a job whose matrix has no entries,
240
+ and a job-level `if` skips it before the matrix is read.
241
+ Each shard's `files` are explicit, even on a full run,
242
+ so the same job runs any runner:
243
+ `npx playwright test ${{ matrix.files }}` balances Playwright the
244
+ same way.
245
+ The files come longest first, so `bun test --parallel` starts the
246
+ slowest first within the shard too.
247
+
248
+ A cache entry can't be overwritten, so each run saves under its own key,
249
+ and `restore-keys` picks the newest.
250
+ A pull request restores what the default branch saved,
251
+ and only the default branch saves, so a branch's runs can't skew the
252
+ durations another branch splits by.
253
+
254
+ Without a timings file, a count splits by file count,
255
+ and a target takes `max` shards.
256
+ Each run on the default branch records the tests it ran,
257
+ and later plans balance by them.
258
+
126
259
  ## What a plan costs
127
260
 
128
261
  Measured on an Apple M-series laptop under load
@@ -144,7 +277,8 @@ and 124 MB on Node.
144
277
  ## Related
145
278
 
146
279
  - [CLI](cli.md): `plan --github` and the other commands
147
- - [Config](config.md): a suite's `output`, and `cache`
280
+ - [Config](config.md): a suite's `output`, `shards` and `timings`,
281
+ and `cache`
148
282
  - [How it works](how-it-works.md): what a plan reads
149
283
  - [Not supported](how-it-works.md#not-supported): what bivium leaves to
150
284
  other tools
package/docs/cli.md CHANGED
@@ -75,6 +75,11 @@ Options:
75
75
  - `--github` also writes each suite's selection to `$GITHUB_OUTPUT` as
76
76
  `<output>=all`, `none`, or the files separated by spaces.
77
77
  `<output>` is the suite's `output`, `<name>-tests` by default.
78
+ When a selected test needs only some of its [cases](config.md#cases),
79
+ it writes `<name>-cases` too: the case list `run` would pass,
80
+ separated by spaces.
81
+ A suite with [`shards`](config.md#shards-and-timings) also gets
82
+ `<name>-matrix` and `<name>-shards`, below.
78
83
 
79
84
  | Field | Holds |
80
85
  | --- | --- |
@@ -82,16 +87,82 @@ Options:
82
87
  | `config` | the config file |
83
88
  | `changed` | the files changed since the merge base |
84
89
  | `suites` | each suite's selection: `{ mode: "all" }`, `{ mode: "none" }`, or `{ mode: "some", files }` |
90
+ | `cases` | per suite, each selected test that needs only some of its [cases](config.md#cases) → those cases; a test not listed runs every case |
85
91
  | `totals` | how many test files each suite has |
86
92
  | `reasons` | why a suite runs in full, as sentences |
87
93
  | `causes` | the same reasons as data, each a `FullRunCause`: `{ kind, suites, file?, package?, narrower?, message }` |
88
94
  | `packages` | a line per package a lockfile or `package.json` change changed: `bun.lock: svelte 5.1.0 → 5.2.0` |
89
95
  | `narrowed` | what each [narrower](api.md#narrowers) returned |
96
+ | `shards` | per suite with `shards`, its shards: `[{ shard, files, estimatedMs }]`, the files longest first |
97
+ | `timings` | per suite with `shards`, what balanced them: `{ file, timed, medianMs, problem? }`, the timings file, how many of the split files it has, what a file without an entry counts as, and what's wrong with a file that doesn't parse |
90
98
 
91
99
  ```sh
92
100
  bivium plan origin/main --json
93
101
  ```
94
102
 
103
+ ### Shards
104
+
105
+ For a suite with `shards`, `--github` writes the selection split for a
106
+ CI matrix, beside `<name>-tests`:
107
+
108
+ | Output | Holds |
109
+ | --- | --- |
110
+ | `<name>-matrix` | a JSON array, one entry per shard: `{"shard":1,"files":"a b"}`, the files separated by spaces, longest first |
111
+ | `<name>-shards` | how many shards: `0` when no test is selected |
112
+
113
+ ```text
114
+ unit-tests=all
115
+ unit-matrix=[{"shard":1,"files":"tests/t1.test.js tests/t5.test.js"},{"shard":2,"files":"tests/t2.test.js tests/t7.test.js"},{"shard":3,"files":"tests/t3.test.js tests/t6.test.js tests/t4.test.js"}]
116
+ unit-shards=3
117
+ ```
118
+
119
+ A selection of `all` lists every test of the suite in the matrix,
120
+ so each shard runs files it names.
121
+ `none` gives `[]` and `0`; a matrix with no entries is an error in
122
+ GitHub Actions, so the job skips on `0` ([CI](ci.md#shards)).
123
+ A value with a line break is written between delimiters,
124
+ as GitHub reads one.
125
+
126
+ On a terminal, `plan` shows each shard's file count and estimated time,
127
+ under a line that says what balanced them:
128
+
129
+ ```console
130
+ $ bunx bivium plan origin/main
131
+ 300 of 1200 tests run for 3 changed files
132
+ since origin/main (merge base 26a0b6c) · config bivium.config.json
133
+
134
+ directory tests
135
+ tests/area2/ 100
136
+ tests/area5/ 100
137
+ tests/area8/ 100
138
+ ─────
139
+ 3 directories 300
140
+
141
+ 4 shards · target 40.0 s, max 4 · 297 of 300 files timed
142
+ shard files estimate
143
+ 1 75 30.8 s
144
+ 2 74 30.8 s
145
+ 3 75 30.8 s
146
+ 4 76 30.8 s
147
+
148
+ ✓ Planned 300 tests · 113 ms · --list for the files
149
+ ```
150
+
151
+ The estimate is the sum of each file's recorded duration,
152
+ with the median for a file that has none.
153
+ With no durations recorded, the line says the split is by file count,
154
+ and the estimate reads `n/a`.
155
+ A timings file that doesn't parse counts as missing,
156
+ after a warning on stderr that names it and what's wrong:
157
+
158
+ ```text
159
+ bivium plan: .bivium/timings/unit.json: not a version 1 timings file (expected { "version": 1, "files": { "<path>": <ms> } }); splitting by file count. Delete it, or rewrite it with bun test --timings=.bivium/timings/unit.json --update-timings
160
+ ```
161
+
162
+ Past 8 shards, the rest are counted; `--json` has each.
163
+ Piped, or for an agent, each shard is a
164
+ line: ` shard 1: 75 files, 30.8 s`.
165
+
95
166
  ## run
96
167
 
97
168
  `run` runs a suite's `run` command on the tests `plan` selects for it.
@@ -103,13 +174,25 @@ bivium run [base] [--suite <name>]
103
174
  - `--suite <name>` picks the suite.
104
175
  Default: the first one in the config.
105
176
 
106
- The selected files go where the command says `{files}`, or at its end.
177
+ The selected files go where the command says `{files}`, or at its end,
178
+ longest first by the suite's [`timings`](config.md#shards-and-timings),
179
+ so a runner that starts files in the order it's given starts the
180
+ slowest first.
181
+ Without a timings file, they go in path order;
182
+ with one that doesn't parse, too, after a warning on stderr.
107
183
  When every test is selected, the suite's `root` goes there instead,
108
184
  so a runner that would run every suite's tests runs only this one's;
109
185
  `runAll` in the config replaces the command for that case.
110
186
  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.
187
+ Otherwise it exits with the command's status.
188
+
189
+ When a selected test needs only some of its [cases](config.md#cases),
190
+ `run` writes the case list to a temporary file,
191
+ one repository path per line, and names it in the command's
192
+ `BIVIUM_CASES` variable.
193
+ The list holds every case each selected test needs,
194
+ so a test runs the cases it finds there.
195
+ Without `BIVIUM_CASES`, every case runs, as in a full run.
113
196
 
114
197
  On a terminal, it opens as `plan` does, names the suites it didn't run,
115
198
  echoes the command, then closes with the result:
@@ -133,6 +216,19 @@ then the runner's output.
133
216
  bivium run --suite e2e
134
217
  ```
135
218
 
219
+ Ctrl-C reaches the runner too, as one job;
220
+ `run` waits for the runner to stop, says what stopped it, and exits 130:
221
+
222
+ ```console
223
+ ✗ unit stopped by Ctrl-C · 1.04 s
224
+ ```
225
+
226
+ A second Ctrl-C, while the runner cleans up, kills it and exits at once.
227
+ `SIGTERM` reaches only `run`, which passes it to the runner,
228
+ and exits 143.
229
+ Piped, or for a coding agent, the line is on
230
+ stderr: `bivium run: unit stopped by Ctrl-C after 1.04 s`.
231
+
136
232
  ## why
137
233
 
138
234
  `why` shows the shortest chain of edges from a changed file to a test.
@@ -221,6 +317,7 @@ The sections cover:
221
317
  (see [A change no test reaches](tuning.md#a-change-no-test-reaches));
222
318
  - `tsconfig.json` files that don't parse;
223
319
  - [dead globs](tuning.md#dead-globs);
320
+ - [globs that match files outside `roots`](tuning.md#globs-outside-the-roots);
224
321
  - repository paths a test spells that nothing declares.
225
322
 
226
323
  `check` exits 1 on any of these:
@@ -230,6 +327,7 @@ The sections cover:
230
327
  list, or an entry whose dependencies are all known;
231
328
  - a dead glob `deadGlobs` doesn't allow,
232
329
  or a `deadGlobs` entry that matches none;
330
+ - a glob that matches files outside `roots`;
233
331
  - a repository path a test spells that nothing declares.
234
332
 
235
333
  Options:
package/docs/config.md CHANGED
@@ -53,6 +53,8 @@ a set of test files and the command that runs them.
53
53
  | `nonInputs` | Files under `root` the runner never reads, such as type-check inputs | none |
54
54
  | `types` | Whether the suite's tests can observe types | `true` |
55
55
  | `output` | The step output `plan --github` writes | `<name>-tests` |
56
+ | `timings` | The file of each test's recorded duration | `.bivium/timings/<name>.json` |
57
+ | `shards` | How many CI jobs to split the selection into | none |
56
58
 
57
59
  ### `run`
58
60
 
@@ -130,6 +132,76 @@ With `types: false`, the orphan rule counts a type-only reach only for a
130
132
  declaration file, since the runner may load any other file by name.
131
133
  List a types-only module under `root` in `nonInputs`.
132
134
 
135
+ With `types: false`, an edit to a script's comments alone selects only
136
+ what reads it as text.
137
+ With `types: true`, JSDoc is a type,
138
+ so it selects the file's
139
+ importers
140
+ ([Edits only some files can see](how-it-works.md#edits-only-some-files-can-see)).
141
+
142
+ ### `shards` and `timings`
143
+
144
+ `shards` splits a suite's selection into shards, one per CI job,
145
+ balanced by how long each test took:
146
+
147
+ ```ts
148
+ unit: {
149
+ tests: "tests/**/*.test.ts",
150
+ run: "bun test {files}",
151
+ shards: { targetMs: 60_000, max: 3 },
152
+ },
153
+ ```
154
+
155
+ | `shards` | Splits into |
156
+ |:---|:---|
157
+ | `3` | 3 shards |
158
+ | `{ targetMs: 60_000, max: 3 }` | the fewest shards whose slowest takes at most `targetMs`, up to `max` |
159
+
160
+ A count is a whole number from 1 to 256,
161
+ the most jobs GitHub Actions runs from one matrix, and so is `max`;
162
+ `targetMs` is a duration in milliseconds, above 0.
163
+ A split never has more shards than selected files,
164
+ since a shard with none would hand its runner nothing to name,
165
+ and most runners then run every test.
166
+ When `max` shards can't keep each within `targetMs`,
167
+ the plan takes the fewest that finish as soon as `max` would:
168
+ a file longer than the target alone sets the time,
169
+ and more shards past that sit idle.
170
+
171
+ `timings` is the file of each test's recorded duration,
172
+ in the format `bun test --timings` reads
173
+ and `bun test --update-timings` writes:
174
+
175
+ ```json
176
+ { "version": 1, "files": { "tests/a.test.ts": 1234, "tests/b.test.ts": 87 } }
177
+ ```
178
+
179
+ Each key is a test's repository path; each value is milliseconds.
180
+ A Bun suite run from the repository root can pass the same file to
181
+ `--timings` and refresh it with `--update-timings`.
182
+ A test with no entry counts as the median of the suite's recorded ones.
183
+ A missing file is a cold start: every test counts the same,
184
+ so a count splits by file count, and a target takes `max` shards
185
+ until a run records durations.
186
+ A file in any other shape counts as missing:
187
+ `plan` and `run` print a warning on stderr that names the file
188
+ and what's wrong, and go on, splitting by file count.
189
+
190
+ The default path is `.bivium/timings/<name>.json`:
191
+ `.bivium/` holds the cache too when there's no `node_modules`,
192
+ and the plan job reads it before any install.
193
+ A change to a suite's timings file selects nothing,
194
+ so a CI step can restore it before planning.
195
+ `bivium run` reads it whether or not the suite has `shards`,
196
+ to pass the files longest first.
197
+ [CI](ci.md#shards) has the workflow.
198
+
199
+ bivium doesn't write the file.
200
+ `bun test --update-timings` does; for Vitest, Jest or Playwright,
201
+ a step that turns the runner's report into this shape does.
202
+ A test file is split whole: its [cases](#cases) all run in the shard
203
+ that has it.
204
+
133
205
  ## What the graph reads
134
206
 
135
207
  The graph is bivium's map of which file depends on which.
@@ -147,6 +219,8 @@ These keys set which files it reads and how it resolves imports.
147
219
  A changed file outside the roots that isn't ignored runs everything.
148
220
  That is the backstop for wiring the graph can't see,
149
221
  such as a CI workflow.
222
+ `check` fails on an annotation or config glob that matches files outside
223
+ the roots, and names what to add.
150
224
 
151
225
  `alias` is tried before tsconfig `paths` and `package.json` `exports`.
152
226
  A key ending in `/` is a prefix, as Vite reads it:
@@ -321,6 +395,7 @@ const css = readFileSync("src/tokens.css", "utf-8");
321
395
  | Comment | Declares | A change that counts |
322
396
  |:---|:---|:---|
323
397
  | `// @depends-on <glob> [glob…]` | Inputs that aren't imports: files a script reads, a tool it spawns, pages a `goto()` opens | One to an input, or to what it depends on |
398
+ | `// @depends-on-each <glob> [glob…]` | The same, where each input is a [case](#cases) of its own, such as a page a sweep test opens | The same; it runs only the cases it reaches |
324
399
  | `// @reads <glob> [glob…]` | Files read as text | A direct change to one, not to what it imports |
325
400
  | `// @lists <glob> [glob…]` | Files whose names it lists, not their contents | Adding, deleting or renaming one |
326
401
  | `// @glob-registry` | This file's `import.meta.glob` is a lookup table | None: it adds no edges |
@@ -340,6 +415,46 @@ and doesn't run its suite by the orphan rule either.
340
415
  `@glob-registry` is for an `import.meta.glob` used as a lookup table:
341
416
  whatever loads an entry names it itself.
342
417
 
418
+ ### Cases
419
+
420
+ A sweep test makes one test case per input,
421
+ such as a test that opens every fixture page.
422
+ With `@depends-on`, a change that reaches one page runs every
423
+ page's case.
424
+ `@depends-on-each` declares the same inputs and says each is a case of
425
+ its own, so a plan can pass the test the cases a change reaches:
426
+
427
+ ```ts
428
+ // e2e/layout-sweep.test.ts
429
+ // @depends-on-each e2e/fixtures/*.html
430
+ import { readdirSync, readFileSync } from "node:fs";
431
+
432
+ // The pages to run: the ones bivium lists, or every page without a list.
433
+ const list = process.env.BIVIUM_CASES;
434
+ const cases = list && new Set(readFileSync(list, "utf-8").split("\n"));
435
+ const pages = readdirSync("e2e/fixtures")
436
+ .filter((file) => file.endsWith(".html"))
437
+ .filter((file) => !cases || cases.has(`e2e/fixtures/${file}`));
438
+
439
+ for (const page of pages) {
440
+ test(page, async ({ page: tab }) => {
441
+ await tab.goto(`/${page}`);
442
+ });
443
+ }
444
+ ```
445
+
446
+ A test runs only some of its cases when a change reaches it through
447
+ them alone.
448
+ A change to the test itself, to another of its dependencies,
449
+ or to a file it depends on through an unknown runs every case,
450
+ and so does a full run.
451
+ `plan --json` lists the cases each test needs under `cases`,
452
+ `plan --github` writes them as `<suite>-cases`,
453
+ and `bivium run` names a file of them in `BIVIUM_CASES`:
454
+ one repository path per line.
455
+ Two tests can share cases, so the list holds every case of a test that
456
+ needs them all.
457
+
343
458
  ## Related
344
459
 
345
460
  - [Tuning a plan](tuning.md): which key to reach for
@@ -30,6 +30,10 @@ A one-pass lexer reads the code in these files:
30
30
  - `.vue` and `.astro`: the scripts;
31
31
  - `.html`: the scripts, and the `script[src]`,
32
32
  `link[href]` and `iframe[src]`.
33
+ A root-absolute one, as Vite's `/src/main.ts`,
34
+ resolves from the page's folder, or the nearest folder above it that
35
+ has the file, since the folder a site is served from isn't in
36
+ the page.
33
37
 
34
38
  Only code counts: an import spelled in a string
35
39
  or a comment adds no edge.
@@ -86,6 +90,100 @@ CSS isn't scanned.
86
90
  A generated stylesheet reaches its inputs through `edges`,
87
91
  and a [narrower](api.md#narrowers) can do better.
88
92
 
93
+ ## Edits only some files can see
94
+
95
+ A changed file seeds the walk whole: everything that imports it,
96
+ directly or not, can observe the change.
97
+ Two kinds of edit to a script are narrower,
98
+ and bivium reads the file's version at the merge base to tell
99
+ them apart.
100
+ Anything else it can't prove harmless is a change to the whole file.
101
+
102
+ ```console
103
+ $ bunx bivium plan
104
+ 2 of 40 tests run for 1 changed file
105
+ since origin/main (merge base 1c0ffee) · config bivium.config.ts
106
+ src/utils/keyboard-shortcut.js: only comments or line breaks changed
107
+ …
108
+ ```
109
+
110
+ ### Comments only
111
+
112
+ When a JavaScript or TypeScript file, or a `.svelte` file's `<script>`,
113
+ is the same code as at the merge base, token for token,
114
+ only a file that reads it as text can observe the edit:
115
+ an `@reads` or `reads` entry, an import with a query (`?raw`),
116
+ an `@depends-on` or `edges` glob, or an `import.meta.glob`.
117
+ Its importers aren't selected.
118
+ The same code means the comments, and the spaces and line breaks between
119
+ tokens, are all that changed; a line break still counts
120
+ where there was none, and a component's markup counts as it's written.
121
+
122
+ A barrel, a module made only of re-exports, isn't read this way:
123
+ its change already selects by the names that moved.
124
+
125
+ This applies to a suite with `types: false`.
126
+ For a suite that checks types, JSDoc is a type in JavaScript,
127
+ so a comment is code.
128
+
129
+ A comment a tool reads is code too.
130
+ An edit to one, or a move, changes the whole file:
131
+
132
+ - bivium's annotations: `@depends-on`, `@reads`,
133
+ `@lists`, `@glob-registry`;
134
+ - bundler and minifier hints: `@vite-ignore`,
135
+ `webpack…` and `turbopack…` magic comments, `#__PURE__`,
136
+ `@__NO_SIDE_EFFECTS__` and any other `#__…__` or `@__…__`;
137
+ - compiler pragmas: `@jsx`, `@jsxImportSource` and the rest of `@jsx…`,
138
+ `@ts-…` (`@ts-check`, `@ts-expect-error`), a `/// <reference …>` line,
139
+ `@flow`, `@noflow`, `@bun`, `@ngInject`;
140
+ - test environments: `@vitest-environment`, `@jest-environment`;
141
+ - coverage hints: `istanbul ignore`, `c8 ignore`, `v8 ignore`;
142
+ - `svelte-ignore`;
143
+ - comments a build keeps or reads: `@license`, `@preserve`, `/*!`,
144
+ `sourceMappingURL=`, `sourceURL=`.
145
+
146
+ ### Added exports only
147
+
148
+ When a module's only change is new `export const`,
149
+ `let` or `var` declarations whose values are literals,
150
+ loading it runs nothing new, so only a file that imports one of the new
151
+ names, or the module whole, can observe it.
152
+ That's a named import or re-export of a new name,
153
+ and any import that takes the whole module: `import * as`,
154
+ a default import, a side-effect import, `export *`, `require()`,
155
+ a dynamic `import()`, `vi.mock()`.
156
+ Text readers and globs see it, as for any change.
157
+ A barrel that re-exports a new name is a change of its own,
158
+ and selects the importers of that name.
159
+
160
+ A literal is a number, a string, a template without `${`, `true`,
161
+ `false`, `null`, `undefined`, `NaN` or `Infinity`,
162
+ or an array or object of them, joined by arithmetic and unary operators.
163
+ TypeScript adds simple annotations, as `: Array<string>`,
164
+ and `as const`.
165
+ The declarations are whole lines, between two top-level statements,
166
+ each ending with `;`, and no name they declare appears in the base
167
+ version of the file, comments included.
168
+
169
+ Everything else is a change to the whole module:
170
+
171
+ - a changed or removed export, or any other edit in the same file;
172
+ - a value that names a binding, calls, interpolates,
173
+ or is a BigInt (mixing one with a number throws);
174
+ - `export function`: bivium doesn't parse a function's body,
175
+ and one that doesn't parse would break every importer;
176
+ - `export class`, whose static fields run, `export default`,
177
+ `export { … }` and any re-export;
178
+ - a declaration without `;`, or one that would continue the statement
179
+ around it;
180
+ - a comment a tool reads, in the new lines.
181
+
182
+ For a suite that checks types, a comment edit elsewhere in the file
183
+ makes the change whole, as above.
184
+ A component's `<script>` declares no exports this way,
185
+ so a `.svelte` edit is only ever comments or the whole file.
186
+
89
187
  ## Lockfiles
90
188
 
91
189
  A dependency bump changes a lockfile, and no file imports a lockfile,
@@ -146,6 +244,34 @@ Other lockfiles (`yarn.lock`, `bun.lockb`, `npm-shrinkwrap.json`) are
146
244
  files like any other.
147
245
  Outside the roots, a change to one runs everything.
148
246
 
247
+ ## Shards
248
+
249
+ A suite with [`shards`](config.md#shards-and-timings) has its selection
250
+ split by the durations in its timings file.
251
+ Splitting files across shards so the slowest finishes first is makespan
252
+ scheduling on identical machines, and finding the best split is NP-hard.
253
+ bivium uses LPT, longest processing time first:
254
+ it sorts the files longest first, with ties by path,
255
+ and puts each on the shard with the least time so far,
256
+ the lowest-numbered of equals.
257
+ Graham proved in 1969 that the slowest shard then takes at most 4/3 −
258
+ 1/(3m) of the best possible time on m shards: 1.17 times at 2 shards,
259
+ 1.22 at 3, and closer to even when no one file is long next to
260
+ the total.
261
+ MULTIFIT and approximation schemes beat that bound by a few percent,
262
+ less than recorded durations vary between runs, so LPT's simple,
263
+ stable split wins.
264
+ A shared queue that every shard pulls from (work stealing) adapts to
265
+ that variance, but needs a service to coordinate it,
266
+ while a CI matrix fixes each job's input when the workflow starts.
267
+
268
+ A file with no recorded duration counts as the median of the suite's
269
+ recorded ones, and as 1 ms when there are none,
270
+ so the same input always gives the same shards.
271
+ With a target, the count is the fewest shards whose LPT split keeps the
272
+ slowest within it; no fewer than the total over the target can,
273
+ so the search starts there.
274
+
149
275
  ## Not supported
150
276
 
151
277
  What bivium leaves to other tools, and what to use instead:
@@ -157,7 +283,10 @@ What bivium leaves to other tools, and what to use instead:
157
283
  | scan CSS | `edges` from a stylesheet to its sources, or a [narrower](api.md#narrowers) |
158
284
  | parse `yarn.lock` or `bun.lockb` | they're files like any other, so a change to one doesn't seed packages |
159
285
  | select below the file | a test file is selected whole, every case in it |
286
+ | record durations | `bun test --update-timings` writes the [timings file](config.md#shards-and-timings); for another runner, a step that turns its report (junit, Playwright's JSON) into that shape |
287
+ | split one test's cases across shards | a test file runs whole in one shard, every case it selects with it |
160
288
  | follow an import it can't read | the file counts as depending on every change, so its tests always run |
289
+ | see code read its own source at run time (`fn.toString()`, a stack trace's line numbers) | name the file in the test's `@reads`, so an edit to its comments selects the test |
161
290
  | build or cache outputs | Nx, Turborepo, or Bazel, which skip whole projects |
162
291
 
163
292
  ## Compared with