bivium 0.10.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/README.md CHANGED
@@ -21,7 +21,7 @@ Piped, or with `--list`, it prints the files, one per line.
21
21
 
22
22
  <picture>
23
23
  <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/metonym/bivium/master/.github/assets/run-dark.svg">
24
- <img alt="bivium run main on Hono, a branch that documents its CORS middleware: 7 of 103 tests run for 1 changed file; Vitest queues the 7 files, passes them one by one, 280 tests in all, and bivium closes with unit passed in 3.06 s" src="https://raw.githubusercontent.com/metonym/bivium/master/.github/assets/run-light.svg">
24
+ <img alt="bivium run main on Hono, a branch that documents its CORS middleware: 7 of 103 tests run for 1 changed file; Vitest queues the 7 files, passes them one by one, 280 tests in all, and bivium closes with unit passed in 9.64 s" src="https://raw.githubusercontent.com/metonym/bivium/master/.github/assets/run-light.svg">
25
25
  </picture>
26
26
 
27
27
  **Every selection has a reason.**
package/cli.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  } from "./shared-graedbt1.js";
6
6
  import {
7
7
  version
8
- } from "./shared-x17wzptz.js";
8
+ } from "./shared-jp8yw63q.js";
9
9
 
10
10
  // src/main.ts
11
11
  var PIPED = {
@@ -36,13 +36,13 @@ async function main(argv, io = PIPED) {
36
36
  { BiviumError, didYouMean },
37
37
  { fitTerminal }
38
38
  ] = await Promise.all([
39
- import("./shared-m8z858pr.js"),
39
+ import("./shared-1erx1bv8.js"),
40
40
  import("./errors.js"),
41
- import("./shared-wahjx628.js")
41
+ import("./shared-dyz928f5.js")
42
42
  ]);
43
43
  const out = outFor(io, argv, startMs);
44
44
  const showHelp = async () => {
45
- const { usage } = await import("./shared-a5kfg3qy.js");
45
+ const { usage } = await import("./shared-k2ahcc61.js");
46
46
  console.log(fitTerminal(usage(out.paint), out.io.stdout, process.stdout.columns));
47
47
  return 0;
48
48
  };
@@ -65,7 +65,7 @@ async function main(argv, io = PIPED) {
65
65
  const rest = [...argv.slice(0, at), ...argv.slice(at + 1)];
66
66
  try {
67
67
  const args = parseArgs(command, rest);
68
- const { graphCommand, inspect, runCommand } = await import("./shared-rzbfbyqq.js");
68
+ const { graphCommand, inspect, runCommand } = await import("./shared-nyb7n090.js");
69
69
  if (command === "why" || command === "check")
70
70
  return await inspect(command, args, out);
71
71
  if (command === "graph")
package/compute.js CHANGED
@@ -6,10 +6,10 @@ import {
6
6
  computePlan2,
7
7
  prepare2,
8
8
  plan2
9
- } from "./shared-70w84x4c.js";
10
- import"./shared-px5a17nj.js";
11
- import"./shared-118ck8qt.js";
12
- import"./shared-a8ebfhzf.js";
9
+ } from "./shared-wxem8d5w.js";
10
+ import"./shared-qaqjsxsk.js";
11
+ import"./shared-p3qfqmwd.js";
12
+ import"./shared-mpjk8met.js";
13
13
  export {
14
14
  collectPackages2 as collectPackages,
15
15
  computePlan2 as computePlan,
package/config.js CHANGED
@@ -4,9 +4,9 @@ import {
4
4
  inRoot2,
5
5
  checkConfig2,
6
6
  loadConfig2
7
- } from "./shared-px5a17nj.js";
8
- import"./shared-118ck8qt.js";
9
- import"./shared-a8ebfhzf.js";
7
+ } from "./shared-qaqjsxsk.js";
8
+ import"./shared-p3qfqmwd.js";
9
+ import"./shared-mpjk8met.js";
10
10
  export {
11
11
  checkConfig2 as checkConfig,
12
12
  defineConfig2 as defineConfig,
package/docs/api.md CHANGED
@@ -42,6 +42,8 @@ except `schemaVersion` and `config`:
42
42
  | `base`, `mergeBase` | the base ref, and the merge base the working tree is compared with |
43
43
  | `changed` | the files changed since the merge base, untracked ones included |
44
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? }` |
45
47
 
46
48
  On failure, `plan()` throws a `BiviumError`,
47
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 }}
@@ -68,6 +68,7 @@ under `outputs`: `e2e-cases: ${{ steps.plan.outputs.e2e-cases }}`.
68
68
 
69
69
  Three decisions shape the workflow: the checkout, the cache,
70
70
  and the cost of a plan.
71
+ A suite too slow for one job can also run in [shards](#shards).
71
72
 
72
73
  ## The checkout
73
74
 
@@ -144,6 +145,117 @@ The plan job runs before any install, so its cache is `.bivium/cache`.
144
145
  bivium writes a `.gitignore` there, so the cache never shows up as
145
146
  a change.
146
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
+
147
259
  ## What a plan costs
148
260
 
149
261
  Measured on an Apple M-series laptop under load
@@ -165,7 +277,8 @@ and 124 MB on Node.
165
277
  ## Related
166
278
 
167
279
  - [CLI](cli.md): `plan --github` and the other commands
168
- - [Config](config.md): a suite's `output`, and `cache`
280
+ - [Config](config.md): a suite's `output`, `shards` and `timings`,
281
+ and `cache`
169
282
  - [How it works](how-it-works.md): what a plan reads
170
283
  - [Not supported](how-it-works.md#not-supported): what bivium leaves to
171
284
  other tools
package/docs/cli.md CHANGED
@@ -78,6 +78,8 @@ Options:
78
78
  When a selected test needs only some of its [cases](config.md#cases),
79
79
  it writes `<name>-cases` too: the case list `run` would pass,
80
80
  separated by spaces.
81
+ A suite with [`shards`](config.md#shards-and-timings) also gets
82
+ `<name>-matrix` and `<name>-shards`, below.
81
83
 
82
84
  | Field | Holds |
83
85
  | --- | --- |
@@ -91,11 +93,76 @@ Options:
91
93
  | `causes` | the same reasons as data, each a `FullRunCause`: `{ kind, suites, file?, package?, narrower?, message }` |
92
94
  | `packages` | a line per package a lockfile or `package.json` change changed: `bun.lock: svelte 5.1.0 → 5.2.0` |
93
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 |
94
98
 
95
99
  ```sh
96
100
  bivium plan origin/main --json
97
101
  ```
98
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
+
99
166
  ## run
100
167
 
101
168
  `run` runs a suite's `run` command on the tests `plan` selects for it.
@@ -107,7 +174,12 @@ bivium run [base] [--suite <name>]
107
174
  - `--suite <name>` picks the suite.
108
175
  Default: the first one in the config.
109
176
 
110
- 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.
111
183
  When every test is selected, the suite's `root` goes there instead,
112
184
  so a runner that would run every suite's tests runs only this one's;
113
185
  `runAll` in the config replaces the command for that case.
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
 
@@ -137,6 +139,69 @@ so it selects the file's
137
139
  importers
138
140
  ([Edits only some files can see](how-it-works.md#edits-only-some-files-can-see)).
139
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
+
140
205
  ## What the graph reads
141
206
 
142
207
  The graph is bivium's map of which file depends on which.
@@ -244,6 +244,34 @@ Other lockfiles (`yarn.lock`, `bun.lockb`, `npm-shrinkwrap.json`) are
244
244
  files like any other.
245
245
  Outside the roots, a change to one runs everything.
246
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
+
247
275
  ## Not supported
248
276
 
249
277
  What bivium leaves to other tools, and what to use instead:
@@ -255,6 +283,8 @@ What bivium leaves to other tools, and what to use instead:
255
283
  | scan CSS | `edges` from a stylesheet to its sources, or a [narrower](api.md#narrowers) |
256
284
  | parse `yarn.lock` or `bun.lockb` | they're files like any other, so a change to one doesn't seed packages |
257
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 |
258
288
  | follow an import it can't read | the file counts as depending on every change, so its tests always run |
259
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 |
260
290
  | build or cache outputs | Nx, Turborepo, or Bazel, which skip whole projects |
package/errors.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  BiviumError2,
3
3
  didYouMean2
4
- } from "./shared-118ck8qt.js";
5
- import"./shared-a8ebfhzf.js";
4
+ } from "./shared-p3qfqmwd.js";
5
+ import"./shared-mpjk8met.js";
6
6
  export {
7
7
  BiviumError2 as BiviumError,
8
8
  didYouMean2 as didYouMean
package/index.d.ts CHANGED
@@ -204,8 +204,31 @@ export interface SuiteConfig {
204
204
  * to. Default: `<name>-tests`.
205
205
  */
206
206
  output?: string;
207
+ /**
208
+ * The suite's recorded test durations, in the format of `bun test
209
+ * --timings`: `{ "version": 1, "files": { "<path>": <ms> } }`, keyed by
210
+ * repository path. Shards balance by them, and `bivium run` passes the
211
+ * files longest first. A missing file, or one that doesn't parse (with a
212
+ * warning), counts every test the same. A change to it selects nothing.
213
+ * Default: `.bivium/timings/<name>.json`.
214
+ */
215
+ timings?: string;
216
+ /**
217
+ * Splits the selection into shards for a CI matrix, balanced by
218
+ * `timings`: a count, or the fewest shards whose slowest one is
219
+ * estimated at most `targetMs`, up to `max`. Never more shards than
220
+ * selected files. Default: no shards.
221
+ */
222
+ shards?: number | ShardTarget;
207
223
  }
208
224
  export type Globs = string | readonly string[];
225
+ /** How many shards: the fewest that keep each within `targetMs`. */
226
+ export interface ShardTarget {
227
+ /** The longest a shard may take, by `timings`. */
228
+ targetMs: number;
229
+ /** The most shards to split into, up to 256. */
230
+ max: number;
231
+ }
209
232
  /**
210
233
  * Replaces the coarse seeds of some changed files with finer ones from a
211
234
  * semantic diff: a stylesheet change seeded with the sources that render a
@@ -308,6 +331,14 @@ export interface PlanResult<Suite extends string = string> {
308
331
  name: string;
309
332
  result: NarrowResult;
310
333
  }[];
334
+ /**
335
+ * Each suite with `shards` → its selection split into shards, balanced
336
+ * by its `timings`; a selection of all lists every test, and none
337
+ * gives no shards.
338
+ */
339
+ shards: Partial<Record<Suite, Shard[]>>;
340
+ /** Each suite with `shards` → what its shards were balanced by. */
341
+ timings: Partial<Record<Suite, ShardTimings>>;
311
342
  }
312
343
  /** A suite's selected tests. */
313
344
  export type Selection = {
@@ -340,6 +371,31 @@ export interface FullRunCause<Suite extends string = string> {
340
371
  /** The sentence `reasons` has for it. */
341
372
  message: string;
342
373
  }
374
+ /** One shard of a suite's selection, its files longest first. */
375
+ export interface Shard {
376
+ /** Its number, from 1. */
377
+ shard: number;
378
+ files: string[];
379
+ /** The sum of its files' recorded durations, the median for the rest. */
380
+ estimatedMs: number;
381
+ }
382
+ /** What a suite's shards were balanced by. */
383
+ export interface ShardTimings {
384
+ /** The suite's `timings` file, repository-relative. */
385
+ file: string;
386
+ /** How many of the files split have a recorded duration. */
387
+ timed: number;
388
+ /**
389
+ * What a file with no recorded duration counts as: the median of the
390
+ * suite's recorded ones, or 1 when it has none.
391
+ */
392
+ medianMs: number;
393
+ /**
394
+ * What's wrong with a timings file that doesn't parse, which is then
395
+ * read as empty, so the split is by count.
396
+ */
397
+ problem?: string;
398
+ }
343
399
  /** Types a config. Returns it unchanged. */
344
400
  export declare function defineConfig<Suite extends string>(config: Config<Suite>): Config<Suite>;
345
401
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bivium",
3
- "version": "0.10.0",
3
+ "version": "0.11.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)",
@@ -9,9 +9,9 @@ import {
9
9
  EVERY_FLAG2,
10
10
  unknownFlag2,
11
11
  fail2
12
- } from "./shared-ke52sg37.js";
13
- import"./shared-118ck8qt.js";
14
- import"./shared-a8ebfhzf.js";
12
+ } from "./shared-jee85qxj.js";
13
+ import"./shared-p3qfqmwd.js";
14
+ import"./shared-mpjk8met.js";
15
15
  export {
16
16
  COMMANDS2 as COMMANDS,
17
17
  EVERY_FLAG2 as EVERY_FLAG,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  showCursor2,
3
3
  cursorHidden2
4
- } from "./shared-a8ebfhzf.js";
4
+ } from "./shared-mpjk8met.js";
5
5
 
6
6
  // src/live.ts
7
7
  var EXIT_INTERRUPTED = 130;
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  plural2
3
- } from "./shared-a8ebfhzf.js";
3
+ } from "./shared-mpjk8met.js";
4
4
  import {
5
5
  walksByTypes,
6
6
  importersOf,
7
7
  sorted
8
- } from "./shared-70w84x4c.js";
8
+ } from "./shared-wxem8d5w.js";
9
9
 
10
10
  // src/fanin.ts
11
11
  function fanIn2(graph, suite) {
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  PLAIN2,
3
3
  plural2
4
- } from "./shared-a8ebfhzf.js";
4
+ } from "./shared-mpjk8met.js";
5
5
  import {
6
6
  BiviumError2
7
- } from "./shared-118ck8qt.js";
7
+ } from "./shared-p3qfqmwd.js";
8
8
  import {
9
9
  globToRegExp
10
- } from "./shared-px5a17nj.js";
11
- import"./shared-my87dhfd.js";
10
+ } from "./shared-qaqjsxsk.js";
11
+ import"./shared-8kbmg99n.js";
12
12
  import {
13
13
  specifierLine,
14
14
  gotoLine,
@@ -20,8 +20,8 @@ import {
20
20
  fileOf,
21
21
  causesOf,
22
22
  fixFor2
23
- } from "./shared-byhfswm9.js";
24
- import"./shared-yfvpkeff.js";
23
+ } from "./shared-9xwazb0f.js";
24
+ import"./shared-b9dpffxv.js";
25
25
  import {
26
26
  createResolver,
27
27
  SCANNED,
@@ -32,7 +32,7 @@ import {
32
32
  walksByTypes,
33
33
  affectedBy,
34
34
  sorted
35
- } from "./shared-70w84x4c.js";
35
+ } from "./shared-wxem8d5w.js";
36
36
 
37
37
  // src/why.ts
38
38
  var CONFIG_EDGES = "edges in the config";
@@ -9,18 +9,18 @@ import {
9
9
  textWidth2,
10
10
  MEASURE2,
11
11
  plural2
12
- } from "./shared-a8ebfhzf.js";
12
+ } from "./shared-mpjk8met.js";
13
13
  import {
14
14
  globToRegExp,
15
15
  inRoot2
16
- } from "./shared-px5a17nj.js";
16
+ } from "./shared-qaqjsxsk.js";
17
17
  import {
18
18
  fanIn2
19
- } from "./shared-my87dhfd.js";
19
+ } from "./shared-8kbmg99n.js";
20
20
  import {
21
21
  duration,
22
22
  wrapped
23
- } from "./shared-yfvpkeff.js";
23
+ } from "./shared-b9dpffxv.js";
24
24
  import {
25
25
  QUERY,
26
26
  UNDECLARED_READS,
@@ -35,7 +35,7 @@ import {
35
35
  sorted,
36
36
  isPackageFile,
37
37
  orphanOf
38
- } from "./shared-70w84x4c.js";
38
+ } from "./shared-wxem8d5w.js";
39
39
 
40
40
  // src/check.ts
41
41
  import { statSync } from "node:fs";