fix(agent-browser): restore bounded presentation lifecycle

This commit is contained in:
2026-09-06 12:50:18 +08:00
parent 5c61110f46
commit 9fed0cc7c4
20 changed files with 1714 additions and 49 deletions

View File

@@ -5,6 +5,8 @@ import { tmpdir } from 'node:os';
import path from 'node:path';
import { afterEach, describe, expect, it } from 'vitest';
import { PiManagedExtensionHost } from '../../electron/coding-runtime/pi/extension-host';
import { AgentBrowserFault } from '../../electron/agent-browser/fault';
import type { PiProductTools } from '../../electron/coding-runtime/pi/product-tools';
import { PiProjectWriteLeaseCoordinator } from '../../electron/coding-runtime/pi/write-lease';
import {
PiSubagentChildError,
@@ -35,6 +37,42 @@ async function post(
}
describe('managed Pi extension bridge', () => {
it('preserves structured Agent Browser faults across the product bridge', async () => {
const root = await mkdtemp(path.join(tmpdir(), 'makelore-pi-extension-browser-fault-'));
roots.push(root);
const host = new PiManagedExtensionHost();
hosts.push(host);
host.configureProductTools({
beginRun: async () => undefined,
execute: async () => {
throw new AgentBrowserFault(
'VIEWPORT_NOT_READY',
'开发浏览器显示区域没有及时准备好。',
true,
7,
);
},
} as unknown as PiProductTools);
const registration = await host.registerWorker({
conversationId: 'conversation-a', generation: 1, projectId: 'project-a',
projectPath: root, extensionsDir: root,
});
await host.bindRun('conversation-a', 1, 'run-a');
const response = await post(registration, {
action: 'product.invoke', conversationId: 'conversation-a', workerGeneration: 1,
runId: 'run-a', resourceId: 'browser-a', toolName: 'agent_browser', input: { action: 'status' },
});
expect(response.status).toBe(400);
await expect(response.json()).resolves.toEqual({
code: 'VIEWPORT_NOT_READY',
error: 'VIEWPORT_NOT_READY: 开发浏览器显示区域没有及时准备好。',
retryable: true,
generation: 7,
});
});
it('single-flights the shared managed extension for concurrent worker registration', async () => {
const root = await mkdtemp(path.join(tmpdir(), 'makelore-pi-extension-concurrent-'));
roots.push(root);