@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,138 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
import {
|
|
4
|
+
classifyFailure,
|
|
5
|
+
readExecutionSnapshot
|
|
6
|
+
} from "@open-qa/qa-engine";
|
|
7
|
+
import { scopedClassificationDiff } from "./classification-diff.js";
|
|
8
|
+
const execute = promisify(execFile);
|
|
9
|
+
async function lastPassedDiff(options) {
|
|
10
|
+
const unavailable = (reason) => {
|
|
11
|
+
options.onUnavailable?.(reason);
|
|
12
|
+
return null;
|
|
13
|
+
};
|
|
14
|
+
try {
|
|
15
|
+
if (!options.sourceFiles?.length)
|
|
16
|
+
return unavailable("No trusted classifier.sourceFiles configured");
|
|
17
|
+
const current = (await execute("git", ["rev-parse", "HEAD"], { cwd: options.root, timeout: 3e3 })).stdout.trim();
|
|
18
|
+
if (!/^[a-f0-9]{40,64}$/.test(current) || options.revision && current !== options.revision)
|
|
19
|
+
return unavailable("Checkout HEAD does not match the declared target revision");
|
|
20
|
+
if ((await execute("git", ["status", "--porcelain"], { cwd: options.root, timeout: 3e3 })).stdout.trim())
|
|
21
|
+
return unavailable("Checkout is dirty; classification requires committed source files");
|
|
22
|
+
const baseline = (await options.runs.listRuns(1e3)).find((run) => {
|
|
23
|
+
const snapshot2 = readExecutionSnapshot(run.run.metadata?.executionSnapshot);
|
|
24
|
+
return run.run.flow === options.flow && run.result?.verdict === "passed" && snapshot2.status === "recorded" && snapshot2.snapshot.target.origin === new URL(options.target).origin;
|
|
25
|
+
});
|
|
26
|
+
const snapshot = readExecutionSnapshot(baseline?.run.metadata?.executionSnapshot);
|
|
27
|
+
if (snapshot.status !== "recorded")
|
|
28
|
+
return unavailable(
|
|
29
|
+
"No passed baseline with a recorded snapshot for this flow and target origin in run history"
|
|
30
|
+
);
|
|
31
|
+
const targetRevision = snapshot.snapshot.schemaVersion !== 1 ? snapshot.snapshot.target.revision : void 0;
|
|
32
|
+
if (!targetRevision && snapshot.snapshot.versions.dirty !== false)
|
|
33
|
+
return unavailable(
|
|
34
|
+
"Passed baseline has no verified target revision or clean checkout commit"
|
|
35
|
+
);
|
|
36
|
+
const commit = targetRevision ?? snapshot.snapshot.versions.commit;
|
|
37
|
+
if (!commit || !/^[a-f0-9]{40,64}$/.test(commit))
|
|
38
|
+
return unavailable("Passed baseline has no immutable Git revision");
|
|
39
|
+
const diff = await scopedClassificationDiff({ ...options, baseline: commit, current });
|
|
40
|
+
return diff ?? unavailable(
|
|
41
|
+
"Source diff is empty, unsafe, oversized or unavailable; check sourceFiles and both Git revisions"
|
|
42
|
+
);
|
|
43
|
+
} catch {
|
|
44
|
+
return unavailable(
|
|
45
|
+
"Git or run history unavailable; verify checkout and persistent history access"
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
class ClassifyingRuns {
|
|
50
|
+
constructor(options) {
|
|
51
|
+
this.options = options;
|
|
52
|
+
this.store = {
|
|
53
|
+
createRun: async (run) => {
|
|
54
|
+
await options.store.createRun(run);
|
|
55
|
+
let revision = null;
|
|
56
|
+
try {
|
|
57
|
+
revision = await options.targetRevision?.() ?? null;
|
|
58
|
+
} catch {
|
|
59
|
+
}
|
|
60
|
+
this.attempts.set(run.id, { started: false, reviews: [], incomplete: false, revision });
|
|
61
|
+
},
|
|
62
|
+
appendEvents: async (id, events) => {
|
|
63
|
+
await options.store.appendEvents(id, events);
|
|
64
|
+
const evidence = this.attempts.get(id);
|
|
65
|
+
if (!evidence) return;
|
|
66
|
+
for (const event of events) {
|
|
67
|
+
if (event.by === "conductor" && event.kind === "run_phase" && event.phase === "running")
|
|
68
|
+
evidence.started = true;
|
|
69
|
+
if (event.by === "conductor" && event.kind === "reviewer_result") {
|
|
70
|
+
if (evidence.reviews.length < 128) evidence.reviews.push(event.result);
|
|
71
|
+
else evidence.incomplete = true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
finishRun: (id, result) => options.store.finishRun(id, result)
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
options;
|
|
79
|
+
store;
|
|
80
|
+
attempts = /* @__PURE__ */ new Map();
|
|
81
|
+
async finish(flow, result, signal) {
|
|
82
|
+
try {
|
|
83
|
+
let diff;
|
|
84
|
+
for (const [index, run] of result.runs.entries()) {
|
|
85
|
+
if (run.verdict !== "failed" && run.verdict !== "error") continue;
|
|
86
|
+
const evidence = this.attempts.get(run.runId);
|
|
87
|
+
const retry = result.runs[index + 1];
|
|
88
|
+
const retryEvidence = retry && this.attempts.get(retry.runId);
|
|
89
|
+
const context = {
|
|
90
|
+
verdict: run.verdict,
|
|
91
|
+
errorReason: run.errorReason,
|
|
92
|
+
infrastructureFailure: !!run.infrastructureFailure || !evidence?.started,
|
|
93
|
+
sameVersionRetryPassed: !!(retry?.retryOf === run.runId && retry.verdict === "passed" && evidence?.revision && evidence.revision === retryEvidence?.revision),
|
|
94
|
+
reviews: evidence?.incomplete ? [] : evidence?.reviews ?? [],
|
|
95
|
+
gitDiff: null,
|
|
96
|
+
failure: JSON.stringify({ reason: run.reason, reviews: evidence?.reviews })
|
|
97
|
+
};
|
|
98
|
+
let classification = await classifyFailure(context, this.options.classifier, signal);
|
|
99
|
+
if (classification.source === "fallback") {
|
|
100
|
+
if (diff === void 0) diff = await this.options.diff(flow);
|
|
101
|
+
classification = await classifyFailure(
|
|
102
|
+
{
|
|
103
|
+
...context,
|
|
104
|
+
gitDiff: typeof diff === "object" && diff !== null ? diff.gitDiff : diff,
|
|
105
|
+
...typeof diff === "object" && diff !== null && { gitDiffUnavailableReason: diff.reason }
|
|
106
|
+
},
|
|
107
|
+
this.options.classifier,
|
|
108
|
+
signal
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
classification = {
|
|
112
|
+
...classification,
|
|
113
|
+
reason: this.options.redactor.text(classification.reason)
|
|
114
|
+
};
|
|
115
|
+
await this.options.classifications.saveClassification(run.runId, classification);
|
|
116
|
+
const effective = await this.options.classifications.getClassification(run.runId);
|
|
117
|
+
if (effective?.classification?.source !== "human") {
|
|
118
|
+
try {
|
|
119
|
+
await this.options.onClassified?.(
|
|
120
|
+
run.runId,
|
|
121
|
+
classification,
|
|
122
|
+
run.verdict,
|
|
123
|
+
run.errorReason
|
|
124
|
+
);
|
|
125
|
+
} catch {
|
|
126
|
+
console.warn("Classification notification failed; the classification is saved");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
} finally {
|
|
131
|
+
this.attempts.clear();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
export {
|
|
136
|
+
ClassifyingRuns,
|
|
137
|
+
lastPassedDiff
|
|
138
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import type { runCommand } from "./run-command.js";
|
|
3
|
+
import type { remoteRunCommand, authCommand } from "./remote-command.js";
|
|
4
|
+
export declare function createCli(overrides?: {
|
|
5
|
+
draft?: typeof import("./draft-command.js").draftCommand;
|
|
6
|
+
run?: typeof runCommand;
|
|
7
|
+
remoteRun?: typeof remoteRunCommand;
|
|
8
|
+
auth?: typeof authCommand;
|
|
9
|
+
}): Command;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import pkg from "../package.json" with { type: "json" };
|
|
3
|
+
function createCli(overrides = {}) {
|
|
4
|
+
const cli = new Command().name(Object.keys(pkg.bin)[0] ?? "open-qa").description("open-qa CLI").version(pkg.version).exitOverride();
|
|
5
|
+
for (const name of ["validate", "lint"]) {
|
|
6
|
+
const command = cli.command(`${name} [path]`).description(
|
|
7
|
+
name === "validate" ? "Parse and compile .qa flows without executing them" : "Check flow writing rules"
|
|
8
|
+
).option("--root <directory>", ".qa configuration directory");
|
|
9
|
+
if (name === "lint") command.option("--strict", "Fail when lint warnings are found");
|
|
10
|
+
command.action(async (path = ".qa", options) => {
|
|
11
|
+
try {
|
|
12
|
+
const { tsImport } = await import("tsx/esm/api");
|
|
13
|
+
const { checkFlows } = await tsImport(
|
|
14
|
+
"./flow-check.js",
|
|
15
|
+
import.meta.url
|
|
16
|
+
);
|
|
17
|
+
const result = await checkFlows(path, { ...options, lint: name === "lint" });
|
|
18
|
+
for (const diagnostic of result.diagnostics) console.error(diagnostic);
|
|
19
|
+
console.log(result.summary);
|
|
20
|
+
process.exitCode = result.failed ? 1 : 0;
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.error(
|
|
23
|
+
error instanceof Error && "code" in error && error.code === "ENOENT" && "path" in error ? `not found: ${error.path}` : error instanceof Error ? error.message : "Flow validation failed"
|
|
24
|
+
);
|
|
25
|
+
process.exitCode = 1;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
cli.command("draft").description("Generate a reviewed-later flow draft from issue acceptance criteria").requiredOption("--issue <number>", "GitHub issue number").requiredOption("--model <model>", "Team Pi model identifier").option("--root <directory>", "QA directory containing qa.md", ".qa").option("--suite <directory>", "Existing suite path relative to root", ".").option("--repo <owner/name>", "GitHub repository (gh defaults to current repository)").option("--no-screenshots", "Omit local stage page screenshots").option(
|
|
30
|
+
"--timeout <milliseconds>",
|
|
31
|
+
"Input/model deadline for all attempts; publication gets a separate 30 seconds",
|
|
32
|
+
"600000"
|
|
33
|
+
).action(async (options) => {
|
|
34
|
+
const { tsImport } = await import("tsx/esm/api");
|
|
35
|
+
const command = overrides.draft ?? (await tsImport(
|
|
36
|
+
"./draft-command.js",
|
|
37
|
+
import.meta.url
|
|
38
|
+
)).draftCommand;
|
|
39
|
+
process.exitCode = await command(options);
|
|
40
|
+
});
|
|
41
|
+
cli.command("run <path>").option("--accept-estimate", "Accept historical cost estimates above confirmation thresholds").description("Run a flow or suite directory").option("--root <directory>", ".qa configuration directory").option("--target <name>", "Target from config.yaml", "local").option("--runtime <runtime>", "Agent runtime (claude-code|codex)", "claude-code").option("--model-access <mode>", "Local login/env (default login) or remote personal/team").option("--agent-at <placement>", "Agent placement (host|stage); CLI defaults to host").option("--remote", "Queue a published flow ID on qa-server").option("--server <url>", "QA server URL").option("--project <id>", "QA project ID").option("--idempotency-key <key>", "Reuse this key when retrying a remote submission").option("--executor <placement>", "Stage placement (local-host|e2b)", "local-host").option("--headed", "Show the browser").option(
|
|
42
|
+
"--replay <mode>",
|
|
43
|
+
"Disable reading cached steps (off); successful agent steps still update the cache"
|
|
44
|
+
).option("--level <level>", "Override every step to pixel").option("--persona <name>", "Override every user actor persona").option("--tag <tag>", "Select flows containing this tag").option("--retries <count>", "Retry a failed flow (0 or 1)", "1").option("--repeat <count>", "Repeat one flow in fresh stages and leases (1-100)").action(async (path, options) => {
|
|
45
|
+
if (options.remote) {
|
|
46
|
+
if (options.repeat !== void 0)
|
|
47
|
+
throw new Error("--repeat requires local execution; --remote only queues a batch");
|
|
48
|
+
if (options.executor !== "local-host")
|
|
49
|
+
throw new Error("--executor cannot be combined with --remote");
|
|
50
|
+
const remoteRun = overrides.remoteRun ?? (await commands()).remoteRunCommand;
|
|
51
|
+
process.exitCode = await remoteRun(path, { ...options, retries: Number(options.retries) });
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const { runCommand } = await commands();
|
|
55
|
+
process.exitCode = await (overrides.run ?? runCommand)(path, {
|
|
56
|
+
...options,
|
|
57
|
+
retries: Number(options.retries),
|
|
58
|
+
...options.repeat !== void 0 ? { repeat: Number(options.repeat) } : {}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
cli.command("setup").description("Install Chromium and create a private local QA environment").option("--root <directory>", ".qa configuration directory").option("--env-file <file>", "Import an existing QA credential inventory into a new .env.local").action(async (options) => {
|
|
62
|
+
process.exitCode = await (await commands()).setupCommand(options);
|
|
63
|
+
});
|
|
64
|
+
cli.command("doctor").description("Check runtime, subscription, browser, target and configured accounts").option("--save", "Save a safe diagnostic summary for Studio").option("--root <directory>", ".qa configuration directory").option("--target <name>", "Target from config.yaml", "local").action(async (options) => {
|
|
65
|
+
process.exitCode = await (await commands()).doctorCommand(options);
|
|
66
|
+
});
|
|
67
|
+
cli.command("open <run>").description("Open a run report or its directory while the report is pending").option("--root <directory>", ".qa configuration directory").action(async (id, options) => {
|
|
68
|
+
process.exitCode = await (await commands()).openCommand(id, options);
|
|
69
|
+
});
|
|
70
|
+
cli.command("watch <run>").description("Stream run events and print the private E2B screen URL while active").option("--root <directory>", ".qa configuration directory").option("--remote", "Watch a qa-server run").option("--server <url>", "QA server URL").option("--project <id>", "QA project ID").option("--after <sequence>", "Resume after this event sequence", "0").action(async (id, options) => {
|
|
71
|
+
process.exitCode = await (await commands()).watchCommand(id, options);
|
|
72
|
+
});
|
|
73
|
+
cli.command("demo-data <directory>").description("Create synthetic Studio demo runs without models or cloud calls").action(async (directory) => {
|
|
74
|
+
await (await commands()).demoCommand(directory);
|
|
75
|
+
});
|
|
76
|
+
cli.command("studio").description("Open the local QA Studio").option("--root <directory>", ".qa configuration directory").option("--port <port>", "Loopback port (automatically selected by default)").option("--allow-run", "Allow confirmed local flow runs for this launcher session").option("--ready-timeout <milliseconds>", "Ready handshake timeout", "30000").option("--no-open", "Print the URL without opening a browser (default)").action(async (options) => {
|
|
77
|
+
const { studioCommand } = await import("./studio-command.js");
|
|
78
|
+
process.exitCode = await studioCommand(options);
|
|
79
|
+
});
|
|
80
|
+
const auth = cli.command("auth").description("Manage personal remote model credentials");
|
|
81
|
+
for (const action of ["connect", "status", "revoke"]) {
|
|
82
|
+
auth.command(action === "status" ? "status" : `${action} <kind>`).option("--server <url>", "QA server URL").option("--project <id>", "QA project ID").option("--runtime <runtime>", "Credential runtime (claude-code|pi)").option("--expires-at <timestamp>", "Credential expiry in ISO format").action(async (...args) => {
|
|
83
|
+
const kind = action === "status" ? void 0 : args[0];
|
|
84
|
+
const options = args[action === "status" ? 0 : 1];
|
|
85
|
+
const runAuth = overrides.auth ?? (await commands()).authCommand;
|
|
86
|
+
process.exitCode = await runAuth(action, kind, options);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
const quarantine = cli.command("quarantine").description("Manage PostgreSQL flow quarantine");
|
|
90
|
+
for (const action of ["list", "release"]) {
|
|
91
|
+
quarantine.command(action === "release" ? "release <flow>" : "list").option("--root <directory>", ".qa configuration directory").option("--project <id>", "QA project ID (or QA_PROJECT_ID)").action(async (...args) => {
|
|
92
|
+
const { tsImport } = await import("tsx/esm/api");
|
|
93
|
+
const { quarantineCommand } = await tsImport(
|
|
94
|
+
"./quarantine-command.js",
|
|
95
|
+
import.meta.url
|
|
96
|
+
);
|
|
97
|
+
process.exitCode = await quarantineCommand(
|
|
98
|
+
action,
|
|
99
|
+
action === "release" ? String(args[0]) : void 0,
|
|
100
|
+
args[action === "release" ? 1 : 0]
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
for (const action of ["accept", "retire"]) {
|
|
105
|
+
const command = cli.command(action === "accept" ? "accept [flow]" : "retire <flow>").description(
|
|
106
|
+
action === "accept" ? "Make a reviewed flow active after watching its first run" : "Retire an active or quarantined flow so it never runs again"
|
|
107
|
+
).option("--root <directory>", ".qa configuration directory").option("--project <id>", "QA project ID (or QA_PROJECT_ID)").option("--by <name>", "Name recorded with the decision (default: OS user)");
|
|
108
|
+
if (action === "accept")
|
|
109
|
+
command.option(
|
|
110
|
+
"--baseline <directory>",
|
|
111
|
+
"Adopt existing flows without a lifecycle state as active, once"
|
|
112
|
+
).option("--yes", "Skip confirmation for --baseline; accepting one flow always asks");
|
|
113
|
+
else command.option("--yes", "Skip confirmation");
|
|
114
|
+
command.action(async (flow, options) => {
|
|
115
|
+
const { tsImport } = await import("tsx/esm/api");
|
|
116
|
+
const { lifecycleCommand } = await tsImport(
|
|
117
|
+
"./lifecycle-command.js",
|
|
118
|
+
import.meta.url
|
|
119
|
+
);
|
|
120
|
+
process.exitCode = await lifecycleCommand(action, flow, options);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
const cache = cli.command("cache").description("Review healed replay cache versions");
|
|
124
|
+
for (const action of ["pending", "approve", "reject", "serve"]) {
|
|
125
|
+
const command = cache.command(action === "approve" || action === "reject" ? `${action} <id>` : action).option("--root <directory>", ".qa cache directory");
|
|
126
|
+
if (action === "serve") command.option("--port <port>", "Loopback API port");
|
|
127
|
+
command.action(async (...args) => {
|
|
128
|
+
const { tsImport } = await import("tsx/esm/api");
|
|
129
|
+
const { cacheCommand } = await tsImport(
|
|
130
|
+
"./cache-command.js",
|
|
131
|
+
import.meta.url
|
|
132
|
+
);
|
|
133
|
+
const options = args[action === "approve" || action === "reject" ? 1 : 0];
|
|
134
|
+
process.exitCode = await cacheCommand(action, {
|
|
135
|
+
...options,
|
|
136
|
+
...(action === "approve" || action === "reject") && { id: String(args[0]) }
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
cli.command("classify <run> <category>").description("Record a human failure classification with an audit reason").requiredOption("--reason <reason>", "Reason for correcting the classification").option("--root <directory>", ".qa directory").option("--remote", "Correct a remote run").option("--server <url>", "QA server URL").option("--project <id>", "QA project ID").action(async (run, category, options) => {
|
|
141
|
+
const { tsImport } = await import("tsx/esm/api");
|
|
142
|
+
const { classifyCommand } = await tsImport(
|
|
143
|
+
"./classification-command.js",
|
|
144
|
+
import.meta.url
|
|
145
|
+
);
|
|
146
|
+
process.exitCode = await classifyCommand(run, category, options);
|
|
147
|
+
});
|
|
148
|
+
cli.command("classification-eval <labels>").description("Evaluate original predictions against independently labeled runs").option("--root <directory>", ".qa directory").action(async (labels, options) => {
|
|
149
|
+
const { tsImport } = await import("tsx/esm/api");
|
|
150
|
+
const { classificationEvalCommand } = await tsImport(
|
|
151
|
+
"./classification-command.js",
|
|
152
|
+
import.meta.url
|
|
153
|
+
);
|
|
154
|
+
process.exitCode = await classificationEvalCommand(labels, options);
|
|
155
|
+
});
|
|
156
|
+
cli.command("sandboxes").description("Manage QA-owned E2B sandboxes").command("prune").description("Terminate QA sandboxes for confirmed finished runs in this project").option("--root <directory>", ".qa configuration directory").option("--dry-run", "List cleanup counts without terminating sandboxes").action(async (options) => {
|
|
157
|
+
const { tsImport } = await import("tsx/esm/api");
|
|
158
|
+
const { sandboxesPruneCommand } = await tsImport(
|
|
159
|
+
"./sandboxes-command.js",
|
|
160
|
+
import.meta.url
|
|
161
|
+
);
|
|
162
|
+
process.exitCode = await sandboxesPruneCommand(options);
|
|
163
|
+
});
|
|
164
|
+
return cli;
|
|
165
|
+
}
|
|
166
|
+
async function commands() {
|
|
167
|
+
const { tsImport } = await import("tsx/esm/api");
|
|
168
|
+
return await tsImport("./commands.js", import.meta.url);
|
|
169
|
+
}
|
|
170
|
+
export {
|
|
171
|
+
createCli
|
|
172
|
+
};
|
package/src/cli.d.ts
ADDED
package/src/cli.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { CommanderError } from "commander";
|
|
3
|
+
import { createCli } from "./cli-program.js";
|
|
4
|
+
try {
|
|
5
|
+
await createCli().parseAsync();
|
|
6
|
+
} catch (error) {
|
|
7
|
+
if (error instanceof CommanderError) process.exitCode = error.exitCode === 0 ? 0 : 2;
|
|
8
|
+
else {
|
|
9
|
+
console.error(error instanceof Error ? error.message : "QA command failed");
|
|
10
|
+
process.exitCode = 2;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { runCommand } from "./run-command.js";
|
|
2
|
+
export { setupCommand } from "./setup-command.js";
|
|
3
|
+
export { doctorCommand } from "./doctor-command.js";
|
|
4
|
+
export { openCommand } from "./open-command.js";
|
|
5
|
+
export { remoteRunCommand, authCommand } from "./remote-command.js";
|
|
6
|
+
export { watchCommand } from "./watch-command.js";
|
|
7
|
+
export { demoCommand } from "./demo-command.js";
|
package/src/commands.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { runCommand } from "./run-command.js";
|
|
2
|
+
import { setupCommand } from "./setup-command.js";
|
|
3
|
+
import { doctorCommand } from "./doctor-command.js";
|
|
4
|
+
import { openCommand } from "./open-command.js";
|
|
5
|
+
import { remoteRunCommand, authCommand } from "./remote-command.js";
|
|
6
|
+
import { watchCommand } from "./watch-command.js";
|
|
7
|
+
import { demoCommand } from "./demo-command.js";
|
|
8
|
+
export {
|
|
9
|
+
authCommand,
|
|
10
|
+
demoCommand,
|
|
11
|
+
doctorCommand,
|
|
12
|
+
openCommand,
|
|
13
|
+
remoteRunCommand,
|
|
14
|
+
runCommand,
|
|
15
|
+
setupCommand,
|
|
16
|
+
watchCommand
|
|
17
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const cloudRuntimeSchema: z.ZodEnum<{
|
|
3
|
+
"claude-code": "claude-code";
|
|
4
|
+
pi: "pi";
|
|
5
|
+
}>;
|
|
6
|
+
export type CloudRuntime = z.infer<typeof cloudRuntimeSchema>;
|
|
7
|
+
export declare const secretRefSchema: z.ZodString;
|
|
8
|
+
declare const credentialReferenceSchema: z.ZodObject<{
|
|
9
|
+
userId: z.ZodString;
|
|
10
|
+
runtime: z.ZodEnum<{
|
|
11
|
+
"claude-code": "claude-code";
|
|
12
|
+
pi: "pi";
|
|
13
|
+
}>;
|
|
14
|
+
secretRef: z.ZodString;
|
|
15
|
+
expiresAt: z.ZodNullable<z.ZodNumber>;
|
|
16
|
+
}, z.core.$strict>;
|
|
17
|
+
export type CredentialReference = z.infer<typeof credentialReferenceSchema>;
|
|
18
|
+
export interface CredentialReferences {
|
|
19
|
+
get(userId: string, runtime: CloudRuntime): Promise<CredentialReference | undefined>;
|
|
20
|
+
}
|
|
21
|
+
export declare function parseCredentialReference(input: unknown): CredentialReference;
|
|
22
|
+
export declare function personalSecretName(project: string, userId: string, runtime: CloudRuntime): string;
|
|
23
|
+
export declare function assertPersonalReference(link: CredentialReference, project: string): void;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { publicId } from "./public-id.js";
|
|
3
|
+
const cloudRuntimeSchema = z.enum(["claude-code", "pi"]);
|
|
4
|
+
const secretRefSchema = z.string().regex(/^projects\/[a-zA-Z0-9_-]+\/secrets\/[a-zA-Z0-9_-]+\/versions\/(latest|[1-9][0-9]*)$/);
|
|
5
|
+
const credentialReferenceSchema = z.strictObject({
|
|
6
|
+
userId: publicId,
|
|
7
|
+
runtime: cloudRuntimeSchema,
|
|
8
|
+
secretRef: secretRefSchema,
|
|
9
|
+
expiresAt: z.number().int().nonnegative().max(864e13).nullable()
|
|
10
|
+
});
|
|
11
|
+
function parseCredentialReference(input) {
|
|
12
|
+
const parsed = credentialReferenceSchema.safeParse(input);
|
|
13
|
+
if (!parsed.success) throw new Error("Invalid model credential reference");
|
|
14
|
+
return parsed.data;
|
|
15
|
+
}
|
|
16
|
+
function personalSecretName(project, userId, runtime) {
|
|
17
|
+
if (!publicId.safeParse(project).success || !publicId.safeParse(userId).success || !cloudRuntimeSchema.safeParse(runtime).success)
|
|
18
|
+
throw new Error("Invalid model credential identity");
|
|
19
|
+
return `projects/${project}/secrets/qa-user-${userId}-${runtime}`;
|
|
20
|
+
}
|
|
21
|
+
function assertPersonalReference(link, project) {
|
|
22
|
+
if (!link.secretRef.startsWith(
|
|
23
|
+
`${personalSecretName(project, link.userId, link.runtime)}/versions/`
|
|
24
|
+
))
|
|
25
|
+
throw new Error("Model credential reference does not match its owner and runtime");
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
assertPersonalReference,
|
|
29
|
+
cloudRuntimeSchema,
|
|
30
|
+
parseCredentialReference,
|
|
31
|
+
personalSecretName,
|
|
32
|
+
secretRefSchema
|
|
33
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { QaDatabase, migrateQa } from "./database.js";
|
|
3
|
+
import { importResources } from "./resources.js";
|
|
4
|
+
async function main() {
|
|
5
|
+
const url = process.env.QA_DATABASE_URL;
|
|
6
|
+
if (!url) throw new Error("Set QA_DATABASE_URL before running database commands");
|
|
7
|
+
const db = new QaDatabase(url, process.argv[2] === "migrate" ? { statement_timeout: 0 } : {});
|
|
8
|
+
try {
|
|
9
|
+
if (process.argv[2] === "migrate") {
|
|
10
|
+
await migrateQa(db);
|
|
11
|
+
console.log("QA PostgreSQL migrations applied");
|
|
12
|
+
} else if (process.argv[2] === "import-resources") {
|
|
13
|
+
const project = process.env.QA_PROJECT_ID;
|
|
14
|
+
const file = process.argv[3];
|
|
15
|
+
if (!project || !file) throw new Error("Set QA_PROJECT_ID and pass a resource manifest path");
|
|
16
|
+
let manifest;
|
|
17
|
+
try {
|
|
18
|
+
manifest = JSON.parse(await readFile(file, "utf8"));
|
|
19
|
+
} catch {
|
|
20
|
+
throw new Error("Could not read resource manifest JSON");
|
|
21
|
+
}
|
|
22
|
+
const count = await importResources(db, project, manifest);
|
|
23
|
+
console.log(`Imported ${count} QA resource references`);
|
|
24
|
+
} else throw new Error("Expected migrate or import-resources");
|
|
25
|
+
} finally {
|
|
26
|
+
await db.close();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
main().catch(() => {
|
|
30
|
+
console.error(
|
|
31
|
+
"QA database command failed. Check QA_DATABASE_URL, connectivity, migrations and the resource manifest; see apps/qa/docs/postgresql.md"
|
|
32
|
+
);
|
|
33
|
+
process.exitCode = 1;
|
|
34
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { QaDatabase } from "./database.js";
|
|
2
|
+
import { type CloudRuntime, type CredentialReference, type CredentialReferences } from "../credential-references.js";
|
|
3
|
+
export declare class PgCredentialStore implements CredentialReferences {
|
|
4
|
+
private readonly db;
|
|
5
|
+
private readonly project;
|
|
6
|
+
private readonly secretProject;
|
|
7
|
+
constructor(db: {
|
|
8
|
+
pool: Pick<QaDatabase["pool"], "query">;
|
|
9
|
+
}, project: string, secretProject: string);
|
|
10
|
+
private identity;
|
|
11
|
+
get(userId: string, runtime: CloudRuntime): Promise<CredentialReference | undefined>;
|
|
12
|
+
list(userId: string): Promise<CredentialReference[]>;
|
|
13
|
+
put(input: unknown): Promise<void>;
|
|
14
|
+
remove(userId: string, runtime: CloudRuntime): Promise<void>;
|
|
15
|
+
private parse;
|
|
16
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { publicId } from "../public-id.js";
|
|
2
|
+
import {
|
|
3
|
+
assertPersonalReference,
|
|
4
|
+
cloudRuntimeSchema,
|
|
5
|
+
parseCredentialReference
|
|
6
|
+
} from "../credential-references.js";
|
|
7
|
+
class PgCredentialStore {
|
|
8
|
+
// The existing provider key stores the runtime ID: reconnecting a different
|
|
9
|
+
// credential kind replaces that user's runtime link instead of adding one.
|
|
10
|
+
constructor(db, project, secretProject) {
|
|
11
|
+
this.db = db;
|
|
12
|
+
this.project = project;
|
|
13
|
+
this.secretProject = secretProject;
|
|
14
|
+
if (!publicId.safeParse(project).success || !publicId.safeParse(secretProject).success)
|
|
15
|
+
throw new Error("Invalid model credential project");
|
|
16
|
+
}
|
|
17
|
+
db;
|
|
18
|
+
project;
|
|
19
|
+
secretProject;
|
|
20
|
+
identity(userId, runtime) {
|
|
21
|
+
if (!publicId.safeParse(userId).success || runtime !== void 0 && !cloudRuntimeSchema.safeParse(runtime).success)
|
|
22
|
+
throw new Error("Invalid model credential identity");
|
|
23
|
+
}
|
|
24
|
+
async get(userId, runtime) {
|
|
25
|
+
this.identity(userId, runtime);
|
|
26
|
+
const { rows } = await this.db.pool.query(
|
|
27
|
+
`SELECT user_id AS "userId",provider AS runtime,secret_ref AS "secretRef",
|
|
28
|
+
floor(extract(epoch FROM expires_at)*1000)::double precision AS "expiresAt"
|
|
29
|
+
FROM qa.credentials WHERE project_id=$1 AND user_id=$2 AND provider=$3`,
|
|
30
|
+
[this.project, userId, runtime]
|
|
31
|
+
);
|
|
32
|
+
return rows[0] ? this.parse(rows[0]) : void 0;
|
|
33
|
+
}
|
|
34
|
+
async list(userId) {
|
|
35
|
+
this.identity(userId);
|
|
36
|
+
const { rows } = await this.db.pool.query(
|
|
37
|
+
`SELECT user_id AS "userId",provider AS runtime,secret_ref AS "secretRef",
|
|
38
|
+
floor(extract(epoch FROM expires_at)*1000)::double precision AS "expiresAt"
|
|
39
|
+
FROM qa.credentials WHERE project_id=$1 AND user_id=$2 ORDER BY provider`,
|
|
40
|
+
[this.project, userId]
|
|
41
|
+
);
|
|
42
|
+
return rows.map((row) => this.parse(row));
|
|
43
|
+
}
|
|
44
|
+
async put(input) {
|
|
45
|
+
const link = this.parse(input);
|
|
46
|
+
await this.db.pool.query(
|
|
47
|
+
`INSERT INTO qa.credentials(project_id,user_id,provider,secret_ref,expires_at) VALUES($1,$2,$3,$4,$5)
|
|
48
|
+
ON CONFLICT(project_id,user_id,provider) DO UPDATE SET secret_ref=EXCLUDED.secret_ref,expires_at=EXCLUDED.expires_at`,
|
|
49
|
+
[
|
|
50
|
+
this.project,
|
|
51
|
+
link.userId,
|
|
52
|
+
link.runtime,
|
|
53
|
+
link.secretRef,
|
|
54
|
+
link.expiresAt === null ? null : new Date(link.expiresAt)
|
|
55
|
+
]
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
async remove(userId, runtime) {
|
|
59
|
+
this.identity(userId, runtime);
|
|
60
|
+
await this.db.pool.query(
|
|
61
|
+
"DELETE FROM qa.credentials WHERE project_id=$1 AND user_id=$2 AND provider=$3",
|
|
62
|
+
[this.project, userId, runtime]
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
parse(input) {
|
|
66
|
+
const link = parseCredentialReference(input);
|
|
67
|
+
assertPersonalReference(link, this.secretProject);
|
|
68
|
+
return link;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export {
|
|
72
|
+
PgCredentialStore
|
|
73
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Pool, type PoolClient, type PoolConfig } from "pg";
|
|
2
|
+
export { publicId } from "../public-id.js";
|
|
3
|
+
export declare function assertPostgresText(value: unknown): void;
|
|
4
|
+
export type QaDatabaseOptions = Pick<PoolConfig, "max" | "ssl" | "statement_timeout" | "idle_in_transaction_session_timeout">;
|
|
5
|
+
export declare class QaDatabase {
|
|
6
|
+
readonly pool: Pool;
|
|
7
|
+
constructor(url: string, options?: QaDatabaseOptions);
|
|
8
|
+
transaction<T>(operation: (client: PoolClient) => Promise<T>): Promise<T>;
|
|
9
|
+
close(): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export declare const migrationsFolder: string;
|
|
12
|
+
export declare function migrateQa(db: QaDatabase, folder?: string): Promise<void>;
|