@open-qa/qa 0.1.0-alpha.4 → 0.1.0-alpha.5

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 (109) hide show
  1. package/THIRD_PARTY.md +5 -0
  2. package/drizzle/0017_provider_notifications.sql +13 -0
  3. package/drizzle/0018_classification_registry.sql +39 -0
  4. package/drizzle/0019_trial_audit.sql +44 -0
  5. package/drizzle/meta/0017_snapshot.json +2092 -0
  6. package/drizzle/meta/0018_snapshot.json +2102 -0
  7. package/drizzle/meta/0019_snapshot.json +2451 -0
  8. package/drizzle/meta/_journal.json +21 -0
  9. package/package.json +12 -7
  10. package/src/access-binding.d.ts +8 -0
  11. package/src/access-binding.js +26 -0
  12. package/src/adapters/classification-write.d.ts +87 -0
  13. package/src/adapters/classification-write.js +64 -0
  14. package/src/adapters/e2b-executor.js +4 -0
  15. package/src/adapters/file-run-store.d.ts +186 -41
  16. package/src/adapters/file-run-store.js +87 -19
  17. package/src/adapters/file-trial-audit.d.ts +280 -0
  18. package/src/adapters/file-trial-audit.js +105 -0
  19. package/src/adapters/pg-classification-store.d.ts +98 -20
  20. package/src/adapters/pg-classification-store.js +84 -44
  21. package/src/adapters/pg-run-store.d.ts +1 -0
  22. package/src/adapters/pg-run-store.js +70 -9
  23. package/src/adapters/run-metadata.d.ts +2 -0
  24. package/src/adapters/run-metadata.js +10 -0
  25. package/src/adapters/secret-manager-credential-resolver.d.ts +1 -1
  26. package/src/attempt-audit.d.ts +363 -0
  27. package/src/attempt-audit.js +253 -0
  28. package/src/audit-command.d.ts +13 -0
  29. package/src/audit-command.js +77 -0
  30. package/src/classification-command.d.ts +14 -9
  31. package/src/classification-command.js +119 -26
  32. package/src/classification-model.d.ts +10 -3
  33. package/src/classification-model.js +40 -24
  34. package/src/classification-notifier.d.ts +4 -3
  35. package/src/classification-notifier.js +26 -6
  36. package/src/classify-runs.d.ts +2 -1
  37. package/src/classify-runs.js +39 -3
  38. package/src/cli-program.js +53 -7
  39. package/src/commands.d.ts +1 -0
  40. package/src/commands.js +2 -0
  41. package/src/db/database.d.ts +7 -0
  42. package/src/db/database.js +15 -0
  43. package/src/db/event-chunks.d.ts +38 -29
  44. package/src/db/flow-status.d.ts +7 -3
  45. package/src/db/flow-status.js +240 -16
  46. package/src/db/queries.d.ts +24 -1
  47. package/src/db/queries.js +22 -0
  48. package/src/db/schema.d.ts +333 -4
  49. package/src/db/schema.js +83 -11
  50. package/src/db/trial-audit.d.ts +526 -0
  51. package/src/db/trial-audit.js +84 -0
  52. package/src/draft-api.d.ts +25 -421
  53. package/src/draft-api.js +10 -3
  54. package/src/engine.d.ts +47 -4
  55. package/src/engine.js +97 -8
  56. package/src/execution-snapshot.d.ts +1 -1
  57. package/src/execution-snapshot.js +22 -17
  58. package/src/export-command.d.ts +6 -0
  59. package/src/export-command.js +106 -0
  60. package/src/flow-check.js +1 -1
  61. package/src/flow-loader.d.ts +72 -6
  62. package/src/flow-loader.js +76 -12
  63. package/src/http-stage-client.d.ts +98 -1
  64. package/src/independent-model.js +53 -6
  65. package/src/judge-review-store.d.ts +13 -0
  66. package/src/judge-review-store.js +58 -0
  67. package/src/local-host-executor.d.ts +3 -1
  68. package/src/local-host-executor.js +2 -0
  69. package/src/quarantine-command.d.ts +5 -1
  70. package/src/quarantine-command.js +56 -13
  71. package/src/remote-command.js +2 -0
  72. package/src/report/browser.js +37 -37
  73. package/src/report/ctrf.d.ts +983 -0
  74. package/src/report/ctrf.js +306 -0
  75. package/src/report/generate.d.ts +1 -1
  76. package/src/report/generate.js +29 -6
  77. package/src/report/load.d.ts +738 -42
  78. package/src/report/load.js +78 -6
  79. package/src/result-notifier.js +1 -1
  80. package/src/result-trace.d.ts +62 -0
  81. package/src/result-trace.js +81 -0
  82. package/src/run-command.d.ts +2 -0
  83. package/src/run-command.js +285 -62
  84. package/src/run-setup-error.d.ts +1 -1
  85. package/src/run-setup-error.js +2 -2
  86. package/src/server/app.js +5 -4
  87. package/src/server/index.d.ts +2 -0
  88. package/src/server/index.js +11 -2
  89. package/src/server/repository.d.ts +166 -29
  90. package/src/server/repository.js +14 -2
  91. package/src/studio-review.js +1 -1
  92. package/src/system-config.d.ts +2 -2
  93. package/src/system-config.js +5 -4
  94. package/src/trial-audit.d.ts +630 -0
  95. package/src/trial-audit.js +272 -0
  96. package/src/visual-baseline.d.ts +4 -0
  97. package/src/visual-baseline.js +42 -0
  98. package/src/webhook-notification.d.ts +15 -0
  99. package/src/webhook-notification.js +61 -0
  100. package/src/worker/execution.d.ts +2 -1
  101. package/src/worker/execution.js +122 -3
  102. package/src/worker/index.d.ts +4 -0
  103. package/src/worker/index.js +10 -1
  104. package/src/worker/quarantine-notifications.js +2 -2
  105. package/src/worker/queue.d.ts +6 -2
  106. package/src/worker/queue.js +80 -19
  107. package/src/worker/result-notifications.d.ts +10 -2
  108. package/src/worker/result-notifications.js +120 -23
  109. package/src/worker/store.js +6 -3
@@ -1,22 +1,34 @@
1
- import { readExecutionSnapshot } from "@open-qa/qa-engine/protocol";
2
1
  import { createHash } from "node:crypto";
3
- import { runEventSchema } from "@open-qa/qa-engine/protocol";
2
+ import {
3
+ jsonObjectSchema,
4
+ readExecutionSnapshot,
5
+ readResultTrace,
6
+ runEventSchema,
7
+ runUsageSchema
8
+ } from "@open-qa/qa-engine/protocol";
4
9
  import { viewTimeline } from "@open-qa/qa-replay";
5
10
  import {
6
11
  readHealShot,
12
+ readClassificationHistory,
7
13
  FileRunReader,
8
14
  ReplayReader,
9
15
  hasCode,
10
16
  ArtifactReader
11
17
  } from "@open-qa/qa-inspect/server";
12
18
  import { assetMime, embeddedAssets } from "./assets.js";
19
+ import { loadConfig } from "../flow-loader.js";
20
+ import { projectAttemptAudit } from "../attempt-audit.js";
21
+ import { readJudgeReviews } from "../judge-review-store.js";
22
+ import { FileTrialAudit } from "../adapters/file-trial-audit.js";
23
+ import { summarizeTrial } from "../trial-audit.js";
13
24
  const hash = (bytes) => createHash("sha256").update(bytes).digest("hex");
14
25
  function lines(bytes) {
15
26
  return bytes.toString("utf8").split("\n").filter(Boolean).map((line) => JSON.parse(line));
16
27
  }
17
- async function loadReport(root, runId) {
28
+ async function loadReport(root, runId, projectId) {
18
29
  if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/.test(runId)) throw new Error("Invalid run ID");
19
- const reader = new FileRunReader(root);
30
+ const project = projectId ?? (await loadConfig(root).catch(() => void 0))?.projectId;
31
+ const reader = new FileRunReader(root, project);
20
32
  const artifacts = new ArtifactReader(root);
21
33
  const file = (directory2, path, maxBytes) => artifacts.read(`${directory2}/${path}`, maxBytes);
22
34
  const directory = `runs/${runId}`;
@@ -24,18 +36,53 @@ async function loadReport(root, runId) {
24
36
  let committed = false;
25
37
  let result = null;
26
38
  let executionSnapshot = readExecutionSnapshot(void 0);
39
+ let classificationHistory;
40
+ let attemptAudit = null;
41
+ let trial;
42
+ let quarantined = null;
43
+ let quarantineOverdueSince = null;
27
44
  try {
28
45
  const metadata = JSON.parse(
29
46
  (await file(directory, "run.json", 1024 * 1024)).toString("utf8")
30
47
  );
31
48
  const run = metadata && typeof metadata === "object" && "run" in metadata ? metadata.run : void 0;
32
49
  const values = run && typeof run === "object" && "metadata" in run ? run.metadata : void 0;
50
+ const parsed = jsonObjectSchema.safeParse(values);
51
+ if (parsed.success) {
52
+ const trace = readResultTrace(parsed.data.resultTrace);
53
+ const scope = trace.status === "recorded" ? trace.trace.projectId : project;
54
+ const outcome = metadata && typeof metadata === "object" && "result" in metadata ? metadata.result : null;
55
+ const usage = runUsageSchema.safeParse(
56
+ outcome && typeof outcome === "object" && "usage" in outcome ? outcome.usage : void 0
57
+ );
58
+ attemptAudit = projectAttemptAudit(
59
+ parsed.data,
60
+ usage.data,
61
+ scope ? await readJudgeReviews(root, void 0, scope, runId) : []
62
+ );
63
+ if (typeof parsed.data.flowQuarantined === "boolean")
64
+ quarantined = parsed.data.flowQuarantined;
65
+ if (typeof parsed.data.flowQuarantineOverdueSince === "number")
66
+ quarantineOverdueSince = parsed.data.flowQuarantineOverdueSince;
67
+ if (trace.status === "recorded" && trace.trace.trial) {
68
+ const history = await new FileTrialAudit(root, trace.trace.projectId).get(
69
+ trace.trace.trial.groupId
70
+ );
71
+ if (history) trial = summarizeTrial(history);
72
+ }
73
+ }
33
74
  if (metadata && typeof metadata === "object" && "eventIndex" in metadata) {
34
75
  committed = true;
35
76
  }
36
77
  executionSnapshot = readExecutionSnapshot(
37
78
  values && typeof values === "object" && "executionSnapshot" in values ? values.executionSnapshot : void 0
38
79
  );
80
+ if (!committed && metadata && typeof metadata === "object" && "classification" in metadata)
81
+ classificationHistory = readClassificationHistory(
82
+ metadata.classification,
83
+ "classificationLabels" in metadata ? metadata.classificationLabels : void 0,
84
+ executionSnapshot.status === "recorded" ? executionSnapshot.snapshot.projectId : project
85
+ );
39
86
  } catch (error) {
40
87
  if (!hasCode(error, "ENOENT")) throw new Error("Could not read execution snapshot");
41
88
  }
@@ -43,6 +90,7 @@ async function loadReport(root, runId) {
43
90
  const stored = await reader.readRun(runId);
44
91
  events = stored.projection.events;
45
92
  result = stored.result;
93
+ classificationHistory = stored.classificationHistory;
46
94
  } else {
47
95
  try {
48
96
  events = lines(await file(directory, "events.ndjson")).map(
@@ -76,7 +124,19 @@ async function loadReport(root, runId) {
76
124
  const manifest = await replayReader.manifest();
77
125
  if (!manifest) {
78
126
  replay.warnings.push("No replay was recorded for this run.");
79
- return { events, replay, resources, healShots, executionSnapshot, result };
127
+ return {
128
+ events,
129
+ replay,
130
+ resources,
131
+ healShots,
132
+ executionSnapshot,
133
+ classificationHistory,
134
+ result,
135
+ attemptAudit,
136
+ trial,
137
+ quarantined,
138
+ quarantineOverdueSince
139
+ };
80
140
  }
81
141
  replay.manifest = manifest;
82
142
  replay.warnings.push(...manifest.warnings);
@@ -132,7 +192,19 @@ async function loadReport(root, runId) {
132
192
  replay.warnings.push(`${view.view}: Recording unavailable.`);
133
193
  }
134
194
  }
135
- return { events, replay, resources, healShots, executionSnapshot, result };
195
+ return {
196
+ events,
197
+ replay,
198
+ resources,
199
+ healShots,
200
+ executionSnapshot,
201
+ classificationHistory,
202
+ result,
203
+ attemptAudit,
204
+ trial,
205
+ quarantined,
206
+ quarantineOverdueSince
207
+ };
136
208
  }
137
209
  export {
138
210
  loadReport
@@ -125,7 +125,7 @@ class GitHubCommitStatusNotifier extends ResultAdapter {
125
125
  sha: this.context.commit,
126
126
  context: this.context.checkContext ?? "open-qa/smoke",
127
127
  state: passed ? "success" : failed ? "failure" : "error",
128
- description: counts(summary),
128
+ description: `${counts(summary)}${summary.quarantineOverdue ? `, ${summary.quarantineOverdue} overdue` : ""}`,
129
129
  ...targetUrl && { targetUrl }
130
130
  },
131
131
  signal
@@ -0,0 +1,62 @@
1
+ import type { ExecutionPlan } from "@open-qa/qa-engine";
2
+ import { type ResultTrace } from "@open-qa/qa-engine/protocol";
3
+ export declare function readRunContext(file: string | undefined): Promise<{
4
+ device?: string | undefined;
5
+ ci?: {
6
+ pipeline?: string | undefined;
7
+ task?: string | undefined;
8
+ runId?: string | undefined;
9
+ runUrl?: string | undefined;
10
+ } | undefined;
11
+ build?: {
12
+ id?: string | undefined;
13
+ url?: string | undefined;
14
+ } | undefined;
15
+ correlation?: {
16
+ traceId?: string | undefined;
17
+ spanId?: string | undefined;
18
+ requestId?: string | undefined;
19
+ } | undefined;
20
+ productPr?: {
21
+ url: string;
22
+ base?: string | undefined;
23
+ head?: string | undefined;
24
+ revision?: string | undefined;
25
+ } | undefined;
26
+ qa?: {
27
+ issue?: string | undefined;
28
+ pr?: string | undefined;
29
+ } | undefined;
30
+ defects?: {
31
+ url: string;
32
+ acceptance: string[];
33
+ }[] | undefined;
34
+ } | undefined>;
35
+ export declare function resultCaseId(projectId: string, flow: string): string;
36
+ export declare function resultExecutionId(firstAttemptId: string): string;
37
+ export declare function buildResultTrace(input: {
38
+ projectId: string;
39
+ flow: string;
40
+ attemptId: string;
41
+ plan?: Pick<ExecutionPlan, "acceptance" | "covers" | "traceability">;
42
+ context?: ResultTrace["context"];
43
+ started?: boolean;
44
+ retryOf?: string;
45
+ batchId?: string;
46
+ trial?: ResultTrace["trial"];
47
+ caseRevision?: string | null;
48
+ target?: string;
49
+ targetRevision?: string | null;
50
+ commit?: string | null;
51
+ parameters: Partial<ResultTrace["parameters"]>;
52
+ environment?: {
53
+ origin?: string | null;
54
+ config?: string | null;
55
+ suite?: string | null;
56
+ zone?: string | null;
57
+ cli?: string | null;
58
+ engine?: string | null;
59
+ node?: string | null;
60
+ dirty?: boolean | null;
61
+ };
62
+ }): ResultTrace;
@@ -0,0 +1,81 @@
1
+ import { createHash } from "node:crypto";
2
+ import { readFile } from "node:fs/promises";
3
+ import {
4
+ acceptanceSnapshotSchema,
5
+ resultTraceSchema,
6
+ runContextSchema
7
+ } from "@open-qa/qa-engine/protocol";
8
+ async function readRunContext(file) {
9
+ if (!file) return void 0;
10
+ try {
11
+ return runContextSchema.parse(JSON.parse(await readFile(file, "utf8")));
12
+ } catch {
13
+ throw new Error("Could not read --run-context as valid QA run context JSON");
14
+ }
15
+ }
16
+ function resultCaseId(projectId, flow) {
17
+ return `case:${projectId}:${flow}`;
18
+ }
19
+ function resultExecutionId(firstAttemptId) {
20
+ return `execution:${firstAttemptId}`;
21
+ }
22
+ function fingerprint(domain, values) {
23
+ return createHash("sha256").update(JSON.stringify([domain, 1, ...values])).digest("hex");
24
+ }
25
+ function buildResultTrace(input) {
26
+ const parameters = resultTraceSchema.shape.parameters.parse({
27
+ runtime: input.parameters.runtime ?? null,
28
+ modelAccess: input.parameters.modelAccess ?? null,
29
+ placement: input.parameters.placement ?? null,
30
+ agentAt: input.parameters.agentAt ?? null,
31
+ headed: input.parameters.headed ?? null,
32
+ level: input.parameters.level ?? null,
33
+ device: input.parameters.device ?? input.context?.device ?? null,
34
+ persona: input.parameters.persona ?? null,
35
+ replay: input.parameters.replay ?? null
36
+ });
37
+ const { origin, config, suite, zone, cli, engine, node, dirty } = input.environment ?? {};
38
+ const acceptance = acceptanceSnapshotSchema.safeParse(input.plan?.acceptance);
39
+ return resultTraceSchema.parse({
40
+ schemaVersion: 1,
41
+ projectId: input.projectId,
42
+ caseId: resultCaseId(input.projectId, input.plan?.traceability?.caseId ?? input.flow),
43
+ ...acceptance.success && { acceptance: acceptance.data },
44
+ ...input.plan?.covers && { covers: input.plan.covers },
45
+ ...input.plan?.traceability && { traceability: input.plan.traceability },
46
+ ...input.context && { context: input.context },
47
+ caseRevision: input.caseRevision ?? null,
48
+ executionId: resultExecutionId(input.retryOf ?? input.attemptId),
49
+ attemptId: input.attemptId,
50
+ attempt: input.retryOf ? 2 : 1,
51
+ started: input.started ?? true,
52
+ retryOf: input.retryOf ?? null,
53
+ batchId: input.batchId ?? null,
54
+ trial: input.trial ?? null,
55
+ target: input.target ?? null,
56
+ targetRevision: input.targetRevision ?? null,
57
+ commit: input.commit ?? null,
58
+ parameters,
59
+ parameterFingerprint: fingerprint("parameters", Object.values(parameters)),
60
+ environmentFingerprint: fingerprint("environment", [
61
+ input.target,
62
+ origin,
63
+ input.targetRevision,
64
+ input.commit,
65
+ config,
66
+ suite,
67
+ zone,
68
+ cli,
69
+ engine,
70
+ node,
71
+ dirty,
72
+ parameters.placement
73
+ ])
74
+ });
75
+ }
76
+ export {
77
+ buildResultTrace,
78
+ readRunContext,
79
+ resultCaseId,
80
+ resultExecutionId
81
+ };
@@ -4,6 +4,7 @@ import { type EngineAdapters } from "./engine.js";
4
4
  import { loadConfig, loadFlowDocument } from "./flow-loader.js";
5
5
  export interface RunOptions {
6
6
  acceptEstimate?: boolean;
7
+ runContext?: string;
7
8
  executor?: string;
8
9
  agentAt?: string;
9
10
  root?: string;
@@ -17,6 +18,7 @@ export interface RunOptions {
17
18
  persona?: string;
18
19
  retries?: number;
19
20
  repeat?: number;
21
+ dependentTrials?: boolean;
20
22
  }
21
23
  export interface RunAdapters extends EngineAdapters, BudgetPrompt {
22
24
  studio?: {