@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.
- package/LICENSE +204 -0
- package/NOTICE +7 -0
- package/THIRD_PARTY.md +12 -0
- package/THIRD_PARTY_NOTICES.md +11 -0
- package/drizzle/0000_qa_core.sql +158 -0
- package/drizzle/0001_run_health.sql +3 -0
- package/drizzle/0002_bounded_cleanup.sql +5 -0
- package/drizzle/0003_step_replay_cache.sql +9 -0
- package/drizzle/0004_credential_expiry.sql +1 -0
- package/drizzle/0005_server_api.sql +19 -0
- package/drizzle/0006_submission_created.sql +3 -0
- package/drizzle/0007_findings.sql +19 -0
- package/drizzle/0008_classification_labels.sql +14 -0
- package/drizzle/0009_job_queue.sql +20 -0
- package/drizzle/0010_result_notifications.sql +13 -0
- package/drizzle/0011_result_notification_retries.sql +5 -0
- package/drizzle/0012_result_notification_flows.sql +44 -0
- package/drizzle/0013_flow_quarantine.sql +35 -0
- package/drizzle/0014_run_budgets.sql +2 -0
- package/drizzle/0015_flow_lifecycle.sql +9 -0
- package/drizzle/0016_open_qa_classification.sql +28 -0
- package/drizzle/meta/0000_snapshot.json +1002 -0
- package/drizzle/meta/0001_snapshot.json +1021 -0
- package/drizzle/meta/0002_snapshot.json +1027 -0
- package/drizzle/meta/0003_snapshot.json +1081 -0
- package/drizzle/meta/0004_snapshot.json +1087 -0
- package/drizzle/meta/0005_snapshot.json +1210 -0
- package/drizzle/meta/0006_snapshot.json +1244 -0
- package/drizzle/meta/0007_snapshot.json +1353 -0
- package/drizzle/meta/0008_snapshot.json +1435 -0
- package/drizzle/meta/0009_snapshot.json +1587 -0
- package/drizzle/meta/0010_snapshot.json +1675 -0
- package/drizzle/meta/0011_snapshot.json +1692 -0
- package/drizzle/meta/0012_snapshot.json +1818 -0
- package/drizzle/meta/0013_snapshot.json +2016 -0
- package/drizzle/meta/0014_snapshot.json +2028 -0
- package/drizzle/meta/0015_snapshot.json +2064 -0
- package/drizzle/meta/0016_snapshot.json +2076 -0
- package/drizzle/meta/_journal.json +125 -0
- package/package.json +118 -4
- package/problem-matcher.json +32 -0
- package/src/adapters/db-lease-pool.d.ts +25 -0
- package/src/adapters/db-lease-pool.js +293 -0
- package/src/adapters/dir-artifact-store.d.ts +9 -0
- package/src/adapters/dir-artifact-store.js +64 -0
- package/src/adapters/e2b-agent.d.ts +7 -0
- package/src/adapters/e2b-agent.js +94 -0
- package/src/adapters/e2b-artifacts.d.ts +3 -0
- package/src/adapters/e2b-artifacts.js +66 -0
- package/src/adapters/e2b-bounded.d.ts +1 -0
- package/src/adapters/e2b-bounded.js +19 -0
- package/src/adapters/e2b-client.d.ts +33 -0
- package/src/adapters/e2b-client.js +114 -0
- package/src/adapters/e2b-executor.d.ts +26 -0
- package/src/adapters/e2b-executor.js +194 -0
- package/src/adapters/e2b-lifetime.d.ts +20 -0
- package/src/adapters/e2b-lifetime.js +73 -0
- package/src/adapters/e2b-prune.d.ts +13 -0
- package/src/adapters/e2b-prune.js +42 -0
- package/src/adapters/file-replay-cache.d.ts +14 -0
- package/src/adapters/file-replay-cache.js +120 -0
- package/src/adapters/file-run-store.d.ts +175 -0
- package/src/adapters/file-run-store.js +280 -0
- package/src/adapters/fixed-lease-pool.d.ts +10 -0
- package/src/adapters/fixed-lease-pool.js +237 -0
- package/src/adapters/gcs/artifact-store.d.ts +49 -0
- package/src/adapters/gcs/artifact-store.js +247 -0
- package/src/adapters/gcs/client.d.ts +22 -0
- package/src/adapters/gcs/client.js +106 -0
- package/src/adapters/gcs/download.d.ts +9 -0
- package/src/adapters/gcs/download.js +43 -0
- package/src/adapters/gcs/index.d.ts +8 -0
- package/src/adapters/gcs/index.js +23 -0
- package/src/adapters/gcs/periodic-flush.d.ts +5 -0
- package/src/adapters/gcs/periodic-flush.js +16 -0
- package/src/adapters/gcs/pg-catalog.d.ts +16 -0
- package/src/adapters/gcs/pg-catalog.js +149 -0
- package/src/adapters/gcs/replay-completeness.d.ts +1 -0
- package/src/adapters/gcs/replay-completeness.js +65 -0
- package/src/adapters/gcs/scan-upload.d.ts +10 -0
- package/src/adapters/gcs/scan-upload.js +26 -0
- package/src/adapters/index.d.ts +5 -0
- package/src/adapters/index.js +12 -0
- package/src/adapters/lease-transaction.d.ts +2 -0
- package/src/adapters/lease-transaction.js +61 -0
- package/src/adapters/local-credential-resolver.d.ts +5 -0
- package/src/adapters/local-credential-resolver.js +15 -0
- package/src/adapters/local-env.d.ts +1 -0
- package/src/adapters/local-env.js +37 -0
- package/src/adapters/local-files.d.ts +17 -0
- package/src/adapters/local-files.js +150 -0
- package/src/adapters/pg-classification-store.d.ts +58 -0
- package/src/adapters/pg-classification-store.js +112 -0
- package/src/adapters/pg-replay-cache.d.ts +16 -0
- package/src/adapters/pg-replay-cache.js +111 -0
- package/src/adapters/pg-run-store.d.ts +58 -0
- package/src/adapters/pg-run-store.js +399 -0
- package/src/adapters/resource-pools.d.ts +2 -0
- package/src/adapters/resource-pools.js +28 -0
- package/src/adapters/secret-manager-credential-resolver.d.ts +44 -0
- package/src/adapters/secret-manager-credential-resolver.js +102 -0
- package/src/artifact-scan.d.ts +21 -0
- package/src/artifact-scan.js +139 -0
- package/src/budget-confirmation.d.ts +23 -0
- package/src/budget-confirmation.js +43 -0
- package/src/cache-command.d.ts +7 -0
- package/src/cache-command.js +107 -0
- package/src/classification-command.d.ts +14 -0
- package/src/classification-command.js +72 -0
- package/src/classification-diff.d.ts +10 -0
- package/src/classification-diff.js +47 -0
- package/src/classification-model.d.ts +17 -0
- package/src/classification-model.js +51 -0
- package/src/classification-notifier.d.ts +21 -0
- package/src/classification-notifier.js +34 -0
- package/src/classify-runs.d.ts +31 -0
- package/src/classify-runs.js +138 -0
- package/src/cli-program.d.ts +9 -0
- package/src/cli-program.js +172 -0
- package/src/cli.d.ts +2 -0
- package/src/cli.js +12 -0
- package/src/commands.d.ts +7 -0
- package/src/commands.js +17 -0
- package/src/credential-references.d.ts +24 -0
- package/src/credential-references.js +33 -0
- package/src/db/commands.d.ts +1 -0
- package/src/db/commands.js +34 -0
- package/src/db/credentials.d.ts +16 -0
- package/src/db/credentials.js +73 -0
- package/src/db/database.d.ts +12 -0
- package/src/db/database.js +135 -0
- package/src/db/event-chunks.d.ts +405 -0
- package/src/db/event-chunks.js +74 -0
- package/src/db/fencing.d.ts +8 -0
- package/src/db/fencing.js +16 -0
- package/src/db/flow-status.d.ts +41 -0
- package/src/db/flow-status.js +208 -0
- package/src/db/index.d.ts +12 -0
- package/src/db/index.js +24 -0
- package/src/db/queries.d.ts +73 -0
- package/src/db/queries.js +122 -0
- package/src/db/resources.d.ts +14 -0
- package/src/db/resources.js +61 -0
- package/src/db/schema.d.ts +3532 -0
- package/src/db/schema.js +501 -0
- package/src/demo-command.d.ts +1 -0
- package/src/demo-command.js +50 -0
- package/src/doctor-command.d.ts +15 -0
- package/src/doctor-command.js +275 -0
- package/src/doctor-summary.d.ts +2 -0
- package/src/doctor-summary.js +31 -0
- package/src/draft-api.d.ts +460 -0
- package/src/draft-api.js +333 -0
- package/src/draft-command.d.ts +10 -0
- package/src/draft-command.js +73 -0
- package/src/draft-hooks.d.ts +3 -0
- package/src/draft-hooks.js +33 -0
- package/src/draft-pages.d.ts +11 -0
- package/src/draft-pages.js +82 -0
- package/src/engine.d.ts +105 -0
- package/src/engine.js +323 -0
- package/src/execution-snapshot.d.ts +21 -0
- package/src/execution-snapshot.js +141 -0
- package/src/flow-check.d.ts +9 -0
- package/src/flow-check.js +68 -0
- package/src/flow-lifecycle.d.ts +6 -0
- package/src/flow-lifecycle.js +61 -0
- package/src/flow-lint.d.ts +8 -0
- package/src/flow-lint.js +73 -0
- package/src/flow-loader.d.ts +219 -0
- package/src/flow-loader.js +236 -0
- package/src/flow-source.d.ts +2 -0
- package/src/flow-source.js +6 -0
- package/src/flows-api.d.ts +1 -0
- package/src/flows-api.js +12 -0
- package/src/heal-notification.d.ts +16 -0
- package/src/heal-notification.js +62 -0
- package/src/hooks/api.d.ts +29 -0
- package/src/hooks/api.js +15 -0
- package/src/hooks/consumer.d.ts +18 -0
- package/src/hooks/consumer.js +98 -0
- package/src/hooks/loader.d.ts +6 -0
- package/src/hooks/loader.js +28 -0
- package/src/hooks/registry.d.ts +22 -0
- package/src/hooks/registry.js +23 -0
- package/src/hooks/runner.d.ts +19 -0
- package/src/hooks/runner.js +279 -0
- package/src/hooks/session-cache.d.ts +16 -0
- package/src/hooks/session-cache.js +42 -0
- package/src/hooks/session-store.d.ts +20 -0
- package/src/hooks/session-store.js +95 -0
- package/src/hooks/worker.d.ts +1 -0
- package/src/hooks/worker.js +84 -0
- package/src/http-stage-client.d.ts +367 -0
- package/src/http-stage-client.js +190 -0
- package/src/independent-model.d.ts +22 -0
- package/src/independent-model.js +215 -0
- package/src/lifecycle-command.d.ts +15 -0
- package/src/lifecycle-command.js +190 -0
- package/src/local-command.d.ts +3 -0
- package/src/local-command.js +27 -0
- package/src/local-host-executor.d.ts +38 -0
- package/src/local-host-executor.js +196 -0
- package/src/open-command.d.ts +7 -0
- package/src/open-command.js +39 -0
- package/src/operations-api.d.ts +2 -0
- package/src/operations-api.js +6 -0
- package/src/personas.d.ts +2 -0
- package/src/personas.js +61 -0
- package/src/program-runner.d.ts +3 -0
- package/src/program-runner.js +263 -0
- package/src/program-sandbox.py +75 -0
- package/src/program-scratch.d.ts +2 -0
- package/src/program-scratch.js +48 -0
- package/src/program-worker.mjs +101 -0
- package/src/public-id.d.ts +2 -0
- package/src/public-id.js +5 -0
- package/src/public-report-url.d.ts +1 -0
- package/src/public-report-url.js +18 -0
- package/src/publication-check.d.ts +1 -0
- package/src/publication-check.js +31 -0
- package/src/quarantine-command.d.ts +9 -0
- package/src/quarantine-command.js +69 -0
- package/src/remote-command.d.ts +30 -0
- package/src/remote-command.js +156 -0
- package/src/replay-image.d.ts +1 -0
- package/src/replay-image.js +35 -0
- package/src/report/assets.d.ts +1 -0
- package/src/report/assets.js +5 -0
- package/src/report/browser.css +414 -0
- package/src/report/browser.d.ts +1 -0
- package/src/report/browser.js +219 -0
- package/src/report/data.d.ts +1 -0
- package/src/report/data.js +4 -0
- package/src/report/generate.d.ts +1 -0
- package/src/report/generate.js +54 -0
- package/src/report/load.d.ts +870 -0
- package/src/report/load.js +139 -0
- package/src/report/resource-table.d.ts +2 -0
- package/src/report/resource-table.js +4 -0
- package/src/report/status-icon.d.ts +2 -0
- package/src/report/status-icon.js +20 -0
- package/src/report/style.css +413 -0
- package/src/result-notifier.d.ts +121 -0
- package/src/result-notifier.js +230 -0
- package/src/result-transports.d.ts +12 -0
- package/src/result-transports.js +150 -0
- package/src/run-command.d.ts +32 -0
- package/src/run-command.js +493 -0
- package/src/run-setup-error.d.ts +11 -0
- package/src/run-setup-error.js +18 -0
- package/src/sandboxes-command.d.ts +9 -0
- package/src/sandboxes-command.js +29 -0
- package/src/screen-proxy.d.ts +5 -0
- package/src/screen-proxy.js +79 -0
- package/src/screen-url.d.ts +18 -0
- package/src/screen-url.js +54 -0
- package/src/server/app.d.ts +29 -0
- package/src/server/app.js +350 -0
- package/src/server/auth.d.ts +33 -0
- package/src/server/auth.js +113 -0
- package/src/server/credentials.d.ts +30 -0
- package/src/server/credentials.js +77 -0
- package/src/server/errors.d.ts +9 -0
- package/src/server/errors.js +26 -0
- package/src/server/index.d.ts +35 -0
- package/src/server/index.js +96 -0
- package/src/server/maintenance.d.ts +13 -0
- package/src/server/maintenance.js +54 -0
- package/src/server/repository.d.ts +534 -0
- package/src/server/repository.js +219 -0
- package/src/setup-command.d.ts +10 -0
- package/src/setup-command.js +52 -0
- package/src/stage-environment.d.ts +1 -0
- package/src/stage-environment.js +35 -0
- package/src/stage-supervisor.mjs +95 -0
- package/src/studio-command.d.ts +7 -0
- package/src/studio-command.js +47 -0
- package/src/studio-control.d.ts +5 -0
- package/src/studio-control.js +207 -0
- package/src/studio-review.d.ts +24 -0
- package/src/studio-review.js +64 -0
- package/src/studio-worker.d.ts +1 -0
- package/src/studio-worker.js +48 -0
- package/src/system-config.d.ts +7 -0
- package/src/system-config.js +70 -0
- package/src/terminal-reporter.d.ts +13 -0
- package/src/terminal-reporter.js +93 -0
- package/src/vendor/gmail.d.ts +45 -0
- package/src/vendor/gmail.js +193 -0
- package/src/watch-command.d.ts +16 -0
- package/src/watch-command.js +93 -0
- package/src/watch-state.d.ts +4 -0
- package/src/watch-state.js +53 -0
- package/src/worker/execution-error.d.ts +5 -0
- package/src/worker/execution-error.js +10 -0
- package/src/worker/execution.d.ts +24 -0
- package/src/worker/execution.js +190 -0
- package/src/worker/index.d.ts +8 -0
- package/src/worker/index.js +40 -0
- package/src/worker/prune.d.ts +3 -0
- package/src/worker/prune.js +22 -0
- package/src/worker/quarantine-notifications.d.ts +8 -0
- package/src/worker/quarantine-notifications.js +89 -0
- package/src/worker/queue.d.ts +65 -0
- package/src/worker/queue.js +438 -0
- package/src/worker/result-notifications.d.ts +28 -0
- package/src/worker/result-notifications.js +347 -0
- package/src/worker/store.d.ts +4 -0
- package/src/worker/store.js +46 -0
- package/src/worker/worker.d.ts +21 -0
- package/src/worker/worker.js +140 -0
- package/README.md +0 -3
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { publicReportUrl } from "./public-report-url.js";
|
|
4
|
+
const repository = z.string().regex(/^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$/).max(200).refine((value) => value.split("/").every((part) => part !== "." && part !== ".."));
|
|
5
|
+
const common = {
|
|
6
|
+
checkContext: z.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._/-]{0,99}$/).optional(),
|
|
7
|
+
repository,
|
|
8
|
+
commit: z.string().regex(/^[a-f0-9]{40,64}$/),
|
|
9
|
+
target: z.string().regex(/^[a-zA-Z][a-zA-Z0-9.-]{0,63}$/)
|
|
10
|
+
};
|
|
11
|
+
const resultContextSchema = z.discriminatedUnion("source", [
|
|
12
|
+
z.strictObject({ ...common, source: z.literal("staging"), target: z.literal("staging") }),
|
|
13
|
+
z.strictObject({
|
|
14
|
+
...common,
|
|
15
|
+
source: z.literal("pr-label"),
|
|
16
|
+
pullRequest: z.number().int().positive()
|
|
17
|
+
}),
|
|
18
|
+
z.strictObject({
|
|
19
|
+
...common,
|
|
20
|
+
source: z.literal("new-flow"),
|
|
21
|
+
pullRequest: z.number().int().positive()
|
|
22
|
+
}),
|
|
23
|
+
z.strictObject({ ...common, source: z.literal("nightly") }),
|
|
24
|
+
z.strictObject({ ...common, source: z.literal("remote") })
|
|
25
|
+
]);
|
|
26
|
+
function resultChannels(context) {
|
|
27
|
+
switch (context.source) {
|
|
28
|
+
case "staging":
|
|
29
|
+
return ["commit", "discord"];
|
|
30
|
+
case "pr-label":
|
|
31
|
+
case "new-flow":
|
|
32
|
+
return ["pr"];
|
|
33
|
+
case "nightly":
|
|
34
|
+
return ["discord"];
|
|
35
|
+
case "remote":
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function resultMarker(projectId, source, flow) {
|
|
40
|
+
if (source === "new-flow" && !flow) throw new Error("Missing new-flow identity");
|
|
41
|
+
const suffix = source === "new-flow" ? `:new-flow:${createHash("sha256").update(flow).digest("hex")}` : "";
|
|
42
|
+
return `<!-- open-qa:result:${createHash("sha256").update(projectId).digest("hex")}${suffix} -->`;
|
|
43
|
+
}
|
|
44
|
+
function counts(summary) {
|
|
45
|
+
const budgets = summary.runs.filter((run) => run.errorReason === "budget").length;
|
|
46
|
+
const failed = summary.runs.filter((run) => run.verdict === "failed").length;
|
|
47
|
+
const errors = summary.runs.filter((run) => run.verdict === "error").length;
|
|
48
|
+
const other = summary.runs.filter(
|
|
49
|
+
(run) => run.verdict === "inconclusive" || run.verdict === "canceled"
|
|
50
|
+
).length;
|
|
51
|
+
return `${summary.runs.length}${summary.quarantined ? " blocking" : ""} flow${summary.runs.length === 1 ? "" : "s"}, ${failed} failed, ${errors} error${errors === 1 ? "" : "s"}${other ? `, ${other} inconclusive/canceled` : ""}${budgets ? `, ${budgets} budget exhausted` : ""}${summary.quarantined ? `; ${summary.quarantined} quarantined` : ""}`;
|
|
52
|
+
}
|
|
53
|
+
function render(summary, context, options, limit) {
|
|
54
|
+
const label = context.source === "nightly" ? "Nightly" : context.source === "new-flow" ? "New flow" : "Smoke";
|
|
55
|
+
let body = `${label} \xB7 ${context.target} \xB7 ${context.commit.slice(0, 7)} \xB7 ${counts(summary)}`;
|
|
56
|
+
if (context.source === "new-flow")
|
|
57
|
+
body += "\nPlease confirm the first run using the report and replay.";
|
|
58
|
+
const sorted = [...summary.runs].sort(
|
|
59
|
+
(a, b) => Number(a.verdict === "passed") - Number(b.verdict === "passed")
|
|
60
|
+
);
|
|
61
|
+
for (const [index, run] of sorted.entries()) {
|
|
62
|
+
const detail = options.details?.[run.runId];
|
|
63
|
+
const flow = detail?.flow && /^[a-z][a-z0-9.-]{0,79}$/i.test(detail.flow) ? detail.flow : "flow";
|
|
64
|
+
let line = `
|
|
65
|
+
- ${flow}: ${run.verdict}${run.errorReason === "budget" ? " (budget exhausted)" : ""}`;
|
|
66
|
+
if (run.verdict !== "passed" || context.source === "new-flow") {
|
|
67
|
+
for (const [label2, candidate] of [
|
|
68
|
+
["Report", run.reportUrl],
|
|
69
|
+
["Replay", detail?.replayUrl]
|
|
70
|
+
]) {
|
|
71
|
+
const url = publicReportUrl(candidate, options.publicOrigins ?? []);
|
|
72
|
+
if (url && url.length <= 500) line += `
|
|
73
|
+
${label2}: ${url}`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (body.length + line.length > limit - 60) {
|
|
77
|
+
const omitted = sorted.length - index;
|
|
78
|
+
body += `
|
|
79
|
+
${omitted} more flow${omitted === 1 ? "" : "s"} omitted.`;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
body += line;
|
|
83
|
+
}
|
|
84
|
+
return body;
|
|
85
|
+
}
|
|
86
|
+
class ResultAdapter {
|
|
87
|
+
async notify(summary) {
|
|
88
|
+
const controller = new AbortController();
|
|
89
|
+
let timer;
|
|
90
|
+
try {
|
|
91
|
+
await Promise.race([
|
|
92
|
+
this.deliver(summary, controller.signal),
|
|
93
|
+
new Promise((_, reject) => {
|
|
94
|
+
timer = setTimeout(() => {
|
|
95
|
+
controller.abort();
|
|
96
|
+
reject(new Error("QA result delivery failed"));
|
|
97
|
+
}, 5e3);
|
|
98
|
+
})
|
|
99
|
+
]);
|
|
100
|
+
} catch {
|
|
101
|
+
throw new Error("QA result delivery failed");
|
|
102
|
+
} finally {
|
|
103
|
+
clearTimeout(timer);
|
|
104
|
+
controller.abort();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
class GitHubCommitStatusNotifier extends ResultAdapter {
|
|
109
|
+
constructor(context, transport, options = {}) {
|
|
110
|
+
super();
|
|
111
|
+
this.context = context;
|
|
112
|
+
this.transport = transport;
|
|
113
|
+
this.options = options;
|
|
114
|
+
}
|
|
115
|
+
context;
|
|
116
|
+
transport;
|
|
117
|
+
options;
|
|
118
|
+
async deliver(summary, signal) {
|
|
119
|
+
const failed = summary.runs.some((run) => run.verdict === "failed");
|
|
120
|
+
const passed = summary.runs.every((run) => run.verdict === "passed");
|
|
121
|
+
const targetUrl = summary.runs.filter((run) => run.verdict !== "passed").map((run) => publicReportUrl(run.reportUrl, this.options.publicOrigins ?? [])).find(Boolean);
|
|
122
|
+
await this.transport.status(
|
|
123
|
+
{
|
|
124
|
+
repository: this.context.repository,
|
|
125
|
+
sha: this.context.commit,
|
|
126
|
+
context: this.context.checkContext ?? "open-qa/smoke",
|
|
127
|
+
state: passed ? "success" : failed ? "failure" : "error",
|
|
128
|
+
description: counts(summary),
|
|
129
|
+
...targetUrl && { targetUrl }
|
|
130
|
+
},
|
|
131
|
+
signal
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
class GitHubPrCommentNotifier extends ResultAdapter {
|
|
136
|
+
constructor(projectId, context, transport, options = {}) {
|
|
137
|
+
super();
|
|
138
|
+
this.projectId = projectId;
|
|
139
|
+
this.context = context;
|
|
140
|
+
this.transport = transport;
|
|
141
|
+
this.options = options;
|
|
142
|
+
}
|
|
143
|
+
projectId;
|
|
144
|
+
context;
|
|
145
|
+
transport;
|
|
146
|
+
options;
|
|
147
|
+
async notify(summary) {
|
|
148
|
+
if (this.context.source !== "new-flow") return super.notify(summary);
|
|
149
|
+
const groups = /* @__PURE__ */ new Map();
|
|
150
|
+
for (const run of summary.runs) {
|
|
151
|
+
const flow = this.options.details?.[run.runId]?.flow;
|
|
152
|
+
if (!flow) throw new Error("QA result delivery failed");
|
|
153
|
+
groups.set(flow, [...groups.get(flow) ?? [], run]);
|
|
154
|
+
}
|
|
155
|
+
for (const runs of groups.values()) await super.notify({ ...summary, runs });
|
|
156
|
+
}
|
|
157
|
+
async deliver(summary, signal) {
|
|
158
|
+
const flow = this.context.source === "new-flow" ? this.options.details?.[summary.runs[0].runId]?.flow : void 0;
|
|
159
|
+
await this.upsert(summary, signal, flow);
|
|
160
|
+
}
|
|
161
|
+
async upsert(summary, signal, flow) {
|
|
162
|
+
const pr = { repository: this.context.repository, pullRequest: this.context.pullRequest };
|
|
163
|
+
const marker = resultMarker(this.projectId, this.context.source, flow);
|
|
164
|
+
const body = `${marker}
|
|
165
|
+
${render(summary, this.context, this.options, 6e4)}`;
|
|
166
|
+
let page = 1;
|
|
167
|
+
for (let visited = 0; page !== void 0 && visited < 100; visited++) {
|
|
168
|
+
signal.throwIfAborted();
|
|
169
|
+
const result = await this.transport.comments({ ...pr, page }, signal);
|
|
170
|
+
const existing = result.comments.find(
|
|
171
|
+
(comment) => comment.appId === this.transport.appId && comment.body.startsWith(`${marker}
|
|
172
|
+
`)
|
|
173
|
+
);
|
|
174
|
+
signal.throwIfAborted();
|
|
175
|
+
if (existing) {
|
|
176
|
+
await this.transport.updateComment({ ...pr, id: existing.id, body }, signal);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (result.nextPage !== void 0 && (!Number.isSafeInteger(result.nextPage) || result.nextPage <= page))
|
|
180
|
+
throw new Error("Invalid comment pagination");
|
|
181
|
+
page = result.nextPage;
|
|
182
|
+
}
|
|
183
|
+
if (page !== void 0) throw new Error("Comment search limit exceeded");
|
|
184
|
+
signal.throwIfAborted();
|
|
185
|
+
await this.transport.createComment({ ...pr, body }, signal);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
class DiscordResultNotifier extends ResultAdapter {
|
|
189
|
+
constructor(context, transport, options = {}) {
|
|
190
|
+
super();
|
|
191
|
+
this.context = context;
|
|
192
|
+
this.transport = transport;
|
|
193
|
+
this.options = options;
|
|
194
|
+
}
|
|
195
|
+
context;
|
|
196
|
+
transport;
|
|
197
|
+
options;
|
|
198
|
+
async deliver(summary, signal) {
|
|
199
|
+
await this.transport.send(
|
|
200
|
+
{
|
|
201
|
+
content: render(summary, this.context, this.options, 2e3),
|
|
202
|
+
allowedMentions: { parse: [] }
|
|
203
|
+
},
|
|
204
|
+
signal
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function resultNotifiers(projectId, context, transports, options = {}) {
|
|
209
|
+
const parsed = resultContextSchema.safeParse(context);
|
|
210
|
+
if (!parsed.success) throw new Error("Invalid QA result context");
|
|
211
|
+
context = parsed.data;
|
|
212
|
+
if (context.source === "remote") return {};
|
|
213
|
+
if (context.source === "pr-label" || context.source === "new-flow")
|
|
214
|
+
return { pr: new GitHubPrCommentNotifier(projectId, context, transports.github, options) };
|
|
215
|
+
return {
|
|
216
|
+
...context.source === "staging" && {
|
|
217
|
+
commit: new GitHubCommitStatusNotifier(context, transports.github, options)
|
|
218
|
+
},
|
|
219
|
+
discord: new DiscordResultNotifier(context, transports.discord, options)
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
export {
|
|
223
|
+
DiscordResultNotifier,
|
|
224
|
+
GitHubCommitStatusNotifier,
|
|
225
|
+
GitHubPrCommentNotifier,
|
|
226
|
+
resultChannels,
|
|
227
|
+
resultContextSchema,
|
|
228
|
+
resultMarker,
|
|
229
|
+
resultNotifiers
|
|
230
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ResultTransports } from "./result-notifier.js";
|
|
2
|
+
export type ResultHttp = (url: URL, init: RequestInit) => Promise<Response>;
|
|
3
|
+
export declare function createGitHubResultTransport(options: {
|
|
4
|
+
appId: number;
|
|
5
|
+
repositories: readonly string[];
|
|
6
|
+
installationToken: (signal: AbortSignal) => Promise<string>;
|
|
7
|
+
http: ResultHttp;
|
|
8
|
+
}): ResultTransports["github"];
|
|
9
|
+
export declare function createDiscordResultTransport(options: {
|
|
10
|
+
webhook: string;
|
|
11
|
+
http: ResultHttp;
|
|
12
|
+
}): ResultTransports["discord"];
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const repoSchema = z.string().regex(/^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$/).max(200).refine((value) => value.split("/").every((part) => part !== "." && part !== ".."));
|
|
3
|
+
const commentsSchema = z.array(
|
|
4
|
+
z.object({
|
|
5
|
+
id: z.number().int().positive(),
|
|
6
|
+
body: z.string().max(65536),
|
|
7
|
+
performed_via_github_app: z.object({ id: z.number().int().positive() }).nullable().optional()
|
|
8
|
+
})
|
|
9
|
+
).max(100);
|
|
10
|
+
async function readJson(response) {
|
|
11
|
+
if (!response.body) throw new Error("Missing response body");
|
|
12
|
+
const reader = response.body.getReader();
|
|
13
|
+
const chunks = [];
|
|
14
|
+
let size = 0;
|
|
15
|
+
try {
|
|
16
|
+
for (; ; ) {
|
|
17
|
+
const { value, done } = await reader.read();
|
|
18
|
+
if (done) break;
|
|
19
|
+
size += value.length;
|
|
20
|
+
if (size > 2 * 1024 * 1024) throw new Error("Response size limit exceeded");
|
|
21
|
+
chunks.push(value);
|
|
22
|
+
}
|
|
23
|
+
return JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
24
|
+
} finally {
|
|
25
|
+
await reader.cancel().catch(() => {
|
|
26
|
+
});
|
|
27
|
+
reader.releaseLock();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function createGitHubResultTransport(options) {
|
|
31
|
+
if (!z.number().int().positive().safeParse(options.appId).success || !z.array(repoSchema).min(1).safeParse(options.repositories).success)
|
|
32
|
+
throw new Error("Invalid QA GitHub transport configuration");
|
|
33
|
+
async function request(repository, path, signal, body) {
|
|
34
|
+
if (!options.repositories.includes(repository)) throw new Error("Unknown QA repository");
|
|
35
|
+
const token = await options.installationToken(signal);
|
|
36
|
+
if (!/^[\x21-\x7e]{1,4096}$/.test(token)) throw new Error("Invalid QA App token");
|
|
37
|
+
signal.throwIfAborted();
|
|
38
|
+
const response = await options.http(
|
|
39
|
+
new URL(`https://api.github.com/repos/${repository}/${path}`),
|
|
40
|
+
{
|
|
41
|
+
method: body === void 0 ? "GET" : path.startsWith("issues/comments/") ? "PATCH" : "POST",
|
|
42
|
+
redirect: "error",
|
|
43
|
+
signal,
|
|
44
|
+
headers: {
|
|
45
|
+
authorization: `Bearer ${token}`,
|
|
46
|
+
accept: "application/vnd.github+json",
|
|
47
|
+
"content-type": "application/json",
|
|
48
|
+
"user-agent": "open-qa"
|
|
49
|
+
},
|
|
50
|
+
...body !== void 0 && { body: JSON.stringify(body) }
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
if (!response.ok) {
|
|
54
|
+
await response.body?.cancel();
|
|
55
|
+
throw new Error("QA GitHub request failed");
|
|
56
|
+
}
|
|
57
|
+
return response;
|
|
58
|
+
}
|
|
59
|
+
async function write(repository, path, body, signal) {
|
|
60
|
+
const response = await request(repository, path, signal, body);
|
|
61
|
+
await response.body?.cancel();
|
|
62
|
+
}
|
|
63
|
+
async function safe(action) {
|
|
64
|
+
try {
|
|
65
|
+
return await action();
|
|
66
|
+
} catch {
|
|
67
|
+
throw new Error("QA result delivery failed");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
appId: options.appId,
|
|
72
|
+
status: (input, signal) => safe(async () => {
|
|
73
|
+
if (!/^[a-f0-9]{40,64}$/.test(input.sha)) throw new Error("Invalid QA commit");
|
|
74
|
+
await write(
|
|
75
|
+
input.repository,
|
|
76
|
+
`statuses/${input.sha}`,
|
|
77
|
+
{
|
|
78
|
+
state: input.state,
|
|
79
|
+
context: input.context,
|
|
80
|
+
description: input.description,
|
|
81
|
+
...input.targetUrl && { target_url: input.targetUrl }
|
|
82
|
+
},
|
|
83
|
+
signal
|
|
84
|
+
);
|
|
85
|
+
}),
|
|
86
|
+
comments: (input, signal) => safe(async () => {
|
|
87
|
+
z.number().int().positive().parse(input.pullRequest);
|
|
88
|
+
z.number().int().min(1).max(100).parse(input.page);
|
|
89
|
+
const response = await request(
|
|
90
|
+
input.repository,
|
|
91
|
+
`issues/${input.pullRequest}/comments?per_page=100&page=${input.page}`,
|
|
92
|
+
signal
|
|
93
|
+
);
|
|
94
|
+
const comments = commentsSchema.parse(await readJson(response));
|
|
95
|
+
return {
|
|
96
|
+
comments: comments.map((comment) => ({
|
|
97
|
+
id: comment.id,
|
|
98
|
+
body: comment.body,
|
|
99
|
+
appId: comment.performed_via_github_app?.id ?? null
|
|
100
|
+
})),
|
|
101
|
+
...comments.length === 100 && { nextPage: input.page + 1 }
|
|
102
|
+
};
|
|
103
|
+
}),
|
|
104
|
+
createComment: (input, signal) => safe(async () => {
|
|
105
|
+
z.number().int().positive().parse(input.pullRequest);
|
|
106
|
+
await write(
|
|
107
|
+
input.repository,
|
|
108
|
+
`issues/${input.pullRequest}/comments`,
|
|
109
|
+
{ body: input.body },
|
|
110
|
+
signal
|
|
111
|
+
);
|
|
112
|
+
}),
|
|
113
|
+
updateComment: (input, signal) => safe(async () => {
|
|
114
|
+
z.number().int().positive().parse(input.id);
|
|
115
|
+
await write(input.repository, `issues/comments/${input.id}`, { body: input.body }, signal);
|
|
116
|
+
})
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function createDiscordResultTransport(options) {
|
|
120
|
+
let webhook;
|
|
121
|
+
try {
|
|
122
|
+
webhook = new URL(options.webhook);
|
|
123
|
+
if (webhook.origin !== "https://discord.com" || webhook.username || webhook.password || webhook.search || webhook.hash || !/^\/api\/webhooks\/\d{5,30}\/[a-zA-Z0-9_-]{1,200}$/.test(webhook.pathname))
|
|
124
|
+
throw new Error("Invalid webhook");
|
|
125
|
+
} catch {
|
|
126
|
+
throw new Error("Invalid QA Discord transport configuration");
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
async send(input, signal) {
|
|
130
|
+
try {
|
|
131
|
+
signal.throwIfAborted();
|
|
132
|
+
const response = await options.http(webhook, {
|
|
133
|
+
method: "POST",
|
|
134
|
+
redirect: "error",
|
|
135
|
+
signal,
|
|
136
|
+
headers: { "content-type": "application/json" },
|
|
137
|
+
body: JSON.stringify({ content: input.content, allowed_mentions: { parse: [] } })
|
|
138
|
+
});
|
|
139
|
+
await response.body?.cancel();
|
|
140
|
+
if (!response.ok) throw new Error("QA Discord request failed");
|
|
141
|
+
} catch {
|
|
142
|
+
throw new Error("QA result delivery failed");
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
export {
|
|
148
|
+
createDiscordResultTransport,
|
|
149
|
+
createGitHubResultTransport
|
|
150
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type BudgetPrompt } from "./budget-confirmation.js";
|
|
2
|
+
import { type FlowLifecycleStore } from "@open-qa/qa-engine";
|
|
3
|
+
import { type EngineAdapters } from "./engine.js";
|
|
4
|
+
import { loadConfig, loadFlowDocument } from "./flow-loader.js";
|
|
5
|
+
export interface RunOptions {
|
|
6
|
+
acceptEstimate?: boolean;
|
|
7
|
+
executor?: string;
|
|
8
|
+
agentAt?: string;
|
|
9
|
+
root?: string;
|
|
10
|
+
target?: string;
|
|
11
|
+
runtime?: string;
|
|
12
|
+
modelAccess?: string;
|
|
13
|
+
headed?: boolean;
|
|
14
|
+
level?: string;
|
|
15
|
+
replay?: string;
|
|
16
|
+
tag?: string;
|
|
17
|
+
persona?: string;
|
|
18
|
+
retries?: number;
|
|
19
|
+
repeat?: number;
|
|
20
|
+
}
|
|
21
|
+
export interface RunAdapters extends EngineAdapters, BudgetPrompt {
|
|
22
|
+
studio?: {
|
|
23
|
+
runId: string;
|
|
24
|
+
verify: (config: Awaited<ReturnType<typeof loadConfig>>, doc: Awaited<ReturnType<typeof loadFlowDocument>>) => void;
|
|
25
|
+
created: () => void;
|
|
26
|
+
saved: () => void;
|
|
27
|
+
};
|
|
28
|
+
lifecycle?: FlowLifecycleStore;
|
|
29
|
+
output?: (line: string) => void;
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
}
|
|
32
|
+
export declare function runCommand(path: string, options: RunOptions, adapters?: RunAdapters): Promise<number>;
|