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

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