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

@@ -128,6 +128,51 @@ describe('Agent Browser Host API routes', () => {
.toHaveBeenCalledWith('agent-browser:show', expect.objectContaining({ browserId: 'browser-1' }));
});
it('lets the trusted Renderer address the active project by id without exposing its path', async () => {
const projectPath = await temporaryProject('niancode-agent-browser-renderer-project-');
const open = vi.fn().mockResolvedValue(snapshot(projectPath));
const response = createResponse();
await handleAgentBrowserRoutes(
createRequest('POST', {
project_id: 'project-1',
url: 'http://127.0.0.1:5173',
bounds: { x: 10, y: 20, width: 640, height: 480 },
}, {
[RENDERER_CAPABILITY_HEADER]: getRendererCapability(),
}),
response.res,
new URL('http://127.0.0.1/api/agent-browser/open'),
context(projectPath, { open }),
);
expect(response.res.statusCode).toBe(200);
expect(open).toHaveBeenCalledWith(expect.objectContaining({
projectId: 'project-1',
projectPath,
}));
});
it('rejects project-id addressing without the Renderer capability', async () => {
const projectPath = await temporaryProject('niancode-agent-browser-untrusted-project-');
const open = vi.fn();
const response = createResponse();
await handleAgentBrowserRoutes(
createRequest('POST', {
project_id: 'project-1',
url: 'http://127.0.0.1:5173',
}),
response.res,
new URL('http://127.0.0.1/api/agent-browser/open'),
context(projectPath, { open }),
);
expect(response.res.statusCode).toBe(403);
expect(response.json()).toMatchObject({ success: false, code: 'TARGET_DENIED' });
expect(open).not.toHaveBeenCalled();
});
it('forwards only an explicit data-injection opt-in to the browser service', async () => {
const projectPath = await temporaryProject('niancode-agent-browser-preview-route-');
const open = vi.fn().mockResolvedValue(snapshot(projectPath));