bivium 0.6.1 → 0.7.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/docs/api.md CHANGED
@@ -1,9 +1,7 @@
1
1
  # API
2
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()
3
+ `plan()` picks each suite's tests from code,
4
+ and returns the plan `bivium plan --json` prints, typed by your config.
7
5
 
8
6
  ```ts
9
7
  import { defineConfig, plan } from "bivium";
@@ -13,24 +11,48 @@ const result = await plan({ config, base: "origin/main" });
13
11
  result.suites.unit; // { mode: "some", files: [...] }; result.suites.e2e is a type error
14
12
  ```
15
13
 
14
+ Given a config, the suite names carry through to the result's type,
15
+ so a suite the config doesn't have is a type error.
16
+ The package exports `plan`, `defineConfig`, `BiviumError`,
17
+ and their types.
18
+
19
+ ## plan()
20
+
16
21
  `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.
22
+ takes four options, all optional:
23
+
24
+ | Option | Is | Default |
25
+ | --- | --- | --- |
26
+ | `cwd` | the repository | the current directory |
27
+ | `base` | the ref to compare the working tree with | the config's `base`, else the upstream default branch |
28
+ | `config` | the config | the `bivium.config.*` file in `cwd` |
29
+ | `cache` | the extraction cache's directory, or `false` for none | the config's `cache` |
30
+
31
+ It returns the fields `bivium plan --json` prints,
32
+ except `schemaVersion` and `config`:
33
+
34
+ | Field | Holds |
35
+ | --- | --- |
36
+ | `suites` | each suite's selection: `{ mode: "all" }`, `{ mode: "none" }`, or `{ mode: "some", files }` |
37
+ | `totals` | how many test files each suite has |
38
+ | `reasons` | why a suite runs in full, as sentences |
39
+ | `causes` | the same reasons as data, one `FullRunCause` each, in order |
40
+ | `packages` | a line per package a lockfile or `package.json` change changed, and that selects through its importers or nothing |
41
+ | `base`, `mergeBase` | the base ref, and the merge base the working tree is compared with |
42
+ | `changed` | the files changed since the merge base, untracked ones included |
43
+ | `narrowed` | what each narrower that ran returned, as `{ name, result }` |
44
+
45
+ On failure, `plan()` throws a `BiviumError`,
46
+ whose `code` and `kind` are the CLI's
47
+ (see [JSON and errors](cli.md#json-and-errors)).
24
48
 
25
49
  ## Narrowers
26
50
 
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.
51
+ A narrower is a plugin in the config that makes a change to some files
52
+ select fewer tests, from a semantic diff.
32
53
 
33
54
  ```ts
55
+ // bivium.config.ts, inside defineConfig({ … })
34
56
  narrowers: [
35
57
  {
36
58
  name: "css",
@@ -46,24 +68,57 @@ narrowers: [
46
68
  ],
47
69
  ```
48
70
 
71
+ `compile`, `diffRules`, and `sourcesSpelling` stand for your own code.
72
+
73
+ Some changes reach every test through a generated file.
74
+ Every page loads the compiled stylesheet,
75
+ so any style edit selects every e2e test.
76
+ bivium plans by a walk: from the changed files (the seeds),
77
+ it follows edges back to the tests that reach them.
78
+ A narrower replaces a change's coarse seeds with finer ones,
79
+ such as the sources that render a changed CSS rule.
80
+
49
81
  The matched files still seed the walk,
50
- but it stops at the `opaque` nodes, and the seeds stand in for them.
82
+ but it stops at the `opaque` nodes, and the narrower's seeds stand in
83
+ for them.
51
84
  A narrower can only narrow: its suites' selection is cut to what the
52
85
  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:
86
+
87
+ | Key | Is |
88
+ | --- | --- |
89
+ | `name` | names it in reasons and notes: `css: …` |
90
+ | `match` | the changed files it narrows |
91
+ | `opaque` | the generated nodes its seeds stand in for, such as `dist/*.css` |
92
+ | `suites` | the suites it narrows; default: every suite |
93
+ | `narrow` | the function that returns the finer seeds |
94
+
95
+ `narrow()` gets one object:
56
96
 
57
97
  - `root`, the repository;
58
98
  - `base` and `head`, the merge base and the working tree,
59
99
  each with `commit` and `read(path)`;
60
100
  - `changed`, the matched files;
61
- - `graph`, read-only: `nodes()`, `importers(node)`,
62
- `dependents(nodes)` and `tests(suite)`.
101
+ - `graph`, read-only: `nodes()`, `importers(node)`, `dependents(nodes)`,
102
+ and `tests(suite)`.
103
+
104
+ It returns one of two shapes:
105
+
106
+ | Returns | Then |
107
+ | --- | --- |
108
+ | `{ seeds, note? }` | the walk uses `seeds`; `bivium plan` prints `note` after the narrower's name |
109
+ | `{ all: reason }` | its suites run in full, with `reason` |
110
+
111
+ A narrower that throws, or returns anything else,
112
+ runs its suites in full with the reason too.
63
113
 
64
- carbon-components-svelte runs one over crassus.
114
+ carbon-components-svelte runs one built on
115
+ [crassus](https://github.com/metonym/crassus), a CSS cascade
116
+ regression tool.
65
117
 
66
118
  ## Related
67
119
 
68
120
  - [Config](config.md): `defineConfig` and every key
69
121
  - [CLI](cli.md): the same plan from the command line
122
+ - [How it works](how-it-works.md): the graph a plan walks
123
+ - [Not supported](how-it-works.md#not-supported): what bivium leaves to
124
+ other tools
package/docs/ci.md CHANGED
@@ -1,10 +1,8 @@
1
1
  # CI
2
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:
3
+ In CI, bivium plans in a job of its own, before any install,
4
+ and hands each test job its suite's selection.
5
+ A job whose selection is `none` doesn't run.
8
6
 
9
7
  ```yaml
10
8
  jobs:
@@ -34,38 +32,63 @@ jobs:
34
32
  unit:
35
33
  needs: plan
36
34
  if: needs.plan.outputs.unit != 'none'
35
+ runs-on: ubuntu-latest
37
36
  steps:
38
37
  # …install, then run all tests or the selected files:
39
38
  - run: bunx vitest run ${{ needs.plan.outputs.unit != 'all' && needs.plan.outputs.unit || '' }}
40
39
  ```
41
40
 
41
+ `--github` writes each suite's selection to a step output named
42
+ `<suite>-tests`, such as `unit-tests`;
43
+ a suite's `output` key renames it.
44
+ The value is `all`, `none`, or the selected files, separated by spaces.
45
+ The `unit` job skips on `none`, runs every test on `all`,
46
+ and otherwise passes the files to Vitest.
47
+
48
+ Three decisions shape the workflow: the checkout, the cache,
49
+ and the cost of a plan.
50
+
42
51
  ## The checkout
43
52
 
44
53
  A plan compares the branch with its merge base:
45
- the commit where it forked from the base branch.
54
+ the commit where the branch forked from the base branch.
46
55
  So the job needs the history back to that commit,
47
56
  not only the commit under test.
57
+
48
58
  `actions/checkout` fetches one commit by default (`fetch-depth: 1`),
49
- with no base branch, and the plan stops with what's missing:
59
+ with no base branch.
60
+ The plan then stops and names what's missing.
61
+ Without the base, it prints the first line;
62
+ with the base but not the history back to the fork, the second:
50
63
 
51
64
  ```text
65
+ bivium: no commit origin/main here to diff against: fetch it. The clone is shallow: fetch the history (actions/checkout: `fetch-depth: 0`).
52
66
  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
67
  ```
54
68
 
55
69
  `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' }}`.
70
+ Only a job that plans needs it.
71
+ A job that runs every test anyway, such as a push to the default branch,
72
+ can keep one commit:
73
+
74
+ ```yaml
75
+ fetch-depth: ${{ github.event_name == 'pull_request' && '0' || '1' }}
76
+ ```
77
+
78
+ Git stores history as three kinds of object:
79
+
80
+ - **commits**;
81
+ - **trees**: each directory's file names,
82
+ with the ID of each file's content;
83
+ - **blobs**: the contents.
59
84
 
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
85
  A plan needs the commits, to find the merge base, and the trees,
64
86
  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.
87
+ It needs few blobs: the working tree's, which the checkout has,
88
+ and the merge base's version of a few changed files.
89
+ Those are a lockfile, a `package.json`, a `tsconfig.json`,
90
+ a barrel (a module made only of re-exports),
91
+ and what a [narrower](api.md#narrowers) reads.
69
92
  So pick the clone by how big the history is:
70
93
 
71
94
  | History | Checkout | What a plan pays |
@@ -77,18 +100,28 @@ So pick the clone by how big the history is:
77
100
  and only the blobs the checkout needs.
78
101
  Git fetches any other blob when something reads it,
79
102
  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.
103
+ On a large history, the old contents are most of the download,
104
+ and the filter skips them.
105
+ On a small one, the filter costs a round trip to the remote for contents
106
+ a full clone has for free.
83
107
 
84
108
  ## The cache
85
109
 
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.
110
+ The cache holds what bivium extracted from each file,
111
+ its imports and annotations, keyed by the file's git blob.
112
+ A warm plan reads only the files a branch changed.
113
+
114
+ Key the cache on the merge base.
115
+ A pull request can restore caches from the default branch,
116
+ and the default branch's run at the merge base is the one to hit.
117
+ `restore-keys: bivium-` falls back to the newest cache
118
+ when no key matches exactly.
119
+
120
+ The cache lives in `node_modules/.cache/bivium`
121
+ when `node_modules` exists, and in `.bivium/cache` otherwise.
122
+ The plan job runs before any install, so its cache is `.bivium/cache`.
123
+ bivium writes a `.gitignore` there, so the cache never shows up as
124
+ a change.
92
125
 
93
126
  ## What a plan costs
94
127
 
@@ -100,13 +133,18 @@ Measured on an Apple M-series laptop under load
100
133
  | carbon-components-svelte | 4,680 | 0.15 s | 0.09 s | 0.27 s | 0.13 s | 452 KB |
101
134
  | generated TypeScript, 23 MB | 7,000 | 0.14 s | 0.08 s | 0.30 s | 0.12 s | 896 KB |
102
135
 
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.
136
+ At this size the cache saves under 0.2 s, so it's optional.
137
+ Bun plans a cold repository in about half the time Node 24 takes,
138
+ so `bunx --bun` pays for itself.
139
+ Planning inside a test job, with no extra job and no install,
140
+ costs well under a second.
106
141
  A cold plan of the generated repository peaks at 88 MB of RSS on Bun
107
142
  and 124 MB on Node.
108
143
 
109
144
  ## Related
110
145
 
111
146
  - [CLI](cli.md): `plan --github` and the other commands
147
+ - [Config](config.md): a suite's `output`, and `cache`
112
148
  - [How it works](how-it-works.md): what a plan reads
149
+ - [Not supported](how-it-works.md#not-supported): what bivium leaves to
150
+ other tools