Skip to content

Commit 799b14c

Browse files
committed
fix(tooling): limit serialized validation to supported hosts
1 parent be7a8ae commit 799b14c

10 files changed

Lines changed: 326 additions & 380 deletions

‎CONTRIBUTING.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ For broad refactors or when explicitly requested, run the deterministic core agg
217217
pnpm check
218218
```
219219

220+
Serialized validation (`pnpm check` and `check:affected --run`) requires macOS or Linux.
221+
On Windows, use the affected plan and direct focused checks.
222+
220223
`pnpm check` takes the same host lock as `check:affected --run`, prints a receipt path, and writes
221224
logs under `.tmp/validation`. It covers formatting, lint, typechecking, layering, dependency-graph parity, production
222225
exports, MCP metadata, the distributable build, bundle ownership, Fallow, unit tests, and local smoke

‎docs/agents/testing.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# Validate a change
22

3-
Use this to select checks and interpret results. Use [isolated experiments](test-experiments.md) for mutations or base comparisons.
3+
For mutations or base comparisons, use [isolated experiments](test-experiments.md).
44

55
## Run checks
66

77
1. While editing, run the focused test or `pnpm check:quick`.
88
2. Before pushing, commit the change. Run `pnpm check:affected --run --head <commit>`.
99
3. For a broad refactor or an explicitly requested full gate, run `pnpm check`.
1010

11+
Serialized validation requires macOS or Linux. On Windows, use plan mode or focused checks.
1112
Both broad commands acquire the same host lock. Wait for the owner to finish, or cancel your waiter with Ctrl-C.
1213
Do not add lock wrappers or delete lock files. A wait ends after two hours. Nested validation fails immediately.
1314
Focused tests do not lock. Avoid subprocess-heavy tests beside a broad gate.
1415

15-
The runner prints progress and a receipt path. The receipt links command logs and Vitest JSON.
16-
It records refs, checkout state, commands, exit codes, skips, and failures.
16+
The runner prints progress and a receipt path with refs, checkout state, command logs, exits, skips, and Vitest results.
1717
Execution stops at the first failure. Unexecuted checks remain `not-run`.
1818

1919
- `pnpm check:affected`: compact plan.
@@ -29,7 +29,7 @@ Initial/final checks detect persistent changes; they do not sandbox the checkout
2929
## Interpret selection
3030

3131
A package manifest or TypeScript config can affect every consumer. A full selection for these changes is intentional.
32-
`FAIL-OPEN` means the selector could not safely narrow the set. Read `plan.failOpenReasons`.
32+
`FAIL-OPEN` means the selector could not safely narrow the set. Read `failOpenReasons` in plan JSON or `plan.failOpenReasons` in a receipt.
3333
Do not reduce selection to get a pass.
3434

3535
Read required-check status on the PR. The receipt lists skipped checks and owners in `results[].reason`.

‎scripts/check-affected/checkout-state.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ test('checkout fingerprint distinguishes edits with identical porcelain status a
3535
git('add', '.');
3636
assert.notEqual(second.fingerprint, readCheckoutState(cwd).fingerprint);
3737
// Both status and ls-files must tolerate more than spawnSync's default 1 MiB.
38+
git('config', 'core.longpaths', 'true');
3839
const wide = path.join(cwd, ...Array<string>(3).fill('d'.repeat(220)));
3940
fs.mkdirSync(wide, { recursive: true });
4041
for (let index = 0; index < 1200; index++)

‎scripts/check-affected/command-execution.test.ts‎

Lines changed: 98 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -7,108 +7,116 @@ import { runCmdBackground } from '@agent-device/host-kit/command';
77
import { entry, fixture, run } from './execution.fixtures.ts';
88
import type { ExecutionReceipt } from './execution.ts';
99

10-
test('SIGTERM cancels the command group, records cancellation, and releases the host lock', async () => {
11-
const { cwd } = fixture();
12-
const ready = path.join(cwd, '.tmp', 'ready.json');
13-
const source = `
10+
test(
11+
'SIGTERM cancels the command group, records cancellation, and releases the host lock',
12+
{ skip: process.platform === 'win32' },
13+
async () => {
14+
const { cwd } = fixture();
15+
const ready = path.join(cwd, '.tmp', 'ready.json');
16+
const source = `
1417
import { runValidation } from ${JSON.stringify(entry)};
1518
const code = await runValidation(${JSON.stringify(cwd)}, { base: 'HEAD', head: 'HEAD', json: true }, async ({execute}) => {
1619
return execute([process.execPath, '-e', ${JSON.stringify(`require('node:fs').writeFileSync(${JSON.stringify(ready)}, JSON.stringify(process.pid)); setInterval(() => {}, 1000);`)}], ${JSON.stringify(cwd)}, 'sleep');
1720
}); process.exitCode = code;
1821
`;
19-
const { child, wait } = runCmdBackground(
20-
process.execPath,
21-
['--experimental-strip-types', '--input-type=module', '-e', source],
22-
{
23-
cwd,
24-
allowFailure: true,
25-
env: { ...process.env, HOME: cwd, USERPROFILE: cwd, AGENT_DEVICE_VALIDATION_PARENT: '' },
26-
},
27-
);
28-
try {
29-
const deadline = Date.now() + 5000;
30-
while (!fs.existsSync(ready) && Date.now() < deadline) await setTimeout(20);
31-
assert.ok(fs.existsSync(ready), 'command must actually start');
32-
const commandPid = JSON.parse(fs.readFileSync(ready, 'utf8')) as number;
33-
child.kill('SIGTERM');
34-
const result = await wait;
35-
assert.equal(result.exitCode, 143, result.stderr);
36-
const receipt = JSON.parse(result.stdout) as ExecutionReceipt;
37-
assert.equal(receipt.status, 'cancelled');
38-
assert.equal(receipt.results[0]?.status, 'cancelled');
39-
assert.throws(() => process.kill(commandPid, 0), { code: 'ESRCH' });
40-
assert.equal(run(cwd, 'HEAD', 'return 0;').exitCode, 0);
41-
} finally {
42-
child.kill('SIGKILL');
43-
await wait;
44-
fs.rmSync(cwd, { recursive: true, force: true });
45-
}
46-
});
22+
const { child, wait } = runCmdBackground(
23+
process.execPath,
24+
['--experimental-strip-types', '--input-type=module', '-e', source],
25+
{
26+
cwd,
27+
allowFailure: true,
28+
env: { ...process.env, HOME: cwd, USERPROFILE: cwd, AGENT_DEVICE_VALIDATION_PARENT: '' },
29+
},
30+
);
31+
try {
32+
const deadline = Date.now() + 5000;
33+
while (!fs.existsSync(ready) && Date.now() < deadline) await setTimeout(20);
34+
assert.ok(fs.existsSync(ready), 'command must actually start');
35+
const commandPid = JSON.parse(fs.readFileSync(ready, 'utf8')) as number;
36+
child.kill('SIGTERM');
37+
const result = await wait;
38+
assert.equal(result.exitCode, 143, result.stderr);
39+
const receipt = JSON.parse(result.stdout) as ExecutionReceipt;
40+
assert.equal(receipt.status, 'cancelled');
41+
assert.equal(receipt.results[0]?.status, 'cancelled');
42+
assert.throws(() => process.kill(commandPid, 0), { code: 'ESRCH' });
43+
assert.equal(run(cwd, 'HEAD', 'return 0;').exitCode, 0);
44+
} finally {
45+
child.kill('SIGKILL');
46+
await wait;
47+
fs.rmSync(cwd, { recursive: true, force: true });
48+
}
49+
},
50+
);
4751

48-
test('a killed validation parent does not let a waiter overlap its surviving command group', async () => {
49-
const { cwd } = fixture();
50-
const ready = path.join(cwd, '.tmp', 'orphan.json');
51-
const env = { ...process.env, HOME: cwd, USERPROFILE: cwd, AGENT_DEVICE_VALIDATION_PARENT: '' };
52-
const source = `
52+
test(
53+
'a killed validation parent does not let a waiter overlap its surviving command group',
54+
{ skip: process.platform === 'win32' },
55+
async () => {
56+
const { cwd } = fixture();
57+
const ready = path.join(cwd, '.tmp', 'orphan.json');
58+
const env = { ...process.env, HOME: cwd, USERPROFILE: cwd, AGENT_DEVICE_VALIDATION_PARENT: '' };
59+
const source = `
5360
import { runValidation } from ${JSON.stringify(entry)};
5461
const code = await runValidation(${JSON.stringify(cwd)}, { base: 'HEAD', head: 'HEAD', json: true }, async ({execute}) => execute([process.execPath, '-e', ${JSON.stringify(`require('node:fs').writeFileSync(${JSON.stringify(ready)}, JSON.stringify(process.pid)); setInterval(() => {}, 1000);`)}], ${JSON.stringify(cwd)}, 'orphan'));
5562
process.exitCode = code;
5663
`;
57-
const parent = runCmdBackground(
58-
process.execPath,
59-
['--experimental-strip-types', '--input-type=module', '-e', source],
60-
{ cwd, env, allowFailure: true },
61-
);
62-
let commandPid: number | undefined;
63-
let waiter: ReturnType<typeof runCmdBackground> | undefined;
64-
try {
65-
const deadline = Date.now() + 5000;
66-
while (!fs.existsSync(ready) && Date.now() < deadline) await setTimeout(20);
67-
assert.ok(fs.existsSync(ready));
68-
commandPid = (
69-
JSON.parse(
70-
fs.readFileSync(
71-
path.join(cwd, '.cache', 'agent-device', 'validation.lock.active.json'),
72-
'utf8',
73-
),
74-
) as { pid: number }
75-
).pid;
76-
parent.child.kill('SIGKILL');
77-
await parent.wait;
78-
waiter = runCmdBackground(
64+
const parent = runCmdBackground(
7965
process.execPath,
80-
[
81-
'--experimental-strip-types',
82-
'--input-type=module',
83-
'-e',
84-
`
66+
['--experimental-strip-types', '--input-type=module', '-e', source],
67+
{ cwd, env, allowFailure: true },
68+
);
69+
let commandPid: number | undefined;
70+
let waiter: ReturnType<typeof runCmdBackground> | undefined;
71+
try {
72+
const deadline = Date.now() + 5000;
73+
while (!fs.existsSync(ready) && Date.now() < deadline) await setTimeout(20);
74+
assert.ok(fs.existsSync(ready));
75+
commandPid = (
76+
JSON.parse(
77+
fs.readFileSync(
78+
path.join(cwd, '.cache', 'agent-device', 'validation.lock.active.json'),
79+
'utf8',
80+
),
81+
) as { pid: number }
82+
).pid;
83+
parent.child.kill('SIGKILL');
84+
await parent.wait;
85+
waiter = runCmdBackground(
86+
process.execPath,
87+
[
88+
'--experimental-strip-types',
89+
'--input-type=module',
90+
'-e',
91+
`
8592
import { runValidation } from ${JSON.stringify(entry)};
8693
process.exitCode = await runValidation(${JSON.stringify(cwd)}, {base:'HEAD',head:'HEAD',json:true}, async () => 0);
8794
`,
88-
],
89-
{ cwd, env, allowFailure: true },
90-
);
91-
let observedWait = false;
92-
waiter.child.stderr?.on('data', (data) => {
93-
if (String(data).includes('[wait] orphan')) observedWait = true;
94-
});
95-
const waitDeadline = Date.now() + 5000;
96-
while (!observedWait && Date.now() < waitDeadline) await setTimeout(20);
97-
assert.equal(observedWait, true, 'waiter must observe surviving command before acquiring');
98-
process.kill(-commandPid, 'SIGTERM');
99-
const result = await waiter.wait;
100-
assert.equal(result.exitCode, 0, result.stderr);
101-
assert.equal(JSON.parse(result.stdout).status, 'passed');
102-
} finally {
103-
parent.child.kill('SIGKILL');
104-
waiter?.child.kill('SIGTERM');
105-
if (commandPid) {
106-
try {
107-
process.kill(-commandPid, 'SIGKILL');
108-
} catch {}
95+
],
96+
{ cwd, env, allowFailure: true },
97+
);
98+
let observedWait = false;
99+
waiter.child.stderr?.on('data', (data) => {
100+
if (String(data).includes('[wait] orphan')) observedWait = true;
101+
});
102+
const waitDeadline = Date.now() + 5000;
103+
while (!observedWait && Date.now() < waitDeadline) await setTimeout(20);
104+
assert.equal(observedWait, true, 'waiter must observe surviving command before acquiring');
105+
process.kill(-commandPid, 'SIGTERM');
106+
const result = await waiter.wait;
107+
assert.equal(result.exitCode, 0, result.stderr);
108+
assert.equal(JSON.parse(result.stdout).status, 'passed');
109+
} finally {
110+
parent.child.kill('SIGKILL');
111+
waiter?.child.kill('SIGTERM');
112+
if (commandPid) {
113+
try {
114+
process.kill(-commandPid, 'SIGKILL');
115+
} catch {}
116+
}
117+
await parent.wait;
118+
await waiter?.wait;
119+
fs.rmSync(cwd, { recursive: true, force: true });
109120
}
110-
await parent.wait;
111-
await waiter?.wait;
112-
fs.rmSync(cwd, { recursive: true, force: true });
113-
}
114-
});
121+
},
122+
);

‎scripts/check-affected/command-execution.ts‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ export async function executeValidationCommand(
2626
15_000,
2727
);
2828
let commandPid: number | undefined;
29-
const cancelTree = () => {
30-
if (commandPid !== undefined) lock.cancelCommand(commandPid);
31-
};
3229
try {
3330
lock.recordCommand(run.receiptPath, null);
3431
const output = await runCmdStreaming(
@@ -38,16 +35,13 @@ export async function executeValidationCommand(
3835
cwd,
3936
allowFailure: true,
4037
captureOutput: false,
41-
detached: process.platform !== 'win32',
38+
detached: true,
4239
kill: { signal: 'SIGTERM', graceMs: 5000 },
4340
signal: run.controller.signal,
4441
stdin: 'run\n',
4542
onSpawn: (child) => {
4643
commandPid = child.pid;
4744
if (commandPid) lock.recordCommand(run.receiptPath, commandPid);
48-
// Register before host-kit installs its abort handler, which can kill the wrapper.
49-
if (process.platform === 'win32')
50-
run.controller.signal.addEventListener('abort', cancelTree, { once: true });
5145
},
5246
env: {
5347
...process.env,
@@ -72,7 +66,6 @@ export async function executeValidationCommand(
7266
result.reason = error instanceof Error ? error.message : String(error);
7367
throw error;
7468
} finally {
75-
run.controller.signal.removeEventListener('abort', cancelTree);
7669
clearInterval(heartbeat);
7770
fs.closeSync(descriptor);
7871
result.durationMs = Date.now() - started;

0 commit comments

Comments
 (0)