@zgeoff/rig 0.1.5 → 0.2.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 +4 -4
- package/dist/build-test-selection.d.ts +1 -0
- package/dist/build-unit-command.d.ts +8 -1
- package/dist/bunfig-declaration-schema.d.ts +5 -0
- package/dist/collect-test-runs.d.ts +14 -0
- package/dist/find-single-run-flag.d.ts +5 -0
- package/dist/has-lane-suffix.d.ts +1 -0
- package/dist/index.js +65 -2
- package/dist/is-test-file.d.ts +1 -0
- package/dist/make-ignore-check.d.ts +1 -0
- package/dist/pick-unit-run-plan.d.ts +15 -0
- package/dist/repo-glob-schema.d.ts +2 -0
- package/dist/run-related-tests.d.ts +1 -2
- package/dist/run-unit-tests.d.ts +4 -3
- package/dist/run-unit.d.ts +1 -2
- package/dist/types.d.ts +8 -0
- package/package.json +1 -1
- package/src/build-test-selection.ts +10 -12
- package/src/build-unit-command.ts +53 -8
- package/src/bunfig-declaration-schema.ts +11 -0
- package/src/collect-test-runs.ts +102 -0
- package/src/define-rig.ts +46 -1
- package/src/find-single-run-flag.ts +33 -0
- package/src/has-lane-suffix.ts +3 -0
- package/src/is-test-file.ts +5 -0
- package/src/make-ignore-check.ts +15 -0
- package/src/parse-rig-config.ts +36 -2
- package/src/pick-unit-run-plan.ts +55 -0
- package/src/repo-glob-schema.ts +11 -0
- package/src/resolve-related-tests.ts +4 -4
- package/src/run-lane.ts +47 -15
- package/src/run-related-tests.ts +23 -12
- package/src/run-unit-tests.ts +73 -17
- package/src/run-unit.ts +13 -5
- package/src/types.ts +17 -0
package/README.md
CHANGED
|
@@ -64,19 +64,19 @@ no file and fails the run.
|
|
|
64
64
|
|
|
65
65
|
## Configuration
|
|
66
66
|
|
|
67
|
-
`rig.config.ts` at the repo root declares what differs from the built-in lanes
|
|
67
|
+
`rig.config.ts` at the repo root declares what differs from the built-in lanes, in `ignore` the
|
|
68
|
+
[paths that no lane tests](../../docs/architecture/rig.md#ignored-paths), and in `bunfigs` the
|
|
69
|
+
[bunfig of a set of unit tests](../../docs/architecture/rig.md#the-bunfig-of-each-test):
|
|
68
70
|
|
|
69
71
|
```ts
|
|
70
72
|
import { defineRig } from '@zgeoff/rig';
|
|
71
73
|
|
|
72
74
|
export default defineRig({
|
|
75
|
+
ignore: ['docs/drafts/**'],
|
|
73
76
|
lanes: { kiln: { suffix: '.kiln', limit: '15s', start: './test-utils/start-kiln.ts' } },
|
|
74
77
|
});
|
|
75
78
|
```
|
|
76
79
|
|
|
77
|
-
Oxlint's plugin reads this file under Node 22.18 or later, or under Bun, because it imports the
|
|
78
|
-
config to take the limits from it.
|
|
79
|
-
|
|
80
80
|
A repo declares the programs its `e2e/` folders and benchmarks run in `programs`, which `rig e2e`
|
|
81
81
|
and `rig bench` build first; `resolveProgram` gives each one's command. `rig bench` and `rig eval`
|
|
82
82
|
run the benchmarks and evaluation suites. [Programs in e2e tests](../../docs/guides/e2e-programs.md)
|
|
@@ -2,6 +2,7 @@ import type { TestArgs } from './parse-test-args.ts';
|
|
|
2
2
|
import type { ResolvedLane, RigConfig } from './types.ts';
|
|
3
3
|
export type TestSelection = {
|
|
4
4
|
readonly kind: 'lane';
|
|
5
|
+
readonly files: readonly string[];
|
|
5
6
|
readonly flags: readonly string[];
|
|
6
7
|
} | {
|
|
7
8
|
readonly kind: 'empty';
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
+
import type { TestRun } from './collect-test-runs.ts';
|
|
1
2
|
import type { RigConfig } from './types.ts';
|
|
2
|
-
export
|
|
3
|
+
export interface UnitCommandRequest {
|
|
4
|
+
readonly e2eDirs: readonly string[];
|
|
5
|
+
readonly workerCount: number;
|
|
6
|
+
readonly testRun: TestRun;
|
|
7
|
+
readonly flags: readonly string[];
|
|
8
|
+
}
|
|
9
|
+
export declare function buildUnitCommand(config: RigConfig, request: UnitCommandRequest): readonly string[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { BunfigDeclaration } from './types.ts';
|
|
2
|
+
export interface TestRun {
|
|
3
|
+
readonly folder: string;
|
|
4
|
+
readonly bunfig: string | null;
|
|
5
|
+
readonly files: readonly string[] | null;
|
|
6
|
+
readonly ignore: readonly string[];
|
|
7
|
+
}
|
|
8
|
+
export interface TestRunRequest {
|
|
9
|
+
readonly bunfigs: readonly BunfigDeclaration[];
|
|
10
|
+
readonly trackedFiles: readonly string[];
|
|
11
|
+
readonly tests: readonly string[];
|
|
12
|
+
readonly isDiscovery: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function collectTestRuns(request: TestRunRequest): TestRun[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function hasLaneSuffix(file: string, suffix: string): boolean;
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
// src/bunfig-declaration-schema.ts
|
|
2
|
+
import { z as z2 } from "zod";
|
|
3
|
+
|
|
4
|
+
// src/repo-glob-schema.ts
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
var repoGlobSchema = z.string().refine((pattern) => pattern !== "" && !pattern.startsWith("/") && !hasDotSegment(pattern));
|
|
7
|
+
function hasDotSegment(path) {
|
|
8
|
+
return path.split("/").some((segment) => segment === "." || segment === "..");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// src/bunfig-declaration-schema.ts
|
|
12
|
+
var bunfigDeclarationSchema = z2.object({
|
|
13
|
+
path: repoGlobSchema.refine((path) => path.endsWith(".toml")),
|
|
14
|
+
files: z2.array(repoGlobSchema).min(1)
|
|
15
|
+
}).readonly();
|
|
16
|
+
|
|
1
17
|
// src/is-command-name.ts
|
|
2
18
|
var commandNames = ["bench", "eval", "init", "related"];
|
|
3
19
|
function isCommandName(name) {
|
|
@@ -47,7 +63,13 @@ function defineRig(declaration) {
|
|
|
47
63
|
name,
|
|
48
64
|
readProgram(name, program)
|
|
49
65
|
]));
|
|
50
|
-
return {
|
|
66
|
+
return {
|
|
67
|
+
ignore: (declaration.ignore ?? []).map((pattern) => readIgnorePattern(pattern)),
|
|
68
|
+
bunfigs: (declaration.bunfigs ?? []).map((bunfig) => readBunfig(bunfig)),
|
|
69
|
+
lanes,
|
|
70
|
+
programs,
|
|
71
|
+
benchLane: readBenchLane(declaration.bench?.lane, lanes)
|
|
72
|
+
};
|
|
51
73
|
}
|
|
52
74
|
function resolveStandardLane(standard, declaration) {
|
|
53
75
|
const declared = declaration ?? {};
|
|
@@ -167,6 +189,30 @@ function readProgram(name, program) {
|
|
|
167
189
|
artifact: program.artifact
|
|
168
190
|
};
|
|
169
191
|
}
|
|
192
|
+
function readIgnorePattern(pattern) {
|
|
193
|
+
const parsed = repoGlobSchema.safeParse(pattern);
|
|
194
|
+
if (!parsed.success) {
|
|
195
|
+
throw new Error(`rig.config.ts: the ignore pattern ${JSON.stringify(pattern)} must be a non-empty glob relative to the repo root, with no "." or ".." segment`);
|
|
196
|
+
}
|
|
197
|
+
return parsed.data;
|
|
198
|
+
}
|
|
199
|
+
function readBunfig(bunfig) {
|
|
200
|
+
const parsed = bunfigDeclarationSchema.safeParse(bunfig);
|
|
201
|
+
if (!parsed.success) {
|
|
202
|
+
throw new Error(formatBunfigError(bunfig, parsed.error.issues.at(0)?.path ?? []));
|
|
203
|
+
}
|
|
204
|
+
return parsed.data;
|
|
205
|
+
}
|
|
206
|
+
function formatBunfigError(bunfig, issuePath) {
|
|
207
|
+
const [field, index] = issuePath;
|
|
208
|
+
if (field === "path") {
|
|
209
|
+
return `rig.config.ts: the bunfig path ${JSON.stringify(bunfig.path)} must be a .toml file relative to the repo root, with no "." or ".." segment`;
|
|
210
|
+
}
|
|
211
|
+
if (typeof index === "number") {
|
|
212
|
+
return `rig.config.ts: the bunfig "${bunfig.path}" file glob ${JSON.stringify(bunfig.files[index])} must be a non-empty glob relative to the repo root, with no "." or ".." segment`;
|
|
213
|
+
}
|
|
214
|
+
return `rig.config.ts: the bunfig "${bunfig.path}" needs files, a list of globs`;
|
|
215
|
+
}
|
|
170
216
|
function readBenchLane(lane, lanes) {
|
|
171
217
|
if (lane === undefined) {
|
|
172
218
|
return null;
|
|
@@ -177,6 +223,7 @@ function readBenchLane(lane, lanes) {
|
|
|
177
223
|
return lane;
|
|
178
224
|
}
|
|
179
225
|
// src/parse-rig-config.ts
|
|
226
|
+
import { z as z3 } from "zod";
|
|
180
227
|
function parseRigConfig(value) {
|
|
181
228
|
if (typeof value !== "object" || value === null || !("lanes" in value)) {
|
|
182
229
|
return { kind: "refused", reason: "the default export has no lanes" };
|
|
@@ -201,9 +248,17 @@ function parseRigConfig(value) {
|
|
|
201
248
|
if (benchLane !== undefined && !isNullableString(benchLane)) {
|
|
202
249
|
return { kind: "refused", reason: `its benchLane is ${JSON.stringify(benchLane)}` };
|
|
203
250
|
}
|
|
251
|
+
const ignore = parseIgnore(Reflect.get(value, "ignore"));
|
|
252
|
+
if (ignore === null) {
|
|
253
|
+
return { kind: "refused", reason: "its ignore is no list of patterns" };
|
|
254
|
+
}
|
|
255
|
+
const bunfigs = parseBunfigs(Reflect.get(value, "bunfigs"));
|
|
256
|
+
if (bunfigs === null) {
|
|
257
|
+
return { kind: "refused", reason: "its bunfigs are no list of bunfig declarations" };
|
|
258
|
+
}
|
|
204
259
|
return {
|
|
205
260
|
kind: "parsed",
|
|
206
|
-
config: { lanes: resolved, programs, benchLane: benchLane ?? null }
|
|
261
|
+
config: { ignore, bunfigs, lanes: resolved, programs, benchLane: benchLane ?? null }
|
|
207
262
|
};
|
|
208
263
|
}
|
|
209
264
|
function parseResolvedLane(value, index) {
|
|
@@ -282,6 +337,14 @@ function parseProgram(value) {
|
|
|
282
337
|
}
|
|
283
338
|
return { package: packageFolder, source, build, artifact };
|
|
284
339
|
}
|
|
340
|
+
function parseIgnore(value) {
|
|
341
|
+
const parsed = z3.array(repoGlobSchema).optional().safeParse(value);
|
|
342
|
+
return parsed.success ? parsed.data ?? [] : null;
|
|
343
|
+
}
|
|
344
|
+
function parseBunfigs(value) {
|
|
345
|
+
const parsed = z3.array(bunfigDeclarationSchema).optional().safeParse(value);
|
|
346
|
+
return parsed.success ? parsed.data ?? [] : null;
|
|
347
|
+
}
|
|
285
348
|
// src/browser/run-in-page.ts
|
|
286
349
|
async function runInPage(view, pageFunction, argument, schema) {
|
|
287
350
|
const source = pageFunction.toString();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isTestFile(path: string): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function makeIgnoreCheck(patterns: readonly string[]): (path: string) => boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TestRun } from './collect-test-runs.ts';
|
|
2
|
+
import type { RigConfig } from './types.ts';
|
|
3
|
+
export interface UnitRunPlanRequest {
|
|
4
|
+
readonly flags: readonly string[];
|
|
5
|
+
readonly tests: readonly string[];
|
|
6
|
+
readonly isDiscovery: boolean;
|
|
7
|
+
}
|
|
8
|
+
export type UnitRunPlan = {
|
|
9
|
+
readonly kind: 'refused';
|
|
10
|
+
readonly message: string;
|
|
11
|
+
} | {
|
|
12
|
+
readonly kind: 'runs';
|
|
13
|
+
readonly testRuns: readonly TestRun[];
|
|
14
|
+
};
|
|
15
|
+
export declare function pickUnitRunPlan(config: RigConfig, request: UnitRunPlanRequest, trackedFiles: readonly string[]): UnitRunPlan;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { WorkerCount } from './read-worker-count.ts';
|
|
2
2
|
import type { RelatedTestSources } from './resolve-related-tests.ts';
|
|
3
3
|
import type { UnitRunDeps } from './run-unit-tests.ts';
|
|
4
|
-
import type { RigConfig,
|
|
4
|
+
import type { RigConfig, RigRun } from './types.ts';
|
|
5
5
|
export interface RelatedTestDeps extends UnitRunDeps {
|
|
6
6
|
readonly sources: Readonly<RelatedTestSources>;
|
|
7
7
|
readonly readWorkerCount: () => Promise<WorkerCount>;
|
|
8
|
-
readonly output: RigOutput;
|
|
9
8
|
}
|
|
10
9
|
export declare function runRelatedTests(args: readonly string[], config: RigConfig, run: RigRun, deps: Readonly<RelatedTestDeps>): Promise<number>;
|
package/dist/run-unit-tests.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import type { UnitRunPlanRequest } from './pick-unit-run-plan.ts';
|
|
1
2
|
import type { CommandOptions } from './run-command.ts';
|
|
2
|
-
import type { RigConfig, RigRun } from './types.ts';
|
|
3
|
-
export interface UnitRequest {
|
|
3
|
+
import type { RigConfig, RigOutput, RigRun } from './types.ts';
|
|
4
|
+
export interface UnitRequest extends UnitRunPlanRequest {
|
|
4
5
|
readonly workerCount: number;
|
|
5
|
-
readonly extraArgs: readonly string[];
|
|
6
6
|
}
|
|
7
7
|
export interface UnitRunDeps {
|
|
8
8
|
readonly dietScript: string;
|
|
9
9
|
readonly probeWorkspaceRepo: (repoRoot: string) => Promise<boolean>;
|
|
10
10
|
readonly readTrackedFiles: (repoRoot: string) => Promise<readonly string[]>;
|
|
11
11
|
readonly runCommand: (command: readonly string[], options: CommandOptions) => Promise<number>;
|
|
12
|
+
readonly output: RigOutput;
|
|
12
13
|
}
|
|
13
14
|
export declare function runUnitTests(config: RigConfig, request: UnitRequest, run: RigRun, deps: UnitRunDeps): Promise<number>;
|
package/dist/run-unit.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { WorkerCount } from './read-worker-count.ts';
|
|
2
2
|
import type { UnitRunDeps } from './run-unit-tests.ts';
|
|
3
|
-
import type { RigConfig,
|
|
3
|
+
import type { RigConfig, RigRun } from './types.ts';
|
|
4
4
|
export interface UnitDeps extends UnitRunDeps {
|
|
5
5
|
readonly readWorkerCount: () => Promise<WorkerCount>;
|
|
6
|
-
readonly output: RigOutput;
|
|
7
6
|
}
|
|
8
7
|
export declare function runUnit(config: RigConfig, extraArgs: readonly string[], run: RigRun, deps: UnitDeps): Promise<number>;
|
package/dist/types.d.ts
CHANGED
|
@@ -14,7 +14,13 @@ export interface ProgramDeclaration {
|
|
|
14
14
|
export interface BenchDeclaration {
|
|
15
15
|
readonly lane?: string;
|
|
16
16
|
}
|
|
17
|
+
export interface BunfigDeclaration {
|
|
18
|
+
readonly path: string;
|
|
19
|
+
readonly files: readonly string[];
|
|
20
|
+
}
|
|
17
21
|
export interface RigDeclaration {
|
|
22
|
+
readonly ignore?: readonly string[];
|
|
23
|
+
readonly bunfigs?: readonly BunfigDeclaration[];
|
|
18
24
|
readonly lanes?: Readonly<Record<string, LaneDeclaration>>;
|
|
19
25
|
readonly programs?: Readonly<Record<string, ProgramDeclaration>>;
|
|
20
26
|
readonly bench?: BenchDeclaration;
|
|
@@ -30,6 +36,8 @@ export interface ResolvedLane {
|
|
|
30
36
|
readonly stop: string | null;
|
|
31
37
|
}
|
|
32
38
|
export interface RigConfig {
|
|
39
|
+
readonly ignore: readonly string[];
|
|
40
|
+
readonly bunfigs: readonly BunfigDeclaration[];
|
|
33
41
|
readonly lanes: readonly ResolvedLane[];
|
|
34
42
|
readonly programs: Readonly<Record<string, ProgramDeclaration>>;
|
|
35
43
|
readonly benchLane: string | null;
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { posix } from 'node:path';
|
|
2
2
|
import { match } from 'ts-pattern';
|
|
3
|
+
import { hasLaneSuffix } from './has-lane-suffix.ts';
|
|
4
|
+
import { isTestFile } from './is-test-file.ts';
|
|
5
|
+
import { makeIgnoreCheck } from './make-ignore-check.ts';
|
|
3
6
|
import type { TestArgs } from './parse-test-args.ts';
|
|
4
7
|
import { pickE2EDirs } from './pick-e2e-dirs.ts';
|
|
5
8
|
import type { ResolvedLane, RigConfig } from './types.ts';
|
|
6
9
|
|
|
7
10
|
export type TestSelection =
|
|
8
|
-
| { readonly kind: 'lane'; readonly flags: readonly string[] }
|
|
11
|
+
| { readonly kind: 'lane'; readonly files: readonly string[]; readonly flags: readonly string[] }
|
|
9
12
|
| { readonly kind: 'empty' }
|
|
10
13
|
| { readonly kind: 'files'; readonly files: readonly string[]; readonly flags: readonly string[] }
|
|
11
14
|
| { readonly kind: 'none'; readonly paths: readonly string[] };
|
|
@@ -31,7 +34,9 @@ export function buildTestSelection(request: TestSelectionRequest): TestSelection
|
|
|
31
34
|
const laneFiles = collectLaneTestFiles(request);
|
|
32
35
|
|
|
33
36
|
if (split.paths.length === 0) {
|
|
34
|
-
return laneFiles.length === 0
|
|
37
|
+
return laneFiles.length === 0
|
|
38
|
+
? { kind: 'empty' }
|
|
39
|
+
: { kind: 'lane', files: laneFiles, flags: split.flags };
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
const selectors = split.paths.map((path) =>
|
|
@@ -44,18 +49,15 @@ export function buildTestSelection(request: TestSelectionRequest): TestSelection
|
|
|
44
49
|
|
|
45
50
|
return files.length === 0
|
|
46
51
|
? { kind: 'none', paths: split.paths }
|
|
47
|
-
: { kind: 'files', files
|
|
52
|
+
: { kind: 'files', files, flags: split.flags };
|
|
48
53
|
}
|
|
49
54
|
|
|
50
|
-
const testFilePattern = /[._](?:test|spec)\.[jt]sx?$/u;
|
|
51
|
-
|
|
52
|
-
// The unit lane takes every test file that no other lane claims, the e2e lane the ones under its
|
|
53
|
-
// folders, and any other lane the ones with its suffix.
|
|
54
55
|
function collectLaneTestFiles(request: TestSelectionRequest): readonly string[] {
|
|
55
56
|
const config = request.config;
|
|
56
57
|
const lane = request.lane;
|
|
57
58
|
const trackedFiles = request.trackedFiles;
|
|
58
59
|
const e2eDirs = pickE2EDirs(trackedFiles, request.isWorkspaceRepo);
|
|
60
|
+
const isIgnored = makeIgnoreCheck(config.ignore);
|
|
59
61
|
|
|
60
62
|
const isUnderE2EDir = (file: string) =>
|
|
61
63
|
e2eDirs.some((directory) => file.startsWith(`${directory}/`));
|
|
@@ -63,7 +65,7 @@ function collectLaneTestFiles(request: TestSelectionRequest): readonly string[]
|
|
|
63
65
|
const isClaimedBySuffix = (file: string) =>
|
|
64
66
|
config.lanes.some((other) => other.suffix !== null && hasLaneSuffix(file, other.suffix));
|
|
65
67
|
|
|
66
|
-
const testFiles = trackedFiles.filter((file) =>
|
|
68
|
+
const testFiles = trackedFiles.filter((file) => isTestFile(file) && !isIgnored(file));
|
|
67
69
|
const suffix = lane.suffix;
|
|
68
70
|
|
|
69
71
|
if (suffix !== null) {
|
|
@@ -75,10 +77,6 @@ function collectLaneTestFiles(request: TestSelectionRequest): readonly string[]
|
|
|
75
77
|
: testFiles.filter((file) => !isUnderE2EDir(file) && !isClaimedBySuffix(file));
|
|
76
78
|
}
|
|
77
79
|
|
|
78
|
-
function hasLaneSuffix(file: string, suffix: string): boolean {
|
|
79
|
-
return file.endsWith(`${suffix}.test.ts`) || file.endsWith(`${suffix}.test.tsx`);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
80
|
type Selector =
|
|
83
81
|
| { readonly kind: 'file'; readonly path: string }
|
|
84
82
|
| { readonly kind: 'directory'; readonly path: string }
|
|
@@ -1,23 +1,68 @@
|
|
|
1
|
+
import { posix } from 'node:path';
|
|
2
|
+
import type { TestRun } from './collect-test-runs.ts';
|
|
1
3
|
import { testRunArgs } from './test-run-args.ts';
|
|
2
4
|
import type { RigConfig } from './types.ts';
|
|
3
5
|
|
|
6
|
+
export interface UnitCommandRequest {
|
|
7
|
+
readonly e2eDirs: readonly string[];
|
|
8
|
+
|
|
9
|
+
readonly workerCount: number;
|
|
10
|
+
|
|
11
|
+
readonly testRun: TestRun;
|
|
12
|
+
|
|
13
|
+
readonly flags: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
|
|
4
16
|
// The e2e lane has no suffix, so the unit run leaves out the folders that the e2e lane selects,
|
|
5
|
-
// from the same list
|
|
17
|
+
// from the same list. A --path-ignore-patterns argument replaces bunfig.toml's pathIgnorePatterns,
|
|
18
|
+
// so the config's ignore list is the only place a repo can leave a path out of the unit run.
|
|
6
19
|
export function buildUnitCommand(
|
|
7
20
|
config: RigConfig,
|
|
8
|
-
|
|
9
|
-
workerCount: number,
|
|
10
|
-
extraArgs: readonly string[],
|
|
21
|
+
request: UnitCommandRequest,
|
|
11
22
|
): readonly string[] {
|
|
23
|
+
const testRun = request.testRun;
|
|
24
|
+
|
|
12
25
|
const suffixPatterns = config.lanes.flatMap((lane) =>
|
|
13
26
|
lane.suffix === null ? [] : [`**/*${lane.suffix}.test.ts`, `**/*${lane.suffix}.test.tsx`],
|
|
14
27
|
);
|
|
15
28
|
|
|
16
|
-
const e2ePatterns = e2eDirs.map((directory) => `${directory}/**`);
|
|
29
|
+
const e2ePatterns = request.e2eDirs.map((directory) => `${directory}/**`);
|
|
17
30
|
|
|
18
|
-
const
|
|
19
|
-
|
|
31
|
+
const patterns = collectFolderPatterns(
|
|
32
|
+
[...suffixPatterns, ...e2ePatterns, ...config.ignore, ...testRun.ignore],
|
|
33
|
+
testRun.folder,
|
|
20
34
|
);
|
|
21
35
|
|
|
22
|
-
|
|
36
|
+
const ignoreArgs = patterns.map((pattern) => `--path-ignore-patterns=${pattern}`);
|
|
37
|
+
const configArgs = testRun.bunfig === null ? [] : [`--config=./${testRun.bunfig}`];
|
|
38
|
+
|
|
39
|
+
// bun test reads a bare argument as a name filter; the ./ makes it a path.
|
|
40
|
+
const fileArgs = (testRun.files ?? []).map((file) => `./${posix.relative(testRun.folder, file)}`);
|
|
41
|
+
|
|
42
|
+
return [
|
|
43
|
+
'bun',
|
|
44
|
+
'test',
|
|
45
|
+
...configArgs,
|
|
46
|
+
`--parallel=${request.workerCount}`,
|
|
47
|
+
...testRunArgs,
|
|
48
|
+
...ignoreArgs,
|
|
49
|
+
...request.flags,
|
|
50
|
+
...fileArgs,
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// bun test matches a glob against paths relative to the folder it runs from. A glob that starts
|
|
55
|
+
// with `**/` matches in any folder, and a glob for another folder can match nothing in this one.
|
|
56
|
+
function collectFolderPatterns(patterns: readonly string[], folder: string): readonly string[] {
|
|
57
|
+
if (folder === '') {
|
|
58
|
+
return patterns;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return patterns.flatMap((pattern) => {
|
|
62
|
+
if (pattern.startsWith('**/')) {
|
|
63
|
+
return [pattern];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return pattern.startsWith(`${folder}/`) ? [pattern.slice(folder.length + 1)] : [];
|
|
67
|
+
});
|
|
23
68
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { repoGlobSchema } from './repo-glob-schema.ts';
|
|
3
|
+
|
|
4
|
+
// rig runs the bunfig's tests from the repo root, and compares a changed file's bare path with the
|
|
5
|
+
// bunfig's, so the path follows the same rules as a glob.
|
|
6
|
+
export const bunfigDeclarationSchema = z
|
|
7
|
+
.object({
|
|
8
|
+
path: repoGlobSchema.refine((path) => path.endsWith('.toml')),
|
|
9
|
+
files: z.array(repoGlobSchema).min(1),
|
|
10
|
+
})
|
|
11
|
+
.readonly();
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { makeIgnoreCheck } from './make-ignore-check.ts';
|
|
2
|
+
import type { BunfigDeclaration } from './types.ts';
|
|
3
|
+
|
|
4
|
+
// One `bun test` process: the folder it runs from, the bunfig it reads, and its tests.
|
|
5
|
+
export interface TestRun {
|
|
6
|
+
// Relative to the repo root, and '' for the root.
|
|
7
|
+
readonly folder: string;
|
|
8
|
+
|
|
9
|
+
// A path relative to the repo root that the run passes as --config, or null for the bunfig.toml
|
|
10
|
+
// of the run's folder.
|
|
11
|
+
readonly bunfig: string | null;
|
|
12
|
+
|
|
13
|
+
// Test files relative to the repo root, or null when bun test finds the tests under the folder.
|
|
14
|
+
readonly files: readonly string[] | null;
|
|
15
|
+
|
|
16
|
+
// Globs relative to the repo root of the tests that another run takes.
|
|
17
|
+
readonly ignore: readonly string[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface TestRunRequest {
|
|
21
|
+
readonly bunfigs: readonly BunfigDeclaration[];
|
|
22
|
+
|
|
23
|
+
readonly trackedFiles: readonly string[];
|
|
24
|
+
|
|
25
|
+
// The unit tests to run, relative to the repo root.
|
|
26
|
+
readonly tests: readonly string[];
|
|
27
|
+
|
|
28
|
+
// True when the root run finds its own tests, as a run of the whole unit lane does.
|
|
29
|
+
readonly isDiscovery: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface TestGroup {
|
|
33
|
+
readonly folder: string;
|
|
34
|
+
|
|
35
|
+
readonly bunfig: string | null;
|
|
36
|
+
|
|
37
|
+
readonly files: string[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// bun test reads only the bunfig.toml of the folder it runs from, and resolves a preload against
|
|
41
|
+
// that folder, even under --config. So a package with a bunfig.toml of its own runs its tests from
|
|
42
|
+
// its folder, and a bunfigs entry runs its tests from the repo root.
|
|
43
|
+
export function collectTestRuns(request: TestRunRequest): TestRun[] {
|
|
44
|
+
const packageFolders = collectPackageBunfigFolders(request.trackedFiles);
|
|
45
|
+
|
|
46
|
+
const bunfigChecks = request.bunfigs.map((bunfig) => ({
|
|
47
|
+
path: bunfig.path,
|
|
48
|
+
isBunfigFile: makeIgnoreCheck(bunfig.files),
|
|
49
|
+
}));
|
|
50
|
+
|
|
51
|
+
const groups = new Map<string, TestGroup>();
|
|
52
|
+
|
|
53
|
+
for (const test of request.tests) {
|
|
54
|
+
const bunfig = bunfigChecks.find((check) => check.isBunfigFile(test))?.path ?? null;
|
|
55
|
+
|
|
56
|
+
const folder =
|
|
57
|
+
bunfig === null ? (packageFolders.find((owner) => test.startsWith(`${owner}/`)) ?? '') : '';
|
|
58
|
+
|
|
59
|
+
const key = JSON.stringify([folder, bunfig]);
|
|
60
|
+
const group = groups.get(key) ?? { folder, bunfig, files: [] };
|
|
61
|
+
|
|
62
|
+
group.files.push(test);
|
|
63
|
+
groups.set(key, group);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const otherRunGlobs = [
|
|
67
|
+
...packageFolders.map((folder) => `${folder}/**`),
|
|
68
|
+
...request.bunfigs.flatMap((bunfig) => bunfig.files),
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
return [...groups.values()]
|
|
72
|
+
.toSorted((first, second) => toSortKey(first).localeCompare(toSortKey(second)))
|
|
73
|
+
.map((group) => {
|
|
74
|
+
const isRootDiscovery = request.isDiscovery && group.folder === '' && group.bunfig === null;
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
folder: group.folder,
|
|
78
|
+
bunfig: group.bunfig,
|
|
79
|
+
files: isRootDiscovery ? null : group.files,
|
|
80
|
+
ignore: isRootDiscovery ? otherRunGlobs : [],
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// The deepest package folder above a test owns it, so the list runs from the deepest folder up.
|
|
86
|
+
function collectPackageBunfigFolders(trackedFiles: readonly string[]): readonly string[] {
|
|
87
|
+
const tracked = new Set(trackedFiles);
|
|
88
|
+
|
|
89
|
+
const suffix = '/bunfig.toml';
|
|
90
|
+
|
|
91
|
+
return trackedFiles
|
|
92
|
+
.filter((file) => file.endsWith(suffix))
|
|
93
|
+
.map((file) => file.slice(0, -suffix.length))
|
|
94
|
+
.filter((folder) => tracked.has(`${folder}/package.json`))
|
|
95
|
+
.toSorted((first, second) => second.length - first.length);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function toSortKey(group: TestGroup): string {
|
|
99
|
+
return group.folder === '' && group.bunfig === null
|
|
100
|
+
? ''
|
|
101
|
+
: `${group.folder}\0${group.bunfig ?? ''}`;
|
|
102
|
+
}
|
package/src/define-rig.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { bunfigDeclarationSchema } from './bunfig-declaration-schema.ts';
|
|
1
2
|
import { isCommandName } from './is-command-name.ts';
|
|
2
3
|
import { parseDuration } from './parse-duration.ts';
|
|
4
|
+
import { repoGlobSchema } from './repo-glob-schema.ts';
|
|
3
5
|
import { standardLanes } from './standard-lanes.ts';
|
|
4
6
|
import type { StandardLane } from './standard-lanes.ts';
|
|
5
7
|
import type {
|
|
8
|
+
BunfigDeclaration,
|
|
6
9
|
LaneDeclaration,
|
|
7
10
|
ProgramDeclaration,
|
|
8
11
|
ResolvedLane,
|
|
@@ -48,7 +51,13 @@ export function defineRig(declaration: RigDeclaration): RigConfig {
|
|
|
48
51
|
]),
|
|
49
52
|
);
|
|
50
53
|
|
|
51
|
-
return {
|
|
54
|
+
return {
|
|
55
|
+
ignore: (declaration.ignore ?? []).map((pattern) => readIgnorePattern(pattern)),
|
|
56
|
+
bunfigs: (declaration.bunfigs ?? []).map((bunfig) => readBunfig(bunfig)),
|
|
57
|
+
lanes,
|
|
58
|
+
programs,
|
|
59
|
+
benchLane: readBenchLane(declaration.bench?.lane, lanes),
|
|
60
|
+
};
|
|
52
61
|
}
|
|
53
62
|
|
|
54
63
|
function resolveStandardLane(
|
|
@@ -245,6 +254,42 @@ function readProgram(name: string, program: ProgramDeclaration): ProgramDeclarat
|
|
|
245
254
|
};
|
|
246
255
|
}
|
|
247
256
|
|
|
257
|
+
function readIgnorePattern(pattern: unknown): string {
|
|
258
|
+
const parsed = repoGlobSchema.safeParse(pattern);
|
|
259
|
+
|
|
260
|
+
if (!parsed.success) {
|
|
261
|
+
throw new Error(
|
|
262
|
+
`rig.config.ts: the ignore pattern ${JSON.stringify(pattern)} must be a non-empty glob relative to the repo root, with no "." or ".." segment`,
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return parsed.data;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function readBunfig(bunfig: BunfigDeclaration): BunfigDeclaration {
|
|
270
|
+
const parsed = bunfigDeclarationSchema.safeParse(bunfig);
|
|
271
|
+
|
|
272
|
+
if (!parsed.success) {
|
|
273
|
+
throw new Error(formatBunfigError(bunfig, parsed.error.issues.at(0)?.path ?? []));
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return parsed.data;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function formatBunfigError(bunfig: BunfigDeclaration, issuePath: readonly PropertyKey[]): string {
|
|
280
|
+
const [field, index] = issuePath;
|
|
281
|
+
|
|
282
|
+
if (field === 'path') {
|
|
283
|
+
return `rig.config.ts: the bunfig path ${JSON.stringify(bunfig.path)} must be a .toml file relative to the repo root, with no "." or ".." segment`;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (typeof index === 'number') {
|
|
287
|
+
return `rig.config.ts: the bunfig "${bunfig.path}" file glob ${JSON.stringify(bunfig.files[index])} must be a non-empty glob relative to the repo root, with no "." or ".." segment`;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return `rig.config.ts: the bunfig "${bunfig.path}" needs files, a list of globs`;
|
|
291
|
+
}
|
|
292
|
+
|
|
248
293
|
function readBenchLane(lane: string | undefined, lanes: readonly ResolvedLane[]): string | null {
|
|
249
294
|
if (lane === undefined) {
|
|
250
295
|
return null;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface SingleRunFlag {
|
|
2
|
+
readonly flag: string;
|
|
3
|
+
|
|
4
|
+
// True when the flag writes or reads a path that resolves against the folder the run starts from.
|
|
5
|
+
readonly holdsPath: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// A `--watch` run never exits, so the runs after it never start. Each `--coverage` or
|
|
9
|
+
// `--reporter-outfile` run writes its file relative to its own folder, or over the one before it,
|
|
10
|
+
// and a relative `--preload` resolves against each run's folder. All need one `bun test` run.
|
|
11
|
+
const singleRunFlags = [
|
|
12
|
+
{ name: '--watch', holdsPath: false },
|
|
13
|
+
{ name: '--coverage', holdsPath: true },
|
|
14
|
+
{ name: '--reporter-outfile', holdsPath: true },
|
|
15
|
+
{ name: '--preload', holdsPath: true },
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
export function findSingleRunFlag(flags: readonly string[]): SingleRunFlag | undefined {
|
|
19
|
+
for (const flag of flags) {
|
|
20
|
+
const known = singleRunFlags.find(
|
|
21
|
+
(candidate) =>
|
|
22
|
+
flag === candidate.name ||
|
|
23
|
+
flag.startsWith(`${candidate.name}=`) ||
|
|
24
|
+
flag.startsWith(`${candidate.name}-`),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
if (known !== undefined) {
|
|
28
|
+
return { flag, holdsPath: known.holdsPath };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// bun test reads each ignore pattern as a glob on the path relative to the repo root, and skips a
|
|
2
|
+
// folder that a glob matches during discovery, so a file under a matched folder is ignored too.
|
|
3
|
+
export function makeIgnoreCheck(patterns: readonly string[]): (path: string) => boolean {
|
|
4
|
+
const globs = patterns.map((pattern) => new Bun.Glob(pattern));
|
|
5
|
+
|
|
6
|
+
return (path) => {
|
|
7
|
+
const segments = path.split('/');
|
|
8
|
+
|
|
9
|
+
return segments.some((_, index) => {
|
|
10
|
+
const prefix = segments.slice(0, index + 1).join('/');
|
|
11
|
+
|
|
12
|
+
return globs.some((glob) => glob.match(prefix));
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
}
|
package/src/parse-rig-config.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { bunfigDeclarationSchema } from './bunfig-declaration-schema.ts';
|
|
3
|
+
import { repoGlobSchema } from './repo-glob-schema.ts';
|
|
4
|
+
import type {
|
|
5
|
+
BunfigDeclaration,
|
|
6
|
+
LaneParallelism,
|
|
7
|
+
ProgramDeclaration,
|
|
8
|
+
ResolvedLane,
|
|
9
|
+
RigConfig,
|
|
10
|
+
} from './types.ts';
|
|
2
11
|
|
|
3
12
|
export type ParsedRigConfig =
|
|
4
13
|
| { readonly kind: 'parsed'; readonly config: RigConfig }
|
|
@@ -41,9 +50,21 @@ export function parseRigConfig(value: unknown): ParsedRigConfig {
|
|
|
41
50
|
return { kind: 'refused', reason: `its benchLane is ${JSON.stringify(benchLane)}` };
|
|
42
51
|
}
|
|
43
52
|
|
|
53
|
+
const ignore = parseIgnore(Reflect.get(value, 'ignore'));
|
|
54
|
+
|
|
55
|
+
if (ignore === null) {
|
|
56
|
+
return { kind: 'refused', reason: 'its ignore is no list of patterns' };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const bunfigs = parseBunfigs(Reflect.get(value, 'bunfigs'));
|
|
60
|
+
|
|
61
|
+
if (bunfigs === null) {
|
|
62
|
+
return { kind: 'refused', reason: 'its bunfigs are no list of bunfig declarations' };
|
|
63
|
+
}
|
|
64
|
+
|
|
44
65
|
return {
|
|
45
66
|
kind: 'parsed',
|
|
46
|
-
config: { lanes: resolved, programs, benchLane: benchLane ?? null },
|
|
67
|
+
config: { ignore, bunfigs, lanes: resolved, programs, benchLane: benchLane ?? null },
|
|
47
68
|
};
|
|
48
69
|
}
|
|
49
70
|
|
|
@@ -156,3 +177,16 @@ function parseProgram(value: unknown): ProgramDeclaration | null {
|
|
|
156
177
|
|
|
157
178
|
return { package: packageFolder, source, build, artifact };
|
|
158
179
|
}
|
|
180
|
+
|
|
181
|
+
function parseIgnore(value: unknown): string[] | null {
|
|
182
|
+
const parsed = z.array(repoGlobSchema).optional().safeParse(value);
|
|
183
|
+
|
|
184
|
+
return parsed.success ? (parsed.data ?? []) : null;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// A config may leave bunfigs out, and then every unit test runs under the bunfig of its folder.
|
|
188
|
+
function parseBunfigs(value: unknown): readonly BunfigDeclaration[] | null {
|
|
189
|
+
const parsed = z.array(bunfigDeclarationSchema).optional().safeParse(value);
|
|
190
|
+
|
|
191
|
+
return parsed.success ? (parsed.data ?? []) : null;
|
|
192
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { TestRun } from './collect-test-runs.ts';
|
|
2
|
+
import { collectTestRuns } from './collect-test-runs.ts';
|
|
3
|
+
import { findSingleRunFlag } from './find-single-run-flag.ts';
|
|
4
|
+
import type { RigConfig } from './types.ts';
|
|
5
|
+
|
|
6
|
+
export interface UnitRunPlanRequest {
|
|
7
|
+
readonly flags: readonly string[];
|
|
8
|
+
|
|
9
|
+
// The unit tests to run, relative to the repo root.
|
|
10
|
+
readonly tests: readonly string[];
|
|
11
|
+
|
|
12
|
+
// True when the run takes the whole unit lane, so the root run finds its own tests.
|
|
13
|
+
readonly isDiscovery: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type UnitRunPlan =
|
|
17
|
+
| { readonly kind: 'refused'; readonly message: string }
|
|
18
|
+
| { readonly kind: 'runs'; readonly testRuns: readonly TestRun[] };
|
|
19
|
+
|
|
20
|
+
export function pickUnitRunPlan(
|
|
21
|
+
config: RigConfig,
|
|
22
|
+
request: UnitRunPlanRequest,
|
|
23
|
+
trackedFiles: readonly string[],
|
|
24
|
+
): UnitRunPlan {
|
|
25
|
+
const testRuns = collectTestRuns({
|
|
26
|
+
bunfigs: config.bunfigs,
|
|
27
|
+
trackedFiles,
|
|
28
|
+
tests: request.tests,
|
|
29
|
+
isDiscovery: request.isDiscovery,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const singleRunFlag = findSingleRunFlag(request.flags);
|
|
33
|
+
|
|
34
|
+
if (singleRunFlag === undefined) {
|
|
35
|
+
return { kind: 'runs', testRuns };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (testRuns.length > 1) {
|
|
39
|
+
return {
|
|
40
|
+
kind: 'refused',
|
|
41
|
+
message: `rig: ${singleRunFlag.flag} needs the tests in one bun test run, and these tests need ${testRuns.length}, one for each bunfig; name the tests of one bunfig\n`,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const packageFolder = testRuns.find((testRun) => testRun.folder !== '')?.folder;
|
|
46
|
+
|
|
47
|
+
if (singleRunFlag.holdsPath && packageFolder !== undefined) {
|
|
48
|
+
return {
|
|
49
|
+
kind: 'refused',
|
|
50
|
+
message: `rig: ${singleRunFlag.flag} holds a path, and these tests run from ${packageFolder} under its own bunfig.toml, so the path would resolve there; run bun test from that folder\n`,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return { kind: 'runs', testRuns };
|
|
55
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// rig matches each glob against bare paths relative to the repo root, so an absolute glob, one
|
|
4
|
+
// that climbs out of the repo, or one with a `./` segment would never match.
|
|
5
|
+
export const repoGlobSchema = z
|
|
6
|
+
.string()
|
|
7
|
+
.refine((pattern) => pattern !== '' && !pattern.startsWith('/') && !hasDotSegment(pattern));
|
|
8
|
+
|
|
9
|
+
function hasDotSegment(path: string): boolean {
|
|
10
|
+
return path.split('/').some((segment) => segment === '.' || segment === '..');
|
|
11
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { basename, join } from 'node:path';
|
|
2
|
+
import { makeIgnoreCheck } from './make-ignore-check.ts';
|
|
2
3
|
import type { RigConfig } from './types.ts';
|
|
3
4
|
|
|
4
5
|
export interface RelatedTestSources {
|
|
@@ -7,21 +8,20 @@ export interface RelatedTestSources {
|
|
|
7
8
|
readonly probeFile: (path: string) => boolean;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
// The unit run covers a changed file through the test beside it, so each changed path maps to its
|
|
11
|
-
// sibling test, and the files of a lane drop out.
|
|
12
11
|
export function resolveRelatedTests(
|
|
13
12
|
paths: readonly string[],
|
|
14
13
|
config: RigConfig,
|
|
15
14
|
sources: Readonly<RelatedTestSources>,
|
|
16
15
|
): string[] {
|
|
17
16
|
const suffixes = config.lanes.flatMap((lane) => (lane.suffix === null ? [] : [lane.suffix]));
|
|
17
|
+
const isIgnored = makeIgnoreCheck(config.ignore);
|
|
18
18
|
|
|
19
19
|
const selected = new Set<string>();
|
|
20
20
|
|
|
21
21
|
for (const path of paths) {
|
|
22
|
-
const test = findRelatedTest(path, suffixes);
|
|
22
|
+
const test = isIgnored(path) ? undefined : findRelatedTest(path, suffixes);
|
|
23
23
|
|
|
24
|
-
if (test !== undefined && sources.probeFile(join(sources.cwd, test))) {
|
|
24
|
+
if (test !== undefined && !isIgnored(test) && sources.probeFile(join(sources.cwd, test))) {
|
|
25
25
|
selected.add(test);
|
|
26
26
|
}
|
|
27
27
|
}
|
package/src/run-lane.ts
CHANGED
|
@@ -7,7 +7,10 @@ import { buildTestSelection } from './build-test-selection.ts';
|
|
|
7
7
|
import { collectUnprogrammedE2EDirs } from './collect-unprogrammed-e2e-dirs.ts';
|
|
8
8
|
import { formatNoMatchMessage } from './format-no-match-message.ts';
|
|
9
9
|
import { formatNoTestsMessage } from './format-no-tests-message.ts';
|
|
10
|
+
import { hasLaneSuffix } from './has-lane-suffix.ts';
|
|
11
|
+
import { isTestFile } from './is-test-file.ts';
|
|
10
12
|
import type { LaneHooks } from './lane-hooks.ts';
|
|
13
|
+
import { makeIgnoreCheck } from './make-ignore-check.ts';
|
|
11
14
|
import { makeRepoLaneHooks } from './make-repo-lane-hooks.ts';
|
|
12
15
|
import { parseTestArgs } from './parse-test-args.ts';
|
|
13
16
|
import { pickE2EDirs } from './pick-e2e-dirs.ts';
|
|
@@ -66,7 +69,12 @@ export async function runLane(request: LaneRequest, run: RigRun, deps: LaneDeps)
|
|
|
66
69
|
return 0;
|
|
67
70
|
}
|
|
68
71
|
|
|
69
|
-
const e2eDirs =
|
|
72
|
+
const e2eDirs = collectRunnableE2EDirs(
|
|
73
|
+
pickE2EDirs(trackedFiles, isWorkspaceRepo),
|
|
74
|
+
trackedFiles,
|
|
75
|
+
request.config,
|
|
76
|
+
);
|
|
77
|
+
|
|
70
78
|
const testArgs = pickLaneTestArgs(request.config, lane, selection, e2eDirs);
|
|
71
79
|
const programs = lane.name === 'e2e' ? request.config.programs : {};
|
|
72
80
|
|
|
@@ -97,6 +105,23 @@ export async function runLane(request: LaneRequest, run: RigRun, deps: LaneDeps)
|
|
|
97
105
|
return pickExitCodeAfterTests(exitCode, run.signal.aborted);
|
|
98
106
|
}
|
|
99
107
|
|
|
108
|
+
function collectRunnableE2EDirs(
|
|
109
|
+
e2eDirs: readonly string[],
|
|
110
|
+
trackedFiles: readonly string[],
|
|
111
|
+
config: RigConfig,
|
|
112
|
+
): readonly string[] {
|
|
113
|
+
const isIgnored = makeIgnoreCheck(config.ignore);
|
|
114
|
+
|
|
115
|
+
const isE2ETest = (file: string) =>
|
|
116
|
+
isTestFile(file) &&
|
|
117
|
+
!isIgnored(file) &&
|
|
118
|
+
!config.lanes.some((lane) => lane.suffix !== null && hasLaneSuffix(file, lane.suffix));
|
|
119
|
+
|
|
120
|
+
return e2eDirs.filter((directory) =>
|
|
121
|
+
trackedFiles.some((file) => file.startsWith(`${directory}/`) && isE2ETest(file)),
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
100
125
|
function pickLaneTestArgs(
|
|
101
126
|
config: RigConfig,
|
|
102
127
|
lane: ResolvedLane,
|
|
@@ -105,30 +130,37 @@ function pickLaneTestArgs(
|
|
|
105
130
|
): readonly string[] {
|
|
106
131
|
const timeoutArg = `--timeout=${lane.limitMs}`;
|
|
107
132
|
|
|
133
|
+
// bun test reads a bare argument as a name filter; the ./ makes it a path.
|
|
108
134
|
return match(selection)
|
|
109
|
-
.with({ kind: 'files' }, (files) => [
|
|
135
|
+
.with({ kind: 'files' }, (files) => [
|
|
136
|
+
timeoutArg,
|
|
137
|
+
...files.files.map((file) => `./${file}`),
|
|
138
|
+
...files.flags,
|
|
139
|
+
])
|
|
110
140
|
.with({ kind: 'lane' }, (laneRun) => [
|
|
111
141
|
timeoutArg,
|
|
112
142
|
...pickLaneSelection(lane, e2eDirs),
|
|
113
|
-
...
|
|
143
|
+
...pickLaneIgnoreArgs(config, lane),
|
|
114
144
|
...laneRun.flags,
|
|
115
145
|
])
|
|
116
146
|
.exhaustive();
|
|
117
147
|
}
|
|
118
148
|
|
|
119
149
|
// A folder selection takes every test file under it, so the e2e lane leaves out the files that
|
|
120
|
-
// belong to a lane with a suffix.
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
150
|
+
// belong to a lane with a suffix. A --path-ignore-patterns argument replaces bunfig.toml's
|
|
151
|
+
// pathIgnorePatterns, so every lane passes the config's ignore list itself.
|
|
152
|
+
function pickLaneIgnoreArgs(config: RigConfig, lane: ResolvedLane): readonly string[] {
|
|
153
|
+
const otherLanePatterns =
|
|
154
|
+
lane.suffix === null
|
|
155
|
+
? config.lanes.flatMap((other) =>
|
|
156
|
+
other.suffix === null
|
|
157
|
+
? []
|
|
158
|
+
: [`**/*${other.suffix}.test.ts`, `**/*${other.suffix}.test.tsx`],
|
|
159
|
+
)
|
|
160
|
+
: [];
|
|
161
|
+
|
|
162
|
+
return [...otherLanePatterns, ...config.ignore].map(
|
|
163
|
+
(pattern) => `--path-ignore-patterns=${pattern}`,
|
|
132
164
|
);
|
|
133
165
|
}
|
|
134
166
|
|
package/src/run-related-tests.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { resolveRelatedTests } from './resolve-related-tests.ts';
|
|
|
5
5
|
import type { RelatedTestSources } from './resolve-related-tests.ts';
|
|
6
6
|
import type { UnitRunDeps } from './run-unit-tests.ts';
|
|
7
7
|
import { runUnitTests } from './run-unit-tests.ts';
|
|
8
|
-
import type { RigConfig,
|
|
8
|
+
import type { RigConfig, RigRun } from './types.ts';
|
|
9
9
|
|
|
10
10
|
// A host with one worker runs each file slower than CI, and a test that passes there must not fail
|
|
11
11
|
// the push.
|
|
@@ -15,8 +15,6 @@ export interface RelatedTestDeps extends UnitRunDeps {
|
|
|
15
15
|
readonly sources: Readonly<RelatedTestSources>;
|
|
16
16
|
|
|
17
17
|
readonly readWorkerCount: () => Promise<WorkerCount>;
|
|
18
|
-
|
|
19
|
-
readonly output: RigOutput;
|
|
20
18
|
}
|
|
21
19
|
|
|
22
20
|
// The related run is the unit lane on the tests beside the changed files, in this process.
|
|
@@ -36,6 +34,7 @@ export async function runRelatedTests(
|
|
|
36
34
|
|
|
37
35
|
const plan = buildRelatedTestPlan(
|
|
38
36
|
options.paths,
|
|
37
|
+
config,
|
|
39
38
|
resolveRelatedTests(options.paths, config, deps.sources),
|
|
40
39
|
);
|
|
41
40
|
|
|
@@ -55,10 +54,12 @@ export async function runRelatedTests(
|
|
|
55
54
|
|
|
56
55
|
const timeoutArgs = workers.count === 1 ? [`--timeout=${slowHostTestTimeoutMs}`] : [];
|
|
57
56
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
return runUnitTests(
|
|
58
|
+
config,
|
|
59
|
+
{ workerCount: workers.count, flags: timeoutArgs, tests: plan.tests, isDiscovery: false },
|
|
60
|
+
run,
|
|
61
|
+
deps,
|
|
62
|
+
);
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
type RelatedTestArgs =
|
|
@@ -83,8 +84,13 @@ type RelatedTestPlan =
|
|
|
83
84
|
|
|
84
85
|
const maxTestFiles = 50;
|
|
85
86
|
|
|
86
|
-
function buildRelatedTestPlan(
|
|
87
|
-
|
|
87
|
+
function buildRelatedTestPlan(
|
|
88
|
+
paths: readonly string[],
|
|
89
|
+
config: RigConfig,
|
|
90
|
+
tests: readonly string[],
|
|
91
|
+
): RelatedTestPlan {
|
|
92
|
+
const bunfigPaths = config.bunfigs.map((bunfig) => bunfig.path);
|
|
93
|
+
const shared = paths.find((path) => isSharedTestInput(path, bunfigPaths));
|
|
88
94
|
|
|
89
95
|
if (shared !== undefined) {
|
|
90
96
|
return {
|
|
@@ -107,7 +113,12 @@ function buildRelatedTestPlan(paths: readonly string[], tests: readonly string[]
|
|
|
107
113
|
return { kind: 'run', tests };
|
|
108
114
|
}
|
|
109
115
|
|
|
110
|
-
// A shared helper
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
// A shared helper, a bunfig.toml or a bunfig that the config names reaches tests beyond the
|
|
117
|
+
// siblings of the files it changes.
|
|
118
|
+
function isSharedTestInput(path: string, bunfigPaths: readonly string[]): boolean {
|
|
119
|
+
return (
|
|
120
|
+
/(?:^|\/)test-utils\//u.test(path) ||
|
|
121
|
+
basename(path) === 'bunfig.toml' ||
|
|
122
|
+
bunfigPaths.includes(path)
|
|
123
|
+
);
|
|
113
124
|
}
|
package/src/run-unit-tests.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { match } from 'ts-pattern';
|
|
1
3
|
import { buildDietCommand } from './build-diet-command.ts';
|
|
2
4
|
import { buildUnitCommand } from './build-unit-command.ts';
|
|
5
|
+
import type { TestRun } from './collect-test-runs.ts';
|
|
3
6
|
import { pickE2EDirs } from './pick-e2e-dirs.ts';
|
|
7
|
+
import type { UnitRunPlanRequest } from './pick-unit-run-plan.ts';
|
|
8
|
+
import { pickUnitRunPlan } from './pick-unit-run-plan.ts';
|
|
4
9
|
import type { CommandOptions } from './run-command.ts';
|
|
5
|
-
import type { RigConfig, RigRun } from './types.ts';
|
|
10
|
+
import type { RigConfig, RigOutput, RigRun } from './types.ts';
|
|
6
11
|
|
|
7
|
-
export interface UnitRequest {
|
|
12
|
+
export interface UnitRequest extends UnitRunPlanRequest {
|
|
8
13
|
readonly workerCount: number;
|
|
9
|
-
|
|
10
|
-
readonly extraArgs: readonly string[];
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
export interface UnitRunDeps {
|
|
@@ -18,10 +21,10 @@ export interface UnitRunDeps {
|
|
|
18
21
|
readonly readTrackedFiles: (repoRoot: string) => Promise<readonly string[]>;
|
|
19
22
|
|
|
20
23
|
readonly runCommand: (command: readonly string[], options: CommandOptions) => Promise<number>;
|
|
24
|
+
|
|
25
|
+
readonly output: RigOutput;
|
|
21
26
|
}
|
|
22
27
|
|
|
23
|
-
// The unit lane's command is built from the lane table, so a lane that the table lists never
|
|
24
|
-
// reaches the unit run.
|
|
25
28
|
export async function runUnitTests(
|
|
26
29
|
config: RigConfig,
|
|
27
30
|
request: UnitRequest,
|
|
@@ -31,15 +34,68 @@ export async function runUnitTests(
|
|
|
31
34
|
const trackedFiles = await deps.readTrackedFiles(run.repoRoot);
|
|
32
35
|
const isWorkspaceRepo = await deps.probeWorkspaceRepo(run.repoRoot);
|
|
33
36
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
return match(pickUnitRunPlan(config, request, trackedFiles))
|
|
38
|
+
.with({ kind: 'refused' }, (refused) => {
|
|
39
|
+
deps.output.err(refused.message);
|
|
40
|
+
|
|
41
|
+
return 2;
|
|
42
|
+
})
|
|
43
|
+
.with({ kind: 'runs' }, (plan) =>
|
|
44
|
+
runTestRuns(plan.testRuns, pickE2EDirs(trackedFiles, isWorkspaceRepo), {
|
|
45
|
+
config,
|
|
46
|
+
request,
|
|
47
|
+
run,
|
|
48
|
+
deps,
|
|
49
|
+
}),
|
|
50
|
+
)
|
|
51
|
+
.exhaustive();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface TestRunsContext {
|
|
55
|
+
readonly config: RigConfig;
|
|
56
|
+
|
|
57
|
+
readonly request: UnitRequest;
|
|
58
|
+
|
|
59
|
+
readonly run: RigRun;
|
|
60
|
+
|
|
61
|
+
readonly deps: UnitRunDeps;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// The unit lane's command is built from the lane table, so a lane that the table lists never
|
|
65
|
+
// reaches the unit run. Every run goes ahead after one fails, so the output shows every failure.
|
|
66
|
+
async function runTestRuns(
|
|
67
|
+
testRuns: readonly TestRun[],
|
|
68
|
+
e2eDirs: readonly string[],
|
|
69
|
+
ctx: TestRunsContext,
|
|
70
|
+
): Promise<number> {
|
|
71
|
+
const memory = ctx.config.lanes.find((lane) => lane.name === 'unit')?.memory ?? null;
|
|
72
|
+
let exitCode = 0;
|
|
73
|
+
|
|
74
|
+
for (const testRun of testRuns) {
|
|
75
|
+
const runExitCode = await ctx.deps.runCommand(
|
|
76
|
+
buildDietCommand(
|
|
77
|
+
ctx.deps.dietScript,
|
|
78
|
+
memory,
|
|
79
|
+
buildUnitCommand(ctx.config, {
|
|
80
|
+
e2eDirs,
|
|
81
|
+
workerCount: ctx.request.workerCount,
|
|
82
|
+
testRun,
|
|
83
|
+
flags: ctx.request.flags,
|
|
84
|
+
}),
|
|
85
|
+
),
|
|
86
|
+
{
|
|
87
|
+
cwd: join(ctx.run.repoRoot, testRun.folder),
|
|
88
|
+
environment: ctx.run.environment,
|
|
89
|
+
signal: ctx.run.signal,
|
|
90
|
+
},
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
exitCode = exitCode === 0 ? runExitCode : exitCode;
|
|
94
|
+
|
|
95
|
+
if (ctx.run.signal.aborted) {
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return exitCode;
|
|
45
101
|
}
|
package/src/run-unit.ts
CHANGED
|
@@ -6,12 +6,10 @@ import { parseTestArgs } from './parse-test-args.ts';
|
|
|
6
6
|
import type { WorkerCount } from './read-worker-count.ts';
|
|
7
7
|
import type { UnitRunDeps } from './run-unit-tests.ts';
|
|
8
8
|
import { runUnitTests } from './run-unit-tests.ts';
|
|
9
|
-
import type { RigConfig,
|
|
9
|
+
import type { RigConfig, RigRun } from './types.ts';
|
|
10
10
|
|
|
11
11
|
export interface UnitDeps extends UnitRunDeps {
|
|
12
12
|
readonly readWorkerCount: () => Promise<WorkerCount>;
|
|
13
|
-
|
|
14
|
-
readonly output: RigOutput;
|
|
15
13
|
}
|
|
16
14
|
|
|
17
15
|
export async function runUnit(
|
|
@@ -57,13 +55,23 @@ export async function runUnit(
|
|
|
57
55
|
.with({ kind: 'files' }, (files) =>
|
|
58
56
|
runUnitTests(
|
|
59
57
|
config,
|
|
60
|
-
{ workerCount: workers.count,
|
|
58
|
+
{ workerCount: workers.count, flags: files.flags, tests: files.files, isDiscovery: false },
|
|
61
59
|
run,
|
|
62
60
|
deps,
|
|
63
61
|
),
|
|
64
62
|
)
|
|
65
63
|
.with({ kind: 'lane' }, (laneRun) =>
|
|
66
|
-
runUnitTests(
|
|
64
|
+
runUnitTests(
|
|
65
|
+
config,
|
|
66
|
+
{
|
|
67
|
+
workerCount: workers.count,
|
|
68
|
+
flags: laneRun.flags,
|
|
69
|
+
tests: laneRun.files,
|
|
70
|
+
isDiscovery: true,
|
|
71
|
+
},
|
|
72
|
+
run,
|
|
73
|
+
deps,
|
|
74
|
+
),
|
|
67
75
|
)
|
|
68
76
|
.exhaustive();
|
|
69
77
|
}
|
package/src/types.ts
CHANGED
|
@@ -35,7 +35,20 @@ export interface BenchDeclaration {
|
|
|
35
35
|
readonly lane?: string;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
// A bunfig that the unit tests matching its globs run under, such as one with a DOM preload.
|
|
39
|
+
export interface BunfigDeclaration {
|
|
40
|
+
// A path relative to the repo root.
|
|
41
|
+
readonly path: string;
|
|
42
|
+
|
|
43
|
+
// Globs relative to the repo root.
|
|
44
|
+
readonly files: readonly string[];
|
|
45
|
+
}
|
|
46
|
+
|
|
38
47
|
export interface RigDeclaration {
|
|
48
|
+
readonly ignore?: readonly string[];
|
|
49
|
+
|
|
50
|
+
readonly bunfigs?: readonly BunfigDeclaration[];
|
|
51
|
+
|
|
39
52
|
readonly lanes?: Readonly<Record<string, LaneDeclaration>>;
|
|
40
53
|
|
|
41
54
|
readonly programs?: Readonly<Record<string, ProgramDeclaration>>;
|
|
@@ -64,6 +77,10 @@ export interface ResolvedLane {
|
|
|
64
77
|
}
|
|
65
78
|
|
|
66
79
|
export interface RigConfig {
|
|
80
|
+
readonly ignore: readonly string[];
|
|
81
|
+
|
|
82
|
+
readonly bunfigs: readonly BunfigDeclaration[];
|
|
83
|
+
|
|
67
84
|
readonly lanes: readonly ResolvedLane[];
|
|
68
85
|
|
|
69
86
|
readonly programs: Readonly<Record<string, ProgramDeclaration>>;
|