@open-qa/qa 0.1.0-alpha.4 → 0.1.0-alpha.5
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/THIRD_PARTY.md +5 -0
- package/drizzle/0017_provider_notifications.sql +13 -0
- package/drizzle/0018_classification_registry.sql +39 -0
- package/drizzle/0019_trial_audit.sql +44 -0
- package/drizzle/meta/0017_snapshot.json +2092 -0
- package/drizzle/meta/0018_snapshot.json +2102 -0
- package/drizzle/meta/0019_snapshot.json +2451 -0
- package/drizzle/meta/_journal.json +21 -0
- package/package.json +12 -7
- package/src/access-binding.d.ts +8 -0
- package/src/access-binding.js +26 -0
- package/src/adapters/classification-write.d.ts +87 -0
- package/src/adapters/classification-write.js +64 -0
- package/src/adapters/e2b-executor.js +4 -0
- package/src/adapters/file-run-store.d.ts +186 -41
- package/src/adapters/file-run-store.js +87 -19
- package/src/adapters/file-trial-audit.d.ts +280 -0
- package/src/adapters/file-trial-audit.js +105 -0
- package/src/adapters/pg-classification-store.d.ts +98 -20
- package/src/adapters/pg-classification-store.js +84 -44
- package/src/adapters/pg-run-store.d.ts +1 -0
- package/src/adapters/pg-run-store.js +70 -9
- package/src/adapters/run-metadata.d.ts +2 -0
- package/src/adapters/run-metadata.js +10 -0
- package/src/adapters/secret-manager-credential-resolver.d.ts +1 -1
- package/src/attempt-audit.d.ts +363 -0
- package/src/attempt-audit.js +253 -0
- package/src/audit-command.d.ts +13 -0
- package/src/audit-command.js +77 -0
- package/src/classification-command.d.ts +14 -9
- package/src/classification-command.js +119 -26
- package/src/classification-model.d.ts +10 -3
- package/src/classification-model.js +40 -24
- package/src/classification-notifier.d.ts +4 -3
- package/src/classification-notifier.js +26 -6
- package/src/classify-runs.d.ts +2 -1
- package/src/classify-runs.js +39 -3
- package/src/cli-program.js +53 -7
- package/src/commands.d.ts +1 -0
- package/src/commands.js +2 -0
- package/src/db/database.d.ts +7 -0
- package/src/db/database.js +15 -0
- package/src/db/event-chunks.d.ts +38 -29
- package/src/db/flow-status.d.ts +7 -3
- package/src/db/flow-status.js +240 -16
- package/src/db/queries.d.ts +24 -1
- package/src/db/queries.js +22 -0
- package/src/db/schema.d.ts +333 -4
- package/src/db/schema.js +83 -11
- package/src/db/trial-audit.d.ts +526 -0
- package/src/db/trial-audit.js +84 -0
- package/src/draft-api.d.ts +25 -421
- package/src/draft-api.js +10 -3
- package/src/engine.d.ts +47 -4
- package/src/engine.js +97 -8
- package/src/execution-snapshot.d.ts +1 -1
- package/src/execution-snapshot.js +22 -17
- package/src/export-command.d.ts +6 -0
- package/src/export-command.js +106 -0
- package/src/flow-check.js +1 -1
- package/src/flow-loader.d.ts +72 -6
- package/src/flow-loader.js +76 -12
- package/src/http-stage-client.d.ts +98 -1
- package/src/independent-model.js +53 -6
- package/src/judge-review-store.d.ts +13 -0
- package/src/judge-review-store.js +58 -0
- package/src/local-host-executor.d.ts +3 -1
- package/src/local-host-executor.js +2 -0
- package/src/quarantine-command.d.ts +5 -1
- package/src/quarantine-command.js +56 -13
- package/src/remote-command.js +2 -0
- package/src/report/browser.js +37 -37
- package/src/report/ctrf.d.ts +983 -0
- package/src/report/ctrf.js +306 -0
- package/src/report/generate.d.ts +1 -1
- package/src/report/generate.js +29 -6
- package/src/report/load.d.ts +738 -42
- package/src/report/load.js +78 -6
- package/src/result-notifier.js +1 -1
- package/src/result-trace.d.ts +62 -0
- package/src/result-trace.js +81 -0
- package/src/run-command.d.ts +2 -0
- package/src/run-command.js +285 -62
- package/src/run-setup-error.d.ts +1 -1
- package/src/run-setup-error.js +2 -2
- package/src/server/app.js +5 -4
- package/src/server/index.d.ts +2 -0
- package/src/server/index.js +11 -2
- package/src/server/repository.d.ts +166 -29
- package/src/server/repository.js +14 -2
- package/src/studio-review.js +1 -1
- package/src/system-config.d.ts +2 -2
- package/src/system-config.js +5 -4
- package/src/trial-audit.d.ts +630 -0
- package/src/trial-audit.js +272 -0
- package/src/visual-baseline.d.ts +4 -0
- package/src/visual-baseline.js +42 -0
- package/src/webhook-notification.d.ts +15 -0
- package/src/webhook-notification.js +61 -0
- package/src/worker/execution.d.ts +2 -1
- package/src/worker/execution.js +122 -3
- package/src/worker/index.d.ts +4 -0
- package/src/worker/index.js +10 -1
- package/src/worker/quarantine-notifications.js +2 -2
- package/src/worker/queue.d.ts +6 -2
- package/src/worker/queue.js +80 -19
- package/src/worker/result-notifications.d.ts +10 -2
- package/src/worker/result-notifications.js +120 -23
- package/src/worker/store.js +6 -3
package/src/run-command.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveAccessBinding } from "./access-binding.js";
|
|
1
2
|
import { RunSetupError } from "./run-setup-error.js";
|
|
2
3
|
import { isProtectedTarget } from "@open-qa/qa-engine";
|
|
3
4
|
import { confirmRunEstimate } from "./budget-confirmation.js";
|
|
@@ -11,7 +12,11 @@ import { readFile, stat } from "node:fs/promises";
|
|
|
11
12
|
import { join, resolve } from "node:path";
|
|
12
13
|
import {
|
|
13
14
|
compile,
|
|
15
|
+
CompileError,
|
|
16
|
+
loadProviderRegistry,
|
|
17
|
+
loadClassificationRegistry,
|
|
14
18
|
sumRunUsage,
|
|
19
|
+
quarantinePolicySchema,
|
|
15
20
|
SecretRedactor,
|
|
16
21
|
selectAgentPlacement,
|
|
17
22
|
targetAllowsUrl
|
|
@@ -24,17 +29,25 @@ import { hasCode, runDirectory } from "./adapters/local-files.js";
|
|
|
24
29
|
import { readLocalEnv } from "./adapters/local-env.js";
|
|
25
30
|
import { generateReport } from "./report/generate.js";
|
|
26
31
|
import { captureExecutionSnapshot, sourceVersions } from "./execution-snapshot.js";
|
|
32
|
+
import { buildResultTrace, readRunContext, resultCaseId } from "./result-trace.js";
|
|
27
33
|
import { readConsumerManifest } from "./hooks/consumer.js";
|
|
28
34
|
import { TerminalReporter } from "./terminal-reporter.js";
|
|
29
35
|
import { scanRunArtifacts } from "./artifact-scan.js";
|
|
30
|
-
import { QaDatabase } from "./db/database.js";
|
|
36
|
+
import { QaDatabase, postgresNow } from "./db/database.js";
|
|
31
37
|
import { PgFlowStatus } from "./db/flow-status.js";
|
|
32
38
|
import { printRepeat } from "./quarantine-command.js";
|
|
33
39
|
import { selectByLifecycle } from "./flow-lifecycle.js";
|
|
40
|
+
import { FileTrialAudit } from "./adapters/file-trial-audit.js";
|
|
41
|
+
import { PgTrialAudit } from "./db/trial-audit.js";
|
|
42
|
+
import { printTrial, summarizeTrial } from "./trial-audit.js";
|
|
43
|
+
import { attemptAuditSchema } from "./attempt-audit.js";
|
|
34
44
|
async function runCommand(path, options, adapters = {}) {
|
|
45
|
+
const runContext = await readRunContext(options.runContext);
|
|
35
46
|
const repeat = options.repeat ?? 1;
|
|
36
47
|
if (!Number.isInteger(repeat) || repeat < 1 || repeat > 100)
|
|
37
48
|
throw new Error("--repeat must be an integer between 1 and 100");
|
|
49
|
+
if (options.dependentTrials && options.repeat === void 0)
|
|
50
|
+
throw new Error("--dependent-trials requires --repeat");
|
|
38
51
|
if (options.executor && options.executor !== "local-host" && options.executor !== "e2b")
|
|
39
52
|
throw new Error("--executor must be local-host or e2b");
|
|
40
53
|
const placement = options.executor === "e2b" ? "e2b" : "local-host";
|
|
@@ -75,7 +88,8 @@ async function runCommand(path, options, adapters = {}) {
|
|
|
75
88
|
if (options.replay !== void 0 && options.replay !== "off")
|
|
76
89
|
throw new Error("--replay only accepts off");
|
|
77
90
|
const root = options.root ? resolve(options.root) : findQaRoot(path);
|
|
78
|
-
const
|
|
91
|
+
const providers = await loadProviderRegistry();
|
|
92
|
+
const config = await loadConfig(root, providers);
|
|
79
93
|
if (!config.projectId)
|
|
80
94
|
throw new Error(
|
|
81
95
|
"Missing projectId in config.yaml; configure a persistent opaque projectId once and commit it with the project"
|
|
@@ -89,7 +103,7 @@ async function runCommand(path, options, adapters = {}) {
|
|
|
89
103
|
if (!targetAllowsUrl(target, target.url))
|
|
90
104
|
throw new Error(`Target ${targetName} URL is outside its allow list`);
|
|
91
105
|
const trigger = (await stat(path)).isDirectory() ? "suite" : "manual";
|
|
92
|
-
let flows = trigger === "suite" ? await loadFlowDocuments(root, path) : [await loadFlowDocument(path, root)];
|
|
106
|
+
let flows = trigger === "suite" ? await loadFlowDocuments(root, path, void 0, providers) : [await loadFlowDocument(path, root, providers)];
|
|
93
107
|
if (adapters.studio) {
|
|
94
108
|
if (trigger !== "manual" || isProtectedTarget(targetName, target) || flows.length !== 1)
|
|
95
109
|
throw new Error("Target unavailable in Studio");
|
|
@@ -106,41 +120,55 @@ async function runCommand(path, options, adapters = {}) {
|
|
|
106
120
|
if (!flows.length) throw new Error("No flows match the selection");
|
|
107
121
|
if (options.repeat !== void 0 && flows.length !== 1)
|
|
108
122
|
throw new Error("--repeat requires exactly one selected flow");
|
|
109
|
-
const plans = flows.map(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
123
|
+
const plans = flows.map((document) => {
|
|
124
|
+
const { flow } = document;
|
|
125
|
+
try {
|
|
126
|
+
return compile(
|
|
127
|
+
{
|
|
128
|
+
...flow,
|
|
129
|
+
...cloud ? { budget: { ...flow.budget, minutes: flow.budget?.minutes ?? 15 } } : {},
|
|
130
|
+
actors: Object.fromEntries(
|
|
131
|
+
Object.entries(flow.actors).map(([name, actor]) => [
|
|
132
|
+
name,
|
|
133
|
+
{
|
|
134
|
+
...actor,
|
|
135
|
+
...actor.kind !== "system" ? { persona: options.persona ?? actor.persona ?? "default" } : {}
|
|
136
|
+
}
|
|
137
|
+
])
|
|
138
|
+
)
|
|
139
|
+
},
|
|
140
|
+
void 0,
|
|
141
|
+
{
|
|
142
|
+
providers,
|
|
143
|
+
target: {
|
|
144
|
+
name: targetName,
|
|
145
|
+
access: target.access,
|
|
146
|
+
protected: isProtectedTarget(targetName, target),
|
|
147
|
+
placement
|
|
119
148
|
}
|
|
120
|
-
|
|
121
|
-
)
|
|
122
|
-
})
|
|
123
|
-
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
} catch (error) {
|
|
152
|
+
if (!(error instanceof CompileError)) throw error;
|
|
153
|
+
const message = error.issues.map((issue) => document.diagnostic(issue, "compile")).join("\n");
|
|
154
|
+
if (error.issues.some(
|
|
155
|
+
(issue) => issue.message.startsWith("Unsupported ") && issue.path[0] === "views"
|
|
156
|
+
))
|
|
157
|
+
throw new RunSetupError("unsupported-surface", message, { cause: error });
|
|
158
|
+
throw new Error(message, { cause: error });
|
|
159
|
+
}
|
|
160
|
+
});
|
|
124
161
|
const personas = await loadPersonas(
|
|
125
162
|
root,
|
|
126
163
|
plans.flatMap(
|
|
127
164
|
(plan) => plan.lanes.filter((lane) => lane.kind === "user").map((lane) => lane.spec.persona)
|
|
128
165
|
)
|
|
129
166
|
);
|
|
130
|
-
for (const plan of plans)
|
|
167
|
+
for (const plan of plans)
|
|
131
168
|
if (isProtectedTarget(targetName, target) && plan.prod !== "safe")
|
|
132
169
|
throw new Error(`Flow ${plan.key} must declare prod: safe for target ${targetName}`);
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
throw new RunSetupError(
|
|
136
|
-
"unsupported-surface",
|
|
137
|
-
`Unsupported local view surface: ${view.surface}`
|
|
138
|
-
);
|
|
139
|
-
if (view.surface === "telegram" && isProtectedTarget(targetName, target))
|
|
140
|
-
throw new Error("Telegram requires a non-production target");
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
const store = adapters.runStore ?? new FileRunStore(root);
|
|
170
|
+
const classificationScope = adapters.classificationScope ?? (adapters.runStore instanceof FileRunStore ? adapters.runStore.classificationScope : loadClassificationRegistry().forProject(config.projectId));
|
|
171
|
+
const store = adapters.runStore ?? new FileRunStore(root, classificationScope);
|
|
144
172
|
await confirmRunEstimate({
|
|
145
173
|
...adapters,
|
|
146
174
|
flows: plans.map((plan) => plan.key),
|
|
@@ -170,6 +198,19 @@ async function runCommand(path, options, adapters = {}) {
|
|
|
170
198
|
clientSecret: env.QA_CF_ACCESS_CLIENT_SECRET
|
|
171
199
|
};
|
|
172
200
|
}
|
|
201
|
+
const accessBinding = target.access && target.access !== "cloudflare" ? resolveAccessBinding(providers, target.access, targetName, target.url, {
|
|
202
|
+
...process.env,
|
|
203
|
+
...env
|
|
204
|
+
}) : void 0;
|
|
205
|
+
for (const [plan, config2] of systems) {
|
|
206
|
+
for (const capability of plan.providers ?? []) {
|
|
207
|
+
if (capability.kind === "tool" && ["db", "logs", "github"].includes(capability.id) && capability.provider === "open-qa" && !config2?.[capability.id])
|
|
208
|
+
throw new RunSetupError(
|
|
209
|
+
"configuration",
|
|
210
|
+
`Tool ${capability.id} requires target.systems configuration`
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
173
214
|
const output = adapters.output ?? console.log;
|
|
174
215
|
const subscriptionToken = modelAccess === "login" && runtimeId === "claude-code" ? process.env.CLAUDE_CODE_OAUTH_TOKEN : void 0;
|
|
175
216
|
if (subscriptionToken) output("Using CLAUDE_CODE_OAUTH_TOKEN for subscription login");
|
|
@@ -201,11 +242,19 @@ async function runCommand(path, options, adapters = {}) {
|
|
|
201
242
|
try {
|
|
202
243
|
database = !adapters.flowStatus && process.env.QA_DATABASE_URL ? new QaDatabase(process.env.QA_DATABASE_URL) : void 0;
|
|
203
244
|
const flowStatus = adapters.flowStatus ?? (database ? new PgFlowStatus(database, config.projectId) : void 0);
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
245
|
+
const audit = options.repeat === void 0 ? void 0 : database ? new PgTrialAudit(database, config.projectId) : new FileTrialAudit(root, config.projectId);
|
|
246
|
+
const localAudit = database && localStore && audit ? new FileTrialAudit(root, config.projectId) : void 0;
|
|
247
|
+
const trialTime = (localTime = Date.now()) => database ? postgresNow(database.pool) : localTime;
|
|
248
|
+
const appendTrialReceipt = async (groupId, receipt) => {
|
|
249
|
+
await audit.append(groupId, receipt);
|
|
250
|
+
await localAudit?.append(groupId, receipt);
|
|
251
|
+
};
|
|
252
|
+
let group;
|
|
253
|
+
let quarantinedAtGroupStart = false;
|
|
254
|
+
const trials = plans.flatMap(
|
|
255
|
+
(plan) => Array.from({ length: repeat }, (_, index) => ({ plan, index: index + 1 }))
|
|
256
|
+
);
|
|
257
|
+
for (const { plan, index } of trials) {
|
|
209
258
|
const reporter = new TerminalReporter(plan, output);
|
|
210
259
|
const redactor = new SecretRedactor();
|
|
211
260
|
const blocked = /* @__PURE__ */ new Set();
|
|
@@ -227,12 +276,98 @@ async function runCommand(path, options, adapters = {}) {
|
|
|
227
276
|
env,
|
|
228
277
|
publicEnv: readConsumerManifest(root)?.publicEnv,
|
|
229
278
|
subscriptionToken,
|
|
230
|
-
systemSecrets:
|
|
279
|
+
systemSecrets: [
|
|
280
|
+
...systemSecretValues(systems.get(plan)),
|
|
281
|
+
...accessBinding?.secrets ?? []
|
|
282
|
+
]
|
|
231
283
|
});
|
|
284
|
+
const caseId = resultCaseId(snapshot.projectId, plan.traceability?.caseId ?? plan.key);
|
|
285
|
+
if (audit && !group) {
|
|
286
|
+
const state = await flowStatus?.get(plan.key);
|
|
287
|
+
quarantinedAtGroupStart = state?.status === "quarantined";
|
|
288
|
+
const { expiresAfterHours, evidenceMaxAgeHours, minimumPassedTrials, flakyStreak } = config.quarantine ?? quarantinePolicySchema.parse({});
|
|
289
|
+
group = redactor.json({
|
|
290
|
+
schemaVersion: 1,
|
|
291
|
+
groupId: `trial:${batchId}:${caseId}`,
|
|
292
|
+
projectId: config.projectId,
|
|
293
|
+
batchId,
|
|
294
|
+
caseId,
|
|
295
|
+
flow: plan.key,
|
|
296
|
+
caseRevision: snapshot.definitions.flow.sha256,
|
|
297
|
+
target: targetName,
|
|
298
|
+
targetRevision: "revision" in snapshot.target ? snapshot.target.revision ?? null : null,
|
|
299
|
+
generation: state?.generation ?? null,
|
|
300
|
+
planned: repeat,
|
|
301
|
+
startedAt: await trialTime(repeatResult.startedAt),
|
|
302
|
+
environment: snapshot,
|
|
303
|
+
...options.dependentTrials && { independent: false },
|
|
304
|
+
quarantinePolicy: {
|
|
305
|
+
expiresAfterHours,
|
|
306
|
+
evidenceMaxAgeHours,
|
|
307
|
+
minimumPassedTrials,
|
|
308
|
+
flakyStreak
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
await audit.create(group);
|
|
312
|
+
await localAudit?.create(group);
|
|
313
|
+
output(`Trial group ${group.groupId}`);
|
|
314
|
+
}
|
|
315
|
+
if (signal.aborted && !adapters.studio) {
|
|
316
|
+
code = Math.max(code, 1);
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
319
|
+
const recordTrial = async (completed) => {
|
|
320
|
+
if (group)
|
|
321
|
+
await appendTrialReceipt(group.groupId, {
|
|
322
|
+
kind: "trial-finished",
|
|
323
|
+
index,
|
|
324
|
+
attemptId: completed.runId,
|
|
325
|
+
quarantined: completed.quarantined ?? false
|
|
326
|
+
});
|
|
327
|
+
};
|
|
328
|
+
const finished = [];
|
|
232
329
|
const runStore = {
|
|
233
330
|
...store.listRuns && { listRuns: store.listRuns.bind(store) },
|
|
331
|
+
async recordClassifierUsage(id, samples) {
|
|
332
|
+
await store.recordClassifierUsage?.(id, samples);
|
|
333
|
+
if (group && samples.length)
|
|
334
|
+
await appendTrialReceipt(group.groupId, {
|
|
335
|
+
kind: "classifier-usage",
|
|
336
|
+
attemptId: id,
|
|
337
|
+
usage: [...samples]
|
|
338
|
+
});
|
|
339
|
+
},
|
|
234
340
|
createRun: async (run) => {
|
|
235
341
|
Object.assign(engine.observation, snapshot.observed);
|
|
342
|
+
const resultTrace = buildResultTrace({
|
|
343
|
+
projectId: snapshot.projectId,
|
|
344
|
+
flow: plan.key,
|
|
345
|
+
plan,
|
|
346
|
+
context: runContext,
|
|
347
|
+
attemptId: run.id,
|
|
348
|
+
retryOf: typeof run.metadata?.retryOf === "string" ? run.metadata.retryOf : void 0,
|
|
349
|
+
batchId,
|
|
350
|
+
trial: options.repeat === void 0 ? null : { groupId: `trial:${batchId}:${caseId}`, index, count: repeat },
|
|
351
|
+
caseRevision: snapshot.definitions.flow.sha256,
|
|
352
|
+
target: snapshot.target.name,
|
|
353
|
+
targetRevision: "revision" in snapshot.target ? snapshot.target.revision : null,
|
|
354
|
+
commit: snapshot.versions.commit,
|
|
355
|
+
parameters: {
|
|
356
|
+
...context,
|
|
357
|
+
placement,
|
|
358
|
+
headed: snapshot.effective.headed,
|
|
359
|
+
level: snapshot.effective.level,
|
|
360
|
+
persona: options.persona,
|
|
361
|
+
replay: options.repeat !== void 0 || options.replay === "off" ? "off" : "enabled"
|
|
362
|
+
},
|
|
363
|
+
environment: {
|
|
364
|
+
...snapshot.versions,
|
|
365
|
+
origin: snapshot.target.origin,
|
|
366
|
+
suite: snapshot.definitions.suite?.sha256,
|
|
367
|
+
config: snapshot.definitions.config?.sha256,
|
|
368
|
+
zone: snapshot.timeZone.value
|
|
369
|
+
}
|
|
370
|
+
});
|
|
236
371
|
await store.createRun(
|
|
237
372
|
redactor.json({
|
|
238
373
|
...run,
|
|
@@ -241,10 +376,16 @@ async function runCommand(path, options, adapters = {}) {
|
|
|
241
376
|
batchId,
|
|
242
377
|
target: targetName,
|
|
243
378
|
...context,
|
|
244
|
-
executionSnapshot: { ...snapshot, capturedAt: run.startedAt }
|
|
379
|
+
executionSnapshot: { ...snapshot, capturedAt: run.startedAt },
|
|
380
|
+
resultTrace
|
|
245
381
|
}
|
|
246
382
|
})
|
|
247
383
|
);
|
|
384
|
+
if (group)
|
|
385
|
+
await appendTrialReceipt(group.groupId, {
|
|
386
|
+
kind: "attempt-started",
|
|
387
|
+
trace: redactor.json(resultTrace)
|
|
388
|
+
});
|
|
248
389
|
adapters.studio?.created();
|
|
249
390
|
output(` ${plan.key} \xB7 ${run.id}`);
|
|
250
391
|
},
|
|
@@ -267,27 +408,20 @@ async function runCommand(path, options, adapters = {}) {
|
|
|
267
408
|
finishRun: async (id, result2) => {
|
|
268
409
|
if (localStore) await removeWatchState(root, id);
|
|
269
410
|
await store.finishRun(id, { ...result2, executionObservation: { ...engine.observation } });
|
|
411
|
+
if (group)
|
|
412
|
+
await appendTrialReceipt(group.groupId, {
|
|
413
|
+
kind: "attempt-finished",
|
|
414
|
+
attemptId: id,
|
|
415
|
+
at: await trialTime(result2.finishedAt),
|
|
416
|
+
verdict: result2.verdict,
|
|
417
|
+
...result2.attemptAudit && { audit: attemptAuditSchema.parse(result2.attemptAudit) },
|
|
418
|
+
observation: { ...engine.observation },
|
|
419
|
+
...result2.evidence && { evidence: result2.evidence },
|
|
420
|
+
...result2.outcome && { outcome: result2.outcome },
|
|
421
|
+
...result2.usage && { usage: result2.usage }
|
|
422
|
+
});
|
|
270
423
|
adapters.studio?.saved();
|
|
271
|
-
if (localStore)
|
|
272
|
-
try {
|
|
273
|
-
reports.set(id, await generateReport(root, id));
|
|
274
|
-
} catch {
|
|
275
|
-
output(
|
|
276
|
-
` Report not generated for ${id}; run result saved. Use open-qa open ${id} to inspect the run directory.`
|
|
277
|
-
);
|
|
278
|
-
}
|
|
279
|
-
const scan = await scanRunArtifacts(root, id, redactor);
|
|
280
|
-
await store.recordArtifactScan(id, scan);
|
|
281
|
-
scans.set(id, scan);
|
|
282
|
-
if (scan.status !== "passed") {
|
|
283
|
-
blocked.add(id);
|
|
284
|
-
reports.delete(id);
|
|
285
|
-
code = 2;
|
|
286
|
-
output(
|
|
287
|
-
` secret-leak \xB7 ${id} \xB7 artifact sharing blocked; inspect artifactScan in run.json locally`
|
|
288
|
-
);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
424
|
+
if (localStore) finished.push(id);
|
|
291
425
|
}
|
|
292
426
|
};
|
|
293
427
|
const engine = createEngine({
|
|
@@ -301,7 +435,12 @@ async function runCommand(path, options, adapters = {}) {
|
|
|
301
435
|
classifications: adapters.classifications ?? (localStore ? store : void 0),
|
|
302
436
|
targetRevision: adapters.targetRevision ?? (target.revision ? async () => target.revision : void 0),
|
|
303
437
|
flowRevision: flows[plans.indexOf(plan)].definitions.flow.sha256,
|
|
438
|
+
visualBaseline: { caseId, environment: targetName },
|
|
439
|
+
quarantine: config.quarantine,
|
|
440
|
+
quarantineCaseId: caseId,
|
|
441
|
+
quarantineTarget: targetName,
|
|
304
442
|
...adapters,
|
|
443
|
+
classificationScope,
|
|
305
444
|
flowStatus,
|
|
306
445
|
onStage: async (id, handle) => {
|
|
307
446
|
await adapters.onStage?.(id, handle);
|
|
@@ -341,6 +480,7 @@ async function runCommand(path, options, adapters = {}) {
|
|
|
341
480
|
stage: {
|
|
342
481
|
...Object.values(plan.views).some((view) => view.surface === "email") ? { email: requiredEmail(env) } : {},
|
|
343
482
|
systems: systems.get(plan),
|
|
483
|
+
redactions: accessBinding?.secrets,
|
|
344
484
|
headed: options.headed,
|
|
345
485
|
...Object.values(plan.views).some((view) => view.surface === "discord") ? { discord: { botToken: requiredDiscordToken(env) } } : {},
|
|
346
486
|
page: {
|
|
@@ -349,13 +489,68 @@ async function runCommand(path, options, adapters = {}) {
|
|
|
349
489
|
allowedHosts: target.allow,
|
|
350
490
|
targetOrigin: new URL(target.url).origin,
|
|
351
491
|
access,
|
|
352
|
-
|
|
492
|
+
accessHeaders: accessBinding?.accessHeaders,
|
|
493
|
+
permissions: actorPermissions(plan, providers)
|
|
353
494
|
}
|
|
354
495
|
}
|
|
355
496
|
});
|
|
497
|
+
const finalizeArtifacts = async () => {
|
|
498
|
+
if (!localStore) return;
|
|
499
|
+
for (const id of finished) {
|
|
500
|
+
try {
|
|
501
|
+
reports.set(id, await generateReport(root, id, config.projectId));
|
|
502
|
+
} catch {
|
|
503
|
+
output(
|
|
504
|
+
` Report not generated for ${id}; run result saved. Use open-qa open ${id} to inspect the run directory.`
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
let diagnostic;
|
|
508
|
+
try {
|
|
509
|
+
const scan = await scanRunArtifacts(root, id, redactor);
|
|
510
|
+
await store.recordArtifactScan(id, scan);
|
|
511
|
+
scans.set(id, scan);
|
|
512
|
+
if (scan.status === "passed") continue;
|
|
513
|
+
diagnostic = "inspect artifactScan in run.json locally";
|
|
514
|
+
} catch {
|
|
515
|
+
diagnostic = "could not complete and record the artifact scan";
|
|
516
|
+
}
|
|
517
|
+
blocked.add(id);
|
|
518
|
+
reports.delete(id);
|
|
519
|
+
code = 2;
|
|
520
|
+
output(` secret-leak \xB7 ${id} \xB7 artifact sharing blocked; ${diagnostic}`);
|
|
521
|
+
}
|
|
522
|
+
};
|
|
356
523
|
let result;
|
|
357
524
|
try {
|
|
358
|
-
result = await engine.run(plan, signal)
|
|
525
|
+
result = await engine.run(plan, signal).then(
|
|
526
|
+
async (completed) => {
|
|
527
|
+
await recordTrial(completed);
|
|
528
|
+
if (group && index === group.planned) {
|
|
529
|
+
await appendTrialReceipt(group.groupId, {
|
|
530
|
+
kind: "group-finished",
|
|
531
|
+
at: await trialTime()
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
if (localStore && flowStatus) {
|
|
535
|
+
const [state] = completed.quarantined && flowStatus instanceof PgFlowStatus ? await flowStatus.list([plan.key]) : [];
|
|
536
|
+
const deadline = state?.quarantineDeadline;
|
|
537
|
+
await store.recordQuarantine(
|
|
538
|
+
completed.runId,
|
|
539
|
+
completed.quarantined,
|
|
540
|
+
deadline?.overdue ? deadline.expiresAt : void 0
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
await finalizeArtifacts();
|
|
544
|
+
return completed;
|
|
545
|
+
},
|
|
546
|
+
async (error) => {
|
|
547
|
+
try {
|
|
548
|
+
await finalizeArtifacts();
|
|
549
|
+
} catch {
|
|
550
|
+
}
|
|
551
|
+
throw error;
|
|
552
|
+
}
|
|
553
|
+
);
|
|
359
554
|
} catch (error) {
|
|
360
555
|
if (!(error instanceof FlowStatusWriteError)) throw error;
|
|
361
556
|
const completed = error.result;
|
|
@@ -368,7 +563,8 @@ async function runCommand(path, options, adapters = {}) {
|
|
|
368
563
|
repeatResult.runs.push({
|
|
369
564
|
runId: completed.runId,
|
|
370
565
|
verdict: completed.verdict,
|
|
371
|
-
category: completed.category
|
|
566
|
+
category: completed.category,
|
|
567
|
+
...completed.taxonomy && { taxonomy: completed.taxonomy }
|
|
372
568
|
});
|
|
373
569
|
repeatResult.finishedAt = Date.now();
|
|
374
570
|
try {
|
|
@@ -385,7 +581,8 @@ async function runCommand(path, options, adapters = {}) {
|
|
|
385
581
|
repeatResult.runs.push({
|
|
386
582
|
runId: result.runId,
|
|
387
583
|
verdict: result.verdict,
|
|
388
|
-
category: result.category
|
|
584
|
+
category: result.category,
|
|
585
|
+
...result.taxonomy && { taxonomy: result.taxonomy }
|
|
389
586
|
});
|
|
390
587
|
if (!result.quarantined && localStore && notificationChannel)
|
|
391
588
|
for (const [id, notifications] of healEvents) {
|
|
@@ -410,7 +607,9 @@ async function runCommand(path, options, adapters = {}) {
|
|
|
410
607
|
for (const run of result.runs) {
|
|
411
608
|
const classification = (await store.getClassification(run.runId))?.classification;
|
|
412
609
|
if (classification)
|
|
413
|
-
output(
|
|
610
|
+
output(
|
|
611
|
+
` ${run.runId} \xB7 ${classification.category ?? "needs review"} \xB7 ${classification.reason}`
|
|
612
|
+
);
|
|
414
613
|
}
|
|
415
614
|
if (signal.aborted || result.verdict === "canceled") code = Math.max(code, 1);
|
|
416
615
|
else if (!result.quarantined)
|
|
@@ -423,11 +622,35 @@ async function runCommand(path, options, adapters = {}) {
|
|
|
423
622
|
}
|
|
424
623
|
if (options.repeat !== void 0) {
|
|
425
624
|
repeatResult.finishedAt = Date.now();
|
|
625
|
+
if (group) {
|
|
626
|
+
let history = await audit.get(group.groupId);
|
|
627
|
+
if (history && !history.receipts.some(({ kind }) => kind === "group-finished")) {
|
|
628
|
+
await appendTrialReceipt(group.groupId, {
|
|
629
|
+
kind: "group-finished",
|
|
630
|
+
at: await trialTime(repeatResult.finishedAt)
|
|
631
|
+
});
|
|
632
|
+
history = await audit.get(group.groupId);
|
|
633
|
+
}
|
|
634
|
+
if (history) printTrial(summarizeTrial(history), output);
|
|
635
|
+
if (database && flowStatus instanceof PgFlowStatus && quarantinedAtGroupStart) {
|
|
636
|
+
const decision = await flowStatus.autoRelease(group.flow, {
|
|
637
|
+
groupId: group.groupId,
|
|
638
|
+
generation: group.generation ?? -1,
|
|
639
|
+
caseId: group.caseId,
|
|
640
|
+
revision: group.caseRevision,
|
|
641
|
+
targetRevision: group.targetRevision,
|
|
642
|
+
policy: config.quarantine ?? quarantinePolicySchema.parse({})
|
|
643
|
+
});
|
|
644
|
+
output(
|
|
645
|
+
decision.ok ? ` ${group.flow} \xB7 quarantine released automatically` : ` ${group.flow} \xB7 automatic quarantine release denied \xB7 ${decision.reason}`
|
|
646
|
+
);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
426
649
|
await flowStatus?.saveRepeat(plans[0].key, repeatResult);
|
|
427
650
|
printRepeat(repeatResult, output);
|
|
428
651
|
if (!flowStatus)
|
|
429
652
|
output(
|
|
430
|
-
"Repeat result was not saved to QA PostgreSQL; configure QA_DATABASE_URL to
|
|
653
|
+
"Repeat result was not saved to QA PostgreSQL; configure QA_DATABASE_URL to check for automatic quarantine release"
|
|
431
654
|
);
|
|
432
655
|
}
|
|
433
656
|
output(`Batch usage: ${JSON.stringify(sumRunUsage(usage))}`);
|
package/src/run-setup-error.d.ts
CHANGED
|
@@ -7,5 +7,5 @@ export declare const setupReasons: {
|
|
|
7
7
|
};
|
|
8
8
|
export declare class RunSetupError extends Error {
|
|
9
9
|
readonly code: keyof typeof setupReasons;
|
|
10
|
-
constructor(code: keyof typeof setupReasons, detail: string);
|
|
10
|
+
constructor(code: keyof typeof setupReasons, detail: string, options?: ErrorOptions);
|
|
11
11
|
}
|
package/src/run-setup-error.js
CHANGED
|
@@ -6,8 +6,8 @@ const setupReasons = {
|
|
|
6
6
|
configuration: "Check the flow, environment and systems configuration. Run open-qa doctor for details."
|
|
7
7
|
};
|
|
8
8
|
class RunSetupError extends Error {
|
|
9
|
-
constructor(code, detail) {
|
|
10
|
-
super(detail);
|
|
9
|
+
constructor(code, detail, options) {
|
|
10
|
+
super(detail, options);
|
|
11
11
|
this.code = code;
|
|
12
12
|
}
|
|
13
13
|
code;
|
package/src/server/app.js
CHANGED
|
@@ -6,7 +6,8 @@ import { z } from "zod";
|
|
|
6
6
|
import {
|
|
7
7
|
replayCacheId,
|
|
8
8
|
parseReplayCacheId,
|
|
9
|
-
SecretRedactor
|
|
9
|
+
SecretRedactor,
|
|
10
|
+
ClassificationRegistryError
|
|
10
11
|
} from "@open-qa/qa-engine";
|
|
11
12
|
import {
|
|
12
13
|
classificationPatchSchema,
|
|
@@ -67,13 +68,13 @@ function createQaServer(options) {
|
|
|
67
68
|
})
|
|
68
69
|
);
|
|
69
70
|
app.onError((error, c) => {
|
|
71
|
+
const invalid = error instanceof z.ZodError || error instanceof SyntaxError || error instanceof InvalidRequest || error instanceof ClassificationRegistryError;
|
|
70
72
|
logFailure(
|
|
71
|
-
error instanceof ServerFailure ? error.category :
|
|
73
|
+
error instanceof ServerFailure ? error.category : invalid ? "invalid-request" : error instanceof Conflict ? "conflict" : "repository",
|
|
72
74
|
c.req.routePath,
|
|
73
75
|
c.get("project")
|
|
74
76
|
);
|
|
75
|
-
if (
|
|
76
|
-
return c.json({ error: "Invalid request" }, 400);
|
|
77
|
+
if (invalid) return c.json({ error: "Invalid request" }, 400);
|
|
77
78
|
if (error instanceof Conflict) return c.json({ error: "Conflicting request" }, 409);
|
|
78
79
|
return c.json({ error: "QA service unavailable" }, 503);
|
|
79
80
|
});
|
package/src/server/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ScreenAccess } from "../screen-url.js";
|
|
2
|
+
import { type ClassificationRegistry } from "@open-qa/qa-engine";
|
|
2
3
|
import { QaDatabase } from "../db/database.js";
|
|
3
4
|
import type { EventObjects } from "../db/event-chunks.js";
|
|
4
5
|
import { type AuthPolicy } from "./auth.js";
|
|
@@ -14,6 +15,7 @@ export declare function startQaServer(options: {
|
|
|
14
15
|
auth: AuthPolicy;
|
|
15
16
|
objects: EventObjects;
|
|
16
17
|
secrets: CredentialSecrets;
|
|
18
|
+
classificationRegistry?: ClassificationRegistry;
|
|
17
19
|
projects: Readonly<Record<string, {
|
|
18
20
|
secretProject: string;
|
|
19
21
|
}>>;
|
package/src/server/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { serve } from "@hono/node-server";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
loadClassificationRegistry,
|
|
4
|
+
SecretRedactor
|
|
5
|
+
} from "@open-qa/qa-engine";
|
|
3
6
|
import { PgClassificationStore } from "../adapters/pg-classification-store.js";
|
|
4
7
|
import { PgReplayCache } from "../adapters/pg-replay-cache.js";
|
|
5
8
|
import { DbLeasePool } from "../adapters/db-lease-pool.js";
|
|
@@ -34,10 +37,16 @@ function startQaServer(options) {
|
|
|
34
37
|
new PgReplayCache(options.db, project, redactor)
|
|
35
38
|
])
|
|
36
39
|
);
|
|
40
|
+
const registry = options.classificationRegistry ?? loadClassificationRegistry();
|
|
37
41
|
const classifications = new Map(
|
|
38
42
|
Object.keys(options.projects).map((project) => [
|
|
39
43
|
project,
|
|
40
|
-
new PgClassificationStore(
|
|
44
|
+
new PgClassificationStore(
|
|
45
|
+
options.db,
|
|
46
|
+
project,
|
|
47
|
+
void 0,
|
|
48
|
+
registry.findProject(project) ?? null
|
|
49
|
+
)
|
|
41
50
|
])
|
|
42
51
|
);
|
|
43
52
|
const credentials = new Map(
|