@zgeoff/rig 0.1.4 → 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 +3 -4
- package/dist/bench/bench-report-entry-schema.d.ts +10 -0
- package/dist/bench/build-base-side-root.d.ts +1 -0
- package/dist/bench/collect-bench-comparison.d.ts +3 -0
- package/dist/bench/define-bench.d.ts +2 -0
- package/dist/bench/find-base-setup-verdict.d.ts +3 -0
- package/dist/bench/find-missing-bench-verdict.d.ts +2 -0
- package/dist/bench/format-bench-comparison.d.ts +2 -0
- package/dist/bench/format-bench-report.d.ts +3 -0
- package/dist/bench/format-benchmark-result.d.ts +1 -1
- package/dist/bench/is-concurrency-list.d.ts +1 -0
- package/dist/bench/parse-bench-report.d.ts +9 -0
- package/dist/bench/pick-bench-exit-code.d.ts +2 -0
- package/dist/bench/pick-bench-plan.d.ts +13 -0
- package/dist/bench/pick-checkout-cleanup.d.ts +7 -0
- package/dist/bench/pick-cleaned-up-result.d.ts +9 -0
- package/dist/bench/pick-comparison-verdict.d.ts +7 -0
- package/dist/bench/pick-head-verdict.d.ts +3 -0
- package/dist/bench/pick-named-bench-files.d.ts +1 -0
- package/dist/bench/pick-quantile.d.ts +1 -0
- package/dist/bench/pick-unremoved-checkout-state.d.ts +3 -0
- package/dist/bench/read-bench-args.d.ts +9 -0
- package/dist/bench/read-bench-file-args.d.ts +9 -0
- package/dist/bench/run-benchmark.d.ts +3 -3
- package/dist/bench/to-bench-name.d.ts +1 -0
- package/dist/bench/types.d.ts +20 -0
- package/dist/build-bench-folder-path.d.ts +1 -0
- package/dist/create-bench-work-folder.d.ts +6 -0
- package/dist/format-parse-error.d.ts +1 -0
- package/dist/has-lane-suffix.d.ts +1 -0
- package/dist/index.js +33 -2
- package/dist/is-test-file.d.ts +1 -0
- package/dist/make-ignore-check.d.ts +1 -0
- package/dist/read-command-output.d.ts +8 -0
- package/dist/read-git-common-dir.d.ts +6 -0
- package/dist/read-git-prefix.d.ts +6 -0
- package/dist/run-bench.d.ts +7 -0
- package/dist/run-cli.d.ts +1 -2
- package/dist/types.d.ts +2 -0
- package/package.json +4 -4
- package/src/bench/bench-report-entry-schema.ts +17 -0
- package/src/bench/build-base-side-root.ts +7 -0
- package/src/bench/collect-bench-comparison.ts +43 -0
- package/src/bench/define-bench.ts +15 -0
- package/src/bench/find-base-setup-verdict.ts +21 -0
- package/src/bench/find-missing-bench-verdict.ts +33 -0
- package/src/bench/format-bench-comparison.ts +72 -0
- package/src/bench/format-bench-report.ts +24 -0
- package/src/bench/format-benchmark-result.ts +7 -3
- package/src/bench/is-concurrency-list.ts +10 -0
- package/src/bench/parse-bench-definition.ts +21 -3
- package/src/bench/parse-bench-report.ts +42 -0
- package/src/bench/pick-bench-exit-code.ts +15 -0
- package/src/bench/pick-bench-plan.ts +25 -0
- package/src/bench/pick-checkout-cleanup.ts +29 -0
- package/src/bench/pick-cleaned-up-result.ts +30 -0
- package/src/bench/pick-comparison-verdict.ts +36 -0
- package/src/bench/pick-head-verdict.ts +11 -0
- package/src/bench/pick-named-bench-files.ts +8 -0
- package/src/bench/pick-quantile.ts +9 -0
- package/src/bench/pick-unremoved-checkout-state.ts +30 -0
- package/src/bench/read-bench-args.ts +45 -0
- package/src/bench/read-bench-file-args.ts +38 -0
- package/src/bench/run-benchmark.ts +88 -21
- package/src/bench/to-bench-name.ts +5 -0
- package/src/bench/types.ts +37 -0
- package/src/build-bench-folder-path.ts +7 -0
- package/src/build-test-selection.ts +5 -9
- package/src/build-unit-command.ts +3 -2
- package/src/cli.ts +31 -0
- package/src/create-bench-work-folder.ts +26 -0
- package/src/define-rig.ts +23 -1
- package/src/format-parse-error.ts +9 -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 +29 -1
- package/src/read-cli-args.ts +1 -10
- package/src/read-command-output.ts +30 -0
- package/src/read-git-common-dir.ts +27 -0
- package/src/read-git-prefix.ts +27 -0
- package/src/resolve-related-tests.ts +4 -4
- package/src/run-bench-file.ts +23 -13
- package/src/run-bench.ts +348 -39
- package/src/run-cli.ts +1 -3
- package/src/run-lane.ts +41 -14
- package/src/types.ts +4 -0
- package/dist/bench/pick-median.d.ts +0 -1
- package/src/bench/pick-median.ts +0 -10
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface BenchOutput {
|
|
2
|
+
readonly stream: 'out' | 'err';
|
|
3
|
+
|
|
4
|
+
readonly text: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// What `rig bench` prints, in order, and the exit code it returns after.
|
|
8
|
+
export interface BenchVerdict {
|
|
9
|
+
readonly output: readonly BenchOutput[];
|
|
10
|
+
|
|
11
|
+
readonly exitCode: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// What became of the base checkout after its removal: `absent` when the removal failed and git
|
|
15
|
+
// registers no such worktree, `left` when git still registers it or its list failed.
|
|
16
|
+
export type CheckoutState = 'removed' | 'absent' | 'left';
|
|
17
|
+
|
|
18
|
+
export interface BenchSideTimes {
|
|
19
|
+
readonly medianMs: number;
|
|
20
|
+
|
|
21
|
+
readonly spreadMs: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// One benchmark at one level, with its times on the base and on the head, or null on a side that
|
|
25
|
+
// lacks it.
|
|
26
|
+
export interface BenchComparisonRow {
|
|
27
|
+
// The bench file, relative to the root of its side, so both sides give the same path.
|
|
28
|
+
readonly file: string;
|
|
29
|
+
|
|
30
|
+
readonly name: string;
|
|
31
|
+
|
|
32
|
+
readonly concurrency: number;
|
|
33
|
+
|
|
34
|
+
readonly base: BenchSideTimes | null;
|
|
35
|
+
|
|
36
|
+
readonly head: BenchSideTimes | null;
|
|
37
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { join, resolve } from 'node:path';
|
|
2
|
+
|
|
3
|
+
// The folder sits in the git folder, which git never lists as untracked, and in the common one, so
|
|
4
|
+
// a run from a linked worktree shares one place with the main checkout.
|
|
5
|
+
export function buildBenchFolderPath(repoRoot: string, gitCommonDir: string): string {
|
|
6
|
+
return join(resolve(repoRoot, gitCommonDir), 'rig-bench');
|
|
7
|
+
}
|
|
@@ -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) =>
|
|
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
|
|
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/cli.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
|
+
import { mkdir, mkdtemp } from 'node:fs/promises';
|
|
3
4
|
import { availableParallelism, totalmem } from 'node:os';
|
|
4
5
|
import { join } from 'node:path';
|
|
5
6
|
import { readOptionalText } from '@zgeoff/std';
|
|
7
|
+
import { processRuntime } from './browser/process-runtime.ts';
|
|
8
|
+
import { removePath } from './browser/remove-path.ts';
|
|
6
9
|
import { wireBrowserLaneHooks } from './browser/wire-browser-lane-hooks.ts';
|
|
10
|
+
import { createBenchWorkFolder } from './create-bench-work-folder.ts';
|
|
7
11
|
import { initFiles } from './init-files.ts';
|
|
8
12
|
import { probeWorkspaceRepo } from './probe-workspace-repo.ts';
|
|
13
|
+
import { readCommandOutput } from './read-command-output.ts';
|
|
14
|
+
import type { CommandOutput, ReadCommandOptions } from './read-command-output.ts';
|
|
15
|
+
import { readGitCommonDir } from './read-git-common-dir.ts';
|
|
9
16
|
import { readRigConfig } from './read-rig-config.ts';
|
|
10
17
|
import { readTrackedFiles } from './read-tracked-files.ts';
|
|
11
18
|
import { readWorkerCount } from './read-worker-count.ts';
|
|
@@ -37,6 +44,13 @@ const output = {
|
|
|
37
44
|
// `bun run` starts a package script in the folder of the package that defines it.
|
|
38
45
|
const repoRoot = process.cwd();
|
|
39
46
|
|
|
47
|
+
function readOutput(
|
|
48
|
+
command: readonly string[],
|
|
49
|
+
options: ReadCommandOptions,
|
|
50
|
+
): Promise<CommandOutput> {
|
|
51
|
+
return readCommandOutput(command, options, processRuntime);
|
|
52
|
+
}
|
|
53
|
+
|
|
40
54
|
try {
|
|
41
55
|
process.exitCode = await runCLI(
|
|
42
56
|
process.argv.slice(2),
|
|
@@ -66,6 +80,23 @@ try {
|
|
|
66
80
|
readText: readOptionalText,
|
|
67
81
|
}),
|
|
68
82
|
importModule: (path) => import(path),
|
|
83
|
+
createWorkFolder: (root) =>
|
|
84
|
+
createBenchWorkFolder(root, {
|
|
85
|
+
readGitCommonDir: (gitRoot) =>
|
|
86
|
+
readGitCommonDir(gitRoot, process.env, { readCommandOutput: readOutput }),
|
|
87
|
+
createFolder: async (path) => {
|
|
88
|
+
await mkdir(path, { recursive: true });
|
|
89
|
+
},
|
|
90
|
+
createTempFolder: (prefix) => mkdtemp(prefix),
|
|
91
|
+
}),
|
|
92
|
+
readText: async (path) => {
|
|
93
|
+
const text = await readOptionalText(path);
|
|
94
|
+
|
|
95
|
+
return text ?? null;
|
|
96
|
+
},
|
|
97
|
+
probeFolder: (path) => Promise.resolve(existsSync(path)),
|
|
98
|
+
removeFolder: removePath,
|
|
99
|
+
readCommandOutput: readOutput,
|
|
69
100
|
runCommand,
|
|
70
101
|
wireBrowserLaneHooks,
|
|
71
102
|
},
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { buildBenchFolderPath } from './build-bench-folder-path.ts';
|
|
3
|
+
|
|
4
|
+
export interface BenchWorkFolderDeps {
|
|
5
|
+
// Returns what `git rev-parse --git-common-dir` prints in the repo root.
|
|
6
|
+
readonly readGitCommonDir: (repoRoot: string) => Promise<string>;
|
|
7
|
+
|
|
8
|
+
// Makes the folder and its parents, and keeps a folder that exists.
|
|
9
|
+
readonly createFolder: (path: string) => Promise<void>;
|
|
10
|
+
|
|
11
|
+
// Makes a new folder whose path starts with the prefix, and returns its path.
|
|
12
|
+
readonly createTempFolder: (prefix: string) => Promise<string>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function createBenchWorkFolder(
|
|
16
|
+
repoRoot: string,
|
|
17
|
+
deps: BenchWorkFolderDeps,
|
|
18
|
+
): Promise<string> {
|
|
19
|
+
const gitCommonDir = await deps.readGitCommonDir(repoRoot);
|
|
20
|
+
|
|
21
|
+
const benchFolder = buildBenchFolderPath(repoRoot, gitCommonDir);
|
|
22
|
+
|
|
23
|
+
await deps.createFolder(benchFolder);
|
|
24
|
+
|
|
25
|
+
return deps.createTempFolder(join(benchFolder, 'run-'));
|
|
26
|
+
}
|
package/src/define-rig.ts
CHANGED
|
@@ -48,7 +48,12 @@ export function defineRig(declaration: RigDeclaration): RigConfig {
|
|
|
48
48
|
]),
|
|
49
49
|
);
|
|
50
50
|
|
|
51
|
-
return {
|
|
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,9 @@
|
|
|
1
|
+
// The parser throws one error that holds every reason the command line is refused, so each reason
|
|
2
|
+
// prints on a line of its own.
|
|
3
|
+
export function formatParseError(error: unknown): string {
|
|
4
|
+
if (error instanceof AggregateError) {
|
|
5
|
+
return error.errors.map((reason) => formatParseError(reason)).join('\n');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return error instanceof Error ? error.message : String(error);
|
|
9
|
+
}
|
|
@@ -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
|
@@ -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
|
+
}
|
package/src/read-cli-args.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { cli } from 'gunshi/bone';
|
|
2
2
|
import { define } from 'gunshi/definition';
|
|
3
|
+
import { formatParseError } from './format-parse-error.ts';
|
|
3
4
|
|
|
4
5
|
export interface CLIArgs {
|
|
5
6
|
readonly command: string;
|
|
@@ -55,16 +56,6 @@ function dropFirstSeparator(args: readonly string[]): readonly string[] {
|
|
|
55
56
|
return separator === -1 ? args : args.toSpliced(separator, 1);
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
// The parser throws one error that holds every reason the command line is refused, so each reason
|
|
59
|
-
// prints on a line of its own.
|
|
60
|
-
function formatParseError(error: unknown): string {
|
|
61
|
-
if (error instanceof AggregateError) {
|
|
62
|
-
return error.errors.map((reason) => formatParseError(reason)).join('\n');
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return error instanceof Error ? error.message : String(error);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
59
|
const forwardedArgSchema = { isolate: { type: 'boolean' } } as const;
|
|
69
60
|
|
|
70
61
|
// The forwarded arguments hold `bun test` options that rig never declares, so this parse is not
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ProcessRuntime, SpawnOptions } from './browser/process-runtime.ts';
|
|
2
|
+
|
|
3
|
+
export interface CommandOutput {
|
|
4
|
+
readonly exitCode: number;
|
|
5
|
+
|
|
6
|
+
readonly stdout: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type ReadCommandOptions = Omit<SpawnOptions, 'stdout'>;
|
|
10
|
+
|
|
11
|
+
export type ReadCommandOutput = (
|
|
12
|
+
command: readonly string[],
|
|
13
|
+
options: ReadCommandOptions,
|
|
14
|
+
) => Promise<CommandOutput>;
|
|
15
|
+
|
|
16
|
+
// The command's stderr goes to rig's own, so a failure prints git's reason.
|
|
17
|
+
export async function readCommandOutput(
|
|
18
|
+
command: readonly string[],
|
|
19
|
+
options: ReadCommandOptions,
|
|
20
|
+
runtime: Pick<ProcessRuntime, 'spawn'>,
|
|
21
|
+
): Promise<CommandOutput> {
|
|
22
|
+
const listing = runtime.spawn(command, { ...options, stdout: 'pipe' });
|
|
23
|
+
|
|
24
|
+
const [exitCode, stdout] = await Promise.all([
|
|
25
|
+
listing.exited,
|
|
26
|
+
new Response(listing.stdout).text(),
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
return { exitCode, stdout };
|
|
30
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { SpawnOptions } from './browser/process-runtime.ts';
|
|
2
|
+
import type { ReadCommandOutput } from './read-command-output.ts';
|
|
3
|
+
|
|
4
|
+
export interface GitCommonDirDeps {
|
|
5
|
+
readonly readCommandOutput: ReadCommandOutput;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// Returns git's own answer: in the main checkout it is relative to the folder git runs in, such as
|
|
9
|
+
// ../../.git from a package folder, and in a linked worktree it is absolute.
|
|
10
|
+
export async function readGitCommonDir(
|
|
11
|
+
repoRoot: string,
|
|
12
|
+
environment: SpawnOptions['environment'],
|
|
13
|
+
deps: GitCommonDirDeps,
|
|
14
|
+
): Promise<string> {
|
|
15
|
+
const output = await deps.readCommandOutput(['git', 'rev-parse', '--git-common-dir'], {
|
|
16
|
+
cwd: repoRoot,
|
|
17
|
+
environment,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
if (output.exitCode !== 0) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
`git rev-parse --git-common-dir failed in ${repoRoot} with exit code ${output.exitCode}`,
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return output.stdout.trim();
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { SpawnOptions } from './browser/process-runtime.ts';
|
|
2
|
+
import type { ReadCommandOutput } from './read-command-output.ts';
|
|
3
|
+
|
|
4
|
+
export interface GitPrefixDeps {
|
|
5
|
+
readonly readCommandOutput: ReadCommandOutput;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// Returns the folder's path inside its repo as git prints it, with a trailing slash, or an empty
|
|
9
|
+
// string at the repo's top level.
|
|
10
|
+
export async function readGitPrefix(
|
|
11
|
+
folder: string,
|
|
12
|
+
environment: SpawnOptions['environment'],
|
|
13
|
+
deps: GitPrefixDeps,
|
|
14
|
+
): Promise<string> {
|
|
15
|
+
const output = await deps.readCommandOutput(['git', 'rev-parse', '--show-prefix'], {
|
|
16
|
+
cwd: folder,
|
|
17
|
+
environment,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
if (output.exitCode !== 0) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
`git rev-parse --show-prefix failed in ${folder} with exit code ${output.exitCode}`,
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return output.stdout.trim();
|
|
27
|
+
}
|
|
@@ -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-bench-file.ts
CHANGED
|
@@ -1,25 +1,35 @@
|
|
|
1
|
+
import { appendFile } from 'node:fs/promises';
|
|
2
|
+
import { formatBenchReport } from './bench/format-bench-report.ts';
|
|
1
3
|
import { formatBenchmarkResult } from './bench/format-benchmark-result.ts';
|
|
2
4
|
import { parseBenchDefinition } from './bench/parse-bench-definition.ts';
|
|
5
|
+
import { readBenchFileArgs } from './bench/read-bench-file-args.ts';
|
|
3
6
|
import { runBenchmark } from './bench/run-benchmark.ts';
|
|
4
7
|
|
|
5
|
-
// `rig bench` runs this once per bench file, in the environment the benchmarks get
|
|
6
|
-
|
|
8
|
+
// `rig bench` runs this once per bench file, in the environment the benchmarks get, and judges the
|
|
9
|
+
// budget from the report this appends, so a bench that ran exits 0 whatever its median.
|
|
10
|
+
const args = await readBenchFileArgs(process.argv.slice(2));
|
|
7
11
|
|
|
8
|
-
|
|
12
|
+
if (args.kind === 'refused') {
|
|
13
|
+
process.stderr.write(`rig bench: ${args.reason}\n`);
|
|
9
14
|
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
process.exitCode = 2;
|
|
16
|
+
} else {
|
|
17
|
+
const loaded: unknown = await import(args.file);
|
|
12
18
|
|
|
13
|
-
const
|
|
19
|
+
const defaultExport: unknown =
|
|
20
|
+
typeof loaded === 'object' && loaded !== null ? Reflect.get(loaded, 'default') : null;
|
|
14
21
|
|
|
15
|
-
|
|
16
|
-
process.stderr.write(`rig bench: ${file}: ${parsed.reason}\n`);
|
|
22
|
+
const parsed = parseBenchDefinition(defaultExport);
|
|
17
23
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
if (parsed.kind === 'refused') {
|
|
25
|
+
process.stderr.write(`rig bench: ${args.file}: ${parsed.reason}\n`);
|
|
26
|
+
|
|
27
|
+
process.exitCode = 2;
|
|
28
|
+
} else {
|
|
29
|
+
const results = await runBenchmark(parsed.definition, () => performance.now());
|
|
21
30
|
|
|
22
|
-
|
|
31
|
+
process.stdout.write(formatBenchmarkResult(parsed.definition, results));
|
|
23
32
|
|
|
24
|
-
|
|
33
|
+
await appendFile(args.reportPath, formatBenchReport(args.file, parsed.definition, results));
|
|
34
|
+
}
|
|
25
35
|
}
|