@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,43 @@
|
|
|
1
|
+
async function downloadArtifact(authorize, signal, send = fetch, now = Date.now) {
|
|
2
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
3
|
+
let response;
|
|
4
|
+
try {
|
|
5
|
+
const grant = await authorize();
|
|
6
|
+
const url = new URL(grant.url);
|
|
7
|
+
if (!Number.isFinite(grant.expiresAt) || grant.expiresAt <= now()) throw new Error("Expired");
|
|
8
|
+
if (url.protocol !== "https:" || url.hostname !== "storage.googleapis.com" || url.port || url.username || url.password || url.hash)
|
|
9
|
+
throw new Error("Invalid URL");
|
|
10
|
+
response = await send(grant.url, {
|
|
11
|
+
redirect: "error",
|
|
12
|
+
cache: "no-store",
|
|
13
|
+
signal: AbortSignal.any([signal, AbortSignal.timeout(3e4)])
|
|
14
|
+
});
|
|
15
|
+
if (response.ok) {
|
|
16
|
+
const reader = response.body?.getReader();
|
|
17
|
+
if (!reader) return new Uint8Array();
|
|
18
|
+
const chunks = [];
|
|
19
|
+
let bytes = 0;
|
|
20
|
+
try {
|
|
21
|
+
for (; ; ) {
|
|
22
|
+
const chunk = await reader.read();
|
|
23
|
+
if (chunk.done) break;
|
|
24
|
+
bytes += chunk.value.length;
|
|
25
|
+
if (bytes > 64 * 1024 * 1024) throw new Error("Limit");
|
|
26
|
+
chunks.push(chunk.value);
|
|
27
|
+
}
|
|
28
|
+
} finally {
|
|
29
|
+
await reader.cancel();
|
|
30
|
+
}
|
|
31
|
+
return Buffer.concat(chunks);
|
|
32
|
+
}
|
|
33
|
+
await response.body?.cancel();
|
|
34
|
+
} catch {
|
|
35
|
+
throw new Error("Artifact download unavailable");
|
|
36
|
+
}
|
|
37
|
+
if (response.status !== 403 || attempt === 1) throw new Error("Artifact download unavailable");
|
|
38
|
+
}
|
|
39
|
+
throw new Error("Artifact download unavailable");
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
downloadArtifact
|
|
43
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { GcsArtifactStore, recordingFreeReport, UPLOAD_TTL_MS, REPORT_TTL_MS, RETENTION_MS, } from "./artifact-store.js";
|
|
2
|
+
export type { ArtifactCatalog, ArtifactRun, StoredArtifact } from "./artifact-store.js";
|
|
3
|
+
export { GcsEventObjects, createGcsClient } from "./client.js";
|
|
4
|
+
export type { GcsClient } from "./client.js";
|
|
5
|
+
export { PgArtifactCatalog } from "./pg-catalog.js";
|
|
6
|
+
export { downloadArtifact } from "./download.js";
|
|
7
|
+
export type { AuthorizedArtifact } from "./download.js";
|
|
8
|
+
export { periodicFlush } from "./periodic-flush.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GcsArtifactStore,
|
|
3
|
+
recordingFreeReport,
|
|
4
|
+
UPLOAD_TTL_MS,
|
|
5
|
+
REPORT_TTL_MS,
|
|
6
|
+
RETENTION_MS
|
|
7
|
+
} from "./artifact-store.js";
|
|
8
|
+
import { GcsEventObjects, createGcsClient } from "./client.js";
|
|
9
|
+
import { PgArtifactCatalog } from "./pg-catalog.js";
|
|
10
|
+
import { downloadArtifact } from "./download.js";
|
|
11
|
+
import { periodicFlush } from "./periodic-flush.js";
|
|
12
|
+
export {
|
|
13
|
+
GcsArtifactStore,
|
|
14
|
+
GcsEventObjects,
|
|
15
|
+
PgArtifactCatalog,
|
|
16
|
+
REPORT_TTL_MS,
|
|
17
|
+
RETENTION_MS,
|
|
18
|
+
UPLOAD_TTL_MS,
|
|
19
|
+
createGcsClient,
|
|
20
|
+
downloadArtifact,
|
|
21
|
+
periodicFlush,
|
|
22
|
+
recordingFreeReport
|
|
23
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Start alongside a run, await at shutdown, then perform one final flush after recordStop.
|
|
2
|
+
* Persist each snapshot ID through retries. A failed flush rejects this pump so the
|
|
3
|
+
* conductor can mark durability incomplete, rather than acknowledging lost data.
|
|
4
|
+
*/
|
|
5
|
+
export declare function periodicFlush(flush: () => Promise<void>, signal: AbortSignal, intervalMs?: number): Promise<void>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
2
|
+
async function periodicFlush(flush, signal, intervalMs = 3e4) {
|
|
3
|
+
if (!Number.isSafeInteger(intervalMs) || intervalMs < 1)
|
|
4
|
+
throw new Error("Invalid flush interval");
|
|
5
|
+
while (!signal.aborted) {
|
|
6
|
+
await flush();
|
|
7
|
+
try {
|
|
8
|
+
await delay(intervalMs, void 0, { signal });
|
|
9
|
+
} catch (error) {
|
|
10
|
+
if (!signal.aborted) throw error;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
periodicFlush
|
|
16
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type JobToken } from "../../worker/queue.js";
|
|
2
|
+
import { QaDatabase } from "../../db/database.js";
|
|
3
|
+
import { type ArtifactScan } from "../../artifact-scan.js";
|
|
4
|
+
import type { ArtifactCatalog, ArtifactRun, StoredArtifact } from "./artifact-store.js";
|
|
5
|
+
export declare class PgArtifactCatalog implements ArtifactCatalog {
|
|
6
|
+
private readonly db;
|
|
7
|
+
private readonly projectId;
|
|
8
|
+
private readonly job?;
|
|
9
|
+
constructor(db: QaDatabase, projectId: string, job?: JobToken);
|
|
10
|
+
private authorize;
|
|
11
|
+
recordScan(runId: string, input: ArtifactScan): Promise<void>;
|
|
12
|
+
clear(runId: string): Promise<void>;
|
|
13
|
+
run(runId: string): Promise<ArtifactRun | undefined>;
|
|
14
|
+
artifact(runId: string, path: string): Promise<StoredArtifact | undefined>;
|
|
15
|
+
commit(runId: string, artifacts: StoredArtifact[]): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { ARTIFACT_NAMESPACES } from "@open-qa/qa-engine";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { lockJob } from "../../worker/queue.js";
|
|
4
|
+
import { publicId } from "../../public-id.js";
|
|
5
|
+
import { artifactScanSchema } from "../../artifact-scan.js";
|
|
6
|
+
import { recordingFreeReport } from "./artifact-store.js";
|
|
7
|
+
import { sha256 } from "../../db/event-chunks.js";
|
|
8
|
+
function access(row) {
|
|
9
|
+
const metadata = z.object({
|
|
10
|
+
recordKeep: z.enum(["all", "failed"]),
|
|
11
|
+
artifactScan: artifactScanSchema.optional(),
|
|
12
|
+
artifactScanPending: artifactScanSchema.optional()
|
|
13
|
+
}).parse(row.metadata);
|
|
14
|
+
const pending = metadata.artifactScanPending ?? metadata.artifactScan;
|
|
15
|
+
return {
|
|
16
|
+
batchId: publicId.parse(row.batch_id),
|
|
17
|
+
startedAt: row.started_at,
|
|
18
|
+
verdict: row.verdict,
|
|
19
|
+
keep: metadata.recordKeep,
|
|
20
|
+
scanned: pending?.status === "passed" ? pending.files : {},
|
|
21
|
+
publishedScanned: metadata.artifactScan?.status === "passed" ? metadata.artifactScan.files : {}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
class PgArtifactCatalog {
|
|
25
|
+
constructor(db, projectId, job) {
|
|
26
|
+
this.db = db;
|
|
27
|
+
this.projectId = projectId;
|
|
28
|
+
publicId.parse(projectId);
|
|
29
|
+
this.job = job ? { ...job } : void 0;
|
|
30
|
+
}
|
|
31
|
+
db;
|
|
32
|
+
projectId;
|
|
33
|
+
job;
|
|
34
|
+
async authorize(client, runId) {
|
|
35
|
+
if (this.job) {
|
|
36
|
+
if (this.job.projectId !== this.projectId || this.job.runId !== runId)
|
|
37
|
+
throw new Error("Artifact job scope denied");
|
|
38
|
+
await lockJob(client, this.job);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const queued = await client.query(
|
|
42
|
+
"SELECT id FROM qa.jobs WHERE project_id=$1 AND run_id=$2 FOR UPDATE",
|
|
43
|
+
[this.projectId, runId]
|
|
44
|
+
);
|
|
45
|
+
if (queued.rowCount) throw new Error("Artifact job ownership required");
|
|
46
|
+
}
|
|
47
|
+
async recordScan(runId, input) {
|
|
48
|
+
publicId.parse(runId);
|
|
49
|
+
const scan = artifactScanSchema.parse(input);
|
|
50
|
+
await this.db.transaction(async (client) => {
|
|
51
|
+
await this.authorize(client, runId);
|
|
52
|
+
const result = await client.query(
|
|
53
|
+
"UPDATE qa.runs SET metadata=jsonb_set(COALESCE(metadata,'{}'),'{artifactScanPending}',$3::jsonb) WHERE project_id=$1 AND id=$2",
|
|
54
|
+
[this.projectId, runId, JSON.stringify(scan)]
|
|
55
|
+
);
|
|
56
|
+
if (result.rowCount !== 1) throw new Error("Artifact run scope denied");
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async clear(runId) {
|
|
60
|
+
publicId.parse(runId);
|
|
61
|
+
await this.db.transaction(async (client) => {
|
|
62
|
+
await this.authorize(client, runId);
|
|
63
|
+
const { rows } = await client.query(
|
|
64
|
+
"SELECT batch_id,started_at,verdict,metadata FROM qa.runs WHERE project_id=$1 AND id=$2 FOR UPDATE",
|
|
65
|
+
[this.projectId, runId]
|
|
66
|
+
);
|
|
67
|
+
if (!rows[0]) throw new Error("Artifact run scope denied");
|
|
68
|
+
const run = access(rows[0]);
|
|
69
|
+
if (run.keep !== "failed" || run.verdict !== "passed")
|
|
70
|
+
throw new Error("Artifact publication policy changed");
|
|
71
|
+
await client.query(
|
|
72
|
+
"DELETE FROM qa.artifacts WHERE project_id=$1 AND run_id=$2 AND NOT(path='report.html' AND sha256=$3)",
|
|
73
|
+
[this.projectId, runId, sha256(recordingFreeReport(runId))]
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
async run(runId) {
|
|
78
|
+
publicId.parse(runId);
|
|
79
|
+
const { rows } = await this.db.pool.query(
|
|
80
|
+
"SELECT batch_id,started_at,verdict,metadata FROM qa.runs WHERE project_id=$1 AND id=$2",
|
|
81
|
+
[this.projectId, runId]
|
|
82
|
+
);
|
|
83
|
+
return rows[0] ? access(rows[0]) : void 0;
|
|
84
|
+
}
|
|
85
|
+
async artifact(runId, path) {
|
|
86
|
+
publicId.parse(runId);
|
|
87
|
+
const { rows } = await this.db.pool.query(
|
|
88
|
+
"SELECT object_key,bytes,sha256 FROM qa.artifacts WHERE project_id=$1 AND run_id=$2 AND path=$3",
|
|
89
|
+
[this.projectId, runId, path]
|
|
90
|
+
);
|
|
91
|
+
const row = rows[0];
|
|
92
|
+
return row ? {
|
|
93
|
+
path,
|
|
94
|
+
contentType: "application/octet-stream",
|
|
95
|
+
bytes: Number(row.bytes),
|
|
96
|
+
objectKey: row.object_key,
|
|
97
|
+
sha256: row.sha256
|
|
98
|
+
} : void 0;
|
|
99
|
+
}
|
|
100
|
+
async commit(runId, artifacts) {
|
|
101
|
+
publicId.parse(runId);
|
|
102
|
+
await this.db.transaction(async (client) => {
|
|
103
|
+
await this.authorize(client, runId);
|
|
104
|
+
const { rows } = await client.query(
|
|
105
|
+
"SELECT batch_id,started_at,verdict,metadata FROM qa.runs WHERE project_id=$1 AND id=$2 FOR UPDATE",
|
|
106
|
+
[this.projectId, runId]
|
|
107
|
+
);
|
|
108
|
+
if (!rows[0]) throw new Error("Artifact run scope denied");
|
|
109
|
+
const run = access(rows[0]);
|
|
110
|
+
if (Date.now() >= run.startedAt + 30 * 24 * 60 * 60 * 1e3)
|
|
111
|
+
throw new Error("Artifact retention expired");
|
|
112
|
+
const published = { ...run.publishedScanned };
|
|
113
|
+
for (const artifact of artifacts) {
|
|
114
|
+
if (run.scanned[artifact.path] !== artifact.sha256 || run.keep === "failed" && run.verdict === "passed" && (artifact.path !== "report.html" || artifact.sha256 !== sha256(recordingFreeReport(runId))))
|
|
115
|
+
throw new Error("Artifact publication policy changed");
|
|
116
|
+
const prefixes = ARTIFACT_NAMESPACES.map(
|
|
117
|
+
(namespace) => `${namespace}/${this.projectId}/${run.batchId}/${runId}/`
|
|
118
|
+
);
|
|
119
|
+
if (!prefixes.some((prefix) => artifact.objectKey.startsWith(prefix)))
|
|
120
|
+
throw new Error("Artifact object scope denied");
|
|
121
|
+
await client.query(
|
|
122
|
+
`INSERT INTO qa.artifacts(project_id,run_id,path,kind,object_key,bytes,sha256) VALUES($1,$2,$3,$4,$5,$6,$7)
|
|
123
|
+
ON CONFLICT(project_id,run_id,path) DO UPDATE SET object_key=EXCLUDED.object_key,bytes=EXCLUDED.bytes,sha256=EXCLUDED.sha256`,
|
|
124
|
+
[
|
|
125
|
+
this.projectId,
|
|
126
|
+
runId,
|
|
127
|
+
artifact.path,
|
|
128
|
+
artifact.path === "report.html" ? "report" : "recording",
|
|
129
|
+
artifact.objectKey,
|
|
130
|
+
artifact.bytes,
|
|
131
|
+
artifact.sha256
|
|
132
|
+
]
|
|
133
|
+
);
|
|
134
|
+
published[artifact.path] = artifact.sha256;
|
|
135
|
+
}
|
|
136
|
+
await client.query(
|
|
137
|
+
"UPDATE qa.runs SET metadata=jsonb_set(metadata,'{artifactScan}',$3::jsonb) WHERE project_id=$1 AND id=$2",
|
|
138
|
+
[
|
|
139
|
+
this.projectId,
|
|
140
|
+
runId,
|
|
141
|
+
JSON.stringify({ status: "passed", files: published, findings: [] })
|
|
142
|
+
]
|
|
143
|
+
);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
export {
|
|
148
|
+
PgArtifactCatalog
|
|
149
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function assertReplayComplete(files: ReadonlyMap<string, Uint8Array>): void;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { posix } from "node:path";
|
|
2
|
+
import {
|
|
3
|
+
replayAssetsSchema,
|
|
4
|
+
replayIndexSchema,
|
|
5
|
+
replayManifestSchema
|
|
6
|
+
} from "@open-qa/qa-engine/protocol";
|
|
7
|
+
import { sha256 } from "../../db/event-chunks.js";
|
|
8
|
+
import { objectPath } from "./client.js";
|
|
9
|
+
function validateReplay(files) {
|
|
10
|
+
function read(path) {
|
|
11
|
+
objectPath(path);
|
|
12
|
+
const data = files.get(path);
|
|
13
|
+
if (!data) throw new Error("Incomplete replay snapshot");
|
|
14
|
+
return data;
|
|
15
|
+
}
|
|
16
|
+
function json(path) {
|
|
17
|
+
return JSON.parse(Buffer.from(read(path)).toString("utf8"));
|
|
18
|
+
}
|
|
19
|
+
const indexes = new Set(
|
|
20
|
+
[...files.keys()].filter((path) => /^views\/[^/]+\/index\.json$/.test(path))
|
|
21
|
+
);
|
|
22
|
+
const resources = new Set(
|
|
23
|
+
[...files.keys()].filter((path) => path === "assets/index.json")
|
|
24
|
+
);
|
|
25
|
+
if (files.has("manifest.json")) {
|
|
26
|
+
const manifest = replayManifestSchema.parse(json("manifest.json"));
|
|
27
|
+
resources.add(manifest.assets);
|
|
28
|
+
for (const view of manifest.views) indexes.add(view.index);
|
|
29
|
+
}
|
|
30
|
+
for (const path of indexes) {
|
|
31
|
+
const index = replayIndexSchema.parse(json(path));
|
|
32
|
+
const blocks = new Set(index.blocks.map((block) => block.path));
|
|
33
|
+
for (const block of index.blocks) {
|
|
34
|
+
objectPath(block.path);
|
|
35
|
+
const data = read(`${posix.dirname(path)}/${block.path}`);
|
|
36
|
+
if (data.length !== block.bytes || sha256(data) !== block.sha256)
|
|
37
|
+
throw new Error("Replay block digest mismatch");
|
|
38
|
+
}
|
|
39
|
+
for (const checkpoint of [
|
|
40
|
+
...index.checkpoints,
|
|
41
|
+
...index.blocks.flatMap((b) => b.checkpoint ? [b.checkpoint] : [])
|
|
42
|
+
]) {
|
|
43
|
+
if (!blocks.has(checkpoint.meta.block) || !blocks.has(checkpoint.snapshot.block))
|
|
44
|
+
throw new Error("Incomplete replay checkpoint");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
for (const path of resources) {
|
|
48
|
+
const assets = replayAssetsSchema.parse(json(path));
|
|
49
|
+
for (const asset of Object.values(assets)) {
|
|
50
|
+
const data = read(`assets/${asset.hash}`);
|
|
51
|
+
if (data.length !== asset.bytes || sha256(data) !== asset.hash)
|
|
52
|
+
throw new Error("Replay asset digest mismatch");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function assertReplayComplete(files) {
|
|
57
|
+
try {
|
|
58
|
+
validateReplay(files);
|
|
59
|
+
} catch {
|
|
60
|
+
throw new Error("Incomplete replay snapshot");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
assertReplayComplete
|
|
65
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SecretRedactor } from "@open-qa/qa-engine";
|
|
2
|
+
import type { Artifact } from "@open-qa/qa-engine/protocol";
|
|
3
|
+
export declare function scanUpload(runId: string, artifacts: Artifact[], redactor: SecretRedactor, scratch: string, read: (artifact: Artifact) => Promise<Uint8Array>): Promise<{
|
|
4
|
+
status: "passed" | "secret-leak";
|
|
5
|
+
files: Record<string, string>;
|
|
6
|
+
findings: {
|
|
7
|
+
file: string;
|
|
8
|
+
reason: "known-secret" | "unscannable";
|
|
9
|
+
}[];
|
|
10
|
+
}>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { mkdtemp, mkdir, writeFile, rm } from "node:fs/promises";
|
|
2
|
+
import { join, dirname } from "node:path";
|
|
3
|
+
import { scanRunArtifacts } from "../../artifact-scan.js";
|
|
4
|
+
async function scanUpload(runId, artifacts, redactor, scratch, read) {
|
|
5
|
+
await mkdir(scratch, { recursive: true, mode: 448 });
|
|
6
|
+
const root = await mkdtemp(join(scratch, "gcs-scan-"));
|
|
7
|
+
try {
|
|
8
|
+
let bytes = 0;
|
|
9
|
+
for (const artifact of artifacts) {
|
|
10
|
+
const data = await read(artifact);
|
|
11
|
+
bytes += data.length;
|
|
12
|
+
if (data.length !== artifact.bytes || data.length > 64 * 1024 * 1024 || bytes > 256 * 1024 * 1024)
|
|
13
|
+
throw new Error("Artifact scan byte limit");
|
|
14
|
+
const path = join(root, "runs", runId, artifact.path);
|
|
15
|
+
await mkdir(dirname(path), { recursive: true, mode: 448 });
|
|
16
|
+
await writeFile(path, data, { mode: 384, flag: "wx" });
|
|
17
|
+
}
|
|
18
|
+
await mkdir(join(root, "runs", runId), { recursive: true, mode: 448 });
|
|
19
|
+
return await scanRunArtifacts(root, runId, redactor);
|
|
20
|
+
} finally {
|
|
21
|
+
await rm(root, { recursive: true, force: true });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
scanUpload
|
|
26
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { FileRunStore, type FileRun } from "./file-run-store.js";
|
|
2
|
+
export { DirArtifactStore } from "./dir-artifact-store.js";
|
|
3
|
+
export { FixedLeasePool } from "./fixed-lease-pool.js";
|
|
4
|
+
export { LocalCredentialResolver } from "./local-credential-resolver.js";
|
|
5
|
+
export { FileReplayCache } from "./file-replay-cache.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FileRunStore } from "./file-run-store.js";
|
|
2
|
+
import { DirArtifactStore } from "./dir-artifact-store.js";
|
|
3
|
+
import { FixedLeasePool } from "./fixed-lease-pool.js";
|
|
4
|
+
import { LocalCredentialResolver } from "./local-credential-resolver.js";
|
|
5
|
+
import { FileReplayCache } from "./file-replay-cache.js";
|
|
6
|
+
export {
|
|
7
|
+
DirArtifactStore,
|
|
8
|
+
FileReplayCache,
|
|
9
|
+
FileRunStore,
|
|
10
|
+
FixedLeasePool,
|
|
11
|
+
LocalCredentialResolver
|
|
12
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { mkdtemp, open, rm } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { ensureDirectory, noFollowWrite } from "./local-files.js";
|
|
6
|
+
async function leaseTransaction(root, operation, signal, deadline) {
|
|
7
|
+
signal?.throwIfAborted();
|
|
8
|
+
await ensureDirectory(root);
|
|
9
|
+
const file = await open(join(root, "lease-transaction.lock"), noFollowWrite, 384);
|
|
10
|
+
try {
|
|
11
|
+
await lockFile(
|
|
12
|
+
file,
|
|
13
|
+
deadline === void 0 ? void 0 : Math.max(0, deadline - Date.now()) / 1e3,
|
|
14
|
+
signal
|
|
15
|
+
);
|
|
16
|
+
signal?.throwIfAborted();
|
|
17
|
+
return await operation();
|
|
18
|
+
} finally {
|
|
19
|
+
await file.close();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
async function probeLeaseLock() {
|
|
23
|
+
const root = await mkdtemp(join(tmpdir(), "qa-lease-lock-check-"));
|
|
24
|
+
try {
|
|
25
|
+
const file = await open(join(root, "probe.lock"), noFollowWrite, 384);
|
|
26
|
+
try {
|
|
27
|
+
await lockFile(file, 1e-3, AbortSignal.timeout(5e3));
|
|
28
|
+
} finally {
|
|
29
|
+
await file.close();
|
|
30
|
+
}
|
|
31
|
+
} finally {
|
|
32
|
+
await rm(root, { recursive: true, force: true });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function lockFile(file, waitSeconds, signal) {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
const child = spawn(
|
|
38
|
+
"flock",
|
|
39
|
+
["-x", "-E", "75", ...waitSeconds === void 0 ? [] : ["-w", String(waitSeconds)], "3"],
|
|
40
|
+
{ stdio: ["ignore", "ignore", "ignore", file.fd], signal }
|
|
41
|
+
);
|
|
42
|
+
child.once(
|
|
43
|
+
"error",
|
|
44
|
+
() => reject(
|
|
45
|
+
signal?.aborted ? signal.reason : new Error("Lease locking requires the flock utility")
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
child.once(
|
|
49
|
+
"close",
|
|
50
|
+
(code) => code === 0 ? resolve() : reject(
|
|
51
|
+
new Error(
|
|
52
|
+
code === 75 ? "lease-timeout: QA lease transaction deadline exceeded" : "Could not acquire lease transaction lock"
|
|
53
|
+
)
|
|
54
|
+
)
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
leaseTransaction,
|
|
60
|
+
probeLeaseLock
|
|
61
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CredentialRequest, CredentialResolver } from "@open-qa/qa-engine";
|
|
2
|
+
import { type ModelAccess } from "@open-qa/qa-engine/protocol";
|
|
3
|
+
export declare class LocalCredentialResolver implements CredentialResolver {
|
|
4
|
+
resolve(request: CredentialRequest): Promise<ModelAccess>;
|
|
5
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DEFAULT_MODEL_ACCESS } from "@open-qa/qa-engine/protocol";
|
|
2
|
+
class LocalCredentialResolver {
|
|
3
|
+
async resolve(request) {
|
|
4
|
+
if (request.purpose && !request.access) return { mode: "inherit-login" };
|
|
5
|
+
const access = request.access ?? DEFAULT_MODEL_ACCESS;
|
|
6
|
+
if (request.runtime === "pi" && (access.mode === "inherit-login" || access.env.CLAUDE_CODE_OAUTH_TOKEN || access.env.ANTHROPIC_AUTH_TOKEN))
|
|
7
|
+
throw new Error(
|
|
8
|
+
"Pi cannot inherit CLI login. Use Claude Code or Codex for subscription login. Pi requires QA team credentials supplied by the caller."
|
|
9
|
+
);
|
|
10
|
+
return structuredClone(access);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
LocalCredentialResolver
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function readLocalEnv(qaRoot: string): Promise<Record<string, string | undefined>>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { open } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { parseEnv } from "node:util";
|
|
4
|
+
import { hasCode, noFollowRead } from "./local-files.js";
|
|
5
|
+
async function readLocalEnv(qaRoot) {
|
|
6
|
+
const file = join(qaRoot, ".env.local");
|
|
7
|
+
let content;
|
|
8
|
+
try {
|
|
9
|
+
const handle = await open(file, noFollowRead);
|
|
10
|
+
try {
|
|
11
|
+
const stat = await handle.stat();
|
|
12
|
+
if (!stat.isFile())
|
|
13
|
+
throw new Error(`Expected a regular local QA environment file at ${file}`);
|
|
14
|
+
if (process.platform !== "win32" && (stat.mode & 63) !== 0)
|
|
15
|
+
throw new Error(`QA credentials must be private; run chmod 600 ${JSON.stringify(file)}`);
|
|
16
|
+
content = await handle.readFile("utf8");
|
|
17
|
+
} finally {
|
|
18
|
+
await handle.close();
|
|
19
|
+
}
|
|
20
|
+
} catch (error) {
|
|
21
|
+
if (error instanceof Error && !("code" in error)) throw error;
|
|
22
|
+
if (hasCode(error, "ENOENT"))
|
|
23
|
+
throw new Error(
|
|
24
|
+
`Cannot read ${file}; create the local QA resource configuration before running`,
|
|
25
|
+
{ cause: error }
|
|
26
|
+
);
|
|
27
|
+
throw new Error(`Cannot read local QA configuration at ${file}`, { cause: error });
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
return parseEnv(content);
|
|
31
|
+
} catch {
|
|
32
|
+
throw new Error(`Invalid dotenv configuration at ${file}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
readLocalEnv
|
|
37
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare function hasCode(error: unknown, code: string): boolean;
|
|
2
|
+
export declare function runDirectory(qaRoot: string, runId: string): string;
|
|
3
|
+
export declare function lockName(value: string): string;
|
|
4
|
+
export declare function ensureDirectory(directory: string): Promise<void>;
|
|
5
|
+
export declare function assertDirectory(directory: string): Promise<void>;
|
|
6
|
+
export declare function assertRegularFile(file: string): Promise<void>;
|
|
7
|
+
export declare function atomicWrite(file: string, data: string | Uint8Array): Promise<void>;
|
|
8
|
+
export declare function acquireLock(directory: string, owner: string, context: {
|
|
9
|
+
runId: string;
|
|
10
|
+
resource?: string;
|
|
11
|
+
expiresAt?: number;
|
|
12
|
+
}): Promise<boolean>;
|
|
13
|
+
export declare function lockConflict(directory: string): Promise<string>;
|
|
14
|
+
export declare function releaseLock(directory: string, owner: string): Promise<void>;
|
|
15
|
+
export declare function withRunLock<T>(qaRoot: string, runId: string, operation: () => Promise<T>): Promise<T>;
|
|
16
|
+
export declare const noFollowRead: number;
|
|
17
|
+
export declare const noFollowWrite: number;
|