@open-qa/qa 0.0.0-stage → 0.1.0-alpha.4

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 (313) hide show
  1. package/LICENSE +204 -0
  2. package/NOTICE +7 -0
  3. package/THIRD_PARTY.md +12 -0
  4. package/THIRD_PARTY_NOTICES.md +11 -0
  5. package/drizzle/0000_qa_core.sql +158 -0
  6. package/drizzle/0001_run_health.sql +3 -0
  7. package/drizzle/0002_bounded_cleanup.sql +5 -0
  8. package/drizzle/0003_step_replay_cache.sql +9 -0
  9. package/drizzle/0004_credential_expiry.sql +1 -0
  10. package/drizzle/0005_server_api.sql +19 -0
  11. package/drizzle/0006_submission_created.sql +3 -0
  12. package/drizzle/0007_findings.sql +19 -0
  13. package/drizzle/0008_classification_labels.sql +14 -0
  14. package/drizzle/0009_job_queue.sql +20 -0
  15. package/drizzle/0010_result_notifications.sql +13 -0
  16. package/drizzle/0011_result_notification_retries.sql +5 -0
  17. package/drizzle/0012_result_notification_flows.sql +44 -0
  18. package/drizzle/0013_flow_quarantine.sql +35 -0
  19. package/drizzle/0014_run_budgets.sql +2 -0
  20. package/drizzle/0015_flow_lifecycle.sql +9 -0
  21. package/drizzle/0016_open_qa_classification.sql +28 -0
  22. package/drizzle/meta/0000_snapshot.json +1002 -0
  23. package/drizzle/meta/0001_snapshot.json +1021 -0
  24. package/drizzle/meta/0002_snapshot.json +1027 -0
  25. package/drizzle/meta/0003_snapshot.json +1081 -0
  26. package/drizzle/meta/0004_snapshot.json +1087 -0
  27. package/drizzle/meta/0005_snapshot.json +1210 -0
  28. package/drizzle/meta/0006_snapshot.json +1244 -0
  29. package/drizzle/meta/0007_snapshot.json +1353 -0
  30. package/drizzle/meta/0008_snapshot.json +1435 -0
  31. package/drizzle/meta/0009_snapshot.json +1587 -0
  32. package/drizzle/meta/0010_snapshot.json +1675 -0
  33. package/drizzle/meta/0011_snapshot.json +1692 -0
  34. package/drizzle/meta/0012_snapshot.json +1818 -0
  35. package/drizzle/meta/0013_snapshot.json +2016 -0
  36. package/drizzle/meta/0014_snapshot.json +2028 -0
  37. package/drizzle/meta/0015_snapshot.json +2064 -0
  38. package/drizzle/meta/0016_snapshot.json +2076 -0
  39. package/drizzle/meta/_journal.json +125 -0
  40. package/package.json +118 -4
  41. package/problem-matcher.json +32 -0
  42. package/src/adapters/db-lease-pool.d.ts +25 -0
  43. package/src/adapters/db-lease-pool.js +293 -0
  44. package/src/adapters/dir-artifact-store.d.ts +9 -0
  45. package/src/adapters/dir-artifact-store.js +64 -0
  46. package/src/adapters/e2b-agent.d.ts +7 -0
  47. package/src/adapters/e2b-agent.js +94 -0
  48. package/src/adapters/e2b-artifacts.d.ts +3 -0
  49. package/src/adapters/e2b-artifacts.js +66 -0
  50. package/src/adapters/e2b-bounded.d.ts +1 -0
  51. package/src/adapters/e2b-bounded.js +19 -0
  52. package/src/adapters/e2b-client.d.ts +33 -0
  53. package/src/adapters/e2b-client.js +114 -0
  54. package/src/adapters/e2b-executor.d.ts +26 -0
  55. package/src/adapters/e2b-executor.js +194 -0
  56. package/src/adapters/e2b-lifetime.d.ts +20 -0
  57. package/src/adapters/e2b-lifetime.js +73 -0
  58. package/src/adapters/e2b-prune.d.ts +13 -0
  59. package/src/adapters/e2b-prune.js +42 -0
  60. package/src/adapters/file-replay-cache.d.ts +14 -0
  61. package/src/adapters/file-replay-cache.js +120 -0
  62. package/src/adapters/file-run-store.d.ts +175 -0
  63. package/src/adapters/file-run-store.js +280 -0
  64. package/src/adapters/fixed-lease-pool.d.ts +10 -0
  65. package/src/adapters/fixed-lease-pool.js +237 -0
  66. package/src/adapters/gcs/artifact-store.d.ts +49 -0
  67. package/src/adapters/gcs/artifact-store.js +247 -0
  68. package/src/adapters/gcs/client.d.ts +22 -0
  69. package/src/adapters/gcs/client.js +106 -0
  70. package/src/adapters/gcs/download.d.ts +9 -0
  71. package/src/adapters/gcs/download.js +43 -0
  72. package/src/adapters/gcs/index.d.ts +8 -0
  73. package/src/adapters/gcs/index.js +23 -0
  74. package/src/adapters/gcs/periodic-flush.d.ts +5 -0
  75. package/src/adapters/gcs/periodic-flush.js +16 -0
  76. package/src/adapters/gcs/pg-catalog.d.ts +16 -0
  77. package/src/adapters/gcs/pg-catalog.js +149 -0
  78. package/src/adapters/gcs/replay-completeness.d.ts +1 -0
  79. package/src/adapters/gcs/replay-completeness.js +65 -0
  80. package/src/adapters/gcs/scan-upload.d.ts +10 -0
  81. package/src/adapters/gcs/scan-upload.js +26 -0
  82. package/src/adapters/index.d.ts +5 -0
  83. package/src/adapters/index.js +12 -0
  84. package/src/adapters/lease-transaction.d.ts +2 -0
  85. package/src/adapters/lease-transaction.js +61 -0
  86. package/src/adapters/local-credential-resolver.d.ts +5 -0
  87. package/src/adapters/local-credential-resolver.js +15 -0
  88. package/src/adapters/local-env.d.ts +1 -0
  89. package/src/adapters/local-env.js +37 -0
  90. package/src/adapters/local-files.d.ts +17 -0
  91. package/src/adapters/local-files.js +150 -0
  92. package/src/adapters/pg-classification-store.d.ts +58 -0
  93. package/src/adapters/pg-classification-store.js +112 -0
  94. package/src/adapters/pg-replay-cache.d.ts +16 -0
  95. package/src/adapters/pg-replay-cache.js +111 -0
  96. package/src/adapters/pg-run-store.d.ts +58 -0
  97. package/src/adapters/pg-run-store.js +399 -0
  98. package/src/adapters/resource-pools.d.ts +2 -0
  99. package/src/adapters/resource-pools.js +28 -0
  100. package/src/adapters/secret-manager-credential-resolver.d.ts +44 -0
  101. package/src/adapters/secret-manager-credential-resolver.js +102 -0
  102. package/src/artifact-scan.d.ts +21 -0
  103. package/src/artifact-scan.js +139 -0
  104. package/src/budget-confirmation.d.ts +23 -0
  105. package/src/budget-confirmation.js +43 -0
  106. package/src/cache-command.d.ts +7 -0
  107. package/src/cache-command.js +107 -0
  108. package/src/classification-command.d.ts +14 -0
  109. package/src/classification-command.js +72 -0
  110. package/src/classification-diff.d.ts +10 -0
  111. package/src/classification-diff.js +47 -0
  112. package/src/classification-model.d.ts +17 -0
  113. package/src/classification-model.js +51 -0
  114. package/src/classification-notifier.d.ts +21 -0
  115. package/src/classification-notifier.js +34 -0
  116. package/src/classify-runs.d.ts +31 -0
  117. package/src/classify-runs.js +138 -0
  118. package/src/cli-program.d.ts +9 -0
  119. package/src/cli-program.js +172 -0
  120. package/src/cli.d.ts +2 -0
  121. package/src/cli.js +12 -0
  122. package/src/commands.d.ts +7 -0
  123. package/src/commands.js +17 -0
  124. package/src/credential-references.d.ts +24 -0
  125. package/src/credential-references.js +33 -0
  126. package/src/db/commands.d.ts +1 -0
  127. package/src/db/commands.js +34 -0
  128. package/src/db/credentials.d.ts +16 -0
  129. package/src/db/credentials.js +73 -0
  130. package/src/db/database.d.ts +12 -0
  131. package/src/db/database.js +135 -0
  132. package/src/db/event-chunks.d.ts +405 -0
  133. package/src/db/event-chunks.js +74 -0
  134. package/src/db/fencing.d.ts +8 -0
  135. package/src/db/fencing.js +16 -0
  136. package/src/db/flow-status.d.ts +41 -0
  137. package/src/db/flow-status.js +208 -0
  138. package/src/db/index.d.ts +12 -0
  139. package/src/db/index.js +24 -0
  140. package/src/db/queries.d.ts +73 -0
  141. package/src/db/queries.js +122 -0
  142. package/src/db/resources.d.ts +14 -0
  143. package/src/db/resources.js +61 -0
  144. package/src/db/schema.d.ts +3532 -0
  145. package/src/db/schema.js +501 -0
  146. package/src/demo-command.d.ts +1 -0
  147. package/src/demo-command.js +50 -0
  148. package/src/doctor-command.d.ts +15 -0
  149. package/src/doctor-command.js +275 -0
  150. package/src/doctor-summary.d.ts +2 -0
  151. package/src/doctor-summary.js +31 -0
  152. package/src/draft-api.d.ts +460 -0
  153. package/src/draft-api.js +333 -0
  154. package/src/draft-command.d.ts +10 -0
  155. package/src/draft-command.js +73 -0
  156. package/src/draft-hooks.d.ts +3 -0
  157. package/src/draft-hooks.js +33 -0
  158. package/src/draft-pages.d.ts +11 -0
  159. package/src/draft-pages.js +82 -0
  160. package/src/engine.d.ts +105 -0
  161. package/src/engine.js +323 -0
  162. package/src/execution-snapshot.d.ts +21 -0
  163. package/src/execution-snapshot.js +141 -0
  164. package/src/flow-check.d.ts +9 -0
  165. package/src/flow-check.js +68 -0
  166. package/src/flow-lifecycle.d.ts +6 -0
  167. package/src/flow-lifecycle.js +61 -0
  168. package/src/flow-lint.d.ts +8 -0
  169. package/src/flow-lint.js +73 -0
  170. package/src/flow-loader.d.ts +219 -0
  171. package/src/flow-loader.js +236 -0
  172. package/src/flow-source.d.ts +2 -0
  173. package/src/flow-source.js +6 -0
  174. package/src/flows-api.d.ts +1 -0
  175. package/src/flows-api.js +12 -0
  176. package/src/heal-notification.d.ts +16 -0
  177. package/src/heal-notification.js +62 -0
  178. package/src/hooks/api.d.ts +29 -0
  179. package/src/hooks/api.js +15 -0
  180. package/src/hooks/consumer.d.ts +18 -0
  181. package/src/hooks/consumer.js +98 -0
  182. package/src/hooks/loader.d.ts +6 -0
  183. package/src/hooks/loader.js +28 -0
  184. package/src/hooks/registry.d.ts +22 -0
  185. package/src/hooks/registry.js +23 -0
  186. package/src/hooks/runner.d.ts +19 -0
  187. package/src/hooks/runner.js +279 -0
  188. package/src/hooks/session-cache.d.ts +16 -0
  189. package/src/hooks/session-cache.js +42 -0
  190. package/src/hooks/session-store.d.ts +20 -0
  191. package/src/hooks/session-store.js +95 -0
  192. package/src/hooks/worker.d.ts +1 -0
  193. package/src/hooks/worker.js +84 -0
  194. package/src/http-stage-client.d.ts +367 -0
  195. package/src/http-stage-client.js +190 -0
  196. package/src/independent-model.d.ts +22 -0
  197. package/src/independent-model.js +215 -0
  198. package/src/lifecycle-command.d.ts +15 -0
  199. package/src/lifecycle-command.js +190 -0
  200. package/src/local-command.d.ts +3 -0
  201. package/src/local-command.js +27 -0
  202. package/src/local-host-executor.d.ts +38 -0
  203. package/src/local-host-executor.js +196 -0
  204. package/src/open-command.d.ts +7 -0
  205. package/src/open-command.js +39 -0
  206. package/src/operations-api.d.ts +2 -0
  207. package/src/operations-api.js +6 -0
  208. package/src/personas.d.ts +2 -0
  209. package/src/personas.js +61 -0
  210. package/src/program-runner.d.ts +3 -0
  211. package/src/program-runner.js +263 -0
  212. package/src/program-sandbox.py +75 -0
  213. package/src/program-scratch.d.ts +2 -0
  214. package/src/program-scratch.js +48 -0
  215. package/src/program-worker.mjs +101 -0
  216. package/src/public-id.d.ts +2 -0
  217. package/src/public-id.js +5 -0
  218. package/src/public-report-url.d.ts +1 -0
  219. package/src/public-report-url.js +18 -0
  220. package/src/publication-check.d.ts +1 -0
  221. package/src/publication-check.js +31 -0
  222. package/src/quarantine-command.d.ts +9 -0
  223. package/src/quarantine-command.js +69 -0
  224. package/src/remote-command.d.ts +30 -0
  225. package/src/remote-command.js +156 -0
  226. package/src/replay-image.d.ts +1 -0
  227. package/src/replay-image.js +35 -0
  228. package/src/report/assets.d.ts +1 -0
  229. package/src/report/assets.js +5 -0
  230. package/src/report/browser.css +414 -0
  231. package/src/report/browser.d.ts +1 -0
  232. package/src/report/browser.js +219 -0
  233. package/src/report/data.d.ts +1 -0
  234. package/src/report/data.js +4 -0
  235. package/src/report/generate.d.ts +1 -0
  236. package/src/report/generate.js +54 -0
  237. package/src/report/load.d.ts +870 -0
  238. package/src/report/load.js +139 -0
  239. package/src/report/resource-table.d.ts +2 -0
  240. package/src/report/resource-table.js +4 -0
  241. package/src/report/status-icon.d.ts +2 -0
  242. package/src/report/status-icon.js +20 -0
  243. package/src/report/style.css +413 -0
  244. package/src/result-notifier.d.ts +121 -0
  245. package/src/result-notifier.js +230 -0
  246. package/src/result-transports.d.ts +12 -0
  247. package/src/result-transports.js +150 -0
  248. package/src/run-command.d.ts +32 -0
  249. package/src/run-command.js +493 -0
  250. package/src/run-setup-error.d.ts +11 -0
  251. package/src/run-setup-error.js +18 -0
  252. package/src/sandboxes-command.d.ts +9 -0
  253. package/src/sandboxes-command.js +29 -0
  254. package/src/screen-proxy.d.ts +5 -0
  255. package/src/screen-proxy.js +79 -0
  256. package/src/screen-url.d.ts +18 -0
  257. package/src/screen-url.js +54 -0
  258. package/src/server/app.d.ts +29 -0
  259. package/src/server/app.js +350 -0
  260. package/src/server/auth.d.ts +33 -0
  261. package/src/server/auth.js +113 -0
  262. package/src/server/credentials.d.ts +30 -0
  263. package/src/server/credentials.js +77 -0
  264. package/src/server/errors.d.ts +9 -0
  265. package/src/server/errors.js +26 -0
  266. package/src/server/index.d.ts +35 -0
  267. package/src/server/index.js +96 -0
  268. package/src/server/maintenance.d.ts +13 -0
  269. package/src/server/maintenance.js +54 -0
  270. package/src/server/repository.d.ts +534 -0
  271. package/src/server/repository.js +219 -0
  272. package/src/setup-command.d.ts +10 -0
  273. package/src/setup-command.js +52 -0
  274. package/src/stage-environment.d.ts +1 -0
  275. package/src/stage-environment.js +35 -0
  276. package/src/stage-supervisor.mjs +95 -0
  277. package/src/studio-command.d.ts +7 -0
  278. package/src/studio-command.js +47 -0
  279. package/src/studio-control.d.ts +5 -0
  280. package/src/studio-control.js +207 -0
  281. package/src/studio-review.d.ts +24 -0
  282. package/src/studio-review.js +64 -0
  283. package/src/studio-worker.d.ts +1 -0
  284. package/src/studio-worker.js +48 -0
  285. package/src/system-config.d.ts +7 -0
  286. package/src/system-config.js +70 -0
  287. package/src/terminal-reporter.d.ts +13 -0
  288. package/src/terminal-reporter.js +93 -0
  289. package/src/vendor/gmail.d.ts +45 -0
  290. package/src/vendor/gmail.js +193 -0
  291. package/src/watch-command.d.ts +16 -0
  292. package/src/watch-command.js +93 -0
  293. package/src/watch-state.d.ts +4 -0
  294. package/src/watch-state.js +53 -0
  295. package/src/worker/execution-error.d.ts +5 -0
  296. package/src/worker/execution-error.js +10 -0
  297. package/src/worker/execution.d.ts +24 -0
  298. package/src/worker/execution.js +190 -0
  299. package/src/worker/index.d.ts +8 -0
  300. package/src/worker/index.js +40 -0
  301. package/src/worker/prune.d.ts +3 -0
  302. package/src/worker/prune.js +22 -0
  303. package/src/worker/quarantine-notifications.d.ts +8 -0
  304. package/src/worker/quarantine-notifications.js +89 -0
  305. package/src/worker/queue.d.ts +65 -0
  306. package/src/worker/queue.js +438 -0
  307. package/src/worker/result-notifications.d.ts +28 -0
  308. package/src/worker/result-notifications.js +347 -0
  309. package/src/worker/store.d.ts +4 -0
  310. package/src/worker/store.js +46 -0
  311. package/src/worker/worker.d.ts +21 -0
  312. package/src/worker/worker.js +140 -0
  313. package/README.md +0 -3
@@ -0,0 +1,73 @@
1
+ import ts from "typescript";
2
+ const operationDetail = /\b(?:css\s+selector|querySelector|nth-child|nth-of-type)\b|(?:^|[\s`'"])#[a-zA-Z][\w-]*(?=$|[\s`'".,;])|(?:\b(?:class|selector)\s+[`'"]?|`)\.[a-zA-Z_][\w-]*|[a-zA-Z][\w-]*\[[a-zA-Z_][\w-]*\s*(?:[~|^$*]?=|\])|(?:[.#][a-zA-Z_][\w-]*|\b(?:div|button|input|span|a|form|ul|li|section|main))\s*>\s*[\w.#-]+|\b[\w.-]+>[\w.#-]+|第\s*[一二三四五六七八九十百\d]+\s*個?\s*按鈕|\b(?:first|second|third|fourth|fifth|\d+(?:st|nd|rd|th))\s+button\b/i;
3
+ const deterministicJudge = /^(?:(?:the\s+)?(?:url|address)\s+(?:is|equals|matches)\s+\S+|(?:網址|URL)\s*(?:是|等於|符合)\s*\S+|(?:the\s+)?(?:page|screen)\s+(?:contains|shows|displays)\s+(?:the\s+)?(?:fixed\s+)?text\s+["'「][^"'」]+["'」]|(?:畫面|頁面)\s*(?:顯示|包含)\s*(?:固定)?文字\s*[「"'][^」"']+[」"'])\s*[.!。]?$/i;
4
+ function hasProgramCheck(source) {
5
+ const ast = ts.createSourceFile(
6
+ "flow.ts",
7
+ source,
8
+ ts.ScriptTarget.Latest,
9
+ true,
10
+ ts.ScriptKind.TS
11
+ );
12
+ let found = false;
13
+ function visit(node) {
14
+ if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression)) {
15
+ if (node.expression.name.text === "do") found = true;
16
+ let target = node.expression.expression;
17
+ while (ts.isPropertyAccessExpression(target)) {
18
+ if (target.name.text === "expect") found = true;
19
+ target = target.expression;
20
+ }
21
+ if (ts.isIdentifier(target) && target.text === "expect") found = true;
22
+ }
23
+ ts.forEachChild(node, visit);
24
+ }
25
+ visit(ast);
26
+ return found;
27
+ }
28
+ function lintFlow(flow, programSource = flow.run?.toString()) {
29
+ const warnings = [];
30
+ const warn = (path, rule, message) => {
31
+ warnings.push({ path, rule, message });
32
+ };
33
+ if (Array.from(flow.story.trim()).length < 20)
34
+ warn(
35
+ ["story"],
36
+ "story-length",
37
+ "Write at least 20 characters describing who wants what and why."
38
+ );
39
+ flow.steps.forEach((step, index) => {
40
+ const instructions = typeof step.do === "string" ? [[[], step.do]] : Object.entries(step.do ?? {}).map(([actor, text]) => [[actor], text]);
41
+ for (const [suffix, text] of instructions) {
42
+ const instruction = text.replace(/\b(?:to|in|channel)\s+#[\w-]+/gi, "channel");
43
+ if (operationDetail.test(instruction))
44
+ warn(
45
+ ["steps", index, "do", ...suffix],
46
+ "step-intent",
47
+ "Describe the intent instead of CSS selectors, element ids or numbered buttons."
48
+ );
49
+ }
50
+ if (step.judge && deterministicJudge.test(step.judge.trim()))
51
+ warn(
52
+ ["steps", index, "judge"],
53
+ "prefer-expect",
54
+ "Use web.url or web.visible expect for a fixed URL or text comparison."
55
+ );
56
+ });
57
+ if (!flow.expect_always?.length && !flow.steps.some((step) => step.expect?.length)) {
58
+ if (flow.run) {
59
+ if (!hasProgramCheck(programSource ?? ""))
60
+ warn(
61
+ ["run"],
62
+ "require-expect",
63
+ "Add at least one expect or actor.do call to the program flow."
64
+ );
65
+ } else warn(["steps"], "require-expect", "Add at least one deterministic expect to the flow.");
66
+ }
67
+ if (flow.tier === "T1" && !flow.budget?.actions && !flow.budget?.minutes)
68
+ warn(["budget"], "smoke-budget", "Set an actions or minutes budget for a T1 smoke flow.");
69
+ return warnings;
70
+ }
71
+ export {
72
+ lintFlow
73
+ };
@@ -0,0 +1,219 @@
1
+ import { type FlowSpec, type DefinitionRevision } from "@open-qa/qa-engine";
2
+ import { type ValidationIssue } from "./flow-source.js";
3
+ export declare function findQaRoot(file: string): string;
4
+ export interface LoadedFlow {
5
+ flow: FlowSpec;
6
+ programSource?: string;
7
+ definitions: {
8
+ flow: DefinitionRevision;
9
+ suite: DefinitionRevision | null;
10
+ config: DefinitionRevision | null;
11
+ };
12
+ diagnostic(issue: ValidationIssue, rule: string): string;
13
+ }
14
+ export declare function loadFlow(file: string, qaRoot?: string): Promise<FlowSpec>;
15
+ export declare function loadFlowDocument(file: string, qaRoot?: string): Promise<LoadedFlow>;
16
+ export declare function loadFlows(qaRoot: string, directory?: string): Promise<FlowSpec[]>;
17
+ export declare function loadFlowDocuments(qaRoot: string, directory?: string, onError?: (error: unknown) => void): Promise<LoadedFlow[]>;
18
+ export declare function loadConfig(qaRoot: string): Promise<{
19
+ budgets?: Partial<Record<"T1" | "T2" | "T3" | "T4", {
20
+ actions?: number | undefined;
21
+ minutes?: number | undefined;
22
+ usd?: number | undefined;
23
+ }>> | undefined;
24
+ confirmAbove?: {
25
+ actions?: number | undefined;
26
+ minutes?: number | undefined;
27
+ usd?: number | undefined;
28
+ } | undefined;
29
+ judge?: {
30
+ confidenceThreshold: number;
31
+ timeoutMs: number;
32
+ screenshots: boolean;
33
+ model?: string | undefined;
34
+ } | undefined;
35
+ reviewer?: {
36
+ confidenceThreshold: number;
37
+ timeoutMs: number;
38
+ screenshots: boolean;
39
+ model?: string | undefined;
40
+ } | undefined;
41
+ classifier?: {
42
+ screenshots: boolean;
43
+ timeoutMs: number;
44
+ model?: string | undefined;
45
+ sourceFiles?: string[] | undefined;
46
+ } | undefined;
47
+ heal?: {
48
+ runtime?: "claude-code" | "codex" | "pi" | undefined;
49
+ model?: string | undefined;
50
+ } | undefined;
51
+ projectId?: string | undefined;
52
+ timeZone?: string | undefined;
53
+ defaults?: {
54
+ lease?: string | undefined;
55
+ heal?: "auto" | "review" | "off" | undefined;
56
+ tier?: "T1" | "T2" | "T3" | "T4" | undefined;
57
+ tags?: string[] | undefined;
58
+ prod?: "never" | "safe" | undefined;
59
+ budget?: {
60
+ actions?: number | undefined;
61
+ minutes?: number | undefined;
62
+ usd?: number | undefined;
63
+ } | undefined;
64
+ record?: "rrweb"[] | undefined;
65
+ actors?: Record<string, {
66
+ role?: string | undefined;
67
+ kind?: "system" | "user" | undefined;
68
+ lease?: string | undefined;
69
+ views?: string[] | undefined;
70
+ persona?: string | undefined;
71
+ count?: number | undefined;
72
+ tools?: ("db" | "logs" | "github" | "http")[] | undefined;
73
+ }> | undefined;
74
+ views?: Record<string, {
75
+ surface: string;
76
+ start?: string | undefined;
77
+ chat?: string | undefined;
78
+ owner?: string | undefined;
79
+ }> | undefined;
80
+ setup?: {
81
+ hook: string;
82
+ params?: Record<string, import("zod").JSONType> | undefined;
83
+ }[] | undefined;
84
+ teardown?: {
85
+ hook: string;
86
+ params?: Record<string, import("zod").JSONType> | undefined;
87
+ }[] | undefined;
88
+ expect_always?: ({
89
+ "web.url": {
90
+ matches: string;
91
+ view?: string | undefined;
92
+ within?: string | undefined;
93
+ };
94
+ } | {
95
+ "web.visible": {
96
+ text?: string | undefined;
97
+ role?: string | undefined;
98
+ name?: string | undefined;
99
+ view?: string | undefined;
100
+ within?: string | undefined;
101
+ };
102
+ } | {
103
+ "web.images_loaded": {
104
+ view?: string | undefined;
105
+ within?: string | undefined;
106
+ };
107
+ } | {
108
+ "web.no_console_errors": {
109
+ ignore?: string[] | undefined;
110
+ view?: string | undefined;
111
+ within?: string | undefined;
112
+ };
113
+ } | {
114
+ "telegram.message": {
115
+ from?: string | undefined;
116
+ contains?: string | undefined;
117
+ reply_to?: string | undefined;
118
+ count?: number | undefined;
119
+ view?: string | undefined;
120
+ within?: string | undefined;
121
+ };
122
+ } | {
123
+ "telegram.no_message": {
124
+ for: string;
125
+ from?: string | undefined;
126
+ contains?: string | undefined;
127
+ reply_to?: string | undefined;
128
+ count?: number | undefined;
129
+ view?: string | undefined;
130
+ within?: string | undefined;
131
+ };
132
+ } | {
133
+ "discord.message": {
134
+ channel?: string | undefined;
135
+ has_button?: string | undefined;
136
+ embed_title?: string | undefined;
137
+ from?: string | undefined;
138
+ contains?: string | undefined;
139
+ reply_to?: string | undefined;
140
+ count?: number | undefined;
141
+ view?: string | undefined;
142
+ within?: string | undefined;
143
+ };
144
+ } | {
145
+ "email.received": {
146
+ to: string;
147
+ subject?: string | undefined;
148
+ subject_contains?: string | undefined;
149
+ contains?: string | undefined;
150
+ view?: string | undefined;
151
+ within?: string | undefined;
152
+ };
153
+ } | {
154
+ "http.status": {
155
+ url: string;
156
+ equals: number;
157
+ view?: string | undefined;
158
+ within?: string | undefined;
159
+ };
160
+ } | {
161
+ "http.json": {
162
+ url: string;
163
+ equals: import("zod").JSONType;
164
+ view?: string | undefined;
165
+ within?: string | undefined;
166
+ };
167
+ } | {
168
+ "db.count": {
169
+ sql: string;
170
+ equals: number;
171
+ view?: string | undefined;
172
+ within?: string | undefined;
173
+ };
174
+ } | {
175
+ "db.row": {
176
+ sql: string;
177
+ equals: number | Record<string, import("zod").JSONType>;
178
+ view?: string | undefined;
179
+ within?: string | undefined;
180
+ };
181
+ } | {
182
+ "logs.entry": {
183
+ filter: string;
184
+ contains?: string | undefined;
185
+ view?: string | undefined;
186
+ within?: string | undefined;
187
+ };
188
+ } | {
189
+ "github.pr": {
190
+ repo: string;
191
+ title_contains?: string | undefined;
192
+ state?: "closed" | "open" | "merged" | undefined;
193
+ view?: string | undefined;
194
+ within?: string | undefined;
195
+ };
196
+ } | {
197
+ "logs.contains": {
198
+ filter: string;
199
+ view?: string | undefined;
200
+ within?: string | undefined;
201
+ };
202
+ })[] | undefined;
203
+ } | undefined;
204
+ targets?: Record<string, {
205
+ url: string;
206
+ allow: string[];
207
+ revision?: string | undefined;
208
+ access?: "cloudflare" | undefined;
209
+ prodSafeOnly?: boolean | undefined;
210
+ systems?: {
211
+ db?: string | undefined;
212
+ logs?: string | undefined;
213
+ github?: string | undefined;
214
+ secrets?: Record<string, string> | undefined;
215
+ } | undefined;
216
+ }> | undefined;
217
+ }>;
218
+ /** Uses the same static parsers and root-wide identity rules as suite loading; never executes flows. */
219
+ export declare function loadFlowKeys(qaRoot: string): Promise<ReadonlyMap<string, string>>;
@@ -0,0 +1,236 @@
1
+ import { createHash } from "node:crypto";
2
+ import { lstat, readFile, readdir } from "node:fs/promises";
3
+ import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
4
+ import {
5
+ flowSchema,
6
+ resolveFlowDefaults,
7
+ qaConfigSchema,
8
+ suiteSchema
9
+ } from "@open-qa/qa-engine";
10
+ import { DEFAULT_PROGRAM_MINUTES, runProgram } from "./program-runner.js";
11
+ import {
12
+ parseTypeScriptSource,
13
+ parseYamlSource,
14
+ sourceError
15
+ } from "./flow-source.js";
16
+ function isMissing(error) {
17
+ return error instanceof Error && "code" in error && error.code === "ENOENT";
18
+ }
19
+ async function rejectSymlinks(root, file) {
20
+ const paths = [file];
21
+ while (paths.at(-1) !== root) paths.push(dirname(paths.at(-1)));
22
+ for (const path of paths.reverse()) {
23
+ if ((await lstat(path)).isSymbolicLink())
24
+ throw new Error(`${file}:1:1 $: symlinks are not supported`);
25
+ }
26
+ }
27
+ async function readSource(file, root) {
28
+ await rejectSymlinks(root, file);
29
+ const content = await readFile(file, "utf8");
30
+ const source = file.endsWith(".flow.ts") ? parseTypeScriptSource(file, content) : parseYamlSource(file, content);
31
+ return {
32
+ ...source,
33
+ content,
34
+ revision: {
35
+ source: relative(root, file),
36
+ sha256: createHash("sha256").update(content).digest("hex")
37
+ }
38
+ };
39
+ }
40
+ async function optionalSource(file, root) {
41
+ try {
42
+ return await readSource(file, root);
43
+ } catch (error) {
44
+ if (isMissing(error)) return void 0;
45
+ throw error;
46
+ }
47
+ }
48
+ function validate(schema, source) {
49
+ const result = schema.safeParse(source.value);
50
+ if (!result.success)
51
+ throw new Error(
52
+ result.error.issues.map((issue) => sourceError(source, issue).message).join("\n")
53
+ );
54
+ return result.data;
55
+ }
56
+ function owns(value, path) {
57
+ for (const key of path) {
58
+ if (value === null || typeof value !== "object" || !Object.hasOwn(value, key)) return false;
59
+ value = Reflect.get(value, key);
60
+ }
61
+ return true;
62
+ }
63
+ function inside(root, file) {
64
+ const path = relative(root, file);
65
+ return path !== ".." && !path.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) && !isAbsolute(path);
66
+ }
67
+ function findQaRoot(file) {
68
+ let directory = resolve(file);
69
+ while (dirname(directory) !== directory) {
70
+ if (basename(directory) === ".qa") return directory;
71
+ directory = dirname(directory);
72
+ }
73
+ throw new Error(
74
+ `cannot find a .qa directory for ${file}; use --root to specify the configuration directory`
75
+ );
76
+ }
77
+ async function loadFlow(file, qaRoot = findQaRoot(file)) {
78
+ return (await loadFlowDocument(file, qaRoot)).flow;
79
+ }
80
+ async function loadFlowDocument(file, qaRoot = findQaRoot(file)) {
81
+ file = resolve(file);
82
+ qaRoot = resolve(qaRoot);
83
+ if (!inside(qaRoot, file)) throw new Error(`${file}:1:1 $: flow must be inside ${qaRoot}`);
84
+ if (!/\.flow\.(yaml|ts)$/.test(file))
85
+ throw new Error(`${file}:1:1 $: only *.flow.yaml and *.flow.ts are supported`);
86
+ const configSource = await optionalSource(join(qaRoot, "config.yaml"), qaRoot);
87
+ const config = configSource ? validate(qaConfigSchema, configSource) : {};
88
+ let suiteSource;
89
+ for (let directory = dirname(file); inside(qaRoot, directory); directory = dirname(directory)) {
90
+ suiteSource = await optionalSource(join(directory, "_suite.yaml"), qaRoot);
91
+ if (suiteSource || directory === qaRoot) break;
92
+ }
93
+ const suite = suiteSource ? validate(suiteSchema, suiteSource) : {};
94
+ const flowSource = await readSource(file, qaRoot);
95
+ const result = flowSchema.safeParse(resolveFlowDefaults(flowSource.value, config, suite));
96
+ function diagnostic(issue, rule) {
97
+ const path = issue.path.filter((key) => typeof key !== "symbol");
98
+ const lookup = issue.keys?.length ? [...path, issue.keys[0]] : path;
99
+ let source = flowSource;
100
+ let prefix = [];
101
+ for (let length = lookup.length; length > 0; length--) {
102
+ const ancestor = lookup.slice(0, length);
103
+ if (owns(flowSource.value, ancestor)) break;
104
+ if (suiteSource && owns(suiteSource.value, ancestor)) {
105
+ source = suiteSource;
106
+ break;
107
+ }
108
+ if (configSource && owns(config.defaults, ancestor)) {
109
+ source = configSource;
110
+ prefix = ["defaults"];
111
+ break;
112
+ }
113
+ }
114
+ const message = sourceError(source, issue, prefix).message;
115
+ return rule ? message.replace(/(:\d+:\d+) /, `$1 ${rule} `) : message;
116
+ }
117
+ if (!result.success)
118
+ throw new Error(result.error.issues.map((issue) => diagnostic(issue)).join("\n"));
119
+ const flow = result.data;
120
+ if (flow.run) {
121
+ flow.budget = { ...flow.budget, minutes: flow.budget?.minutes ?? DEFAULT_PROGRAM_MINUTES };
122
+ const timeoutMs = flow.budget.minutes * 6e4;
123
+ flow.run = (context) => runProgram(flowSource.content, context, timeoutMs);
124
+ }
125
+ return {
126
+ flow,
127
+ ...flow.run ? { programSource: flowSource.content } : {},
128
+ diagnostic,
129
+ definitions: {
130
+ flow: flowSource.revision,
131
+ suite: suiteSource?.revision ?? null,
132
+ config: configSource?.revision ?? null
133
+ }
134
+ };
135
+ }
136
+ async function loadFlows(qaRoot, directory = qaRoot) {
137
+ return (await loadFlowDocuments(qaRoot, directory)).map((document) => document.flow);
138
+ }
139
+ async function loadFlowDocuments(qaRoot, directory = qaRoot, onError) {
140
+ qaRoot = resolve(qaRoot);
141
+ directory = resolve(directory);
142
+ if (!inside(qaRoot, directory))
143
+ throw new Error(`${directory}:1:1 $: flow directory must be inside ${qaRoot}`);
144
+ await rejectSymlinks(qaRoot, directory);
145
+ const configSource = await optionalSource(join(qaRoot, "config.yaml"), qaRoot);
146
+ if (configSource) validate(qaConfigSchema, configSource);
147
+ const { files, suites } = await discoverFlowSources(qaRoot);
148
+ function report(error) {
149
+ if (!onError) throw error;
150
+ onError(error);
151
+ }
152
+ for (const file of suites.sort()) {
153
+ try {
154
+ validate(suiteSchema, await readSource(file, qaRoot));
155
+ } catch (error) {
156
+ report(error);
157
+ }
158
+ }
159
+ const { readable } = await readFlowKeys(qaRoot, files, report);
160
+ const selected = readable.filter((file) => inside(directory, file));
161
+ if (!selected.length && !files.some((file) => inside(directory, file)))
162
+ throw new Error(`${directory}:1:1 $: no flows found (*.flow.yaml or *.flow.ts)`);
163
+ const flows = [];
164
+ for (const file of selected) {
165
+ try {
166
+ flows.push(await loadFlowDocument(file, qaRoot));
167
+ } catch (error) {
168
+ report(error);
169
+ }
170
+ }
171
+ return flows;
172
+ }
173
+ async function loadConfig(qaRoot) {
174
+ qaRoot = resolve(qaRoot);
175
+ const source = await optionalSource(join(qaRoot, "config.yaml"), qaRoot);
176
+ return source ? validate(qaConfigSchema, source) : {};
177
+ }
178
+ async function discoverFlowSources(qaRoot) {
179
+ const files = [];
180
+ const suites = [];
181
+ async function walk(path) {
182
+ for (const entry of await readdir(path, { withFileTypes: true })) {
183
+ if (entry.isDirectory()) await walk(join(path, entry.name));
184
+ else if (entry.isFile()) {
185
+ if (entry.name === "_suite.yaml") suites.push(join(path, entry.name));
186
+ else if (/\.flow\.(yaml|ts)$/.test(entry.name)) files.push(join(path, entry.name));
187
+ } else if (entry.isSymbolicLink() && entry.name === "_suite.yaml") {
188
+ suites.push(join(path, entry.name));
189
+ }
190
+ }
191
+ }
192
+ await walk(qaRoot);
193
+ return { files: files.sort(), suites: suites.sort() };
194
+ }
195
+ async function readFlowKeys(qaRoot, files, report = (error) => {
196
+ throw error;
197
+ }) {
198
+ const keys = /* @__PURE__ */ new Map();
199
+ const readable = [];
200
+ for (const file of files.sort()) {
201
+ let source;
202
+ try {
203
+ source = await readSource(file, qaRoot);
204
+ } catch (error) {
205
+ report(error);
206
+ continue;
207
+ }
208
+ const key = source.value !== null && typeof source.value === "object" && "key" in source.value ? source.value.key : void 0;
209
+ if (typeof key === "string") {
210
+ const previous = keys.get(key);
211
+ if (previous)
212
+ throw sourceError(source, {
213
+ path: ["key"],
214
+ message: `duplicate flow key ${key}; already defined in ${previous}`
215
+ });
216
+ keys.set(key, file);
217
+ }
218
+ readable.push(file);
219
+ }
220
+ return { keys, readable };
221
+ }
222
+ async function loadFlowKeys(qaRoot) {
223
+ qaRoot = resolve(qaRoot);
224
+ await rejectSymlinks(qaRoot, qaRoot);
225
+ const { files } = await discoverFlowSources(qaRoot);
226
+ return (await readFlowKeys(qaRoot, files)).keys;
227
+ }
228
+ export {
229
+ findQaRoot,
230
+ loadConfig,
231
+ loadFlow,
232
+ loadFlowDocument,
233
+ loadFlowDocuments,
234
+ loadFlowKeys,
235
+ loadFlows
236
+ };
@@ -0,0 +1,2 @@
1
+ export { parseYamlSource, parseTypeScriptSource, sourceError } from "@open-qa/qa-inspect/server";
2
+ export type { FieldPath, FlowSource, ValidationIssue } from "@open-qa/qa-inspect/server";
@@ -0,0 +1,6 @@
1
+ import { parseYamlSource, parseTypeScriptSource, sourceError } from "@open-qa/qa-inspect/server";
2
+ export {
3
+ parseTypeScriptSource,
4
+ parseYamlSource,
5
+ sourceError
6
+ };
@@ -0,0 +1 @@
1
+ export { loadFlow, loadFlows, loadFlowDocument, loadFlowDocuments, type LoadedFlow, } from "./flow-loader.js";
@@ -0,0 +1,12 @@
1
+ import {
2
+ loadFlow,
3
+ loadFlows,
4
+ loadFlowDocument,
5
+ loadFlowDocuments
6
+ } from "./flow-loader.js";
7
+ export {
8
+ loadFlow,
9
+ loadFlowDocument,
10
+ loadFlowDocuments,
11
+ loadFlows
12
+ };
@@ -0,0 +1,16 @@
1
+ import type { RunEvent } from "@open-qa/qa-engine/protocol";
2
+ import type { SecretRedactor } from "@open-qa/qa-engine";
3
+ import type { ArtifactScan } from "./artifact-scan.js";
4
+ export declare function healNotificationChannel(env: NodeJS.ProcessEnv): string | undefined;
5
+ export declare function notifyHeals(options: {
6
+ root: string;
7
+ runId: string;
8
+ events: readonly Extract<RunEvent, {
9
+ kind: "heal_result";
10
+ }>[];
11
+ channel: string;
12
+ token: string;
13
+ redactor: SecretRedactor;
14
+ scan: ArtifactScan;
15
+ fetch?: typeof fetch;
16
+ }): Promise<void>;
@@ -0,0 +1,62 @@
1
+ import { ArtifactReader } from "@open-qa/qa-inspect/server";
2
+ import { createHash } from "node:crypto";
3
+ import { z } from "zod";
4
+ function healNotificationChannel(env) {
5
+ return z.string().regex(/^\d{5,30}$/, "Invalid QA_HEAL_DISCORD_CHANNEL_ID").optional().parse(env.QA_HEAL_DISCORD_CHANNEL_ID);
6
+ }
7
+ async function notifyHeals(options) {
8
+ if (options.scan.status !== "passed") throw new Error("Heal artifact sharing is blocked");
9
+ if (!/^\d{5,30}$/.test(options.channel)) throw new Error("Invalid Discord channel");
10
+ options.redactor.add([options.token]);
11
+ const artifacts = new ArtifactReader(options.root);
12
+ for (const event of options.events) {
13
+ const form = new FormData();
14
+ const attachments = [];
15
+ for (const [label, path] of [
16
+ ["before", event.beforeShot],
17
+ ["after", event.shot]
18
+ ]) {
19
+ if (!path || !/^shots\/[a-zA-Z0-9_-]+\.png$/.test(path)) continue;
20
+ const bytes = await artifacts.read(`runs/${options.runId}/stage/${path}`, 4 * 1024 * 1024);
21
+ if (createHash("sha256").update(bytes).digest("hex") !== options.scan.files[`stage/${path}`])
22
+ throw new Error("Heal screenshot changed after scanning");
23
+ if (!bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10])))
24
+ throw new Error("Invalid heal screenshot");
25
+ const id = attachments.length;
26
+ attachments.push({ id, filename: `${label}.png` });
27
+ form.set(
28
+ `files[${id}]`,
29
+ new Blob([new Uint8Array(bytes)], { type: "image/png" }),
30
+ `${label}.png`
31
+ );
32
+ }
33
+ form.set(
34
+ "payload_json",
35
+ JSON.stringify({
36
+ content: options.redactor.text(
37
+ `QA self-heal ${event.outcome}: ${event.step}
38
+ Run: ${options.runId}
39
+ Mode: ${event.mode}; cache: ${event.cache}${event.cacheId ? `
40
+ Review: ${event.cacheId}` : ""}`
41
+ ),
42
+ allowed_mentions: { parse: [] },
43
+ attachments
44
+ })
45
+ );
46
+ const response = await (options.fetch ?? fetch)(
47
+ `https://discord.com/api/v10/channels/${options.channel}/messages`,
48
+ {
49
+ method: "POST",
50
+ headers: { authorization: `Bot ${options.token}` },
51
+ body: form,
52
+ signal: AbortSignal.timeout(15e3),
53
+ redirect: "error"
54
+ }
55
+ );
56
+ if (!response.ok) throw new Error("Discord heal notification failed");
57
+ }
58
+ }
59
+ export {
60
+ healNotificationChannel,
61
+ notifyHeals
62
+ };
@@ -0,0 +1,29 @@
1
+ import type { HookContext, StageClient } from "@open-qa/qa-engine";
2
+ import type { JsonObject } from "@open-qa/qa-engine/protocol";
3
+ export type HookStage = Omit<StageClient, "events" | "setStep" | "fire">;
4
+ export interface HookInput extends Omit<HookContext, "stage" | "progress"> {
5
+ run: {
6
+ id: string;
7
+ marker: string;
8
+ attempt: 1 | 2;
9
+ };
10
+ lease: JsonObject;
11
+ params: JsonObject;
12
+ signal: AbortSignal;
13
+ stage: HookStage;
14
+ browser: {
15
+ signIn(actor: string | {
16
+ id: string;
17
+ }, account: string): Promise<void>;
18
+ };
19
+ }
20
+ export type Hook = (context: HookInput) => Promise<JsonObject | void>;
21
+ export declare function defineHook(hook: Hook): Hook;
22
+ export { HookRegistry } from "./registry.js";
23
+ export type { HostHook, HookServices, HookRegistryFactory, HookRegistryOptions, } from "./registry.js";
24
+ export type { HookCall, HookContext, HookResult } from "@open-qa/qa-engine";
25
+ export { FileHookRunner } from "./runner.js";
26
+ export type { FileHookRunnerOptions } from "./runner.js";
27
+ export { SessionCache, SESSION_EXPIRY_MARGIN_MS } from "./session-cache.js";
28
+ export type { CachedSession } from "./session-cache.js";
29
+ export { SessionCacheError } from "./session-store.js";
@@ -0,0 +1,15 @@
1
+ function defineHook(hook) {
2
+ return hook;
3
+ }
4
+ import { HookRegistry } from "./registry.js";
5
+ import { FileHookRunner } from "./runner.js";
6
+ import { SessionCache, SESSION_EXPIRY_MARGIN_MS } from "./session-cache.js";
7
+ import { SessionCacheError } from "./session-store.js";
8
+ export {
9
+ FileHookRunner,
10
+ HookRegistry,
11
+ SESSION_EXPIRY_MARGIN_MS,
12
+ SessionCache,
13
+ SessionCacheError,
14
+ defineHook
15
+ };