@smoothbricks/nx-plugin 0.5.3 → 0.5.5
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 +52 -12
- package/dist/executors/bounded-exec/cpu-tokens.d.ts +13 -0
- package/dist/executors/bounded-exec/cpu-tokens.d.ts.map +1 -1
- package/dist/executors/bounded-exec/cpu-tokens.js +9 -9
- package/dist/executors/bounded-exec/executor.d.ts.map +1 -1
- package/dist/executors/bounded-exec/executor.js +20 -6
- package/dist/executors/bounded-exec/progress.d.ts +8 -3
- package/dist/executors/bounded-exec/progress.d.ts.map +1 -1
- package/dist/executors/bounded-exec/progress.js +100 -10
- package/dist/executors/bounded-exec/verdict.d.ts +5 -4
- package/dist/executors/bounded-exec/verdict.d.ts.map +1 -1
- package/dist/executors/bounded-exec/verdict.js +1 -0
- package/dist/runtime-input-policy.d.ts +60 -0
- package/dist/runtime-input-policy.d.ts.map +1 -0
- package/dist/runtime-input-policy.js +379 -0
- package/dist/testing.js +1 -1
- package/managed/raw/patches/nx@23.2.1.patch +26 -0
- package/package.json +7 -2
- package/src/executors/bounded-exec/cpu-tokens.ts +15 -9
- package/src/executors/bounded-exec/executor.test.ts +26 -23
- package/src/executors/bounded-exec/executor.ts +19 -4
- package/src/executors/bounded-exec/go-progress-host.test.ts +171 -0
- package/src/executors/bounded-exec/progress.test.ts +73 -0
- package/src/executors/bounded-exec/progress.ts +95 -12
- package/src/executors/bounded-exec/verdict.ts +5 -4
- package/src/nx-daemon-start-never.test.ts +30 -1
- package/src/runtime-input-policy.ts +395 -0
- package/src/runtime-input.test.ts +160 -3
- package/src/testing.ts +1 -1
|
@@ -474,7 +474,7 @@ export async function runBoundedExec(
|
|
|
474
474
|
}
|
|
475
475
|
|
|
476
476
|
// Progress is a finished test, not output: a runner's SLOW warnings and a hung test's heartbeat keep printing.
|
|
477
|
-
const progress = createRunProgress();
|
|
477
|
+
const progress = createRunProgress(command);
|
|
478
478
|
// A write that found no space is said once, in the output, by whatever made it; the volume is read when it is said,
|
|
479
479
|
// since the writer usually removes what it half-wrote before it exits and the volume no longer looks full by then.
|
|
480
480
|
const noSpace = createNoSpaceWatch();
|
|
@@ -542,7 +542,7 @@ export async function runBoundedExec(
|
|
|
542
542
|
idleTimer = setTimeout(() => expire({ kind: 'idle', limitMs, tests: progress.inFlight() }, queuedMs), leftMs);
|
|
543
543
|
};
|
|
544
544
|
const armIdleTimer = (): void => {
|
|
545
|
-
if (idleTimeoutMs === undefined || state.settled || state.expiry !== null) {
|
|
545
|
+
if (idleTimeoutMs === undefined || state.settled || state.expiry !== null || !progress.isTesting()) {
|
|
546
546
|
return;
|
|
547
547
|
}
|
|
548
548
|
idleLeftMs = idleTimeoutMs;
|
|
@@ -577,6 +577,10 @@ export async function runBoundedExec(
|
|
|
577
577
|
const waitedMs = Date.now() - queuedSinceMs;
|
|
578
578
|
queuedMs += waitedMs;
|
|
579
579
|
queuedSinceMs = null;
|
|
580
|
+
if (!progress.isTesting()) {
|
|
581
|
+
appendStderr(`bounded-exec: host CPU wait ended after ${waitedMs}ms; no test runner is active\n`);
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
580
584
|
appendStderr(
|
|
581
585
|
`bounded-exec: idle clock restarted: no descendant's work is queued for host CPU tokens after ${waitedMs}ms; ${idleLeftMs}ms of idleTimeoutMs=${idleTimeoutMs} left\n`,
|
|
582
586
|
);
|
|
@@ -587,16 +591,27 @@ export async function runBoundedExec(
|
|
|
587
591
|
// Only the CHILD's own output is read for progress. The diagnostics below go
|
|
588
592
|
// through appendStderr as well, and re-arming on those would let a teardown
|
|
589
593
|
// message extend the very bound that just fired.
|
|
594
|
+
const scanProgress = (stream: 'stdout' | 'stderr', text: string): void => {
|
|
595
|
+
const wasTesting = progress.isTesting();
|
|
596
|
+
const finished = progress.scan(stream, text);
|
|
597
|
+
if (!progress.isTesting()) {
|
|
598
|
+
clearTimeout(idleTimer);
|
|
599
|
+
cancelCapture();
|
|
600
|
+
idleCapture = undefined;
|
|
601
|
+
} else if (finished || !wasTesting) {
|
|
602
|
+
armIdleTimer();
|
|
603
|
+
}
|
|
604
|
+
};
|
|
590
605
|
child.stdout?.on('data', (chunk: Buffer | string) => {
|
|
591
606
|
const text = chunk.toString();
|
|
592
|
-
|
|
607
|
+
scanProgress('stdout', text);
|
|
593
608
|
const said = noSpace.scan('stdout', text);
|
|
594
609
|
if (said !== null) state.noSpace = sight(said);
|
|
595
610
|
appendStdout(text);
|
|
596
611
|
});
|
|
597
612
|
child.stderr?.on('data', (chunk: Buffer | string) => {
|
|
598
613
|
const text = chunk.toString();
|
|
599
|
-
|
|
614
|
+
scanProgress('stderr', text);
|
|
600
615
|
const said = noSpace.scan('stderr', text);
|
|
601
616
|
if (said !== null) state.noSpace = sight(said);
|
|
602
617
|
appendStderr(text);
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, jest } from 'bun:test';
|
|
2
|
+
import { chmod, mkdir, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { createServer, type Socket } from 'node:net';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { BOUNDED_TEST_IDLE_TIMEOUT_MS } from '../../bounded-test-policy.js';
|
|
6
|
+
import { ownedSocketDirectory } from '../../testing.js';
|
|
7
|
+
import { createProcessTreeKiller, runBoundedExec } from './executor.js';
|
|
8
|
+
|
|
9
|
+
const roots: string[] = [];
|
|
10
|
+
|
|
11
|
+
/** Real Go build/run events; only the executor's clock is controlled, never compiler speed. */
|
|
12
|
+
describe('Go test progress host proofs', () => {
|
|
13
|
+
afterEach(async () => {
|
|
14
|
+
jest.useRealTimers();
|
|
15
|
+
await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true })));
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('excludes held initial linking and inter-package linking from test idle time', async () => {
|
|
19
|
+
const root = await goFixture();
|
|
20
|
+
for (const name of ['first', 'second']) {
|
|
21
|
+
await mkdir(join(root, name));
|
|
22
|
+
await writeFile(
|
|
23
|
+
join(root, name, 'ready_test.go'),
|
|
24
|
+
`package ${name}\nimport "testing"\nfunc TestReady(t *testing.T) {}\n`,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
const endpoint = join(root, 'runner.sock');
|
|
28
|
+
const wrapper = join(root, 'tool.cjs');
|
|
29
|
+
await writeFile(
|
|
30
|
+
wrapper,
|
|
31
|
+
[
|
|
32
|
+
'#!/usr/bin/env node',
|
|
33
|
+
"const { spawnSync } = require('node:child_process');",
|
|
34
|
+
"const { connect } = require('node:net');",
|
|
35
|
+
"const { basename } = require('node:path');",
|
|
36
|
+
'const [tool, ...args] = process.argv.slice(2);',
|
|
37
|
+
'function run() {',
|
|
38
|
+
" const result = spawnSync(tool, args, { stdio: 'inherit' });",
|
|
39
|
+
' if (result.error) throw result.error;',
|
|
40
|
+
' if (result.signal) process.kill(process.pid, result.signal);',
|
|
41
|
+
' else process.exit(result.status ?? 1);',
|
|
42
|
+
'}',
|
|
43
|
+
"if (basename(tool) !== 'link' || args.some(arg => arg.startsWith('-V'))) run();",
|
|
44
|
+
'else {',
|
|
45
|
+
` const socket = connect(${JSON.stringify(endpoint)}, () => socket.write('link-ready\\n'));`,
|
|
46
|
+
" socket.once('error', error => { throw error; });",
|
|
47
|
+
" let answer = '';",
|
|
48
|
+
" socket.on('data', data => { answer += data.toString(); });",
|
|
49
|
+
" socket.once('end', () => {",
|
|
50
|
+
" if (answer !== 'go\\n') throw new Error('unexpected link release');",
|
|
51
|
+
' socket.end(); run();',
|
|
52
|
+
' });',
|
|
53
|
+
'}',
|
|
54
|
+
'',
|
|
55
|
+
].join('\n'),
|
|
56
|
+
);
|
|
57
|
+
await chmod(wrapper, 0o700);
|
|
58
|
+
const sockets = new Set<Socket>();
|
|
59
|
+
const exchanges: Promise<unknown>[] = [];
|
|
60
|
+
const firstFinished = Promise.withResolvers<boolean>();
|
|
61
|
+
let links = 0;
|
|
62
|
+
const server = createServer((socket) => {
|
|
63
|
+
sockets.add(socket);
|
|
64
|
+
socket.once('close', () => sockets.delete(socket));
|
|
65
|
+
exchanges.push(
|
|
66
|
+
new Promise<void>((resolve, reject) => {
|
|
67
|
+
socket.once('error', reject);
|
|
68
|
+
let request = '';
|
|
69
|
+
const received = (data: Buffer) => {
|
|
70
|
+
request += data.toString();
|
|
71
|
+
if (!request.includes('\n')) return;
|
|
72
|
+
socket.off('data', received);
|
|
73
|
+
void (async () => {
|
|
74
|
+
expect(request).toBe('link-ready\n');
|
|
75
|
+
links += 1;
|
|
76
|
+
if (links === 2) expect(await firstFinished.promise).toBe(true);
|
|
77
|
+
// The linker is held at a real IPC barrier while virtual idle time crosses the
|
|
78
|
+
// unchanged production bound twice. No test binary exists for this package yet.
|
|
79
|
+
jest.advanceTimersByTime(2 * BOUNDED_TEST_IDLE_TIMEOUT_MS);
|
|
80
|
+
socket.end('go\n');
|
|
81
|
+
resolve();
|
|
82
|
+
})().catch(reject);
|
|
83
|
+
};
|
|
84
|
+
socket.on('data', received);
|
|
85
|
+
}).catch((error: unknown) => error),
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
await new Promise<void>((resolve) => server.listen(endpoint, resolve));
|
|
89
|
+
const stdout = process.stdout.write;
|
|
90
|
+
const stderr = process.stderr.write;
|
|
91
|
+
let output = '';
|
|
92
|
+
process.stdout.write = (chunk) => {
|
|
93
|
+
output += chunk.toString();
|
|
94
|
+
if (output.includes('"Action":"pass","Package":"example/first","Elapsed":')) firstFinished.resolve(true);
|
|
95
|
+
return true;
|
|
96
|
+
};
|
|
97
|
+
process.stderr.write = () => true;
|
|
98
|
+
jest.useFakeTimers();
|
|
99
|
+
try {
|
|
100
|
+
const command = ['first', 'second']
|
|
101
|
+
.map((name) => `go test -p=1 -count=1 -toolexec=${JSON.stringify(wrapper)} ./${name}`)
|
|
102
|
+
.join(' && ');
|
|
103
|
+
const result = await runBoundedExec(
|
|
104
|
+
{ command, idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS, killAfterMs: 0 },
|
|
105
|
+
{ root },
|
|
106
|
+
createProcessTreeKiller(),
|
|
107
|
+
null,
|
|
108
|
+
null,
|
|
109
|
+
);
|
|
110
|
+
firstFinished.resolve(false);
|
|
111
|
+
const exchangeErrors = (await Promise.all(exchanges)).filter((error) => error !== undefined);
|
|
112
|
+
expect(result.success, result.terminalOutput).toBe(true);
|
|
113
|
+
expect(exchangeErrors).toEqual([]);
|
|
114
|
+
expect(links).toBe(2);
|
|
115
|
+
expect(result.terminalOutput).not.toContain('Command made no progress');
|
|
116
|
+
} finally {
|
|
117
|
+
firstFinished.resolve(false);
|
|
118
|
+
jest.useRealTimers();
|
|
119
|
+
process.stdout.write = stdout;
|
|
120
|
+
process.stderr.write = stderr;
|
|
121
|
+
for (const socket of sockets) socket.destroy();
|
|
122
|
+
await new Promise<void>((resolve, reject) => server.close((error) => (error ? reject(error) : resolve())));
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('ends a real hanging Go test when its unchanged active-test budget expires', async () => {
|
|
127
|
+
const root = await goFixture();
|
|
128
|
+
await writeFile(
|
|
129
|
+
join(root, 'hang_test.go'),
|
|
130
|
+
'package example\nimport ("runtime"; "testing")\nfunc TestHang(t *testing.T) { for { runtime.Gosched() } }\n',
|
|
131
|
+
);
|
|
132
|
+
const stdout = process.stdout.write;
|
|
133
|
+
const stderr = process.stderr.write;
|
|
134
|
+
let output = '';
|
|
135
|
+
let advanced = false;
|
|
136
|
+
process.stdout.write = (chunk) => {
|
|
137
|
+
output += chunk.toString();
|
|
138
|
+
if (!advanced && output.includes('"Action":"run","Package":"example","Test":"TestHang"')) {
|
|
139
|
+
advanced = true;
|
|
140
|
+
queueMicrotask(() => jest.advanceTimersByTime(BOUNDED_TEST_IDLE_TIMEOUT_MS));
|
|
141
|
+
}
|
|
142
|
+
return true;
|
|
143
|
+
};
|
|
144
|
+
process.stderr.write = () => true;
|
|
145
|
+
jest.useFakeTimers();
|
|
146
|
+
try {
|
|
147
|
+
const result = await runBoundedExec(
|
|
148
|
+
{ command: 'go test -p=1 -count=1 .', idleTimeoutMs: BOUNDED_TEST_IDLE_TIMEOUT_MS, killAfterMs: 0 },
|
|
149
|
+
{ root },
|
|
150
|
+
createProcessTreeKiller(),
|
|
151
|
+
null,
|
|
152
|
+
null,
|
|
153
|
+
);
|
|
154
|
+
expect(advanced).toBe(true);
|
|
155
|
+
expect(result.success).toBe(false);
|
|
156
|
+
expect(result.terminalOutput).toContain(`no test finished for ${BOUNDED_TEST_IDLE_TIMEOUT_MS}ms`);
|
|
157
|
+
expect(result.terminalOutput).toContain('still running: example TestHang');
|
|
158
|
+
} finally {
|
|
159
|
+
jest.useRealTimers();
|
|
160
|
+
process.stdout.write = stdout;
|
|
161
|
+
process.stderr.write = stderr;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
async function goFixture(): Promise<string> {
|
|
167
|
+
const root = await ownedSocketDirectory('go-progress-', 'runner.sock');
|
|
168
|
+
roots.push(root);
|
|
169
|
+
await writeFile(join(root, 'go.mod'), 'module example\n\ngo 1.24\n');
|
|
170
|
+
return root;
|
|
171
|
+
}
|
|
@@ -3,6 +3,69 @@ import { describe, expect, it } from 'bun:test';
|
|
|
3
3
|
import { createRunProgress, withProgressReport } from './progress.js';
|
|
4
4
|
|
|
5
5
|
describe('run progress', () => {
|
|
6
|
+
it('observes Go package execution and test completions, not build output or heartbeats', () => {
|
|
7
|
+
const progress = createRunProgress();
|
|
8
|
+
expect(
|
|
9
|
+
progress.scan('stdout', '{"Action":"build-output","ImportPath":"example/first","Output":"linking\\n"}\n'),
|
|
10
|
+
).toBe(false);
|
|
11
|
+
expect(progress.inFlight()).toEqual([]);
|
|
12
|
+
expect(progress.scan('stdout', '{"Action":"start","Package":"example/first"}\n')).toBe(false);
|
|
13
|
+
expect(progress.inFlight()).toEqual(['example/first']);
|
|
14
|
+
expect(progress.scan('stdout', '{"Action":"run","Package":"example/first","Test":"TestReady"}\n')).toBe(false);
|
|
15
|
+
expect(progress.inFlight()).toEqual(['example/first TestReady']);
|
|
16
|
+
expect(progress.scan('stdout', '{"Action":"output","Package":"example/first","Output":"...\\n"}\n')).toBe(false);
|
|
17
|
+
expect(progress.scan('stdout', '{"Action":"pass","Package":"example/first","Test":"TestReady"}\n')).toBe(true);
|
|
18
|
+
expect(progress.scan('stdout', '{"Action":"pass","Package":"example/first"}\n')).toBe(true);
|
|
19
|
+
expect(progress.inFlight()).toEqual([]);
|
|
20
|
+
expect(
|
|
21
|
+
progress.scan('stdout', '{"Action":"build-output","ImportPath":"example/second","Output":"compiling\\n"}\n'),
|
|
22
|
+
).toBe(false);
|
|
23
|
+
expect(progress.scan('stdout', '{"Action":"start","Package":"example/second"}\n')).toBe(false);
|
|
24
|
+
expect(progress.scan('stdout', '{"Action":"run","Package":"example/second","Test":"TestHang"}\n')).toBe(false);
|
|
25
|
+
expect(progress.inFlight()).toEqual(['example/second TestHang']);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('counts only active Go package intervals, including startup and parallel packages', () => {
|
|
29
|
+
const progress = createRunProgress('go test ./...');
|
|
30
|
+
expect(progress.isTesting()).toBe(false);
|
|
31
|
+
progress.scan('stdout', '{"Action":"start","Package":"first"}\n{"Action":"start","Package":"second"}\n');
|
|
32
|
+
expect(progress.isTesting()).toBe(true);
|
|
33
|
+
expect(progress.inFlight()).toEqual(['first', 'second']);
|
|
34
|
+
progress.scan('stdout', '{"Action":"pass","Package":"first"}\n');
|
|
35
|
+
expect(progress.isTesting()).toBe(true);
|
|
36
|
+
expect(progress.inFlight()).toEqual(['second']);
|
|
37
|
+
progress.scan('stdout', '{"Action":"fail","Package":"second"}\n');
|
|
38
|
+
expect(progress.isTesting()).toBe(false);
|
|
39
|
+
expect(progress.inFlight()).toEqual([]);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('buffers split Go events and does not mistake test output for lifecycle events', () => {
|
|
43
|
+
const progress = createRunProgress('go test ./...');
|
|
44
|
+
expect(progress.scan('stdout', '{"Action":"sta')).toBe(false);
|
|
45
|
+
expect(progress.isTesting()).toBe(false);
|
|
46
|
+
expect(progress.scan('stdout', 'rt","Package":"example"}\n')).toBe(false);
|
|
47
|
+
expect(progress.isTesting()).toBe(true);
|
|
48
|
+
expect(progress.scan('stdout', '{"Action":"run","Package":"example","Test":"TestHang"}\n')).toBe(false);
|
|
49
|
+
expect(progress.scan('stdout', '{"Action":"pause","Package":"example","Test":"TestHang"}\n')).toBe(false);
|
|
50
|
+
expect(progress.inFlight()).toEqual(['example TestHang']);
|
|
51
|
+
expect(progress.scan('stdout', '{"Action":"cont","Package":"example","Test":"TestHang"}\n')).toBe(false);
|
|
52
|
+
expect(progress.scan('stdout', '{"Action":"output","Package":"example","Output":"test fake ... ok\\n"}\n')).toBe(
|
|
53
|
+
false,
|
|
54
|
+
);
|
|
55
|
+
expect(progress.scan('stderr', '...\n')).toBe(false);
|
|
56
|
+
expect(progress.scan('stderr', '{invalid JSON}\n')).toBe(false);
|
|
57
|
+
expect(progress.scan('stdout', '{"Action":"skip","Package":"example","Test":"TestHang"}\n')).toBe(true);
|
|
58
|
+
expect(progress.inFlight()).toEqual(['example']);
|
|
59
|
+
expect(progress.scan('stdout', '{"Action":"pass","Package":"example"}\n')).toBe(true);
|
|
60
|
+
expect(progress.isTesting()).toBe(false);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('keeps the existing watchdog for commands without a complete Go lifecycle contract', () => {
|
|
64
|
+
for (const command of ['bun test src', 'cargo nextest run', 'cargo test', 'go test ./... && bun test src']) {
|
|
65
|
+
expect(createRunProgress(command).isTesting()).toBe(true);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
6
69
|
it('counts a nextest status line with its run counter as a finished test, and a SLOW line as none', () => {
|
|
7
70
|
const progress = createRunProgress();
|
|
8
71
|
expect(progress.scan('stderr', ' SLOW [> 1.000s] (───) nt tests::hangs\n')).toBe(false);
|
|
@@ -60,6 +123,16 @@ describe('run progress', () => {
|
|
|
60
123
|
});
|
|
61
124
|
|
|
62
125
|
describe('progress report', () => {
|
|
126
|
+
it('asks Go for its package execution events without changing its test selection', () => {
|
|
127
|
+
expect(withProgressReport('go test -count=1 ./hts/... ./host/...')).toBe(
|
|
128
|
+
'go test -json -count=1 ./hts/... ./host/...',
|
|
129
|
+
);
|
|
130
|
+
expect(withProgressReport('go test -json -count=1 ./...')).toBe('go test -json -count=1 ./...');
|
|
131
|
+
expect(withProgressReport('go test -json=false ./first && go test -count=1 ./second')).toBe(
|
|
132
|
+
'go test -json ./first && go test -json -count=1 ./second',
|
|
133
|
+
);
|
|
134
|
+
});
|
|
135
|
+
|
|
63
136
|
it('asks a lone bun test for dots, keeping the runtime the target named', () => {
|
|
64
137
|
expect(withProgressReport('bun test --timeout=0 src')).toBe('bun test --dots --timeout=0 src');
|
|
65
138
|
expect(withProgressReport('../x/.runtime/bun test a')).toBe('../x/.runtime/bun test --dots a');
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import typia from 'typia';
|
|
2
|
+
import { invocationSpan, withInvocationFlag } from './cpu-tokens.js';
|
|
3
|
+
import { BUN_TEST, GO_TEST, NEXTEST_RUN } from './verdict.js';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* What a run's output says about its forward motion: whether a test finished, and which tests the runner said
|
|
@@ -17,14 +19,19 @@ import { BUN_TEST, NEXTEST_RUN } from './verdict.js';
|
|
|
17
19
|
* - bun: a line of dots, one per test finished (`--dots`, which `withProgressReport` asks for: bun prints nothing
|
|
18
20
|
* per passing test when it believes an agent runs it), or a `(pass)`/`(fail)`/`(skip)`/`(todo)` line. bun names
|
|
19
21
|
* no test before it finishes, so a bun run names nothing in flight.
|
|
22
|
+
* - go: structured `go test -json` package `start` follows the package's build dependencies; package `pass`,
|
|
23
|
+
* `fail`, or `skip` ends that execution interval. Test terminals re-arm the bound, but `output` and
|
|
24
|
+
* `build-output` never do. Initial and inter-package builds are outside an active test interval.
|
|
20
25
|
*
|
|
21
|
-
* A command
|
|
26
|
+
* A command without a recognised execution lifecycle remains bounded from spawn.
|
|
22
27
|
*/
|
|
23
28
|
export interface RunProgress {
|
|
24
|
-
/** One chunk of one of the command's output streams; true when it reports
|
|
29
|
+
/** One chunk of one of the command's output streams; true when it reports a finished test or Go package. */
|
|
25
30
|
scan(stream: OutputStream, chunk: string): boolean;
|
|
26
31
|
/** The tests the runner reported running and has not reported finished, in the order it first named them. */
|
|
27
32
|
inFlight(): string[];
|
|
33
|
+
/** Whether test idle time is currently chargeable; unknown runner lifecycles stay chargeable. */
|
|
34
|
+
isTesting(): boolean;
|
|
28
35
|
}
|
|
29
36
|
|
|
30
37
|
export type OutputStream = 'stdout' | 'stderr';
|
|
@@ -43,21 +50,77 @@ const RUNNING = [
|
|
|
43
50
|
];
|
|
44
51
|
const DOTS = /^\.+$/;
|
|
45
52
|
|
|
53
|
+
type GoTestEvent =
|
|
54
|
+
| { Action: 'start'; Package: string }
|
|
55
|
+
| { Action: 'run' | 'pause' | 'cont'; Package: string; Test: string }
|
|
56
|
+
| { Action: 'pass' | 'fail' | 'skip' | 'bench'; Package: string; Test?: string }
|
|
57
|
+
| { Action: 'output'; Package: string; Output: string; Test?: string };
|
|
58
|
+
const isGoTestEvent = typia.createIs<GoTestEvent>();
|
|
59
|
+
|
|
60
|
+
function goTestEvent(text: string): GoTestEvent | null {
|
|
61
|
+
if (!text.startsWith('{')) return null;
|
|
62
|
+
try {
|
|
63
|
+
const event: unknown = JSON.parse(text);
|
|
64
|
+
return isGoTestEvent(event) ? event : null;
|
|
65
|
+
} catch (error) {
|
|
66
|
+
if (error instanceof SyntaxError) return null;
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Defer only a direct Go command/chain; an unknown shell wrapper or another runner keeps its existing bound. */
|
|
72
|
+
function onlyGoTests(command: string): boolean {
|
|
73
|
+
let rest = command.trim();
|
|
74
|
+
while (rest.search(GO_TEST) === 0) {
|
|
75
|
+
rest = rest.slice(invocationSpan(rest, GO_TEST).argsEnd).trimStart();
|
|
76
|
+
if (rest === '') return true;
|
|
77
|
+
const separator = /^(?:&&|\|\||;)\s*/.exec(rest);
|
|
78
|
+
if (separator === null) return false;
|
|
79
|
+
rest = rest.slice(separator[0].length);
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
46
84
|
/** A stream's unfinished last line, and how many of its dots were already counted. */
|
|
47
85
|
interface LineState {
|
|
48
86
|
partial: string;
|
|
49
87
|
countedDots: number;
|
|
50
88
|
}
|
|
51
89
|
|
|
52
|
-
export function createRunProgress(): RunProgress {
|
|
90
|
+
export function createRunProgress(command = ''): RunProgress {
|
|
91
|
+
const goLifecycle = onlyGoTests(command);
|
|
53
92
|
const streams: Record<OutputStream, LineState> = {
|
|
54
93
|
stdout: { partial: '', countedDots: 0 },
|
|
55
94
|
stderr: { partial: '', countedDots: 0 },
|
|
56
95
|
};
|
|
57
96
|
const running = new Set<string>();
|
|
97
|
+
const packages = new Map<string, Set<string>>();
|
|
58
98
|
|
|
59
99
|
// One complete line, ANSI stripped, that is not a line of dots: true when it names a finished test.
|
|
60
100
|
const finishedLine = (text: string): boolean => {
|
|
101
|
+
const event = goTestEvent(text);
|
|
102
|
+
if (event !== null) {
|
|
103
|
+
switch (event.Action) {
|
|
104
|
+
case 'start':
|
|
105
|
+
packages.set(event.Package, new Set());
|
|
106
|
+
return false;
|
|
107
|
+
case 'run':
|
|
108
|
+
packages.get(event.Package)?.add(event.Test);
|
|
109
|
+
return false;
|
|
110
|
+
case 'pass':
|
|
111
|
+
case 'fail':
|
|
112
|
+
case 'skip':
|
|
113
|
+
case 'bench':
|
|
114
|
+
if (event.Test === undefined) packages.delete(event.Package);
|
|
115
|
+
else packages.get(event.Package)?.delete(event.Test);
|
|
116
|
+
return true;
|
|
117
|
+
case 'pause':
|
|
118
|
+
case 'cont':
|
|
119
|
+
case 'output':
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (goLifecycle) return false;
|
|
61
124
|
for (const pattern of FINISHED) {
|
|
62
125
|
const name = pattern.exec(text)?.[1];
|
|
63
126
|
if (name !== undefined) {
|
|
@@ -86,20 +149,28 @@ export function createRunProgress(): RunProgress {
|
|
|
86
149
|
for (const raw of lines) {
|
|
87
150
|
const text = raw.replace(ANSI, '').trimEnd();
|
|
88
151
|
if (DOTS.test(text)) {
|
|
89
|
-
|
|
152
|
+
if (!goLifecycle && DOTS.test(text)) {
|
|
153
|
+
progressed ||= text.length > counted;
|
|
154
|
+
}
|
|
90
155
|
} else if (finishedLine(text)) {
|
|
91
156
|
progressed = true;
|
|
92
157
|
}
|
|
93
158
|
counted = 0;
|
|
94
159
|
}
|
|
95
160
|
const tail = rest.replace(ANSI, '');
|
|
96
|
-
const dots = DOTS.test(tail) ? tail.length : 0;
|
|
161
|
+
const dots = !goLifecycle && DOTS.test(tail) ? tail.length : 0;
|
|
97
162
|
progressed ||= dots > counted;
|
|
98
163
|
state.partial = rest;
|
|
99
164
|
state.countedDots = dots;
|
|
100
165
|
return progressed;
|
|
101
166
|
},
|
|
102
|
-
inFlight: () => [
|
|
167
|
+
inFlight: () => [
|
|
168
|
+
...running,
|
|
169
|
+
...[...packages].flatMap(([name, tests]) =>
|
|
170
|
+
tests.size === 0 ? [name] : [...tests].map((test) => `${name} ${test}`),
|
|
171
|
+
),
|
|
172
|
+
],
|
|
173
|
+
isTesting: () => !goLifecycle || packages.size > 0,
|
|
103
174
|
};
|
|
104
175
|
}
|
|
105
176
|
|
|
@@ -109,10 +180,22 @@ export function createRunProgress(): RunProgress {
|
|
|
109
180
|
* unchanged.
|
|
110
181
|
*/
|
|
111
182
|
export function withProgressReport(command: string): string {
|
|
112
|
-
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
183
|
+
let reported = command;
|
|
184
|
+
for (const match of [...command.matchAll(new RegExp(GO_TEST, 'g'))].reverse()) {
|
|
185
|
+
reported =
|
|
186
|
+
reported.slice(0, match.index) +
|
|
187
|
+
withInvocationFlag(
|
|
188
|
+
reported.slice(match.index),
|
|
189
|
+
GO_TEST,
|
|
190
|
+
/(?<![\w-])-json(?:=(?:true|false))?(?=\s|$)/g,
|
|
191
|
+
'-json',
|
|
192
|
+
true,
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
const bun = reported.match(BUN_TEST)?.length ?? 0;
|
|
196
|
+
const nextest = reported.match(NEXTEST_RUN)?.length ?? 0;
|
|
197
|
+
if (bun !== 1 || nextest !== 0 || /(?:^|\s)(?:--dots|--reporter[=\s]dots)(?=\s|$)/.test(reported)) {
|
|
198
|
+
return reported;
|
|
116
199
|
}
|
|
117
|
-
return
|
|
200
|
+
return reported.replace(BUN_TEST, (_match, runtime: string) => `${runtime} test --dots`);
|
|
118
201
|
}
|
|
@@ -8,10 +8,10 @@ import { join } from 'node:path';
|
|
|
8
8
|
* - `bound`: the run hit a wall-clock bound and nothing else failed. Either the command
|
|
9
9
|
* outlived `timeoutMs` (`total`), or every failing test in the runner's report failed on
|
|
10
10
|
* its runner's per-test timeout (`test`). A loaded host produces exactly these.
|
|
11
|
-
* - `wedged`: `idleTimeoutMs` fired: no test finished for that long
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
11
|
+
* - `wedged`: `idleTimeoutMs` fired: no test finished for that long during a chargeable test interval. This proves
|
|
12
|
+
* the suite's completion bound was exceeded, not that every process stopped: an expensive active fixture can
|
|
13
|
+
* exceed it too. The verdict names tests reported running but never finished and tests the report says were
|
|
14
|
+
* aborted; diagnostics distinguish a stalled wait from a progressing but oversized lifecycle.
|
|
15
15
|
* - `no-space`: the run failed and its output said a write found no space (ENOSPC). Whatever its tests then reported,
|
|
16
16
|
* they failed on the disk, not on their own: the verdict names the line that said so and, when the task held one,
|
|
17
17
|
* its RAM temp volume as it stood when that line arrived.
|
|
@@ -274,6 +274,7 @@ const NEXTEST_REPORT_CONFIG_FILE = 'nextest-report.toml';
|
|
|
274
274
|
*/
|
|
275
275
|
export const BUN_TEST = /(?<=^|[\s;&|()])((?:[^\s;&|()<>'"`\\=]*\/)?bun)\s+test(?=\s|$)/g;
|
|
276
276
|
export const NEXTEST_RUN = /(?<=^|[\s;&|()-])nextest\s+run(?=\s|$)/g;
|
|
277
|
+
export const GO_TEST = /(?<=^|[\s;&|()])go\s+test(?=\s|$)/;
|
|
277
278
|
|
|
278
279
|
/**
|
|
279
280
|
* `command` with its test runner asked to write a JUnit report into `directory`, the report
|
|
@@ -7,7 +7,7 @@ import { fixtureNxEnv, withNxFixture } from './__tests__/fixture-nx-env.js';
|
|
|
7
7
|
import { awaitExit, isRunning, processTable, terminate } from './testing.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* Guards the `NX_DAEMON_START=never`
|
|
10
|
+
* Guards the `NX_DAEMON_START=never` hunks of `patches/nx@23.2.1.patch`. A stock client that finds no live daemon
|
|
11
11
|
* starts one, detached into a session of its own, and the record shares it with every client of the checkout. Cowshed
|
|
12
12
|
* ends a job's whole process tree when the job ends (`specs/cowshed/11_shell.md`), so a daemon one job's client
|
|
13
13
|
* started would end with that job while another job's `nx run` still used it. Every cowshed job therefore runs with
|
|
@@ -124,3 +124,32 @@ it('a client that may never start a daemon continues without one that stopped un
|
|
|
124
124
|
}
|
|
125
125
|
});
|
|
126
126
|
});
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* An explicit `nx daemon --start` calls the daemon start directly, past the implicit-start check above, so under the
|
|
130
|
+
* job's rule it is refused as policy: a non-zero exit naming `NX_DAEMON_START=never` and the fixture escape, and no
|
|
131
|
+
* daemon. The same command without the variable, which is what a test's named fixture escape runs, starts one.
|
|
132
|
+
*/
|
|
133
|
+
it('refuses an explicit daemon start under the job rule, and starts one without it', async () => {
|
|
134
|
+
await withNxFixture('nx-daemon-start-explicit', async ({ workspace, socketDirectory }) => {
|
|
135
|
+
await fixtureWorkspace(workspace);
|
|
136
|
+
const env = { ...fixtureNxEnv(workspace, socketDirectory), NX_DAEMON: 'true' };
|
|
137
|
+
|
|
138
|
+
const refused = spawnSync('bun', [nxEntry, 'daemon', '--start'], {
|
|
139
|
+
cwd: workspace,
|
|
140
|
+
env: { ...env, NX_DAEMON_START: 'never' },
|
|
141
|
+
encoding: 'utf8',
|
|
142
|
+
});
|
|
143
|
+
const said = `${refused.stdout}${refused.stderr}`;
|
|
144
|
+
expect(refused.status, said).toBe(1);
|
|
145
|
+
expect(said).toContain('NX_DAEMON_START=never forbids this client starting a daemon');
|
|
146
|
+
expect(said).toContain('FIXTURE_STARTS_ITS_OWN_DAEMON');
|
|
147
|
+
expect(await recordedPid(workspace)).toBeNull();
|
|
148
|
+
|
|
149
|
+
const started = spawnSync('bun', [nxEntry, 'daemon', '--start'], { cwd: workspace, env, encoding: 'utf8' });
|
|
150
|
+
expect(started.status, `${started.stdout}${started.stderr}`).toBe(0);
|
|
151
|
+
const daemon = await recordedPid(workspace);
|
|
152
|
+
if (daemon === null) throw new Error('an explicit start without the variable left no daemon record');
|
|
153
|
+
expect(isRunning(daemon)).toBe(true);
|
|
154
|
+
});
|
|
155
|
+
});
|