@smoothbricks/nx-plugin 0.4.28 → 0.4.30
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 +277 -89
- package/dist/bin/smoo-nx-test-clocks.d.ts +3 -0
- package/dist/bin/smoo-nx-test-clocks.d.ts.map +1 -0
- package/dist/bin/smoo-nx-test-clocks.js +28 -0
- package/dist/bounded-test-policy.d.ts +8 -8
- package/dist/bounded-test-policy.d.ts.map +1 -1
- package/dist/bounded-test-policy.js +18 -30
- package/dist/cargo-closure-input.d.ts +23 -0
- package/dist/cargo-closure-input.d.ts.map +1 -1
- package/dist/cargo-closure-input.js +41 -9
- package/dist/cargo-source-hash.d.ts.map +1 -1
- package/dist/cargo-source-hash.js +42 -19
- package/dist/ensure-built-receipt.d.ts +40 -6
- package/dist/ensure-built-receipt.d.ts.map +1 -1
- package/dist/ensure-built-receipt.js +297 -159
- package/dist/ensure-built-witness.d.ts +65 -4
- package/dist/ensure-built-witness.d.ts.map +1 -1
- package/dist/ensure-built-witness.js +2237 -23
- package/dist/ensure-built.d.ts +99 -1
- package/dist/ensure-built.d.ts.map +1 -1
- package/dist/ensure-built.js +45 -56
- package/dist/executors/bounded-exec/cpu-pool.d.ts +22 -7
- package/dist/executors/bounded-exec/cpu-pool.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-pool.js +51 -22
- package/dist/executors/bounded-exec/executor.d.ts +12 -3
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +174 -51
- package/dist/executors/bounded-exec/no-space.d.ts +8 -0
- package/dist/executors/bounded-exec/no-space.d.ts.map +1 -0
- package/dist/executors/bounded-exec/no-space.js +31 -0
- package/dist/executors/bounded-exec/ram-temp.d.ts +20 -11
- package/dist/executors/bounded-exec/ram-temp.d.ts.map +1 -1
- package/dist/executors/bounded-exec/ram-temp.js +42 -17
- package/dist/executors/bounded-exec/verdict.d.ts +34 -4
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.js +54 -3
- package/dist/generators/bun-test-tracing/generator.js +2 -2
- package/dist/graph-input-contract.d.ts +102 -0
- package/dist/graph-input-contract.d.ts.map +1 -0
- package/dist/graph-input-contract.js +637 -0
- package/dist/index.d.ts +12 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -3
- package/dist/managed-files/ci-workflow.d.ts.map +1 -1
- package/dist/managed-files/ci-workflow.js +5 -2
- package/dist/managed-files/publish-workflow.d.ts +11 -1
- package/dist/managed-files/publish-workflow.d.ts.map +1 -1
- package/dist/owned-installation.d.ts +14 -0
- package/dist/owned-installation.d.ts.map +1 -0
- package/dist/owned-installation.js +324 -0
- package/dist/producer-receipts.d.ts +19 -0
- package/dist/producer-receipts.d.ts.map +1 -0
- package/dist/producer-receipts.js +926 -0
- package/dist/test-backstop.d.ts +9 -0
- package/dist/test-backstop.d.ts.map +1 -0
- package/dist/test-backstop.js +10 -0
- package/dist/test-clock-policy.d.ts +30 -0
- package/dist/test-clock-policy.d.ts.map +1 -0
- package/dist/test-clock-policy.js +686 -0
- package/dist/testing.d.ts +8 -0
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +66 -1
- package/managed/raw/patches/nx@23.2.1.patch +328 -50
- package/managed/raw/tooling/direnv/developer-links.ts +148 -29
- package/managed/raw/tooling/direnv/devenv.smoo.nix +7 -7
- package/managed/raw/tooling/direnv/github-actions-bootstrap.sh +14 -5
- package/managed/raw/tooling/direnv/linked-snapshots.ts +206 -40
- package/managed/raw/tooling/direnv/repo-path +15 -2
- package/managed/raw/tooling/direnv/setup-environment.ts +179 -115
- package/managed/templates/github/actions/cache-node-modules/action.yml +9 -0
- package/managed/templates/github/actions/setup-devenv/action.yml +63 -7
- package/nextest.toml +1 -1
- package/package.json +25 -9
- package/src/__tests__/cargo-closure-fixture.ts +113 -0
- package/src/__tests__/counted-cargo.ts +8 -25
- package/src/__tests__/directory-change.ts +27 -0
- package/src/__tests__/fixture-nx-env.ts +7 -0
- package/src/__tests__/owned-installation.ts +14 -0
- package/src/__tests__/past-tick.ts +12 -0
- package/src/bin/smoo-nx-bound-failures.test.ts +1 -1
- package/src/bin/smoo-nx-test-clocks.ts +29 -0
- package/src/bounded-test-policy.test.ts +36 -22
- package/src/bounded-test-policy.ts +18 -32
- package/src/bun-bootstrap.test.ts +1 -1
- package/src/cargo-closure-input.property.test.ts +50 -0
- package/src/cargo-closure-input.test.ts +73 -121
- package/src/cargo-closure-input.ts +47 -8
- package/src/cargo-closure-key.test.ts +239 -0
- package/src/cargo-resolve-cache.test.ts +168 -31
- package/src/cargo-source-hash.test.ts +78 -3
- package/src/cargo-source-hash.ts +48 -30
- package/src/cross-check-policy.test.ts +2 -2
- package/src/ensure-built-receipt.test.ts +111 -16
- package/src/ensure-built-receipt.ts +294 -149
- package/src/ensure-built-witness.test.ts +306 -13
- package/src/ensure-built-witness.ts +255 -24
- package/src/ensure-built.test.ts +228 -102
- package/src/ensure-built.ts +127 -66
- package/src/executors/bounded-exec/cpu-pool.test.ts +134 -32
- package/src/executors/bounded-exec/cpu-pool.ts +64 -20
- package/src/executors/bounded-exec/cpu-tokens.test.ts +2 -2
- package/src/executors/bounded-exec/disk-lease.test.ts +47 -13
- package/src/executors/bounded-exec/executor-host.test.ts +74 -52
- package/src/executors/bounded-exec/executor.test.ts +343 -97
- package/src/executors/bounded-exec/executor.ts +192 -56
- package/src/executors/bounded-exec/hang-diagnostics.test.ts +14 -8
- package/src/executors/bounded-exec/no-space.ts +40 -0
- package/src/executors/bounded-exec/progress.test.ts +1 -1
- package/src/executors/bounded-exec/ram-temp-host.test.ts +51 -21
- package/src/executors/bounded-exec/ram-temp.test.ts +92 -16
- package/src/executors/bounded-exec/ram-temp.ts +49 -20
- package/src/executors/bounded-exec/verdict.test.ts +127 -22
- package/src/executors/bounded-exec/verdict.ts +78 -3
- package/src/generators/bounded-test-targets/generator.test.ts +1 -3
- package/src/generators/bun-test-tracing/generator.test.ts +2 -2
- package/src/generators/bun-test-tracing/generator.ts +2 -2
- package/src/graph-input-contract.test.ts +379 -0
- package/src/graph-input-contract.ts +627 -0
- package/src/index.test.ts +3 -3
- package/src/index.ts +24 -3
- package/src/linked-snapshots.nx.test.ts +112 -30
- package/src/managed-files/ci-workflow.ts +5 -2
- package/src/managed-files/publish-workflow.ts +12 -1
- package/src/managed-files/repo-path.test.ts +44 -1
- package/src/managed-files/setup-devenv-free-disk.test.ts +95 -0
- package/src/nextest-code-bound.test.ts +23 -17
- package/src/nextest-extraction.test.ts +114 -4
- package/src/nextest-partitions.test.ts +7 -1
- package/src/nx-cache-restore-mtime.test.ts +2 -2
- package/src/nx-daemon-claim.test.ts +10 -8
- package/src/nx-daemon-idle-cpu.test.ts +0 -1
- package/src/nx-daemon-idle-policy.test.ts +61 -1
- package/src/nx-daemon-ignore-files.test.ts +2 -2
- package/src/nx-daemon-validity.test.ts +36 -22
- package/src/nx-dot-input-policy.test.ts +5 -5
- package/src/nx-files-archive-racy.test.ts +1 -1
- package/src/nx-incomplete-run-summary.test.ts +1 -1
- package/src/nx-plugin-load-errors.test.ts +2 -2
- package/src/nx-project-graph-errors.test.ts +70 -0
- package/src/nx-skipped-task-exit.test.ts +2 -2
- package/src/nx-store-resolution.test.ts +7 -25
- package/src/nx-task-output-lease.test.ts +3 -3
- package/src/nx-use-local.test.ts +7 -5
- package/src/owned-installation.ts +174 -0
- package/src/producer-receipts.test.ts +164 -0
- package/src/producer-receipts.ts +636 -0
- package/src/runtime-input.test.ts +1 -1
- package/src/serial-group-wiring.test.ts +4 -4
- package/src/task-results.test.ts +18 -16
- package/src/test-backstop.ts +11 -0
- package/src/test-clock-policy.test.ts +338 -0
- package/src/test-clock-policy.ts +708 -0
- package/src/test-timings.test.ts +2 -2
- package/src/testing.test.ts +5 -5
- package/src/testing.ts +67 -1
- package/src/typecheck-test-policy.test.ts +1 -1
- package/src/typescript-resolution.test.ts +76 -0
- package/test-timings.json +8 -0
package/src/task-results.test.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { expect, it } from 'bun:test';
|
|
1
|
+
import { afterAll, expect, it } from 'bun:test';
|
|
2
2
|
import { mkdir, readdir, readFile, realpath, stat, symlink, writeFile } from 'node:fs/promises';
|
|
3
|
-
import {
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { join } from 'node:path';
|
|
5
4
|
import { fixtureNxEnv, withNxFixture } from './__tests__/fixture-nx-env.js';
|
|
5
|
+
import { testFileInstallation } from './__tests__/owned-installation.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* The plugin's `preTasksExecution`/`postTasksExecution` hooks, run by a real Nx subprocess in a
|
|
@@ -15,18 +15,20 @@ import { fixtureNxEnv, withNxFixture } from './__tests__/fixture-nx-env.js';
|
|
|
15
15
|
const RECEIPT_ENV = 'COWSHED_NX_TASK_RECEIPT_ID';
|
|
16
16
|
const RECEIPT = '0123456789abcdef0123456789abcdef';
|
|
17
17
|
const CHANGED_RECEIPT = 'fedcba9876543210fedcba9876543210';
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const nxEntry = join(repoRoot, 'node_modules', '.bin', 'nx');
|
|
18
|
+
/** The Nx CLI of a fixture workspace's own installation. */
|
|
19
|
+
const nxEntry = (workspace: string) => join(workspace, 'node_modules', '.bin', 'nx');
|
|
21
20
|
const HINTS = join('.nx', 'cache', '.cowshed-task-results');
|
|
22
21
|
|
|
22
|
+
/** The Nx and the plugin under test, one copy this file's fixtures share; none may write into it. */
|
|
23
|
+
const installation = testFileInstallation('task-results-installation-');
|
|
24
|
+
afterAll(() => installation.retire());
|
|
25
|
+
|
|
23
26
|
/** A fixture workspace: `app:build` caches its copy of `source.txt`; `app:fail` always exits 3. */
|
|
24
27
|
async function writeWorkspace(workspace: string): Promise<void> {
|
|
25
28
|
await mkdir(join(workspace, 'app'), { recursive: true });
|
|
26
29
|
const git = Bun.spawnSync(['git', 'init', '--quiet', workspace]);
|
|
27
30
|
expect(git.exitCode, git.stderr.toString()).toBe(0);
|
|
28
|
-
|
|
29
|
-
await symlink(join(repoRoot, 'node_modules'), join(workspace, 'node_modules'), 'dir');
|
|
31
|
+
await symlink(await installation.nodeModules(), join(workspace, 'node_modules'), 'dir');
|
|
30
32
|
await writeFile(
|
|
31
33
|
join(workspace, 'nx.json'),
|
|
32
34
|
JSON.stringify({ cacheDirectory: '.nx/cache', plugins: ['@smoothbricks/nx-plugin'] }),
|
|
@@ -53,7 +55,7 @@ async function writeWorkspace(workspace: string): Promise<void> {
|
|
|
53
55
|
|
|
54
56
|
/** Runs one target with `nx run` under `env`, returning its exit code, output and argv. */
|
|
55
57
|
async function nx(workspace: string, env: Record<string, string>, target: string) {
|
|
56
|
-
const argv = [process.execPath, nxEntry, 'run', target, '--outputStyle=static'];
|
|
58
|
+
const argv = [process.execPath, nxEntry(workspace), 'run', target, '--outputStyle=static'];
|
|
57
59
|
const child = Bun.spawn(argv, { cwd: workspace, env, stdout: 'pipe', stderr: 'pipe' });
|
|
58
60
|
const [exitCode, stdout, stderr] = await Promise.all([
|
|
59
61
|
child.exited,
|
|
@@ -112,7 +114,7 @@ it('records a task hint only under a controller receipt, and never on an ordinar
|
|
|
112
114
|
version: 1,
|
|
113
115
|
requestId: RECEIPT,
|
|
114
116
|
workspaceRoot: workspace,
|
|
115
|
-
run: { argv: [process.execPath, await realpath(nxEntry), ...hit.argv.slice(2)] },
|
|
117
|
+
run: { argv: [process.execPath, await realpath(nxEntry(workspace)), ...hit.argv.slice(2)] },
|
|
116
118
|
tasks: [{ task: { id: 'app:build', hash: expect.stringMatching(/^\d+$/) }, status: 'local-cache', code: 0 }],
|
|
117
119
|
});
|
|
118
120
|
|
|
@@ -129,13 +131,13 @@ it('records a task hint only under a controller receipt, and never on an ordinar
|
|
|
129
131
|
expect(await readHint(join(hints, CHANGED_RECEIPT))).toMatchObject({
|
|
130
132
|
version: 1,
|
|
131
133
|
requestId: CHANGED_RECEIPT,
|
|
132
|
-
run: { argv: [process.execPath, await realpath(nxEntry), ...changed.argv.slice(2)] },
|
|
134
|
+
run: { argv: [process.execPath, await realpath(nxEntry(workspace)), ...changed.argv.slice(2)] },
|
|
133
135
|
tasks: [{ task: { id: 'app:build', hash: expect.stringMatching(/^\d+$/) }, status: 'success', code: 0 }],
|
|
134
136
|
});
|
|
135
137
|
},
|
|
136
138
|
'.',
|
|
137
139
|
);
|
|
138
|
-
}
|
|
140
|
+
});
|
|
139
141
|
|
|
140
142
|
it('records a failed task as a failure under a receipt, never as a success', async () => {
|
|
141
143
|
await withNxFixture(
|
|
@@ -153,7 +155,7 @@ it('records a failed task as a failure under a receipt, never as a success', asy
|
|
|
153
155
|
},
|
|
154
156
|
'.',
|
|
155
157
|
);
|
|
156
|
-
}
|
|
158
|
+
});
|
|
157
159
|
|
|
158
160
|
it('records hints through a daemon-backed Nx only under a checked receipt', async () => {
|
|
159
161
|
await withNxFixture(
|
|
@@ -179,7 +181,7 @@ it('records hints through a daemon-backed Nx only under a checked receipt', asyn
|
|
|
179
181
|
version: 1,
|
|
180
182
|
requestId: RECEIPT,
|
|
181
183
|
workspaceRoot: workspace,
|
|
182
|
-
run: { argv: [checkedA.argv[0] ?? '', await realpath(nxEntry), ...checkedA.argv.slice(2)] },
|
|
184
|
+
run: { argv: [checkedA.argv[0] ?? '', await realpath(nxEntry(workspace)), ...checkedA.argv.slice(2)] },
|
|
183
185
|
tasks: [
|
|
184
186
|
{
|
|
185
187
|
task: { id: 'app:build', hash: expect.stringMatching(/^\d+$/) },
|
|
@@ -211,7 +213,7 @@ it('records hints through a daemon-backed Nx only under a checked receipt', asyn
|
|
|
211
213
|
version: 1,
|
|
212
214
|
requestId: CHANGED_RECEIPT,
|
|
213
215
|
workspaceRoot: workspace,
|
|
214
|
-
run: { argv: [checkedB.argv[0] ?? '', await realpath(nxEntry), ...checkedB.argv.slice(2)] },
|
|
216
|
+
run: { argv: [checkedB.argv[0] ?? '', await realpath(nxEntry(workspace)), ...checkedB.argv.slice(2)] },
|
|
215
217
|
tasks: [
|
|
216
218
|
{
|
|
217
219
|
task: { id: 'app:build', hash: expect.stringMatching(/^\d+$/) },
|
|
@@ -223,4 +225,4 @@ it('records hints through a daemon-backed Nx only under a checked receipt', asyn
|
|
|
223
225
|
},
|
|
224
226
|
'.',
|
|
225
227
|
);
|
|
226
|
-
}
|
|
228
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// A leaf module with no imports: tests' child processes on plain bun load testing.ts, which reads this bound, so
|
|
2
|
+
// nothing here may pull in a module that needs the typia transform (bounded-test-policy.ts does).
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A test target's one bound: the `idleTimeoutMs` with which no test may go unfinished, the hang backstop of
|
|
6
|
+
* specs/cowshed/08_testing.md. It is no wall-clock ceiling: a suite that keeps finishing tests runs as long as it
|
|
7
|
+
* needs. It is the longest any single test may run, so it stays above every slow-timeout class in the plugin's
|
|
8
|
+
* nextest.toml; a bun leg has no per-test deadline of its own (`BUN_TEST_TIMEOUT_FLAG`).
|
|
9
|
+
*/
|
|
10
|
+
export const BOUNDED_TEST_IDLE_TIMEOUT_MS = 180_000;
|
|
11
|
+
export const BOUNDED_TEST_KILL_AFTER_MS = 10_000;
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
import { type ClockOracleKind, findClockOracles, formatClockOracle, TEST_CLOCK_ORACLE } from './test-clock-policy.js';
|
|
7
|
+
import { diffScope } from './test-walk-policy.js';
|
|
8
|
+
|
|
9
|
+
const lines = (...source: string[]): string => `${source.join('\n')}\n`;
|
|
10
|
+
// Assembled so this file's own cases carry no runner flag a scan of it would read as a bound.
|
|
11
|
+
const flag = ['--time', 'out'].join('');
|
|
12
|
+
|
|
13
|
+
describe('test-clock-policy', () => {
|
|
14
|
+
// One walk: each planted site and each control is a step over one fixture directory, then the diff scope.
|
|
15
|
+
it('refuses runner and test-owned deadlines, elapsed-time asserts and clocked bounds, passes the controls, and scopes to changed cases', () => {
|
|
16
|
+
const root = mkdtempSync(join(tmpdir(), 'test-clock-policy-'));
|
|
17
|
+
const write = (file: string, source: string): void => {
|
|
18
|
+
mkdirSync(dirname(join(root, file)), { recursive: true });
|
|
19
|
+
writeFileSync(join(root, file), source);
|
|
20
|
+
};
|
|
21
|
+
const kinds = (file: string) => findClockOracles(root, [file]).map((oracle) => oracle.kind);
|
|
22
|
+
const git = (...args: string[]): string => {
|
|
23
|
+
const result = spawnSync(
|
|
24
|
+
'git',
|
|
25
|
+
['-c', 'user.name=Fixture', '-c', 'user.email=fixture@example.invalid', ...args],
|
|
26
|
+
{
|
|
27
|
+
cwd: root,
|
|
28
|
+
encoding: 'utf8',
|
|
29
|
+
env: { ...process.env, GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1' },
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
if (result.status !== 0) throw new Error(`git ${args.join(' ')}: ${result.stderr}`);
|
|
33
|
+
return result.stdout;
|
|
34
|
+
};
|
|
35
|
+
try {
|
|
36
|
+
const planted: readonly [ClockOracleKind, string, string][] = [
|
|
37
|
+
['runner-deadline', 'tests/a.test.ts', "test('slow', async () => { await child.exited; }, 60_000);"],
|
|
38
|
+
[
|
|
39
|
+
'runner-deadline',
|
|
40
|
+
'tests/a.test.ts',
|
|
41
|
+
"test('slow', async () => { await child.exited; }, { timeout: 60_000 });",
|
|
42
|
+
],
|
|
43
|
+
['runner-deadline', 'tests/a.test.ts', "test.each([1])('n %d', async (n) => { await run(n); }, 30_000);"],
|
|
44
|
+
['runner-deadline', 'tests/a.test.ts', 'setDefaultTimeout(60_000);'],
|
|
45
|
+
[
|
|
46
|
+
'clock-delta',
|
|
47
|
+
'tests/a.test.ts',
|
|
48
|
+
"test('fast', async () => { const started = Date.now(); await run(); expect(Date.now() - started).toBeLessThan(5_000); });",
|
|
49
|
+
],
|
|
50
|
+
[
|
|
51
|
+
'clock-delta',
|
|
52
|
+
'tests/a.test.ts',
|
|
53
|
+
"test('fast', () => { const t = performance.now(); work(); const elapsedMs = performance.now() - t; expect(elapsedMs < 1_000).toBe(true); });",
|
|
54
|
+
],
|
|
55
|
+
[
|
|
56
|
+
'clock-delta',
|
|
57
|
+
'tests/a.test.ts',
|
|
58
|
+
"test('deadline', () => { const deadline = Date.now() + 1_000; work(); expect(Date.now()).toBeLessThanOrEqual(deadline); });",
|
|
59
|
+
],
|
|
60
|
+
[
|
|
61
|
+
'clock-delta',
|
|
62
|
+
'tests/a.test.ts',
|
|
63
|
+
"test('close', () => { expect(Math.abs(stamp() - Date.now())).not.toBeGreaterThan(1); });",
|
|
64
|
+
],
|
|
65
|
+
[
|
|
66
|
+
'clock-delta',
|
|
67
|
+
'tests/quick.rs',
|
|
68
|
+
lines(
|
|
69
|
+
'#[test]',
|
|
70
|
+
'fn quick() {',
|
|
71
|
+
' let started = Instant::now();',
|
|
72
|
+
' work();',
|
|
73
|
+
' assert!(started.elapsed() < Duration::from_secs(10), "slow");',
|
|
74
|
+
'}',
|
|
75
|
+
),
|
|
76
|
+
],
|
|
77
|
+
[
|
|
78
|
+
'clock-delta',
|
|
79
|
+
'src/quick.rs',
|
|
80
|
+
lines(
|
|
81
|
+
'fn work() {}',
|
|
82
|
+
'#[cfg(test)]',
|
|
83
|
+
'mod tests {',
|
|
84
|
+
' #[test]',
|
|
85
|
+
' fn quick() {',
|
|
86
|
+
' let started = Instant::now();',
|
|
87
|
+
' let elapsed = started.elapsed();',
|
|
88
|
+
' assert!(Duration::from_millis(500) > elapsed);',
|
|
89
|
+
' }',
|
|
90
|
+
'}',
|
|
91
|
+
),
|
|
92
|
+
],
|
|
93
|
+
[
|
|
94
|
+
'clocked-bound',
|
|
95
|
+
'tests/a.test.ts',
|
|
96
|
+
`test('times out', async () => { const result = await runBoundedExec({ command: 'node -e "setTimeout(() => {}, 5000)"', timeoutMs: 50 }); expect(result.success).toBe(false); });`,
|
|
97
|
+
],
|
|
98
|
+
[
|
|
99
|
+
'clocked-bound',
|
|
100
|
+
'tests/a.test.ts',
|
|
101
|
+
lines(
|
|
102
|
+
"const SLOW = `test('slow', async () => { await new Promise((r) => setTimeout(r, 5000)); });`;",
|
|
103
|
+
`test('per-test bound', async () => { expect(await verdictOf('bun test ${flag}=100 ./slow.test.ts', { 'slow.test.ts': SLOW })).toEqual({ outcome: 'bound' }); });`,
|
|
104
|
+
),
|
|
105
|
+
],
|
|
106
|
+
[
|
|
107
|
+
'clocked-bound',
|
|
108
|
+
'tests/a.test.ts',
|
|
109
|
+
"test('idle', async () => { await run({ argv: ['sleep', '5'], idleTimeoutSeconds: 1 }); });",
|
|
110
|
+
],
|
|
111
|
+
[
|
|
112
|
+
'clocked-bound',
|
|
113
|
+
'tests/a.test.ts',
|
|
114
|
+
"test('short stand-in', async () => { const path = await fakeChild('exec sleep 30'); await openService({ path, lspQueryTimeoutMs: 1_000 }); });",
|
|
115
|
+
],
|
|
116
|
+
[
|
|
117
|
+
'clocked-bound',
|
|
118
|
+
'tests/a.test.ts',
|
|
119
|
+
`test('talking child under a progress bound', async () => { await verdictOf('node -e "setInterval(() => console.log(1), 10)"', { idleTimeoutMs: 100 }); });`,
|
|
120
|
+
],
|
|
121
|
+
[
|
|
122
|
+
'clocked-bound',
|
|
123
|
+
'tests/bound.rs',
|
|
124
|
+
lines(
|
|
125
|
+
'#[test]',
|
|
126
|
+
'fn bound() {',
|
|
127
|
+
' let outcome = run(Command::new("sleep").arg("5"), Options { timeout_ms: 50 });',
|
|
128
|
+
' assert!(outcome.timed_out);',
|
|
129
|
+
'}',
|
|
130
|
+
),
|
|
131
|
+
],
|
|
132
|
+
[
|
|
133
|
+
'test-deadline',
|
|
134
|
+
'tests/deadline.rs',
|
|
135
|
+
lines(
|
|
136
|
+
'#[test]',
|
|
137
|
+
'fn event() {',
|
|
138
|
+
' let (tx, rx) = channel();',
|
|
139
|
+
' spawn(tx);',
|
|
140
|
+
' rx.recv_timeout(Duration::from_secs(10)).expect("the event");',
|
|
141
|
+
'}',
|
|
142
|
+
),
|
|
143
|
+
],
|
|
144
|
+
[
|
|
145
|
+
'test-deadline',
|
|
146
|
+
'tests/deadline.rs',
|
|
147
|
+
lines(
|
|
148
|
+
'#[tokio::test]',
|
|
149
|
+
'async fn event() {',
|
|
150
|
+
' tokio::time::timeout(Duration::from_millis(500), served()).await.expect("served");',
|
|
151
|
+
'}',
|
|
152
|
+
),
|
|
153
|
+
],
|
|
154
|
+
];
|
|
155
|
+
for (const [kind, file, source] of planted) {
|
|
156
|
+
write(file, source);
|
|
157
|
+
expect([file, source, kinds(file)]).toEqual([file, source, [kind]]);
|
|
158
|
+
rmSync(join(root, file));
|
|
159
|
+
}
|
|
160
|
+
write('tests/a.test.ts', planted[4]?.[2] ?? '');
|
|
161
|
+
const diagnostic = findClockOracles(root, ['tests/a.test.ts']).map(formatClockOracle)[0] ?? '';
|
|
162
|
+
for (const part of [
|
|
163
|
+
`error[${TEST_CLOCK_ORACLE.id}]: ${TEST_CLOCK_ORACLE.message['clock-delta']}`,
|
|
164
|
+
' --> tests/a.test.ts:1:',
|
|
165
|
+
' = help: Elapsed time on a loaded host',
|
|
166
|
+
])
|
|
167
|
+
expect(diagnostic).toContain(part);
|
|
168
|
+
rmSync(join(root, 'tests/a.test.ts'));
|
|
169
|
+
|
|
170
|
+
const controls: readonly [string, string][] = [
|
|
171
|
+
[
|
|
172
|
+
'tests/c.test.ts',
|
|
173
|
+
"test('injected clock', () => { const timer = new MemoryTimer(); const started = timer.now(); timer.advance(30); expect(timer.now() - started).toBeLessThan(31); });",
|
|
174
|
+
],
|
|
175
|
+
[
|
|
176
|
+
'tests/c.test.ts',
|
|
177
|
+
`test('exit decides', async () => { const run = await onProgressClock(() => false, 0, () => verdictOf('node -e ""', { timeoutMs: 5_000 })); expect(run.result).toEqual({ outcome: 'passed' }); });`,
|
|
178
|
+
],
|
|
179
|
+
[
|
|
180
|
+
'tests/c.test.ts',
|
|
181
|
+
`test('subject held off by construction', async () => { const result = await runBoundedExec({ command: 'node -e "process.stdin.resume()"', timeoutMs: 50 }); expect(result.terminalOutput).toContain('timeoutMs=50'); });`,
|
|
182
|
+
],
|
|
183
|
+
[
|
|
184
|
+
'tests/c.test.ts',
|
|
185
|
+
`test('bounds that cannot decide', async () => { await runBoundedExec({ command: 'node -e "setTimeout(() => {}, 400)"', idleTimeoutMs: 0, timeoutMs: 180_000 }); });`,
|
|
186
|
+
],
|
|
187
|
+
[
|
|
188
|
+
'tests/c.test.ts',
|
|
189
|
+
"test('waited at least', async () => { const started = performance.now(); await lock.acquired; expect(performance.now() - started).toBeGreaterThanOrEqual(100); });",
|
|
190
|
+
],
|
|
191
|
+
[
|
|
192
|
+
'tests/c.test.ts',
|
|
193
|
+
"test('stamped after', () => { const before = Date.now(); const record = make(); expect(record.at).toBeGreaterThanOrEqual(before); expect(before).toBeLessThanOrEqual(record.at); });",
|
|
194
|
+
],
|
|
195
|
+
['tests/c.test.ts', "test('cpu time', () => { expect(cpuTime.total).toBeLessThanOrEqual(100_000); });"],
|
|
196
|
+
[
|
|
197
|
+
'tests/c.test.ts',
|
|
198
|
+
"test('stand-in outlasts the leg', async () => { const path = await fakeChild('exec sleep 3600'); await openService({ path, lspQueryTimeoutMs: 1_000 }); });",
|
|
199
|
+
],
|
|
200
|
+
[
|
|
201
|
+
'tests/c.test.ts',
|
|
202
|
+
`test('silent child held past the backstop', async () => { await runBoundedExec({ command: 'node -e "setInterval(() => {}, 1 << 30)"', timeoutMs: 50, killAfterMs: 10 }); });`,
|
|
203
|
+
],
|
|
204
|
+
[
|
|
205
|
+
'tests/c.test.ts',
|
|
206
|
+
`test('a ceiling and a progress bound', async () => { await verdictOf('node -e "setInterval(() => console.log(1), 10)"', { timeoutMs: 200 }); await verdictOf('node -e "setInterval(() => {}, 1 << 30)"', { idleTimeoutMs: 100 }); });`,
|
|
207
|
+
],
|
|
208
|
+
[
|
|
209
|
+
'tests/c.test.ts',
|
|
210
|
+
`test('virtual progress clock', async () => { const script = "setInterval(() => console.error('SLOW'), 50);"; await onProgressClock((chunk) => chunk.includes('SLOW'), 400, () => runBoundedExec({ command: 'node runner.js', idleTimeoutMs: 400 })); expect(verdict).toMatchObject({ outcome: 'wedged', idleMs: 400 }); });`,
|
|
211
|
+
],
|
|
212
|
+
[
|
|
213
|
+
'tests/c.rs',
|
|
214
|
+
lines(
|
|
215
|
+
'#[tokio::test]',
|
|
216
|
+
'async fn parked() {',
|
|
217
|
+
' let child = Command::new("sleep").arg("1");',
|
|
218
|
+
' assert!(tokio::time::timeout(Duration::from_millis(500), &mut parked).await.is_err());',
|
|
219
|
+
'}',
|
|
220
|
+
),
|
|
221
|
+
],
|
|
222
|
+
[
|
|
223
|
+
'tests/c.test.ts',
|
|
224
|
+
lines(
|
|
225
|
+
'const elapsed = Date.now() - t0;',
|
|
226
|
+
"test('shadowed', () => { const elapsed = timer.elapsed(); expect(elapsed).toBeLessThan(5); });",
|
|
227
|
+
),
|
|
228
|
+
],
|
|
229
|
+
[
|
|
230
|
+
'tests/c.rs',
|
|
231
|
+
lines(
|
|
232
|
+
'#[test]',
|
|
233
|
+
'fn waited() {',
|
|
234
|
+
' let started = Instant::now();',
|
|
235
|
+
' acquire();',
|
|
236
|
+
' assert!(started.elapsed() >= Duration::from_millis(100));',
|
|
237
|
+
' let clock = ManualClock::new();',
|
|
238
|
+
' clock.advance(Duration::from_millis(30));',
|
|
239
|
+
' assert!(clock.elapsed() < Duration::from_millis(31));',
|
|
240
|
+
'}',
|
|
241
|
+
),
|
|
242
|
+
],
|
|
243
|
+
[
|
|
244
|
+
'tests/c.rs',
|
|
245
|
+
lines(
|
|
246
|
+
'#[test]',
|
|
247
|
+
'fn stamped() {',
|
|
248
|
+
' let wall_before = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_micros();',
|
|
249
|
+
' let since_us = start();',
|
|
250
|
+
' assert!(since_us >= wall_before);',
|
|
251
|
+
' let config = format!(r#"timeoutMs = 1; cmd = "sleep 5""#);',
|
|
252
|
+
'}',
|
|
253
|
+
),
|
|
254
|
+
],
|
|
255
|
+
[
|
|
256
|
+
'tests/c.rs',
|
|
257
|
+
lines(
|
|
258
|
+
'#[tokio::test]',
|
|
259
|
+
'async fn quiet() {',
|
|
260
|
+
' assert!(timeout(Duration::from_millis(50), rx.recv()).await.is_err());',
|
|
261
|
+
' timeout(NO_PROGRESS, served()).await.expect("served");',
|
|
262
|
+
'}',
|
|
263
|
+
),
|
|
264
|
+
],
|
|
265
|
+
[
|
|
266
|
+
'tests/c.rs',
|
|
267
|
+
lines(
|
|
268
|
+
'#[tokio::test(start_paused = true)]',
|
|
269
|
+
'async fn virtual_time() {',
|
|
270
|
+
' let deadline = Instant::now() + Duration::from_secs(5);',
|
|
271
|
+
' advance().await;',
|
|
272
|
+
' assert!(Instant::now() < deadline);',
|
|
273
|
+
' timeout(Duration::from_millis(500), served()).await.expect("served");',
|
|
274
|
+
'}',
|
|
275
|
+
),
|
|
276
|
+
],
|
|
277
|
+
];
|
|
278
|
+
for (const [file, source] of controls) {
|
|
279
|
+
write(file, source);
|
|
280
|
+
expect([source, kinds(file)]).toEqual([source, []]);
|
|
281
|
+
rmSync(join(root, file));
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// Diff scope: an existing elapsed bound in the upstream refuses nothing until its own case is edited, and then the
|
|
285
|
+
// whole case is examined; the bin judges the same changes.
|
|
286
|
+
const legacy = [
|
|
287
|
+
"test('old elapsed bound', async () => {",
|
|
288
|
+
' const started = Date.now();',
|
|
289
|
+
' await run();',
|
|
290
|
+
' expect(Date.now() - started).toBeLessThan(5_000);',
|
|
291
|
+
'});',
|
|
292
|
+
"test('event case', async () => {",
|
|
293
|
+
' await child.exited;',
|
|
294
|
+
'});',
|
|
295
|
+
];
|
|
296
|
+
write('tests/legacy.test.ts', lines(...legacy));
|
|
297
|
+
git('init', '--quiet', '-b', 'main');
|
|
298
|
+
git('add', '.');
|
|
299
|
+
git('commit', '--quiet', '-m', 'base');
|
|
300
|
+
git('checkout', '--quiet', '-b', 'topic');
|
|
301
|
+
const base = git('rev-parse', 'HEAD').trim();
|
|
302
|
+
const judged = () => {
|
|
303
|
+
const scope = diffScope(root, base);
|
|
304
|
+
if (!scope.ok) throw new Error(scope.reason);
|
|
305
|
+
return findClockOracles(root, scope.value.files, scope.value.changes).map((oracle) => [
|
|
306
|
+
oracle.kind,
|
|
307
|
+
oracle.line,
|
|
308
|
+
]);
|
|
309
|
+
};
|
|
310
|
+
expect(judged()).toEqual([]);
|
|
311
|
+
write('tests/legacy.test.ts', lines(...legacy.slice(0, 6), ' await child.closed;', ...legacy.slice(7)));
|
|
312
|
+
expect(judged()).toEqual([]);
|
|
313
|
+
write(
|
|
314
|
+
'tests/legacy.test.ts',
|
|
315
|
+
lines(...legacy.slice(0, 2), ' await run({ verbose: true });', ...legacy.slice(3)),
|
|
316
|
+
);
|
|
317
|
+
expect(judged()).toEqual([['clock-delta', 4]]);
|
|
318
|
+
const scope = diffScope(root, base);
|
|
319
|
+
expect(
|
|
320
|
+
(scope.ok ? findClockOracles(root, scope.value.files, scope.value.changes) : [])
|
|
321
|
+
.map(formatClockOracle)
|
|
322
|
+
.map((each) => each.split('\n').slice(0, 2)),
|
|
323
|
+
).toEqual([
|
|
324
|
+
[
|
|
325
|
+
`error[${TEST_CLOCK_ORACLE.id}]: ${TEST_CLOCK_ORACLE.message['clock-delta']}: expect(Date.now() - started).toBeLessThan(5_000)`,
|
|
326
|
+
' --> tests/legacy.test.ts:4:3',
|
|
327
|
+
],
|
|
328
|
+
]);
|
|
329
|
+
write('tests/new.test.ts', planted[0]?.[2] ?? '');
|
|
330
|
+
expect(judged()).toEqual([
|
|
331
|
+
['clock-delta', 4],
|
|
332
|
+
['runner-deadline', 1],
|
|
333
|
+
]);
|
|
334
|
+
} finally {
|
|
335
|
+
rmSync(root, { recursive: true, force: true });
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
});
|