spana-test 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/.agents/skills/spana-testing/SKILL.md +0 -0
  2. package/LICENSE +0 -0
  3. package/README.md +199 -68
  4. package/dist/{accessibility-audit-RS3VIWRT.js → accessibility-audit-YZOPUY3D.js} +7 -3
  5. package/dist/accessibility-audit-YZOPUY3D.js.map +1 -0
  6. package/dist/agent/index.d.ts +3 -84
  7. package/dist/agent/index.js +11 -10
  8. package/dist/agent/index.js.map +0 -0
  9. package/dist/allure-RNMEYTXS.js +0 -0
  10. package/dist/allure-RNMEYTXS.js.map +0 -0
  11. package/dist/{android-GFW6OXPQ.js → android-4NVTZMHL.js} +6 -2
  12. package/dist/{android-GFW6OXPQ.js.map → android-4NVTZMHL.js.map} +0 -0
  13. package/dist/appium-server-66GVUL24.js +0 -0
  14. package/dist/appium-server-66GVUL24.js.map +0 -0
  15. package/dist/baseline-manager-5TIUCNP5.js +0 -0
  16. package/dist/baseline-manager-5TIUCNP5.js.map +0 -0
  17. package/dist/chunk-3FSZNKEF.js +0 -0
  18. package/dist/chunk-3FSZNKEF.js.map +0 -0
  19. package/dist/chunk-3TRMQCUT.js +0 -0
  20. package/dist/chunk-3TRMQCUT.js.map +0 -0
  21. package/dist/chunk-3YE2POGD.js +471 -0
  22. package/dist/chunk-3YE2POGD.js.map +1 -0
  23. package/dist/chunk-5245YBLL.js +0 -0
  24. package/dist/chunk-5245YBLL.js.map +0 -0
  25. package/dist/{chunk-3J4NG7JU.js → chunk-CY3DKTBZ.js} +8 -2
  26. package/dist/chunk-CY3DKTBZ.js.map +1 -0
  27. package/dist/chunk-DGUM43GV.js +0 -0
  28. package/dist/chunk-DGUM43GV.js.map +0 -0
  29. package/dist/chunk-DTNK54C2.js +127 -0
  30. package/dist/chunk-DTNK54C2.js.map +1 -0
  31. package/dist/{chunk-EWIR2GVV.js → chunk-H27IBIGA.js} +19 -2
  32. package/dist/chunk-H27IBIGA.js.map +1 -0
  33. package/dist/chunk-H3RWZCID.js +439 -0
  34. package/dist/chunk-H3RWZCID.js.map +1 -0
  35. package/dist/{chunk-PZYZ4O6D.js → chunk-HCG4CJKR.js} +23 -5
  36. package/dist/chunk-HCG4CJKR.js.map +1 -0
  37. package/dist/{chunk-YGHDMA6D.js → chunk-HYSTRWYN.js} +142 -41
  38. package/dist/chunk-HYSTRWYN.js.map +1 -0
  39. package/dist/chunk-IHVZKQQW.js +0 -0
  40. package/dist/chunk-IHVZKQQW.js.map +0 -0
  41. package/dist/chunk-KJPHH2TW.js +0 -0
  42. package/dist/chunk-KJPHH2TW.js.map +0 -0
  43. package/dist/chunk-LAMTF4LX.js +89 -0
  44. package/dist/chunk-LAMTF4LX.js.map +1 -0
  45. package/dist/chunk-LRGT342X.js +2300 -0
  46. package/dist/chunk-LRGT342X.js.map +1 -0
  47. package/dist/chunk-OBCFACUW.js +0 -0
  48. package/dist/chunk-OBCFACUW.js.map +0 -0
  49. package/dist/chunk-PJKIXVSO.js +5019 -0
  50. package/dist/chunk-PJKIXVSO.js.map +1 -0
  51. package/dist/chunk-S5JNNDXS.js +0 -0
  52. package/dist/chunk-S5JNNDXS.js.map +0 -0
  53. package/dist/{chunk-7VOWF42B.js → chunk-SQL3YRR5.js} +74 -8
  54. package/dist/chunk-SQL3YRR5.js.map +1 -0
  55. package/dist/{chunk-KYPLYRKW.js → chunk-UJQ7PID5.js} +47 -15
  56. package/dist/chunk-UJQ7PID5.js.map +1 -0
  57. package/dist/{chunk-FJAJ4YNC.js → chunk-WSA5QPTA.js} +2 -2
  58. package/dist/{chunk-FJAJ4YNC.js.map → chunk-WSA5QPTA.js.map} +0 -0
  59. package/dist/chunk-X2TJP7LB.js +0 -0
  60. package/dist/chunk-X2TJP7LB.js.map +0 -0
  61. package/dist/chunk-XENRC3YO.js +2486 -0
  62. package/dist/chunk-XENRC3YO.js.map +1 -0
  63. package/dist/cli.js +60 -20
  64. package/dist/cli.js.map +1 -1
  65. package/dist/compiler-X6WTFMYF.js +0 -0
  66. package/dist/compiler-X6WTFMYF.js.map +0 -0
  67. package/dist/config-loader-XGDDJGVY.js +9 -0
  68. package/dist/{config-loader-QM72GKEL.js.map → config-loader-XGDDJGVY.js.map} +0 -0
  69. package/dist/{console-7UW7VROK.js → console-MI2XB5RG.js} +8 -2
  70. package/dist/console-MI2XB5RG.js.map +1 -0
  71. package/dist/daemon-manager-FBISTX24.js +28 -0
  72. package/dist/{discover-CAQY6EG6.js.map → daemon-manager-FBISTX24.js.map} +0 -0
  73. package/dist/{discover-CAQY6EG6.js → discover-LHEBSUIP.js} +3 -3
  74. package/dist/{installer-PVBSX7UC.js.map → discover-LHEBSUIP.js.map} +0 -0
  75. package/dist/doctor-command-WB3O2H64.js +378 -0
  76. package/dist/doctor-command-WB3O2H64.js.map +1 -0
  77. package/dist/filters-Q3ALKWZ5.js +24 -0
  78. package/dist/{session-2MZVGYAC.js.map → filters-Q3ALKWZ5.js.map} +0 -0
  79. package/dist/{flow-thjUxXXx.d.ts → flow-CyRC-tTc.d.ts} +15 -7
  80. package/dist/gherkin/steps.d.ts +2 -2
  81. package/dist/gherkin/steps.js +0 -0
  82. package/dist/gherkin/steps.js.map +0 -0
  83. package/dist/github-pr-YMWIPCCZ.js +10 -0
  84. package/dist/github-pr-YMWIPCCZ.js.map +1 -0
  85. package/dist/html-F3X3XPSX.js +0 -0
  86. package/dist/html-F3X3XPSX.js.map +0 -0
  87. package/dist/index.d.ts +1129 -6
  88. package/dist/index.js +575 -6
  89. package/dist/index.js.map +1 -1
  90. package/dist/{init-command-U66XCM66.js → init-command-Z3QREABL.js} +60 -1
  91. package/dist/init-command-Z3QREABL.js.map +1 -0
  92. package/dist/{init-flow-command-PR7J5FBM.js → init-flow-command-4EKRVTNT.js} +2 -2
  93. package/dist/{init-flow-command-PR7J5FBM.js.map → init-flow-command-4EKRVTNT.js.map} +0 -0
  94. package/dist/{installer-PVBSX7UC.js → installer-VUPFWP5X.js} +7 -2
  95. package/dist/installer-VUPFWP5X.js.map +1 -0
  96. package/dist/ios-JPK43TFZ.js +0 -0
  97. package/dist/ios-JPK43TFZ.js.map +0 -0
  98. package/dist/json-JMRPUVY2.js +0 -0
  99. package/dist/json-JMRPUVY2.js.map +0 -0
  100. package/dist/junit-HLC62MK6.js +0 -0
  101. package/dist/junit-HLC62MK6.js.map +0 -0
  102. package/dist/machine-6H25TRTU.js +0 -0
  103. package/dist/machine-6H25TRTU.js.map +0 -0
  104. package/dist/provider-YIPU5K42.js +0 -0
  105. package/dist/provider-YIPU5K42.js.map +0 -0
  106. package/dist/redact-U72BUBBR.js +0 -0
  107. package/dist/redact-U72BUBBR.js.map +0 -0
  108. package/dist/runner-6HK62Q7B.js +0 -0
  109. package/dist/runner-6HK62Q7B.js.map +0 -0
  110. package/dist/screenshot-compare-3QRHHSFZ.js +116 -0
  111. package/dist/screenshot-compare-3QRHHSFZ.js.map +1 -0
  112. package/dist/{server-PZBRGU7P.js → server-PRM7BVVD.js} +14 -13
  113. package/dist/{server-PZBRGU7P.js.map → server-PRM7BVVD.js.map} +1 -1
  114. package/dist/server-QWJJB3WG.js +14 -0
  115. package/dist/server-QWJJB3WG.js.map +1 -0
  116. package/dist/session-2E6OK6BH.js +18 -0
  117. package/dist/session-2E6OK6BH.js.map +1 -0
  118. package/dist/session-Ddem-Q5n.d.ts +119 -0
  119. package/dist/{storybook-pBOPe_1D.d.ts → storybook-CxaP3YDz.d.ts} +265 -4
  120. package/dist/{studio-command-YDWQOMRX.js → studio-command-O3NN5BCG.js} +2 -2
  121. package/dist/{studio-command-YDWQOMRX.js.map → studio-command-O3NN5BCG.js.map} +0 -0
  122. package/dist/{test-command-B2VLWGDK.js → test-command-FYOZ6QAE.js} +231 -1341
  123. package/dist/test-command-FYOZ6QAE.js.map +1 -0
  124. package/dist/validator-HZ2A3NEI.js +0 -0
  125. package/dist/validator-HZ2A3NEI.js.map +0 -0
  126. package/package.json +7 -3
  127. package/studio-dist/assets/index-C-Io44gy.js +0 -0
  128. package/studio-dist/assets/index-DfM9lK4p.css +0 -0
  129. package/studio-dist/index.html +0 -0
  130. package/dist/accessibility-audit-RS3VIWRT.js.map +0 -1
  131. package/dist/chunk-3J4NG7JU.js.map +0 -1
  132. package/dist/chunk-7VOWF42B.js.map +0 -1
  133. package/dist/chunk-EWIR2GVV.js.map +0 -1
  134. package/dist/chunk-KYPLYRKW.js.map +0 -1
  135. package/dist/chunk-LC3QJIHY.js +0 -440
  136. package/dist/chunk-LC3QJIHY.js.map +0 -1
  137. package/dist/chunk-MCT4DYDK.js +0 -2671
  138. package/dist/chunk-MCT4DYDK.js.map +0 -1
  139. package/dist/chunk-PZYZ4O6D.js.map +0 -1
  140. package/dist/chunk-YAV6KBSW.js +0 -1318
  141. package/dist/chunk-YAV6KBSW.js.map +0 -1
  142. package/dist/chunk-YGHDMA6D.js.map +0 -1
  143. package/dist/config-loader-QM72GKEL.js +0 -9
  144. package/dist/console-7UW7VROK.js.map +0 -1
  145. package/dist/doctor-command-YGQPO7GH.js +0 -71
  146. package/dist/doctor-command-YGQPO7GH.js.map +0 -1
  147. package/dist/element-DZ0HyJ3C.d.ts +0 -25
  148. package/dist/init-command-U66XCM66.js.map +0 -1
  149. package/dist/screenshot-compare-JFHH2WR4.js +0 -75
  150. package/dist/screenshot-compare-JFHH2WR4.js.map +0 -1
  151. package/dist/session-2MZVGYAC.js +0 -17
  152. package/dist/test-command-B2VLWGDK.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/mcp/server.ts"],"sourcesContent":["import { createInterface } from \"node:readline\";\nimport type { ExtendedSelector, Platform } from \"../schemas/selector.js\";\nimport type { ConnectOptions, Session } from \"../agent/session.js\";\n\n/** MCP Tool definition advertised by `tools/list`. */\nexport interface McpToolDefinition {\n name: string;\n description: string;\n inputSchema: {\n type: \"object\";\n properties: Record<string, unknown>;\n required?: string[];\n };\n}\n\nexport interface McpContentBlock {\n type: \"text\" | \"image\";\n text?: string;\n data?: string;\n mimeType?: string;\n}\n\nexport interface McpToolResult {\n content: McpContentBlock[];\n isError?: boolean;\n}\n\nexport interface JsonRpcRequest {\n jsonrpc: \"2.0\";\n id?: string | number | null;\n method: string;\n params?: Record<string, unknown>;\n}\n\nexport interface JsonRpcResponse {\n jsonrpc: \"2.0\";\n id: string | number | null;\n result?: unknown;\n error?: { code: number; message: string; data?: unknown };\n}\n\nexport interface SpanaMcpServerOptions {\n /** Custom session connector (defaults to `connect()` from `agent/session.js`). */\n connectFn?: (opts: ConnectOptions) => Promise<Session>;\n /** Custom flow runner for `spana_run_flow` (defaults to `runTestCommand`). */\n runFlowFn?: (opts: { flowPath: string; platform?: Platform }) => Promise<boolean>;\n}\n\n/** Format a Spana selector into clean TypeScript code for verified `.flow.ts` generation. */\nexport function formatSelectorCode(selector: ExtendedSelector): string {\n if (typeof selector === \"string\") {\n return JSON.stringify(selector);\n }\n const sel = selector as Record<string, unknown>;\n if (sel.systemUI === true) {\n const rest = { ...sel };\n delete rest.systemUI;\n return `systemUI(${JSON.stringify(rest)})`;\n }\n return JSON.stringify(selector);\n}\n\n/** Generate a complete `.flow.ts` file from recorded verified MCP actions. */\nexport function buildFlowFileFromLines(flowName: string, lines: string[]): string {\n const usesSystemUI = lines.some((l) => l.includes(\"systemUI(\"));\n const imports = usesSystemUI\n ? 'import { flow, systemUI } from \"spana-test\";'\n : 'import { flow } from \"spana-test\";';\n const body =\n lines.length > 0 ? lines.map((l) => ` ${l}`).join(\"\\n\") : \" // Add verified steps here\";\n return `${imports}\\n\\nexport default flow(${JSON.stringify(flowName)}, async ({ app, expect }) => {\\n${body}\\n});\\n`;\n}\n\nexport const SPANA_MCP_TOOLS: McpToolDefinition[] = [\n {\n name: \"spana_session_start\",\n description:\n \"Connect Spana to a live target (web, android, ios, electron, electrobun) and begin recording verified .flow.ts lines.\",\n inputSchema: {\n type: \"object\",\n properties: {\n platform: {\n type: \"string\",\n enum: [\"web\", \"android\", \"ios\", \"electron\", \"electrobun\"],\n },\n baseUrl: { type: \"string\" },\n packageName: { type: \"string\" },\n bundleId: { type: \"string\" },\n device: { type: \"string\" },\n headless: { type: \"boolean\" },\n cdpUrl: { type: \"string\" },\n },\n required: [\"platform\"],\n },\n },\n {\n name: \"spana_session_stop\",\n description:\n \"Disconnect the active Spana session and return the generated .flow.ts file containing every verified step.\",\n inputSchema: {\n type: \"object\",\n properties: {\n flowName: { type: \"string\" },\n },\n },\n },\n {\n name: \"spana_observe\",\n description:\n \"Inspect the current screen: returns actionable elements with suggested { testID } / systemUI() selectors plus recent console logs and JS errors.\",\n inputSchema: {\n type: \"object\",\n properties: {\n maxElements: { type: \"number\" },\n },\n },\n },\n {\n name: \"spana_tap\",\n description:\n \"Tap an element via Spana's dual-channel resolver and return the verified `.flow.ts` line.\",\n inputSchema: {\n type: \"object\",\n properties: {\n selector: { type: \"object\" },\n },\n required: [\"selector\"],\n },\n },\n {\n name: \"spana_input_text\",\n description: \"Type text into the focused element and return the verified `.flow.ts` line.\",\n inputSchema: {\n type: \"object\",\n properties: {\n text: { type: \"string\" },\n },\n required: [\"text\"],\n },\n },\n {\n name: \"spana_assert_visible\",\n description:\n \"Verify that an element matching selector is currently visible on screen and return the verified `expect(...)` line.\",\n inputSchema: {\n type: \"object\",\n properties: {\n selector: { type: \"object\" },\n },\n required: [\"selector\"],\n },\n },\n {\n name: \"spana_open_link\",\n description: \"Navigate the active target to a URL or deep link and record the verified line.\",\n inputSchema: {\n type: \"object\",\n properties: {\n url: { type: \"string\" },\n },\n required: [\"url\"],\n },\n },\n {\n name: \"spana_screenshot\",\n description: \"Capture a live PNG screenshot of the current screen for visual verification.\",\n inputSchema: {\n type: \"object\",\n properties: {},\n },\n },\n {\n name: \"spana_diagnostics\",\n description:\n \"Argent-inspired live runtime diagnostics: returns captured console logs, JS errors, element count, and platform metadata.\",\n inputSchema: {\n type: \"object\",\n properties: {},\n },\n },\n {\n name: \"spana_export_flow\",\n description:\n \"Export all verified actions from the current session as a runnable TypeScript `.flow.ts` file without disconnecting.\",\n inputSchema: {\n type: \"object\",\n properties: {\n flowName: { type: \"string\" },\n },\n },\n },\n {\n name: \"spana_run_flow\",\n description:\n \"Run an existing `.flow.ts` test file via Spana and return pass/fail status for rapid agent fix-and-verify loops.\",\n inputSchema: {\n type: \"object\",\n properties: {\n flowPath: { type: \"string\" },\n platform: {\n type: \"string\",\n enum: [\"web\", \"android\", \"ios\", \"electron\", \"electrobun\"],\n },\n },\n required: [\"flowPath\"],\n },\n },\n];\n\n/**\n * Model-free MCP (Model Context Protocol) server for Spana.\n *\n * Lets coding agents (Claude Code, Codex, Cursor, Antigravity) drive live\n * web, iOS, Android, Electron, and Electrobun sessions, inspect unified\n * DOM/native + console/error diagnostics, and receive verified `.flow.ts` lines.\n */\nexport class SpanaMcpServer {\n private session: Session | null = null;\n private recordedLines: string[] = [];\n private readonly connectFn: (opts: ConnectOptions) => Promise<Session>;\n private readonly runFlowFn: (opts: { flowPath: string; platform?: Platform }) => Promise<boolean>;\n\n constructor(options: SpanaMcpServerOptions = {}) {\n this.connectFn =\n options.connectFn ??\n (async (opts) => {\n const { connect } = await import(\"../agent/session.js\");\n return connect(opts);\n });\n this.runFlowFn =\n options.runFlowFn ??\n (async ({ flowPath, platform }) => {\n const { runTestCommand } = await import(\"../cli/test-command.js\");\n return runTestCommand({\n flowPath,\n platforms: platform ? [platform] : [],\n quiet: true,\n });\n });\n }\n\n private requireSession(): Session {\n if (!this.session) {\n throw new Error(\n \"No active Spana MCP session. Call `spana_session_start` first with a target platform.\",\n );\n }\n return this.session;\n }\n\n async handleRequest(req: JsonRpcRequest): Promise<JsonRpcResponse | null> {\n const id = req.id ?? null;\n\n // Notifications (no id) get no JSON-RPC response\n if (req.method === \"notifications/initialized\" || req.id === undefined) {\n return null;\n }\n\n try {\n switch (req.method) {\n case \"initialize\":\n return {\n jsonrpc: \"2.0\",\n id,\n result: {\n protocolVersion: \"2024-11-05\",\n capabilities: { tools: {} },\n serverInfo: { name: \"spana-mcp\", version: \"1.0.0\" },\n },\n };\n\n case \"ping\":\n return { jsonrpc: \"2.0\", id, result: {} };\n\n case \"tools/list\":\n return {\n jsonrpc: \"2.0\",\n id,\n result: { tools: SPANA_MCP_TOOLS },\n };\n\n case \"tools/call\": {\n const name = String(req.params?.[\"name\"] ?? \"\");\n const args = (req.params?.[\"arguments\"] ?? {}) as Record<string, unknown>;\n const toolResult = await this.callTool(name, args);\n return { jsonrpc: \"2.0\", id, result: toolResult };\n }\n\n default:\n return {\n jsonrpc: \"2.0\",\n id,\n error: { code: -32601, message: `Method not found: ${req.method}` },\n };\n }\n } catch (err) {\n return {\n jsonrpc: \"2.0\",\n id,\n error: {\n code: -32603,\n message: err instanceof Error ? err.message : String(err),\n },\n };\n }\n }\n\n async callTool(name: string, args: Record<string, unknown>): Promise<McpToolResult> {\n try {\n switch (name) {\n case \"spana_session_start\": {\n if (this.session) {\n await this.session.disconnect().catch(() => undefined);\n this.session = null;\n }\n const platform = args[\"platform\"] as Platform;\n this.session = await this.connectFn({\n platform,\n baseUrl: args[\"baseUrl\"] as string | undefined,\n packageName: args[\"packageName\"] as string | undefined,\n bundleId: args[\"bundleId\"] as string | undefined,\n device: args[\"device\"] as string | undefined,\n headless: (args[\"headless\"] as boolean | undefined) ?? true,\n cdpUrl: args[\"cdpUrl\"] as string | undefined,\n });\n this.recordedLines = [];\n return this.jsonResult({ connected: true, platform });\n }\n\n case \"spana_session_stop\": {\n const flowName = (args[\"flowName\"] as string | undefined) ?? \"recorded flow\";\n const code = buildFlowFileFromLines(flowName, this.recordedLines);\n if (this.session) {\n await this.session.disconnect().catch(() => undefined);\n this.session = null;\n }\n return this.jsonResult({\n disconnected: true,\n stepCount: this.recordedLines.length,\n code,\n });\n }\n\n case \"spana_observe\": {\n const session = this.requireSession();\n const maxElements = (args[\"maxElements\"] as number | undefined) ?? 60;\n const elements = (await session.selectors()).slice(0, maxElements);\n const consoleLogs = await session.getConsoleLogs().catch(() => []);\n const jsErrors = await session.getJSErrors().catch(() => []);\n return this.jsonResult({\n platform: session.platform,\n elementCount: elements.length,\n elements,\n recentConsoleLogs: consoleLogs.slice(-15),\n jsErrors: jsErrors.slice(-10),\n });\n }\n\n case \"spana_tap\": {\n const session = this.requireSession();\n const selector = args[\"selector\"] as ExtendedSelector;\n await session.tap(selector);\n const codeLine = `await app.tap(${formatSelectorCode(selector)});`;\n this.recordedLines.push(codeLine);\n return this.jsonResult({ ok: true, codeLine });\n }\n\n case \"spana_input_text\": {\n const session = this.requireSession();\n const text = String(args[\"text\"] ?? \"\");\n await session.inputText(text);\n const codeLine = `await app.inputText(${JSON.stringify(text)});`;\n this.recordedLines.push(codeLine);\n return this.jsonResult({ ok: true, codeLine });\n }\n\n case \"spana_assert_visible\": {\n const session = this.requireSession();\n const selector = args[\"selector\"] as ExtendedSelector;\n const elements = await session.selectors();\n const sel = selector as Record<string, unknown>;\n const matched = elements.some((el) => {\n if (typeof sel[\"testID\"] === \"string\") return el.id === sel[\"testID\"];\n if (typeof sel[\"text\"] === \"string\") return el.text?.includes(sel[\"text\"]);\n if (typeof sel[\"accessibilityLabel\"] === \"string\") {\n return el.accessibilityLabel === sel[\"accessibilityLabel\"];\n }\n return false;\n });\n if (!matched) {\n return {\n isError: true,\n content: [\n {\n type: \"text\",\n text: JSON.stringify({\n ok: false,\n message: `Element not visible: ${formatSelectorCode(selector)}`,\n availableTestIDs: elements\n .map((e) => e.id)\n .filter(Boolean)\n .slice(0, 20),\n }),\n },\n ],\n };\n }\n const codeLine = `await expect(${formatSelectorCode(selector)}).toBeVisible();`;\n this.recordedLines.push(codeLine);\n return this.jsonResult({ ok: true, codeLine });\n }\n\n case \"spana_open_link\": {\n const session = this.requireSession();\n const url = String(args[\"url\"] ?? \"\");\n await session.openLink(url);\n const codeLine = `await app.openLink(${JSON.stringify(url)});`;\n this.recordedLines.push(codeLine);\n return this.jsonResult({ ok: true, codeLine });\n }\n\n case \"spana_screenshot\": {\n const session = this.requireSession();\n const png = await session.screenshot();\n return {\n content: [\n {\n type: \"image\",\n data: Buffer.from(png).toString(\"base64\"),\n mimeType: \"image/png\",\n },\n ],\n };\n }\n\n case \"spana_diagnostics\": {\n const session = this.requireSession();\n const [elements, consoleLogs, jsErrors] = await Promise.all([\n session.selectors().catch(() => []),\n session.getConsoleLogs().catch(() => []),\n session.getJSErrors().catch(() => []),\n ]);\n return this.jsonResult({\n platform: session.platform,\n actionableElements: elements.length,\n testIDCount: elements.filter((e) => Boolean(e.id)).length,\n consoleLogCount: consoleLogs.length,\n consoleLogs: consoleLogs.slice(-25),\n jsErrorCount: jsErrors.length,\n jsErrors: jsErrors.slice(-15),\n });\n }\n\n case \"spana_export_flow\": {\n const flowName = (args[\"flowName\"] as string | undefined) ?? \"recorded flow\";\n return this.jsonResult({\n flowName,\n stepCount: this.recordedLines.length,\n code: buildFlowFileFromLines(flowName, this.recordedLines),\n });\n }\n\n case \"spana_run_flow\": {\n const flowPath = String(args[\"flowPath\"] ?? \"\");\n const platform = args[\"platform\"] as Platform | undefined;\n const passed = await this.runFlowFn({ flowPath, platform });\n return this.jsonResult({ flowPath, platform: platform ?? \"default\", passed });\n }\n\n default:\n return {\n isError: true,\n content: [{ type: \"text\", text: `Unknown tool: ${name}` }],\n };\n }\n } catch (err) {\n return {\n isError: true,\n content: [\n {\n type: \"text\",\n text: err instanceof Error ? err.message : String(err),\n },\n ],\n };\n }\n }\n\n private jsonResult(payload: unknown): McpToolResult {\n return {\n content: [{ type: \"text\", text: JSON.stringify(payload, null, 2) }],\n };\n }\n\n /** Run the server over newline-delimited JSON-RPC stdio until stdin closes. */\n async runStdio(): Promise<void> {\n const rl = createInterface({ input: process.stdin, crlfDelay: Infinity });\n for await (const line of rl) {\n const trimmed = line.trim();\n if (!trimmed) continue;\n try {\n const req = JSON.parse(trimmed) as JsonRpcRequest;\n const res = await this.handleRequest(req);\n if (res) {\n process.stdout.write(`${JSON.stringify(res)}\\n`);\n }\n } catch (err) {\n const parseErr: JsonRpcResponse = {\n jsonrpc: \"2.0\",\n id: null,\n error: {\n code: -32700,\n message: err instanceof Error ? err.message : \"Parse error\",\n },\n };\n process.stdout.write(`${JSON.stringify(parseErr)}\\n`);\n }\n }\n if (this.session) {\n await this.session.disconnect().catch(() => undefined);\n this.session = null;\n }\n }\n}\n"],"mappings":";AAAA,SAAS,uBAAuB;AAiDzB,SAAS,mBAAmB,UAAoC;AACrE,MAAI,OAAO,aAAa,UAAU;AAChC,WAAO,KAAK,UAAU,QAAQ;AAAA,EAChC;AACA,QAAM,MAAM;AACZ,MAAI,IAAI,aAAa,MAAM;AACzB,UAAM,OAAO,EAAE,GAAG,IAAI;AACtB,WAAO,KAAK;AACZ,WAAO,YAAY,KAAK,UAAU,IAAI,CAAC;AAAA,EACzC;AACA,SAAO,KAAK,UAAU,QAAQ;AAChC;AAGO,SAAS,uBAAuB,UAAkB,OAAyB;AAChF,QAAM,eAAe,MAAM,KAAK,CAAC,MAAM,EAAE,SAAS,WAAW,CAAC;AAC9D,QAAM,UAAU,eACZ,iDACA;AACJ,QAAM,OACJ,MAAM,SAAS,IAAI,MAAM,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,EAAE,KAAK,IAAI,IAAI;AAC7D,SAAO,GAAG,OAAO;AAAA;AAAA,sBAA2B,KAAK,UAAU,QAAQ,CAAC;AAAA,EAAmC,IAAI;AAAA;AAAA;AAC7G;AAEO,IAAM,kBAAuC;AAAA,EAClD;AAAA,IACE,MAAM;AAAA,IACN,aACE;AAAA,IACF,aAAa;AAAA,MACX,MAAM;AAAA,MACN,YAAY;AAAA,QACV,UAAU;AAAA,UACR,MAAM;AAAA,UACN,MAAM,CAAC,OAAO,WAAW,OAAO,YAAY,YAAY;AAAA,QAC1D;AAAA,QACA,SAAS,EAAE,MAAM,SAAS;AAAA,QAC1B,aAAa,EAAE,MAAM,SAAS;AAAA,QAC9B,UAAU,EAAE,MAAM,SAAS;AAAA,QAC3B,QAAQ,EAAE,MAAM,SAAS;AAAA,QACzB,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AA,UACvD;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,WAAW,SAAiC;AAClD,WAAO;AAAA,MACL,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,KAAK,UAAU,SAAS,MAAM,CAAC,EAAE,CAAC;AAAA,IACpE;AAAA,EACF;AAAA;AAAA,EAGA,MAAM,WAA0B;AAC9B,UAAM,KAAK,gBAAgB,EAAE,OAAO,QAAQ,OAAO,WAAW,SAAS,CAAC;AACxE,qBAAiB,QAAQ,IAAI;AAC3B,YAAM,UAAU,KAAK,KAAK;AAC1B,UAAI,CAAC,QAAS;AACd,UAAI;AACF,cAAM,MAAM,KAAK,MAAM,OAAO;AAC9B,cAAM,MAAM,MAAM,KAAK,cAAc,GAAG;AACxC,YAAI,KAAK;AACP,kBAAQ,OAAO,MAAM,GAAG,KAAK,UAAU,GAAG,CAAC;AAAA,CAAI;AAAA,QACjD;AAAA,MACF,SAAS,KAAK;AACZ,cAAM,WAA4B;AAAA,UAChC,SAAS;AAAA,UACT,IAAI;AAAA,UACJ,OAAO;AAAA,YACL,MAAM;AAAA,YACN,SAAS,eAAe,QAAQ,IAAI,UAAU;AAAA,UAChD;AAAA,QACF;AACA,gBAAQ,OAAO,MAAM,GAAG,KAAK,UAAU,QAAQ,CAAC;AAAA,CAAI;AAAA,MACtD;AAAA,IACF;AACA,QAAI,KAAK,SAAS;AAChB,YAAM,KAAK,QAAQ,WAAW,EAAE,MAAM,MAAM,MAAS;AACrD,WAAK,UAAU;AAAA,IACjB;AAAA,EACF;AACF;","names":[]}
@@ -1,10 +1,10 @@
1
- import {
2
- listAndroidDevices
3
- } from "./chunk-EWIR2GVV.js";
4
1
  import {
5
2
  listIOSPhysicalDevices,
6
3
  listIOSSimulators
7
4
  } from "./chunk-S5JNNDXS.js";
5
+ import {
6
+ listAndroidDevices
7
+ } from "./chunk-H27IBIGA.js";
8
8
 
9
9
  // src/device/discover.ts
10
10
  function discoverDevices(platforms) {
@@ -18,6 +18,24 @@ function discoverDevices(platforms) {
18
18
  state: "available"
19
19
  });
20
20
  }
21
+ if (platforms.includes("electron")) {
22
+ devices.push({
23
+ platform: "electron",
24
+ id: "electron-local",
25
+ name: "Electron (Playwright _electron / CDP)",
26
+ type: "desktop",
27
+ state: "available"
28
+ });
29
+ }
30
+ if (platforms.includes("electrobun")) {
31
+ devices.push({
32
+ platform: "electrobun",
33
+ id: "electrobun-local",
34
+ name: "Electrobun (Native WebView / CEF)",
35
+ type: "desktop",
36
+ state: "available"
37
+ });
38
+ }
21
39
  if (platforms.includes("android")) {
22
40
  for (const d of listAndroidDevices()) {
23
41
  if (d.state === "device") {
@@ -59,7 +77,7 @@ function firstDeviceForPlatform(platform) {
59
77
  return devices[0] ?? null;
60
78
  }
61
79
  function findDeviceById(id) {
62
- const devices = discoverDevices(["web", "android", "ios"]);
80
+ const devices = discoverDevices(["web", "android", "ios", "electron", "electrobun"]);
63
81
  return devices.find((d) => d.id === id) ?? null;
64
82
  }
65
83
 
@@ -68,4 +86,4 @@ export {
68
86
  firstDeviceForPlatform,
69
87
  findDeviceById
70
88
  };
71
- //# sourceMappingURL=chunk-PZYZ4O6D.js.map
89
+ //# sourceMappingURL=chunk-HCG4CJKR.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/device/discover.ts"],"sourcesContent":["import type { Platform } from \"../schemas/selector.js\";\nimport { listAndroidDevices } from \"./android.js\";\nimport { listIOSPhysicalDevices, listIOSSimulators } from \"./ios.js\";\n\nexport interface DiscoveredDevice {\n platform: Platform;\n id: string;\n name: string;\n type: \"emulator\" | \"simulator\" | \"device\" | \"browser\" | \"desktop\";\n state: string;\n}\n\n/** Discover all available devices across requested platforms */\nexport function discoverDevices(platforms: Platform[]): DiscoveredDevice[] {\n const devices: DiscoveredDevice[] = [];\n\n if (platforms.includes(\"web\")) {\n devices.push({\n platform: \"web\",\n id: \"playwright-chromium\",\n name: \"Chromium (Playwright)\",\n type: \"browser\",\n state: \"available\",\n });\n }\n\n if (platforms.includes(\"electron\")) {\n devices.push({\n platform: \"electron\",\n id: \"electron-local\",\n name: \"Electron (Playwright _electron / CDP)\",\n type: \"desktop\",\n state: \"available\",\n });\n }\n\n if (platforms.includes(\"electrobun\")) {\n devices.push({\n platform: \"electrobun\",\n id: \"electrobun-local\",\n name: \"Electrobun (Native WebView / CEF)\",\n type: \"desktop\",\n state: \"available\",\n });\n }\n\n if (platforms.includes(\"android\")) {\n for (const d of listAndroidDevices()) {\n if (d.state === \"device\") {\n devices.push({\n platform: \"android\",\n id: d.serial,\n name: d.serial,\n type: d.type === \"emulator\" ? \"emulator\" : \"device\",\n state: d.state,\n });\n }\n }\n }\n\n if (platforms.includes(\"ios\")) {\n for (const device of listIOSPhysicalDevices()) {\n devices.push({\n platform: \"ios\",\n id: device.udid,\n name: device.name,\n type: \"device\",\n state: \"connected\",\n });\n }\n\n for (const s of listIOSSimulators()) {\n if (!s.isAvailable) continue;\n devices.push({\n platform: \"ios\",\n id: s.udid,\n name: `${s.name} (${s.runtime})`,\n type: \"simulator\",\n state: s.state,\n });\n }\n }\n\n return devices;\n}\n\n/** Get first available device for a platform */\nexport function firstDeviceForPlatform(platform: Platform): DiscoveredDevice | null {\n const devices = discoverDevices([platform]);\n return devices[0] ?? null;\n}\n\n/** Find a specific device by ID across all platforms */\nexport function findDeviceById(id: string): DiscoveredDevice | null {\n const devices = discoverDevices([\"web\", \"android\", \"ios\", \"electron\", \"electrobun\"]);\n return devices.find((d) => d.id === id) ?? null;\n}\n"],"mappings":";;;;;;;;;AAaO,SAAS,gBAAgB,WAA2C;AACzE,QAAM,UAA8B,CAAC;AAErC,MAAI,UAAU,SAAS,KAAK,GAAG;AAC7B,YAAQ,KAAK;AAAA,MACX,UAAU;AAAA,MACV,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,MAAM;AAAA,MACN,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AAEA,MAAI,UAAU,SAAS,UAAU,GAAG;AAClC,YAAQ,KAA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AAC,OAAO,WAAW,OAAO,YAAY,YAAY,CAAC;AACnF,SAAO,QAAQ,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK;AAC7C;","names":[]}
@@ -1,3 +1,7 @@
1
+ import {
2
+ getHealthyWarmDaemon,
3
+ registerWarmDaemon
4
+ } from "./chunk-DTNK54C2.js";
1
5
  import {
2
6
  allocatePort,
3
7
  releasePort
@@ -5,9 +9,9 @@ import {
5
9
 
6
10
  // src/drivers/wda/installer.ts
7
11
  import { execSync, spawn } from "child_process";
8
- import { existsSync } from "fs";
12
+ import { existsSync, readdirSync } from "fs";
9
13
  import { createRequire } from "module";
10
- import { dirname, resolve } from "path";
14
+ import { dirname, join, resolve } from "path";
11
15
  import { fileURLToPath } from "url";
12
16
  var __dirname = fileURLToPath(new URL(".", import.meta.url));
13
17
  var require2 = createRequire(import.meta.url);
@@ -35,6 +39,17 @@ function findWDAProject() {
35
39
  }
36
40
  return null;
37
41
  }
42
+ function findXctestrunFile(derivedDataPath) {
43
+ const productsDir = resolve(derivedDataPath, "Build", "Products");
44
+ if (!existsSync(productsDir)) return null;
45
+ try {
46
+ const files = readdirSync(productsDir);
47
+ const xctestrun = files.find((f) => f.endsWith(".xctestrun") && !f.startsWith("._"));
48
+ return xctestrun ? join(productsDir, xctestrun) : null;
49
+ } catch {
50
+ return null;
51
+ }
52
+ }
38
53
  function buildWDA(simulatorUDID) {
39
54
  const wdaPath = findWDAProject();
40
55
  if (!wdaPath) {
@@ -59,41 +74,61 @@ function buildWDA(simulatorUDID) {
59
74
  "-quiet"
60
75
  ].join(" "),
61
76
  { stdio: "inherit", timeout: 6e5 }
62
- // 10 min build timeout
63
77
  );
64
78
  console.log("WebDriverAgent built successfully.");
65
79
  return derivedDataPath;
66
80
  }
81
+ function buildWdaLaunchArgs(params) {
82
+ const destination = params.isPhysicalDevice ? `id=${params.udid}` : `platform=iOS Simulator,id=${params.udid}`;
83
+ if (params.xctestrunPath) {
84
+ return [
85
+ "test-without-building",
86
+ "-xctestrun",
87
+ params.xctestrunPath,
88
+ "-destination",
89
+ destination
90
+ ];
91
+ }
92
+ return [
93
+ "test-without-building",
94
+ "-project",
95
+ resolve(params.wdaProjectPath ?? "", "WebDriverAgent.xcodeproj"),
96
+ "-scheme",
97
+ "WebDriverAgentRunner",
98
+ "-destination",
99
+ destination,
100
+ "-derivedDataPath",
101
+ params.derivedDataPath
102
+ ];
103
+ }
67
104
  function startWDA(simulatorUDID, port = 8100, derivedDataPath) {
68
105
  const wdaPath = findWDAProject();
69
106
  if (!wdaPath) {
70
107
  throw new Error("WebDriverAgent project not found");
71
108
  }
72
109
  const ddPath = derivedDataPath ?? resolve(wdaPath, "../../.wda-builds", simulatorUDID);
73
- const env = { ...process.env, USE_PORT: String(port) };
110
+ const xctestrunPath = findXctestrunFile(ddPath);
111
+ const env = {
112
+ ...process.env,
113
+ USE_PORT: String(port),
114
+ TEST_RUNNER_USE_PORT: String(port)
115
+ };
74
116
  console.log(`Starting WebDriverAgent on port ${port}...`);
75
- const child = spawn(
76
- "xcodebuild",
77
- [
78
- "test-without-building",
79
- "-project",
80
- resolve(wdaPath, "WebDriverAgent.xcodeproj"),
81
- "-scheme",
82
- "WebDriverAgentRunner",
83
- "-destination",
84
- `platform=iOS Simulator,id=${simulatorUDID}`,
85
- "-derivedDataPath",
86
- ddPath
87
- ],
88
- { env, stdio: "ignore", detached: true }
89
- );
117
+ const args = buildWdaLaunchArgs({
118
+ udid: simulatorUDID,
119
+ isPhysicalDevice: false,
120
+ derivedDataPath: ddPath,
121
+ wdaProjectPath: wdaPath,
122
+ xctestrunPath
123
+ });
124
+ const child = spawn("xcodebuild", args, { env, stdio: "ignore", detached: true });
90
125
  child.unref();
91
126
  return child;
92
127
  }
93
- function stopWDA(process2) {
94
- if (process2) {
128
+ function stopWDA(proc) {
129
+ if (proc) {
95
130
  try {
96
- process2.kill();
131
+ proc.kill();
97
132
  } catch {
98
133
  }
99
134
  }
@@ -132,27 +167,42 @@ function startWDAOnDevice(deviceUDID, port = 8100, derivedDataPath) {
132
167
  const wdaPath = findWDAProject();
133
168
  if (!wdaPath) throw new Error("WebDriverAgent project not found");
134
169
  const ddPath = derivedDataPath ?? resolve(wdaPath, "../../.wda-builds", deviceUDID);
135
- const env = { ...process.env, USE_PORT: String(port) };
170
+ const xctestrunPath = findXctestrunFile(ddPath);
171
+ const env = {
172
+ ...process.env,
173
+ USE_PORT: String(port),
174
+ TEST_RUNNER_USE_PORT: String(port)
175
+ };
136
176
  console.log(`Starting WebDriverAgent on physical device (port ${port})...`);
137
- const child = spawn(
138
- "xcodebuild",
139
- [
140
- "test-without-building",
141
- "-project",
142
- resolve(wdaPath, "WebDriverAgent.xcodeproj"),
143
- "-scheme",
144
- "WebDriverAgentRunner",
145
- "-destination",
146
- `platform=iOS,id=${deviceUDID}`,
147
- "-derivedDataPath",
148
- ddPath
149
- ],
150
- { env, stdio: "ignore", detached: true }
151
- );
177
+ const args = buildWdaLaunchArgs({
178
+ udid: deviceUDID,
179
+ isPhysicalDevice: true,
180
+ derivedDataPath: ddPath,
181
+ wdaProjectPath: wdaPath,
182
+ xctestrunPath
183
+ });
184
+ const child = spawn("xcodebuild", args, { env, stdio: "ignore", detached: true });
152
185
  child.unref();
153
186
  return child;
154
187
  }
155
- async function setupWDAForDevice(deviceUDID, port = 8100, teamId, signingIdentity) {
188
+ async function setupWDAForDevice(deviceUDID, port = 8100, teamId, signingIdentity, options = {}) {
189
+ const warm = options.warm ?? process.env["SPANA_WARM_DAEMON"] === "1";
190
+ if (warm) {
191
+ const existing = await getHealthyWarmDaemon("wda", deviceUDID, {
192
+ stateFile: options.daemonStateFile
193
+ });
194
+ if (existing) {
195
+ console.log(`Reusing warm WebDriverAgent daemon on ${existing.host}:${existing.port}`);
196
+ return {
197
+ host: existing.host,
198
+ port: existing.port,
199
+ reusedWarmDaemon: true,
200
+ warmSessionId: existing.sessionId,
201
+ cleanup: () => {
202
+ }
203
+ };
204
+ }
205
+ }
156
206
  let wdaProcess = null;
157
207
  let tunnel = null;
158
208
  try {
@@ -174,10 +224,26 @@ async function setupWDAForDevice(deviceUDID, port = 8100, teamId, signingIdentit
174
224
  console.log(`WebDriverAgent ready on physical device (port ${tunnel.port})`);
175
225
  const activeProcess = wdaProcess;
176
226
  const activeTunnel = tunnel;
227
+ if (warm) {
228
+ registerWarmDaemon(
229
+ {
230
+ kind: "wda",
231
+ deviceId: deviceUDID,
232
+ host: activeTunnel.host,
233
+ port: activeTunnel.port,
234
+ pid: activeProcess.pid,
235
+ xctestrunPath: findXctestrunFile(derivedDataPath) ?? void 0,
236
+ startedAt: (/* @__PURE__ */ new Date()).toISOString()
237
+ },
238
+ options.daemonStateFile
239
+ );
240
+ }
177
241
  return {
178
242
  host: activeTunnel.host,
179
243
  port: activeTunnel.port,
244
+ reusedWarmDaemon: false,
180
245
  cleanup: () => {
246
+ if (warm) return;
181
247
  stopWDA(activeProcess);
182
248
  activeTunnel.cleanup();
183
249
  releasePort(port);
@@ -196,7 +262,24 @@ async function setupWDAForDevice(deviceUDID, port = 8100, teamId, signingIdentit
196
262
  throw error;
197
263
  }
198
264
  }
199
- async function setupWDA(simulatorUDID, port) {
265
+ async function setupWDA(simulatorUDID, port, options = {}) {
266
+ const warm = options.warm ?? process.env["SPANA_WARM_DAEMON"] === "1";
267
+ if (warm) {
268
+ const existing = await getHealthyWarmDaemon("wda", simulatorUDID, {
269
+ stateFile: options.daemonStateFile
270
+ });
271
+ if (existing) {
272
+ console.log(`Reusing warm WebDriverAgent daemon on ${existing.host}:${existing.port}`);
273
+ return {
274
+ host: existing.host,
275
+ port: existing.port,
276
+ reusedWarmDaemon: true,
277
+ warmSessionId: existing.sessionId,
278
+ cleanup: () => {
279
+ }
280
+ };
281
+ }
282
+ }
200
283
  const actualPort = port ?? allocatePort(8100);
201
284
  const wdaPath = findWDAProject();
202
285
  if (!wdaPath) {
@@ -214,10 +297,26 @@ async function setupWDA(simulatorUDID, port) {
214
297
  const res = await fetch(`http://localhost:${actualPort}/status`);
215
298
  if (res.ok) {
216
299
  console.log(`WebDriverAgent ready on port ${actualPort}`);
300
+ if (warm) {
301
+ registerWarmDaemon(
302
+ {
303
+ kind: "wda",
304
+ deviceId: simulatorUDID,
305
+ host: "localhost",
306
+ port: actualPort,
307
+ pid: wdaProcess.pid,
308
+ xctestrunPath: findXctestrunFile(derivedDataPath) ?? void 0,
309
+ startedAt: (/* @__PURE__ */ new Date()).toISOString()
310
+ },
311
+ options.daemonStateFile
312
+ );
313
+ }
217
314
  return {
218
315
  host: "localhost",
219
316
  port: actualPort,
317
+ reusedWarmDaemon: false,
220
318
  cleanup: () => {
319
+ if (warm) return;
221
320
  stopWDA(wdaProcess);
222
321
  releasePort(actualPort);
223
322
  }
@@ -233,7 +332,9 @@ async function setupWDA(simulatorUDID, port) {
233
332
  }
234
333
 
235
334
  export {
335
+ findXctestrunFile,
236
336
  buildWDA,
337
+ buildWdaLaunchArgs,
237
338
  startWDA,
238
339
  stopWDA,
239
340
  buildWDAForDevice,
@@ -241,4 +342,4 @@ export {
241
342
  setupWDAForDevice,
242
343
  setupWDA
243
344
  };
244
- //# sourceMappingURL=chunk-YGHDMA6D.js.map
345
+ //# sourceMappingURL=chunk-HYSTRWYN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/drivers/wda/installer.ts"],"sourcesContent":["import { execSync, spawn, type ChildProcess } from \"node:child_process\";\nimport { existsSync, readdirSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { allocatePort, releasePort } from \"../../core/port-allocator.js\";\nimport { getHealthyWarmDaemon, registerWarmDaemon } from \"../../runtime/daemon-manager.js\";\n\nconst __dirname = fileURLToPath(new URL(\".\", import.meta.url));\nconst require = createRequire(import.meta.url);\n\nexport interface WDASetupOptions {\n /** Reuse a healthy warm WDA daemon if already running, and leave it up between runs */\n warm?: boolean;\n /** Optional custom daemon registry file path */\n daemonStateFile?: string;\n}\n\nfunction resolveOptionalPackageDir(packageName: string): string | null {\n try {\n const packageJsonPath = require.resolve(`${packageName}/package.json`);\n return dirname(packageJsonPath);\n } catch {\n return null;\n }\n}\n\n/** Find the WDA Xcode project directory */\nfunction findWDAProject(): string | null {\n const appiumWDA = resolveOptionalPackageDir(\"appium-webdriveragent\");\n const projectWDA = resolve(process.cwd(), \"drivers/ios/WebDriverAgent\");\n const provWDA = resolve(__dirname, \"../../../../drivers/ios/WebDriverAgent\");\n const maestroRunnerWDA = resolve(\n __dirname,\n \"../../../../../../maestro-runner/drivers/ios/WebDriverAgent\",\n );\n\n for (const wdaPath of [projectWDA, provWDA, maestroRunnerWDA, appiumWDA]) {\n if (!wdaPath) continue;\n if (existsSync(resolve(wdaPath, \"WebDriverAgent.xcodeproj\"))) {\n return wdaPath;\n }\n }\n return null;\n}\n\n/**\n * Locate the cached `*.xctestrun` file produced by `xcodebuild build-for-testing`\n * inside `<derivedDataPath>/Build/Products/`. Using `-xctestrun` avoids Xcode\n * reparsing the project graph on every `test-without-building` invocation.\n */\nexport function findXctestrunFile(derivedDataPath: string): string | null {\n const productsDir = resolve(derivedDataPath, \"Build\", \"Products\");\n if (!existsSync(productsDir)) return null;\n try {\n const files = readdirSync(productsDir);\n const xctestrun = files.find((f) => f.endsWith(\".xctestrun\") && !f.startsWith(\"._\"));\n return xctestrun ? join(productsDir, xctestrun) : null;\n } catch {\n return null;\n }\n}\n\n/** Build WDA for a specific simulator using build-for-testing */\nexport function buildWDA(simulatorUDID: string): string {\n const wdaPath = findWDAProject();\n if (!wdaPath) {\n throw new Error(\n \"WebDriverAgent project not found. Install appium-webdriveragent or place WDA in drivers/ios/WebDriverAgent/\",\n );\n }\n\n const derivedDataPath = resolve(wdaPath, \"../../.wda-builds\", simulatorUDID);\n\n console.log(\"Building WebDriverAgent for simulator...\");\n\n execSync(\n [\n \"xcodebuild\",\n \"build-for-testing\",\n `-project \"${resolve(wdaPath, \"WebDriverAgent.xcodeproj\")}\"`,\n \"-scheme WebDriverAgentRunner\",\n `-destination \"platform=iOS Simulator,id=${simulatorUDID}\"`,\n `-derivedDataPath \"${derivedDataPath}\"`,\n 'CODE_SIGN_IDENTITY=\"\"',\n \"CODE_SIGNING_REQUIRED=NO\",\n \"CODE_SIGNING_ALLOWED=NO\",\n \"GCC_TREAT_WARNINGS_AS_ERRORS=0\",\n \"-quiet\",\n ].join(\" \"),\n { stdio: \"inherit\", timeout: 600_000 },\n );\n\n console.log(\"WebDriverAgent built successfully.\");\n return derivedDataPath;\n}\n\n/**\n * Build the `xcodebuild test-without-building` argument list.\n * Prefers cached `-xctestrun <file>` when present (no compile/scheme resolution).\n */\nexport function buildWdaLaunchArgs(params: {\n udid: string;\n isPhysicalDevice: boolean;\n derivedDataPath: string;\n wdaProjectPath?: string;\n xctestrunPath?: string | null;\n}): string[] {\n const destination = params.isPhysicalDevice\n ? `id=${params.udid}`\n : `platform=iOS Simulator,id=${params.udid}`;\n\n if (params.xctestrunPath) {\n return [\n \"test-without-building\",\n \"-xctestrun\",\n params.xctestrunPath,\n \"-destination\",\n destination,\n ];\n }\n\n return [\n \"test-without-building\",\n \"-project\",\n resolve(params.wdaProjectPath ?? \"\", \"WebDriverAgent.xcodeproj\"),\n \"-scheme\",\n \"WebDriverAgentRunner\",\n \"-destination\",\n destination,\n \"-derivedDataPath\",\n params.derivedDataPath,\n ];\n}\n\n/** Start WDA on a simulator using xcodebuild test-without-building */\nexport function startWDA(\n simulatorUDID: string,\n port: number = 8100,\n derivedDataPath?: string,\n): ChildProcess {\n const wdaPath = findWDAProject();\n if (!wdaPath) {\n throw new Error(\"WebDriverAgent project not found\");\n }\n\n const ddPath = derivedDataPath ?? resolve(wdaPath, \"../../.wda-builds\", simulatorUDID);\n const xctestrunPath = findXctestrunFile(ddPath);\n\n // Set both USE_PORT and TEST_RUNNER_USE_PORT so WDA honors the port whether\n // launched via -xctestrun or via -project/-scheme.\n const env = {\n ...process.env,\n USE_PORT: String(port),\n TEST_RUNNER_USE_PORT: String(port),\n };\n\n console.log(`Starting WebDriverAgent on port ${port}...`);\n\n const args = buildWdaLaunchArgs({\n udid: simulatorUDID,\n isPhysicalDevice: false,\n derivedDataPath: ddPath,\n wdaProjectPath: wdaPath,\n xctestrunPath,\n });\n\n const child = spawn(\"xcodebuild\", args, { env, stdio: \"ignore\", detached: true });\n\n child.unref();\n return child;\n}\n\n/** Stop a specific WDA process spawned by startWDA/startWDAOnDevice. */\nexport function stopWDA(proc: ChildProcess | null | undefined): void {\n if (proc) {\n try {\n proc.kill();\n } catch {\n // already exited\n }\n }\n}\n\n/** Build WDA for a physical device with code signing */\nexport function buildWDAForDevice(\n deviceUDID: string,\n teamId: string,\n signingIdentity = \"Apple Development\",\n): string {\n const wdaPath = findWDAProject();\n if (!wdaPath) {\n throw new Error(\n \"WebDriverAgent project not found. Install appium-webdriveragent or place WDA in drivers/ios/WebDriverAgent/\",\n );\n }\n\n const derivedDataPath = resolve(wdaPath, \"../../.wda-builds\", deviceUDID);\n\n console.log(\"Building WebDriverAgent for physical device...\");\n\n execSync(\n [\n \"xcodebuild\",\n \"build-for-testing\",\n `-project \"${resolve(wdaPath, \"WebDriverAgent.xcodeproj\")}\"`,\n \"-scheme WebDriverAgentRunner\",\n `-destination \"platform=iOS,id=${deviceUDID}\"`,\n `-derivedDataPath \"${derivedDataPath}\"`,\n `DEVELOPMENT_TEAM=${teamId}`,\n `CODE_SIGN_IDENTITY=\"${signingIdentity}\"`,\n \"CODE_SIGNING_REQUIRED=YES\",\n \"CODE_SIGNING_ALLOWED=YES\",\n \"GCC_TREAT_WARNINGS_AS_ERRORS=0\",\n \"-allowProvisioningUpdates\",\n \"-quiet\",\n ].join(\" \"),\n { stdio: \"inherit\", timeout: 600_000 },\n );\n\n console.log(\"WebDriverAgent built for device successfully.\");\n return derivedDataPath;\n}\n\n/** Start WDA on a physical device */\nexport function startWDAOnDevice(\n deviceUDID: string,\n port: number = 8100,\n derivedDataPath?: string,\n): ChildProcess {\n const wdaPath = findWDAProject();\n if (!wdaPath) throw new Error(\"WebDriverAgent project not found\");\n\n const ddPath = derivedDataPath ?? resolve(wdaPath, \"../../.wda-builds\", deviceUDID);\n const xctestrunPath = findXctestrunFile(ddPath);\n const env = {\n ...process.env,\n USE_PORT: String(port),\n TEST_RUNNER_USE_PORT: String(port),\n };\n\n console.log(`Starting WebDriverAgent on physical device (port ${port})...`);\n\n const args = buildWdaLaunchArgs({\n udid: deviceUDID,\n isPhysicalDevice: true,\n derivedDataPath: ddPath,\n wdaProjectPath: wdaPath,\n xctestrunPath,\n });\n\n const child = spawn(\"xcodebuild\", args, { env, stdio: \"ignore\", detached: true });\n\n child.unref();\n return child;\n}\n\n/** Full setup for physical device: reuse warm daemon or build, start WDA, tunnel via iproxy, wait for ready */\nexport async function setupWDAForDevice(\n deviceUDID: string,\n port: number = 8100,\n teamId: string,\n signingIdentity?: string,\n options: WDASetupOptions = {},\n): Promise<{\n host: string;\n port: number;\n cleanup: () => void;\n reusedWarmDaemon?: boolean;\n warmSessionId?: string;\n}> {\n const warm = options.warm ?? process.env[\"SPANA_WARM_DAEMON\"] === \"1\";\n\n if (warm) {\n const existing = await getHealthyWarmDaemon(\"wda\", deviceUDID, {\n stateFile: options.daemonStateFile,\n });\n if (existing) {\n console.log(`Reusing warm WebDriverAgent daemon on ${existing.host}:${existing.port}`);\n return {\n host: existing.host,\n port: existing.port,\n reusedWarmDaemon: true,\n warmSessionId: existing.sessionId,\n cleanup: () => {\n // Intentionally keep warm daemon running across runs\n },\n };\n }\n }\n\n let wdaProcess: ChildProcess | null = null;\n let tunnel: { host: string; port: number; cleanup: () => void } | null = null;\n\n try {\n const wdaPath = findWDAProject();\n if (!wdaPath) throw new Error(\"WebDriverAgent project not found\");\n\n const derivedDataPath = resolve(wdaPath, \"../../.wda-builds\", deviceUDID);\n const buildProductsDir = resolve(derivedDataPath, \"Build\", \"Products\");\n\n if (!existsSync(buildProductsDir)) {\n buildWDAForDevice(deviceUDID, teamId, signingIdentity);\n }\n\n wdaProcess = startWDAOnDevice(deviceUDID, 8100, derivedDataPath);\n\n const { startIproxy } = await import(\"../../device/ios.js\");\n tunnel = startIproxy(deviceUDID, port, 8100);\n\n const maxRetries = 45;\n for (let i = 0; i < maxRetries; i++) {\n try {\n const res = await fetch(`http://localhost:${tunnel.port}/status`);\n if (res.ok) {\n console.log(`WebDriverAgent ready on physical device (port ${tunnel.port})`);\n const activeProcess = wdaProcess;\n const activeTunnel = tunnel;\n if (warm) {\n registerWarmDaemon(\n {\n kind: \"wda\",\n deviceId: deviceUDID,\n host: activeTunnel.host,\n port: activeTunnel.port,\n pid: activeProcess.pid,\n xctestrunPath: findXctestrunFile(derivedDataPath) ?? undefined,\n startedAt: new Date().toISOString(),\n },\n options.daemonStateFile,\n );\n }\n return {\n host: activeTunnel.host,\n port: activeTunnel.port,\n reusedWarmDaemon: false,\n cleanup: () => {\n if (warm) return;\n stopWDA(activeProcess);\n activeTunnel.cleanup();\n releasePort(port);\n },\n };\n }\n } catch {\n // Not ready yet\n }\n await new Promise((r) => setTimeout(r, 1000));\n }\n\n throw new Error(`WebDriverAgent did not start on device within ${maxRetries} seconds`);\n } catch (error) {\n stopWDA(wdaProcess);\n tunnel?.cleanup();\n releasePort(port);\n throw error;\n }\n}\n\n/** Full setup: reuse warm daemon or build if needed, start WDA, wait for it to be ready */\nexport async function setupWDA(\n simulatorUDID: string,\n port?: number,\n options: WDASetupOptions = {},\n): Promise<{\n host: string;\n port: number;\n cleanup: () => void;\n reusedWarmDaemon?: boolean;\n warmSessionId?: string;\n}> {\n const warm = options.warm ?? process.env[\"SPANA_WARM_DAEMON\"] === \"1\";\n\n if (warm) {\n const existing = await getHealthyWarmDaemon(\"wda\", simulatorUDID, {\n stateFile: options.daemonStateFile,\n });\n if (existing) {\n console.log(`Reusing warm WebDriverAgent daemon on ${existing.host}:${existing.port}`);\n return {\n host: existing.host,\n port: existing.port,\n reusedWarmDaemon: true,\n warmSessionId: existing.sessionId,\n cleanup: () => {\n // Keep warm daemon alive between runs\n },\n };\n }\n }\n\n const actualPort = port ?? allocatePort(8100);\n const wdaPath = findWDAProject();\n if (!wdaPath) {\n throw new Error(\"WebDriverAgent project not found\");\n }\n\n const derivedDataPath = resolve(wdaPath, \"../../.wda-builds\", simulatorUDID);\n const buildProductsDir = resolve(derivedDataPath, \"Build\", \"Products\");\n\n if (!existsSync(buildProductsDir)) {\n buildWDA(simulatorUDID);\n }\n\n const wdaProcess = startWDA(simulatorUDID, actualPort, derivedDataPath);\n\n const maxRetries = 60;\n for (let i = 0; i < maxRetries; i++) {\n try {\n const res = await fetch(`http://localhost:${actualPort}/status`);\n if (res.ok) {\n console.log(`WebDriverAgent ready on port ${actualPort}`);\n if (warm) {\n registerWarmDaemon(\n {\n kind: \"wda\",\n deviceId: simulatorUDID,\n host: \"localhost\",\n port: actualPort,\n pid: wdaProcess.pid,\n xctestrunPath: findXctestrunFile(derivedDataPath) ?? undefined,\n startedAt: new Date().toISOString(),\n },\n options.daemonStateFile,\n );\n }\n return {\n host: \"localhost\",\n port: actualPort,\n reusedWarmDaemon: false,\n cleanup: () => {\n if (warm) return;\n stopWDA(wdaProcess);\n releasePort(actualPort);\n },\n };\n }\n } catch {\n // Not ready yet\n }\n await new Promise((r) => setTimeout(r, 1000));\n }\n\n stopWDA(wdaProcess);\n releasePort(actualPort);\n throw new Error(`WebDriverAgent did not start within ${maxRetries} seconds`);\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAS,UAAU,aAAgC;AACnD,SAAS,YAAY,mBAAmB;AACxC,SAAS,qBAAqB;AAC9B,SAAS,SAAS,MAAM,eAAe;AACvC,SAAS,qBAAqB;AAI9B,IAAM,YAAY,cAAc,IAAI,IAAI,KAAK,YAAY,GAAG,CAAC;AAC7D,IAAMA,WAAU,cAAc,YAAY,GAAG;AAS7C,SAAS,0BAA0B,aAAoC;AACrE,MAAI;AACF,UAAM,kBAAkBA,SAAQ,QAAQ,GAAG,WAAW,eAAe;AACrE,WAAO,QAAQ,eAAe;AA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AAEA,QAAM,kBAAkB,QAAQ,SAAS,qBAAqB,aAAa;AAC3E,QAAM,mBAAmB,QAAQ,iBAAiB,SAAS,UAAU;AAErE,MAAI,CAAC,WAAW,gBAAgB,GAAG;AACjC,aAAS,aAAa;AAAA,EACxB;AAEA,QAAM,aAAa,SAAS,eAAe,YAAY,eAAe;AAEtE,QAAM,aAAa;AACnB,WAAS,IAAI,GAAG,IAAI,YAAY,KAAK;AACnC,QAAI;AACF,YAAM,MAAM,MAAM,MAAM,oBAAoB,UAAU,SAAS;AAC/D,UAAI,IAAI,IAAI;AACV,gBAAQ,IAAI,gCAAgC,UAAU,EAAE;AACxD,YAAI,MAAM;AACR;AAAA,YACE;AAAA,cACE,MAAM;AAAA,cACN,UAAU;AAAA,cACV,MAAM;AAAA,cACN,MAAM;AAAA,cACN,KAAK,WAAW;AAAA,cAChB,eAAe,kBAAkB,eAAe,KAAK;AAAA,cACrD,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,YACpC;AAAA,YACA,QAAQ;AAAA,UACV;AAAA,QACF;AACA,eAAO;AAAA,UACL,MAAM;AAAA,UACN,MAAM;AAAA,UACN,kBAAkB;AAAA,UAClB,SAAS,MAAM;AACb,gBAAI,KAAM;AACV,oBAAQ,UAAU;AAClB,wBAAY,UAAU;AAAA,UACxB;AAAA,QACF;AAAA,MACF;AAAA,IACF,QAAQ;AAAA,IAER;AACA,UAAM,IAAI,QAAQ,CAAC,MAAM,WAAW,GAAG,GAAI,CAAC;AAAA,EAC9C;AAEA,UAAQ,UAAU;AAClB,cAAY,UAAU;AACtB,QAAM,IAAI,MAAM,uCAAuC,UAAU,UAAU;AAC7E;","names":["require"]}
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,89 @@
1
+ // src/report/github-pr.ts
2
+ import { appendFileSync, mkdirSync, writeFileSync } from "fs";
3
+ import { dirname, join } from "path";
4
+ function formatGitHubPrMarkdown(summary, filterSummaries = []) {
5
+ const icon = summary.failed === 0 ? "\u2705" : "\u274C";
6
+ const statusText = summary.failed === 0 ? "All flows passed" : `${summary.failed} flow(s) failed`;
7
+ const durationSec = (summary.durationMs / 1e3).toFixed(2);
8
+ const lines = [
9
+ `## ${icon} Spana E2E \u2014 ${statusText}`,
10
+ "",
11
+ `| Passed | Failed | Skipped | Duration |`,
12
+ `| ---: | ---: | ---: | ---: |`,
13
+ `| ${summary.passed} | ${summary.failed} | ${summary.skipped} | ${durationSec}s |`
14
+ ];
15
+ if (filterSummaries.length > 0) {
16
+ lines.push("", "**CI Filter Savings:**");
17
+ for (const note of filterSummaries) {
18
+ lines.push(`- \`${note}\``);
19
+ }
20
+ }
21
+ const byPlatform = /* @__PURE__ */ new Map();
22
+ for (const r of summary.results) {
23
+ const arr = byPlatform.get(r.platform) ?? [];
24
+ arr.push(r);
25
+ byPlatform.set(r.platform, arr);
26
+ }
27
+ if (byPlatform.size > 0) {
28
+ lines.push(
29
+ "",
30
+ "### Platform Breakdown",
31
+ "",
32
+ "| Platform | Passed | Failed | Skipped |",
33
+ "| --- | ---: | ---: | ---: |"
34
+ );
35
+ for (const [platform, results] of byPlatform) {
36
+ const p = results.filter((r) => r.status === "passed").length;
37
+ const f = results.filter((r) => r.status === "failed").length;
38
+ const s = results.filter((r) => r.status === "skipped").length;
39
+ lines.push(`| \`${platform}\` | ${p} | ${f} | ${s} |`);
40
+ }
41
+ }
42
+ const failures = summary.results.filter((r) => r.status === "failed");
43
+ if (failures.length > 0) {
44
+ lines.push("", "### Failures");
45
+ for (const f of failures) {
46
+ lines.push(
47
+ "",
48
+ `<details>`,
49
+ `<summary>\u274C <code>${f.platform}</code> \u2014 ${f.name} (${f.durationMs}ms)</summary>`,
50
+ "",
51
+ "```text",
52
+ f.error?.message ?? "Unknown failure",
53
+ "```",
54
+ ...f.error?.suggestion ? ["", `**Suggestion:** ${f.error.suggestion}`] : [],
55
+ `</details>`
56
+ );
57
+ }
58
+ }
59
+ lines.push("");
60
+ return lines.join("\n");
61
+ }
62
+ function createGitHubPrReporter(options = {}) {
63
+ const outputDir = options.outputDir ?? "./spana-output";
64
+ const filterSummaries = options.filterSummaries ?? [];
65
+ const writeStepSummary = options.writeStepSummary ?? true;
66
+ return {
67
+ onRunComplete(summary) {
68
+ const markdown = formatGitHubPrMarkdown(summary, filterSummaries);
69
+ const outPath = join(outputDir, "github-pr-summary.md");
70
+ mkdirSync(dirname(outPath), { recursive: true });
71
+ writeFileSync(outPath, markdown, "utf-8");
72
+ const stepSummaryPath = process.env.GITHUB_STEP_SUMMARY;
73
+ if (writeStepSummary && stepSummaryPath) {
74
+ try {
75
+ appendFileSync(stepSummaryPath, `
76
+ ${markdown}
77
+ `, "utf-8");
78
+ } catch {
79
+ }
80
+ }
81
+ }
82
+ };
83
+ }
84
+
85
+ export {
86
+ formatGitHubPrMarkdown,
87
+ createGitHubPrReporter
88
+ };
89
+ //# sourceMappingURL=chunk-LAMTF4LX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/report/github-pr.ts"],"sourcesContent":["import { appendFileSync, mkdirSync, writeFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport type { FlowResult, Reporter, RunSummary } from \"./types.js\";\n\nexport interface GitHubPrReporterOptions {\n /** Directory where `github-pr-summary.md` is written (default: `./spana-output`). */\n outputDir?: string;\n /** Optional filter summary lines (from `--changed-since` filters) to include in the comment. */\n filterSummaries?: string[];\n /** Write to `process.env.GITHUB_STEP_SUMMARY` automatically when present (default: true). */\n writeStepSummary?: boolean;\n}\n\n/**\n * Format a concise Markdown summary suitable for GitHub Actions Job Summaries\n * and Pull Request comments (inspired by `@e2e-dev/github`).\n */\nexport function formatGitHubPrMarkdown(\n summary: RunSummary,\n filterSummaries: string[] = [],\n): string {\n const icon = summary.failed === 0 ? \"✅\" : \"❌\";\n const statusText = summary.failed === 0 ? \"All flows passed\" : `${summary.failed} flow(s) failed`;\n const durationSec = (summary.durationMs / 1000).toFixed(2);\n\n const lines: string[] = [\n `## ${icon} Spana E2E — ${statusText}`,\n \"\",\n `| Passed | Failed | Skipped | Duration |`,\n `| ---: | ---: | ---: | ---: |`,\n `| ${summary.passed} | ${summary.failed} | ${summary.skipped} | ${durationSec}s |`,\n ];\n\n if (filterSummaries.length > 0) {\n lines.push(\"\", \"**CI Filter Savings:**\");\n for (const note of filterSummaries) {\n lines.push(`- \\`${note}\\``);\n }\n }\n\n // Group by platform\n const byPlatform = new Map<string, FlowResult[]>();\n for (const r of summary.results) {\n const arr = byPlatform.get(r.platform) ?? [];\n arr.push(r);\n byPlatform.set(r.platform, arr);\n }\n\n if (byPlatform.size > 0) {\n lines.push(\n \"\",\n \"### Platform Breakdown\",\n \"\",\n \"| Platform | Passed | Failed | Skipped |\",\n \"| --- | ---: | ---: | ---: |\",\n );\n for (const [platform, results] of byPlatform) {\n const p = results.filter((r) => r.status === \"passed\").length;\n const f = results.filter((r) => r.status === \"failed\").length;\n const s = results.filter((r) => r.status === \"skipped\").length;\n lines.push(`| \\`${platform}\\` | ${p} | ${f} | ${s} |`);\n }\n }\n\n const failures = summary.results.filter((r) => r.status === \"failed\");\n if (failures.length > 0) {\n lines.push(\"\", \"### Failures\");\n for (const f of failures) {\n lines.push(\n \"\",\n `<details>`,\n `<summary>❌ <code>${f.platform}</code> — ${f.name} (${f.durationMs}ms)</summary>`,\n \"\",\n \"```text\",\n f.error?.message ?? \"Unknown failure\",\n \"```\",\n ...(f.error?.suggestion ? [\"\", `**Suggestion:** ${f.error.suggestion}`] : []),\n `</details>`,\n );\n }\n }\n\n lines.push(\"\");\n return lines.join(\"\\n\");\n}\n\n/**\n * Built-in `\"github\"` reporter: writes `github-pr-summary.md` to the artifact\n * output directory and appends to `$GITHUB_STEP_SUMMARY` in GitHub Actions.\n */\nexport function createGitHubPrReporter(options: GitHubPrReporterOptions = {}): Reporter {\n const outputDir = options.outputDir ?? \"./spana-output\";\n const filterSummaries = options.filterSummaries ?? [];\n const writeStepSummary = options.writeStepSummary ?? true;\n\n return {\n onRunComplete(summary: RunSummary) {\n const markdown = formatGitHubPrMarkdown(summary, filterSummaries);\n const outPath = join(outputDir, \"github-pr-summary.md\");\n mkdirSync(dirname(outPath), { recursive: true });\n writeFileSync(outPath, markdown, \"utf-8\");\n\n const stepSummaryPath = process.env.GITHUB_STEP_SUMMARY;\n if (writeStepSummary && stepSummaryPath) {\n try {\n appendFileSync(stepSummaryPath, `\\n${markdown}\\n`, \"utf-8\");\n } catch {\n // Best-effort in GitHub Actions\n }\n }\n },\n };\n}\n"],"mappings":";AAAA,SAAS,gBAAgB,WAAW,qBAAqB;AACzD,SAAS,SAAS,YAAY;AAgBvB,SAAS,uBACd,SACA,kBAA4B,CAAC,GACrB;AACR,QAAM,OAAO,QAAQ,WAAW,IAAI,WAAM;AAC1C,QAAM,aAAa,QAAQ,WAAW,IAAI,qBAAqB,GAAG,QAAQ,MAAM;AAChF,QAAM,eAAe,QAAQ,aAAa,KAAM,QAAQ,CAAC;AAEzD,QAAM,QAAkB;AAAA,IACtB,MAAM,IAAI,qBAAgB,UAAU;AAAA,IACpC;AAAA,IACA;AAAA,IACA;AAAA,IACA,KAAK,QAAQ,MAAM,MAAM,QAAQ,MAAM,MAAM,QAAQ,OAAO,MAAM,WAAW;AAAA,EAC/E;AAEA,MAAI,gBAAgB,SAAS,GAAG;AAC9B,UAAM,KAAK,IAAI,wBAAwB;AACvC,eAAW,QAAQ,iBAAiB;AAClC,YAAM,KAAK,OAAO,IAAI,IAAI;AAAA,IAC5B;AAAA,EACF;AAGA,QAAM,aAAa,oBAAI,IAA0B;AACjD,aAAW,KAAK,QAAQ,SAAS;AAC/B,UAAM,MAAM,WAAW,IAAI,EAAE,QAAQ,KAAK,CAAC;AAC3C,QAAI,KAAK,CAAC;AACV,eAAW,IAAI,EAAE,UAAU,GAAG;AAAA,EAChC;AAEA,MAAI,WAAW,OAAO,GAAG;AACvB,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AACA,eAAW,CAAC,UAAU,OA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