conversation-session-browser-use-keypress-host-isolation.json 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. {
  2. "version": 1,
  3. "caseName": "conversation-session-browser-use-keypress-host-isolation",
  4. "spec": "./test/e2e/conversation-session/browser-use/conversation-session-browser-use-keypress-host-isolation.test.ts",
  5. "fixtures": [
  6. {
  7. "id": "upstream-browser-use-keypress-title",
  8. "description": "按键隔离用例的异步标题响应。",
  9. "metadata": {
  10. "kind": "common",
  11. "timingPolicy": "fast-text",
  12. "source": "synthetic",
  13. "syntheticReason": "标题不属于本用例语义,只需与 Browser tool continuation 隔离。"
  14. },
  15. "maxMatches": 1,
  16. "match": {
  17. "method": "POST",
  18. "pathIncludes": "/messages",
  19. "bodyIncludes": ["Generate a concise title", "E2E_BROWSER_USE_KEYPRESS_ISOLATION"]
  20. },
  21. "response": {
  22. "statusCode": 200,
  23. "text": "{\"title\": \"Browser 按键隔离\"}"
  24. }
  25. },
  26. {
  27. "id": "upstream-browser-use-keypress-action",
  28. "description": "打开测试页,只用页面脚本把焦点放进输入框(不点击),等测试让宿主 Composer 拿到焦点后,用 cua.keypress 依次按 a、b、Enter,打开 dialog 后按 Escape,回读页面状态。",
  29. "metadata": {
  30. "kind": "main",
  31. "timingPolicy": "fast-text",
  32. "source": "synthetic",
  33. "syntheticReason": "稳定制造「网页没有键盘焦点、宿主 Composer 有焦点」的时序,驱动真实 BrowserControl keypress 链路。"
  34. },
  35. "maxMatches": 1,
  36. "match": {
  37. "method": "POST",
  38. "pathIncludes": "/messages",
  39. "bodyIncludes": [
  40. "E2E_BROWSER_USE_KEYPRESS_ISOLATION",
  41. "E2E_BROWSER_FIXTURE_URL:",
  42. "mcp__node_repl__js"
  43. ],
  44. "bodyExcludes": [
  45. "Generate a concise title",
  46. "CRITICAL: Respond with TEXT ONLY",
  47. "toolu_e2e_browser_keypress_isolation"
  48. ]
  49. },
  50. "response": {
  51. "statusCode": 200,
  52. "toolUse": {
  53. "id": "toolu_e2e_browser_keypress_isolation",
  54. "name": "mcp__node_repl__js",
  55. "input": {
  56. "title": "在网页里按键",
  57. "code": "let e2eResult;\ntry {\n const browserPluginRoot = process.env.ZCODE_PLUGIN_ROOT ?? process.env.CLAUDE_PLUGIN_ROOT;\n if (!browserPluginRoot) throw new Error('Browser plugin root is unavailable in the node_repl host');\n const { join } = await import('node:path');\n const { pathToFileURL } = await import('node:url');\n const browserClientUrl = pathToFileURL(join(browserPluginRoot, 'scripts', 'browser-client.mjs')).href;\n const { setupBrowserRuntime } = await import(browserClientUrl);\n await setupBrowserRuntime({ globals: globalThis });\n const browser = await agent.browsers.get('iab');\n const tab = await browser.tabs.new();\n await tab.goto(new URL('/keys', '{{browserFixtureUrl}}').href);\n let inputFocused = false;\n for (let attempt = 0; attempt < 100 && !inputFocused; attempt += 1) {\n inputFocused = await tab.playwright.evaluate(() => { const input = document.getElementById('name'); input?.focus(); return input !== null && document.activeElement === input; });\n if (!inputFocused) await new Promise((resolve) => setTimeout(resolve, 100));\n }\n if (!inputFocused) throw new Error('keypress fixture input never received page focus');\n let gateOpen = false;\n for (let attempt = 0; attempt < 300 && !gateOpen; attempt += 1) {\n gateOpen = await tab.playwright.evaluate(() => window.__e2eGate === true);\n if (!gateOpen) await new Promise((resolve) => setTimeout(resolve, 100));\n }\n const guestFocusedBeforeKeys = await tab.playwright.evaluate(() => document.hasFocus());\n await tab.cua.keypress({ keys: ['a'] });\n await tab.cua.keypress({ keys: ['b'] });\n await tab.cua.keypress({ keys: ['Enter'] });\n await tab.playwright.evaluate(() => { document.getElementById('dialog').showModal(); });\n await tab.cua.keypress({ keys: ['Escape'] });\n const page = await tab.playwright.evaluate(() => ({ keys: window.__e2eKeys, submits: window.__e2eSubmits, value: document.getElementById('name').value, dialogOpen: document.getElementById('dialog').open }));\n const keypressOk = gateOpen && !guestFocusedBeforeKeys && page.value === 'ab' && page.submits === 1 && !page.dialogOpen && page.keys.join(',') === 'a,b,Enter,Escape';\n e2eResult = { marker: keypressOk ? 'E2E_BROWSER_USE_KEYPRESS_OK' : 'E2E_BROWSER_USE_KEYPRESS_FAILED', gateOpen, guestFocusedBeforeKeys, page };\n} catch (error) {\n e2eResult = { marker: 'E2E_BROWSER_USE_KEYPRESS_FAILED', error: error instanceof Error ? (error.stack ?? error.message) : String(error) };\n}\ne2eResult;"
  58. }
  59. }
  60. }
  61. },
  62. {
  63. "id": "upstream-browser-use-keypress-action-mcp-wait-1",
  64. "description": "Browser MCP 尚未就绪时执行第 1 次有界等待,工具出现后直接进入原业务动作。",
  65. "metadata": {
  66. "kind": "main",
  67. "source": "synthetic",
  68. "timingPolicy": "fast-text",
  69. "syntheticReason": "首请求不等 MCP;用真实等待工具推进普通 step,保留尚未就绪、就绪后调用两条回放路径。"
  70. },
  71. "maxMatches": 1,
  72. "match": {
  73. "method": "POST",
  74. "pathIncludes": "/messages",
  75. "bodyIncludes": [
  76. "E2E_BROWSER_USE_KEYPRESS_ISOLATION",
  77. "E2E_BROWSER_FIXTURE_URL:",
  78. "WaitForMcpServers"
  79. ],
  80. "bodyExcludes": [
  81. "mcp__node_repl__js",
  82. "Generate a concise title",
  83. "CRITICAL: Respond with TEXT ONLY",
  84. "toolu_e2e_browser_keypress_isolation"
  85. ]
  86. },
  87. "response": {
  88. "statusCode": 200,
  89. "toolUse": {
  90. "id": "toolu_upstream_browser_use_keypress_action_mcp_wait_1",
  91. "name": "WaitForMcpServers",
  92. "input": {
  93. "servers": ["node_repl"]
  94. }
  95. }
  96. }
  97. },
  98. {
  99. "id": "upstream-browser-use-keypress-action-mcp-wait-2",
  100. "description": "Browser MCP 尚未就绪时执行第 2 次有界等待,工具出现后直接进入原业务动作。",
  101. "metadata": {
  102. "kind": "main",
  103. "source": "synthetic",
  104. "timingPolicy": "fast-text",
  105. "syntheticReason": "首请求不等 MCP;用真实等待工具推进普通 step,保留尚未就绪、就绪后调用两条回放路径。"
  106. },
  107. "maxMatches": 1,
  108. "match": {
  109. "method": "POST",
  110. "pathIncludes": "/messages",
  111. "bodyIncludes": [
  112. "E2E_BROWSER_USE_KEYPRESS_ISOLATION",
  113. "E2E_BROWSER_FIXTURE_URL:",
  114. "WaitForMcpServers",
  115. "toolu_upstream_browser_use_keypress_action_mcp_wait_1"
  116. ],
  117. "bodyExcludes": [
  118. "mcp__node_repl__js",
  119. "Generate a concise title",
  120. "CRITICAL: Respond with TEXT ONLY",
  121. "toolu_e2e_browser_keypress_isolation"
  122. ],
  123. "lastUserMessageIncludes": ["Still connecting"]
  124. },
  125. "response": {
  126. "statusCode": 200,
  127. "toolUse": {
  128. "id": "toolu_upstream_browser_use_keypress_action_mcp_wait_2",
  129. "name": "WaitForMcpServers",
  130. "input": {
  131. "servers": ["node_repl"]
  132. }
  133. }
  134. }
  135. },
  136. {
  137. "id": "upstream-browser-use-keypress-action-mcp-wait-3",
  138. "description": "Browser MCP 尚未就绪时执行第 3 次有界等待,工具出现后直接进入原业务动作。",
  139. "metadata": {
  140. "kind": "main",
  141. "source": "synthetic",
  142. "timingPolicy": "fast-text",
  143. "syntheticReason": "首请求不等 MCP;用真实等待工具推进普通 step,保留尚未就绪、就绪后调用两条回放路径。"
  144. },
  145. "maxMatches": 1,
  146. "match": {
  147. "method": "POST",
  148. "pathIncludes": "/messages",
  149. "bodyIncludes": [
  150. "E2E_BROWSER_USE_KEYPRESS_ISOLATION",
  151. "E2E_BROWSER_FIXTURE_URL:",
  152. "WaitForMcpServers",
  153. "toolu_upstream_browser_use_keypress_action_mcp_wait_2"
  154. ],
  155. "bodyExcludes": [
  156. "mcp__node_repl__js",
  157. "Generate a concise title",
  158. "CRITICAL: Respond with TEXT ONLY",
  159. "toolu_e2e_browser_keypress_isolation"
  160. ],
  161. "lastUserMessageIncludes": ["Still connecting"]
  162. },
  163. "response": {
  164. "statusCode": 200,
  165. "toolUse": {
  166. "id": "toolu_upstream_browser_use_keypress_action_mcp_wait_3",
  167. "name": "WaitForMcpServers",
  168. "input": {
  169. "servers": ["node_repl"]
  170. }
  171. }
  172. }
  173. },
  174. {
  175. "id": "upstream-browser-use-keypress-final",
  176. "description": "按键结果正确时正常完成 turn;会话若被 Escape 停止则不会走到这一步。",
  177. "metadata": {
  178. "kind": "main",
  179. "timingPolicy": "fast-text",
  180. "source": "synthetic",
  181. "syntheticReason": "用正常完成证明 Escape 没有停止会话。"
  182. },
  183. "maxMatches": 1,
  184. "match": {
  185. "method": "POST",
  186. "pathIncludes": "/messages",
  187. "bodyIncludes": [
  188. "E2E_BROWSER_USE_KEYPRESS_ISOLATION",
  189. "toolu_e2e_browser_keypress_isolation"
  190. ],
  191. "lastUserMessageIncludes": ["E2E_BROWSER_USE_KEYPRESS_OK"],
  192. "bodyExcludes": ["Generate a concise title", "CRITICAL: Respond with TEXT ONLY"]
  193. },
  194. "response": {
  195. "statusCode": 200,
  196. "text": "E2E_BROWSER_USE_KEYPRESS_DONE"
  197. }
  198. }
  199. ]
  200. }