spana-test 0.1.0 → 0.3.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 (131) hide show
  1. package/.agents/skills/spana-testing/SKILL.md +4 -1
  2. package/README.md +312 -86
  3. package/dist/accessibility-audit-RS3VIWRT.js +140 -0
  4. package/dist/accessibility-audit-RS3VIWRT.js.map +1 -0
  5. package/dist/agent/index.d.ts +14 -3
  6. package/dist/agent/index.js +10 -9
  7. package/dist/{allure-PTTVORQ6.js → allure-RNMEYTXS.js} +42 -2
  8. package/dist/allure-RNMEYTXS.js.map +1 -0
  9. package/dist/appium-server-66GVUL24.js +119 -0
  10. package/dist/appium-server-66GVUL24.js.map +1 -0
  11. package/dist/baseline-manager-5TIUCNP5.js +38 -0
  12. package/dist/baseline-manager-5TIUCNP5.js.map +1 -0
  13. package/dist/chunk-24KSKK2I.js +1289 -0
  14. package/dist/chunk-24KSKK2I.js.map +1 -0
  15. package/dist/chunk-3J4NG7JU.js +80 -0
  16. package/dist/chunk-3J4NG7JU.js.map +1 -0
  17. package/dist/{chunk-5XO6S7AI.js → chunk-3TRMQCUT.js} +5 -4
  18. package/dist/chunk-3TRMQCUT.js.map +1 -0
  19. package/dist/{chunk-V62HFH6E.js → chunk-4OHBO7LD.js} +23 -8
  20. package/dist/chunk-4OHBO7LD.js.map +1 -0
  21. package/dist/chunk-5245YBLL.js +127 -0
  22. package/dist/chunk-5245YBLL.js.map +1 -0
  23. package/dist/{chunk-VDWWIVM6.js → chunk-7IA2XG3G.js} +119 -69
  24. package/dist/chunk-7IA2XG3G.js.map +1 -0
  25. package/dist/{chunk-RJ5VPHVX.js → chunk-7VOWF42B.js} +42 -8
  26. package/dist/chunk-7VOWF42B.js.map +1 -0
  27. package/dist/{chunk-WIJYK22K.js → chunk-DSTUWLSW.js} +15 -4
  28. package/dist/chunk-DSTUWLSW.js.map +1 -0
  29. package/dist/{chunk-53MUJUJY.js → chunk-FJAJ4YNC.js} +17 -4
  30. package/dist/chunk-FJAJ4YNC.js.map +1 -0
  31. package/dist/chunk-IHVZKQQW.js +24 -0
  32. package/dist/chunk-IHVZKQQW.js.map +1 -0
  33. package/dist/{chunk-CKJQX73M.js → chunk-KAKHFSVA.js} +987 -240
  34. package/dist/chunk-KAKHFSVA.js.map +1 -0
  35. package/dist/chunk-KJPHH2TW.js +168 -0
  36. package/dist/chunk-KJPHH2TW.js.map +1 -0
  37. package/dist/chunk-OBCFACUW.js +28 -0
  38. package/dist/chunk-OBCFACUW.js.map +1 -0
  39. package/dist/{chunk-RK4Z6C7M.js → chunk-QPIE3IMG.js} +65 -69
  40. package/dist/chunk-QPIE3IMG.js.map +1 -0
  41. package/dist/{chunk-PWEOJKUF.js → chunk-X2TJP7LB.js} +26 -7
  42. package/dist/chunk-X2TJP7LB.js.map +1 -0
  43. package/dist/chunk-YXQEPVEW.js +372 -0
  44. package/dist/chunk-YXQEPVEW.js.map +1 -0
  45. package/dist/cli.js +332 -41
  46. package/dist/cli.js.map +1 -1
  47. package/dist/{compiler-G75RIIYS.js → compiler-X6WTFMYF.js} +16 -8
  48. package/dist/compiler-X6WTFMYF.js.map +1 -0
  49. package/dist/config-loader-QM72GKEL.js +9 -0
  50. package/dist/{console-FV4RJPO4.js → console-7UW7VROK.js} +109 -7
  51. package/dist/console-7UW7VROK.js.map +1 -0
  52. package/dist/{discover-RWBKI5IB.js → discover-NPNF6SWQ.js} +4 -3
  53. package/dist/doctor-command-C3SEQGRQ.js +71 -0
  54. package/dist/doctor-command-C3SEQGRQ.js.map +1 -0
  55. package/dist/{element-CGteXiXB.d.ts → element-DZ0HyJ3C.d.ts} +2 -0
  56. package/dist/flow-CW0_j7tw.d.ts +146 -0
  57. package/dist/gherkin/steps.d.ts +2 -2
  58. package/dist/{html-JP2HBIJQ.js → html-F3X3XPSX.js} +100 -9
  59. package/dist/html-F3X3XPSX.js.map +1 -0
  60. package/dist/index.d.ts +167 -3
  61. package/dist/index.js +6 -3
  62. package/dist/index.js.map +1 -1
  63. package/dist/{init-command-CELKL2CX.js → init-command-U66XCM66.js} +4 -3
  64. package/dist/init-command-U66XCM66.js.map +1 -0
  65. package/dist/init-flow-command-PR7J5FBM.js +37 -0
  66. package/dist/init-flow-command-PR7J5FBM.js.map +1 -0
  67. package/dist/{installer-R6NX7BYQ.js → installer-W5DITECS.js} +3 -2
  68. package/dist/{ios-ZZU6DHH7.js → ios-3GRECXAP.js} +3 -2
  69. package/dist/{junit-UDY5JG22.js → junit-HLC62MK6.js} +2 -2
  70. package/dist/junit-HLC62MK6.js.map +1 -0
  71. package/dist/machine-6H25TRTU.js +16 -0
  72. package/dist/provider-YIPU5K42.js +12 -0
  73. package/dist/{redact-IDA3C4UH.js → redact-U72BUBBR.js} +2 -2
  74. package/dist/{redact-IDA3C4UH.js.map → redact-U72BUBBR.js.map} +1 -1
  75. package/dist/{runner-QEF6PJOE.js → runner-6HK62Q7B.js} +2 -2
  76. package/dist/screenshot-compare-JFHH2WR4.js +75 -0
  77. package/dist/screenshot-compare-JFHH2WR4.js.map +1 -0
  78. package/dist/{server-MMK7PZIH.js → server-MZERO364.js} +401 -69
  79. package/dist/server-MZERO364.js.map +1 -0
  80. package/dist/session-3UZ5WAAD.js +17 -0
  81. package/dist/storybook-BK2JE4ld.d.ts +447 -0
  82. package/dist/{studio-command-CDVPREMG.js → studio-command-5BUER2RH.js} +2 -2
  83. package/dist/test-command-2PXTHASW.js +3161 -0
  84. package/dist/test-command-2PXTHASW.js.map +1 -0
  85. package/dist/validator-HZ2A3NEI.js +17 -0
  86. package/dist/validator-HZ2A3NEI.js.map +1 -0
  87. package/package.json +6 -1
  88. package/studio-dist/assets/index-C-Io44gy.js +193 -0
  89. package/studio-dist/assets/index-DfM9lK4p.css +1 -0
  90. package/studio-dist/index.html +2 -2
  91. package/dist/allure-PTTVORQ6.js.map +0 -1
  92. package/dist/chunk-53MUJUJY.js.map +0 -1
  93. package/dist/chunk-5XO6S7AI.js.map +0 -1
  94. package/dist/chunk-BZRLA4Z3.js +0 -82
  95. package/dist/chunk-BZRLA4Z3.js.map +0 -1
  96. package/dist/chunk-CKJQX73M.js.map +0 -1
  97. package/dist/chunk-PANFRTIU.js +0 -310
  98. package/dist/chunk-PANFRTIU.js.map +0 -1
  99. package/dist/chunk-PWEOJKUF.js.map +0 -1
  100. package/dist/chunk-RJ5VPHVX.js.map +0 -1
  101. package/dist/chunk-RK4Z6C7M.js.map +0 -1
  102. package/dist/chunk-U564GCO2.js +0 -259
  103. package/dist/chunk-U564GCO2.js.map +0 -1
  104. package/dist/chunk-V62HFH6E.js.map +0 -1
  105. package/dist/chunk-VDWWIVM6.js.map +0 -1
  106. package/dist/chunk-WIJYK22K.js.map +0 -1
  107. package/dist/compiler-G75RIIYS.js.map +0 -1
  108. package/dist/config-Dg9O0rcQ.d.ts +0 -219
  109. package/dist/config-loader-JJ5RPP53.js +0 -9
  110. package/dist/console-FV4RJPO4.js.map +0 -1
  111. package/dist/flow-D-_tlLpp.d.ts +0 -99
  112. package/dist/html-JP2HBIJQ.js.map +0 -1
  113. package/dist/init-command-CELKL2CX.js.map +0 -1
  114. package/dist/junit-UDY5JG22.js.map +0 -1
  115. package/dist/provider-CUWPULGC.js +0 -10
  116. package/dist/server-MMK7PZIH.js.map +0 -1
  117. package/dist/session-FBJABNXL.js +0 -16
  118. package/dist/test-command-SB5KYPQI.js +0 -1929
  119. package/dist/test-command-SB5KYPQI.js.map +0 -1
  120. package/dist/validator-CFQ55NUQ.js +0 -13
  121. package/studio-dist/assets/index-CPdpC9i-.css +0 -1
  122. package/studio-dist/assets/index-L1Wd0vop.js +0 -183
  123. /package/dist/{config-loader-JJ5RPP53.js.map → config-loader-QM72GKEL.js.map} +0 -0
  124. /package/dist/{discover-RWBKI5IB.js.map → discover-NPNF6SWQ.js.map} +0 -0
  125. /package/dist/{installer-R6NX7BYQ.js.map → installer-W5DITECS.js.map} +0 -0
  126. /package/dist/{ios-ZZU6DHH7.js.map → ios-3GRECXAP.js.map} +0 -0
  127. /package/dist/{provider-CUWPULGC.js.map → machine-6H25TRTU.js.map} +0 -0
  128. /package/dist/{runner-QEF6PJOE.js.map → provider-YIPU5K42.js.map} +0 -0
  129. /package/dist/{session-FBJABNXL.js.map → runner-6HK62Q7B.js.map} +0 -0
  130. /package/dist/{validator-CFQ55NUQ.js.map → session-3UZ5WAAD.js.map} +0 -0
  131. /package/dist/{studio-command-CDVPREMG.js.map → studio-command-5BUER2RH.js.map} +0 -0
@@ -1,21 +1,22 @@
1
1
  import {
2
2
  connect
3
- } from "./chunk-VDWWIVM6.js";
4
- import "./chunk-CKJQX73M.js";
3
+ } from "./chunk-7IA2XG3G.js";
4
+ import "./chunk-KAKHFSVA.js";
5
+ import "./chunk-QPIE3IMG.js";
6
+ import {
7
+ discoverDevices
8
+ } from "./chunk-DSTUWLSW.js";
9
+ import "./chunk-GZK22EIE.js";
10
+ import "./chunk-4OHBO7LD.js";
11
+ import "./chunk-OBCFACUW.js";
5
12
  import {
6
13
  discoverFlows,
7
14
  discoverStepFiles,
8
15
  filterFlows,
9
16
  loadStepFiles,
10
17
  loadTestSource
11
- } from "./chunk-5XO6S7AI.js";
12
- import "./chunk-U564GCO2.js";
13
- import "./chunk-RK4Z6C7M.js";
14
- import {
15
- discoverDevices
16
- } from "./chunk-WIJYK22K.js";
17
- import "./chunk-GZK22EIE.js";
18
- import "./chunk-V62HFH6E.js";
18
+ } from "./chunk-3TRMQCUT.js";
19
+ import "./chunk-24KSKK2I.js";
19
20
  import {
20
21
  __require
21
22
  } from "./chunk-DGUM43GV.js";
@@ -81,39 +82,342 @@ async function getOrCreateSession(platform, config, deviceId) {
81
82
  sessions.set(key, session);
82
83
  return session;
83
84
  }
85
+ async function disconnectSession(platform, deviceId) {
86
+ const key = sessionKey(platform, deviceId);
87
+ const session = sessions.get(key);
88
+ sessions.delete(key);
89
+ if (session) {
90
+ await session.disconnect();
91
+ }
92
+ }
93
+ async function runWithRecoveredSession(action, resetSession) {
94
+ try {
95
+ return await action();
96
+ } catch {
97
+ await resetSession();
98
+ }
99
+ try {
100
+ return await action();
101
+ } catch (error) {
102
+ await resetSession();
103
+ throw error;
104
+ }
105
+ }
84
106
  var inspectorInput = z2.object({
85
107
  platform: z2.enum(["web", "android", "ios"]),
86
108
  deviceId: z2.string().optional()
87
109
  });
88
110
  var inspectorRouter = {
89
111
  screenshot: publicProcedure.input(inspectorInput).handler(async ({ input, context }) => {
90
- const session = await getOrCreateSession(input.platform, context.config, input.deviceId);
91
- const data = await session.screenshot();
92
- const base64 = Buffer.from(data).toString("base64");
93
- return { image: base64 };
112
+ const data = await runWithRecoveredSession(
113
+ async () => {
114
+ const session = await getOrCreateSession(input.platform, context.config, input.deviceId);
115
+ return session.screenshot();
116
+ },
117
+ () => disconnectSession(input.platform, input.deviceId)
118
+ );
119
+ return { image: Buffer.from(data).toString("base64") };
94
120
  }),
95
121
  hierarchy: publicProcedure.input(inspectorInput).handler(async ({ input, context }) => {
96
- const session = await getOrCreateSession(input.platform, context.config, input.deviceId);
97
- return session.hierarchy();
122
+ return runWithRecoveredSession(
123
+ async () => {
124
+ const session = await getOrCreateSession(input.platform, context.config, input.deviceId);
125
+ return session.hierarchy();
126
+ },
127
+ () => disconnectSession(input.platform, input.deviceId)
128
+ );
98
129
  }),
99
130
  selectors: publicProcedure.input(inspectorInput).handler(async ({ input, context }) => {
100
- const session = await getOrCreateSession(input.platform, context.config, input.deviceId);
101
- return session.selectors();
131
+ return runWithRecoveredSession(
132
+ async () => {
133
+ const session = await getOrCreateSession(input.platform, context.config, input.deviceId);
134
+ return session.selectors();
135
+ },
136
+ () => disconnectSession(input.platform, input.deviceId)
137
+ );
102
138
  }),
103
139
  disconnect: publicProcedure.input(inspectorInput).handler(async ({ input }) => {
104
- const key = sessionKey(input.platform, input.deviceId);
105
- const session = sessions.get(key);
106
- if (session) {
107
- await session.disconnect();
108
- sessions.delete(key);
109
- }
140
+ await disconnectSession(input.platform, input.deviceId);
110
141
  return { disconnected: true };
111
142
  })
112
143
  };
113
144
 
114
- // src/studio/routers/tests.ts
145
+ // src/studio/routers/recording.ts
115
146
  import { z as z3 } from "zod";
116
- import { resolve } from "path";
147
+ import * as fs from "fs/promises";
148
+ import * as path from "path";
149
+
150
+ // src/studio/recording-session.ts
151
+ var _idCounter = 0;
152
+ function generateId(prefix) {
153
+ return `${prefix}-${Date.now()}-${++_idCounter}`;
154
+ }
155
+ var RecordingSessionStore = class {
156
+ sessions = /* @__PURE__ */ new Map();
157
+ start(platform) {
158
+ const session = {
159
+ id: generateId("session"),
160
+ platform,
161
+ status: "recording",
162
+ actions: []
163
+ };
164
+ this.sessions.set(session.id, session);
165
+ return session;
166
+ }
167
+ get(sessionId) {
168
+ return this.sessions.get(sessionId);
169
+ }
170
+ stop(sessionId) {
171
+ const session = this.sessions.get(sessionId);
172
+ if (!session) return void 0;
173
+ session.status = "stopped";
174
+ return session;
175
+ }
176
+ addAction(sessionId, input) {
177
+ const session = this.sessions.get(sessionId);
178
+ if (!session) return void 0;
179
+ const action = { id: generateId("action"), ...input };
180
+ session.actions.push(action);
181
+ return action;
182
+ }
183
+ deleteAction(sessionId, actionId) {
184
+ const session = this.sessions.get(sessionId);
185
+ if (!session) return void 0;
186
+ session.actions = session.actions.filter((a) => a.id !== actionId);
187
+ return session;
188
+ }
189
+ reorderActions(sessionId, orderedIds) {
190
+ const session = this.sessions.get(sessionId);
191
+ if (!session) return void 0;
192
+ const byId = new Map(session.actions.map((a) => [a.id, a]));
193
+ session.actions = orderedIds.flatMap((id) => {
194
+ const action = byId.get(id);
195
+ return action ? [action] : [];
196
+ });
197
+ return session;
198
+ }
199
+ updateSelector(sessionId, actionId, selector) {
200
+ const session = this.sessions.get(sessionId);
201
+ if (!session) return void 0;
202
+ const action = session.actions.find((a) => a.id === actionId);
203
+ if (!action) return void 0;
204
+ action.selector = selector;
205
+ return session;
206
+ }
207
+ };
208
+
209
+ // src/core/flow-generator.ts
210
+ function formatSelector(selector) {
211
+ if (typeof selector === "string") {
212
+ return `"${selector}"`;
213
+ }
214
+ if ("testID" in selector) {
215
+ return `{ testID: "${selector.testID}" }`;
216
+ }
217
+ if ("text" in selector) {
218
+ return `{ text: "${selector.text}" }`;
219
+ }
220
+ if ("accessibilityLabel" in selector) {
221
+ return `{ accessibilityLabel: "${selector.accessibilityLabel}" }`;
222
+ }
223
+ if ("point" in selector) {
224
+ return `{ point: { x: ${selector.point.x}, y: ${selector.point.y} } }`;
225
+ }
226
+ return JSON.stringify(selector);
227
+ }
228
+ function generateActionLine(action) {
229
+ const { type, selector, params } = action;
230
+ if (type === "expect.toBeVisible") {
231
+ const sel = selector ? formatSelector(selector) : "undefined";
232
+ return `await expect(${sel}).toBeVisible();`;
233
+ }
234
+ if (type === "expect.toHaveText") {
235
+ const sel = selector ? formatSelector(selector) : "undefined";
236
+ const expected = typeof params.expected === "string" ? params.expected : String(params.expected);
237
+ return `await expect(${sel}).toHaveText("${expected}");`;
238
+ }
239
+ if (type === "back") {
240
+ return `await app.back();`;
241
+ }
242
+ if (type === "pressKey") {
243
+ const key = typeof params.key === "string" ? params.key : String(params.key);
244
+ return `await app.pressKey("${key}");`;
245
+ }
246
+ if (type === "inputText") {
247
+ const text = typeof params.text === "string" ? params.text : String(params.text);
248
+ if (selector) {
249
+ return `await app.inputText("${text}", ${formatSelector(selector)});`;
250
+ }
251
+ return `await app.inputText("${text}");`;
252
+ }
253
+ if (type === "scroll" || type === "swipe") {
254
+ const direction = typeof params.direction === "string" ? params.direction : String(params.direction);
255
+ if (selector) {
256
+ return `await app.${type}("${direction}", ${formatSelector(selector)});`;
257
+ }
258
+ return `await app.${type}("${direction}");`;
259
+ }
260
+ if (selector) {
261
+ return `await app.${type}(${formatSelector(selector)});`;
262
+ }
263
+ return `await app.${type}();`;
264
+ }
265
+ function generateFlowCode(flowName, actions) {
266
+ const lines = actions.map((action) => ` ${generateActionLine(action)}`);
267
+ const body = lines.length > 0 ? `
268
+ ${lines.join("\n")}
269
+ ` : "\n";
270
+ return `import { flow } from "spana-test";
271
+
272
+ export default flow("${flowName}", async ({ app, expect }) => {${body}});`;
273
+ }
274
+
275
+ // src/studio/routers/recording.ts
276
+ var store = new RecordingSessionStore();
277
+ var selectorSchema = z3.union([
278
+ z3.string(),
279
+ z3.object({ testID: z3.string() }),
280
+ z3.object({ text: z3.string() }),
281
+ z3.object({ accessibilityLabel: z3.string() }),
282
+ z3.object({ point: z3.object({ x: z3.number(), y: z3.number() }) })
283
+ ]);
284
+ var platformEnum = z3.enum(["web", "android", "ios"]);
285
+ var recordingRouter = {
286
+ start: publicProcedure.input(
287
+ z3.object({
288
+ platform: platformEnum,
289
+ deviceId: z3.string().optional()
290
+ })
291
+ ).handler(async ({ input }) => {
292
+ const session = store.start(input.platform);
293
+ return { sessionId: session.id };
294
+ }),
295
+ stop: publicProcedure.input(z3.object({ sessionId: z3.string() })).handler(async ({ input }) => {
296
+ store.stop(input.sessionId);
297
+ }),
298
+ addAction: publicProcedure.input(
299
+ z3.object({
300
+ sessionId: z3.string(),
301
+ action: z3.object({
302
+ type: z3.string(),
303
+ selector: selectorSchema.optional(),
304
+ selectorAlternatives: z3.array(selectorSchema).default([]),
305
+ params: z3.record(z3.string(), z3.unknown()).default({}),
306
+ timestamp: z3.number(),
307
+ screenshotPath: z3.string().optional()
308
+ })
309
+ })
310
+ ).handler(async ({ input }) => {
311
+ const action = store.addAction(input.sessionId, input.action);
312
+ if (!action) throw new Error(`Session not found: ${input.sessionId}`);
313
+ return { actionId: action.id };
314
+ }),
315
+ deleteAction: publicProcedure.input(z3.object({ sessionId: z3.string(), actionId: z3.string() })).handler(async ({ input }) => {
316
+ store.deleteAction(input.sessionId, input.actionId);
317
+ }),
318
+ reorderActions: publicProcedure.input(z3.object({ sessionId: z3.string(), actionIds: z3.array(z3.string()) })).handler(async ({ input }) => {
319
+ store.reorderActions(input.sessionId, input.actionIds);
320
+ }),
321
+ updateSelector: publicProcedure.input(
322
+ z3.object({
323
+ sessionId: z3.string(),
324
+ actionId: z3.string(),
325
+ selector: selectorSchema
326
+ })
327
+ ).handler(async ({ input }) => {
328
+ store.updateSelector(input.sessionId, input.actionId, input.selector);
329
+ }),
330
+ getSession: publicProcedure.input(z3.object({ sessionId: z3.string() })).handler(async ({ input }) => {
331
+ const session = store.get(input.sessionId);
332
+ if (!session) throw new Error(`Session not found: ${input.sessionId}`);
333
+ return session;
334
+ }),
335
+ generateCode: publicProcedure.input(z3.object({ sessionId: z3.string(), flowName: z3.string() })).handler(async ({ input }) => {
336
+ const session = store.get(input.sessionId);
337
+ if (!session) throw new Error(`Session not found: ${input.sessionId}`);
338
+ const code = generateFlowCode(input.flowName, session.actions);
339
+ return { code };
340
+ }),
341
+ save: publicProcedure.input(
342
+ z3.object({
343
+ sessionId: z3.string(),
344
+ flowName: z3.string(),
345
+ flowDir: z3.string().optional()
346
+ })
347
+ ).handler(async ({ input, context }) => {
348
+ const session = store.get(input.sessionId);
349
+ if (!session) throw new Error(`Session not found: ${input.sessionId}`);
350
+ const code = generateFlowCode(input.flowName, session.actions);
351
+ const dir = input.flowDir ?? context.config.flowDir ?? "flows";
352
+ const fileName = `${input.flowName}.ts`;
353
+ const filePath = path.resolve(dir, fileName);
354
+ await fs.mkdir(dir, { recursive: true });
355
+ await fs.writeFile(filePath, code, "utf8");
356
+ return { filePath, code };
357
+ }),
358
+ executeAction: publicProcedure.input(
359
+ z3.object({
360
+ sessionId: z3.string(),
361
+ platform: platformEnum,
362
+ deviceId: z3.string().optional(),
363
+ actionType: z3.string(),
364
+ selector: selectorSchema.optional(),
365
+ params: z3.record(z3.string(), z3.unknown()).optional()
366
+ })
367
+ ).handler(async ({ input, context }) => {
368
+ const agentSession = await getOrCreateSession(input.platform, context.config, input.deviceId);
369
+ const sel = input.selector;
370
+ const params = input.params ?? {};
371
+ switch (input.actionType) {
372
+ case "tap":
373
+ if (sel) await agentSession.tap(sel);
374
+ break;
375
+ case "doubleTap":
376
+ if (sel) await agentSession.doubleTap(sel);
377
+ break;
378
+ case "longPress":
379
+ if (sel) await agentSession.longPress(sel);
380
+ break;
381
+ case "inputText":
382
+ await agentSession.inputText(String(params.text ?? ""));
383
+ break;
384
+ case "scroll":
385
+ await agentSession.scroll(
386
+ String(params.direction ?? "down")
387
+ );
388
+ break;
389
+ case "swipe":
390
+ await agentSession.swipe(
391
+ String(params.direction ?? "left")
392
+ );
393
+ break;
394
+ case "pressKey":
395
+ await agentSession.pressKey(String(params.key ?? ""));
396
+ break;
397
+ case "back":
398
+ await agentSession.back();
399
+ break;
400
+ default:
401
+ break;
402
+ }
403
+ const selectorAlternatives = await agentSession.selectors();
404
+ return { selectorAlternatives };
405
+ })
406
+ };
407
+
408
+ // src/studio/routers/tests.ts
409
+ import { z as z4 } from "zod";
410
+ import { resolve as resolve2 } from "path";
411
+ var mapAttachments = (atts) => atts?.filter((a) => a.contentType === "image/png").map((a) => {
412
+ const match = a.path.match(/spana-output\/(.+)$/);
413
+ const relativePath = match ? match[1] : a.path;
414
+ return {
415
+ name: a.name,
416
+ contentType: a.contentType,
417
+ path: a.path,
418
+ url: `/artifacts/${relativePath}`
419
+ };
420
+ }) ?? [];
117
421
  var activeChildren = /* @__PURE__ */ new Set();
118
422
  function killActiveChildren() {
119
423
  for (const child of activeChildren) {
@@ -127,13 +431,29 @@ function nextRunId() {
127
431
  runCounter += 1;
128
432
  return `run-${Date.now()}-${runCounter}`;
129
433
  }
130
- var platformEnum = z3.enum(["web", "android", "ios"]);
434
+ var platformEnum2 = z4.enum(["web", "android", "ios"]);
435
+ function buildDeviceSelectionArgs(devices) {
436
+ if (!devices || devices.length === 0) {
437
+ return [];
438
+ }
439
+ const selectedPlatforms = new Set(devices.map((device) => device.platform));
440
+ const explicitlyTargeted = devices.filter(
441
+ (device) => Boolean(device.deviceId)
442
+ );
443
+ const explicitPlatforms = new Set(explicitlyTargeted.map((device) => device.platform));
444
+ const explicitDeviceIds = [...new Set(explicitlyTargeted.map((device) => device.deviceId))];
445
+ if (explicitDeviceIds.length === 0) {
446
+ return [];
447
+ }
448
+ const canUseSingleDeviceFlag = explicitDeviceIds.length === 1 && explicitPlatforms.size === 1 && selectedPlatforms.size === explicitPlatforms.size;
449
+ return canUseSingleDeviceFlag ? ["--device", explicitDeviceIds[0]] : ["--devices", explicitDeviceIds.join(",")];
450
+ }
131
451
  async function discoverAndLoad(flowDir) {
132
- const dir = resolve(flowDir);
452
+ const dir = resolve2(flowDir);
133
453
  try {
134
454
  const { execSync } = await import("child_process");
135
455
  const script = `
136
- import { discoverFlows, loadTestSource } from '${resolve(dir, "../../src/core/runner.ts")}';
456
+ import { discoverFlows, loadTestSource } from '${resolve2(dir, "../../src/core/runner.ts")}';
137
457
  const paths = await discoverFlows('${dir}');
138
458
  const flows = [];
139
459
  for (const p of paths) {
@@ -144,7 +464,7 @@ async function discoverAndLoad(flowDir) {
144
464
  }
145
465
  console.log(JSON.stringify(flows));
146
466
  `;
147
- const json = execSync(`bun -e "${script.replace(/"/g, '\\"')}"`, {
467
+ const json = execSync(`bun -e "${script.replaceAll('"', '\\"')}"`, {
148
468
  encoding: "utf-8",
149
469
  timeout: 15e3,
150
470
  cwd: dir
@@ -176,11 +496,11 @@ async function discoverAndLoad(flowDir) {
176
496
  var testsRouter = {
177
497
  /** Discover flows and return metadata */
178
498
  listFlows: publicProcedure.input(
179
- z3.object({
180
- flowDir: z3.string().optional(),
181
- tags: z3.array(z3.string()).optional(),
182
- platforms: z3.array(platformEnum).optional(),
183
- grep: z3.string().optional()
499
+ z4.object({
500
+ flowDir: z4.string().optional(),
501
+ tags: z4.array(z4.string()).optional(),
502
+ platforms: z4.array(platformEnum2).optional(),
503
+ grep: z4.string().optional()
184
504
  }).optional()
185
505
  ).handler(async ({ input, context }) => {
186
506
  const flowDir = input?.flowDir ?? context.config.flowDir ?? "./flows";
@@ -207,25 +527,40 @@ var testsRouter = {
207
527
  }),
208
528
  /** Start a test run in the background, return a run ID */
209
529
  run: publicProcedure.input(
210
- z3.object({
211
- platforms: z3.array(platformEnum).min(1),
212
- flowDir: z3.string().optional(),
213
- tags: z3.array(z3.string()).optional(),
214
- grep: z3.string().optional(),
215
- captureScreenshots: z3.boolean().optional(),
216
- captureSteps: z3.boolean().optional(),
217
- devices: z3.array(z3.object({ platform: platformEnum, deviceId: z3.string().optional() })).optional()
530
+ z4.object({
531
+ platforms: z4.array(platformEnum2).min(1),
532
+ flowDir: z4.string().optional(),
533
+ tags: z4.array(z4.string()).optional(),
534
+ grep: z4.string().optional(),
535
+ captureScreenshots: z4.boolean().optional(),
536
+ captureSteps: z4.boolean().optional(),
537
+ devices: z4.array(z4.object({ platform: platformEnum2, deviceId: z4.string().optional() })).optional()
218
538
  })
219
539
  ).handler(async ({ input, context }) => {
220
540
  const runId = nextRunId();
221
541
  const run = { id: runId, status: "running", results: [] };
542
+ const platforms = input.platforms;
543
+ try {
544
+ const flowDir = input.flowDir ?? context.config.flowDir ?? "./flows";
545
+ const flows = await discoverAndLoad(flowDir);
546
+ const filtered = filterFlows(flows, {
547
+ tags: input.tags,
548
+ grep: input.grep,
549
+ platforms: input.platforms
550
+ });
551
+ const totals = {};
552
+ for (const p of platforms) {
553
+ totals[p] = filtered.length;
554
+ }
555
+ run.platformTotals = totals;
556
+ } catch {
557
+ }
222
558
  activeRuns.set(runId, run);
223
559
  void (async () => {
224
- const platforms = input.platforms;
225
560
  const flowDir = input.flowDir ?? context.config.flowDir ?? "./flows";
226
561
  try {
227
562
  const { spawn } = await import("child_process");
228
- const cliPath = resolve(process.argv[1]);
563
+ const cliPath = resolve2(process.argv[1]);
229
564
  const args = [
230
565
  cliPath,
231
566
  "test",
@@ -241,18 +576,16 @@ var testsRouter = {
241
576
  if (input.tags && input.tags.length > 0) {
242
577
  args.push("--tag", input.tags.join(","));
243
578
  }
244
- if (input.devices && input.devices.length > 0) {
245
- for (const d of input.devices) {
246
- if (d.deviceId) {
247
- args.push("--device", d.deviceId);
248
- }
249
- }
250
- }
579
+ args.push(
580
+ ...buildDeviceSelectionArgs(
581
+ input.devices
582
+ )
583
+ );
251
584
  let tmpConfig;
252
585
  if (input.captureScreenshots || input.captureSteps) {
253
586
  const { writeFileSync } = await import("fs");
254
587
  const { tmpdir } = await import("os");
255
- tmpConfig = resolve(tmpdir(), `spana-studio-${runId}.config.js`);
588
+ tmpConfig = resolve2(tmpdir(), `spana-studio-${runId}.config.js`);
256
589
  const originalConfig = context.config;
257
590
  const configObj = {
258
591
  ...originalConfig,
@@ -269,7 +602,7 @@ var testsRouter = {
269
602
  args.push("--config", tmpConfig);
270
603
  }
271
604
  const child = spawn("bun", args, {
272
- cwd: resolve("."),
605
+ cwd: resolve2("."),
273
606
  stdio: ["ignore", "pipe", "pipe"]
274
607
  });
275
608
  activeChildren.add(child);
@@ -288,16 +621,6 @@ var testsRouter = {
288
621
  try {
289
622
  const event = JSON.parse(line);
290
623
  if (event.event === "flowPass" || event.event === "flowFail") {
291
- const mapAttachments = (atts) => atts?.filter((a) => a.contentType === "image/png").map((a) => {
292
- const match = a.path.match(/spana-output\/(.+)$/);
293
- const relativePath = match ? match[1] : a.path;
294
- return {
295
- name: a.name,
296
- contentType: a.contentType,
297
- path: a.path,
298
- url: `/artifacts/${relativePath}`
299
- };
300
- }) ?? [];
301
624
  run.results.push({
302
625
  name: event.name,
303
626
  platform: event.platform,
@@ -370,19 +693,27 @@ var testsRouter = {
370
693
  return { runId };
371
694
  }),
372
695
  /** Poll for run progress */
373
- status: publicProcedure.input(z3.object({ runId: z3.string() })).handler(({ input }) => {
696
+ status: publicProcedure.input(z4.object({ runId: z4.string() })).handler(({ input }) => {
374
697
  const run = activeRuns.get(input.runId);
375
698
  if (!run) {
376
- return { status: "not_found", results: [] };
699
+ return { status: "not_found", results: [], progress: {} };
700
+ }
701
+ const progress = {};
702
+ if (run.platformTotals) {
703
+ for (const [platform, total] of Object.entries(run.platformTotals)) {
704
+ const done = run.results.filter((r) => r.platform === platform).length;
705
+ progress[platform] = { done, total };
706
+ }
377
707
  }
378
708
  return {
379
709
  status: run.status,
380
710
  results: run.results,
381
- summary: run.summary
711
+ summary: run.summary,
712
+ progress
382
713
  };
383
714
  }),
384
715
  /** Get final results for a completed run */
385
- results: publicProcedure.input(z3.object({ runId: z3.string() })).handler(({ input }) => {
716
+ results: publicProcedure.input(z4.object({ runId: z4.string() })).handler(({ input }) => {
386
717
  const run = activeRuns.get(input.runId);
387
718
  if (!run || run.status !== "completed") {
388
719
  return null;
@@ -395,6 +726,7 @@ var testsRouter = {
395
726
  var studioRouter = {
396
727
  devices: devicesRouter,
397
728
  inspector: inspectorRouter,
729
+ recording: recordingRouter,
398
730
  tests: testsRouter
399
731
  };
400
732
 
@@ -502,4 +834,4 @@ async function startStudio(options) {
502
834
  export {
503
835
  startStudio
504
836
  };
505
- //# sourceMappingURL=server-MMK7PZIH.js.map
837
+ //# sourceMappingURL=server-MZERO364.js.map