Skip to content

Commit 068992d

Browse files
committed
test: split the leak oracle's unrecorded process arm out of the lane path
Maintainer asked whether the harness can be trimmed. The two arms differ in kind: the daemon already records captures and state-dir artifacts, so those rules are short and fire on every lane run; nothing records what a daemon spawned, so the process arm reconstructs ownership from the OS four ways — and the three CLI daemon lanes are device-free, so it only ever compared an empty set to an empty set. Move that arm to test/integration/support/daemon-owned-process-probe.ts, the manual script that produced the #1109/#1324 evidence, and keep its rules pinned by a fixture test (no lane can run the probe, so its fixtures are the only CI guard on those shapes). The shipped oracle keeps every guarantee it had: surviving daemon at after-shutdown, the closed-session finalization rule, the state-dir allowlist, the CLI refusal, and the phase-discriminated types. Lane-path harness 852 → 548 LOC (-36%); repo total roughly flat, because the ownership reconstruction can be relocated but not deleted. That is the argument for the follow-up: once the daemon records owned child pids the way it records captures, the arm collapses to "read the record, assert they are dead" and moves back into the oracle. Re-proved after the move: #1324 against pre-fix a84caa8 on an iPhone 16 simulator still goes red through the probe (simctl recordVideo, ppid 1, pgid = the dead daemon, 0-byte mp4), and clean once the orphan is reaped. Refs #1781 #1431
1 parent e2c1139 commit 068992d

7 files changed

Lines changed: 358 additions & 362 deletions

‎.fallowrc.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
// subprocess (test/integration/daemon-replace-exit-flush.test.ts), so
2525
// dependency analysis cannot follow the runCmdSync string path to it.
2626
"test/integration/support/exit-after-flush.ts",
27+
// #1781 B1: the manual red-proof probe for daemon-owned child processes. It
28+
// is run by hand (and produced the #1109/#1324 evidence), so nothing imports
29+
// it; see its header for why that arm cannot assert from a device-free lane.
30+
"test/integration/support/daemon-owned-process-probe.ts",
2731
"src/utils/update-check-entry.ts",
2832
"examples/sdk/client-session.ts",
2933
"examples/sdk/metro-runtime.ts",

‎test/integration/support/daemon-leak-model.test.ts‎

Lines changed: 4 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,12 @@ import {
66
type DaemonLeakObservation,
77
type DaemonLeakObservationBase,
88
type DaemonLeakPhaseSelection,
9-
type HostProcess,
109
type NonEmpty,
1110
type StateEntry,
1211
} from './daemon-leak-model.ts';
1312

14-
// The lanes that call the oracle run device-free daemons, so the ownership rules
15-
// would otherwise only ever see an empty process set. These fixtures are the
16-
// real `ps` shapes captured during the #1109 and #1324 red-proofs (SHAs in the
17-
// #1781 B1 PR), so a regex or ordering edit that stops catching either leak
18-
// fails here instead of silently going quiet in CI.
1913
const STATE_DIR = '/tmp/agent-device-lane-abc';
2014
const DAEMON_PID = 4340;
21-
const OBSERVER_PID = 999;
22-
23-
function proc(overrides: Partial<HostProcess> & Pick<HostProcess, 'pid'>): HostProcess {
24-
return { ppid: 1, pgid: overrides.pid, command: 'unrelated', env: '', ...overrides };
25-
}
2615

2716
// The phase and its identity arrive together: `after-close` cannot be requested
2817
// without naming the sessions that closed, so these helpers cannot construct the
@@ -35,8 +24,6 @@ function observe(
3524
stateDir: STATE_DIR,
3625
daemonPids: [DAEMON_PID],
3726
livePids: [],
38-
processes: [],
39-
excludedPids: [OBSERVER_PID],
4027
stateEntries: [],
4128
...overrides,
4229
...selection,
@@ -57,72 +44,6 @@ function file(entryPath: string, descriptorLifecycle?: string): StateEntry {
5744
return { path: entryPath, kind: 'file', ...(descriptorLifecycle ? { descriptorLifecycle } : {}) };
5845
}
5946

60-
describe('owned-process rules', () => {
61-
// #1324: `simctl io … recordVideo` reparents to launchd (ppid 1) but keeps the
62-
// dead daemon's process group, and simctl only finalizes the mp4 on SIGINT.
63-
test('flags a recorder orphaned into the dead daemon process group', () => {
64-
const recorder = proc({
65-
pid: 52420,
66-
ppid: 1,
67-
pgid: DAEMON_PID,
68-
command: '/…/simctl io 416440AE recordVideo /tmp/out.mp4',
69-
});
70-
const snapshot = evaluateDaemonLeaks(observe({ processes: [recorder] }));
71-
72-
expect(snapshot.ownedProcesses).toEqual([
73-
expect.objectContaining({ pid: 52420, reasons: ['process-group'] }),
74-
]);
75-
expect(hasDaemonLeaks(snapshot)).toBe(true);
76-
});
77-
78-
// #1109: the agent-browser daemon setsids away from the daemon's group, so
79-
// only the inherited state-dir environment and its argv identify the fleet.
80-
test('flags an agent-browser fleet by inherited state dir, including its children', () => {
81-
const browserDaemon = proc({
82-
pid: 47515,
83-
ppid: 1,
84-
pgid: 47515,
85-
command: `${STATE_DIR}/tools/agent-browser/0.27.1/package/…/agent-browser-darwin-arm64`,
86-
env: `HOME=/tmp AGENT_DEVICE_STATE_DIR=${STATE_DIR}`,
87-
});
88-
const chrome = proc({
89-
pid: 47586,
90-
ppid: 47515,
91-
pgid: 47586,
92-
command: 'Google Chrome for Testing',
93-
});
94-
const renderer = proc({
95-
pid: 47953,
96-
ppid: 47586,
97-
pgid: 47586,
98-
command: 'Chrome Helper (Renderer)',
99-
});
100-
const snapshot = evaluateDaemonLeaks(observe({ processes: [browserDaemon, chrome, renderer] }));
101-
102-
expect(snapshot.ownedProcesses.map((owned) => owned.pid)).toEqual([47515, 47586, 47953]);
103-
expect(snapshot.ownedProcesses[0]?.reasons).toEqual(['state-dir-env', 'state-dir-argv']);
104-
// The fleet below the matched root is owned transitively, not by its own argv.
105-
expect(snapshot.ownedProcesses[1]?.reasons).toEqual(['descendant']);
106-
});
107-
108-
test('ignores foreign processes, the observer chain, and the daemons themselves', () => {
109-
const simulator = proc({ pid: 700, command: '/…/CoreSimulator … SimulatorTrampoline' });
110-
const neighbourStateDir = proc({
111-
pid: 701,
112-
command: `node --state-dir ${STATE_DIR}-other/daemon.ts`,
113-
env: `AGENT_DEVICE_STATE_DIR=${STATE_DIR}-other`,
114-
});
115-
const observer = proc({ pid: OBSERVER_PID, pgid: DAEMON_PID });
116-
const daemon = proc({ pid: DAEMON_PID, pgid: DAEMON_PID });
117-
const snapshot = evaluateDaemonLeaks(
118-
observe({ processes: [simulator, neighbourStateDir, observer, daemon] }),
119-
);
120-
121-
expect(snapshot.ownedProcesses).toEqual([]);
122-
expect(hasDaemonLeaks(snapshot)).toBe(false);
123-
});
124-
});
125-
12647
describe('surviving-daemon rule', () => {
12748
// stopProcessForTakeover is best-effort void: it returns silently on identity
12849
// mismatch, signal failure, or kill timeout, so a daemon can outlive the stop.
@@ -133,7 +54,9 @@ describe('surviving-daemon rule', () => {
13354

13455
expect(snapshot.liveDaemonPids).toEqual([DAEMON_PID]);
13556
expect(hasDaemonLeaks(snapshot)).toBe(true);
136-
expect(formatDaemonLeakReport(snapshot)).toContain('daemons that outlived shutdown: 1');
57+
expect(formatDaemonLeakReport(snapshot)).toContain(
58+
`daemons that outlived shutdown: ${DAEMON_PID}`,
59+
);
13760
});
13861

13962
test('its metadata files stay stray rather than being excused by its own survival', () => {
@@ -267,10 +190,7 @@ describe('closed-session capture handles', () => {
267190

268191
test('a clean shutdown reports no leak', () => {
269192
const snapshot = evaluateDaemonLeaks(
270-
observe({
271-
processes: [proc({ pid: 700, command: 'unrelated' })],
272-
stateEntries: [file('daemon.log'), file('sessions/default/events.ndjson')],
273-
}),
193+
observe({ stateEntries: [file('daemon.log'), file('sessions/default/events.ndjson')] }),
274194
);
275195

276196
expect(hasDaemonLeaks(snapshot)).toBe(false);

0 commit comments

Comments
 (0)