conversation-session-browser-use-subagent-boundary.json 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. {
  2. "version": 1,
  3. "caseName": "conversation-session-browser-use-subagent-boundary",
  4. "spec": "./test/e2e/conversation-session/browser-use/conversation-session-browser-use-subagent-boundary.test.ts",
  5. "fixtures": [
  6. {
  7. "id": "browser-subagent-boundary-title",
  8. "description": "固定 Browser subagent boundary case 的异步标题响应。",
  9. "metadata": {
  10. "kind": "common",
  11. "timingPolicy": "fast-text",
  12. "source": "synthetic",
  13. "syntheticReason": "标题不属于运行时 scope 边界,只需与父/child 请求隔离。"
  14. },
  15. "maxMatches": 1,
  16. "match": {
  17. "method": "POST",
  18. "pathIncludes": "/messages",
  19. "bodyIncludes": ["Generate a concise title", "E2E_BROWSER_SUBAGENT_BOUNDARY_PARENT"]
  20. },
  21. "response": {
  22. "statusCode": 200,
  23. "statusMessage": "OK",
  24. "headers": {
  25. "content-type": "application/json; charset=utf-8"
  26. },
  27. "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\"}}"
  28. }
  29. },
  30. {
  31. "id": "browser-subagent-parent-init",
  32. "description": "主 Agent 初始化 Browser runtime、打开自己的 Tab 并写入 parent-before。",
  33. "metadata": {
  34. "kind": "main",
  35. "timingPolicy": "fast-text",
  36. "source": "synthetic",
  37. "syntheticReason": "通过真实 Node REPL 与 IAB guest 建立主 Agent 的 Tab,返回稳定 ID 供后续独立 Worker 找回同一页面。"
  38. },
  39. "maxMatches": 1,
  40. "match": {
  41. "method": "POST",
  42. "pathIncludes": "/messages",
  43. "lastUserMessageIncludes": [
  44. "E2E_BROWSER_SUBAGENT_BOUNDARY_PARENT",
  45. "E2E_BROWSER_FIXTURE_URL:"
  46. ],
  47. "bodyIncludes": ["mcp__node_repl__js"],
  48. "bodyExcludes": [
  49. "toolu_e2e_browser_subagent_parent_init",
  50. "Generate a concise title",
  51. "CRITICAL: Respond with TEXT ONLY"
  52. ]
  53. },
  54. "response": {
  55. "statusCode": 200,
  56. "toolUse": {
  57. "id": "toolu_e2e_browser_subagent_parent_init",
  58. "name": "mcp__node_repl__js",
  59. "input": {
  60. "title": "主 Agent 缓存 Browser 与 Tab",
  61. "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 });"
  62. }
  63. }
  64. }
  65. },
  66. {
  67. "id": "browser-subagent-parent-agent",
  68. "description": "主 Agent 收到初始化结果后启动 foreground general-purpose child。",
  69. "metadata": {
  70. "kind": "main",
  71. "timingPolicy": "fast-text",
  72. "source": "synthetic",
  73. "syntheticReason": "显式传递页面 URL 和主 Tab ID,子代理在独立 Worker 中验证当前对话的浏览器归属。"
  74. },
  75. "maxMatches": 1,
  76. "match": {
  77. "method": "POST",
  78. "pathIncludes": "/messages",
  79. "bodyIncludes": [
  80. "E2E_BROWSER_SUBAGENT_BOUNDARY_PARENT",
  81. "toolu_e2e_browser_subagent_parent_init"
  82. ],
  83. "lastUserMessageIncludes": ["E2E_BROWSER_SUBAGENT_PARENT_INIT_OK"],
  84. "bodyExcludes": ["Generate a concise title", "CRITICAL: Respond with TEXT ONLY"]
  85. },
  86. "response": {
  87. "statusCode": 200,
  88. "toolUse": {
  89. "id": "toolu_e2e_browser_subagent_agent",
  90. "name": "Agent",
  91. "input": {
  92. "description": "Verify Browser Use in subagent",
  93. "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}}\"}.",
  94. "subagent_type": "general-purpose"
  95. }
  96. }
  97. }
  98. },
  99. {
  100. "id": "browser-subagent-child-browse",
  101. "description": "Child 看到对话已有的 Tab,再打开一个新 Tab 并完成一次填写。",
  102. "metadata": {
  103. "kind": "main",
  104. "timingPolicy": "fast-text",
  105. "source": "synthetic",
  106. "syntheticReason": "验证 runtime_scope=subagent 的真实 MCP call 以当前对话为 tab 归属:能列出主 Agent 的 Tab,新开的 Tab 也属于同一对话。"
  107. },
  108. "maxMatches": 1,
  109. "match": {
  110. "method": "POST",
  111. "pathIncludes": "/messages",
  112. "lastUserMessageIncludes": ["E2E_BROWSER_SUBAGENT_BOUNDARY_CHILD"],
  113. "bodyIncludes": ["E2E_BROWSER_SUBAGENT_BOUNDARY_CHILD", "mcp__node_repl__js"],
  114. "bodyExcludes": [
  115. "toolu_e2e_browser_subagent_child_check",
  116. "Generate a concise title",
  117. "CRITICAL: Respond with TEXT ONLY"
  118. ]
  119. },
  120. "response": {
  121. "statusCode": 200,
  122. "toolUse": {
  123. "id": "toolu_e2e_browser_subagent_child_check",
  124. "name": "mcp__node_repl__js",
  125. "input": {
  126. "title": "Child 在对话 Browser 中开 Tab",
  127. "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 });"
  128. }
  129. }
  130. }
  131. },
  132. {
  133. "id": "browser-subagent-child-final",
  134. "description": "Child 消费 Browser 检查结果并完成。",
  135. "metadata": {
  136. "kind": "main",
  137. "timingPolicy": "fast-text",
  138. "source": "synthetic",
  139. "syntheticReason": "child 结束不关 Tab,让父 Agent 收到 Agent tool_result 后复验两个 Tab 都在。"
  140. },
  141. "maxMatches": 1,
  142. "match": {
  143. "method": "POST",
  144. "pathIncludes": "/messages",
  145. "bodyIncludes": [
  146. "E2E_BROWSER_SUBAGENT_BOUNDARY_CHILD",
  147. "toolu_e2e_browser_subagent_child_check"
  148. ],
  149. "lastUserMessageIncludes": ["E2E_BROWSER_SUBAGENT_BOUNDARY_CHECKS_OK"],
  150. "bodyExcludes": ["Generate a concise title", "CRITICAL: Respond with TEXT ONLY"]
  151. },
  152. "response": {
  153. "statusCode": 200,
  154. "text": "E2E_BROWSER_SUBAGENT_BOUNDARY_CHILD_DONE"
  155. }
  156. },
  157. {
  158. "id": "browser-subagent-parent-resume",
  159. "description": "主 Agent 收到 child 结果后复用原 Tab,并确认 child 开的 Tab 仍在对话里。",
  160. "metadata": {
  161. "kind": "main",
  162. "timingPolicy": "fast-text",
  163. "source": "synthetic",
  164. "syntheticReason": "证明 child 没有改动主 Agent 的 Tab,且 child 开的 Tab 随子代理结束保留在当前对话。"
  165. },
  166. "maxMatches": 1,
  167. "match": {
  168. "method": "POST",
  169. "pathIncludes": "/messages",
  170. "bodyIncludes": [
  171. "E2E_BROWSER_SUBAGENT_BOUNDARY_PARENT",
  172. "toolu_e2e_browser_subagent_agent",
  173. "E2E_BROWSER_SUBAGENT_BOUNDARY_CHILD_DONE"
  174. ],
  175. "bodyExcludes": [
  176. "toolu_e2e_browser_subagent_parent_resume",
  177. "Generate a concise title",
  178. "CRITICAL: Respond with TEXT ONLY"
  179. ]
  180. },
  181. "response": {
  182. "statusCode": 200,
  183. "toolUse": {
  184. "id": "toolu_e2e_browser_subagent_parent_resume",
  185. "name": "mcp__node_repl__js",
  186. "input": {
  187. "title": "主 Agent 按稳定 ID 找回原 Browser Tab",
  188. "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 });"
  189. }
  190. }
  191. }
  192. },
  193. {
  194. "id": "browser-subagent-parent-final",
  195. "description": "主 Agent 消费复用结果并正常完成。",
  196. "metadata": {
  197. "kind": "main",
  198. "timingPolicy": "fast-text",
  199. "source": "synthetic",
  200. "syntheticReason": "形成正常 turn complete,供 E2E 在最终边界复验同一 guest。"
  201. },
  202. "maxMatches": 1,
  203. "match": {
  204. "method": "POST",
  205. "pathIncludes": "/messages",
  206. "bodyIncludes": [
  207. "E2E_BROWSER_SUBAGENT_BOUNDARY_PARENT",
  208. "toolu_e2e_browser_subagent_parent_resume"
  209. ],
  210. "lastUserMessageIncludes": ["E2E_BROWSER_SUBAGENT_PARENT_RESUME_OK"],
  211. "bodyExcludes": ["Generate a concise title", "CRITICAL: Respond with TEXT ONLY"]
  212. },
  213. "response": {
  214. "statusCode": 200,
  215. "text": "E2E_BROWSER_SUBAGENT_BOUNDARY_DONE"
  216. }
  217. }
  218. ]
  219. }