Skip to content

Commit a4a1110

Browse files
committed
test(runtime): pin host command ownership without timing races
1 parent e72d95f commit a4a1110

3 files changed

Lines changed: 28 additions & 5 deletions

File tree

‎src/platform-runtime-host-command-runner.test.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
} from '@agent-device/host-kit/command';
1212
import { createHostCommandRunner } from './platform-runtime-host-command-runner.ts';
1313

14-
/** A child that answers only after a pause, so a deadline or a cancel always arrives first. */
1514
const DELAYED_CHILD = ['-e', 'setTimeout(() => process.stdout.write("finished"), 300)'];
1615

1716
type DispatchedCommand = Readonly<{
@@ -153,7 +152,11 @@ test('the deadline a request names bounds the command the port runs', async () =
153152
const commands = createHostCommandRunner({ env: process.env, cwd: process.cwd() });
154153

155154
await expect(
156-
commands.run({ executable: process.execPath, args: DELAYED_CHILD, timeoutMs: 100 }),
155+
commands.run({
156+
executable: process.execPath,
157+
args: ['-e', 'setTimeout(() => {}, 10_000)'],
158+
timeoutMs: 100,
159+
}),
157160
).rejects.toSatisfy(isCommandTimeoutError);
158161
});
159162

‎src/platform-runtime-host-command-runner.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import { runCmd, whichCmd } from '@agent-device/host-kit/command';
77
import { guardedHostCommandArgv } from './platform-runtime-host-device-shell.ts';
88

99
/**
10-
* The host command port both runtime hosts expose, built from the host environment each was handed
11-
* rather than the process one (#3794). A request that names no `env` is dispatched without an
12-
* environment, so the command host enclosing the call keeps owning what that command inherits.
10+
* Uses host.env for lookup and explicit request overlays. Only request.cwd sets the spawn directory.
11+
* Without request.env, the enclosing command host owns environment inheritance.
1312
*/
1413
export function createHostCommandRunner(host: HostEnvironment): HostCommandRunner {
1514
const env = host.env;

‎src/platform-runtime-host.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,27 @@ test('inventory host loads scoped Apple mechanics only on first Apple tool use',
4949
expect(toolchains.appleRuns).toEqual([{ args: ['devicectl', 'list', 'devices'], signal }]);
5050
});
5151

52+
test.skipIf(process.platform === 'win32')(
53+
'inventory command lookup uses the supplied host PATH',
54+
async () => {
55+
const directory = mkdtempForTestSync('inventory-host-command-path-');
56+
const executable = path.join(directory, 'inventory-host-only-probe');
57+
writeFileSync(executable, '#!/bin/sh\nexit 0\n');
58+
chmodSync(executable, 0o755);
59+
60+
await expect(
61+
createDeviceInventoryHost({ env: { PATH: directory }, cwd: directory }).commands.which(
62+
'inventory-host-only-probe',
63+
),
64+
).resolves.toBe('inventory-host-only-probe');
65+
await expect(
66+
createDeviceInventoryHost({ env: { PATH: '' }, cwd: directory }).commands.which(
67+
'inventory-host-only-probe',
68+
),
69+
).resolves.toBeUndefined();
70+
},
71+
);
72+
5273
test('vega inventory resolves the CLI from the host home, not the process home', async () => {
5374
// The rule: every Vega executable lookup in one runtime resolves from that runtime host's
5475
// PATH and home. This host's HOME differs from the process HOME and names a default-install

0 commit comments

Comments
 (0)