@zgeoff/rig 0.0.1 → 0.0.2

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.
Files changed (143) hide show
  1. package/README.md +87 -3
  2. package/dist/browser/browser-preload.d.ts +1 -0
  3. package/dist/browser/build-browser-run.d.ts +9 -0
  4. package/dist/browser/build-lane-environments.d.ts +8 -0
  5. package/dist/browser/build-recorded-command.d.ts +1 -0
  6. package/dist/browser/find-browser-run.d.ts +4 -0
  7. package/dist/browser/find-private-dir-problem.d.ts +2 -0
  8. package/dist/browser/has-browser-build-script.d.ts +1 -0
  9. package/dist/browser/has-error-code.d.ts +1 -0
  10. package/dist/browser/is-zombie-state.d.ts +1 -0
  11. package/dist/browser/lane-files.d.ts +13 -0
  12. package/dist/browser/make-browser-lane-hooks.d.ts +22 -0
  13. package/dist/browser/pick-chrome-dirs.d.ts +7 -0
  14. package/dist/browser/pick-exit-code-after-tests.d.ts +1 -0
  15. package/dist/browser/pick-step-after-build.d.ts +7 -0
  16. package/dist/browser/pick-stop-step.d.ts +17 -0
  17. package/dist/browser/probe-host-process.d.ts +1 -0
  18. package/dist/browser/probe-process.d.ts +6 -0
  19. package/dist/browser/probe-run.d.ts +9 -0
  20. package/dist/browser/process-group-still-running-error.d.ts +4 -0
  21. package/dist/browser/process-group-stop-error.d.ts +4 -0
  22. package/dist/browser/process-groups.d.ts +5 -0
  23. package/dist/browser/process-runtime.d.ts +15 -0
  24. package/dist/browser/read-dir-names.d.ts +1 -0
  25. package/dist/browser/read-process-table.d.ts +6 -0
  26. package/dist/browser/remove-exited-run-dirs.d.ts +2 -0
  27. package/dist/browser/remove-path.d.ts +1 -0
  28. package/dist/browser/run-in-page.d.ts +23 -0
  29. package/dist/browser/should-keep-run-folders.d.ts +1 -0
  30. package/dist/browser/start-browser.d.ts +9 -0
  31. package/dist/browser/start-process-group.d.ts +17 -0
  32. package/dist/browser/wire-browser-lane-hooks.d.ts +12 -0
  33. package/dist/build-diet-command.d.ts +1 -0
  34. package/dist/build-init-scripts.d.ts +3 -0
  35. package/dist/build-test-selection.d.ts +23 -0
  36. package/dist/build-unit-command.d.ts +2 -0
  37. package/dist/cli.d.ts +2 -0
  38. package/dist/define-rig.d.ts +2 -0
  39. package/dist/find-timeout-arg.d.ts +1 -0
  40. package/dist/format-no-match-message.d.ts +1 -0
  41. package/dist/format-no-tests-message.d.ts +1 -0
  42. package/dist/index.d.ts +6 -0
  43. package/dist/index.js +255 -0
  44. package/dist/init-files.d.ts +6 -0
  45. package/dist/is-command-name.d.ts +3 -0
  46. package/dist/lane-hooks.d.ts +13 -0
  47. package/dist/make-repo-lane-hooks.d.ts +12 -0
  48. package/dist/parse-duration.d.ts +1 -0
  49. package/dist/parse-lane-hook.d.ts +3 -0
  50. package/dist/parse-lane-start.d.ts +2 -0
  51. package/dist/parse-rig-config.d.ts +9 -0
  52. package/dist/parse-test-args.d.ts +5 -0
  53. package/dist/pick-e2e-dirs.d.ts +1 -0
  54. package/dist/pick-lane-selection.d.ts +2 -0
  55. package/dist/read-cli-args.d.ts +5 -0
  56. package/dist/read-memory-budget.d.ts +8 -0
  57. package/dist/read-rig-config.d.ts +6 -0
  58. package/dist/read-tracked-files.d.ts +1 -0
  59. package/dist/read-worker-count.d.ts +13 -0
  60. package/dist/resolve-diet-script.d.ts +1 -0
  61. package/dist/resolve-related-tests.d.ts +6 -0
  62. package/dist/run-cli.d.ts +9 -0
  63. package/dist/run-command.d.ts +6 -0
  64. package/dist/run-init.d.ts +8 -0
  65. package/dist/run-lane-hooks.d.ts +2 -0
  66. package/dist/run-lane.d.ts +18 -0
  67. package/dist/run-related-tests.d.ts +10 -0
  68. package/dist/run-unit-tests.d.ts +12 -0
  69. package/dist/run-unit.d.ts +8 -0
  70. package/dist/standard-lanes.d.ts +8 -0
  71. package/dist/system-clock.d.ts +5 -0
  72. package/dist/types.d.ts +42 -0
  73. package/package.json +41 -3
  74. package/src/browser/browser-preload.ts +36 -0
  75. package/src/browser/build-browser-run.ts +32 -0
  76. package/src/browser/build-lane-environments.ts +33 -0
  77. package/src/browser/build-recorded-command.ts +12 -0
  78. package/src/browser/find-browser-run.ts +15 -0
  79. package/src/browser/find-private-dir-problem.ts +21 -0
  80. package/src/browser/has-browser-build-script.ts +7 -0
  81. package/src/browser/has-error-code.ts +3 -0
  82. package/src/browser/is-zombie-state.ts +4 -0
  83. package/src/browser/lane-files.ts +56 -0
  84. package/src/browser/make-browser-lane-hooks.ts +228 -0
  85. package/src/browser/pick-chrome-dirs.ts +34 -0
  86. package/src/browser/pick-exit-code-after-tests.ts +5 -0
  87. package/src/browser/pick-step-after-build.ts +20 -0
  88. package/src/browser/pick-stop-step.ts +28 -0
  89. package/src/browser/probe-host-process.ts +11 -0
  90. package/src/browser/probe-process.ts +35 -0
  91. package/src/browser/probe-run.ts +38 -0
  92. package/src/browser/process-group-still-running-error.ts +9 -0
  93. package/src/browser/process-group-stop-error.ts +10 -0
  94. package/src/browser/process-groups.ts +45 -0
  95. package/src/browser/process-runtime.ts +40 -0
  96. package/src/browser/read-dir-names.ts +15 -0
  97. package/src/browser/read-process-table.ts +35 -0
  98. package/src/browser/remove-exited-run-dirs.ts +21 -0
  99. package/src/browser/remove-path.ts +5 -0
  100. package/src/browser/run-in-page.ts +103 -0
  101. package/src/browser/should-keep-run-folders.ts +7 -0
  102. package/src/browser/start-browser.ts +40 -0
  103. package/src/browser/start-process-group.ts +168 -0
  104. package/src/browser/wire-browser-lane-hooks.ts +88 -0
  105. package/src/build-diet-command.ts +11 -0
  106. package/src/build-init-scripts.ts +40 -0
  107. package/src/build-test-selection.ts +124 -0
  108. package/src/build-unit-command.ts +22 -0
  109. package/src/cli.ts +73 -0
  110. package/src/define-rig.ts +195 -0
  111. package/src/find-timeout-arg.ts +3 -0
  112. package/src/format-no-match-message.ts +3 -0
  113. package/src/format-no-tests-message.ts +3 -0
  114. package/src/index.ts +14 -0
  115. package/src/init-files.ts +15 -0
  116. package/src/is-command-name.ts +9 -0
  117. package/src/lane-hooks.ts +15 -0
  118. package/src/make-repo-lane-hooks.ts +70 -0
  119. package/src/parse-duration.ts +14 -0
  120. package/src/parse-lane-hook.ts +20 -0
  121. package/src/parse-lane-start.ts +30 -0
  122. package/src/parse-rig-config.ts +96 -0
  123. package/src/parse-test-args.ts +14 -0
  124. package/src/pick-e2e-dirs.ts +25 -0
  125. package/src/pick-lane-selection.ts +14 -0
  126. package/src/read-cli-args.ts +57 -0
  127. package/src/read-memory-budget.ts +65 -0
  128. package/src/read-rig-config.ts +32 -0
  129. package/src/read-tracked-files.ts +20 -0
  130. package/src/read-worker-count.ts +40 -0
  131. package/src/resolve-diet-script.ts +7 -0
  132. package/src/resolve-related-tests.ts +52 -0
  133. package/src/run-cli.ts +68 -0
  134. package/src/run-command.ts +36 -0
  135. package/src/run-init.ts +71 -0
  136. package/src/run-lane-hooks.ts +49 -0
  137. package/src/run-lane.ts +138 -0
  138. package/src/run-related-tests.ts +113 -0
  139. package/src/run-unit-tests.ts +42 -0
  140. package/src/run-unit.ts +68 -0
  141. package/src/standard-lanes.ts +23 -0
  142. package/src/system-clock.ts +10 -0
  143. package/src/types.ts +75 -0
@@ -0,0 +1,138 @@
1
+ import { match } from 'ts-pattern';
2
+ import { pickExitCodeAfterTests } from './browser/pick-exit-code-after-tests.ts';
3
+ import type { BrowserLaneWiring } from './browser/wire-browser-lane-hooks.ts';
4
+ import type { TestSelection } from './build-test-selection.ts';
5
+ import { buildTestSelection } from './build-test-selection.ts';
6
+ import { formatNoMatchMessage } from './format-no-match-message.ts';
7
+ import { formatNoTestsMessage } from './format-no-tests-message.ts';
8
+ import type { LaneHooks } from './lane-hooks.ts';
9
+ import { makeRepoLaneHooks } from './make-repo-lane-hooks.ts';
10
+ import { parseTestArgs } from './parse-test-args.ts';
11
+ import { pickE2EDirs } from './pick-e2e-dirs.ts';
12
+ import { pickLaneSelection } from './pick-lane-selection.ts';
13
+ import type { CommandOptions } from './run-command.ts';
14
+ import { runLaneHooks } from './run-lane-hooks.ts';
15
+ import type { ResolvedLane, RigConfig, RigOutput, RigRun } from './types.ts';
16
+
17
+ export interface LaneDeps {
18
+ readonly dietScript: string;
19
+
20
+ readonly output: RigOutput;
21
+
22
+ readonly readTrackedFiles: (repoRoot: string) => Promise<readonly string[]>;
23
+
24
+ readonly importModule: (path: string) => Promise<unknown>;
25
+
26
+ readonly runCommand: (command: readonly string[], options: CommandOptions) => Promise<number>;
27
+
28
+ readonly wireBrowserLaneHooks: (wiring: BrowserLaneWiring) => Promise<LaneHooks>;
29
+ }
30
+
31
+ export interface LaneRequest {
32
+ readonly config: RigConfig;
33
+
34
+ readonly lane: ResolvedLane;
35
+
36
+ readonly extraArgs: readonly string[];
37
+ }
38
+
39
+ // A lane runs its start hook, its tests under diet, and its stop hook, which runs even when the
40
+ // start or the tests fail.
41
+ export async function runLane(request: LaneRequest, run: RigRun, deps: LaneDeps): Promise<number> {
42
+ const lane = request.lane;
43
+
44
+ const trackedFiles = await deps.readTrackedFiles(run.repoRoot);
45
+
46
+ const selection = buildTestSelection({
47
+ config: request.config,
48
+ lane,
49
+ repoRoot: run.repoRoot,
50
+ trackedFiles,
51
+ args: parseTestArgs(request.extraArgs),
52
+ });
53
+
54
+ if (selection.kind === 'none') {
55
+ deps.output.err(formatNoMatchMessage(lane.name, selection.paths));
56
+
57
+ return 1;
58
+ }
59
+
60
+ if (selection.kind === 'empty') {
61
+ deps.output.out(formatNoTestsMessage(lane.name));
62
+
63
+ return 0;
64
+ }
65
+
66
+ const testArgs = pickLaneTestArgs(request.config, lane, selection, trackedFiles);
67
+
68
+ const hooks = await wireLaneHooks(lane, run, deps);
69
+ const exitCode = await runLaneHooks(testArgs, hooks);
70
+
71
+ // A signal that arrives while the stop hook cleans up still fails the run.
72
+ return pickExitCodeAfterTests(exitCode, run.signal.aborted);
73
+ }
74
+
75
+ function pickLaneTestArgs(
76
+ config: RigConfig,
77
+ lane: ResolvedLane,
78
+ selection: Extract<TestSelection, { kind: 'files' | 'lane' }>,
79
+ trackedFiles: readonly string[],
80
+ ): readonly string[] {
81
+ const timeoutArg = `--timeout=${lane.limitMs}`;
82
+
83
+ return match(selection)
84
+ .with({ kind: 'files' }, (files) => [timeoutArg, ...files.files, ...files.flags])
85
+ .with({ kind: 'lane' }, (laneRun) => [
86
+ timeoutArg,
87
+ ...pickLaneSelection(lane, pickE2EDirs(trackedFiles)),
88
+ ...pickOtherLaneIgnoreArgs(config, lane),
89
+ ...laneRun.flags,
90
+ ])
91
+ .exhaustive();
92
+ }
93
+
94
+ // A folder selection takes every test file under it, so the e2e lane leaves out the files that
95
+ // belong to a lane with a suffix.
96
+ function pickOtherLaneIgnoreArgs(config: RigConfig, lane: ResolvedLane): readonly string[] {
97
+ if (lane.suffix !== null) {
98
+ return [];
99
+ }
100
+
101
+ return config.lanes.flatMap((other) =>
102
+ other.suffix === null
103
+ ? []
104
+ : [`**/*${other.suffix}.test.ts`, `**/*${other.suffix}.test.tsx`].map(
105
+ (pattern) => `--path-ignore-patterns=${pattern}`,
106
+ ),
107
+ );
108
+ }
109
+
110
+ function wireLaneHooks(lane: ResolvedLane, run: RigRun, deps: LaneDeps): Promise<LaneHooks> {
111
+ if (lane.name === 'browser') {
112
+ return deps.wireBrowserLaneHooks({
113
+ repoRoot: run.repoRoot,
114
+ runID: run.runID,
115
+ memory: lane.memory,
116
+ dietScript: deps.dietScript,
117
+ environment: run.environment,
118
+ signal: run.signal,
119
+ });
120
+ }
121
+
122
+ if (lane.parallel === 'workers') {
123
+ throw new Error(
124
+ `the lane ${lane.name} runs in the worker count of the unit lane, which only unit may`,
125
+ );
126
+ }
127
+
128
+ return Promise.resolve(
129
+ makeRepoLaneHooks({
130
+ context: { repoRoot: run.repoRoot, lane, runID: run.runID, environment: run.environment },
131
+ dietScript: deps.dietScript,
132
+ parallel: lane.parallel,
133
+ signal: run.signal,
134
+ importModule: deps.importModule,
135
+ runCommand: deps.runCommand,
136
+ }),
137
+ );
138
+ }
@@ -0,0 +1,113 @@
1
+ import { basename } from 'node:path';
2
+ import { parseArgs } from 'node:util';
3
+ import type { WorkerCount } from './read-worker-count.ts';
4
+ import { resolveRelatedTests } from './resolve-related-tests.ts';
5
+ import type { RelatedTestSources } from './resolve-related-tests.ts';
6
+ import type { UnitRunDeps } from './run-unit-tests.ts';
7
+ import { runUnitTests } from './run-unit-tests.ts';
8
+ import type { RigConfig, RigOutput, RigRun } from './types.ts';
9
+
10
+ // A host with one worker runs each file slower than CI, and a test that passes there must not fail
11
+ // the push.
12
+ const slowHostTestTimeoutMs = 15_000;
13
+
14
+ export interface RelatedTestDeps extends UnitRunDeps {
15
+ readonly sources: Readonly<RelatedTestSources>;
16
+
17
+ readonly readWorkerCount: () => Promise<WorkerCount>;
18
+
19
+ readonly output: RigOutput;
20
+ }
21
+
22
+ // The related run is the unit lane on the tests beside the changed files, in this process.
23
+ export async function runRelatedTests(
24
+ args: readonly string[],
25
+ config: RigConfig,
26
+ run: RigRun,
27
+ deps: Readonly<RelatedTestDeps>,
28
+ ): Promise<number> {
29
+ const options = parseRelatedTestArgs(args);
30
+
31
+ if (options.kind === 'invalid') {
32
+ deps.output.err(`rig related: ${options.message}\n`);
33
+
34
+ return 2;
35
+ }
36
+
37
+ const plan = buildRelatedTestPlan(
38
+ options.paths,
39
+ resolveRelatedTests(options.paths, config, deps.sources),
40
+ );
41
+
42
+ if (plan.kind === 'skip') {
43
+ deps.output.out(`rig related: ${plan.message}\n`);
44
+
45
+ return 0;
46
+ }
47
+
48
+ const workers = await deps.readWorkerCount();
49
+
50
+ if (workers.kind === 'invalid') {
51
+ deps.output.err(`rig related: ${workers.message}\n`);
52
+
53
+ return 2;
54
+ }
55
+
56
+ const timeoutArgs = workers.count === 1 ? [`--timeout=${slowHostTestTimeoutMs}`] : [];
57
+
58
+ // bun test reads a bare argument as a name filter; the ./ makes it a path.
59
+ const testArgs = [...timeoutArgs, ...plan.tests.map((path) => `./${path}`)];
60
+
61
+ return runUnitTests(config, { workerCount: workers.count, extraArgs: testArgs }, run, deps);
62
+ }
63
+
64
+ type RelatedTestArgs =
65
+ | { readonly kind: 'valid'; readonly paths: readonly string[] }
66
+ | { readonly kind: 'invalid'; readonly message: string };
67
+
68
+ // parseArgs throws on an option it does not declare, which the caller reports as a refused input.
69
+ function parseRelatedTestArgs(args: readonly string[]): RelatedTestArgs {
70
+ try {
71
+ return {
72
+ kind: 'valid',
73
+ paths: parseArgs({ args: [...args], options: {}, allowPositionals: true }).positionals,
74
+ };
75
+ } catch (error) {
76
+ return { kind: 'invalid', message: error instanceof Error ? error.message : String(error) };
77
+ }
78
+ }
79
+
80
+ type RelatedTestPlan =
81
+ | { readonly kind: 'run'; readonly tests: readonly string[] }
82
+ | { readonly kind: 'skip'; readonly message: string };
83
+
84
+ const maxTestFiles = 50;
85
+
86
+ function buildRelatedTestPlan(paths: readonly string[], tests: readonly string[]): RelatedTestPlan {
87
+ const shared = paths.find((path) => isSharedTestInput(path));
88
+
89
+ if (shared !== undefined) {
90
+ return {
91
+ kind: 'skip',
92
+ message: `skipped, because the branch changes ${shared}, a shared test helper or config; CI runs the full suite`,
93
+ };
94
+ }
95
+
96
+ if (tests.length > maxTestFiles) {
97
+ return {
98
+ kind: 'skip',
99
+ message: `skipped, because the branch has ${tests.length} related unit test files, over the cap of ${maxTestFiles}; CI runs the full suite`,
100
+ };
101
+ }
102
+
103
+ if (tests.length === 0) {
104
+ return { kind: 'skip', message: 'no related tests' };
105
+ }
106
+
107
+ return { kind: 'run', tests };
108
+ }
109
+
110
+ // A shared helper or a bunfig.toml reaches tests beyond the siblings of the files it changes.
111
+ function isSharedTestInput(path: string): boolean {
112
+ return /(?:^|\/)test-utils\//u.test(path) || basename(path) === 'bunfig.toml';
113
+ }
@@ -0,0 +1,42 @@
1
+ import { buildDietCommand } from './build-diet-command.ts';
2
+ import { buildUnitCommand } from './build-unit-command.ts';
3
+ import { pickE2EDirs } from './pick-e2e-dirs.ts';
4
+ import type { CommandOptions } from './run-command.ts';
5
+ import type { RigConfig, RigRun } from './types.ts';
6
+
7
+ export interface UnitRequest {
8
+ readonly workerCount: number;
9
+
10
+ readonly extraArgs: readonly string[];
11
+ }
12
+
13
+ export interface UnitRunDeps {
14
+ readonly dietScript: string;
15
+
16
+ readonly readTrackedFiles: (repoRoot: string) => Promise<readonly string[]>;
17
+
18
+ readonly runCommand: (command: readonly string[], options: CommandOptions) => Promise<number>;
19
+ }
20
+
21
+ // The unit lane's command is built from the lane table, so a lane that the table lists never
22
+ // reaches the unit run.
23
+ export async function runUnitTests(
24
+ config: RigConfig,
25
+ request: UnitRequest,
26
+ run: RigRun,
27
+ deps: UnitRunDeps,
28
+ ): Promise<number> {
29
+ const trackedFiles = await deps.readTrackedFiles(run.repoRoot);
30
+
31
+ const e2eDirs = pickE2EDirs(trackedFiles);
32
+ const memory = config.lanes.find((lane) => lane.name === 'unit')?.memory ?? null;
33
+
34
+ return deps.runCommand(
35
+ buildDietCommand(
36
+ deps.dietScript,
37
+ memory,
38
+ buildUnitCommand(config, e2eDirs, request.workerCount, request.extraArgs),
39
+ ),
40
+ { cwd: run.repoRoot, environment: run.environment, signal: run.signal },
41
+ );
42
+ }
@@ -0,0 +1,68 @@
1
+ import { match } from 'ts-pattern';
2
+ import { buildTestSelection } from './build-test-selection.ts';
3
+ import { formatNoMatchMessage } from './format-no-match-message.ts';
4
+ import { formatNoTestsMessage } from './format-no-tests-message.ts';
5
+ import { parseTestArgs } from './parse-test-args.ts';
6
+ import type { WorkerCount } from './read-worker-count.ts';
7
+ import type { UnitRunDeps } from './run-unit-tests.ts';
8
+ import { runUnitTests } from './run-unit-tests.ts';
9
+ import type { RigConfig, RigOutput, RigRun } from './types.ts';
10
+
11
+ export interface UnitDeps extends UnitRunDeps {
12
+ readonly readWorkerCount: () => Promise<WorkerCount>;
13
+
14
+ readonly output: RigOutput;
15
+ }
16
+
17
+ export async function runUnit(
18
+ config: RigConfig,
19
+ extraArgs: readonly string[],
20
+ run: RigRun,
21
+ deps: UnitDeps,
22
+ ): Promise<number> {
23
+ const workers = await deps.readWorkerCount();
24
+
25
+ if (workers.kind === 'invalid') {
26
+ deps.output.err(`rig: ${workers.message}\n`);
27
+
28
+ return 2;
29
+ }
30
+
31
+ const unitLane = config.lanes.find((lane) => lane.name === 'unit');
32
+
33
+ if (unitLane === undefined) {
34
+ throw new Error('the rig config holds no unit lane');
35
+ }
36
+
37
+ const selection = buildTestSelection({
38
+ config,
39
+ lane: unitLane,
40
+ repoRoot: run.repoRoot,
41
+ trackedFiles: await deps.readTrackedFiles(run.repoRoot),
42
+ args: parseTestArgs(extraArgs),
43
+ });
44
+
45
+ return match(selection)
46
+ .with({ kind: 'none' }, (none) => {
47
+ deps.output.err(formatNoMatchMessage('unit', none.paths));
48
+
49
+ return 1;
50
+ })
51
+ .with({ kind: 'empty' }, () => {
52
+ deps.output.out(formatNoTestsMessage('unit'));
53
+
54
+ return 0;
55
+ })
56
+ .with({ kind: 'files' }, (files) =>
57
+ runUnitTests(
58
+ config,
59
+ { workerCount: workers.count, extraArgs: [...files.files, ...files.flags] },
60
+ run,
61
+ deps,
62
+ ),
63
+ )
64
+ .with({ kind: 'lane' }, (laneRun) =>
65
+ runUnitTests(config, { workerCount: workers.count, extraArgs: laneRun.flags }, run, deps),
66
+ )
67
+ .exhaustive();
68
+ }
@@ -0,0 +1,23 @@
1
+ import type { LaneParallelism } from './types.ts';
2
+
3
+ export interface StandardLane {
4
+ readonly name: string;
5
+
6
+ readonly suffix: string | null;
7
+
8
+ readonly limitMs: number;
9
+
10
+ readonly parallel: LaneParallelism;
11
+ }
12
+
13
+ // The limits are the per-test timeouts of the Lanes table in the testing skill. Every lane but
14
+ // unit runs one process per file, because it needs a real system that two files cannot share.
15
+ export const standardLanes: readonly StandardLane[] = [
16
+ { name: 'unit', suffix: null, limitMs: 5000, parallel: 'workers' },
17
+ { name: 'e2e', suffix: null, limitMs: 15_000, parallel: 1 },
18
+ { name: 'browser', suffix: '.browser', limitMs: 10_000, parallel: 1 },
19
+ { name: 'docker', suffix: '.docker', limitMs: 15_000, parallel: 1 },
20
+ { name: 'host', suffix: '.host', limitMs: 15_000, parallel: 1 },
21
+ { name: 'agent-sdk', suffix: '.agent-sdk', limitMs: 5000, parallel: 1 },
22
+ { name: 'model-api', suffix: '.model-api', limitMs: 120_000, parallel: 1 },
23
+ ];
@@ -0,0 +1,10 @@
1
+ export interface Clock {
2
+ readonly now: () => number;
3
+
4
+ readonly sleep: (durationMs: number) => Promise<void>;
5
+ }
6
+
7
+ export const systemClock: Clock = {
8
+ now: () => Date.now(),
9
+ sleep: (durationMs) => Bun.sleep(durationMs),
10
+ };
package/src/types.ts ADDED
@@ -0,0 +1,75 @@
1
+ export interface LaneDeclaration {
2
+ // The file suffix that selects the lane's tests, such as `.kiln`; defaults to `.<name>`.
3
+ readonly suffix?: string;
4
+
5
+ // A duration such as `'15s'` or `'1500ms'`; a lane that is not built in must declare one.
6
+ readonly limit?: string;
7
+
8
+ // A diet budget such as `'8G'`.
9
+ readonly memory?: string;
10
+
11
+ // Paths relative to the repo root of modules whose default export is the hook.
12
+ readonly start?: string;
13
+
14
+ readonly stop?: string;
15
+ }
16
+
17
+ export interface RigDeclaration {
18
+ readonly lanes?: Readonly<Record<string, LaneDeclaration>>;
19
+ }
20
+
21
+ export type LaneParallelism = 'workers' | number;
22
+
23
+ export interface ResolvedLane {
24
+ readonly name: string;
25
+
26
+ // Null for the unit lane and the e2e lane, which select their tests by directory or by leaving
27
+ // the other lanes out.
28
+ readonly suffix: string | null;
29
+
30
+ readonly limitMs: number;
31
+
32
+ readonly parallel: LaneParallelism;
33
+
34
+ readonly memory: string | null;
35
+
36
+ readonly start: string | null;
37
+
38
+ readonly stop: string | null;
39
+ }
40
+
41
+ export interface RigConfig {
42
+ readonly lanes: readonly ResolvedLane[];
43
+ }
44
+
45
+ export interface LaneContext {
46
+ readonly repoRoot: string;
47
+
48
+ readonly lane: ResolvedLane;
49
+
50
+ readonly runID: string;
51
+
52
+ readonly environment: Readonly<Record<string, string | undefined>>;
53
+ }
54
+
55
+ export interface LaneStart {
56
+ // Added to the environment of the lane's test process.
57
+ readonly environment?: Readonly<Record<string, string>>;
58
+ }
59
+
60
+ // The process a command runs in: its repo, environment and abort signal.
61
+ export interface RigRun {
62
+ readonly repoRoot: string;
63
+
64
+ readonly environment: Readonly<Record<string, string | undefined>>;
65
+
66
+ readonly signal: AbortSignal;
67
+
68
+ readonly runID: string;
69
+ }
70
+
71
+ export interface RigOutput {
72
+ readonly out: (text: string) => void;
73
+
74
+ readonly err: (text: string) => void;
75
+ }