{ "version": 1, "caseName": "conversation-session-browser-use-subagent-boundary", "spec": "./test/e2e/conversation-session/browser-use/conversation-session-browser-use-subagent-boundary.test.ts", "fixtures": [ { "id": "browser-subagent-boundary-title", "description": "固定 Browser subagent boundary case 的异步标题响应。", "metadata": { "kind": "common", "timingPolicy": "fast-text", "source": "synthetic", "syntheticReason": "标题不属于运行时 scope 边界,只需与父/child 请求隔离。" }, "maxMatches": 1, "match": { "method": "POST", "pathIncludes": "/messages", "bodyIncludes": ["Generate a concise title", "E2E_BROWSER_SUBAGENT_BOUNDARY_PARENT"] }, "response": { "statusCode": 200, "statusMessage": "OK", "headers": { "content-type": "application/json; charset=utf-8" }, "body": "{\"id\":\"browser-subagent-boundary-title\",\"type\":\"message\",\"role\":\"assistant\",\"model\":\"deepseek-v4-flash\",\"content\":[{\"type\":\"text\",\"text\":\"{\\\"title\\\":\\\"Browser 子智能体边界\\\"}\"}],\"stop_reason\":\"end_turn\",\"stop_sequence\":null,\"usage\":{\"input_tokens\":64,\"cache_creation_input_tokens\":0,\"cache_read_input_tokens\":0,\"output_tokens\":8,\"service_tier\":\"standard\"}}" } }, { "id": "browser-subagent-parent-init", "description": "主 Agent 初始化 Browser runtime、打开自己的 Tab 并写入 parent-before。", "metadata": { "kind": "main", "timingPolicy": "fast-text", "source": "synthetic", "syntheticReason": "通过真实 Node REPL 与 IAB guest 建立主 Agent 的 Tab,返回稳定 ID 供后续独立 Worker 找回同一页面。" }, "maxMatches": 1, "match": { "method": "POST", "pathIncludes": "/messages", "lastUserMessageIncludes": [ "E2E_BROWSER_SUBAGENT_BOUNDARY_PARENT", "E2E_BROWSER_FIXTURE_URL:" ], "bodyIncludes": ["mcp__node_repl__js"], "bodyExcludes": [ "toolu_e2e_browser_subagent_parent_init", "Generate a concise title", "CRITICAL: Respond with TEXT ONLY" ] }, "response": { "statusCode": 200, "toolUse": { "id": "toolu_e2e_browser_subagent_parent_init", "name": "mcp__node_repl__js", "input": { "title": "主 Agent 缓存 Browser 与 Tab", "code": "const browserPluginRoot = process.env.ZCODE_PLUGIN_ROOT ?? process.env.CLAUDE_PLUGIN_ROOT;\nif (!browserPluginRoot) throw new Error('Browser plugin root is unavailable in the node_repl host');\nconst { join } = await import('node:path');\nconst { pathToFileURL } = await import('node:url');\nglobalThis.boundaryBrowserClientUrl = pathToFileURL(join(browserPluginRoot, 'scripts', 'browser-client.mjs')).href;\nconst browserClientModule = await import(boundaryBrowserClientUrl);\nglobalThis.boundarySetupBrowserRuntime = browserClientModule.setupBrowserRuntime;\nif (globalThis.agent?.browsers == null) await boundarySetupBrowserRuntime({ globals: globalThis });\nglobalThis.boundaryBrowser = await agent.browsers.get('iab');\nglobalThis.boundaryTab = await boundaryBrowser.tabs.new();\nawait boundaryTab.goto('{{browserFixtureUrl}}');\nawait boundaryTab.playwright.getByLabel('State').fill('parent-before');\nconst parentTabsBefore = await boundaryBrowser.tabs.list();\nglobalThis.boundaryParentTabId = boundaryTab.id;\n({ marker: parentTabsBefore.length === 1 && parentTabsBefore[0]?.id === boundaryParentTabId ? 'E2E_BROWSER_SUBAGENT_PARENT_INIT_OK' : 'E2E_BROWSER_SUBAGENT_PARENT_INIT_FAILED', tabId: boundaryParentTabId, e2eBrowserTabAId: boundaryParentTabId, tabs: parentTabsBefore });" } } } }, { "id": "browser-subagent-parent-agent", "description": "主 Agent 收到初始化结果后启动 foreground general-purpose child。", "metadata": { "kind": "main", "timingPolicy": "fast-text", "source": "synthetic", "syntheticReason": "显式传递页面 URL 和主 Tab ID,子代理在独立 Worker 中验证当前对话的浏览器归属。" }, "maxMatches": 1, "match": { "method": "POST", "pathIncludes": "/messages", "bodyIncludes": [ "E2E_BROWSER_SUBAGENT_BOUNDARY_PARENT", "toolu_e2e_browser_subagent_parent_init" ], "lastUserMessageIncludes": ["E2E_BROWSER_SUBAGENT_PARENT_INIT_OK"], "bodyExcludes": ["Generate a concise title", "CRITICAL: Respond with TEXT ONLY"] }, "response": { "statusCode": 200, "toolUse": { "id": "toolu_e2e_browser_subagent_agent", "name": "Agent", "input": { "description": "Verify Browser Use in subagent", "prompt": "E2E_BROWSER_SUBAGENT_BOUNDARY_CHILD: list the conversation's Browser tabs and open one more with Node REPL as instructed. Reply exactly E2E_BROWSER_SUBAGENT_BOUNDARY_CHILD_DONE after the checks pass. E2E_BROWSER_FIXTURE_URL:{{browserFixtureUrl}} Parent tab facts: {\"e2eBrowserTabAId\":\"{{latestBrowserTabAId}}\"}.", "subagent_type": "general-purpose" } } } }, { "id": "browser-subagent-child-browse", "description": "Child 看到对话已有的 Tab,再打开一个新 Tab 并完成一次填写。", "metadata": { "kind": "main", "timingPolicy": "fast-text", "source": "synthetic", "syntheticReason": "验证 runtime_scope=subagent 的真实 MCP call 以当前对话为 tab 归属:能列出主 Agent 的 Tab,新开的 Tab 也属于同一对话。" }, "maxMatches": 1, "match": { "method": "POST", "pathIncludes": "/messages", "lastUserMessageIncludes": ["E2E_BROWSER_SUBAGENT_BOUNDARY_CHILD"], "bodyIncludes": ["E2E_BROWSER_SUBAGENT_BOUNDARY_CHILD", "mcp__node_repl__js"], "bodyExcludes": [ "toolu_e2e_browser_subagent_child_check", "Generate a concise title", "CRITICAL: Respond with TEXT ONLY" ] }, "response": { "statusCode": 200, "toolUse": { "id": "toolu_e2e_browser_subagent_child_check", "name": "mcp__node_repl__js", "input": { "title": "Child 在对话 Browser 中开 Tab", "code": "const browserPluginRoot = process.env.ZCODE_PLUGIN_ROOT ?? process.env.CLAUDE_PLUGIN_ROOT;\nif (!browserPluginRoot) throw new Error('Browser plugin root is unavailable in the node_repl host');\nconst { join } = await import('node:path');\nconst { pathToFileURL } = await import('node:url');\nconst { setupBrowserRuntime } = await import(pathToFileURL(join(browserPluginRoot, 'scripts', 'browser-client.mjs')).href);\nif (globalThis.agent?.browsers == null) await setupBrowserRuntime({ globals: globalThis });\nconst ordinaryValue = 6 * 7;\nconst childBrowser = await agent.browsers.get('iab');\nconst tabsBefore = await childBrowser.tabs.list();\nconst seesParentTab = tabsBefore.some((tab) => tab.id === '{{latestBrowserTabAId}}');\nconst childTab = await childBrowser.tabs.new();\nawait childTab.goto('{{browserFixtureUrl}}?child=1');\nawait childTab.playwright.getByLabel('State').fill('child-owned');\nconst childState = await childTab.playwright.getByRole('status').innerText();\nconst tabsAfter = await childBrowser.tabs.list();\nconst sharesConversationTabs = tabsAfter.some((tab) => tab.id === childTab.id) && tabsAfter.some((tab) => tab.id === '{{latestBrowserTabAId}}');\n({ marker: ordinaryValue === 42 && seesParentTab && childState === 'child-owned' && sharesConversationTabs ? 'E2E_BROWSER_SUBAGENT_BOUNDARY_CHECKS_OK' : 'E2E_BROWSER_SUBAGENT_BOUNDARY_CHECKS_FAILED', ordinaryValue, seesParentTab, childState, childTabId: childTab.id, tabsAfter });" } } } }, { "id": "browser-subagent-child-final", "description": "Child 消费 Browser 检查结果并完成。", "metadata": { "kind": "main", "timingPolicy": "fast-text", "source": "synthetic", "syntheticReason": "child 结束不关 Tab,让父 Agent 收到 Agent tool_result 后复验两个 Tab 都在。" }, "maxMatches": 1, "match": { "method": "POST", "pathIncludes": "/messages", "bodyIncludes": [ "E2E_BROWSER_SUBAGENT_BOUNDARY_CHILD", "toolu_e2e_browser_subagent_child_check" ], "lastUserMessageIncludes": ["E2E_BROWSER_SUBAGENT_BOUNDARY_CHECKS_OK"], "bodyExcludes": ["Generate a concise title", "CRITICAL: Respond with TEXT ONLY"] }, "response": { "statusCode": 200, "text": "E2E_BROWSER_SUBAGENT_BOUNDARY_CHILD_DONE" } }, { "id": "browser-subagent-parent-resume", "description": "主 Agent 收到 child 结果后复用原 Tab,并确认 child 开的 Tab 仍在对话里。", "metadata": { "kind": "main", "timingPolicy": "fast-text", "source": "synthetic", "syntheticReason": "证明 child 没有改动主 Agent 的 Tab,且 child 开的 Tab 随子代理结束保留在当前对话。" }, "maxMatches": 1, "match": { "method": "POST", "pathIncludes": "/messages", "bodyIncludes": [ "E2E_BROWSER_SUBAGENT_BOUNDARY_PARENT", "toolu_e2e_browser_subagent_agent", "E2E_BROWSER_SUBAGENT_BOUNDARY_CHILD_DONE" ], "bodyExcludes": [ "toolu_e2e_browser_subagent_parent_resume", "Generate a concise title", "CRITICAL: Respond with TEXT ONLY" ] }, "response": { "statusCode": 200, "toolUse": { "id": "toolu_e2e_browser_subagent_parent_resume", "name": "mcp__node_repl__js", "input": { "title": "主 Agent 按稳定 ID 找回原 Browser Tab", "code": "const browserPluginRoot = process.env.ZCODE_PLUGIN_ROOT ?? process.env.CLAUDE_PLUGIN_ROOT;\nif (!browserPluginRoot) throw new Error('Browser plugin root is unavailable in the node_repl host');\nconst { join } = await import('node:path');\nconst { pathToFileURL } = await import('node:url');\nconst { setupBrowserRuntime } = await import(pathToFileURL(join(browserPluginRoot, 'scripts', 'browser-client.mjs')).href);\nif (globalThis.agent?.browsers == null) await setupBrowserRuntime({ globals: globalThis });\nconst boundaryBrowser = await agent.browsers.get('iab');\nconst boundaryParentTabId = '{{latestBrowserTabAId}}';\nconst boundaryTab = await boundaryBrowser.tabs.get(boundaryParentTabId);\nconst stateBeforeResume = await boundaryTab.playwright.getByRole('status').innerText();\nawait boundaryTab.playwright.getByLabel('State').fill('parent-after');\nconst parentTabsAfter = await boundaryBrowser.tabs.list();\nconst keepsParentTab = parentTabsAfter.some((tab) => tab.id === boundaryParentTabId) && boundaryTab.id === boundaryParentTabId;\nconst keepsChildTab = parentTabsAfter.some((tab) => tab.id !== boundaryParentTabId && String(tab.url ?? '').includes('child=1'));\n({ marker: stateBeforeResume === 'parent-before' && keepsParentTab && keepsChildTab ? 'E2E_BROWSER_SUBAGENT_PARENT_RESUME_OK' : 'E2E_BROWSER_SUBAGENT_PARENT_RESUME_FAILED', stateBeforeResume, tabId: boundaryTab.id, tabs: parentTabsAfter });" } } } }, { "id": "browser-subagent-parent-final", "description": "主 Agent 消费复用结果并正常完成。", "metadata": { "kind": "main", "timingPolicy": "fast-text", "source": "synthetic", "syntheticReason": "形成正常 turn complete,供 E2E 在最终边界复验同一 guest。" }, "maxMatches": 1, "match": { "method": "POST", "pathIncludes": "/messages", "bodyIncludes": [ "E2E_BROWSER_SUBAGENT_BOUNDARY_PARENT", "toolu_e2e_browser_subagent_parent_resume" ], "lastUserMessageIncludes": ["E2E_BROWSER_SUBAGENT_PARENT_RESUME_OK"], "bodyExcludes": ["Generate a concise title", "CRITICAL: Respond with TEXT ONLY"] }, "response": { "statusCode": 200, "text": "E2E_BROWSER_SUBAGENT_BOUNDARY_DONE" } } ] }