Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(browser): navigate refuses a profile that disagrees with the target tab's connection

Dash3df0a9067c29
diff --git a/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/user-browser-backend.test.ts b/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/user-browser-backend.test.ts
index b387de3b32..05cc1b851b 100644
--- a/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/user-browser-backend.test.ts
+++ b/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/user-browser-backend.test.ts
@@ -682,6 +682,26 @@ describe('UserBrowserBackend · 读取与动作', () => {
expect(fake.jobs.length).toBe(jobsBefore);
});
+ // Review 2026-10-30 (Codex P1): a profile that disagrees with the tab's own connection must be refused.
+ it('navigate 的 targetId 与 profile 属于不同连接时拒绝', async () => {
+ const fake = fakeControl({
+ version: '0.4.56',
+ clients: ['client-aaaaaaaa', 'client-bbbbbbbb'],
+ tabs: { 'client-aaaaaaaa': [{ id: 1, url: 'https://a.test/' }], 'client-bbbbbbbb': [] },
+ });
+ const b = backend(fake.control);
+ const listed = (await call(b, { action: 'tabs', profile: 'client-aaaaaaaa' })) as {
+ data?: { tabs?: Array<{ targetId?: string }> };
+ };
+ const targetId = listed.data?.tabs?.[0]?.targetId;
+ expect(targetId).toBeTruthy();
+ const jobsBefore = fake.jobs.length;
+ expect(
+ await call(b, { action: 'navigate', targetId, profile: 'client-bbbbbbbb', url: 'https://c.test/' }),
+ ).toMatchObject({ ok: false, message: expect.stringContaining('不一致') });
+ expect(fake.jobs.length).toBe(jobsBefore);
+ });
+
// Review 2026-10-30 (Codex P1): an abbreviated profile that matches two connections must not pick one.
it('缩写的 profile 匹配多个连接时拒绝,精确 id 优先', async () => {
const fake = fakeControl({
diff --git a/apps/desktop/src/main/mcp-integrations/browser-backend/user-browser-backend.ts b/apps/desktop/src/main/mcp-integrations/browser-backend/user-browser-backend.ts
index 162f3c8c80..858c57472a 100644
--- a/apps/desktop/src/main/mcp-integrations/browser-backend/user-browser-backend.ts
+++ b/apps/desktop/src/main/mcp-integrations/browser-backend/user-browser-backend.ts
@@ -807,6 +807,14 @@ export class UserBrowserBackend implements BrowserBackend {
);
const picked = this.pickClient(req.action, gate.control, req.profile ?? existing?.clientId);
if (!picked.ok) return picked.result;
+ // The target tab belongs to one connection; a profile naming another would open the page there
+ // while the tab the agent meant never moves.
+ if (existing && existing.clientId !== picked.clientId)
+ return actionFailed(
+ req.action,
+ `标签页 ${req.targetId} 属于另一个浏览器连接,和 profile ${req.profile} 不一致;去掉 profile 或用 tabs 重新选择`,
+ 'BROWSER_RUNTIME_INVALID_REQUEST',
+ );
const label = typeof req.label === 'string' ? req.label : undefined;
if (this.parity(gate.control, picked.clientId)) {
// navigate 带 targetId:在原标签页跳转;否则新页开在 Cindy 自己的后台窗口,不碰用户的窗口。