@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,4 @@
|
|
|
1
|
+
import { type ScreenAccess } from "./screen-url.js";
|
|
2
|
+
export declare function writeWatchState(root: string, id: string, access: ScreenAccess): Promise<void>;
|
|
3
|
+
export declare function readWatchState(root: string, id: string): Promise<ScreenAccess | undefined>;
|
|
4
|
+
export declare function removeWatchState(root: string, id: string): Promise<void>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { screenAccessSchema } from "./screen-url.js";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { unlink } from "node:fs/promises";
|
|
4
|
+
import {
|
|
5
|
+
atomicWrite,
|
|
6
|
+
ensureDirectory,
|
|
7
|
+
assertDirectory,
|
|
8
|
+
runDirectory,
|
|
9
|
+
noFollowRead,
|
|
10
|
+
assertRegularFile,
|
|
11
|
+
hasCode
|
|
12
|
+
} from "./adapters/local-files.js";
|
|
13
|
+
import { readFile } from "node:fs/promises";
|
|
14
|
+
function path(root, id) {
|
|
15
|
+
runDirectory(root, id);
|
|
16
|
+
return join(root, ".watch", `${id}.json`);
|
|
17
|
+
}
|
|
18
|
+
async function writeWatchState(root, id, access) {
|
|
19
|
+
screenAccessSchema.parse(access);
|
|
20
|
+
await assertDirectory(root);
|
|
21
|
+
await ensureDirectory(join(root, ".watch"));
|
|
22
|
+
await atomicWrite(path(root, id), JSON.stringify(access));
|
|
23
|
+
}
|
|
24
|
+
async function readWatchState(root, id) {
|
|
25
|
+
const file = path(root, id);
|
|
26
|
+
try {
|
|
27
|
+
await assertDirectory(root);
|
|
28
|
+
await assertDirectory(join(root, ".watch"));
|
|
29
|
+
await assertRegularFile(file);
|
|
30
|
+
const value = JSON.parse(
|
|
31
|
+
await readFile(file, { encoding: "utf8", flag: noFollowRead })
|
|
32
|
+
);
|
|
33
|
+
const result = screenAccessSchema.safeParse(value);
|
|
34
|
+
return result.success ? result.data : void 0;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (hasCode(error, "ENOENT")) return;
|
|
37
|
+
throw new Error("Cannot read private screen access");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async function removeWatchState(root, id) {
|
|
41
|
+
try {
|
|
42
|
+
await assertDirectory(root);
|
|
43
|
+
await assertDirectory(join(root, ".watch"));
|
|
44
|
+
await unlink(path(root, id));
|
|
45
|
+
} catch (error) {
|
|
46
|
+
if (!hasCode(error, "ENOENT")) throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
readWatchState,
|
|
51
|
+
removeWatchState,
|
|
52
|
+
writeWatchState
|
|
53
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SecretRedactor, type CredentialResolver, type ExecutionPlan, type Executor } from "@open-qa/qa-engine";
|
|
2
|
+
import { type EngineOptions } from "../engine.js";
|
|
3
|
+
import type { CloudRunIdentity } from "../adapters/secret-manager-credential-resolver.js";
|
|
4
|
+
import { type ResourceResolver } from "../adapters/db-lease-pool.js";
|
|
5
|
+
import type { EventObjects } from "../db/event-chunks.js";
|
|
6
|
+
import type { ArtifactCatalog } from "../adapters/gcs/artifact-store.js";
|
|
7
|
+
import { type JobClaim, type JobOutcome, type PgJobQueue } from "./queue.js";
|
|
8
|
+
export interface WorkerExecution {
|
|
9
|
+
queue: PgJobQueue;
|
|
10
|
+
objects: EventObjects;
|
|
11
|
+
resolveResource: ResourceResolver;
|
|
12
|
+
credentials: (identity: CloudRunIdentity & {
|
|
13
|
+
projectId: string;
|
|
14
|
+
}, redactor: SecretRedactor) => CredentialResolver;
|
|
15
|
+
prepare: (job: JobClaim, signal: AbortSignal) => Promise<{
|
|
16
|
+
plan: ExecutionPlan;
|
|
17
|
+
options: Omit<EngineOptions, "runId" | "runStore" | "leases" | "credentials" | "retries" | "redactor" | "principalId" | "onCleanup"> & {
|
|
18
|
+
executor: Executor;
|
|
19
|
+
};
|
|
20
|
+
verifyRevision: () => Promise<string | null>;
|
|
21
|
+
}>;
|
|
22
|
+
publish: (job: JobClaim, root: string, redactor: SecretRedactor, catalog: ArtifactCatalog) => Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export declare function createJobExecution(deps: WorkerExecution): (job: JobClaim, signal: AbortSignal) => Promise<JobOutcome>;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SecretRedactor
|
|
3
|
+
} from "@open-qa/qa-engine";
|
|
4
|
+
import { createEngine } from "../engine.js";
|
|
5
|
+
import { DbLeasePool } from "../adapters/db-lease-pool.js";
|
|
6
|
+
import { PgArtifactCatalog } from "../adapters/gcs/pg-catalog.js";
|
|
7
|
+
import { JobExecutionError } from "./execution-error.js";
|
|
8
|
+
import { PgClassificationStore } from "../adapters/pg-classification-store.js";
|
|
9
|
+
import { jobRunStore } from "./store.js";
|
|
10
|
+
import { lockJob } from "./queue.js";
|
|
11
|
+
function createJobExecution(deps) {
|
|
12
|
+
return async (job, signal) => {
|
|
13
|
+
const releases = /* @__PURE__ */ new Map();
|
|
14
|
+
const acquired = /* @__PURE__ */ new Set();
|
|
15
|
+
let pendingAcquisitions = 0;
|
|
16
|
+
const stages = /* @__PURE__ */ new Set();
|
|
17
|
+
let uncertainProvision = false;
|
|
18
|
+
let leases;
|
|
19
|
+
let engineStarted = false;
|
|
20
|
+
let engineCleanupConfirmed = false;
|
|
21
|
+
async function releaseConfirmed() {
|
|
22
|
+
if (uncertainProvision || stages.size || pendingAcquisitions || releases.size !== acquired.size || engineStarted && !engineCleanupConfirmed)
|
|
23
|
+
return false;
|
|
24
|
+
for (const lease of releases.values()) await leases.release(lease);
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
signal.throwIfAborted();
|
|
29
|
+
const prepared = await deps.prepare(job, signal);
|
|
30
|
+
if (prepared.plan.key !== job.flow)
|
|
31
|
+
throw new Error("Worker flow does not match the submitted flow");
|
|
32
|
+
const revision = await prepared.verifyRevision();
|
|
33
|
+
if (!revision || job.commit && job.commit !== revision)
|
|
34
|
+
throw new Error("Worker target revision is unavailable or changed");
|
|
35
|
+
await deps.queue.recordRevision(job, revision);
|
|
36
|
+
const notifier = prepared.options.notifier;
|
|
37
|
+
if (notifier)
|
|
38
|
+
deps.queue.deferClassificationNotification(job, async (runIds) => {
|
|
39
|
+
const classifications = new PgClassificationStore(deps.queue.db, job.projectId);
|
|
40
|
+
for (const runId of runIds) {
|
|
41
|
+
const classification = (await classifications.getClassification(runId))?.classification;
|
|
42
|
+
if (!classification) continue;
|
|
43
|
+
const result2 = await deps.queue.db.pool.query("SELECT verdict,error_reason FROM qa.runs WHERE project_id=$1 AND id=$2", [
|
|
44
|
+
job.projectId,
|
|
45
|
+
runId
|
|
46
|
+
]);
|
|
47
|
+
try {
|
|
48
|
+
await notifier.notify({
|
|
49
|
+
batchId: job.batchId,
|
|
50
|
+
runs: [
|
|
51
|
+
{
|
|
52
|
+
runId,
|
|
53
|
+
verdict: result2.rows[0].verdict,
|
|
54
|
+
classification,
|
|
55
|
+
...result2.rows[0].error_reason === "budget" && {
|
|
56
|
+
errorReason: "budget"
|
|
57
|
+
},
|
|
58
|
+
...prepared.options.classificationOwners
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
});
|
|
62
|
+
} catch {
|
|
63
|
+
try {
|
|
64
|
+
console.warn("QA classification notification failed");
|
|
65
|
+
} catch {
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
const redactor = new SecretRedactor();
|
|
71
|
+
const credentials = deps.credentials(
|
|
72
|
+
{
|
|
73
|
+
projectId: job.projectId,
|
|
74
|
+
trigger: job.trigger,
|
|
75
|
+
createdBy: job.createdBy,
|
|
76
|
+
requestedBy: job.trigger === "developer" ? job.createdBy : void 0,
|
|
77
|
+
modelAccess: job.request.modelAccess
|
|
78
|
+
},
|
|
79
|
+
redactor
|
|
80
|
+
);
|
|
81
|
+
const guard = (client) => lockJob(client, job);
|
|
82
|
+
leases = new DbLeasePool(
|
|
83
|
+
deps.queue.db,
|
|
84
|
+
job.projectId,
|
|
85
|
+
job.owner,
|
|
86
|
+
deps.resolveResource,
|
|
87
|
+
guard
|
|
88
|
+
);
|
|
89
|
+
const executor = {
|
|
90
|
+
async provision(spec, lifetime) {
|
|
91
|
+
signal.throwIfAborted();
|
|
92
|
+
await deps.queue.db.transaction(guard);
|
|
93
|
+
uncertainProvision = true;
|
|
94
|
+
const handle = await prepared.options.executor.provision(spec, lifetime);
|
|
95
|
+
stages.add(handle);
|
|
96
|
+
uncertainProvision = false;
|
|
97
|
+
const dispose = handle.asyncDispose.bind(handle);
|
|
98
|
+
handle.asyncDispose = async () => {
|
|
99
|
+
await dispose();
|
|
100
|
+
stages.delete(handle);
|
|
101
|
+
};
|
|
102
|
+
return handle;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const store = jobRunStore(deps.queue, job, deps.objects);
|
|
106
|
+
const engine = createEngine({
|
|
107
|
+
...prepared.options,
|
|
108
|
+
allowConsumerHooks: prepared.options.allowConsumerHooks ?? false,
|
|
109
|
+
billing: job.trigger === "developer" && job.request.modelAccess === "personal" && job.request.runtime === "claude-code" ? "subscription" : "metered",
|
|
110
|
+
runId: job.runId,
|
|
111
|
+
batchId: job.batchId,
|
|
112
|
+
principalId: job.createdBy,
|
|
113
|
+
executor,
|
|
114
|
+
redactor,
|
|
115
|
+
credentials,
|
|
116
|
+
retries: 0,
|
|
117
|
+
// Queue-managed retry completion owns quarantine transitions and notifications.
|
|
118
|
+
flowStatus: void 0,
|
|
119
|
+
notifier: void 0,
|
|
120
|
+
classifications: new PgClassificationStore(deps.queue.db, job.projectId, guard),
|
|
121
|
+
targetRevision: prepared.verifyRevision,
|
|
122
|
+
runStore: {
|
|
123
|
+
...store,
|
|
124
|
+
createRun: (input) => store.createRun({
|
|
125
|
+
...input,
|
|
126
|
+
metadata: {
|
|
127
|
+
...input.metadata,
|
|
128
|
+
...prepared.options.classificationOwners ? { flowOwner: prepared.options.classificationOwners.flowOwner } : {}
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
},
|
|
132
|
+
onCleanup: (runId, confirmed) => {
|
|
133
|
+
engineCleanupConfirmed = runId === job.runId && confirmed;
|
|
134
|
+
},
|
|
135
|
+
leases: {
|
|
136
|
+
acquire: async (spec, leaseSignal) => {
|
|
137
|
+
pendingAcquisitions++;
|
|
138
|
+
try {
|
|
139
|
+
const lease = await leases.acquire(
|
|
140
|
+
{ ...spec, ttlMs: ((prepared.plan.budget?.minutes ?? 15) + 60) * 6e4 },
|
|
141
|
+
leaseSignal
|
|
142
|
+
);
|
|
143
|
+
acquired.add(lease.id);
|
|
144
|
+
return lease;
|
|
145
|
+
} finally {
|
|
146
|
+
pendingAcquisitions--;
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
// The conductor may request release before stage disposal. Hold accounts until disposal is confirmed.
|
|
150
|
+
release: async (lease) => {
|
|
151
|
+
releases.set(lease.id, lease);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
engineStarted = true;
|
|
156
|
+
const result = await engine.run(prepared.plan, signal);
|
|
157
|
+
const cleanupConfirmed = await releaseConfirmed();
|
|
158
|
+
await deps.publish(
|
|
159
|
+
job,
|
|
160
|
+
prepared.options.root,
|
|
161
|
+
redactor,
|
|
162
|
+
new PgArtifactCatalog(deps.queue.db, job.projectId, job)
|
|
163
|
+
);
|
|
164
|
+
const after = await prepared.verifyRevision();
|
|
165
|
+
return {
|
|
166
|
+
verdict: result.verdict,
|
|
167
|
+
cleanupConfirmed,
|
|
168
|
+
verifiedRevision: after === revision ? revision : null,
|
|
169
|
+
infrastructureFailure: !!result.runs[0]?.infrastructureFailure
|
|
170
|
+
};
|
|
171
|
+
} catch (cause) {
|
|
172
|
+
let cleanupConfirmed = false;
|
|
173
|
+
try {
|
|
174
|
+
cleanupConfirmed = await releaseConfirmed();
|
|
175
|
+
} catch {
|
|
176
|
+
}
|
|
177
|
+
throw new JobExecutionError(
|
|
178
|
+
{
|
|
179
|
+
verdict: signal.aborted ? "canceled" : "error",
|
|
180
|
+
cleanupConfirmed,
|
|
181
|
+
infrastructureFailure: true
|
|
182
|
+
},
|
|
183
|
+
cause
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
export {
|
|
189
|
+
createJobExecution
|
|
190
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { PgJobQueue, JOB_LEASE_MS, type JobClaim, type JobToken, type JobOutcome } from "./queue.js";
|
|
2
|
+
export { startQaWorker, installWorkerSignals, type WorkerOptions } from "./worker.js";
|
|
3
|
+
export { createJobExecution, type WorkerExecution } from "./execution.js";
|
|
4
|
+
export { createWorkerPruner } from "./prune.js";
|
|
5
|
+
export { JobExecutionError } from "./execution-error.js";
|
|
6
|
+
export { PgResultNotifications, RESULT_DELIVERY_MAX_ATTEMPTS, RESULT_DELIVERY_INITIAL_BACKOFF_SECONDS, RESULT_DELIVERY_RETRY_WINDOW_SECONDS, type ResultNotificationOptions, } from "./result-notifications.js";
|
|
7
|
+
export { GitHubCommitStatusNotifier, GitHubPrCommentNotifier, DiscordResultNotifier, resultNotifiers, type ResultContext, type ResultTransports, } from "../result-notifier.js";
|
|
8
|
+
export { createGitHubResultTransport, createDiscordResultTransport, type ResultHttp, } from "../result-transports.js";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { PgJobQueue, JOB_LEASE_MS } from "./queue.js";
|
|
2
|
+
import { startQaWorker, installWorkerSignals } from "./worker.js";
|
|
3
|
+
import { createJobExecution } from "./execution.js";
|
|
4
|
+
import { createWorkerPruner } from "./prune.js";
|
|
5
|
+
import { JobExecutionError } from "./execution-error.js";
|
|
6
|
+
import {
|
|
7
|
+
PgResultNotifications,
|
|
8
|
+
RESULT_DELIVERY_MAX_ATTEMPTS,
|
|
9
|
+
RESULT_DELIVERY_INITIAL_BACKOFF_SECONDS,
|
|
10
|
+
RESULT_DELIVERY_RETRY_WINDOW_SECONDS
|
|
11
|
+
} from "./result-notifications.js";
|
|
12
|
+
import {
|
|
13
|
+
GitHubCommitStatusNotifier,
|
|
14
|
+
GitHubPrCommentNotifier,
|
|
15
|
+
DiscordResultNotifier,
|
|
16
|
+
resultNotifiers
|
|
17
|
+
} from "../result-notifier.js";
|
|
18
|
+
import {
|
|
19
|
+
createGitHubResultTransport,
|
|
20
|
+
createDiscordResultTransport
|
|
21
|
+
} from "../result-transports.js";
|
|
22
|
+
export {
|
|
23
|
+
DiscordResultNotifier,
|
|
24
|
+
GitHubCommitStatusNotifier,
|
|
25
|
+
GitHubPrCommentNotifier,
|
|
26
|
+
JOB_LEASE_MS,
|
|
27
|
+
JobExecutionError,
|
|
28
|
+
PgJobQueue,
|
|
29
|
+
PgResultNotifications,
|
|
30
|
+
RESULT_DELIVERY_INITIAL_BACKOFF_SECONDS,
|
|
31
|
+
RESULT_DELIVERY_MAX_ATTEMPTS,
|
|
32
|
+
RESULT_DELIVERY_RETRY_WINDOW_SECONDS,
|
|
33
|
+
createDiscordResultTransport,
|
|
34
|
+
createGitHubResultTransport,
|
|
35
|
+
createJobExecution,
|
|
36
|
+
createWorkerPruner,
|
|
37
|
+
installWorkerSignals,
|
|
38
|
+
resultNotifiers,
|
|
39
|
+
startQaWorker
|
|
40
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { pruneQaSandboxes } from "../adapters/e2b-prune.js";
|
|
2
|
+
function createWorkerPruner(queue, client) {
|
|
3
|
+
return async () => {
|
|
4
|
+
for (const projectId of queue.projects) {
|
|
5
|
+
const result = await pruneQaSandboxes({
|
|
6
|
+
client,
|
|
7
|
+
projectId,
|
|
8
|
+
isFinished: async (runId, batchId) => {
|
|
9
|
+
const result2 = await queue.db.pool.query(
|
|
10
|
+
`SELECT r.id FROM qa.runs r JOIN qa.jobs j ON j.project_id=r.project_id AND j.run_id=r.id WHERE r.project_id=$1 AND r.id=$2 AND r.batch_id=$3 AND r.verdict IS NOT NULL AND j.state IN ('done','lost')`,
|
|
11
|
+
[projectId, runId, batchId]
|
|
12
|
+
);
|
|
13
|
+
return !!result2.rowCount;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
if (result.failed) throw new Error("QA orphan sandbox cleanup incomplete");
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
createWorkerPruner
|
|
22
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { QaDatabase } from "../db/database.js";
|
|
2
|
+
import type { ResultTransports } from "../result-notifier.js";
|
|
3
|
+
/** Durable entry notices share the result pipeline's Discord transport and worker drain. */
|
|
4
|
+
export declare function drainQuarantineNotifications(db: QaDatabase, options: {
|
|
5
|
+
projects: readonly string[];
|
|
6
|
+
transports: (projectId: string) => ResultTransports;
|
|
7
|
+
onError?: (message: string) => void;
|
|
8
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
function label(value, fallback) {
|
|
3
|
+
const ordinary = /^[A-Za-z0-9_][A-Za-z0-9_. -]{0,95}$/.test(value);
|
|
4
|
+
const credential = /(?:^|[ ._-])(?:sk|gh[pousr]|github_pat|xox[baprs]|bearer|token|secret|password)(?:[ ._-]|$)|(?:^|[ ._-])(?:AKIA|ASIA)[A-Z0-9]{16}(?=$|[ ._-])|(?:^| )eyJ[A-Za-z0-9_-]+\.|[A-Za-z0-9_-]{32}/i.test(
|
|
5
|
+
value
|
|
6
|
+
);
|
|
7
|
+
const address = /(?:^|[ ._-])www\./i.test(value);
|
|
8
|
+
return ordinary && !credential && !address ? value : fallback;
|
|
9
|
+
}
|
|
10
|
+
async function drainQuarantineNotifications(db, options) {
|
|
11
|
+
const pending = await db.pool.query(
|
|
12
|
+
`SELECT project_id,flow,generation FROM qa.quarantine_notifications
|
|
13
|
+
WHERE project_id=ANY($1::text[]) AND completed_at IS NULL AND abandoned_at IS NULL
|
|
14
|
+
AND available_at<=clock_timestamp() ORDER BY available_at LIMIT 100`,
|
|
15
|
+
[options.projects]
|
|
16
|
+
);
|
|
17
|
+
let failed = false;
|
|
18
|
+
for (const row of pending.rows) {
|
|
19
|
+
let failure;
|
|
20
|
+
const delivered = await db.transaction(async (client) => {
|
|
21
|
+
const key = [row.project_id, row.flow, row.generation];
|
|
22
|
+
const locked = await client.query(
|
|
23
|
+
`SELECT owner,run_id FROM qa.quarantine_notifications WHERE project_id=$1 AND flow=$2 AND generation=$3
|
|
24
|
+
AND completed_at IS NULL AND abandoned_at IS NULL AND available_at<=clock_timestamp() FOR UPDATE SKIP LOCKED`,
|
|
25
|
+
key
|
|
26
|
+
);
|
|
27
|
+
if (!locked.rows[0]) return true;
|
|
28
|
+
const entry = locked.rows[0];
|
|
29
|
+
const run = /^(?:run_)?[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i.test(entry.run_id) ? entry.run_id : "run";
|
|
30
|
+
const controller = new AbortController();
|
|
31
|
+
let timer;
|
|
32
|
+
try {
|
|
33
|
+
await Promise.race([
|
|
34
|
+
options.transports(row.project_id).discord.send(
|
|
35
|
+
{
|
|
36
|
+
content: `QA flow quarantined: ${label(row.flow, "flow")}
|
|
37
|
+
Owner: ${label(entry.owner ?? "unassigned", "owner")}
|
|
38
|
+
Three consecutive flaky executions. Runs continue without blocking or result notifications. Run: ${run}
|
|
39
|
+
Use --repeat before quarantine release.`,
|
|
40
|
+
allowedMentions: { parse: [] }
|
|
41
|
+
},
|
|
42
|
+
controller.signal
|
|
43
|
+
),
|
|
44
|
+
new Promise((_, reject) => {
|
|
45
|
+
timer = setTimeout(() => {
|
|
46
|
+
controller.abort();
|
|
47
|
+
reject(new Error("QA quarantine delivery timed out"));
|
|
48
|
+
}, 5e3);
|
|
49
|
+
})
|
|
50
|
+
]);
|
|
51
|
+
await client.query(
|
|
52
|
+
"UPDATE qa.quarantine_notifications SET completed_at=clock_timestamp() WHERE project_id=$1 AND flow=$2 AND generation=$3",
|
|
53
|
+
key
|
|
54
|
+
);
|
|
55
|
+
return true;
|
|
56
|
+
} catch {
|
|
57
|
+
const result = await client.query(
|
|
58
|
+
`UPDATE qa.quarantine_notifications SET attempts=attempts+1,
|
|
59
|
+
abandoned_at=CASE WHEN attempts+1>=5 THEN clock_timestamp() ELSE NULL END,
|
|
60
|
+
available_at=clock_timestamp()+interval '1 minute'*power(2,attempts)
|
|
61
|
+
WHERE project_id=$1 AND flow=$2 AND generation=$3
|
|
62
|
+
RETURNING attempts,abandoned_at IS NOT NULL AS abandoned`,
|
|
63
|
+
key
|
|
64
|
+
);
|
|
65
|
+
failure = result.rows[0];
|
|
66
|
+
return false;
|
|
67
|
+
} finally {
|
|
68
|
+
clearTimeout(timer);
|
|
69
|
+
controller.abort();
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
if (!delivered) {
|
|
73
|
+
failed = true;
|
|
74
|
+
if (failure) {
|
|
75
|
+
const prefix = failure.abandoned ? "QA_QUARANTINE_DELIVERY_ABANDONED" : "QA_QUARANTINE_DELIVERY_RETRY";
|
|
76
|
+
const project = /^[a-z][a-z0-9-]{0,63}$/.test(row.project_id) ? row.project_id : createHash("sha256").update(row.project_id).digest("hex");
|
|
77
|
+
const message = `${prefix} project=${project} flow=${createHash("sha256").update(row.flow).digest("hex")} generation=${row.generation} attempt=${failure.attempts}${failure.abandoned ? "" : ` retryDelaySeconds=${60 * 2 ** (failure.attempts - 1)}`}`;
|
|
78
|
+
try {
|
|
79
|
+
(options.onError ?? console.error)(message);
|
|
80
|
+
} catch {
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (failed) throw new Error("QA quarantine entry delivery failed");
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
drainQuarantineNotifications
|
|
89
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { PoolClient } from "pg";
|
|
2
|
+
import { type SubmitBatch, type BatchDto, type Verdict } from "@open-qa/qa-engine/protocol";
|
|
3
|
+
import { QaDatabase } from "../db/database.js";
|
|
4
|
+
export declare const JOB_LEASE_MS = 120000;
|
|
5
|
+
export interface JobToken {
|
|
6
|
+
projectId: string;
|
|
7
|
+
jobId: string;
|
|
8
|
+
runId: string;
|
|
9
|
+
owner: string;
|
|
10
|
+
epoch: string;
|
|
11
|
+
}
|
|
12
|
+
export interface JobClaim extends JobToken {
|
|
13
|
+
flow: string;
|
|
14
|
+
batchId: string;
|
|
15
|
+
createdBy: string;
|
|
16
|
+
trigger: BatchDto["trigger"];
|
|
17
|
+
commit: string | null;
|
|
18
|
+
target: string | null;
|
|
19
|
+
retryOf: string | null;
|
|
20
|
+
request: SubmitBatch;
|
|
21
|
+
}
|
|
22
|
+
export interface JobOutcome {
|
|
23
|
+
verdict: Verdict;
|
|
24
|
+
cleanupConfirmed: boolean;
|
|
25
|
+
verifiedRevision?: string | null;
|
|
26
|
+
infrastructureFailure?: boolean;
|
|
27
|
+
}
|
|
28
|
+
type JobRow = {
|
|
29
|
+
project_id: string;
|
|
30
|
+
id: string;
|
|
31
|
+
run_id: string;
|
|
32
|
+
owner: string;
|
|
33
|
+
epoch: string;
|
|
34
|
+
state: string;
|
|
35
|
+
attempts: number;
|
|
36
|
+
retry_of: string | null;
|
|
37
|
+
cleaned_at: Date | null;
|
|
38
|
+
};
|
|
39
|
+
export declare function lockJob(client: PoolClient, job: JobToken): Promise<JobRow>;
|
|
40
|
+
export declare class PgJobQueue {
|
|
41
|
+
readonly db: QaDatabase;
|
|
42
|
+
readonly projects: readonly string[];
|
|
43
|
+
private readonly classificationNotifications;
|
|
44
|
+
private readonly completingNotifications;
|
|
45
|
+
deferClassificationNotification(job: JobToken, notify: (runIds: string[]) => Promise<void>): void;
|
|
46
|
+
private notifyCompletion;
|
|
47
|
+
private complete;
|
|
48
|
+
private pruneClassificationNotifications;
|
|
49
|
+
constructor(db: QaDatabase, projects: readonly string[]);
|
|
50
|
+
private scoped;
|
|
51
|
+
claim(owner: string, concurrency: number, signal?: AbortSignal): Promise<JobClaim | undefined>;
|
|
52
|
+
recordRevision(job: JobToken, revision: string): Promise<void>;
|
|
53
|
+
start(job: JobToken): Promise<boolean>;
|
|
54
|
+
heartbeat(job: JobToken): Promise<{
|
|
55
|
+
cancelled: boolean;
|
|
56
|
+
}>;
|
|
57
|
+
finish(job: JobToken, outcome: JobOutcome): Promise<void>;
|
|
58
|
+
release(job: JobToken): Promise<void>;
|
|
59
|
+
expire(): Promise<number>;
|
|
60
|
+
pendingCleanup(): Promise<JobToken[]>;
|
|
61
|
+
recover(job: JobToken, stopAndRevoke: (job: JobToken) => Promise<void>): Promise<void>;
|
|
62
|
+
private quarantine;
|
|
63
|
+
private releaseLocked;
|
|
64
|
+
}
|
|
65
|
+
export {};
|