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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. "lastUserMessageIncludes": [
  40. "E2E_BROWSER_USE_KEYPRESS_ISOLATION",
  41. "E2E_BROWSER_FIXTURE_URL:"
  42. ],
  43. "bodyIncludes": ["mcp__node_repl__js"],
  44. "bodyExcludes": ["Generate a concise title", "CRITICAL: Respond with TEXT ONLY"]
  45. },
  46. "response": {
  47. "statusCode": 200,
  48. "toolUse": {
  49. "id": "toolu_e2e_browser_keypress_isolation",
  50. "name": "mcp__node_repl__js",
  51. "input": {
  52. "title": "在网页里按键",
  53. "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;"
  54. }
  55. }
  56. }
  57. },
  58. {
  59. "id": "upstream-browser-use-keypress-final",
  60. "description": "按键结果正确时正常完成 turn;会话若被 Escape 停止则不会走到这一步。",
  61. "metadata": {
  62. "kind": "main",
  63. "timingPolicy": "fast-text",
  64. "source": "synthetic",
  65. "syntheticReason": "用正常完成证明 Escape 没有停止会话。"
  66. },
  67. "maxMatches": 1,
  68. "match": {
  69. "method": "POST",
  70. "pathIncludes": "/messages",
  71. "bodyIncludes": [
  72. "E2E_BROWSER_USE_KEYPRESS_ISOLATION",
  73. "toolu_e2e_browser_keypress_isolation"
  74. ],
  75. "lastUserMessageIncludes": ["E2E_BROWSER_USE_KEYPRESS_OK"],
  76. "bodyExcludes": ["Generate a concise title", "CRITICAL: Respond with TEXT ONLY"]
  77. },
  78. "response": {
  79. "statusCode": 200,
  80. "text": "E2E_BROWSER_USE_KEYPRESS_DONE"
  81. }
  82. }
  83. ]
  84. }