@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,501 @@
1
+ import { sql } from "drizzle-orm";
2
+ import {
3
+ bigint,
4
+ bigserial,
5
+ check,
6
+ doublePrecision,
7
+ foreignKey,
8
+ index,
9
+ integer,
10
+ jsonb,
11
+ pgSchema,
12
+ primaryKey,
13
+ text,
14
+ timestamp,
15
+ uniqueIndex
16
+ } from "drizzle-orm/pg-core";
17
+ const qa = pgSchema("qa");
18
+ const project = () => text("project_id").notNull();
19
+ const time = (name) => doublePrecision(name).notNull();
20
+ const created = () => timestamp("created_at", { withTimezone: true }).notNull().defaultNow();
21
+ const batches = qa.table(
22
+ "batches",
23
+ {
24
+ projectId: project(),
25
+ id: text("id").notNull(),
26
+ trigger: text("trigger").notNull(),
27
+ target: text("target"),
28
+ commit: text("commit"),
29
+ createdBy: text("created_by"),
30
+ createdAt: created()
31
+ },
32
+ (t) => [primaryKey({ columns: [t.projectId, t.id] })]
33
+ );
34
+ const runs = qa.table(
35
+ "runs",
36
+ {
37
+ projectId: project(),
38
+ id: text("id").notNull(),
39
+ batchId: text("batch_id"),
40
+ flow: text("flow").notNull(),
41
+ startedAt: time("started_at"),
42
+ metadata: jsonb("metadata").$type(),
43
+ phase: text("phase").notNull().default("queued"),
44
+ verdict: text("verdict"),
45
+ finishedAt: doublePrecision("finished_at"),
46
+ reason: text("reason"),
47
+ eventCount: integer("event_count").notNull().default(0),
48
+ lastSeq: bigint("last_seq", { mode: "number" }).notNull().default(0),
49
+ lastT: time("last_t").default(0),
50
+ eventBytes: bigint("event_bytes", { mode: "number" }).notNull().default(0),
51
+ writerLeaseId: text("writer_lease_id"),
52
+ heartbeatAt: timestamp("heartbeat_at", { withTimezone: true }),
53
+ usage: jsonb("usage").$type(),
54
+ errorReason: text("error_reason"),
55
+ costUsd: doublePrecision("cost_usd").notNull().default(0),
56
+ classification: text("classification")
57
+ },
58
+ (t) => [
59
+ primaryKey({ columns: [t.projectId, t.id] }),
60
+ foreignKey({
61
+ columns: [t.projectId, t.batchId],
62
+ foreignColumns: [batches.projectId, batches.id]
63
+ }),
64
+ index("runs_recent").on(t.projectId, t.startedAt.desc(), sql`${t.id} COLLATE "C"`),
65
+ check(
66
+ "run_classification",
67
+ sql`${t.classification} IN ('product-bug','test-case','env','flaky','agent')`
68
+ ),
69
+ check(
70
+ "run_classification_metadata",
71
+ sql`${t.metadata}->'failureClassification'->>'category' IN ('product-bug','test-case','env','flaky','agent')`
72
+ ),
73
+ check(
74
+ "run_cursor_nonnegative",
75
+ sql`${t.lastSeq} >= 0 AND ${t.lastT} >= 0 AND ${t.eventCount} >= 0 AND ${t.eventBytes} >= 0`
76
+ )
77
+ ]
78
+ );
79
+ const resultNotifications = qa.table(
80
+ "result_notifications",
81
+ {
82
+ projectId: project(),
83
+ batchId: text("batch_id").notNull(),
84
+ channel: text("channel").notNull(),
85
+ context: jsonb("context").notNull(),
86
+ completedAt: timestamp("completed_at", { withTimezone: true }),
87
+ abandonedAt: timestamp("abandoned_at", { withTimezone: true }),
88
+ attempts: integer("attempts").notNull().default(0),
89
+ availableAt: timestamp("available_at", { withTimezone: true }).notNull().defaultNow()
90
+ },
91
+ (t) => [
92
+ primaryKey({ columns: [t.projectId, t.batchId, t.channel] }),
93
+ foreignKey({
94
+ columns: [t.projectId, t.batchId],
95
+ foreignColumns: [batches.projectId, batches.id]
96
+ }),
97
+ check("result_notification_channel", sql`${t.channel} IN ('commit','pr','discord')`),
98
+ check("result_notification_attempts", sql`${t.attempts} BETWEEN 0 AND 5`),
99
+ index("result_notifications_pending").on(t.availableAt).where(sql`${t.completedAt} IS NULL AND ${t.abandonedAt} IS NULL`)
100
+ ]
101
+ );
102
+ const resultNotificationFlows = qa.table(
103
+ "result_notification_flows",
104
+ {
105
+ projectId: project(),
106
+ batchId: text("batch_id").notNull(),
107
+ channel: text("channel").notNull().default("pr"),
108
+ flow: text("flow").notNull(),
109
+ outcome: text("outcome"),
110
+ completedAt: timestamp("completed_at", { withTimezone: true }),
111
+ abandonedAt: timestamp("abandoned_at", { withTimezone: true }),
112
+ attempts: integer("attempts").notNull().default(0),
113
+ availableAt: timestamp("available_at", { withTimezone: true }).notNull().defaultNow()
114
+ },
115
+ (t) => [
116
+ primaryKey({ columns: [t.projectId, t.batchId, t.flow] }),
117
+ foreignKey({
118
+ columns: [t.projectId, t.batchId, t.channel],
119
+ foreignColumns: [
120
+ resultNotifications.projectId,
121
+ resultNotifications.batchId,
122
+ resultNotifications.channel
123
+ ]
124
+ }),
125
+ check("result_notification_flow_channel", sql`${t.channel} = 'pr'`),
126
+ check("result_notification_flow_attempts", sql`${t.attempts} BETWEEN 0 AND 5`),
127
+ check("result_notification_flow_outcome", sql`${t.outcome} IN ('delivered','superseded')`),
128
+ check(
129
+ "result_notification_flow_completion",
130
+ sql`(${t.outcome} IS NULL) = (${t.completedAt} IS NULL)`
131
+ ),
132
+ index("result_notification_flow_delivered").on(t.projectId, t.flow).where(sql`${t.outcome} = 'delivered'`)
133
+ ]
134
+ );
135
+ const flowStatuses = qa.table(
136
+ "flow_statuses",
137
+ {
138
+ projectId: project(),
139
+ flow: text("flow").notNull(),
140
+ status: text("status").notNull().default("draft"),
141
+ flakyStreak: integer("flaky_streak").notNull().default(0),
142
+ generation: integer("generation").notNull().default(0),
143
+ owner: text("owner"),
144
+ latestRepeat: jsonb("latest_repeat").$type(),
145
+ firstRunId: text("first_run_id"),
146
+ firstRunRevision: text("first_run_revision"),
147
+ firstRunAt: timestamp("first_run_at", { withTimezone: true }),
148
+ acceptedAt: timestamp("accepted_at", { withTimezone: true }),
149
+ acceptedBy: text("accepted_by"),
150
+ retiredAt: timestamp("retired_at", { withTimezone: true })
151
+ },
152
+ (t) => [
153
+ primaryKey({ columns: [t.projectId, t.flow] }),
154
+ check("flow_status", sql`${t.status} IN ('draft','review','active','quarantined','retired')`),
155
+ check("flow_streak", sql`${t.flakyStreak} >= 0 AND ${t.generation} >= 0`)
156
+ ]
157
+ );
158
+ const flowResults = qa.table(
159
+ "flow_results",
160
+ {
161
+ projectId: project(),
162
+ executionId: text("execution_id").notNull(),
163
+ flow: text("flow").notNull(),
164
+ quarantined: integer("quarantined").notNull()
165
+ },
166
+ (t) => [
167
+ primaryKey({ columns: [t.projectId, t.executionId] }),
168
+ check("flow_result_quarantined", sql`${t.quarantined} IN (0,1)`)
169
+ ]
170
+ );
171
+ const quarantineNotifications = qa.table(
172
+ "quarantine_notifications",
173
+ {
174
+ projectId: project(),
175
+ flow: text("flow").notNull(),
176
+ generation: integer("generation").notNull(),
177
+ runId: text("run_id").notNull(),
178
+ owner: text("owner"),
179
+ completedAt: timestamp("completed_at", { withTimezone: true }),
180
+ abandonedAt: timestamp("abandoned_at", { withTimezone: true }),
181
+ attempts: integer("attempts").notNull().default(0),
182
+ availableAt: timestamp("available_at", { withTimezone: true }).notNull().defaultNow()
183
+ },
184
+ (t) => [
185
+ primaryKey({ columns: [t.projectId, t.flow, t.generation] }),
186
+ check("quarantine_notification_attempts", sql`${t.attempts} BETWEEN 0 AND 5`)
187
+ ]
188
+ );
189
+ const lanes = qa.table(
190
+ "lanes",
191
+ {
192
+ projectId: project(),
193
+ runId: text("run_id").notNull(),
194
+ actor: text("actor").notNull(),
195
+ status: text("status").notNull(),
196
+ startedAt: time("started_at"),
197
+ finishedAt: doublePrecision("finished_at")
198
+ },
199
+ (t) => [
200
+ primaryKey({ columns: [t.projectId, t.runId, t.actor] }),
201
+ foreignKey({ columns: [t.projectId, t.runId], foreignColumns: [runs.projectId, runs.id] })
202
+ ]
203
+ );
204
+ const stepRuns = qa.table(
205
+ "step_runs",
206
+ {
207
+ projectId: project(),
208
+ runId: text("run_id").notNull(),
209
+ actor: text("actor").notNull(),
210
+ step: text("step").notNull(),
211
+ seq: bigint("seq", { mode: "number" }).notNull(),
212
+ status: text("status").notNull(),
213
+ startedAt: time("started_at"),
214
+ finishedAt: doublePrecision("finished_at")
215
+ },
216
+ (t) => [
217
+ primaryKey({ columns: [t.projectId, t.runId, t.seq] }),
218
+ foreignKey({ columns: [t.projectId, t.runId], foreignColumns: [runs.projectId, runs.id] })
219
+ ]
220
+ );
221
+ const eventChunks = qa.table(
222
+ "event_chunks",
223
+ {
224
+ projectId: project(),
225
+ runId: text("run_id").notNull(),
226
+ id: text("id").notNull(),
227
+ objectKey: text("object_key").notNull(),
228
+ sha256: text("sha256").notNull(),
229
+ count: integer("count").notNull(),
230
+ bytes: integer("bytes").notNull(),
231
+ firstSeq: bigint("first_seq", { mode: "number" }).notNull(),
232
+ lastSeq: bigint("last_seq", { mode: "number" }).notNull(),
233
+ firstT: time("first_t"),
234
+ lastT: time("last_t"),
235
+ state: text("state").notNull().default("uploading"),
236
+ cleanedAt: timestamp("cleaned_at", { withTimezone: true }),
237
+ createdAt: created()
238
+ },
239
+ (t) => [
240
+ primaryKey({ columns: [t.projectId, t.runId, t.id] }),
241
+ uniqueIndex("event_object_key").on(t.objectKey),
242
+ foreignKey({ columns: [t.projectId, t.runId], foreignColumns: [runs.projectId, runs.id] }),
243
+ check("chunk_state", sql`${t.state} IN ('uploading','committed','abandoned','cleaned')`),
244
+ check(
245
+ "chunk_range",
246
+ sql`${t.count} > 0 AND ${t.bytes} > 0 AND ${t.firstSeq} > 0 AND ${t.lastSeq} >= ${t.firstSeq} AND ${t.lastT} >= ${t.firstT}`
247
+ )
248
+ ]
249
+ );
250
+ const events = qa.table(
251
+ "events",
252
+ {
253
+ projectId: project(),
254
+ runId: text("run_id").notNull(),
255
+ seq: bigint("seq", { mode: "number" }).notNull(),
256
+ t: time("t"),
257
+ kind: text("kind").notNull(),
258
+ actor: text("actor"),
259
+ step: text("step"),
260
+ chunkId: text("chunk_id").notNull(),
261
+ offset: integer("offset").notNull()
262
+ },
263
+ (t) => [
264
+ primaryKey({ columns: [t.projectId, t.runId, t.seq] }),
265
+ foreignKey({
266
+ columns: [t.projectId, t.runId, t.chunkId],
267
+ foreignColumns: [eventChunks.projectId, eventChunks.runId, eventChunks.id]
268
+ })
269
+ ]
270
+ );
271
+ const artifacts = qa.table(
272
+ "artifacts",
273
+ {
274
+ projectId: project(),
275
+ runId: text("run_id").notNull(),
276
+ path: text("path").notNull(),
277
+ kind: text("kind").notNull(),
278
+ objectKey: text("object_key").notNull(),
279
+ bytes: bigint("bytes", { mode: "number" }).notNull(),
280
+ sha256: text("sha256").notNull()
281
+ },
282
+ (t) => [
283
+ primaryKey({ columns: [t.projectId, t.runId, t.path] }),
284
+ foreignKey({ columns: [t.projectId, t.runId], foreignColumns: [runs.projectId, runs.id] })
285
+ ]
286
+ );
287
+ const leaseResources = qa.table(
288
+ "lease_resources",
289
+ {
290
+ projectId: project(),
291
+ id: text("id").notNull(),
292
+ kind: text("kind").notNull(),
293
+ canonicalId: text("canonical_id").notNull(),
294
+ secretRef: text("secret_ref").notNull()
295
+ },
296
+ (t) => [
297
+ primaryKey({ columns: [t.projectId, t.id] }),
298
+ index("resource_kinds").on(t.projectId, t.kind)
299
+ ]
300
+ );
301
+ const leases = qa.table(
302
+ "leases",
303
+ {
304
+ projectId: project(),
305
+ id: text("id").notNull(),
306
+ runId: text("run_id").notNull(),
307
+ actor: text("actor").notNull(),
308
+ owner: text("owner").notNull(),
309
+ epoch: bigserial("epoch", { mode: "bigint" }).notNull(),
310
+ state: text("state").notNull().default("active"),
311
+ expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
312
+ allocations: jsonb("allocations").$type().notNull()
313
+ },
314
+ (t) => [
315
+ primaryKey({ columns: [t.projectId, t.id] }),
316
+ check("lease_state", sql`${t.state} IN ('active','quarantined','released')`)
317
+ ]
318
+ );
319
+ const leaseClaims = qa.table(
320
+ "lease_claims",
321
+ {
322
+ projectId: project(),
323
+ identity: text("identity").notNull(),
324
+ leaseId: text("lease_id").notNull()
325
+ },
326
+ (t) => [
327
+ primaryKey({ columns: [t.projectId, t.identity] }),
328
+ foreignKey({
329
+ columns: [t.projectId, t.leaseId],
330
+ foreignColumns: [leases.projectId, leases.id]
331
+ })
332
+ ]
333
+ );
334
+ const jobs = qa.table(
335
+ "jobs",
336
+ {
337
+ projectId: project(),
338
+ id: text("id").notNull(),
339
+ runId: text("run_id").notNull(),
340
+ state: text("state").notNull().default("queued"),
341
+ availableAt: timestamp("available_at", { withTimezone: true }).notNull().defaultNow(),
342
+ attempts: integer("attempts").notNull().default(0),
343
+ owner: text("owner"),
344
+ epoch: bigserial("epoch", { mode: "bigint" }).notNull(),
345
+ leaseUntil: timestamp("lease_until", { withTimezone: true }),
346
+ retryOf: text("retry_of"),
347
+ cleanedAt: timestamp("cleaned_at", { withTimezone: true }),
348
+ verifiedRevision: text("verified_revision"),
349
+ infrastructureFailure: integer("infrastructure_failure").notNull().default(0)
350
+ },
351
+ (t) => [
352
+ primaryKey({ columns: [t.projectId, t.id] }),
353
+ foreignKey({ columns: [t.projectId, t.runId], foreignColumns: [runs.projectId, runs.id] }),
354
+ index("jobs_available").on(t.projectId, t.state, t.availableAt),
355
+ uniqueIndex("job_run").on(t.projectId, t.runId),
356
+ uniqueIndex("job_retry").on(t.projectId, t.retryOf),
357
+ check("job_attempt", sql`${t.attempts} IN (0,1)`)
358
+ ]
359
+ );
360
+ const credentials = qa.table(
361
+ "credentials",
362
+ {
363
+ projectId: project(),
364
+ userId: text("user_id").notNull(),
365
+ provider: text("provider").notNull(),
366
+ secretRef: text("secret_ref").notNull(),
367
+ expiresAt: timestamp("expires_at", { withTimezone: true })
368
+ },
369
+ (t) => [primaryKey({ columns: [t.projectId, t.userId, t.provider] })]
370
+ );
371
+ const serverSubmissions = qa.table(
372
+ "server_submissions",
373
+ {
374
+ projectId: project(),
375
+ principalId: text("principal_id").notNull(),
376
+ idempotencyKey: text("idempotency_key").notNull(),
377
+ fingerprint: text("fingerprint").notNull(),
378
+ batchId: text("batch_id").notNull(),
379
+ response: jsonb("response").notNull(),
380
+ createdAt: created()
381
+ },
382
+ (t) => [
383
+ primaryKey({ columns: [t.projectId, t.principalId, t.idempotencyKey] }),
384
+ uniqueIndex("submission_batch").on(t.projectId, t.batchId),
385
+ index("submission_created").on(t.projectId, t.createdAt.desc(), t.batchId),
386
+ foreignKey({
387
+ columns: [t.projectId, t.batchId],
388
+ foreignColumns: [batches.projectId, batches.id]
389
+ })
390
+ ]
391
+ );
392
+ const readPublications = qa.table(
393
+ "read_publications",
394
+ {
395
+ projectId: project(),
396
+ kind: text("kind").notNull(),
397
+ document: jsonb("document").notNull()
398
+ },
399
+ (t) => [primaryKey({ columns: [t.projectId, t.kind] })]
400
+ );
401
+ const cacheEntries = qa.table(
402
+ "cache_entries",
403
+ {
404
+ projectId: project(),
405
+ cacheKey: text("cache_key").notNull(),
406
+ version: integer("version").notNull(),
407
+ entry: jsonb("entry").$type().notNull(),
408
+ createdAt: created()
409
+ },
410
+ (t) => [
411
+ primaryKey({ columns: [t.projectId, t.cacheKey, t.version] }),
412
+ check("cache_version_positive", sql`${t.version} > 0`)
413
+ ]
414
+ );
415
+ const findings = qa.table(
416
+ "findings",
417
+ {
418
+ projectId: project(),
419
+ runId: text("run_id").notNull(),
420
+ ordinal: integer("ordinal").notNull(),
421
+ actor: text("actor").notNull(),
422
+ step: text("step").notNull(),
423
+ category: text("category").notNull(),
424
+ severity: text("severity").notNull(),
425
+ description: text("description").notNull(),
426
+ eventSeqs: jsonb("event_seqs").$type().notNull(),
427
+ shots: jsonb("shots").$type().notNull(),
428
+ createdAt: created()
429
+ },
430
+ (t) => [
431
+ primaryKey({ columns: [t.projectId, t.runId, t.ordinal] }),
432
+ foreignKey({ columns: [t.projectId, t.runId], foreignColumns: [runs.projectId, runs.id] }),
433
+ check("finding_ordinal_positive", sql`${t.ordinal} > 0`),
434
+ check("finding_severity", sql`${t.severity} IN ('low','medium','high')`),
435
+ check("finding_category", sql`${t.category} IN ('scope','other')`)
436
+ ]
437
+ );
438
+ const classificationLabels = qa.table(
439
+ "classification_labels",
440
+ {
441
+ projectId: project(),
442
+ runId: text("run_id").notNull(),
443
+ ordinal: integer("ordinal").notNull(),
444
+ category: text("category").notNull(),
445
+ reason: text("reason").notNull(),
446
+ modifiedBy: text("modified_by").notNull(),
447
+ modifiedAt: time("modified_at"),
448
+ predicted: jsonb("predicted").$type()
449
+ },
450
+ (t) => [
451
+ primaryKey({ columns: [t.projectId, t.runId, t.ordinal] }),
452
+ foreignKey({ columns: [t.projectId, t.runId], foreignColumns: [runs.projectId, runs.id] }),
453
+ check(
454
+ "classification_label_category",
455
+ sql`${t.category} IN ('product-bug','test-case','env','flaky','agent')`
456
+ ),
457
+ check(
458
+ "classification_prediction_category",
459
+ sql`${t.predicted}->>'category' IN ('product-bug','test-case','env','flaky','agent')`
460
+ )
461
+ ]
462
+ );
463
+ const workerSlots = qa.table(
464
+ "worker_slots",
465
+ {
466
+ id: integer("id").primaryKey(),
467
+ projectId: text("project_id"),
468
+ jobId: text("job_id")
469
+ },
470
+ (t) => [
471
+ check("worker_slot_range", sql`${t.id} BETWEEN 1 AND 8`),
472
+ check("worker_slot_pair", sql`(${t.projectId} IS NULL) = (${t.jobId} IS NULL)`),
473
+ uniqueIndex("worker_slot_job").on(t.projectId, t.jobId)
474
+ ]
475
+ );
476
+ export {
477
+ artifacts,
478
+ batches,
479
+ cacheEntries,
480
+ classificationLabels,
481
+ credentials,
482
+ eventChunks,
483
+ events,
484
+ findings,
485
+ flowResults,
486
+ flowStatuses,
487
+ jobs,
488
+ lanes,
489
+ leaseClaims,
490
+ leaseResources,
491
+ leases,
492
+ qa,
493
+ quarantineNotifications,
494
+ readPublications,
495
+ resultNotificationFlows,
496
+ resultNotifications,
497
+ runs,
498
+ serverSubmissions,
499
+ stepRuns,
500
+ workerSlots
501
+ };
@@ -0,0 +1 @@
1
+ export declare function demoCommand(directory: string): Promise<void>;
@@ -0,0 +1,50 @@
1
+ import { execFile } from "node:child_process";
2
+ import { promisify } from "node:util";
3
+ import { fileURLToPath } from "node:url";
4
+ import { rm } from "node:fs/promises";
5
+ import { resolve } from "node:path";
6
+ import { generateReport } from "./report/generate.js";
7
+ async function demoCommand(directory) {
8
+ const root = resolve(directory);
9
+ try {
10
+ await promisify(execFile)(
11
+ process.execPath,
12
+ [fileURLToPath(import.meta.resolve("@open-qa/qa-studio/demo")), root],
13
+ {
14
+ env: { PATH: process.env.PATH }
15
+ }
16
+ );
17
+ } catch (cause) {
18
+ const stderr = cause && typeof cause === "object" && "stderr" in cause && typeof cause.stderr === "string" ? cause.stderr.trim() : "";
19
+ throw new Error(
20
+ `Could not create demo data: ${stderr || (cause instanceof Error ? cause.message : String(cause))}`,
21
+ { cause }
22
+ );
23
+ }
24
+ try {
25
+ for (const id of [
26
+ "demo-passed",
27
+ "demo-single",
28
+ "demo-multi",
29
+ "demo-heal-known",
30
+ "demo-heal-unknown"
31
+ ])
32
+ await generateReport(root, id);
33
+ } catch (error) {
34
+ try {
35
+ await rm(root, { recursive: true, force: true });
36
+ } catch (cleanup) {
37
+ throw new AggregateError([error, cleanup], "Demo report generation and cleanup failed", {
38
+ cause: cleanup
39
+ });
40
+ }
41
+ throw error;
42
+ }
43
+ console.log(
44
+ `Created synthetic demo data at ${root}. No models or cloud services were called.
45
+ Open with: pnpm qa studio --root ${JSON.stringify(root)}`
46
+ );
47
+ }
48
+ export {
49
+ demoCommand
50
+ };
@@ -0,0 +1,15 @@
1
+ import type { HookRegistry } from "./hooks/registry.js";
2
+ import { type LocalCommand } from "./local-command.js";
3
+ export interface DoctorAdapters {
4
+ registry?: HookRegistry;
5
+ command?: LocalCommand;
6
+ fetch?: typeof fetch;
7
+ login?: () => Promise<unknown>;
8
+ leaseLock?: () => Promise<void>;
9
+ output?: (line: string) => void;
10
+ }
11
+ export declare function doctorCommand(options: {
12
+ root?: string;
13
+ target?: string;
14
+ save?: boolean;
15
+ }, adapters?: DoctorAdapters): Promise<number>;