@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,24 @@
|
|
|
1
|
+
import { loadConfig, type LoadedFlow } from "./flow-loader.js";
|
|
2
|
+
export declare class StudioError extends Error {
|
|
3
|
+
status: number;
|
|
4
|
+
runId?: string;
|
|
5
|
+
constructor(message: string, status?: number, runId?: string);
|
|
6
|
+
}
|
|
7
|
+
export declare function studioRevision(config: Awaited<ReturnType<typeof loadConfig>>, doc: LoadedFlow): string;
|
|
8
|
+
export declare function reviewFlow(root: string, project: string, source: string, id: string, name: string): Promise<{
|
|
9
|
+
revision: string;
|
|
10
|
+
estimate: string[];
|
|
11
|
+
prompt: string;
|
|
12
|
+
flow: string;
|
|
13
|
+
target: string;
|
|
14
|
+
url: string;
|
|
15
|
+
budget: {
|
|
16
|
+
actions?: number | undefined;
|
|
17
|
+
minutes?: number | undefined;
|
|
18
|
+
usd?: number | undefined;
|
|
19
|
+
} | null;
|
|
20
|
+
recording: "rrweb"[];
|
|
21
|
+
policy: "never" | "safe";
|
|
22
|
+
runtime: string;
|
|
23
|
+
}>;
|
|
24
|
+
export type Review = Awaited<ReturnType<typeof reviewFlow>>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { compile, isProtectedTarget, targetAllowsUrl } from "@open-qa/qa-engine";
|
|
4
|
+
import { loadConfig, loadFlowDocument } from "./flow-loader.js";
|
|
5
|
+
import { confirmRunEstimate } from "./budget-confirmation.js";
|
|
6
|
+
import { FileRunStore } from "./adapters/file-run-store.js";
|
|
7
|
+
class StudioError extends Error {
|
|
8
|
+
status;
|
|
9
|
+
runId;
|
|
10
|
+
constructor(message, status = 409, runId) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.status = status;
|
|
13
|
+
this.runId = runId;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function studioRevision(config, doc) {
|
|
17
|
+
return createHash("sha256").update(JSON.stringify([config, doc.definitions])).digest("hex");
|
|
18
|
+
}
|
|
19
|
+
async function reviewFlow(root, project, source, id, name) {
|
|
20
|
+
const config = await loadConfig(root);
|
|
21
|
+
const target = config.targets && Object.hasOwn(config.targets, name) && config.targets[name];
|
|
22
|
+
if (!target || config.projectId !== project || !targetAllowsUrl(target, target.url))
|
|
23
|
+
throw new StudioError("This test environment is unavailable.", 400);
|
|
24
|
+
if (isProtectedTarget(name, target))
|
|
25
|
+
throw new StudioError("Protected environments require the CLI.", 403);
|
|
26
|
+
const doc = await loadFlowDocument(resolve(root, source), root);
|
|
27
|
+
if (createHash("sha256").update(doc.flow.key).digest("hex") !== id)
|
|
28
|
+
throw new StudioError("Configuration changed; review again.");
|
|
29
|
+
const plan = compile(doc.flow);
|
|
30
|
+
const estimate = [];
|
|
31
|
+
let prompt = "";
|
|
32
|
+
const store = new FileRunStore(root);
|
|
33
|
+
await confirmRunEstimate({
|
|
34
|
+
flows: [plan.key],
|
|
35
|
+
recentUsage: store.recentUsage.bind(store),
|
|
36
|
+
thresholds: config.confirmAbove,
|
|
37
|
+
subscription: true,
|
|
38
|
+
attempts: 1,
|
|
39
|
+
interactive: true,
|
|
40
|
+
output: (line) => estimate.push(line),
|
|
41
|
+
confirm: async (message) => {
|
|
42
|
+
prompt = message;
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
const url = new URL(target.url);
|
|
47
|
+
return {
|
|
48
|
+
revision: studioRevision(config, doc),
|
|
49
|
+
estimate,
|
|
50
|
+
prompt,
|
|
51
|
+
flow: plan.key,
|
|
52
|
+
target: name,
|
|
53
|
+
url: url.origin + url.pathname,
|
|
54
|
+
budget: plan.budget ?? null,
|
|
55
|
+
recording: plan.record,
|
|
56
|
+
policy: plan.prod,
|
|
57
|
+
runtime: "Claude Code with subscription login on the local host (one attempt)"
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
StudioError,
|
|
62
|
+
reviewFlow,
|
|
63
|
+
studioRevision
|
|
64
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { RunSetupError } from "./run-setup-error.js";
|
|
2
|
+
import { runCommand } from "./run-command.js";
|
|
3
|
+
import { studioRevision } from "./studio-review.js";
|
|
4
|
+
const controller = new AbortController();
|
|
5
|
+
const cancel = () => controller.abort(new Error("Studio canceled this run"));
|
|
6
|
+
process.once("disconnect", cancel);
|
|
7
|
+
process.once("message", async (start) => {
|
|
8
|
+
process.on("message", (message) => {
|
|
9
|
+
if (message === "stop") cancel();
|
|
10
|
+
});
|
|
11
|
+
let estimate = "";
|
|
12
|
+
let created = false;
|
|
13
|
+
try {
|
|
14
|
+
process.exitCode = await runCommand(
|
|
15
|
+
start.path,
|
|
16
|
+
{ root: start.root, target: start.review.target, retries: 0 },
|
|
17
|
+
{
|
|
18
|
+
signal: controller.signal,
|
|
19
|
+
interactive: true,
|
|
20
|
+
output: (line) => {
|
|
21
|
+
if (line.startsWith("Estimate ")) estimate = line;
|
|
22
|
+
},
|
|
23
|
+
confirm: async (message) => {
|
|
24
|
+
if (!start.accepted || message !== start.review.prompt || estimate !== start.review.estimate[0])
|
|
25
|
+
throw new RunSetupError("review-changed", "Review changed");
|
|
26
|
+
return true;
|
|
27
|
+
},
|
|
28
|
+
studio: {
|
|
29
|
+
runId: start.runId,
|
|
30
|
+
verify: (config, doc) => {
|
|
31
|
+
if (studioRevision(config, doc) !== start.review.revision)
|
|
32
|
+
throw new RunSetupError("review-changed", "Review changed");
|
|
33
|
+
},
|
|
34
|
+
created: () => {
|
|
35
|
+
created = true;
|
|
36
|
+
process.send?.("running");
|
|
37
|
+
},
|
|
38
|
+
saved: () => process.send?.("saved")
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (!created) process.send?.(error instanceof RunSetupError ? error.code : "configuration");
|
|
44
|
+
process.exitCode = 2;
|
|
45
|
+
} finally {
|
|
46
|
+
if (process.connected) process.disconnect();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ExecutionPlan, QaConfig } from "@open-qa/qa-engine";
|
|
2
|
+
import { type SystemConfig } from "@open-qa/qa-engine/protocol";
|
|
3
|
+
type Settings = NonNullable<QaConfig["targets"]>[string]["systems"];
|
|
4
|
+
export declare function systemSecretValues(systems?: SystemConfig): string[];
|
|
5
|
+
export declare function resolveSystems(target: SystemConfig["target"], settings: Settings, env: NodeJS.ProcessEnv, plan?: ExecutionPlan): SystemConfig | undefined;
|
|
6
|
+
export declare function actorPermissions(plan: ExecutionPlan): Record<string, string[]>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
discordToolNames,
|
|
3
|
+
emailToolNames,
|
|
4
|
+
pageToolNames,
|
|
5
|
+
telegramToolNames,
|
|
6
|
+
systemConfigSchema,
|
|
7
|
+
systemToolNames
|
|
8
|
+
} from "@open-qa/qa-engine/protocol";
|
|
9
|
+
function systemSecretValues(systems) {
|
|
10
|
+
return [
|
|
11
|
+
...Object.values(systems?.secrets ?? {}),
|
|
12
|
+
systems?.db?.token,
|
|
13
|
+
systems?.logs?.accessToken,
|
|
14
|
+
systems?.github?.token
|
|
15
|
+
].filter((value) => !!value);
|
|
16
|
+
}
|
|
17
|
+
function resolveSystems(target, settings, env, plan) {
|
|
18
|
+
if (!settings) return void 0;
|
|
19
|
+
if (target === "prod" && settings.db) throw new Error("DB surface is unavailable on prod");
|
|
20
|
+
const db = !plan || plan.expectAlways.some((condition) => condition.type.startsWith("db.")) || plan.lanes.some(
|
|
21
|
+
(lane) => lane.spec.tools?.includes("db") || lane.steps.some(
|
|
22
|
+
(step) => step.expect.some((condition) => condition.type.startsWith("db.")) || typeof step.waitFor === "object" && step.waitFor.type.startsWith("db.")
|
|
23
|
+
)
|
|
24
|
+
) ? settings.db : void 0;
|
|
25
|
+
let missingResource;
|
|
26
|
+
try {
|
|
27
|
+
const resources = db || settings.logs || settings.github ? JSON.parse(env.QA_RESOURCES ?? "{}") : {};
|
|
28
|
+
const resource = (name) => {
|
|
29
|
+
if (!Object.hasOwn(resources, name)) {
|
|
30
|
+
missingResource = name;
|
|
31
|
+
throw new Error("Missing resource");
|
|
32
|
+
}
|
|
33
|
+
return resources[name];
|
|
34
|
+
};
|
|
35
|
+
return systemConfigSchema.parse({
|
|
36
|
+
target,
|
|
37
|
+
...db && { db: resource(db) },
|
|
38
|
+
...settings.logs && { logs: resource(settings.logs) },
|
|
39
|
+
...settings.github && { github: resource(settings.github) },
|
|
40
|
+
...settings.secrets && {
|
|
41
|
+
secrets: Object.fromEntries(
|
|
42
|
+
Object.entries(settings.secrets).map(([name, key]) => [name, env[key]])
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
} catch {
|
|
47
|
+
throw new Error(
|
|
48
|
+
`Invalid or missing system resources${missingResource ? `: missing resource ${missingResource}` : ""}; check target.systems and QA_RESOURCES`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function actorPermissions(plan) {
|
|
53
|
+
return Object.fromEntries(
|
|
54
|
+
plan.lanes.map((lane) => [
|
|
55
|
+
lane.actor,
|
|
56
|
+
[
|
|
57
|
+
...pageToolNames,
|
|
58
|
+
...lane.views.some((view) => plan.views[view]?.surface === "telegram") ? telegramToolNames : [],
|
|
59
|
+
...lane.views.some((view) => plan.views[view].surface === "discord") ? discordToolNames : [],
|
|
60
|
+
...lane.views.some((view) => plan.views[view].surface === "email") ? emailToolNames : [],
|
|
61
|
+
...(lane.spec.tools ?? []).map((tool) => systemToolNames[tool])
|
|
62
|
+
]
|
|
63
|
+
])
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
export {
|
|
67
|
+
actorPermissions,
|
|
68
|
+
resolveSystems,
|
|
69
|
+
systemSecretValues
|
|
70
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ExecutionPlan } from "@open-qa/qa-engine";
|
|
2
|
+
import type { RunEvent } from "@open-qa/qa-engine/protocol";
|
|
3
|
+
export declare class TerminalReporter {
|
|
4
|
+
private readonly plan;
|
|
5
|
+
private readonly output;
|
|
6
|
+
private readonly current;
|
|
7
|
+
private totalActions;
|
|
8
|
+
private reviewCounts;
|
|
9
|
+
private readonly unresolved;
|
|
10
|
+
private readonly lanes;
|
|
11
|
+
constructor(plan: ExecutionPlan, output: (line: string) => void);
|
|
12
|
+
event(event: RunEvent): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
const plain = (value) => value.replace(/[\u0000-\u001f\u007f-\u009f]/g, " ");
|
|
2
|
+
class TerminalReporter {
|
|
3
|
+
constructor(plan, output) {
|
|
4
|
+
this.plan = plan;
|
|
5
|
+
this.output = output;
|
|
6
|
+
this.lanes = plan.lanes.filter((lane) => lane.kind === "user").length;
|
|
7
|
+
}
|
|
8
|
+
plan;
|
|
9
|
+
output;
|
|
10
|
+
// Lanes run concurrently, so each actor's current step keeps its own start and action count.
|
|
11
|
+
current = /* @__PURE__ */ new Map();
|
|
12
|
+
totalActions = 0;
|
|
13
|
+
reviewCounts = { completed: 0, incomplete: 0, skipped: 0 };
|
|
14
|
+
unresolved = /* @__PURE__ */ new Set();
|
|
15
|
+
lanes;
|
|
16
|
+
event(event) {
|
|
17
|
+
const actor = event.actor ?? "";
|
|
18
|
+
const who = this.lanes > 1 && event.actor ? `${plain(event.actor)} \xB7 ` : "";
|
|
19
|
+
if (event.kind === "step_started") {
|
|
20
|
+
this.current.set(actor, { started: event.t, actions: 0 });
|
|
21
|
+
const step = this.plan.lanes.flatMap((lane) => lane.steps).find((step2) => step2.id === event.step);
|
|
22
|
+
this.output(
|
|
23
|
+
` ${who}step ${plain(event.step)} started${step?.do ? `: ${plain(step.do)}` : ""}`
|
|
24
|
+
);
|
|
25
|
+
} else if (event.kind === "action" && (event.by === "agent" || event.by === "program" || event.by === "replay")) {
|
|
26
|
+
const step = this.current.get(actor);
|
|
27
|
+
if (step) step.actions++;
|
|
28
|
+
this.totalActions++;
|
|
29
|
+
} else if (event.kind === "step_finished") {
|
|
30
|
+
const step = this.current.get(actor) ?? { started: event.t, actions: 0 };
|
|
31
|
+
this.output(
|
|
32
|
+
` ${who}${event.status} \xB7 step ${plain(event.step)} \xB7 ${step.actions} actions \xB7 ${((event.t - step.started) / 1e3).toFixed(1)}s${event.reason ? ` \xB7 ${plain(event.reason)}` : ""}`
|
|
33
|
+
);
|
|
34
|
+
} else if (event.kind === "expect_result" && !event.result.passed)
|
|
35
|
+
this.output(
|
|
36
|
+
` expect ${plain(event.condition.type)} failed: ${plain(event.result.reason ?? "Expectation failed")}`
|
|
37
|
+
);
|
|
38
|
+
else if (event.kind === "judge_result") {
|
|
39
|
+
const source = event.result.evidence.source;
|
|
40
|
+
this.output(
|
|
41
|
+
` ${who}judge ${event.result.verdict} \xB7 step ${plain(event.step ?? "unknown")} \xB7 confidence ${event.result.confidence ?? "unavailable"} \xB7 source ${plain(typeof source === "string" ? source : "unavailable")} \xB7 ${plain(event.result.reason ?? "No reason recorded")}`
|
|
42
|
+
);
|
|
43
|
+
} else if (event.kind === "reviewer_result") {
|
|
44
|
+
this.reviewCounts[event.result.status]++;
|
|
45
|
+
this.output(
|
|
46
|
+
` Reviewer ${event.result.status} \xB7 ${event.originalVerdict} \u2192 ${event.verdict} \xB7 ${event.result.findings.length} findings \xB7 ${plain(event.result.reason)}`
|
|
47
|
+
);
|
|
48
|
+
for (const check of event.result.checks) {
|
|
49
|
+
if (check.status === "unknown" && event.result.status === "incomplete")
|
|
50
|
+
this.unresolved.add(plain(`${check.actor}/${check.step}: ${check.item}`));
|
|
51
|
+
if (check.status !== "pass")
|
|
52
|
+
this.output(
|
|
53
|
+
` ${plain(check.actor)}/${plain(check.step)} \xB7 ${check.item}: ${check.status} \xB7 ${plain(check.reason)}`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
for (const finding of event.result.findings)
|
|
57
|
+
this.output(
|
|
58
|
+
` ${finding.severity} \xB7 ${finding.category} \xB7 ${plain(finding.actor)}/${plain(finding.step)}: ${plain(finding.description)}`
|
|
59
|
+
);
|
|
60
|
+
} else if (event.kind === "usage" && event.costUnknown)
|
|
61
|
+
this.output(` ${who}Cost unknown: gateway pricing or required token rates unavailable`);
|
|
62
|
+
else if (event.kind === "cache_warning")
|
|
63
|
+
this.output(
|
|
64
|
+
` ${who}cache warning${event.step ? ` \xB7 step ${plain(event.step)}` : ""} \xB7 ${plain(event.message)}`
|
|
65
|
+
);
|
|
66
|
+
else if (event.kind === "heal_result")
|
|
67
|
+
this.output(
|
|
68
|
+
` self-heal ${event.outcome} \xB7 step ${plain(event.step)} \xB7 ${event.mode} \xB7 cache ${event.cache}${event.cacheId ? ` \xB7 ${event.cacheId}` : ""}`
|
|
69
|
+
);
|
|
70
|
+
else if (event.kind === "deadlock")
|
|
71
|
+
for (const lane of event.lanes)
|
|
72
|
+
this.output(
|
|
73
|
+
` deadlock \xB7 ${plain(lane.actor)} \xB7 ${lane.step === void 0 ? "finished" : `step ${plain(lane.step)} waits for ${plain(lane.waitsFor.join(", "))}`}`
|
|
74
|
+
);
|
|
75
|
+
else if (event.kind === "run_finished") {
|
|
76
|
+
const { completed, incomplete, skipped } = this.reviewCounts;
|
|
77
|
+
if (completed + incomplete + skipped)
|
|
78
|
+
this.output(
|
|
79
|
+
` Reviewer summary \xB7 ${completed} completed \xB7 ${incomplete} incomplete \xB7 ${skipped} skipped${this.unresolved.size ? ` \xB7 unresolved: ${[...this.unresolved].join(", ")}` : ""}`
|
|
80
|
+
);
|
|
81
|
+
this.output(
|
|
82
|
+
` ${event.verdict} \xB7 ${this.totalActions} actions \xB7 ${(event.t / 1e3).toFixed(1)}s${event.reason ? ` \xB7 ${plain(event.reason)}` : ""}`
|
|
83
|
+
);
|
|
84
|
+
this.totalActions = 0;
|
|
85
|
+
this.reviewCounts = { completed: 0, incomplete: 0, skipped: 0 };
|
|
86
|
+
this.unresolved.clear();
|
|
87
|
+
this.current.clear();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
TerminalReporter
|
|
93
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const gmailCredentialsSchema: z.ZodObject<{
|
|
3
|
+
clientId: z.ZodString;
|
|
4
|
+
clientSecret: z.ZodString;
|
|
5
|
+
refreshToken: z.ZodString;
|
|
6
|
+
}, z.core.$strict>;
|
|
7
|
+
export type GmailCredentials = z.infer<typeof gmailCredentialsSchema>;
|
|
8
|
+
export interface InboxMessage {
|
|
9
|
+
id: string;
|
|
10
|
+
to: string;
|
|
11
|
+
from: string;
|
|
12
|
+
subject: string;
|
|
13
|
+
date: number;
|
|
14
|
+
text: string;
|
|
15
|
+
html: string;
|
|
16
|
+
}
|
|
17
|
+
declare const querySchema: z.ZodObject<{
|
|
18
|
+
to: z.ZodEmail;
|
|
19
|
+
from: z.ZodOptional<z.ZodEmail>;
|
|
20
|
+
afterMs: z.ZodNumber;
|
|
21
|
+
metadata: z.ZodOptional<z.ZodBoolean>;
|
|
22
|
+
}, z.core.$strict>;
|
|
23
|
+
declare const reasons: {
|
|
24
|
+
readonly authorization: "Email authorization failed";
|
|
25
|
+
readonly rate: "Email rate limited";
|
|
26
|
+
readonly unavailable: "Email unavailable";
|
|
27
|
+
readonly invalid: "Email response invalid";
|
|
28
|
+
};
|
|
29
|
+
export declare class EmailInboxError extends Error {
|
|
30
|
+
readonly reason: keyof typeof reasons;
|
|
31
|
+
constructor(reason: keyof typeof reasons);
|
|
32
|
+
}
|
|
33
|
+
/** Host/stage-only inbox. Provider bodies and credentials never appear in errors. */
|
|
34
|
+
export declare class GmailInbox {
|
|
35
|
+
private readonly credentials;
|
|
36
|
+
private readonly transport;
|
|
37
|
+
private token?;
|
|
38
|
+
private retryAt;
|
|
39
|
+
private readonly checked;
|
|
40
|
+
constructor(credentials: GmailCredentials, transport?: typeof fetch);
|
|
41
|
+
private request;
|
|
42
|
+
authorize(signal?: AbortSignal): Promise<string>;
|
|
43
|
+
read(input: z.infer<typeof querySchema>, signal?: AbortSignal): Promise<InboxMessage[]>;
|
|
44
|
+
}
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const gmailCredentialsSchema = z.strictObject({
|
|
3
|
+
clientId: z.string().min(1).max(4096),
|
|
4
|
+
clientSecret: z.string().min(1).max(4096),
|
|
5
|
+
refreshToken: z.string().min(1).max(4096)
|
|
6
|
+
});
|
|
7
|
+
const querySchema = z.strictObject({
|
|
8
|
+
to: z.email(),
|
|
9
|
+
from: z.email().optional(),
|
|
10
|
+
afterMs: z.number().nonnegative().finite(),
|
|
11
|
+
metadata: z.boolean().optional()
|
|
12
|
+
});
|
|
13
|
+
const partSchema = z.object({
|
|
14
|
+
mimeType: z.string().optional(),
|
|
15
|
+
headers: z.array(z.object({ name: z.string(), value: z.string() })).default([]),
|
|
16
|
+
body: z.object({ data: z.string().optional() }).optional(),
|
|
17
|
+
get parts() {
|
|
18
|
+
return z.array(partSchema).optional();
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
function boundedMime(value) {
|
|
22
|
+
const pending = [{ value, depth: 0 }];
|
|
23
|
+
let count = 0;
|
|
24
|
+
while (pending.length) {
|
|
25
|
+
const item = pending.pop();
|
|
26
|
+
if (++count > 1e4 || item.depth > 30) return false;
|
|
27
|
+
if (item.value && typeof item.value === "object")
|
|
28
|
+
for (const child of Object.values(item.value))
|
|
29
|
+
pending.push({ value: child, depth: item.depth + 1 });
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
const messageSchema = z.object({ internalDate: z.string(), payload: partSchema });
|
|
34
|
+
const listSchema = z.object({
|
|
35
|
+
messages: z.array(z.object({ id: z.string().min(1).max(256) })).max(20).default([])
|
|
36
|
+
});
|
|
37
|
+
const endpoint = "https://gmail.googleapis.com/gmail/v1/users/me/messages";
|
|
38
|
+
const reasons = {
|
|
39
|
+
authorization: "Email authorization failed",
|
|
40
|
+
rate: "Email rate limited",
|
|
41
|
+
unavailable: "Email unavailable",
|
|
42
|
+
invalid: "Email response invalid"
|
|
43
|
+
};
|
|
44
|
+
class EmailInboxError extends Error {
|
|
45
|
+
constructor(reason) {
|
|
46
|
+
super(reasons[reason]);
|
|
47
|
+
this.reason = reason;
|
|
48
|
+
}
|
|
49
|
+
reason;
|
|
50
|
+
}
|
|
51
|
+
class GmailInbox {
|
|
52
|
+
constructor(credentials, transport = fetch) {
|
|
53
|
+
this.credentials = credentials;
|
|
54
|
+
this.transport = transport;
|
|
55
|
+
if (!gmailCredentialsSchema.safeParse(credentials).success)
|
|
56
|
+
throw new EmailInboxError("authorization");
|
|
57
|
+
}
|
|
58
|
+
credentials;
|
|
59
|
+
transport;
|
|
60
|
+
token;
|
|
61
|
+
retryAt = 0;
|
|
62
|
+
checked = /* @__PURE__ */ new Map();
|
|
63
|
+
async request(url, init, signal) {
|
|
64
|
+
try {
|
|
65
|
+
signal?.throwIfAborted();
|
|
66
|
+
if (Date.now() < this.retryAt) throw new EmailInboxError("rate");
|
|
67
|
+
const bounded = AbortSignal.any([...signal ? [signal] : [], AbortSignal.timeout(15e3)]);
|
|
68
|
+
const response = await this.transport(url, { ...init, redirect: "manual", signal: bounded });
|
|
69
|
+
if (!response.ok) {
|
|
70
|
+
await response.body?.cancel();
|
|
71
|
+
if (response.status === 429) {
|
|
72
|
+
const seconds = Number(response.headers.get("retry-after") ?? 1);
|
|
73
|
+
this.retryAt = Date.now() + Math.min(60, Math.max(1, seconds || 1)) * 1e3;
|
|
74
|
+
throw new EmailInboxError("rate");
|
|
75
|
+
}
|
|
76
|
+
throw new EmailInboxError(
|
|
77
|
+
[401, 403].includes(response.status) ? "authorization" : "unavailable"
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
const reader = response.body?.getReader();
|
|
81
|
+
if (!reader) throw new EmailInboxError("invalid");
|
|
82
|
+
const chunks = [];
|
|
83
|
+
let bytes = 0;
|
|
84
|
+
while (true) {
|
|
85
|
+
bounded.throwIfAborted();
|
|
86
|
+
const chunk = await reader.read();
|
|
87
|
+
if (chunk.done) break;
|
|
88
|
+
bytes += chunk.value.byteLength;
|
|
89
|
+
if (bytes > 2e6) {
|
|
90
|
+
await reader.cancel();
|
|
91
|
+
throw new EmailInboxError("invalid");
|
|
92
|
+
}
|
|
93
|
+
chunks.push(chunk.value);
|
|
94
|
+
}
|
|
95
|
+
return JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
96
|
+
} catch (error) {
|
|
97
|
+
signal?.throwIfAborted();
|
|
98
|
+
if (error instanceof EmailInboxError) throw error;
|
|
99
|
+
throw new EmailInboxError("unavailable");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async authorize(signal) {
|
|
103
|
+
if (this.token && this.token.expires > Date.now()) return this.token.value;
|
|
104
|
+
const raw = await this.request(
|
|
105
|
+
"https://oauth2.googleapis.com/token",
|
|
106
|
+
{
|
|
107
|
+
method: "POST",
|
|
108
|
+
body: new URLSearchParams({
|
|
109
|
+
client_id: this.credentials.clientId,
|
|
110
|
+
client_secret: this.credentials.clientSecret,
|
|
111
|
+
refresh_token: this.credentials.refreshToken,
|
|
112
|
+
grant_type: "refresh_token"
|
|
113
|
+
})
|
|
114
|
+
},
|
|
115
|
+
signal
|
|
116
|
+
);
|
|
117
|
+
const parsed = z.object({ access_token: z.string().min(1), expires_in: z.number().positive().default(3600) }).safeParse(raw);
|
|
118
|
+
if (!parsed.success) throw new EmailInboxError("invalid");
|
|
119
|
+
this.token = {
|
|
120
|
+
value: parsed.data.access_token,
|
|
121
|
+
expires: Date.now() + Math.max(0, parsed.data.expires_in - 60) * 1e3
|
|
122
|
+
};
|
|
123
|
+
return this.token.value;
|
|
124
|
+
}
|
|
125
|
+
async read(input, signal) {
|
|
126
|
+
const parsed = querySchema.safeParse(input);
|
|
127
|
+
if (!parsed.success) throw new Error("Invalid inbox query");
|
|
128
|
+
const query = parsed.data;
|
|
129
|
+
const token = await this.authorize(signal);
|
|
130
|
+
const headers = { authorization: `Bearer ${token}` };
|
|
131
|
+
const params = new URLSearchParams({
|
|
132
|
+
q: `to:${query.to}${query.from ? ` from:${query.from}` : ""} after:${Math.floor(query.afterMs / 1e3)}`,
|
|
133
|
+
maxResults: "20"
|
|
134
|
+
});
|
|
135
|
+
const list = listSchema.safeParse(
|
|
136
|
+
await this.request(`${endpoint}?${params}`, { headers }, signal)
|
|
137
|
+
);
|
|
138
|
+
if (!list.success) throw new EmailInboxError("invalid");
|
|
139
|
+
const results = [];
|
|
140
|
+
for (const { id } of list.data.messages) {
|
|
141
|
+
signal?.throwIfAborted();
|
|
142
|
+
const key = JSON.stringify([id, query]);
|
|
143
|
+
if (!this.checked.has(key)) {
|
|
144
|
+
const format = query.metadata ? "metadata&metadataHeaders=Subject&metadataHeaders=To&metadataHeaders=From" : "full";
|
|
145
|
+
const raw = await this.request(
|
|
146
|
+
`${endpoint}/${encodeURIComponent(id)}?format=${format}`,
|
|
147
|
+
{ headers },
|
|
148
|
+
signal
|
|
149
|
+
);
|
|
150
|
+
if (!boundedMime(raw)) throw new EmailInboxError("invalid");
|
|
151
|
+
const parsed2 = messageSchema.safeParse(raw);
|
|
152
|
+
if (!parsed2.success) throw new EmailInboxError("invalid");
|
|
153
|
+
const { payload, internalDate } = parsed2.data;
|
|
154
|
+
const header = (name) => payload.headers.find((field) => field.name.toLowerCase() === name.toLowerCase())?.value ?? "";
|
|
155
|
+
const exact = (value, expected) => (/^[^<>]*<([^<>]+)>$/.exec(value)?.[1] ?? value).toLowerCase() === expected.toLowerCase();
|
|
156
|
+
const date = Number(internalDate);
|
|
157
|
+
let message2 = null;
|
|
158
|
+
if (Number.isFinite(date) && date >= query.afterMs && exact(header("To"), query.to) && (!query.from || exact(header("From"), query.from))) {
|
|
159
|
+
const content = { text: "", html: "" };
|
|
160
|
+
const decode = (part, depth) => {
|
|
161
|
+
if (depth > 20) throw new EmailInboxError("invalid");
|
|
162
|
+
if (part.body?.data && ["text/plain", "text/html"].includes(part.mimeType ?? "")) {
|
|
163
|
+
const key2 = part.mimeType === "text/html" ? "html" : "text";
|
|
164
|
+
content[key2] += Buffer.from(part.body.data, "base64url").toString("utf8");
|
|
165
|
+
}
|
|
166
|
+
for (const child of part.parts ?? []) decode(child, depth + 1);
|
|
167
|
+
};
|
|
168
|
+
decode(payload, 0);
|
|
169
|
+
if (content.text.length + content.html.length > 256e3)
|
|
170
|
+
throw new EmailInboxError("invalid");
|
|
171
|
+
message2 = {
|
|
172
|
+
id,
|
|
173
|
+
date,
|
|
174
|
+
to: query.to,
|
|
175
|
+
from: header("From"),
|
|
176
|
+
subject: header("Subject"),
|
|
177
|
+
...content
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
this.checked.set(key, message2);
|
|
181
|
+
if (this.checked.size > 20) this.checked.delete(this.checked.keys().next().value);
|
|
182
|
+
}
|
|
183
|
+
const message = this.checked.get(key);
|
|
184
|
+
if (message) results.push(message);
|
|
185
|
+
}
|
|
186
|
+
return results.sort((a, b) => b.date - a.date);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
export {
|
|
190
|
+
EmailInboxError,
|
|
191
|
+
GmailInbox,
|
|
192
|
+
gmailCredentialsSchema
|
|
193
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type ScreenAccess } from "./screen-url.js";
|
|
2
|
+
import { FileRunStore } from "./adapters/file-run-store.js";
|
|
3
|
+
import { QaRemoteClient, type RemoteOptions } from "./remote-command.js";
|
|
4
|
+
export interface WatchOptions extends RemoteOptions {
|
|
5
|
+
root?: string;
|
|
6
|
+
remote?: boolean;
|
|
7
|
+
after?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function watchCommand(id: string, options?: WatchOptions, deps?: {
|
|
10
|
+
store?: Pick<FileRunStore, "getRun" | "readEvents">;
|
|
11
|
+
client?: QaRemoteClient;
|
|
12
|
+
output?: (line: string) => void;
|
|
13
|
+
signal?: AbortSignal;
|
|
14
|
+
wait?: (signal: AbortSignal) => Promise<void>;
|
|
15
|
+
screen?: (root: string, id: string) => Promise<ScreenAccess | undefined>;
|
|
16
|
+
}): Promise<number>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { startScreenProxy } from "./screen-proxy.js";
|
|
2
|
+
import {
|
|
3
|
+
readScreenFrames,
|
|
4
|
+
screenFramesSchema,
|
|
5
|
+
screenResponseSchema
|
|
6
|
+
} from "./screen-url.js";
|
|
7
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
8
|
+
import { resolve } from "node:path";
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import {
|
|
11
|
+
eventsPageSchema,
|
|
12
|
+
runDtoSchema,
|
|
13
|
+
serverIdSchema
|
|
14
|
+
} from "@open-qa/qa-engine/protocol";
|
|
15
|
+
import { FileRunStore } from "./adapters/file-run-store.js";
|
|
16
|
+
import { QaRemoteClient } from "./remote-command.js";
|
|
17
|
+
import { readWatchState } from "./watch-state.js";
|
|
18
|
+
async function watchCommand(id, options = {}, deps = {}) {
|
|
19
|
+
serverIdSchema.parse(id);
|
|
20
|
+
let cursor = z.coerce.number().int().nonnegative().parse(options.after ?? 0);
|
|
21
|
+
const root = resolve(options.root ?? ".qa");
|
|
22
|
+
const store = deps.store ?? new FileRunStore(root);
|
|
23
|
+
const client = options.remote ? deps.client ?? new QaRemoteClient(options) : void 0;
|
|
24
|
+
const output = deps.output ?? console.log;
|
|
25
|
+
const controller = new AbortController();
|
|
26
|
+
const cancel = () => controller.abort();
|
|
27
|
+
process.on("SIGINT", cancel);
|
|
28
|
+
process.on("SIGTERM", cancel);
|
|
29
|
+
const signal = deps.signal ? AbortSignal.any([deps.signal, controller.signal]) : controller.signal;
|
|
30
|
+
let proxy;
|
|
31
|
+
try {
|
|
32
|
+
while (!signal.aborted) {
|
|
33
|
+
let events;
|
|
34
|
+
let finished;
|
|
35
|
+
let lastSeq;
|
|
36
|
+
if (client) {
|
|
37
|
+
const run = runDtoSchema.parse(await client.call(`/runs/${id}`));
|
|
38
|
+
if (!proxy && !run.result) {
|
|
39
|
+
if (run.id !== id) throw new Error("QA server returned a different run");
|
|
40
|
+
const { available } = screenResponseSchema.parse(await client.call(`/runs/${id}/screen`));
|
|
41
|
+
if (available) {
|
|
42
|
+
proxy = await startScreenProxy(
|
|
43
|
+
async (signal2) => screenFramesSchema.parse(
|
|
44
|
+
await client.call(`/runs/${id}/screen/frames`, "GET", void 0, void 0, signal2)
|
|
45
|
+
)
|
|
46
|
+
);
|
|
47
|
+
output(`E2B screen (local session, keep watch running): ${proxy.url}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const page = eventsPageSchema.parse(
|
|
51
|
+
await client.call(`/runs/${id}/events?after=${cursor}&limit=1000`)
|
|
52
|
+
);
|
|
53
|
+
if (run.id !== id || page.runId !== id || page.projectId !== run.projectId)
|
|
54
|
+
throw new Error("QA server returned a different run");
|
|
55
|
+
events = page.events;
|
|
56
|
+
finished = !!run.result;
|
|
57
|
+
lastSeq = run.lastSeq;
|
|
58
|
+
} else {
|
|
59
|
+
const run = await store.getRun(id);
|
|
60
|
+
if (!run) throw new Error(`Run not found: ${id}`);
|
|
61
|
+
events = await store.readEvents(id, cursor);
|
|
62
|
+
finished = !!run.result;
|
|
63
|
+
lastSeq = run.eventIndex.lastSeq;
|
|
64
|
+
if (!proxy && !finished) {
|
|
65
|
+
const access = await (deps.screen ?? readWatchState)(root, id);
|
|
66
|
+
if (access) {
|
|
67
|
+
proxy = await startScreenProxy((signal2) => readScreenFrames(access, signal2));
|
|
68
|
+
output(`E2B screen (local session, keep watch running): ${proxy.url}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
for (const event of events) {
|
|
73
|
+
if (event.seq <= cursor) continue;
|
|
74
|
+
output(JSON.stringify(event));
|
|
75
|
+
cursor = event.seq;
|
|
76
|
+
}
|
|
77
|
+
if (finished && cursor >= lastSeq) return 0;
|
|
78
|
+
if (events.length >= 1e3) continue;
|
|
79
|
+
await (deps.wait ?? ((signal2) => delay(1e3, void 0, { signal: signal2 })))(signal);
|
|
80
|
+
}
|
|
81
|
+
return 130;
|
|
82
|
+
} catch (error) {
|
|
83
|
+
if (signal.aborted) return 130;
|
|
84
|
+
throw error;
|
|
85
|
+
} finally {
|
|
86
|
+
process.off("SIGINT", cancel);
|
|
87
|
+
process.off("SIGTERM", cancel);
|
|
88
|
+
await proxy?.close();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
watchCommand
|
|
93
|
+
};
|