Skip to content

Commit 517d66e

Browse files
authored
chore(web): bump managed agent-browser backend to 0.39.0 (#3591)
* chore(web): bump managed agent-browser backend to 0.39.0 (#3573) Off-viewport ref clicks now land (0/3 -> 3/3 on the pinned 3010px fixture). Fleet ownership (launch marker, daemon, managed-home matching) now spans every version directory under the state dir, so a backend left running by the previous pin stays owned and reapable. * fix(web): compute fleet ownership once per scan and list only version directories * fix(web): drop unused process-record exports and share isNoEntryError
1 parent 590f171 commit 517d66e

15 files changed

Lines changed: 316 additions & 102 deletions

‎packages/platform-web/src/__tests__/agent-browser-dispatch-disclosure.test.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// contracts/fixtures/dispatch-disclosure.json, web-agent-browser rows: each drives the real
22
// provider entry point over a scripted agent-browser CLI and asserts the `details.dispatched`
33
// (and `details.dispatchedSteps`) the failure leaves behind. The envelopes are what the managed
4-
// backend answers, including its typed CLI-refusal `type`; where the pinned 0.27.1 CLI cannot
4+
// backend answers, including its typed CLI-refusal `type`; where the pinned CLI cannot
55
// produce one for a current provider argv, that row's driver says so.
66
import assert from 'node:assert/strict';
77
import fs from 'node:fs';
@@ -49,7 +49,7 @@ async function withScriptedBackend(
4949

5050
/**
5151
* Agent-browser answers a command with argv it cannot run, before it contacts the browser daemon.
52-
* This is the verbatim 0.27.1 answer for the argv the driver below sends.
52+
* This is the verbatim answer of the pinned CLI (0.39.0) for the argv the driver below sends.
5353
*/
5454
function refuseMissingArguments(): ExecResult {
5555
return agentBrowserJsonResult({
@@ -61,7 +61,7 @@ function refuseMissingArguments(): ExecResult {
6161

6262
/**
6363
* Agent-browser answers a command it does not implement before it reaches the browser daemon. No
64-
* argv the current provider sends is unknown to 0.27.1, so this row covers the version skew where a
64+
* argv the current provider sends is unknown to the pinned CLI, so this row covers the version skew where a
6565
* newer provider meets an older managed backend; the envelope is what such a CLI answers.
6666
*/
6767
function refuseUnknownCommand(): ExecResult {
@@ -162,7 +162,7 @@ const DRIVERS: Record<string, { drive: () => Promise<unknown>; dispatchedSteps?:
162162
drive: () =>
163163
withScriptedBackend(refuseMissingArguments, async (provider) => {
164164
// `keyboard type` with nothing to type: the argv the provider really sends for an empty
165-
// typeText, which 0.27.1 refuses by type before it reaches the browser.
165+
// typeText, which the pinned CLI refuses by type before it reaches the browser.
166166
await provider.typeText('');
167167
}),
168168
},

‎packages/platform-web/src/__tests__/agent-browser-record-refresh.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ test('open re-derives the fleet record without consulting the probe', async () =
9292
});
9393

9494
test('recording re-derives the fleet record without consulting the probe', async () => {
95-
// 0.27.1's `record start` mints an ffmpeg child of the agent-browser daemon, outside Chrome's
95+
// The pinned CLI's `record start` mints an ffmpeg child of the agent-browser daemon, outside Chrome's
9696
// tree. The probe vouches for recorded pids only, so a scan is the only path that can own it.
9797
mockFleetRecordLive.mockResolvedValue(true);
9898
const executor = recordingAgentBrowserExecutor();

‎packages/platform-web/src/__tests__/agent-browser-snapshot-refless.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { describe, expect, test } from 'vitest';
33
import { normalizeAgentBrowserSnapshot } from '../agent-browser-snapshot.ts';
44

55
/**
6-
* Payloads captured from agent-browser 0.27.1 against a real page (`snapshot` with no `--compact`,
6+
* Payloads captured from agent-browser against a real page (re-checked on 0.39.0) (`snapshot` with no `--compact`,
77
* which is what the capture now asks for), so the projection is tested against the wording the
88
* backend actually produces rather than a hand-written approximation of it.
99
*/

‎packages/platform-web/src/__tests__/test-utils.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { vi } from 'vitest';
1313
import { createAgentBrowserWebProvider } from '../agent-browser-provider.ts';
1414
import type { WebProvider } from '../provider.ts';
1515

16-
const TEST_AGENT_BROWSER_VERSION = '0.27.1';
16+
const TEST_AGENT_BROWSER_VERSION = '0.39.0';
1717

1818
export function mkdtempForTestSync(prefix: string): string {
1919
return fs.mkdtempSync(path.join(os.tmpdir(), prefix));
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import { expect, test } from 'vitest';
4+
import { mkdtempForTestSync } from './__tests__/test-utils.ts';
5+
import { listManagedInstallPaths, managedInstallPaths } from './agent-browser-install-paths.ts';
6+
7+
test('install paths are keyed by state dir and version', () => {
8+
const stateDir = path.join(path.sep, 'state');
9+
const current = managedInstallPaths(stateDir, '0.39.0');
10+
11+
expect(current.installDir).toBe(path.join(stateDir, 'tools', 'agent-browser', '0.39.0'));
12+
expect(current.homeDir).toBe(path.join(current.installDir, 'home'));
13+
expect(managedInstallPaths(stateDir, '0.27.1').socketDir).not.toBe(current.socketDir);
14+
expect(managedInstallPaths(stateDir, '0.39.0')).toEqual(current);
15+
});
16+
17+
test('listing finds every installed version and tolerates a missing tools root', () => {
18+
const stateDir = mkdtempForTestSync('agent-device-web-installs-');
19+
try {
20+
expect(listManagedInstallPaths(stateDir)).toEqual([]);
21+
22+
for (const version of ['0.27.1', '0.39.0']) {
23+
fs.mkdirSync(managedInstallPaths(stateDir, version).installDir, { recursive: true });
24+
}
25+
26+
expect(
27+
listManagedInstallPaths(stateDir)
28+
.map(({ installDir }) => path.basename(installDir))
29+
.sort(),
30+
).toEqual(['0.27.1', '0.39.0']);
31+
} finally {
32+
fs.rmSync(stateDir, { recursive: true, force: true });
33+
}
34+
});
35+
36+
test('listing skips the install lock file beside the version directories', () => {
37+
const stateDir = mkdtempForTestSync('agent-device-web-installs-');
38+
try {
39+
const { installDir } = managedInstallPaths(stateDir, '0.39.0');
40+
fs.mkdirSync(installDir, { recursive: true });
41+
fs.writeFileSync(path.join(installDir, '..', '.agent-browser-install.lock'), '');
42+
43+
expect(listManagedInstallPaths(stateDir).map((install) => install.installDir)).toEqual([
44+
installDir,
45+
]);
46+
} finally {
47+
fs.rmSync(stateDir, { recursive: true, force: true });
48+
}
49+
});
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import crypto from 'node:crypto';
2+
import path from 'node:path';
3+
import {
4+
hostFileStatSync,
5+
hostTemporaryDirectory,
6+
readHostDirectorySync,
7+
} from '@agent-device/host-kit/host-file';
8+
import { hostPlatform } from '@agent-device/host-kit/process';
9+
10+
/** Everything that locates one version's managed install, its home, and its sockets. */
11+
export type ManagedInstallPaths = {
12+
stateDir: string;
13+
installDir: string;
14+
homeDir: string;
15+
runtimeHomeDir: string;
16+
socketDir: string;
17+
};
18+
19+
export function managedInstallPaths(stateDir: string, version: string): ManagedInstallPaths {
20+
const installDir = path.join(managedToolsRoot(stateDir), version);
21+
return {
22+
stateDir,
23+
installDir,
24+
homeDir: path.join(installDir, 'home'),
25+
runtimeHomeDir: resolveManagedRuntimeHomeDir(installDir),
26+
socketDir: resolveManagedSocketDir(installDir),
27+
};
28+
}
29+
30+
/**
31+
* Every version directory under the state dir's managed tools root. A backend left running by a
32+
* previous version lives in a sibling of the current install, so ownership of the fleet spans all of
33+
* them rather than the one the running pin names.
34+
*/
35+
export function listManagedInstallPaths(stateDir: string): ManagedInstallPaths[] {
36+
const root = managedToolsRoot(stateDir);
37+
let entries: string[];
38+
try {
39+
entries = readHostDirectorySync(root);
40+
} catch (error) {
41+
if (isNoEntryError(error)) return [];
42+
throw error;
43+
}
44+
return entries
45+
.filter((entry) => isDirectory(path.join(root, entry)))
46+
.map((version) => managedInstallPaths(stateDir, version));
47+
}
48+
49+
function managedToolsRoot(stateDir: string): string {
50+
return path.join(stateDir, 'tools', 'agent-browser');
51+
}
52+
53+
function resolveManagedRuntimeHomeDir(installDir: string): string {
54+
if (hostPlatform() === 'win32') return path.join(installDir, 'home');
55+
return path.join(hostTemporaryDirectory(), 'agent-device-web', installHash(installDir));
56+
}
57+
58+
function resolveManagedSocketDir(installDir: string): string {
59+
return path.join(hostTemporaryDirectory(), 'adw', installHash(installDir));
60+
}
61+
62+
function installHash(installDir: string): string {
63+
return crypto.createHash('sha1').update(installDir).digest('hex').slice(0, 12);
64+
}
65+
66+
function isDirectory(entryPath: string): boolean {
67+
try {
68+
return hostFileStatSync(entryPath).isDirectory();
69+
} catch (error) {
70+
if (isNoEntryError(error)) return false;
71+
throw error;
72+
}
73+
}
74+
75+
export function isNoEntryError(error: unknown): boolean {
76+
return typeof error === 'object' && error !== null && 'code' in error && error.code === 'ENOENT';
77+
}

‎packages/platform-web/src/agent-browser-lifecycle.test.ts‎

Lines changed: 104 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ import {
3030
agentBrowserChromeLaunchMarker,
3131
appendAgentDeviceChromeArgs,
3232
cleanupManagedAgentBrowserOrphans,
33-
matchAgentBrowserChromeProcess,
3433
resolveAgentBrowserIdleTimeoutMs,
35-
summarizeManagedAgentBrowserProcesses,
3634
summarizeAgentBrowserProcesses,
3735
} from './agent-browser-lifecycle.ts';
36+
import { managedInstallPaths } from './agent-browser-install-paths.ts';
3837
import { recordManagedAgentBrowserProcesses } from './agent-browser-process-record.ts';
3938
import { getManagedAgentBrowserStatus } from './agent-browser-tool.ts';
4039

@@ -87,6 +86,13 @@ test('managed agent-browser idle timeout defaults to five minutes and respects o
8786
);
8887
});
8988

89+
function matchChrome(
90+
processInfo: { pid: number; command: string },
91+
status: ReturnType<typeof getManagedAgentBrowserStatus>,
92+
) {
93+
return summarizeAgentBrowserProcesses([processInfo], status).processes[0];
94+
}
95+
9096
test('ownership detection accepts only Chrome-like processes with managed markers', () => {
9197
const stateDir = mkdtempForTestSync('agent-device-web-life-');
9298
try {
@@ -104,30 +110,24 @@ test('ownership detection accepts only Chrome-like processes with managed marker
104110
'Google Chrome for Testing',
105111
);
106112

107-
const markerMatch = matchAgentBrowserChromeProcess(
113+
const markerMatch = matchChrome(
108114
{ pid: 11, command: `/Applications/Chromium.app/Contents/MacOS/Chromium ${marker}` },
109115
status,
110116
);
111-
const homeMatch = matchAgentBrowserChromeProcess(
112-
{ pid: 12, command: `${managedChrome} --type=renderer` },
113-
status,
114-
);
115-
const userChrome = matchAgentBrowserChromeProcess(
117+
const homeMatch = matchChrome({ pid: 12, command: `${managedChrome} --type=renderer` }, status);
118+
const userChrome = matchChrome(
116119
{
117120
pid: 13,
118121
command:
119122
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome --profile-directory=Default',
120123
},
121124
status,
122125
);
123-
const broadRuntimeHome = matchAgentBrowserChromeProcess(
126+
const broadRuntimeHome = matchChrome(
124127
{ pid: 15, command: `${status.runtimeHomeDir}/profile-cache/chrome-helper` },
125128
status,
126129
);
127-
const markedNonBrowser = matchAgentBrowserChromeProcess(
128-
{ pid: 14, command: `/bin/sh -c echo ${marker}` },
129-
status,
130-
);
130+
const markedNonBrowser = matchChrome({ pid: 14, command: `/bin/sh -c echo ${marker}` }, status);
131131

132132
assert.equal(markerMatch?.reason, 'launch-marker');
133133
assert.equal(homeMatch?.reason, 'managed-browser-home');
@@ -320,18 +320,102 @@ test('records the managed browser daemon and Chrome fleet at the spawn owner', a
320320
}
321321
});
322322

323-
test('managed process summary includes the recordable agent-browser daemon', () => {
323+
function mockProcessList(lines: string[]) {
324+
mockRunCmd.mockResolvedValue({ stdout: lines.join('\n'), stderr: '', exitCode: 0 });
325+
}
326+
327+
test('recording the fleet owns the recordable agent-browser daemon', async () => {
328+
const stateDir = mkdtempForTestSync('agent-device-web-life-');
329+
try {
330+
installFakeManagedAgentBrowser(stateDir);
331+
const status = getManagedAgentBrowserStatus({ stateDir });
332+
const command = `${process.execPath} ${status.entryScript}`;
333+
const store = { replace: vi.fn(), clear: vi.fn(), read: vi.fn(() => []) };
334+
mockProcessList([` 101 1 ${command}`]);
335+
336+
const summary = await recordManagedAgentBrowserProcesses(status, store);
337+
338+
expect(summary.processes[0]?.reason).toBe('agent-browser-daemon');
339+
expect(store.replace).toHaveBeenCalledWith({ kind: 'daemon' }, [
340+
{ pid: 101, startTime: 'start-101', command: 'command-101', purpose: 'managed-web-browser' },
341+
]);
342+
} finally {
343+
fs.rmSync(stateDir, { recursive: true, force: true });
344+
}
345+
});
346+
347+
function installPreviousVersionFleet(stateDir: string) {
348+
const previous = managedInstallPaths(stateDir, '0.27.1');
349+
fs.mkdirSync(previous.installDir, { recursive: true });
350+
const entryScript = path.join(
351+
previous.installDir,
352+
'package',
353+
'node_modules',
354+
'agent-browser',
355+
'bin',
356+
'agent-browser.js',
357+
);
358+
return {
359+
previous,
360+
daemonCommand: `${process.execPath} ${entryScript}`,
361+
markedChromeCommand: `/Applications/Chromium.app/Contents/MacOS/Chromium ${agentBrowserChromeLaunchMarker(previous)}`,
362+
homeChromeCommand: `${path.join(previous.runtimeHomeDir, '.agent-browser', 'browsers')}/chrome-150/chrome --type=renderer`,
363+
};
364+
}
365+
366+
test('a fleet left running by a previous version stays owned after the pin moves', async () => {
367+
const stateDir = mkdtempForTestSync('agent-device-web-life-');
368+
try {
369+
installFakeManagedAgentBrowser(stateDir);
370+
const status = getManagedAgentBrowserStatus({ stateDir });
371+
const { previous, daemonCommand, markedChromeCommand, homeChromeCommand } =
372+
installPreviousVersionFleet(stateDir);
373+
assert.notEqual(previous.installDir, status.installDir);
374+
const store = { replace: vi.fn(), clear: vi.fn(), read: vi.fn(() => []) };
375+
mockProcessList([
376+
` 101 1 ${daemonCommand}`,
377+
` 201 1 ${markedChromeCommand}`,
378+
` 202 1 ${homeChromeCommand}`,
379+
' 999 1 /Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
380+
]);
381+
382+
const summary = await recordManagedAgentBrowserProcesses(status, store);
383+
384+
assert.deepEqual(summary.pids, [101, 201, 202]);
385+
assert.deepEqual(
386+
summary.processes.map(({ reason }) => reason),
387+
['agent-browser-daemon', 'launch-marker', 'managed-browser-home'],
388+
);
389+
expect(store.replace).toHaveBeenCalledWith(
390+
{ kind: 'daemon' },
391+
[101, 201, 202].map((pid) => ({
392+
pid,
393+
startTime: `start-${pid}`,
394+
command: `command-${pid}`,
395+
purpose: 'managed-web-browser',
396+
})),
397+
);
398+
} finally {
399+
fs.rmSync(stateDir, { recursive: true, force: true });
400+
}
401+
});
402+
403+
test('a previous version fleet from another state dir is not claimed', async () => {
324404
const stateDir = mkdtempForTestSync('agent-device-web-life-');
405+
const otherStateDir = mkdtempForTestSync('agent-device-web-life-other-');
325406
try {
326407
installFakeManagedAgentBrowser(stateDir);
327408
const status = getManagedAgentBrowserStatus({ stateDir });
328-
expect(
329-
summarizeManagedAgentBrowserProcesses(
330-
[{ pid: 101, command: `${process.execPath} ${status.entryScript}` }],
331-
status,
332-
).processes[0]?.reason,
333-
).toBe('agent-browser-daemon');
409+
const { daemonCommand, markedChromeCommand } = installPreviousVersionFleet(otherStateDir);
410+
const store = { replace: vi.fn(), clear: vi.fn(), read: vi.fn(() => []) };
411+
mockProcessList([` 101 1 ${daemonCommand}`, ` 201 1 ${markedChromeCommand}`]);
412+
413+
const summary = await recordManagedAgentBrowserProcesses(status, store);
414+
415+
assert.equal(summary.count, 0);
416+
expect(store.replace).not.toHaveBeenCalled();
334417
} finally {
335418
fs.rmSync(stateDir, { recursive: true, force: true });
419+
fs.rmSync(otherStateDir, { recursive: true, force: true });
336420
}
337421
});

‎packages/platform-web/src/agent-browser-lifecycle.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ export {
1515
agentBrowserChromeLaunchMarker,
1616
appendAgentDeviceChromeArgs,
1717
inspectManagedAgentBrowserProcesses,
18-
matchAgentBrowserChromeProcess,
1918
summarizeAgentBrowserProcesses,
20-
summarizeManagedAgentBrowserProcesses,
2119
} from './agent-browser-process-record.ts';
2220
export type { AgentBrowserProcessSummary } from './agent-browser-process-record.ts';
2321

0 commit comments

Comments
 (0)