@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,42 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { qaId } from "./e2b-executor.js";
|
|
3
|
+
import { e2bOperation } from "./e2b-client.js";
|
|
4
|
+
const ownership = z.object({
|
|
5
|
+
owner: z.literal("open-qa"),
|
|
6
|
+
schema: z.literal("2"),
|
|
7
|
+
projectId: qaId,
|
|
8
|
+
runId: qaId,
|
|
9
|
+
batchId: qaId,
|
|
10
|
+
template: z.string().regex(/^open-qa-stage-[sml]:[a-f0-9]{20}$/),
|
|
11
|
+
expiresAt: z.string().regex(/^\d{1,16}$/).transform(Number).pipe(z.number().int().positive().safe())
|
|
12
|
+
});
|
|
13
|
+
async function pruneQaSandboxes(options) {
|
|
14
|
+
if (!qaId.safeParse(options.projectId).success) throw new Error("Invalid QA project ID");
|
|
15
|
+
const result = { inspected: 0, eligible: 0, killed: 0, skipped: 0, failed: 0 };
|
|
16
|
+
for await (const sandbox of options.client.list(options.projectId)) {
|
|
17
|
+
result.inspected++;
|
|
18
|
+
const parsed = ownership.safeParse(sandbox.metadata);
|
|
19
|
+
if (!parsed.success || parsed.data.projectId !== options.projectId || !qaId.safeParse(sandbox.id).success) {
|
|
20
|
+
result.skipped++;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const meta = parsed.data;
|
|
24
|
+
try {
|
|
25
|
+
if (!await options.isFinished(meta.runId, meta.batchId)) {
|
|
26
|
+
result.skipped++;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
result.eligible++;
|
|
30
|
+
if (!options.dryRun) {
|
|
31
|
+
await e2bOperation("QA_E2B_KILL_FAILED", () => options.client.kill(sandbox.id));
|
|
32
|
+
result.killed++;
|
|
33
|
+
}
|
|
34
|
+
} catch {
|
|
35
|
+
result.failed++;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
pruneQaSandboxes
|
|
42
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SecretRedactor, type CacheReview, type ReplayCache, type ReplayCacheDraft, type ReplayCacheEntry, type ReplayCacheKey } from "@open-qa/qa-engine";
|
|
2
|
+
export declare class FileReplayCache implements ReplayCache {
|
|
3
|
+
private readonly redactor;
|
|
4
|
+
private readonly root;
|
|
5
|
+
constructor(root?: string, redactor?: SecretRedactor);
|
|
6
|
+
append(input: ReplayCacheDraft): Promise<ReplayCacheEntry>;
|
|
7
|
+
latest(key: ReplayCacheKey): Promise<ReplayCacheEntry | undefined>;
|
|
8
|
+
pending(key?: ReplayCacheKey): Promise<ReplayCacheEntry[]>;
|
|
9
|
+
approve(id: string, review?: CacheReview): Promise<ReplayCacheEntry>;
|
|
10
|
+
reject(id: string, rejectedBy?: string): Promise<ReplayCacheEntry>;
|
|
11
|
+
private review;
|
|
12
|
+
history(input: ReplayCacheKey): Promise<ReplayCacheEntry[]>;
|
|
13
|
+
private read;
|
|
14
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { open, readdir } from "node:fs/promises";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import {
|
|
5
|
+
replayCacheKey,
|
|
6
|
+
parseReplayCacheId,
|
|
7
|
+
replayCacheKeySchema,
|
|
8
|
+
replayCacheDraftSchema,
|
|
9
|
+
replayCacheEntrySchema,
|
|
10
|
+
approveReplayCache,
|
|
11
|
+
rejectReplayCache,
|
|
12
|
+
SecretRedactor
|
|
13
|
+
} from "@open-qa/qa-engine";
|
|
14
|
+
import {
|
|
15
|
+
assertDirectory,
|
|
16
|
+
atomicWrite,
|
|
17
|
+
ensureDirectory,
|
|
18
|
+
hasCode,
|
|
19
|
+
noFollowRead,
|
|
20
|
+
withRunLock
|
|
21
|
+
} from "./local-files.js";
|
|
22
|
+
class FileReplayCache {
|
|
23
|
+
constructor(root = ".qa", redactor = new SecretRedactor()) {
|
|
24
|
+
this.redactor = redactor;
|
|
25
|
+
this.root = resolve(root);
|
|
26
|
+
}
|
|
27
|
+
redactor;
|
|
28
|
+
root;
|
|
29
|
+
async append(input) {
|
|
30
|
+
const draft = replayCacheDraftSchema.parse(input);
|
|
31
|
+
const digest = replayCacheKey(draft.key);
|
|
32
|
+
return withRunLock(this.root, `cache_${digest}`, async () => {
|
|
33
|
+
const directory = join(this.root, "cache");
|
|
34
|
+
await ensureDirectory(directory);
|
|
35
|
+
const history = await this.history(draft.key);
|
|
36
|
+
if (history.at(-1)?.approval === "pending") throw new Error("Cache review is pending");
|
|
37
|
+
if (draft.healing && history.findLast((entry2) => entry2.approval !== "pending" && entry2.approval !== "rejected")?.version !== draft.healing.sourceVersion)
|
|
38
|
+
throw new Error("Healing source was superseded");
|
|
39
|
+
const entry = replayCacheEntrySchema.parse({
|
|
40
|
+
...draft,
|
|
41
|
+
version: (history.at(-1)?.version ?? 0) + 1
|
|
42
|
+
});
|
|
43
|
+
await atomicWrite(
|
|
44
|
+
join(directory, `${digest}.json`),
|
|
45
|
+
JSON.stringify([...history, entry]) + "\n"
|
|
46
|
+
);
|
|
47
|
+
return entry;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async latest(key) {
|
|
51
|
+
return (await this.history(key)).findLast(
|
|
52
|
+
(entry) => entry.approval !== "pending" && entry.approval !== "rejected"
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
async pending(key) {
|
|
56
|
+
if (key) {
|
|
57
|
+
const latest = (await this.history(key)).at(-1);
|
|
58
|
+
return latest?.approval === "pending" ? [latest] : [];
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
await assertDirectory(this.root);
|
|
62
|
+
await assertDirectory(join(this.root, "cache"));
|
|
63
|
+
const result = [];
|
|
64
|
+
for (const name of (await readdir(join(this.root, "cache"))).sort()) {
|
|
65
|
+
if (!/^[a-f0-9]{64}\.json$/.test(name)) continue;
|
|
66
|
+
const entries = await this.read(name.slice(0, -5));
|
|
67
|
+
const latest = entries.at(-1);
|
|
68
|
+
if (latest?.approval === "pending") result.push(latest);
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
} catch (error) {
|
|
72
|
+
if (hasCode(error, "ENOENT")) return [];
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async approve(id, review) {
|
|
77
|
+
return this.review(id, (entry) => approveReplayCache(entry, this.redactor, review));
|
|
78
|
+
}
|
|
79
|
+
async reject(id, rejectedBy = "local") {
|
|
80
|
+
return this.review(id, (entry) => rejectReplayCache(entry, rejectedBy));
|
|
81
|
+
}
|
|
82
|
+
async review(id, decide) {
|
|
83
|
+
const { digest, version } = parseReplayCacheId(id);
|
|
84
|
+
return withRunLock(this.root, `cache_${digest}`, async () => {
|
|
85
|
+
const entries = await this.read(digest);
|
|
86
|
+
const entry = entries.at(-1);
|
|
87
|
+
if (!entry || entry.version !== version)
|
|
88
|
+
throw new Error("Cache version was superseded or does not exist");
|
|
89
|
+
const approved = decide(entry);
|
|
90
|
+
entries[entries.length - 1] = approved;
|
|
91
|
+
await atomicWrite(join(this.root, "cache", `${digest}.json`), JSON.stringify(entries) + "\n");
|
|
92
|
+
return approved;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
async history(input) {
|
|
96
|
+
return this.read(replayCacheKey(replayCacheKeySchema.parse(input)));
|
|
97
|
+
}
|
|
98
|
+
async read(digest) {
|
|
99
|
+
let handle;
|
|
100
|
+
try {
|
|
101
|
+
await assertDirectory(this.root);
|
|
102
|
+
await assertDirectory(join(this.root, "cache"));
|
|
103
|
+
handle = await open(join(this.root, "cache", `${digest}.json`), noFollowRead);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (hasCode(error, "ENOENT")) return [];
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
const entries = z.array(replayCacheEntrySchema).parse(JSON.parse(await handle.readFile("utf8")));
|
|
110
|
+
if (entries.some((entry, i) => entry.version !== i + 1 || replayCacheKey(entry.key) !== digest))
|
|
111
|
+
throw new Error("Invalid replay cache history");
|
|
112
|
+
return entries;
|
|
113
|
+
} finally {
|
|
114
|
+
await handle.close();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export {
|
|
119
|
+
FileReplayCache
|
|
120
|
+
};
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type ArtifactScan } from "../artifact-scan.js";
|
|
3
|
+
import { type CreateRun, type FinishRun, type RunStore } from "@open-qa/qa-engine";
|
|
4
|
+
import { type Classification, type RunEvent } from "@open-qa/qa-engine/protocol";
|
|
5
|
+
declare const runSchema: z.ZodObject<{
|
|
6
|
+
classification: z.ZodDefault<z.ZodNullable<z.ZodObject<{
|
|
7
|
+
category: z.ZodEnum<{
|
|
8
|
+
env: "env";
|
|
9
|
+
agent: "agent";
|
|
10
|
+
"product-bug": "product-bug";
|
|
11
|
+
"test-case": "test-case";
|
|
12
|
+
flaky: "flaky";
|
|
13
|
+
}>;
|
|
14
|
+
confidence: z.ZodNumber;
|
|
15
|
+
reason: z.ZodString;
|
|
16
|
+
source: z.ZodEnum<{
|
|
17
|
+
model: "model";
|
|
18
|
+
fallback: "fallback";
|
|
19
|
+
rule: "rule";
|
|
20
|
+
human: "human";
|
|
21
|
+
}>;
|
|
22
|
+
}, z.core.$strict>>>;
|
|
23
|
+
classificationLabels: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
24
|
+
category: z.ZodEnum<{
|
|
25
|
+
env: "env";
|
|
26
|
+
agent: "agent";
|
|
27
|
+
"product-bug": "product-bug";
|
|
28
|
+
"test-case": "test-case";
|
|
29
|
+
flaky: "flaky";
|
|
30
|
+
}>;
|
|
31
|
+
reason: z.ZodString;
|
|
32
|
+
modifiedBy: z.ZodString;
|
|
33
|
+
modifiedAt: z.ZodNumber;
|
|
34
|
+
predicted: z.ZodNullable<z.ZodObject<{
|
|
35
|
+
category: z.ZodEnum<{
|
|
36
|
+
env: "env";
|
|
37
|
+
agent: "agent";
|
|
38
|
+
"product-bug": "product-bug";
|
|
39
|
+
"test-case": "test-case";
|
|
40
|
+
flaky: "flaky";
|
|
41
|
+
}>;
|
|
42
|
+
confidence: z.ZodNumber;
|
|
43
|
+
reason: z.ZodString;
|
|
44
|
+
source: z.ZodEnum<{
|
|
45
|
+
model: "model";
|
|
46
|
+
fallback: "fallback";
|
|
47
|
+
rule: "rule";
|
|
48
|
+
human: "human";
|
|
49
|
+
}>;
|
|
50
|
+
}, z.core.$strict>>;
|
|
51
|
+
}, z.core.$strict>>>;
|
|
52
|
+
findings: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
53
|
+
eventSeqs: z.ZodArray<z.ZodNumber>;
|
|
54
|
+
shots: z.ZodArray<z.ZodString>;
|
|
55
|
+
actor: z.ZodString;
|
|
56
|
+
step: z.ZodString;
|
|
57
|
+
category: z.ZodEnum<{
|
|
58
|
+
scope: "scope";
|
|
59
|
+
other: "other";
|
|
60
|
+
}>;
|
|
61
|
+
severity: z.ZodEnum<{
|
|
62
|
+
low: "low";
|
|
63
|
+
medium: "medium";
|
|
64
|
+
high: "high";
|
|
65
|
+
}>;
|
|
66
|
+
description: z.ZodString;
|
|
67
|
+
}, z.core.$strict>>>;
|
|
68
|
+
run: z.ZodObject<{
|
|
69
|
+
id: z.ZodString;
|
|
70
|
+
flow: z.ZodString;
|
|
71
|
+
startedAt: z.ZodNumber;
|
|
72
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
|
|
73
|
+
}, z.core.$strict>;
|
|
74
|
+
eventIndex: z.ZodObject<{
|
|
75
|
+
bytes: z.ZodNumber;
|
|
76
|
+
count: z.ZodNumber;
|
|
77
|
+
lastSeq: z.ZodNumber;
|
|
78
|
+
lastT: z.ZodNumber;
|
|
79
|
+
}, z.core.$strict>;
|
|
80
|
+
result: z.ZodOptional<z.ZodObject<{
|
|
81
|
+
usage: z.ZodOptional<z.ZodObject<{
|
|
82
|
+
inputTokens: z.ZodNumber;
|
|
83
|
+
outputTokens: z.ZodNumber;
|
|
84
|
+
cacheReadTokens: z.ZodOptional<z.ZodNumber>;
|
|
85
|
+
cacheWriteTokens: z.ZodOptional<z.ZodNumber>;
|
|
86
|
+
costUsd: z.ZodOptional<z.ZodNumber>;
|
|
87
|
+
costUnknown: z.ZodOptional<z.ZodLiteral<true>>;
|
|
88
|
+
actions: z.ZodNumber;
|
|
89
|
+
minutes: z.ZodNumber;
|
|
90
|
+
e2bMinutes: z.ZodOptional<z.ZodNumber>;
|
|
91
|
+
}, z.core.$strict>>;
|
|
92
|
+
errorReason: z.ZodOptional<z.ZodLiteral<"budget">>;
|
|
93
|
+
verdict: z.ZodEnum<{
|
|
94
|
+
error: "error";
|
|
95
|
+
passed: "passed";
|
|
96
|
+
failed: "failed";
|
|
97
|
+
inconclusive: "inconclusive";
|
|
98
|
+
canceled: "canceled";
|
|
99
|
+
}>;
|
|
100
|
+
finishedAt: z.ZodNumber;
|
|
101
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
102
|
+
}, z.core.$strict>>;
|
|
103
|
+
}, z.core.$strict>;
|
|
104
|
+
export type FileRun = z.infer<typeof runSchema>;
|
|
105
|
+
export declare class FileRunStore implements RunStore {
|
|
106
|
+
private readonly qaRoot;
|
|
107
|
+
constructor(qaRoot?: string);
|
|
108
|
+
createRun(run: CreateRun): Promise<void>;
|
|
109
|
+
appendEvents(runId: string, events: readonly RunEvent[]): Promise<void>;
|
|
110
|
+
finishRun(runId: string, result: FinishRun): Promise<void>;
|
|
111
|
+
getRun(runId: string): Promise<FileRun | undefined>;
|
|
112
|
+
getClassification(runId: string): Promise<{
|
|
113
|
+
classification: {
|
|
114
|
+
category: "env" | "agent" | "product-bug" | "test-case" | "flaky";
|
|
115
|
+
confidence: number;
|
|
116
|
+
reason: string;
|
|
117
|
+
source: "model" | "fallback" | "rule" | "human";
|
|
118
|
+
} | null;
|
|
119
|
+
labels: {
|
|
120
|
+
category: "env" | "agent" | "product-bug" | "test-case" | "flaky";
|
|
121
|
+
reason: string;
|
|
122
|
+
modifiedBy: string;
|
|
123
|
+
modifiedAt: number;
|
|
124
|
+
predicted: {
|
|
125
|
+
category: "env" | "agent" | "product-bug" | "test-case" | "flaky";
|
|
126
|
+
confidence: number;
|
|
127
|
+
reason: string;
|
|
128
|
+
source: "model" | "fallback" | "rule" | "human";
|
|
129
|
+
} | null;
|
|
130
|
+
}[];
|
|
131
|
+
} | undefined>;
|
|
132
|
+
saveClassification(runId: string, value: Classification): Promise<void>;
|
|
133
|
+
labelClassification(runId: string, input: {
|
|
134
|
+
category: Classification["category"];
|
|
135
|
+
reason: string;
|
|
136
|
+
modifiedBy: string;
|
|
137
|
+
}): Promise<{
|
|
138
|
+
classification: {
|
|
139
|
+
category: "env" | "agent" | "product-bug" | "test-case" | "flaky";
|
|
140
|
+
confidence: number;
|
|
141
|
+
reason: string;
|
|
142
|
+
source: "model" | "fallback" | "rule" | "human";
|
|
143
|
+
};
|
|
144
|
+
labels: {
|
|
145
|
+
category: "env" | "agent" | "product-bug" | "test-case" | "flaky";
|
|
146
|
+
reason: string;
|
|
147
|
+
modifiedBy: string;
|
|
148
|
+
modifiedAt: number;
|
|
149
|
+
predicted: {
|
|
150
|
+
category: "env" | "agent" | "product-bug" | "test-case" | "flaky";
|
|
151
|
+
confidence: number;
|
|
152
|
+
reason: string;
|
|
153
|
+
source: "model" | "fallback" | "rule" | "human";
|
|
154
|
+
} | null;
|
|
155
|
+
}[];
|
|
156
|
+
}>;
|
|
157
|
+
recordArtifactScan(runId: string, scan: ArtifactScan): Promise<void>;
|
|
158
|
+
readEvents(runId: string, afterSeq?: number): Promise<RunEvent[]>;
|
|
159
|
+
recentUsage(flow: string): Promise<{
|
|
160
|
+
inputTokens: number;
|
|
161
|
+
outputTokens: number;
|
|
162
|
+
actions: number;
|
|
163
|
+
minutes: number;
|
|
164
|
+
cacheReadTokens?: number | undefined;
|
|
165
|
+
cacheWriteTokens?: number | undefined;
|
|
166
|
+
costUsd?: number | undefined;
|
|
167
|
+
costUnknown?: true | undefined;
|
|
168
|
+
e2bMinutes?: number | undefined;
|
|
169
|
+
}[]>;
|
|
170
|
+
listRuns(limit?: number): Promise<FileRun[]>;
|
|
171
|
+
private ensureRunDirectory;
|
|
172
|
+
private requireRun;
|
|
173
|
+
private save;
|
|
174
|
+
}
|
|
175
|
+
export {};
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { open, readdir } from "node:fs/promises";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { artifactScanSchema } from "../artifact-scan.js";
|
|
5
|
+
import {
|
|
6
|
+
withExecutionObservation,
|
|
7
|
+
readExecutionSnapshot
|
|
8
|
+
} from "@open-qa/qa-engine";
|
|
9
|
+
import {
|
|
10
|
+
classificationRecordSchema,
|
|
11
|
+
classificationSchema,
|
|
12
|
+
classificationLabelSchema,
|
|
13
|
+
findingSchema,
|
|
14
|
+
jsonObjectSchema,
|
|
15
|
+
millisecondsSchema,
|
|
16
|
+
runEventSchema,
|
|
17
|
+
verdictSchema,
|
|
18
|
+
runUsageSchema
|
|
19
|
+
} from "@open-qa/qa-engine/protocol";
|
|
20
|
+
import {
|
|
21
|
+
assertRegularFile,
|
|
22
|
+
assertDirectory,
|
|
23
|
+
atomicWrite,
|
|
24
|
+
ensureDirectory,
|
|
25
|
+
hasCode,
|
|
26
|
+
noFollowRead,
|
|
27
|
+
noFollowWrite,
|
|
28
|
+
runDirectory,
|
|
29
|
+
withRunLock
|
|
30
|
+
} from "./local-files.js";
|
|
31
|
+
const runSchema = z.strictObject({
|
|
32
|
+
classification: classificationSchema.nullable().default(null),
|
|
33
|
+
classificationLabels: z.array(classificationLabelSchema).default([]),
|
|
34
|
+
findings: z.array(findingSchema).default([]),
|
|
35
|
+
run: z.strictObject({
|
|
36
|
+
id: z.string(),
|
|
37
|
+
flow: z.string(),
|
|
38
|
+
startedAt: millisecondsSchema,
|
|
39
|
+
metadata: jsonObjectSchema.optional()
|
|
40
|
+
}),
|
|
41
|
+
eventIndex: z.strictObject({
|
|
42
|
+
bytes: z.number().int().nonnegative(),
|
|
43
|
+
count: z.number().int().nonnegative(),
|
|
44
|
+
lastSeq: z.number().int().nonnegative(),
|
|
45
|
+
lastT: millisecondsSchema
|
|
46
|
+
}),
|
|
47
|
+
result: z.strictObject({
|
|
48
|
+
usage: runUsageSchema.optional(),
|
|
49
|
+
errorReason: z.literal("budget").optional(),
|
|
50
|
+
verdict: verdictSchema,
|
|
51
|
+
finishedAt: millisecondsSchema,
|
|
52
|
+
reason: z.string().optional()
|
|
53
|
+
}).optional()
|
|
54
|
+
});
|
|
55
|
+
class FileRunStore {
|
|
56
|
+
qaRoot;
|
|
57
|
+
constructor(qaRoot = ".qa") {
|
|
58
|
+
this.qaRoot = resolve(qaRoot);
|
|
59
|
+
}
|
|
60
|
+
async createRun(run) {
|
|
61
|
+
if (run.metadata?.executionSnapshot !== void 0 && readExecutionSnapshot(run.metadata.executionSnapshot).status !== "recorded")
|
|
62
|
+
throw new Error("Invalid execution snapshot");
|
|
63
|
+
const directory = runDirectory(this.qaRoot, run.id);
|
|
64
|
+
await withRunLock(this.qaRoot, run.id, async () => {
|
|
65
|
+
if (await this.getRun(run.id)) throw new Error(`Run already exists: ${run.id}`);
|
|
66
|
+
await this.ensureRunDirectory(run.id);
|
|
67
|
+
const stored = runSchema.parse({
|
|
68
|
+
run,
|
|
69
|
+
eventIndex: { bytes: 0, count: 0, lastSeq: 0, lastT: 0 }
|
|
70
|
+
});
|
|
71
|
+
await atomicWrite(join(directory, "events.ndjson"), "");
|
|
72
|
+
await this.save(run.id, stored);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
async appendEvents(runId, events) {
|
|
76
|
+
await withRunLock(this.qaRoot, runId, async () => {
|
|
77
|
+
const stored = await this.requireRun(runId);
|
|
78
|
+
if (stored.result) throw new Error(`Run is finished: ${runId}`);
|
|
79
|
+
let { lastSeq, lastT } = stored.eventIndex;
|
|
80
|
+
const validated = events.map((event) => runEventSchema.parse(event));
|
|
81
|
+
for (const event of validated) {
|
|
82
|
+
if (event.seq <= lastSeq) throw new Error("Event sequence must increase");
|
|
83
|
+
if (event.t < lastT) throw new Error("Event time must not decrease");
|
|
84
|
+
lastSeq = event.seq;
|
|
85
|
+
lastT = event.t;
|
|
86
|
+
}
|
|
87
|
+
if (!validated.length) return;
|
|
88
|
+
const data = Buffer.from(validated.map((event) => JSON.stringify(event) + "\n").join(""));
|
|
89
|
+
const handle = await open(
|
|
90
|
+
join(runDirectory(this.qaRoot, runId), "events.ndjson"),
|
|
91
|
+
noFollowWrite,
|
|
92
|
+
384
|
|
93
|
+
);
|
|
94
|
+
try {
|
|
95
|
+
if ((await handle.stat()).size < stored.eventIndex.bytes)
|
|
96
|
+
throw new Error("Run event log is truncated");
|
|
97
|
+
await handle.truncate(stored.eventIndex.bytes);
|
|
98
|
+
let offset = 0;
|
|
99
|
+
while (offset < data.length) {
|
|
100
|
+
const { bytesWritten } = await handle.write(
|
|
101
|
+
data,
|
|
102
|
+
offset,
|
|
103
|
+
data.length - offset,
|
|
104
|
+
stored.eventIndex.bytes + offset
|
|
105
|
+
);
|
|
106
|
+
if (!bytesWritten) throw new Error("Could not append run events");
|
|
107
|
+
offset += bytesWritten;
|
|
108
|
+
}
|
|
109
|
+
await handle.sync();
|
|
110
|
+
} finally {
|
|
111
|
+
await handle.close();
|
|
112
|
+
}
|
|
113
|
+
stored.eventIndex = {
|
|
114
|
+
bytes: stored.eventIndex.bytes + data.length,
|
|
115
|
+
count: stored.eventIndex.count + validated.length,
|
|
116
|
+
lastSeq,
|
|
117
|
+
lastT
|
|
118
|
+
};
|
|
119
|
+
await this.save(runId, stored);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
async finishRun(runId, result) {
|
|
123
|
+
await withRunLock(this.qaRoot, runId, async () => {
|
|
124
|
+
const stored = await this.requireRun(runId);
|
|
125
|
+
if (stored.result) throw new Error(`Run is finished: ${runId}`);
|
|
126
|
+
const { executionObservation, findings = [], ...outcome } = result;
|
|
127
|
+
if (executionObservation)
|
|
128
|
+
stored.run.metadata = withExecutionObservation(stored.run.metadata, executionObservation);
|
|
129
|
+
await this.save(runId, runSchema.parse({ ...stored, result: outcome, findings }));
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
async getRun(runId) {
|
|
133
|
+
const directory = runDirectory(this.qaRoot, runId);
|
|
134
|
+
try {
|
|
135
|
+
await assertDirectory(this.qaRoot);
|
|
136
|
+
await assertDirectory(join(this.qaRoot, "runs"));
|
|
137
|
+
await assertDirectory(directory);
|
|
138
|
+
const file = join(directory, "run.json");
|
|
139
|
+
await assertRegularFile(file);
|
|
140
|
+
const handle = await open(file, noFollowRead);
|
|
141
|
+
let stored;
|
|
142
|
+
try {
|
|
143
|
+
stored = runSchema.parse(JSON.parse(await handle.readFile("utf8")));
|
|
144
|
+
} finally {
|
|
145
|
+
await handle.close();
|
|
146
|
+
}
|
|
147
|
+
if (stored.run.id !== runId)
|
|
148
|
+
throw new SyntaxError("Run metadata does not match its directory");
|
|
149
|
+
return stored;
|
|
150
|
+
} catch (error) {
|
|
151
|
+
if (hasCode(error, "ENOENT")) return void 0;
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
async getClassification(runId) {
|
|
156
|
+
const stored = await this.getRun(runId);
|
|
157
|
+
return stored ? classificationRecordSchema.parse({
|
|
158
|
+
classification: stored.classification,
|
|
159
|
+
labels: stored.classificationLabels
|
|
160
|
+
}) : void 0;
|
|
161
|
+
}
|
|
162
|
+
async saveClassification(runId, value) {
|
|
163
|
+
await withRunLock(this.qaRoot, runId, async () => {
|
|
164
|
+
const stored = await this.requireRun(runId);
|
|
165
|
+
if (!["failed", "error"].includes(stored.result?.verdict ?? ""))
|
|
166
|
+
throw new Error("Only failed/error runs can be classified");
|
|
167
|
+
if (stored.classificationLabels.length) return;
|
|
168
|
+
stored.classification = classificationSchema.parse(value);
|
|
169
|
+
await this.save(runId, stored);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
async labelClassification(runId, input) {
|
|
173
|
+
return withRunLock(this.qaRoot, runId, async () => {
|
|
174
|
+
const stored = await this.requireRun(runId);
|
|
175
|
+
if (!["failed", "error"].includes(stored.result?.verdict ?? ""))
|
|
176
|
+
throw new Error("Only failed/error runs can be classified");
|
|
177
|
+
const label = classificationLabelSchema.parse({
|
|
178
|
+
...input,
|
|
179
|
+
modifiedAt: Date.now(),
|
|
180
|
+
predicted: stored.classification?.source === "human" ? stored.classificationLabels[0]?.predicted ?? null : stored.classification
|
|
181
|
+
});
|
|
182
|
+
stored.classificationLabels.push(label);
|
|
183
|
+
stored.classification = {
|
|
184
|
+
category: label.category,
|
|
185
|
+
reason: label.reason,
|
|
186
|
+
confidence: 1,
|
|
187
|
+
source: "human"
|
|
188
|
+
};
|
|
189
|
+
await this.save(runId, stored);
|
|
190
|
+
return { classification: stored.classification, labels: stored.classificationLabels };
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
async recordArtifactScan(runId, scan) {
|
|
194
|
+
await withRunLock(this.qaRoot, runId, async () => {
|
|
195
|
+
const stored = await this.requireRun(runId);
|
|
196
|
+
stored.run.metadata = {
|
|
197
|
+
...stored.run.metadata,
|
|
198
|
+
artifactScan: artifactScanSchema.parse(scan)
|
|
199
|
+
};
|
|
200
|
+
await this.save(runId, stored);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
async readEvents(runId, afterSeq = 0) {
|
|
204
|
+
const stored = await this.requireRun(runId);
|
|
205
|
+
const handle = await open(
|
|
206
|
+
join(runDirectory(this.qaRoot, runId), "events.ndjson"),
|
|
207
|
+
noFollowRead
|
|
208
|
+
);
|
|
209
|
+
try {
|
|
210
|
+
const data = Buffer.alloc(stored.eventIndex.bytes);
|
|
211
|
+
let offset = 0;
|
|
212
|
+
while (offset < data.length) {
|
|
213
|
+
const { bytesRead } = await handle.read(data, offset, data.length - offset, offset);
|
|
214
|
+
if (!bytesRead) throw new Error("Run event log is truncated");
|
|
215
|
+
offset += bytesRead;
|
|
216
|
+
}
|
|
217
|
+
const events = data.toString("utf8").split("\n").filter(Boolean).map((line) => runEventSchema.parse(JSON.parse(line)));
|
|
218
|
+
if (events.length !== stored.eventIndex.count)
|
|
219
|
+
throw new Error("Run event index does not match the log");
|
|
220
|
+
return events.filter((event) => event.seq > afterSeq);
|
|
221
|
+
} finally {
|
|
222
|
+
await handle.close();
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
async recentUsage(flow) {
|
|
226
|
+
return (await this.listRuns(Number.MAX_SAFE_INTEGER)).filter(
|
|
227
|
+
(item) => item.run.flow === flow && item.result?.usage && item.result.errorReason !== "budget"
|
|
228
|
+
).slice(0, 5).map((item) => item.result.usage);
|
|
229
|
+
}
|
|
230
|
+
async listRuns(limit = 20) {
|
|
231
|
+
if (!Number.isInteger(limit) || limit < 0)
|
|
232
|
+
throw new Error("Run limit must be a nonnegative integer");
|
|
233
|
+
let entries;
|
|
234
|
+
try {
|
|
235
|
+
await assertDirectory(this.qaRoot);
|
|
236
|
+
await assertDirectory(join(this.qaRoot, "runs"));
|
|
237
|
+
entries = await readdir(join(this.qaRoot, "runs"), { withFileTypes: true });
|
|
238
|
+
} catch (error) {
|
|
239
|
+
if (hasCode(error, "ENOENT")) return [];
|
|
240
|
+
throw error;
|
|
241
|
+
}
|
|
242
|
+
const runs = [];
|
|
243
|
+
let skipped = 0;
|
|
244
|
+
for (const entry of entries) {
|
|
245
|
+
if (!entry.isDirectory() || !/^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/.test(entry.name)) continue;
|
|
246
|
+
try {
|
|
247
|
+
const stored = await this.getRun(entry.name);
|
|
248
|
+
if (stored) runs.push(stored);
|
|
249
|
+
} catch (error) {
|
|
250
|
+
if (!(error instanceof SyntaxError) && !(error instanceof z.ZodError)) throw error;
|
|
251
|
+
skipped++;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (skipped > 0)
|
|
255
|
+
process.stderr.write(
|
|
256
|
+
`Skipped ${skipped} unreadable run record(s). Convert legacy metadata or repair invalid records before listing runs.
|
|
257
|
+
`
|
|
258
|
+
);
|
|
259
|
+
return runs.sort((a, b) => b.run.startedAt - a.run.startedAt || a.run.id.localeCompare(b.run.id)).slice(0, limit);
|
|
260
|
+
}
|
|
261
|
+
async ensureRunDirectory(runId) {
|
|
262
|
+
await ensureDirectory(this.qaRoot);
|
|
263
|
+
await ensureDirectory(join(this.qaRoot, "runs"));
|
|
264
|
+
await ensureDirectory(runDirectory(this.qaRoot, runId));
|
|
265
|
+
}
|
|
266
|
+
async requireRun(runId) {
|
|
267
|
+
const stored = await this.getRun(runId);
|
|
268
|
+
if (!stored) throw new Error(`Unknown run: ${runId}`);
|
|
269
|
+
return stored;
|
|
270
|
+
}
|
|
271
|
+
save(runId, stored) {
|
|
272
|
+
return atomicWrite(
|
|
273
|
+
join(runDirectory(this.qaRoot, runId), "run.json"),
|
|
274
|
+
JSON.stringify(stored) + "\n"
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
export {
|
|
279
|
+
FileRunStore
|
|
280
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Lease, LeasePool, LeaseSpec } from "@open-qa/qa-engine";
|
|
2
|
+
export declare class FixedLeasePool implements LeasePool {
|
|
3
|
+
private readonly qaRoot;
|
|
4
|
+
private readonly lockRoot;
|
|
5
|
+
constructor(qaRoot?: string, lockRoot?: string);
|
|
6
|
+
acquire(spec: LeaseSpec, signal?: AbortSignal): Promise<Lease>;
|
|
7
|
+
release(lease: Lease): Promise<void>;
|
|
8
|
+
private reapExpired;
|
|
9
|
+
private directories;
|
|
10
|
+
}
|