@zgeoff/rig 0.1.5 → 0.1.6

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
@@ -64,19 +64,18 @@ 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, and in `ignore` the
68
+ [paths that no lane tests](../../docs/architecture/rig.md#ignored-paths):
68
69
 
69
70
  ```ts
70
71
  import { defineRig } from '@zgeoff/rig';
71
72
 
72
73
  export default defineRig({
74
+ ignore: ['docs/drafts/**'],
73
75
  lanes: { kiln: { suffix: '.kiln', limit: '15s', start: './test-utils/start-kiln.ts' } },
74
76
  });
75
77
  ```
76
78
 
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
79
  A repo declares the programs its `e2e/` folders and benchmarks run in `programs`, which `rig e2e`
81
80
  and `rig bench` build first; `resolveProgram` gives each one's command. `rig bench` and `rig eval`
82
81
  run the benchmarks and evaluation suites. [Programs in e2e tests](../../docs/guides/e2e-programs.md)
@@ -0,0 +1 @@
1
+ export declare function hasLaneSuffix(file: string, suffix: string): boolean;
package/dist/index.js CHANGED
@@ -47,7 +47,12 @@ function defineRig(declaration) {
47
47
  name,
48
48
  readProgram(name, program)
49
49
  ]));
50
- return { lanes, programs, benchLane: readBenchLane(declaration.bench?.lane, lanes) };
50
+ return {
51
+ ignore: (declaration.ignore ?? []).map((pattern) => readIgnorePattern(pattern)),
52
+ lanes,
53
+ programs,
54
+ benchLane: readBenchLane(declaration.bench?.lane, lanes)
55
+ };
51
56
  }
52
57
  function resolveStandardLane(standard, declaration) {
53
58
  const declared = declaration ?? {};
@@ -167,6 +172,12 @@ function readProgram(name, program) {
167
172
  artifact: program.artifact
168
173
  };
169
174
  }
175
+ function readIgnorePattern(pattern) {
176
+ if (typeof pattern !== "string" || pattern === "" || pattern.startsWith("/") || pattern.split("/").includes("..")) {
177
+ 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 ".." segment`);
178
+ }
179
+ return pattern;
180
+ }
170
181
  function readBenchLane(lane, lanes) {
171
182
  if (lane === undefined) {
172
183
  return null;
@@ -201,9 +212,13 @@ function parseRigConfig(value) {
201
212
  if (benchLane !== undefined && !isNullableString(benchLane)) {
202
213
  return { kind: "refused", reason: `its benchLane is ${JSON.stringify(benchLane)}` };
203
214
  }
215
+ const ignore = parseIgnore(Reflect.get(value, "ignore"));
216
+ if (ignore === null) {
217
+ return { kind: "refused", reason: "its ignore is no list of patterns" };
218
+ }
204
219
  return {
205
220
  kind: "parsed",
206
- config: { lanes: resolved, programs, benchLane: benchLane ?? null }
221
+ config: { ignore, lanes: resolved, programs, benchLane: benchLane ?? null }
207
222
  };
208
223
  }
209
224
  function parseResolvedLane(value, index) {
@@ -282,6 +297,22 @@ function parseProgram(value) {
282
297
  }
283
298
  return { package: packageFolder, source, build, artifact };
284
299
  }
300
+ function parseIgnore(value) {
301
+ if (value === undefined) {
302
+ return [];
303
+ }
304
+ if (!Array.isArray(value)) {
305
+ return null;
306
+ }
307
+ const patterns = [];
308
+ for (const pattern of value) {
309
+ if (typeof pattern !== "string") {
310
+ return null;
311
+ }
312
+ patterns.push(pattern);
313
+ }
314
+ return patterns;
315
+ }
285
316
  // src/browser/run-in-page.ts
286
317
  async function runInPage(view, pageFunction, argument, schema) {
287
318
  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;
package/dist/types.d.ts CHANGED
@@ -15,6 +15,7 @@ export interface BenchDeclaration {
15
15
  readonly lane?: string;
16
16
  }
17
17
  export interface RigDeclaration {
18
+ readonly ignore?: readonly string[];
18
19
  readonly lanes?: Readonly<Record<string, LaneDeclaration>>;
19
20
  readonly programs?: Readonly<Record<string, ProgramDeclaration>>;
20
21
  readonly bench?: BenchDeclaration;
@@ -30,6 +31,7 @@ export interface ResolvedLane {
30
31
  readonly stop: string | null;
31
32
  }
32
33
  export interface RigConfig {
34
+ readonly ignore: readonly string[];
33
35
  readonly lanes: readonly ResolvedLane[];
34
36
  readonly programs: Readonly<Record<string, ProgramDeclaration>>;
35
37
  readonly benchLane: string | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zgeoff/rig",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Run every test lane of a repo from one declaration of its limits, with a browser lane built in",
5
5
  "keywords": [
6
6
  "bun",
@@ -1,5 +1,8 @@
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';
@@ -47,15 +50,12 @@ export function buildTestSelection(request: TestSelectionRequest): TestSelection
47
50
  : { kind: 'files', files: files.map((file) => `./${file}`), flags: split.flags };
48
51
  }
49
52
 
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
53
  function collectLaneTestFiles(request: TestSelectionRequest): readonly string[] {
55
54
  const config = request.config;
56
55
  const lane = request.lane;
57
56
  const trackedFiles = request.trackedFiles;
58
57
  const e2eDirs = pickE2EDirs(trackedFiles, request.isWorkspaceRepo);
58
+ const isIgnored = makeIgnoreCheck(config.ignore);
59
59
 
60
60
  const isUnderE2EDir = (file: string) =>
61
61
  e2eDirs.some((directory) => file.startsWith(`${directory}/`));
@@ -63,7 +63,7 @@ function collectLaneTestFiles(request: TestSelectionRequest): readonly string[]
63
63
  const isClaimedBySuffix = (file: string) =>
64
64
  config.lanes.some((other) => other.suffix !== null && hasLaneSuffix(file, other.suffix));
65
65
 
66
- const testFiles = trackedFiles.filter((file) => testFilePattern.test(file));
66
+ const testFiles = trackedFiles.filter((file) => isTestFile(file) && !isIgnored(file));
67
67
  const suffix = lane.suffix;
68
68
 
69
69
  if (suffix !== null) {
@@ -75,10 +75,6 @@ function collectLaneTestFiles(request: TestSelectionRequest): readonly string[]
75
75
  : testFiles.filter((file) => !isUnderE2EDir(file) && !isClaimedBySuffix(file));
76
76
  }
77
77
 
78
- function hasLaneSuffix(file: string, suffix: string): boolean {
79
- return file.endsWith(`${suffix}.test.ts`) || file.endsWith(`${suffix}.test.tsx`);
80
- }
81
-
82
78
  type Selector =
83
79
  | { readonly kind: 'file'; readonly path: string }
84
80
  | { readonly kind: 'directory'; readonly path: string }
@@ -2,7 +2,8 @@ import { testRunArgs } from './test-run-args.ts';
2
2
  import type { RigConfig } from './types.ts';
3
3
 
4
4
  // The e2e lane has no suffix, so the unit run leaves out the folders that the e2e lane selects,
5
- // from the same list, and nothing else.
5
+ // from the same list. A --path-ignore-patterns argument replaces bunfig.toml's pathIgnorePatterns,
6
+ // so the config's ignore list is the only place a repo can leave a path out of the unit run.
6
7
  export function buildUnitCommand(
7
8
  config: RigConfig,
8
9
  e2eDirs: readonly string[],
@@ -15,7 +16,7 @@ export function buildUnitCommand(
15
16
 
16
17
  const e2ePatterns = e2eDirs.map((directory) => `${directory}/**`);
17
18
 
18
- const ignoreArgs = [...suffixPatterns, ...e2ePatterns].map(
19
+ const ignoreArgs = [...suffixPatterns, ...e2ePatterns, ...config.ignore].map(
19
20
  (pattern) => `--path-ignore-patterns=${pattern}`,
20
21
  );
21
22
 
package/src/define-rig.ts CHANGED
@@ -48,7 +48,12 @@ export function defineRig(declaration: RigDeclaration): RigConfig {
48
48
  ]),
49
49
  );
50
50
 
51
- return { lanes, programs, benchLane: readBenchLane(declaration.bench?.lane, lanes) };
51
+ return {
52
+ ignore: (declaration.ignore ?? []).map((pattern) => readIgnorePattern(pattern)),
53
+ lanes,
54
+ programs,
55
+ benchLane: readBenchLane(declaration.bench?.lane, lanes),
56
+ };
52
57
  }
53
58
 
54
59
  function resolveStandardLane(
@@ -245,6 +250,23 @@ function readProgram(name: string, program: ProgramDeclaration): ProgramDeclarat
245
250
  };
246
251
  }
247
252
 
253
+ // bun test matches an ignore pattern against paths relative to the repo root, so an absolute
254
+ // pattern or one that climbs out of the repo would never match.
255
+ function readIgnorePattern(pattern: unknown): string {
256
+ if (
257
+ typeof pattern !== 'string' ||
258
+ pattern === '' ||
259
+ pattern.startsWith('/') ||
260
+ pattern.split('/').includes('..')
261
+ ) {
262
+ throw new Error(
263
+ `rig.config.ts: the ignore pattern ${JSON.stringify(pattern)} must be a non-empty glob relative to the repo root, with no ".." segment`,
264
+ );
265
+ }
266
+
267
+ return pattern;
268
+ }
269
+
248
270
  function readBenchLane(lane: string | undefined, lanes: readonly ResolvedLane[]): string | null {
249
271
  if (lane === undefined) {
250
272
  return null;
@@ -0,0 +1,3 @@
1
+ export function hasLaneSuffix(file: string, suffix: string): boolean {
2
+ return file.endsWith(`${suffix}.test.ts`) || file.endsWith(`${suffix}.test.tsx`);
3
+ }
@@ -0,0 +1,5 @@
1
+ const testFilePattern = /[._](?:test|spec)\.[jt]sx?$/u;
2
+
3
+ export function isTestFile(path: string): boolean {
4
+ return testFilePattern.test(path);
5
+ }
@@ -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
+ }
@@ -41,9 +41,15 @@ export function parseRigConfig(value: unknown): ParsedRigConfig {
41
41
  return { kind: 'refused', reason: `its benchLane is ${JSON.stringify(benchLane)}` };
42
42
  }
43
43
 
44
+ const ignore = parseIgnore(Reflect.get(value, 'ignore'));
45
+
46
+ if (ignore === null) {
47
+ return { kind: 'refused', reason: 'its ignore is no list of patterns' };
48
+ }
49
+
44
50
  return {
45
51
  kind: 'parsed',
46
- config: { lanes: resolved, programs, benchLane: benchLane ?? null },
52
+ config: { ignore, lanes: resolved, programs, benchLane: benchLane ?? null },
47
53
  };
48
54
  }
49
55
 
@@ -156,3 +162,25 @@ function parseProgram(value: unknown): ProgramDeclaration | null {
156
162
 
157
163
  return { package: packageFolder, source, build, artifact };
158
164
  }
165
+
166
+ function parseIgnore(value: unknown): string[] | null {
167
+ if (value === undefined) {
168
+ return [];
169
+ }
170
+
171
+ if (!Array.isArray(value)) {
172
+ return null;
173
+ }
174
+
175
+ const patterns: string[] = [];
176
+
177
+ for (const pattern of value) {
178
+ if (typeof pattern !== 'string') {
179
+ return null;
180
+ }
181
+
182
+ patterns.push(pattern);
183
+ }
184
+
185
+ return patterns;
186
+ }
@@ -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 = pickE2EDirs(trackedFiles, isWorkspaceRepo);
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,
@@ -110,25 +135,27 @@ function pickLaneTestArgs(
110
135
  .with({ kind: 'lane' }, (laneRun) => [
111
136
  timeoutArg,
112
137
  ...pickLaneSelection(lane, e2eDirs),
113
- ...pickOtherLaneIgnoreArgs(config, lane),
138
+ ...pickLaneIgnoreArgs(config, lane),
114
139
  ...laneRun.flags,
115
140
  ])
116
141
  .exhaustive();
117
142
  }
118
143
 
119
144
  // 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
- function pickOtherLaneIgnoreArgs(config: RigConfig, lane: ResolvedLane): readonly string[] {
122
- if (lane.suffix !== null) {
123
- return [];
124
- }
125
-
126
- return config.lanes.flatMap((other) =>
127
- other.suffix === null
128
- ? []
129
- : [`**/*${other.suffix}.test.ts`, `**/*${other.suffix}.test.tsx`].map(
130
- (pattern) => `--path-ignore-patterns=${pattern}`,
131
- ),
145
+ // belong to a lane with a suffix. A --path-ignore-patterns argument replaces bunfig.toml's
146
+ // pathIgnorePatterns, so every lane passes the config's ignore list itself.
147
+ function pickLaneIgnoreArgs(config: RigConfig, lane: ResolvedLane): readonly string[] {
148
+ const otherLanePatterns =
149
+ lane.suffix === null
150
+ ? config.lanes.flatMap((other) =>
151
+ other.suffix === null
152
+ ? []
153
+ : [`**/*${other.suffix}.test.ts`, `**/*${other.suffix}.test.tsx`],
154
+ )
155
+ : [];
156
+
157
+ return [...otherLanePatterns, ...config.ignore].map(
158
+ (pattern) => `--path-ignore-patterns=${pattern}`,
132
159
  );
133
160
  }
134
161
 
package/src/types.ts CHANGED
@@ -36,6 +36,8 @@ export interface BenchDeclaration {
36
36
  }
37
37
 
38
38
  export interface RigDeclaration {
39
+ readonly ignore?: readonly string[];
40
+
39
41
  readonly lanes?: Readonly<Record<string, LaneDeclaration>>;
40
42
 
41
43
  readonly programs?: Readonly<Record<string, ProgramDeclaration>>;
@@ -64,6 +66,8 @@ export interface ResolvedLane {
64
66
  }
65
67
 
66
68
  export interface RigConfig {
69
+ readonly ignore: readonly string[];
70
+
67
71
  readonly lanes: readonly ResolvedLane[];
68
72
 
69
73
  readonly programs: Readonly<Record<string, ProgramDeclaration>>;