@zgeoff/rig 0.0.5 → 0.1.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 +16 -4
- package/dist/bench/define-bench.d.ts +24 -0
- package/dist/bench/format-benchmark-result.d.ts +3 -0
- package/dist/bench/parse-bench-definition.d.ts +9 -0
- package/dist/bench/pick-median.d.ts +1 -0
- package/dist/bench/run-benchmark.d.ts +7 -0
- package/dist/bench.d.ts +2 -0
- package/dist/browser/collect-descendant-pids.d.ts +2 -0
- package/dist/browser/pick-descendant-stop-step.d.ts +15 -0
- package/dist/browser/pick-listing-read-step.d.ts +10 -0
- package/dist/browser/probe-process.d.ts +1 -1
- package/dist/browser/read-process-table.d.ts +1 -0
- package/dist/browser/stop-descendant-processes.d.ts +10 -0
- package/dist/build-init-scripts.d.ts +1 -1
- package/dist/build-program-environment.d.ts +3 -0
- package/dist/build-program-lane-hooks.d.ts +3 -0
- package/dist/build-test-selection.d.ts +1 -0
- package/dist/collect-bench-files.d.ts +1 -0
- package/dist/collect-eval-files.d.ts +1 -0
- package/dist/collect-unprogrammed-e2e-dirs.d.ts +2 -0
- package/dist/e2e.d.ts +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +83 -3
- package/dist/is-command-name.d.ts +1 -1
- package/dist/pick-e2e-dirs.d.ts +1 -1
- package/dist/probe-workspace-repo.d.ts +1 -0
- package/dist/programs/resolve-program.d.ts +12 -0
- package/dist/programs/resolve-repo-root.d.ts +1 -0
- package/dist/read-cli-args.d.ts +1 -0
- package/dist/run-bench-file.d.ts +1 -0
- package/dist/run-bench.d.ts +10 -0
- package/dist/run-cli.d.ts +3 -1
- package/dist/run-eval.d.ts +8 -0
- package/dist/run-init.d.ts +1 -0
- package/dist/run-lane.d.ts +4 -5
- package/dist/run-program-builds.d.ts +7 -0
- package/dist/run-unit-tests.d.ts +1 -0
- package/dist/test-run-args.d.ts +1 -0
- package/dist/types.d.ts +13 -0
- package/package.json +17 -5
- package/src/bench/define-bench.ts +78 -0
- package/src/bench/format-benchmark-result.ts +11 -0
- package/src/bench/parse-bench-definition.ts +57 -0
- package/src/bench/pick-median.ts +10 -0
- package/src/bench/run-benchmark.ts +38 -0
- package/src/bench.ts +2 -0
- package/src/browser/browser-preload.ts +18 -4
- package/src/browser/collect-descendant-pids.ts +22 -0
- package/src/browser/make-browser-lane-hooks.ts +2 -3
- package/src/browser/pick-descendant-stop-step.ts +40 -0
- package/src/browser/pick-listing-read-step.ts +17 -0
- package/src/browser/probe-host-process.ts +1 -3
- package/src/browser/probe-process.ts +1 -1
- package/src/browser/read-process-table.ts +10 -6
- package/src/browser/stop-descendant-processes.ts +90 -0
- package/src/build-init-scripts.ts +17 -3
- package/src/build-program-environment.ts +20 -0
- package/src/build-program-lane-hooks.ts +24 -0
- package/src/build-test-selection.ts +8 -7
- package/src/build-unit-command.ts +2 -1
- package/src/cli.ts +4 -0
- package/src/collect-bench-files.ts +23 -0
- package/src/collect-eval-files.ts +5 -0
- package/src/collect-unprogrammed-e2e-dirs.ts +21 -0
- package/src/define-rig.ts +65 -2
- package/src/e2e.ts +2 -0
- package/src/index.ts +2 -0
- package/src/is-command-name.ts +1 -1
- package/src/make-repo-lane-hooks.ts +2 -0
- package/src/parse-rig-config.ts +64 -2
- package/src/pick-e2e-dirs.ts +8 -5
- package/src/probe-workspace-repo.ts +15 -0
- package/src/programs/resolve-program.ts +92 -0
- package/src/programs/resolve-repo-root.ts +18 -0
- package/src/read-cli-args.ts +30 -1
- package/src/run-bench-file.ts +25 -0
- package/src/run-bench.ts +132 -0
- package/src/run-cli.ts +16 -1
- package/src/run-eval.ts +74 -0
- package/src/run-init.ts +6 -1
- package/src/run-lane.ts +39 -10
- package/src/run-program-builds.ts +35 -0
- package/src/run-unit-tests.ts +4 -1
- package/src/run-unit.ts +1 -0
- package/src/standard-lanes.ts +1 -1
- package/src/test-run-args.ts +3 -0
- package/src/types.ts +30 -0
package/src/run-eval.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { basename, dirname } from 'node:path';
|
|
2
|
+
import { collectEvalFiles } from './collect-eval-files.ts';
|
|
3
|
+
import type { CommandOptions } from './run-command.ts';
|
|
4
|
+
import type { RigOutput, RigRun } from './types.ts';
|
|
5
|
+
|
|
6
|
+
export interface EvalDeps {
|
|
7
|
+
readonly output: RigOutput;
|
|
8
|
+
|
|
9
|
+
readonly readTrackedFiles: (repoRoot: string) => Promise<readonly string[]>;
|
|
10
|
+
|
|
11
|
+
readonly runCommand: (command: readonly string[], options: CommandOptions) => Promise<number>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Runs each evaluation script with bun from the repo root, one after another, and fails when any
|
|
15
|
+
// one fails.
|
|
16
|
+
export async function runEval(
|
|
17
|
+
args: readonly string[],
|
|
18
|
+
run: RigRun,
|
|
19
|
+
deps: EvalDeps,
|
|
20
|
+
): Promise<number> {
|
|
21
|
+
if (args.length > 1) {
|
|
22
|
+
deps.output.err('rig eval: takes at most one evaluation name\n');
|
|
23
|
+
|
|
24
|
+
return 2;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const trackedFiles = await deps.readTrackedFiles(run.repoRoot);
|
|
28
|
+
|
|
29
|
+
const evalFiles = collectEvalFiles(trackedFiles);
|
|
30
|
+
const [name] = args;
|
|
31
|
+
|
|
32
|
+
const files =
|
|
33
|
+
name === undefined ? evalFiles : evalFiles.filter((file) => toEvalName(file) === name);
|
|
34
|
+
|
|
35
|
+
if (files.length === 0) {
|
|
36
|
+
return reportNoEval(name, evalFiles, deps);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let exitCode = 0;
|
|
40
|
+
|
|
41
|
+
for (const file of files) {
|
|
42
|
+
const fileExitCode = await deps.runCommand(['bun', file], {
|
|
43
|
+
cwd: run.repoRoot,
|
|
44
|
+
environment: run.environment,
|
|
45
|
+
signal: run.signal,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
exitCode = fileExitCode === 0 ? exitCode : 1;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return run.signal.aborted ? 1 : exitCode;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function toEvalName(file: string): string {
|
|
55
|
+
return basename(dirname(file));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function reportNoEval(
|
|
59
|
+
name: string | undefined,
|
|
60
|
+
evalFiles: readonly string[],
|
|
61
|
+
deps: EvalDeps,
|
|
62
|
+
): number {
|
|
63
|
+
if (name === undefined) {
|
|
64
|
+
deps.output.out('rig: the repo has no evaluations\n');
|
|
65
|
+
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const names = evalFiles.map((file) => toEvalName(file)).join(', ');
|
|
70
|
+
|
|
71
|
+
deps.output.err(`rig eval: no evaluation named "${name}"; the evaluations are ${names}\n`);
|
|
72
|
+
|
|
73
|
+
return 1;
|
|
74
|
+
}
|
package/src/run-init.ts
CHANGED
|
@@ -5,6 +5,8 @@ import type { InitFiles } from './init-files.ts';
|
|
|
5
5
|
import type { RigConfig, RigOutput } from './types.ts';
|
|
6
6
|
|
|
7
7
|
export interface InitDeps {
|
|
8
|
+
readonly probeWorkspaceRepo: (repoRoot: string) => Promise<boolean>;
|
|
9
|
+
|
|
8
10
|
readonly readTrackedFiles: (repoRoot: string) => Promise<readonly string[]>;
|
|
9
11
|
|
|
10
12
|
readonly initFiles: InitFiles;
|
|
@@ -36,7 +38,10 @@ export async function runInit(
|
|
|
36
38
|
const trackedFiles = await deps.readTrackedFiles(repoRoot);
|
|
37
39
|
|
|
38
40
|
const oldScripts = readScripts(manifest['scripts']);
|
|
39
|
-
|
|
41
|
+
|
|
42
|
+
const isWorkspaceRepo = await deps.probeWorkspaceRepo(repoRoot);
|
|
43
|
+
|
|
44
|
+
const newScripts = buildInitScripts(oldScripts, config, trackedFiles, isWorkspaceRepo);
|
|
40
45
|
|
|
41
46
|
if (JSON.stringify(oldScripts) !== JSON.stringify(newScripts)) {
|
|
42
47
|
await deps.initFiles.writeText(
|
package/src/run-lane.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { match } from 'ts-pattern';
|
|
2
2
|
import { pickExitCodeAfterTests } from './browser/pick-exit-code-after-tests.ts';
|
|
3
3
|
import type { BrowserLaneWiring } from './browser/wire-browser-lane-hooks.ts';
|
|
4
|
+
import { buildProgramLaneHooks } from './build-program-lane-hooks.ts';
|
|
4
5
|
import type { TestSelection } from './build-test-selection.ts';
|
|
5
6
|
import { buildTestSelection } from './build-test-selection.ts';
|
|
7
|
+
import { collectUnprogrammedE2EDirs } from './collect-unprogrammed-e2e-dirs.ts';
|
|
6
8
|
import { formatNoMatchMessage } from './format-no-match-message.ts';
|
|
7
9
|
import { formatNoTestsMessage } from './format-no-tests-message.ts';
|
|
8
10
|
import type { LaneHooks } from './lane-hooks.ts';
|
|
@@ -10,21 +12,20 @@ import { makeRepoLaneHooks } from './make-repo-lane-hooks.ts';
|
|
|
10
12
|
import { parseTestArgs } from './parse-test-args.ts';
|
|
11
13
|
import { pickE2EDirs } from './pick-e2e-dirs.ts';
|
|
12
14
|
import { pickLaneSelection } from './pick-lane-selection.ts';
|
|
13
|
-
import type { CommandOptions } from './run-command.ts';
|
|
14
15
|
import { runLaneHooks } from './run-lane-hooks.ts';
|
|
15
|
-
import type {
|
|
16
|
+
import type { ProgramBuildDeps } from './run-program-builds.ts';
|
|
17
|
+
import { runProgramBuilds } from './run-program-builds.ts';
|
|
18
|
+
import type { ResolvedLane, RigConfig, RigRun } from './types.ts';
|
|
16
19
|
|
|
17
|
-
export interface LaneDeps {
|
|
20
|
+
export interface LaneDeps extends ProgramBuildDeps {
|
|
18
21
|
readonly dietScript: string;
|
|
19
22
|
|
|
20
|
-
readonly
|
|
23
|
+
readonly probeWorkspaceRepo: (repoRoot: string) => Promise<boolean>;
|
|
21
24
|
|
|
22
25
|
readonly readTrackedFiles: (repoRoot: string) => Promise<readonly string[]>;
|
|
23
26
|
|
|
24
27
|
readonly importModule: (path: string) => Promise<unknown>;
|
|
25
28
|
|
|
26
|
-
readonly runCommand: (command: readonly string[], options: CommandOptions) => Promise<number>;
|
|
27
|
-
|
|
28
29
|
readonly wireBrowserLaneHooks: (wiring: BrowserLaneWiring) => Promise<LaneHooks>;
|
|
29
30
|
}
|
|
30
31
|
|
|
@@ -42,11 +43,13 @@ export async function runLane(request: LaneRequest, run: RigRun, deps: LaneDeps)
|
|
|
42
43
|
const lane = request.lane;
|
|
43
44
|
|
|
44
45
|
const trackedFiles = await deps.readTrackedFiles(run.repoRoot);
|
|
46
|
+
const isWorkspaceRepo = await deps.probeWorkspaceRepo(run.repoRoot);
|
|
45
47
|
|
|
46
48
|
const selection = buildTestSelection({
|
|
47
49
|
config: request.config,
|
|
48
50
|
lane,
|
|
49
51
|
repoRoot: run.repoRoot,
|
|
52
|
+
isWorkspaceRepo,
|
|
50
53
|
trackedFiles,
|
|
51
54
|
args: parseTestArgs(request.extraArgs),
|
|
52
55
|
});
|
|
@@ -63,10 +66,32 @@ export async function runLane(request: LaneRequest, run: RigRun, deps: LaneDeps)
|
|
|
63
66
|
return 0;
|
|
64
67
|
}
|
|
65
68
|
|
|
66
|
-
const
|
|
69
|
+
const e2eDirs = pickE2EDirs(trackedFiles, isWorkspaceRepo);
|
|
70
|
+
const testArgs = pickLaneTestArgs(request.config, lane, selection, e2eDirs);
|
|
71
|
+
const programs = lane.name === 'e2e' ? request.config.programs : {};
|
|
72
|
+
|
|
73
|
+
if (lane.name === 'e2e') {
|
|
74
|
+
const unprogrammed = collectUnprogrammedE2EDirs(e2eDirs, programs);
|
|
75
|
+
|
|
76
|
+
if (unprogrammed.length > 0) {
|
|
77
|
+
deps.output.err(formatUnprogrammedMessage(unprogrammed));
|
|
78
|
+
|
|
79
|
+
return 2;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const buildExitCode = await runProgramBuilds(programs, run, deps);
|
|
84
|
+
|
|
85
|
+
if (buildExitCode !== 0) {
|
|
86
|
+
return buildExitCode;
|
|
87
|
+
}
|
|
67
88
|
|
|
68
89
|
const hooks = await wireLaneHooks(lane, run, deps);
|
|
69
|
-
|
|
90
|
+
|
|
91
|
+
const exitCode = await runLaneHooks(
|
|
92
|
+
testArgs,
|
|
93
|
+
buildProgramLaneHooks(hooks, run.repoRoot, programs),
|
|
94
|
+
);
|
|
70
95
|
|
|
71
96
|
// A signal that arrives while the stop hook cleans up still fails the run.
|
|
72
97
|
return pickExitCodeAfterTests(exitCode, run.signal.aborted);
|
|
@@ -76,7 +101,7 @@ function pickLaneTestArgs(
|
|
|
76
101
|
config: RigConfig,
|
|
77
102
|
lane: ResolvedLane,
|
|
78
103
|
selection: Extract<TestSelection, { kind: 'files' | 'lane' }>,
|
|
79
|
-
|
|
104
|
+
e2eDirs: readonly string[],
|
|
80
105
|
): readonly string[] {
|
|
81
106
|
const timeoutArg = `--timeout=${lane.limitMs}`;
|
|
82
107
|
|
|
@@ -84,7 +109,7 @@ function pickLaneTestArgs(
|
|
|
84
109
|
.with({ kind: 'files' }, (files) => [timeoutArg, ...files.files, ...files.flags])
|
|
85
110
|
.with({ kind: 'lane' }, (laneRun) => [
|
|
86
111
|
timeoutArg,
|
|
87
|
-
...pickLaneSelection(lane,
|
|
112
|
+
...pickLaneSelection(lane, e2eDirs),
|
|
88
113
|
...pickOtherLaneIgnoreArgs(config, lane),
|
|
89
114
|
...laneRun.flags,
|
|
90
115
|
])
|
|
@@ -107,6 +132,10 @@ function pickOtherLaneIgnoreArgs(config: RigConfig, lane: ResolvedLane): readonl
|
|
|
107
132
|
);
|
|
108
133
|
}
|
|
109
134
|
|
|
135
|
+
function formatUnprogrammedMessage(directories: readonly string[]): string {
|
|
136
|
+
return `rig: ${directories.join(', ')} has no program to run: declare the program in rig.config.ts programs, with the package it belongs to\n`;
|
|
137
|
+
}
|
|
138
|
+
|
|
110
139
|
function wireLaneHooks(lane: ResolvedLane, run: RigRun, deps: LaneDeps): Promise<LaneHooks> {
|
|
111
140
|
if (lane.name === 'browser') {
|
|
112
141
|
return deps.wireBrowserLaneHooks({
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import type { CommandOptions } from './run-command.ts';
|
|
3
|
+
import type { ProgramDeclaration, RigOutput, RigRun } from './types.ts';
|
|
4
|
+
|
|
5
|
+
export interface ProgramBuildDeps {
|
|
6
|
+
readonly output: RigOutput;
|
|
7
|
+
|
|
8
|
+
readonly runCommand: (command: readonly string[], options: CommandOptions) => Promise<number>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Builds each program once, in its package folder, and stops at the first failure. The build's own
|
|
12
|
+
// output goes to the terminal as it runs.
|
|
13
|
+
export async function runProgramBuilds(
|
|
14
|
+
programs: Readonly<Record<string, ProgramDeclaration>>,
|
|
15
|
+
run: RigRun,
|
|
16
|
+
deps: ProgramBuildDeps,
|
|
17
|
+
): Promise<number> {
|
|
18
|
+
for (const [name, program] of Object.entries(programs)) {
|
|
19
|
+
const exitCode = await deps.runCommand(['bash', '-c', program.build], {
|
|
20
|
+
cwd: join(run.repoRoot, program.package),
|
|
21
|
+
environment: run.environment,
|
|
22
|
+
signal: run.signal,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
if (exitCode !== 0) {
|
|
26
|
+
deps.output.err(
|
|
27
|
+
`rig: the build of program "${name}" failed with exit code ${exitCode}: ${program.build}\n`,
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
return exitCode;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
package/src/run-unit-tests.ts
CHANGED
|
@@ -13,6 +13,8 @@ export interface UnitRequest {
|
|
|
13
13
|
export interface UnitRunDeps {
|
|
14
14
|
readonly dietScript: string;
|
|
15
15
|
|
|
16
|
+
readonly probeWorkspaceRepo: (repoRoot: string) => Promise<boolean>;
|
|
17
|
+
|
|
16
18
|
readonly readTrackedFiles: (repoRoot: string) => Promise<readonly string[]>;
|
|
17
19
|
|
|
18
20
|
readonly runCommand: (command: readonly string[], options: CommandOptions) => Promise<number>;
|
|
@@ -27,8 +29,9 @@ export async function runUnitTests(
|
|
|
27
29
|
deps: UnitRunDeps,
|
|
28
30
|
): Promise<number> {
|
|
29
31
|
const trackedFiles = await deps.readTrackedFiles(run.repoRoot);
|
|
32
|
+
const isWorkspaceRepo = await deps.probeWorkspaceRepo(run.repoRoot);
|
|
30
33
|
|
|
31
|
-
const e2eDirs = pickE2EDirs(trackedFiles);
|
|
34
|
+
const e2eDirs = pickE2EDirs(trackedFiles, isWorkspaceRepo);
|
|
32
35
|
const memory = config.lanes.find((lane) => lane.name === 'unit')?.memory ?? null;
|
|
33
36
|
|
|
34
37
|
return deps.runCommand(
|
package/src/run-unit.ts
CHANGED
package/src/standard-lanes.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface StandardLane {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
// The limits are the per-test timeouts of the Lanes table in the testing skill. Every lane but
|
|
14
|
-
// unit runs one
|
|
14
|
+
// unit runs its files one at a time, because it needs a real system that two files cannot share.
|
|
15
15
|
export const standardLanes: readonly StandardLane[] = [
|
|
16
16
|
{ name: 'unit', suffix: null, limitMs: 5000, parallel: 'workers' },
|
|
17
17
|
{ name: 'e2e', suffix: null, limitMs: 15_000, parallel: 1 },
|
package/src/types.ts
CHANGED
|
@@ -14,8 +14,33 @@ export interface LaneDeclaration {
|
|
|
14
14
|
readonly stop?: string;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
// A program that the e2e tests run: the entry file, the command that builds it, and the file the
|
|
18
|
+
// build leaves.
|
|
19
|
+
export interface ProgramDeclaration {
|
|
20
|
+
// The package folder, relative to the repo root.
|
|
21
|
+
readonly package: string;
|
|
22
|
+
|
|
23
|
+
// The entry file, relative to the package.
|
|
24
|
+
readonly source: string;
|
|
25
|
+
|
|
26
|
+
// A shell command that rig runs from the package folder.
|
|
27
|
+
readonly build: string;
|
|
28
|
+
|
|
29
|
+
// The built file, relative to the package.
|
|
30
|
+
readonly artifact: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface BenchDeclaration {
|
|
34
|
+
// The lane whose start and stop hooks surround the benchmarks.
|
|
35
|
+
readonly lane?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
17
38
|
export interface RigDeclaration {
|
|
18
39
|
readonly lanes?: Readonly<Record<string, LaneDeclaration>>;
|
|
40
|
+
|
|
41
|
+
readonly programs?: Readonly<Record<string, ProgramDeclaration>>;
|
|
42
|
+
|
|
43
|
+
readonly bench?: BenchDeclaration;
|
|
19
44
|
}
|
|
20
45
|
|
|
21
46
|
export type LaneParallelism = 'workers' | number;
|
|
@@ -40,6 +65,11 @@ export interface ResolvedLane {
|
|
|
40
65
|
|
|
41
66
|
export interface RigConfig {
|
|
42
67
|
readonly lanes: readonly ResolvedLane[];
|
|
68
|
+
|
|
69
|
+
readonly programs: Readonly<Record<string, ProgramDeclaration>>;
|
|
70
|
+
|
|
71
|
+
// The lane whose hooks surround the benchmarks, or null.
|
|
72
|
+
readonly benchLane: string | null;
|
|
43
73
|
}
|
|
44
74
|
|
|
45
75
|
export interface LaneContext {
|