@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,399 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import {
|
|
4
|
+
readExecutionSnapshot,
|
|
5
|
+
withExecutionObservation
|
|
6
|
+
} from "@open-qa/qa-engine";
|
|
7
|
+
import {
|
|
8
|
+
findingSchema,
|
|
9
|
+
jsonObjectSchema,
|
|
10
|
+
millisecondsSchema,
|
|
11
|
+
verdictSchema,
|
|
12
|
+
runUsageSchema
|
|
13
|
+
} from "@open-qa/qa-engine/protocol";
|
|
14
|
+
import { publicId, assertPostgresText } from "../db/database.js";
|
|
15
|
+
import { assertFence } from "../db/fencing.js";
|
|
16
|
+
import {
|
|
17
|
+
encodeEvents,
|
|
18
|
+
insertEventIndex,
|
|
19
|
+
readChunk
|
|
20
|
+
} from "../db/event-chunks.js";
|
|
21
|
+
import { PgQueries } from "../db/queries.js";
|
|
22
|
+
const createSchema = z.strictObject({
|
|
23
|
+
id: publicId,
|
|
24
|
+
flow: z.string().min(1),
|
|
25
|
+
startedAt: millisecondsSchema,
|
|
26
|
+
metadata: jsonObjectSchema.optional()
|
|
27
|
+
});
|
|
28
|
+
const outcomeSchema = z.strictObject({
|
|
29
|
+
usage: runUsageSchema.optional(),
|
|
30
|
+
errorReason: z.literal("budget").optional(),
|
|
31
|
+
verdict: verdictSchema,
|
|
32
|
+
finishedAt: millisecondsSchema,
|
|
33
|
+
reason: z.string().optional()
|
|
34
|
+
});
|
|
35
|
+
class PgRunStore {
|
|
36
|
+
constructor(db, project, objects, fence, jobGuard) {
|
|
37
|
+
this.db = db;
|
|
38
|
+
this.project = project;
|
|
39
|
+
this.objects = objects;
|
|
40
|
+
this.fence = fence;
|
|
41
|
+
this.jobGuard = jobGuard;
|
|
42
|
+
publicId.parse(project);
|
|
43
|
+
this.queries = new PgQueries(db, project);
|
|
44
|
+
}
|
|
45
|
+
db;
|
|
46
|
+
project;
|
|
47
|
+
objects;
|
|
48
|
+
fence;
|
|
49
|
+
jobGuard;
|
|
50
|
+
queries;
|
|
51
|
+
async createRun(input) {
|
|
52
|
+
const run = createSchema.parse(input);
|
|
53
|
+
assertPostgresText(run);
|
|
54
|
+
if (run.metadata?.executionSnapshot !== void 0 && readExecutionSnapshot(run.metadata.executionSnapshot).status !== "recorded")
|
|
55
|
+
throw new Error("Invalid execution snapshot");
|
|
56
|
+
try {
|
|
57
|
+
await this.db.pool.query(
|
|
58
|
+
`INSERT INTO qa.runs(project_id,id,flow,started_at,metadata) VALUES($1,$2,$3,$4,$5)`,
|
|
59
|
+
[this.project, run.id, run.flow, run.startedAt, run.metadata]
|
|
60
|
+
);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (error && typeof error === "object" && "code" in error && error.code === "23505")
|
|
63
|
+
throw new Error("Run already exists", { cause: error });
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
getRun(id) {
|
|
68
|
+
return this.queries.getRun(id);
|
|
69
|
+
}
|
|
70
|
+
recentUsage(flow) {
|
|
71
|
+
return this.queries.recentUsage(flow);
|
|
72
|
+
}
|
|
73
|
+
listRuns(limit = 20) {
|
|
74
|
+
return this.queries.listRuns({ limit });
|
|
75
|
+
}
|
|
76
|
+
appendEvents(runId, events) {
|
|
77
|
+
return this.appendChunk(runId, randomUUID(), events);
|
|
78
|
+
}
|
|
79
|
+
/** Persist batchId across retries. Different content under that ID is always rejected. */
|
|
80
|
+
async appendChunk(runId, batchId, input) {
|
|
81
|
+
publicId.parse(runId);
|
|
82
|
+
publicId.parse(batchId);
|
|
83
|
+
const { events, data, hash } = encodeEvents(input);
|
|
84
|
+
const objectKey = `events/${this.project}/${runId}/${batchId}/${hash}.ndjson`;
|
|
85
|
+
const complete = await this.db.transaction(async (client) => {
|
|
86
|
+
const run = await this.lockRun(client, runId);
|
|
87
|
+
await this.authorize(client, run);
|
|
88
|
+
const { rows } = await client.query(
|
|
89
|
+
"SELECT * FROM qa.event_chunks WHERE project_id=$1 AND run_id=$2 AND id=$3 FOR UPDATE",
|
|
90
|
+
[this.project, runId, batchId]
|
|
91
|
+
);
|
|
92
|
+
if (rows[0]) return this.existingChunk(rows[0], hash);
|
|
93
|
+
this.writable(run);
|
|
94
|
+
if (!events.length) return true;
|
|
95
|
+
this.checkCursor(run, events);
|
|
96
|
+
await client.query(
|
|
97
|
+
`INSERT INTO qa.event_chunks(project_id,run_id,id,object_key,sha256,count,bytes,first_seq,last_seq,first_t,last_t)
|
|
98
|
+
VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)`,
|
|
99
|
+
[
|
|
100
|
+
this.project,
|
|
101
|
+
runId,
|
|
102
|
+
batchId,
|
|
103
|
+
objectKey,
|
|
104
|
+
hash,
|
|
105
|
+
events.length,
|
|
106
|
+
data.length,
|
|
107
|
+
events[0].seq,
|
|
108
|
+
events.at(-1).seq,
|
|
109
|
+
events[0].t,
|
|
110
|
+
events.at(-1).t
|
|
111
|
+
]
|
|
112
|
+
);
|
|
113
|
+
return false;
|
|
114
|
+
});
|
|
115
|
+
if (complete) return;
|
|
116
|
+
await this.objects.putImmutable(objectKey, data);
|
|
117
|
+
await this.db.transaction(async (client) => {
|
|
118
|
+
const run = await this.lockRun(client, runId);
|
|
119
|
+
await this.authorize(client, run);
|
|
120
|
+
const { rows } = await client.query(
|
|
121
|
+
"SELECT * FROM qa.event_chunks WHERE project_id=$1 AND run_id=$2 AND id=$3 FOR UPDATE",
|
|
122
|
+
[this.project, runId, batchId]
|
|
123
|
+
);
|
|
124
|
+
if (this.existingChunk(rows[0], hash)) return;
|
|
125
|
+
this.writable(run);
|
|
126
|
+
this.checkCursor(run, events);
|
|
127
|
+
await insertEventIndex(client, this.project, runId, batchId, events);
|
|
128
|
+
await this.projectEvents(client, runId, events);
|
|
129
|
+
await client.query(
|
|
130
|
+
`UPDATE qa.event_chunks SET state='committed' WHERE project_id=$1 AND run_id=$2 AND id=$3`,
|
|
131
|
+
[this.project, runId, batchId]
|
|
132
|
+
);
|
|
133
|
+
await client.query(
|
|
134
|
+
`UPDATE qa.runs SET event_count=event_count+$3,event_bytes=event_bytes+$4,last_seq=$5,last_t=$6,heartbeat_at=clock_timestamp()
|
|
135
|
+
WHERE project_id=$1 AND id=$2`,
|
|
136
|
+
[this.project, runId, events.length, data.length, events.at(-1).seq, events.at(-1).t]
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
async finishRun(runId, input) {
|
|
141
|
+
publicId.parse(runId);
|
|
142
|
+
const { executionObservation, findings: rawFindings = [], ...outcome } = input;
|
|
143
|
+
const findings = z.array(findingSchema).parse(rawFindings);
|
|
144
|
+
assertPostgresText(findings);
|
|
145
|
+
const result = outcomeSchema.parse(outcome);
|
|
146
|
+
assertPostgresText(result);
|
|
147
|
+
await this.db.transaction(async (client) => {
|
|
148
|
+
const run = await this.lockRun(client, runId);
|
|
149
|
+
await this.authorize(client, run);
|
|
150
|
+
this.writable(run);
|
|
151
|
+
for (const [index, finding] of findings.entries()) {
|
|
152
|
+
await client.query(
|
|
153
|
+
`INSERT INTO qa.findings (project_id,run_id,ordinal,actor,step,category,severity,description,event_seqs,shots)
|
|
154
|
+
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9::jsonb,$10::jsonb)`,
|
|
155
|
+
[
|
|
156
|
+
this.project,
|
|
157
|
+
runId,
|
|
158
|
+
index + 1,
|
|
159
|
+
finding.actor,
|
|
160
|
+
finding.step,
|
|
161
|
+
finding.category,
|
|
162
|
+
finding.severity,
|
|
163
|
+
finding.description,
|
|
164
|
+
JSON.stringify(finding.eventSeqs),
|
|
165
|
+
JSON.stringify(finding.shots)
|
|
166
|
+
]
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
const metadata = executionObservation ? withExecutionObservation(run.metadata ?? void 0, executionObservation) : run.metadata;
|
|
170
|
+
assertPostgresText(metadata);
|
|
171
|
+
await client.query(
|
|
172
|
+
`UPDATE qa.runs SET verdict=$3,finished_at=$4,reason=$5,metadata=$6,usage=$7,error_reason=$8,cost_usd=COALESCE(($7::jsonb->>'costUsd')::double precision,cost_usd),phase='finished',heartbeat_at=clock_timestamp()
|
|
173
|
+
WHERE project_id=$1 AND id=$2`,
|
|
174
|
+
[
|
|
175
|
+
this.project,
|
|
176
|
+
runId,
|
|
177
|
+
result.verdict,
|
|
178
|
+
result.finishedAt,
|
|
179
|
+
result.reason,
|
|
180
|
+
metadata,
|
|
181
|
+
result.usage ? JSON.stringify(result.usage) : null,
|
|
182
|
+
result.errorReason
|
|
183
|
+
]
|
|
184
|
+
);
|
|
185
|
+
await client.query(
|
|
186
|
+
`UPDATE qa.lanes SET status=$3,finished_at=$4 WHERE project_id=$1 AND run_id=$2 AND status='running'`,
|
|
187
|
+
[
|
|
188
|
+
this.project,
|
|
189
|
+
runId,
|
|
190
|
+
result.verdict,
|
|
191
|
+
Math.max(run.last_t, result.finishedAt - run.started_at)
|
|
192
|
+
]
|
|
193
|
+
);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
async readFindings(runId) {
|
|
197
|
+
publicId.parse(runId);
|
|
198
|
+
const { rows } = await this.db.pool.query(
|
|
199
|
+
`SELECT actor,step,category,severity,description,event_seqs AS "eventSeqs",shots
|
|
200
|
+
FROM qa.findings WHERE project_id=$1 AND run_id=$2 ORDER BY ordinal`,
|
|
201
|
+
[this.project, runId]
|
|
202
|
+
);
|
|
203
|
+
return z.array(findingSchema).parse(rows);
|
|
204
|
+
}
|
|
205
|
+
/** Attach all subsequent writes to this lease's owner/epoch; unfenced writers then fail. */
|
|
206
|
+
async claimRun(runId, token) {
|
|
207
|
+
publicId.parse(runId);
|
|
208
|
+
await this.db.transaction(async (client) => {
|
|
209
|
+
const run = await this.lockRun(client, runId);
|
|
210
|
+
this.writable(run);
|
|
211
|
+
await assertFence(client, this.project, token, runId);
|
|
212
|
+
if (run.writer_lease_id && run.writer_lease_id !== token.id) {
|
|
213
|
+
const { rows } = await client.query(
|
|
214
|
+
"SELECT state FROM qa.leases WHERE project_id=$1 AND id=$2 FOR UPDATE",
|
|
215
|
+
[this.project, run.writer_lease_id]
|
|
216
|
+
);
|
|
217
|
+
if (rows[0]?.state !== "released")
|
|
218
|
+
throw new Error("Previous run owner requires confirmed cleanup");
|
|
219
|
+
}
|
|
220
|
+
await client.query("UPDATE qa.runs SET writer_lease_id=$3 WHERE project_id=$1 AND id=$2", [
|
|
221
|
+
this.project,
|
|
222
|
+
runId,
|
|
223
|
+
token.id
|
|
224
|
+
]);
|
|
225
|
+
});
|
|
226
|
+
return new PgRunStore(this.db, this.project, this.objects, {
|
|
227
|
+
id: token.id,
|
|
228
|
+
owner: token.owner,
|
|
229
|
+
epoch: token.epoch,
|
|
230
|
+
runId
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
async heartbeat(runId) {
|
|
234
|
+
await this.db.transaction(async (client) => {
|
|
235
|
+
const run = await this.lockRun(client, runId);
|
|
236
|
+
await this.authorize(client, run);
|
|
237
|
+
this.writable(run);
|
|
238
|
+
await client.query(
|
|
239
|
+
"UPDATE qa.runs SET heartbeat_at=clock_timestamp() WHERE project_id=$1 AND id=$2",
|
|
240
|
+
[this.project, runId]
|
|
241
|
+
);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
async readEvents(runId, afterSeq = 0, limit) {
|
|
245
|
+
if (!Number.isSafeInteger(afterSeq) || afterSeq < 0) throw new Error("Invalid event cursor");
|
|
246
|
+
if (limit !== void 0 && (!Number.isSafeInteger(limit) || limit < 1))
|
|
247
|
+
throw new Error("Invalid event limit");
|
|
248
|
+
const run = await this.getRun(runId);
|
|
249
|
+
if (!run) throw new Error("Unknown run");
|
|
250
|
+
if (afterSeq >= run.eventIndex.lastSeq) return [];
|
|
251
|
+
const { rows } = await this.db.pool.query(
|
|
252
|
+
`SELECT * FROM qa.event_chunks WHERE project_id=$1 AND run_id=$2 AND state='committed'
|
|
253
|
+
AND last_seq>$4 AND last_seq<=$3 ORDER BY first_seq LIMIT $5`,
|
|
254
|
+
[this.project, runId, run.eventIndex.lastSeq, afterSeq, limit ?? null]
|
|
255
|
+
);
|
|
256
|
+
const chunks = [];
|
|
257
|
+
const events = [];
|
|
258
|
+
let available = 0;
|
|
259
|
+
for (const chunk of rows) {
|
|
260
|
+
const segment = await readChunk(this.objects, chunk);
|
|
261
|
+
chunks.push(chunk);
|
|
262
|
+
events.push(...segment);
|
|
263
|
+
available += segment.filter((event) => event.seq > afterSeq).length;
|
|
264
|
+
if (limit !== void 0 && available >= limit) break;
|
|
265
|
+
}
|
|
266
|
+
if (limit === void 0 || available < limit || events.at(-1)?.seq === run.eventIndex.lastSeq)
|
|
267
|
+
this.checkHistory(chunks, events, run.eventIndex, afterSeq === 0);
|
|
268
|
+
else encodeEventsForHistory(events);
|
|
269
|
+
return events.filter((e) => e.seq > afterSeq).slice(0, limit);
|
|
270
|
+
}
|
|
271
|
+
async repairEventIndex(runId) {
|
|
272
|
+
const snapshot = await this.getRun(runId);
|
|
273
|
+
if (!snapshot) throw new Error("Unknown run");
|
|
274
|
+
const { rows } = await this.db.pool.query(
|
|
275
|
+
`SELECT * FROM qa.event_chunks WHERE project_id=$1 AND run_id=$2 AND state='committed'
|
|
276
|
+
AND last_seq<=$3 ORDER BY first_seq`,
|
|
277
|
+
[this.project, runId, snapshot.eventIndex.lastSeq]
|
|
278
|
+
);
|
|
279
|
+
const segments = await this.readSegments(rows);
|
|
280
|
+
this.checkHistory(rows, segments.flat(), snapshot.eventIndex, true);
|
|
281
|
+
await this.db.transaction(async (client) => {
|
|
282
|
+
const run = await this.lockRun(client, runId);
|
|
283
|
+
if (Number(run.last_seq) !== snapshot.eventIndex.lastSeq || run.last_t !== snapshot.eventIndex.lastT || run.event_count !== snapshot.eventIndex.count || Number(run.event_bytes) !== snapshot.eventIndex.bytes)
|
|
284
|
+
throw new Error("Run cursor changed during repair; retry from a new snapshot");
|
|
285
|
+
await client.query("DELETE FROM qa.events WHERE project_id=$1 AND run_id=$2", [
|
|
286
|
+
this.project,
|
|
287
|
+
runId
|
|
288
|
+
]);
|
|
289
|
+
for (let i = 0; i < rows.length; i++)
|
|
290
|
+
await insertEventIndex(client, this.project, runId, rows[i].id, segments[i]);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
async cleanOrphans(graceMs) {
|
|
294
|
+
if (!Number.isSafeInteger(graceMs) || graceMs < 6e4)
|
|
295
|
+
throw new Error("Orphan grace must be at least 60000ms");
|
|
296
|
+
await this.db.pool.query(
|
|
297
|
+
`UPDATE qa.event_chunks SET state='abandoned' WHERE project_id=$1 AND state='uploading'
|
|
298
|
+
AND created_at < clock_timestamp()-$2 * interval '1 millisecond'`,
|
|
299
|
+
[this.project, graceMs]
|
|
300
|
+
);
|
|
301
|
+
const { rows } = await this.db.pool.query(
|
|
302
|
+
`SELECT * FROM qa.event_chunks WHERE project_id=$1 AND (state='abandoned'
|
|
303
|
+
OR (state='cleaned' AND cleaned_at >= clock_timestamp()-$2 * interval '1 millisecond'))`,
|
|
304
|
+
[this.project, Math.max(graceMs, 864e5)]
|
|
305
|
+
);
|
|
306
|
+
for (const chunk of rows) {
|
|
307
|
+
await this.objects.remove(chunk.object_key);
|
|
308
|
+
await this.db.pool.query(
|
|
309
|
+
"UPDATE qa.event_chunks SET state='cleaned',cleaned_at=clock_timestamp() WHERE project_id=$1 AND run_id=$2 AND id=$3 AND state='abandoned'",
|
|
310
|
+
[this.project, chunk.run_id, chunk.id]
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
return rows.length;
|
|
314
|
+
}
|
|
315
|
+
async lockRun(client, id) {
|
|
316
|
+
await this.jobGuard?.(client);
|
|
317
|
+
publicId.parse(id);
|
|
318
|
+
const { rows } = await client.query(
|
|
319
|
+
"SELECT * FROM qa.runs WHERE project_id=$1 AND id=$2 FOR UPDATE",
|
|
320
|
+
[this.project, id]
|
|
321
|
+
);
|
|
322
|
+
if (!rows[0]) throw new Error("Unknown run");
|
|
323
|
+
return rows[0];
|
|
324
|
+
}
|
|
325
|
+
async authorize(client, run) {
|
|
326
|
+
if (run.writer_lease_id) {
|
|
327
|
+
if (!this.fence || run.writer_lease_id !== this.fence.id)
|
|
328
|
+
throw new Error("Stale lease owner or fencing token");
|
|
329
|
+
await assertFence(client, this.project, this.fence, run.id);
|
|
330
|
+
} else if (this.fence) throw new Error("Run has not been claimed by this lease");
|
|
331
|
+
}
|
|
332
|
+
writable(run) {
|
|
333
|
+
if (run.verdict) throw new Error("Run is finished");
|
|
334
|
+
}
|
|
335
|
+
checkCursor(run, events) {
|
|
336
|
+
if (events[0] && events[0].seq <= Number(run.last_seq))
|
|
337
|
+
throw new Error("Event sequence must increase");
|
|
338
|
+
if (events[0] && events[0].t < run.last_t) throw new Error("Event time must not decrease");
|
|
339
|
+
}
|
|
340
|
+
existingChunk(chunk, hash) {
|
|
341
|
+
if (chunk.sha256 !== hash) throw new Error("Batch content does not match the original upload");
|
|
342
|
+
if (["abandoned", "cleaned"].includes(chunk.state))
|
|
343
|
+
throw new Error("Event upload was abandoned; use a new batch ID");
|
|
344
|
+
return chunk.state === "committed";
|
|
345
|
+
}
|
|
346
|
+
async readSegments(chunks) {
|
|
347
|
+
const segments = [];
|
|
348
|
+
for (const chunk of chunks) segments.push(await readChunk(this.objects, chunk));
|
|
349
|
+
return segments;
|
|
350
|
+
}
|
|
351
|
+
checkHistory(chunks, events, cursor, full) {
|
|
352
|
+
encodeEventsForHistory(events);
|
|
353
|
+
if (full && (events.length !== cursor.count || chunks.reduce((sum, c) => sum + c.bytes, 0) !== cursor.bytes) || (events.at(-1)?.seq ?? 0) !== cursor.lastSeq || (events.at(-1)?.t ?? 0) !== cursor.lastT)
|
|
354
|
+
throw new Error("Event chunk integrity does not match the committed cursor");
|
|
355
|
+
}
|
|
356
|
+
async projectEvents(client, runId, events) {
|
|
357
|
+
for (const e of events) {
|
|
358
|
+
if (e.kind === "run_phase")
|
|
359
|
+
await client.query("UPDATE qa.runs SET phase=$3 WHERE project_id=$1 AND id=$2", [
|
|
360
|
+
this.project,
|
|
361
|
+
runId,
|
|
362
|
+
e.phase
|
|
363
|
+
]);
|
|
364
|
+
if (e.kind === "usage" && e.costUsd !== void 0)
|
|
365
|
+
await client.query(
|
|
366
|
+
"UPDATE qa.runs SET cost_usd=cost_usd+$3 WHERE project_id=$1 AND id=$2",
|
|
367
|
+
[this.project, runId, e.costUsd]
|
|
368
|
+
);
|
|
369
|
+
if (e.kind === "step_started") {
|
|
370
|
+
await client.query(
|
|
371
|
+
`INSERT INTO qa.lanes(project_id,run_id,actor,status,started_at) VALUES($1,$2,$3,'running',$4) ON CONFLICT DO NOTHING`,
|
|
372
|
+
[this.project, runId, e.actor, e.t]
|
|
373
|
+
);
|
|
374
|
+
await client.query(
|
|
375
|
+
`INSERT INTO qa.step_runs(project_id,run_id,actor,step,seq,status,started_at) VALUES($1,$2,$3,$4,$5,'running',$6)`,
|
|
376
|
+
[this.project, runId, e.actor, e.step, e.seq, e.t]
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
if (e.kind === "step_finished")
|
|
380
|
+
await client.query(
|
|
381
|
+
`UPDATE qa.step_runs SET status=$5,finished_at=$6 WHERE project_id=$1 AND run_id=$2 AND seq=(
|
|
382
|
+
SELECT seq FROM qa.step_runs WHERE project_id=$1 AND run_id=$2 AND step=$3 AND ($4::text IS NULL OR actor=$4) AND status='running' ORDER BY seq DESC LIMIT 1)`,
|
|
383
|
+
[this.project, runId, e.step, e.actor, e.status, e.t]
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
function encodeEventsForHistory(events) {
|
|
389
|
+
let seq = 0, t = 0;
|
|
390
|
+
for (const event of events) {
|
|
391
|
+
if (event.seq <= seq || event.t < t)
|
|
392
|
+
throw new Error("Event chunk integrity has overlapping or decreasing history");
|
|
393
|
+
seq = event.seq;
|
|
394
|
+
t = event.t;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
export {
|
|
398
|
+
PgRunStore
|
|
399
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { jsonObjectSchema } from "@open-qa/qa-engine/protocol";
|
|
3
|
+
const publicId = z.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/);
|
|
4
|
+
const poolsSchema = z.record(publicId, z.record(publicId, jsonObjectSchema));
|
|
5
|
+
function parseResourcePools(value) {
|
|
6
|
+
let pools;
|
|
7
|
+
try {
|
|
8
|
+
pools = poolsSchema.parse(JSON.parse(value ?? ""));
|
|
9
|
+
} catch {
|
|
10
|
+
throw new Error(
|
|
11
|
+
"Invalid QA_RESOURCE_POOLS; expected JSON {kind: {resourceId: {fields}}}. Add typed pools alongside legacy QA_RESOURCES; see apps/qa/docs/accounts.md"
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
const ids = /* @__PURE__ */ new Set();
|
|
15
|
+
for (const pool of Object.values(pools)) {
|
|
16
|
+
for (const id of Object.keys(pool)) {
|
|
17
|
+
if (ids.has(id))
|
|
18
|
+
throw new Error(
|
|
19
|
+
"Invalid QA_RESOURCE_POOLS; resourceId must be unique across kinds to share legacy name locks. Use distinct, stable IDs; see apps/qa/docs/accounts.md"
|
|
20
|
+
);
|
|
21
|
+
ids.add(id);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return pools;
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
parseResourcePools
|
|
28
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { CredentialRequest, CredentialResolver, SecretRedactor } from "@open-qa/qa-engine";
|
|
3
|
+
import type { ModelAccess } from "@open-qa/qa-engine/protocol";
|
|
4
|
+
import { type CredentialReferences } from "../credential-references.js";
|
|
5
|
+
export interface SecretManagerReader {
|
|
6
|
+
access(secretRef: string): Promise<string>;
|
|
7
|
+
}
|
|
8
|
+
export type CloudRunIdentity = z.infer<typeof identitySchema>;
|
|
9
|
+
export interface CloudCredentialOptions {
|
|
10
|
+
identity: CloudRunIdentity;
|
|
11
|
+
credentials: CredentialReferences;
|
|
12
|
+
secrets: SecretManagerReader;
|
|
13
|
+
redactor: Pick<SecretRedactor, "add">;
|
|
14
|
+
secretProject: string;
|
|
15
|
+
team: {
|
|
16
|
+
secretRef: string;
|
|
17
|
+
baseUrl: string;
|
|
18
|
+
};
|
|
19
|
+
now?: () => number;
|
|
20
|
+
}
|
|
21
|
+
declare const identitySchema: z.ZodObject<{
|
|
22
|
+
trigger: z.ZodEnum<{
|
|
23
|
+
developer: "developer";
|
|
24
|
+
"pr-label": "pr-label";
|
|
25
|
+
schedule: "schedule";
|
|
26
|
+
deployment: "deployment";
|
|
27
|
+
}>;
|
|
28
|
+
createdBy: z.ZodOptional<z.ZodString>;
|
|
29
|
+
requestedBy: z.ZodOptional<z.ZodString>;
|
|
30
|
+
modelAccess: z.ZodOptional<z.ZodEnum<{
|
|
31
|
+
personal: "personal";
|
|
32
|
+
team: "team";
|
|
33
|
+
}>>;
|
|
34
|
+
}, z.core.$strict>;
|
|
35
|
+
export declare class SecretManagerCredentialResolver implements CredentialResolver {
|
|
36
|
+
private readonly options;
|
|
37
|
+
private readonly identity;
|
|
38
|
+
private readonly team;
|
|
39
|
+
constructor(options: CloudCredentialOptions);
|
|
40
|
+
resolve(request: CredentialRequest): Promise<ModelAccess>;
|
|
41
|
+
private resolveTeam;
|
|
42
|
+
private read;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import {
|
|
3
|
+
assertPersonalReference,
|
|
4
|
+
cloudRuntimeSchema,
|
|
5
|
+
parseCredentialReference,
|
|
6
|
+
secretRefSchema
|
|
7
|
+
} from "../credential-references.js";
|
|
8
|
+
import { publicId } from "../public-id.js";
|
|
9
|
+
const tokenSchema = z.string().min(1).max(65536).regex(/^[!-~]+$/);
|
|
10
|
+
const personalPayloadSchema = z.strictObject({
|
|
11
|
+
kind: z.enum(["claude", "anthropic-key", "openai-key"]),
|
|
12
|
+
token: tokenSchema
|
|
13
|
+
});
|
|
14
|
+
const identitySchema = z.strictObject({
|
|
15
|
+
trigger: z.enum(["deployment", "schedule", "pr-label", "developer"]),
|
|
16
|
+
createdBy: publicId.optional(),
|
|
17
|
+
requestedBy: publicId.optional(),
|
|
18
|
+
modelAccess: z.enum(["personal", "team"]).optional()
|
|
19
|
+
});
|
|
20
|
+
class SecretManagerCredentialResolver {
|
|
21
|
+
constructor(options) {
|
|
22
|
+
this.options = options;
|
|
23
|
+
const identity = identitySchema.safeParse(options.identity);
|
|
24
|
+
const endpoint = z.url().safeParse(options.team.baseUrl);
|
|
25
|
+
const url = endpoint.success ? new URL(endpoint.data) : void 0;
|
|
26
|
+
if (!identity.success || !publicId.safeParse(options.secretProject).success || !secretRefSchema.safeParse(options.team.secretRef).success || !options.team.secretRef.startsWith(`projects/${options.secretProject}/secrets/`) || !url || url.protocol !== "https:" || url.username || url.password || url.search || url.hash)
|
|
27
|
+
throw new Error("Invalid cloud model credential configuration");
|
|
28
|
+
this.identity = identity.data;
|
|
29
|
+
this.team = { ...options.team };
|
|
30
|
+
}
|
|
31
|
+
options;
|
|
32
|
+
identity;
|
|
33
|
+
team;
|
|
34
|
+
async resolve(request) {
|
|
35
|
+
if (request.access?.mode === "env")
|
|
36
|
+
throw new Error("Cloud credentials cannot be overridden by actor access");
|
|
37
|
+
if (request.purpose === "judge" || request.purpose === "reviewer" || request.purpose === "classifier" || request.purpose === "draft")
|
|
38
|
+
return this.resolveTeam("pi");
|
|
39
|
+
if (request.runtime === "codex")
|
|
40
|
+
throw new Error(
|
|
41
|
+
"ChatGPT subscription login is supported only on local-host; cloud Codex login is not supported"
|
|
42
|
+
);
|
|
43
|
+
const runtime = cloudRuntimeSchema.safeParse(request.runtime);
|
|
44
|
+
if (!runtime.success) throw new Error("Unsupported cloud model runtime");
|
|
45
|
+
const { trigger, createdBy, requestedBy, modelAccess } = this.identity;
|
|
46
|
+
if (trigger === "developer" && (!createdBy || createdBy !== requestedBy))
|
|
47
|
+
throw new Error("Personal run owner must match the authenticated developer");
|
|
48
|
+
if (trigger !== "developer" || modelAccess === "team") return this.resolveTeam(runtime.data);
|
|
49
|
+
let input;
|
|
50
|
+
try {
|
|
51
|
+
input = await this.options.credentials.get(createdBy, runtime.data);
|
|
52
|
+
} catch {
|
|
53
|
+
throw new Error("Cloud model credential lookup failed");
|
|
54
|
+
}
|
|
55
|
+
if (!input)
|
|
56
|
+
throw new Error(
|
|
57
|
+
"No personal model account linked; run auth connect or use --model-access team"
|
|
58
|
+
);
|
|
59
|
+
const link = parseCredentialReference(input);
|
|
60
|
+
if (link.userId !== createdBy || link.runtime !== runtime.data)
|
|
61
|
+
throw new Error("Model credential owner or runtime does not match the run");
|
|
62
|
+
assertPersonalReference(link, this.options.secretProject);
|
|
63
|
+
if (link.expiresAt !== null && link.expiresAt <= (this.options.now ?? Date.now)())
|
|
64
|
+
throw new Error("Personal model credential expired; run auth connect again");
|
|
65
|
+
const raw = await this.read(link.secretRef);
|
|
66
|
+
let payload;
|
|
67
|
+
try {
|
|
68
|
+
payload = JSON.parse(raw);
|
|
69
|
+
} catch {
|
|
70
|
+
throw new Error("Invalid personal model credential");
|
|
71
|
+
}
|
|
72
|
+
if (payload && typeof payload === "object" && "token" in payload && typeof payload.token === "string")
|
|
73
|
+
this.options.redactor.add([payload.token]);
|
|
74
|
+
const parsed = personalPayloadSchema.safeParse(payload);
|
|
75
|
+
if (!parsed.success || runtime.data === "claude-code" && parsed.data.kind === "openai-key" || runtime.data === "pi" && parsed.data.kind === "claude")
|
|
76
|
+
throw new Error("Invalid personal model credential");
|
|
77
|
+
const { kind, token } = parsed.data;
|
|
78
|
+
const key = kind === "claude" ? "CLAUDE_CODE_OAUTH_TOKEN" : kind === "anthropic-key" ? "ANTHROPIC_API_KEY" : "OPENAI_API_KEY";
|
|
79
|
+
return { mode: "env", env: { [key]: token } };
|
|
80
|
+
}
|
|
81
|
+
async resolveTeam(runtime) {
|
|
82
|
+
const token = await this.read(this.team.secretRef);
|
|
83
|
+
if (!tokenSchema.safeParse(token).success) throw new Error("Invalid team model credential");
|
|
84
|
+
return {
|
|
85
|
+
mode: "env",
|
|
86
|
+
env: runtime === "claude-code" ? { ANTHROPIC_AUTH_TOKEN: token, ANTHROPIC_BASE_URL: this.team.baseUrl } : { OPENAI_API_KEY: token, OPENAI_BASE_URL: this.team.baseUrl }
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
async read(secretRef) {
|
|
90
|
+
let value;
|
|
91
|
+
try {
|
|
92
|
+
value = await this.options.secrets.access(secretRef);
|
|
93
|
+
} catch {
|
|
94
|
+
throw new Error("Cloud model credential resolution failed");
|
|
95
|
+
}
|
|
96
|
+
this.options.redactor.add([value]);
|
|
97
|
+
return value;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export {
|
|
101
|
+
SecretManagerCredentialResolver
|
|
102
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SecretRedactor } from "@open-qa/qa-engine";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export declare const artifactScanSchema: z.ZodObject<{
|
|
4
|
+
status: z.ZodEnum<{
|
|
5
|
+
passed: "passed";
|
|
6
|
+
"secret-leak": "secret-leak";
|
|
7
|
+
}>;
|
|
8
|
+
files: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
9
|
+
findings: z.ZodArray<z.ZodObject<{
|
|
10
|
+
file: z.ZodString;
|
|
11
|
+
reason: z.ZodEnum<{
|
|
12
|
+
"known-secret": "known-secret";
|
|
13
|
+
unscannable: "unscannable";
|
|
14
|
+
}>;
|
|
15
|
+
}, z.core.$strip>>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
export type ArtifactScan = z.infer<typeof artifactScanSchema>;
|
|
18
|
+
/** A fail-closed publication check, including unreferenced files and decoded rrweb chunks.
|
|
19
|
+
* Keep the registry in memory: receipts contain hashes and safe diagnostics, never secrets.
|
|
20
|
+
*/
|
|
21
|
+
export declare function scanRunArtifacts(root: string, runId: string, redactor: SecretRedactor): Promise<ArtifactScan>;
|