Skip to content

Commit 6377945

Browse files
committed
test(driver): select matrix cells with vitest filters
1 parent e146d85 commit 6377945

3 files changed

Lines changed: 30 additions & 122 deletions

File tree

.claude/skills/driver-test-runner/SKILL.md

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,12 @@ The skill accepts optional arguments:
2424

2525
The driver suite runs over a runtime × SQLite-backend × encoding matrix defined in `rivetkit-typescript/packages/rivetkit/tests/driver/shared-matrix.ts`. The runtime dimension has two values:
2626

27-
- **`native`** — NAPI bindings (`@rivetkit/rivetkit-napi`). Pairs with `sqlite=local` (the in-process SQLite VFS). This is the default when no env override is set.
28-
- **`wasm`** — WebAssembly bindings (`@rivetkit/rivetkit-wasm`). Wasm **cannot** use local SQLite; it must pair with `sqlite=remote` (executes SQL through the engine over the wire). Setting `RIVETKIT_DRIVER_TEST_RUNTIME=wasm` with `RIVETKIT_DRIVER_TEST_SQLITE=local` fails fast.
27+
- **`native`** — NAPI bindings (`@rivetkit/rivetkit-napi`). Pairs with `sqlite=local` for the primary native driver pass.
28+
- **`wasm`** — WebAssembly bindings (`@rivetkit/rivetkit-wasm`). Wasm **cannot** use local SQLite; it must pair with `sqlite=remote` (executes SQL through the engine over the wire).
2929

3030
The skill defaults to running each test file twice: once on `native/local` and once on `wasm/remote`, each at `encoding=bare`. A file is checked off only when both runtimes pass.
3131

32-
Env overrides recognized by the test harness:
33-
34-
- `RIVETKIT_DRIVER_TEST_RUNTIME` — comma-separated subset of `native,wasm`.
35-
- `RIVETKIT_DRIVER_TEST_SQLITE` — comma-separated subset of `local,remote`.
36-
- `RIVETKIT_DRIVER_TEST_ENCODING` — comma-separated subset of `bare,cbor,json`.
37-
38-
When **any** of these env vars is set, the inner describe block name changes from `encoding (<encoding>)` to `runtime (<runtime>) / sqlite (<backend>) / encoding (<encoding>)`. The skill always sets the env vars, so the longer form is always what `-t` must match.
32+
The test harness does not read environment variables for matrix selection. Always select matrix cells with Vitest `-t` using the full inner describe name: `runtime (<runtime>) / sqlite (<backend>) / encoding (<encoding>)`.
3933

4034
## How It Works
4135

@@ -175,21 +169,20 @@ For each unchecked row in order, run the runtimes selected by the `runtime` arg
175169

176170
**b) Build the filter command:**
177171

178-
Each suite lives in its own file under `rivetkit-typescript/packages/rivetkit/tests/driver/<file>.test.ts`. With env overrides set, the describe block nesting is:
172+
Each suite lives in its own file under `rivetkit-typescript/packages/rivetkit/tests/driver/<file>.test.ts`. The describe block nesting is:
179173

180174
```
181175
<Outer Suite> > static registry > runtime (<runtime>) / sqlite (<backend>) / encoding (<encoding>) > <Suite Description>
182176
```
183177

178+
Always use Vitest `-t` for driver matrix cells. Include runtime, SQLite backend, and encoding in the pattern so a partial match does not accidentally select another matrix cell.
179+
184180
Base command (native):
185181

186182
```bash
187183
cd rivetkit-typescript/packages/rivetkit && \
188-
RIVETKIT_DRIVER_TEST_RUNTIME=native \
189-
RIVETKIT_DRIVER_TEST_SQLITE=local \
190-
RIVETKIT_DRIVER_TEST_ENCODING=bare \
191184
pnpm test tests/driver/<FILE>.test.ts \
192-
-t "static registry.*runtime \\(native\\) / sqlite \\(local\\) / encoding \\(bare\\).*<SUITE_DESCRIPTION>" \
185+
-t "runtime \(native\) / sqlite \(local\) / encoding \(bare\)" \
193186
> /tmp/driver-test-current.log 2>&1
194187
echo "EXIT: $?"
195188
```
@@ -198,11 +191,8 @@ Base command (wasm):
198191

199192
```bash
200193
cd rivetkit-typescript/packages/rivetkit && \
201-
RIVETKIT_DRIVER_TEST_RUNTIME=wasm \
202-
RIVETKIT_DRIVER_TEST_SQLITE=remote \
203-
RIVETKIT_DRIVER_TEST_ENCODING=bare \
204194
pnpm test tests/driver/<FILE>.test.ts \
205-
-t "static registry.*runtime \\(wasm\\) / sqlite \\(remote\\) / encoding \\(bare\\).*<SUITE_DESCRIPTION>" \
195+
-t "runtime \(wasm\) / sqlite \(remote\) / encoding \(bare\)" \
206196
> /tmp/driver-test-current.log 2>&1
207197
echo "EXIT: $?"
208198
```
@@ -275,7 +265,7 @@ If both runtime boxes are now checked, the file is fully done; advance to the ne
275265
**e) If tests fail:**
276266

277267
1. Do NOT move to the next runtime or file.
278-
2. Narrow down to the first failing test using a more specific `-t` filter (keep the same env vars).
268+
2. Narrow down to the first failing test by adding enough test-name text to the same `-t` pattern.
279269
3. Read the error output to understand the failure.
280270
4. Append to the log:
281271

@@ -292,18 +282,16 @@ If both runtime boxes are now checked, the file is fully done; advance to the ne
292282

293283
### 5. Narrowing scope on failure
294284

295-
If a file group fails, narrow to individual tests while keeping the same runtime env vars:
285+
If a file group fails, keep the full matrix selector and append enough test-name text to isolate the failing test:
296286

297287
```bash
298288
cd rivetkit-typescript/packages/rivetkit && \
299-
RIVETKIT_DRIVER_TEST_RUNTIME=<runtime> \
300-
RIVETKIT_DRIVER_TEST_SQLITE=<backend> \
301-
RIVETKIT_DRIVER_TEST_ENCODING=bare \
302289
pnpm test tests/driver/<FILE>.test.ts \
303-
-t "static registry.*runtime \\(<runtime>\\) / sqlite \\(<backend>\\) / encoding \\(bare\\).*<SUITE>.*<PARTIAL_TEST_NAME>" \
290+
-t "runtime \(<runtime>\) / sqlite \(<backend>\) / encoding \(bare\).*<test name>" \
304291
> /tmp/driver-test-narrow.log 2>&1
305292
```
306293

294+
Do not use `-t` as a flake workaround. It is only for selecting the intended matrix cell and, when needed, a specific failing test.
307295
If the bug only appears on one runtime, that's a strong signal — focus the diff hunt on the corresponding runtime adapter (`napi-runtime.ts` / `wasm-runtime.ts`) and any wasm-feature-gated code in `rivetkit-core` and `rivetkit-typescript/packages/rivetkit-wasm`.
308296

309297
### 6. Completion
@@ -327,6 +315,6 @@ Report summary:
327315
3. **Fix before advancing.** Do not skip a failing runtime/file to test the next one (unless the user says to skip).
328316
4. **Always pipe to file.** Never rely on inline terminal output for test results. Always write to `/tmp/driver-test-current.log` and grep afterward.
329317
5. **Track everything.** Every run gets logged in the progress file with its runtime tag.
330-
6. **Always set the env vars.** Even when running a single runtime, set `RIVETKIT_DRIVER_TEST_RUNTIME`, `RIVETKIT_DRIVER_TEST_SQLITE`, and `RIVETKIT_DRIVER_TEST_ENCODING`. The describe path depends on having any of them set.
318+
6. **Always use `-t` for matrix selection.** Include runtime, SQLite backend, and encoding in the selector. Do not scope the driver matrix with env vars.
331319
7. **Never pair `wasm` with `local` SQLite.** The harness throws on this combination. If a wasm run somehow needs local SQLite to repro a bug, that's a bug in the matrix, not a workaround to apply.
332320
8. **Respect timeouts.** Set a 600-second timeout for slow tests (sleep, lifecycle, stress). Use 120 seconds for fast tests. Wasm runs may be slower than native — extend timeouts proportionally if you see consistent timeouts on wasm only.
Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,10 @@
1-
import { afterEach, describe, expect, test } from "vitest";
1+
import { describe, expect, test } from "vitest";
22
import {
33
getDriverMatrixCells,
44
SQLITE_DRIVER_MATRIX_OPTIONS,
55
} from "./shared-matrix";
66

7-
const previousRuntimeEnv = process.env.RIVETKIT_DRIVER_TEST_RUNTIME;
8-
const previousSqliteEnv = process.env.RIVETKIT_DRIVER_TEST_SQLITE;
9-
const previousEncodingEnv = process.env.RIVETKIT_DRIVER_TEST_ENCODING;
10-
11-
function restoreMatrixEnv() {
12-
if (previousRuntimeEnv === undefined) {
13-
delete process.env.RIVETKIT_DRIVER_TEST_RUNTIME;
14-
} else {
15-
process.env.RIVETKIT_DRIVER_TEST_RUNTIME = previousRuntimeEnv;
16-
}
17-
18-
if (previousSqliteEnv === undefined) {
19-
delete process.env.RIVETKIT_DRIVER_TEST_SQLITE;
20-
} else {
21-
process.env.RIVETKIT_DRIVER_TEST_SQLITE = previousSqliteEnv;
22-
}
23-
24-
if (previousEncodingEnv === undefined) {
25-
delete process.env.RIVETKIT_DRIVER_TEST_ENCODING;
26-
} else {
27-
process.env.RIVETKIT_DRIVER_TEST_ENCODING = previousEncodingEnv;
28-
}
29-
}
30-
317
describe("driver matrix cells", () => {
32-
afterEach(() => {
33-
restoreMatrixEnv();
34-
});
35-
368
test("excludes wasm with local SQLite from the normal matrix", () => {
379
const cells = getDriverMatrixCells(SQLITE_DRIVER_MATRIX_OPTIONS);
3810

@@ -73,12 +45,18 @@ describe("driver matrix cells", () => {
7345
]);
7446
});
7547

76-
test("fails fast when env explicitly selects wasm with local SQLite", () => {
77-
process.env.RIVETKIT_DRIVER_TEST_RUNTIME = "wasm";
78-
process.env.RIVETKIT_DRIVER_TEST_SQLITE = "local";
48+
test("defaults to both runnable runtime pairs", () => {
49+
const cells = getDriverMatrixCells({ encodings: ["bare"] });
7950

80-
expect(() => getDriverMatrixCells()).toThrow(
81-
/WebAssembly runtime cannot use local SQLite/,
82-
);
51+
expect(
52+
cells.map(
53+
(cell) =>
54+
`${cell.runtime}/${cell.sqliteBackend}/${cell.encoding}`,
55+
),
56+
).toEqual([
57+
"native/local/bare",
58+
"native/remote/bare",
59+
"wasm/remote/bare",
60+
]);
8361
});
8462
});

rivetkit-typescript/packages/rivetkit/tests/driver/shared-matrix.ts

Lines changed: 4 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -42,66 +42,14 @@ export interface DriverMatrixCell {
4242
skipReason?: string;
4343
}
4444

45-
function envList<T extends string>(
46-
name: string,
47-
allowed: readonly T[],
48-
): T[] | undefined {
49-
const value = process.env[name];
50-
if (!value) {
51-
return undefined;
52-
}
53-
54-
const values = value
55-
.split(",")
56-
.map((part) => part.trim())
57-
.filter(Boolean);
58-
for (const item of values) {
59-
if (!allowed.includes(item as T)) {
60-
throw new Error(
61-
`invalid ${name} value '${item}', expected one of ${allowed.join(", ")}`,
62-
);
63-
}
64-
}
65-
return values as T[];
66-
}
67-
68-
function hasEnvMatrixOverride() {
69-
return (
70-
process.env.RIVETKIT_DRIVER_TEST_RUNTIME !== undefined ||
71-
process.env.RIVETKIT_DRIVER_TEST_SQLITE !== undefined ||
72-
process.env.RIVETKIT_DRIVER_TEST_ENCODING !== undefined
73-
);
74-
}
75-
7645
export function getDriverMatrixCells(
7746
options: DriverMatrixOptions = {},
7847
): DriverMatrixCell[] {
79-
const envEncodings = envList("RIVETKIT_DRIVER_TEST_ENCODING", [
80-
"bare",
81-
"cbor",
82-
"json",
83-
] as const);
84-
const envRuntimes = envList("RIVETKIT_DRIVER_TEST_RUNTIME", [
85-
"native",
86-
"wasm",
87-
] as const);
88-
const envSqliteBackends = envList("RIVETKIT_DRIVER_TEST_SQLITE", [
89-
"local",
90-
"remote",
91-
] as const);
92-
const encodings = envEncodings ??
93-
options.encodings ?? ["bare", "cbor", "json"];
94-
const runtimes = envRuntimes ?? options.runtimes ?? ["native"];
95-
const sqliteBackends = envSqliteBackends ??
96-
options.sqliteBackends ?? ["local"];
48+
const encodings = options.encodings ?? ["bare", "cbor", "json"];
49+
const runtimes = options.runtimes ?? ["native", "wasm"];
50+
const sqliteBackends = options.sqliteBackends ?? ["local", "remote"];
9751
const cells: DriverMatrixCell[] = [];
9852

99-
if (envRuntimes?.includes("wasm") && envSqliteBackends?.includes("local")) {
100-
throw new Error(
101-
"invalid driver test matrix: WebAssembly runtime cannot use local SQLite. Set RIVETKIT_DRIVER_TEST_SQLITE=remote for wasm driver tests.",
102-
);
103-
}
104-
10553
for (const runtime of runtimes) {
10654
for (const sqliteBackend of sqliteBackends) {
10755
if (runtime === "wasm" && sqliteBackend === "local") {
@@ -133,10 +81,6 @@ export function describeDriverMatrix(
13381
registryVariantNames.has(variant.name),
13482
);
13583
const cells = getDriverMatrixCells(options);
136-
const includeSqliteDimensions =
137-
hasEnvMatrixOverride() ||
138-
options.runtimes !== undefined ||
139-
options.sqliteBackends !== undefined;
14084

14185
describeDriverSuite(suiteName, () => {
14286
for (const variant of variants) {
@@ -151,9 +95,7 @@ export function describeDriverMatrix(
15195
});
15296

15397
for (const cell of cells) {
154-
const suite = includeSqliteDimensions
155-
? `runtime (${cell.runtime}) / sqlite (${cell.sqliteBackend}) / encoding (${cell.encoding})`
156-
: `encoding (${cell.encoding})`;
98+
const suite = `runtime (${cell.runtime}) / sqlite (${cell.sqliteBackend}) / encoding (${cell.encoding})`;
15799

158100
if (cell.skipReason) {
159101
describe.skip(`${suite}: ${cell.skipReason}`, () => {});

0 commit comments

Comments
 (0)