@open-qa/qa 0.1.0-alpha.3 → 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 +54 -8
- 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/doctor-command.js +2 -1
- 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 +24 -18
- 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.css +1 -1
- package/src/report/browser.js +41 -41
- 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 +9 -0
- package/src/run-command.js +300 -63
- package/src/run-setup-error.d.ts +11 -0
- package/src/run-setup-error.js +18 -0
- 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-command.d.ts +1 -0
- package/src/studio-command.js +11 -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 +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/db/flow-status.js
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { isDeepStrictEqual } from "node:util";
|
|
1
3
|
import { z } from "zod";
|
|
2
4
|
import {
|
|
3
5
|
acceptance,
|
|
4
6
|
canRetire,
|
|
5
7
|
isFirstRun,
|
|
6
|
-
nextFlowStatus
|
|
8
|
+
nextFlowStatus,
|
|
9
|
+
quarantinePolicySchema
|
|
7
10
|
} from "@open-qa/qa-engine";
|
|
8
|
-
import {
|
|
9
|
-
|
|
11
|
+
import {
|
|
12
|
+
verdictSchema,
|
|
13
|
+
failureCategorySchema,
|
|
14
|
+
classificationFlakinessSchema,
|
|
15
|
+
taxonomyIdentitySchema
|
|
16
|
+
} from "@open-qa/qa-engine/protocol";
|
|
17
|
+
import {
|
|
18
|
+
publicId,
|
|
19
|
+
assertPostgresText,
|
|
20
|
+
clockMs,
|
|
21
|
+
postgresAuditContext
|
|
22
|
+
} from "./database.js";
|
|
23
|
+
import { readTrialHistory } from "./trial-audit.js";
|
|
24
|
+
import { summarizeTrial } from "../trial-audit.js";
|
|
25
|
+
import { resultCaseId } from "../result-trace.js";
|
|
10
26
|
const flowKey = z.string().min(1).max(500).refine(
|
|
11
27
|
(value) => [...value].every((char) => char.charCodeAt(0) >= 32 && char.charCodeAt(0) !== 127)
|
|
12
28
|
);
|
|
@@ -15,6 +31,7 @@ const projectRow = (row) => ({
|
|
|
15
31
|
status: row.status,
|
|
16
32
|
flakyStreak: row.flaky_streak,
|
|
17
33
|
owner: row.owner,
|
|
34
|
+
generation: row.generation,
|
|
18
35
|
latestRepeat: row.latest_repeat,
|
|
19
36
|
firstRun: row.first_run_id && row.first_run_at ? {
|
|
20
37
|
runId: row.first_run_id,
|
|
@@ -27,6 +44,24 @@ const projectRow = (row) => ({
|
|
|
27
44
|
});
|
|
28
45
|
const revisionSchema = z.string().regex(/^[a-f0-9]{64}$/);
|
|
29
46
|
const actorSchema = z.string().min(1).max(200);
|
|
47
|
+
const quarantineEntrySchema = z.strictObject({
|
|
48
|
+
schemaVersion: z.literal(1),
|
|
49
|
+
action: z.literal("quarantine-entered"),
|
|
50
|
+
generation: z.number().int().positive(),
|
|
51
|
+
actor: z.literal("open-qa"),
|
|
52
|
+
dbUser: actorSchema.optional(),
|
|
53
|
+
host: z.string().optional(),
|
|
54
|
+
at: z.number(),
|
|
55
|
+
expiresAt: z.number(),
|
|
56
|
+
owner: z.string().nullable(),
|
|
57
|
+
reason: z.string(),
|
|
58
|
+
fixIssue: z.string().nullable(),
|
|
59
|
+
caseId: z.string(),
|
|
60
|
+
revision: z.string().nullable(),
|
|
61
|
+
target: z.string().nullable(),
|
|
62
|
+
evidence: z.strictObject({ attemptId: publicId })
|
|
63
|
+
});
|
|
64
|
+
const quarantineSubject = (flow) => `quarantine:${flow}`;
|
|
30
65
|
const repeatSchema = z.object({
|
|
31
66
|
startedAt: z.number().finite().nonnegative(),
|
|
32
67
|
finishedAt: z.number().finite().nonnegative(),
|
|
@@ -36,7 +71,8 @@ const repeatSchema = z.object({
|
|
|
36
71
|
z.object({
|
|
37
72
|
runId: publicId,
|
|
38
73
|
verdict: verdictSchema,
|
|
39
|
-
category: failureCategorySchema.nullable()
|
|
74
|
+
category: failureCategorySchema.nullable(),
|
|
75
|
+
taxonomy: taxonomyIdentitySchema.optional()
|
|
40
76
|
})
|
|
41
77
|
).max(100)
|
|
42
78
|
}).refine((value) => value.finishedAt >= value.startedAt && value.runs.length <= value.requested);
|
|
@@ -56,12 +92,26 @@ class PgFlowStatus {
|
|
|
56
92
|
);
|
|
57
93
|
return rows[0] ? projectRow(rows[0]) : void 0;
|
|
58
94
|
}
|
|
59
|
-
async list() {
|
|
60
|
-
const { rows } = await
|
|
61
|
-
|
|
62
|
-
|
|
95
|
+
async list(flows, client = this.db.pool) {
|
|
96
|
+
const { rows } = await client.query(
|
|
97
|
+
`SELECT s.*, d.document AS entry, time.checked_at
|
|
98
|
+
FROM qa.flow_statuses s
|
|
99
|
+
CROSS JOIN (SELECT ${clockMs} AS checked_at) time
|
|
100
|
+
LEFT JOIN qa.audit_decisions d ON d.project_id=s.project_id
|
|
101
|
+
AND d.subject='quarantine:' || s.flow AND d.key='entry:' || s.generation
|
|
102
|
+
WHERE s.project_id=$1 AND s.status='quarantined'
|
|
103
|
+
AND ($2::text[] IS NULL OR s.flow=ANY($2::text[])) ORDER BY s.flow`,
|
|
104
|
+
[this.projectId, flows ?? null]
|
|
63
105
|
);
|
|
64
|
-
return rows.map(
|
|
106
|
+
return rows.map((row) => {
|
|
107
|
+
const entry = quarantineEntrySchema.safeParse(row.entry);
|
|
108
|
+
const status = projectRow(row);
|
|
109
|
+
if (entry.success) {
|
|
110
|
+
const { expiresAt } = entry.data;
|
|
111
|
+
status.quarantineDeadline = { expiresAt, overdue: expiresAt <= row.checked_at };
|
|
112
|
+
}
|
|
113
|
+
return status;
|
|
114
|
+
});
|
|
65
115
|
}
|
|
66
116
|
record(input) {
|
|
67
117
|
return this.db.transaction((client) => this.recordInTransaction(client, input));
|
|
@@ -71,6 +121,7 @@ class PgFlowStatus {
|
|
|
71
121
|
publicId.parse(input.executionId);
|
|
72
122
|
verdictSchema.parse(input.verdict);
|
|
73
123
|
failureCategorySchema.nullable().parse(input.category);
|
|
124
|
+
classificationFlakinessSchema.optional().parse(input.flakiness);
|
|
74
125
|
if (input.owner !== void 0) z.string().min(1).max(200).parse(input.owner);
|
|
75
126
|
if (input.revision !== void 0) revisionSchema.parse(input.revision);
|
|
76
127
|
assertPostgresText(input);
|
|
@@ -93,10 +144,19 @@ class PgFlowStatus {
|
|
|
93
144
|
return { quarantined: !!previous.rows[0].quarantined, status: locked.rows[0].status };
|
|
94
145
|
}
|
|
95
146
|
const row = locked.rows[0];
|
|
96
|
-
const
|
|
147
|
+
const policy = quarantinePolicySchema.parse(input.quarantine?.policy ?? {});
|
|
148
|
+
const next = nextFlowStatus(
|
|
149
|
+
projectRow(row),
|
|
150
|
+
input.verdict,
|
|
151
|
+
input.category,
|
|
152
|
+
input.revision,
|
|
153
|
+
input.flakiness,
|
|
154
|
+
policy.flakyStreak
|
|
155
|
+
);
|
|
97
156
|
const entered = row.status === "active" && next.status === "quarantined";
|
|
98
157
|
const generation = row.generation + (entered ? 1 : 0);
|
|
99
|
-
const
|
|
158
|
+
const details = Object.hasOwn(policy.flows, input.flow) ? policy.flows[input.flow] : void 0;
|
|
159
|
+
const owner = details?.owner ?? input.owner ?? row.owner;
|
|
100
160
|
await client.query(
|
|
101
161
|
"UPDATE qa.flow_statuses SET status=$3,flaky_streak=$4,generation=$5,owner=$6 WHERE project_id=$1 AND flow=$2",
|
|
102
162
|
[...key, next.status, next.flakyStreak, generation, owner]
|
|
@@ -110,16 +170,36 @@ class PgFlowStatus {
|
|
|
110
170
|
"INSERT INTO qa.flow_results(project_id,execution_id,flow,quarantined) VALUES($1,$2,$3,$4)",
|
|
111
171
|
[this.projectId, input.executionId, input.flow, next.status === "quarantined" ? 1 : 0]
|
|
112
172
|
);
|
|
113
|
-
if (entered)
|
|
173
|
+
if (entered) {
|
|
114
174
|
await client.query(
|
|
115
175
|
"INSERT INTO qa.quarantine_notifications(project_id,flow,generation,run_id,owner) VALUES($1,$2,$3,$4,$5)",
|
|
116
176
|
[...key, generation, input.executionId, owner]
|
|
117
177
|
);
|
|
178
|
+
const receipt = await postgresAuditContext(client);
|
|
179
|
+
const entry = quarantineEntrySchema.parse({
|
|
180
|
+
schemaVersion: 1,
|
|
181
|
+
action: "quarantine-entered",
|
|
182
|
+
generation,
|
|
183
|
+
actor: "open-qa",
|
|
184
|
+
...receipt,
|
|
185
|
+
expiresAt: receipt.at + policy.expiresAfterHours * 36e5,
|
|
186
|
+
owner,
|
|
187
|
+
reason: details?.reason ?? `Flaky result threshold reached (${policy.flakyStreak})`,
|
|
188
|
+
fixIssue: details?.fixIssue ?? null,
|
|
189
|
+
caseId: input.quarantine?.caseId ?? resultCaseId(this.projectId, input.flow),
|
|
190
|
+
revision: input.revision ?? null,
|
|
191
|
+
target: input.quarantine?.target ?? null,
|
|
192
|
+
evidence: { attemptId: input.executionId }
|
|
193
|
+
});
|
|
194
|
+
await this.appendDecision(client, input.flow, `entry:${generation}`, entry);
|
|
195
|
+
}
|
|
118
196
|
return { quarantined: next.status === "quarantined", status: next.status };
|
|
119
197
|
}
|
|
120
198
|
async saveRepeat(flow, result) {
|
|
121
199
|
flowKey.parse(flow);
|
|
122
200
|
repeatSchema.parse(result);
|
|
201
|
+
if (result.runs.some(({ taxonomy }) => taxonomy && taxonomy.project !== this.projectId))
|
|
202
|
+
throw new Error("Classification project mismatch");
|
|
123
203
|
assertPostgresText(result);
|
|
124
204
|
await this.db.pool.query(
|
|
125
205
|
`INSERT INTO qa.flow_statuses(project_id,flow,status,latest_repeat) VALUES($1,$2,'draft',$3::jsonb)
|
|
@@ -128,13 +208,157 @@ class PgFlowStatus {
|
|
|
128
208
|
[this.projectId, flow, JSON.stringify(result), result.startedAt]
|
|
129
209
|
);
|
|
130
210
|
}
|
|
131
|
-
async
|
|
211
|
+
async quarantineHistory(flow) {
|
|
132
212
|
flowKey.parse(flow);
|
|
133
213
|
const { rows } = await this.db.pool.query(
|
|
134
|
-
"
|
|
135
|
-
[this.projectId, flow]
|
|
214
|
+
"SELECT document FROM qa.audit_decisions WHERE project_id=$1 AND subject=$2 ORDER BY (document->>'at')::double precision,key",
|
|
215
|
+
[this.projectId, quarantineSubject(flow)]
|
|
216
|
+
);
|
|
217
|
+
return rows.map(({ document }) => document);
|
|
218
|
+
}
|
|
219
|
+
release(flow, input) {
|
|
220
|
+
return this.decideRelease(flow, input, "manual");
|
|
221
|
+
}
|
|
222
|
+
autoRelease(flow, input) {
|
|
223
|
+
return this.decideRelease(flow, { ...input, actor: "open-qa" }, "automatic");
|
|
224
|
+
}
|
|
225
|
+
async decideRelease(flow, input, mode) {
|
|
226
|
+
flowKey.parse(flow);
|
|
227
|
+
actorSchema.parse(input.actor);
|
|
228
|
+
assertPostgresText(input);
|
|
229
|
+
return this.db.transaction(async (client) => {
|
|
230
|
+
const key = [this.projectId, flow];
|
|
231
|
+
const { rows } = await client.query(
|
|
232
|
+
"SELECT * FROM qa.flow_statuses WHERE project_id=$1 AND flow=$2 FOR UPDATE",
|
|
233
|
+
key
|
|
234
|
+
);
|
|
235
|
+
const current = rows[0];
|
|
236
|
+
const policy = quarantinePolicySchema.parse(input.policy);
|
|
237
|
+
const identity = await postgresAuditContext(client);
|
|
238
|
+
const { at } = identity;
|
|
239
|
+
const { minimumPassedTrials, evidenceMaxAgeHours, expiresAfterHours, flakyStreak } = policy;
|
|
240
|
+
const expectedGroupPolicy = {
|
|
241
|
+
minimumPassedTrials,
|
|
242
|
+
evidenceMaxAgeHours,
|
|
243
|
+
expiresAfterHours,
|
|
244
|
+
flakyStreak
|
|
245
|
+
};
|
|
246
|
+
const reason = Array.from(input.reason?.trim() ?? "");
|
|
247
|
+
const conditions = {
|
|
248
|
+
requested: {
|
|
249
|
+
generation: input.generation,
|
|
250
|
+
caseId: input.caseId ?? null,
|
|
251
|
+
revision: input.revision ?? null,
|
|
252
|
+
...input.targetRevision !== void 0 && { targetRevision: input.targetRevision }
|
|
253
|
+
},
|
|
254
|
+
current: current ? { status: current.status, generation: current.generation } : null,
|
|
255
|
+
entry: null
|
|
256
|
+
};
|
|
257
|
+
const receipt = {
|
|
258
|
+
schemaVersion: 1,
|
|
259
|
+
action: "quarantine-release",
|
|
260
|
+
mode,
|
|
261
|
+
actor: input.actor,
|
|
262
|
+
...identity,
|
|
263
|
+
reason: reason.slice(0, 500).join("") || null,
|
|
264
|
+
generation: input.generation,
|
|
265
|
+
evidence: { groupId: input.groupId },
|
|
266
|
+
legacy: null,
|
|
267
|
+
overdue: null,
|
|
268
|
+
conditions,
|
|
269
|
+
policy,
|
|
270
|
+
groupPolicy: null
|
|
271
|
+
};
|
|
272
|
+
const write = (decision) => this.appendDecision(client, flow, `release:${randomUUID()}`, { ...receipt, decision });
|
|
273
|
+
const deny = async (reason2) => {
|
|
274
|
+
await write(reason2);
|
|
275
|
+
return { ok: false, reason: reason2 };
|
|
276
|
+
};
|
|
277
|
+
if (mode === "manual" && !policy.releaseActors.includes(input.actor))
|
|
278
|
+
return deny("unauthorized");
|
|
279
|
+
if (reason.length > 500) return deny("invalid-reason");
|
|
280
|
+
if (!input.groupId) return deny("missing-trial-group");
|
|
281
|
+
const entryResult = await client.query(
|
|
282
|
+
"SELECT document FROM qa.audit_decisions WHERE project_id=$1 AND subject=$2 AND key=$3",
|
|
283
|
+
[this.projectId, quarantineSubject(flow), `entry:${input.generation}`]
|
|
284
|
+
);
|
|
285
|
+
const storedEntry = entryResult.rows[0];
|
|
286
|
+
const parsedEntry = quarantineEntrySchema.safeParse(storedEntry?.document);
|
|
287
|
+
const entry = parsedEntry.data;
|
|
288
|
+
if (entry) {
|
|
289
|
+
receipt.legacy = false;
|
|
290
|
+
receipt.overdue = entry.expiresAt <= at;
|
|
291
|
+
conditions.entry = {
|
|
292
|
+
caseId: entry.caseId,
|
|
293
|
+
revision: entry.revision,
|
|
294
|
+
target: entry.target,
|
|
295
|
+
at: entry.at,
|
|
296
|
+
expiresAt: entry.expiresAt
|
|
297
|
+
};
|
|
298
|
+
} else if (!storedEntry && current?.generation === input.generation) {
|
|
299
|
+
receipt.legacy = true;
|
|
300
|
+
}
|
|
301
|
+
if (!current || current.status !== "quarantined") return deny("not-quarantined");
|
|
302
|
+
if (current.generation !== input.generation) return deny("generation-mismatch");
|
|
303
|
+
if (storedEntry && !entry) return deny("invalid-quarantine-entry");
|
|
304
|
+
const history = await readTrialHistory(client, this.projectId, input.groupId);
|
|
305
|
+
if (!history) return deny("missing-trial-group");
|
|
306
|
+
const { group } = history;
|
|
307
|
+
receipt.groupPolicy = group.quarantinePolicy ?? null;
|
|
308
|
+
conditions.group = {
|
|
309
|
+
flow: group.flow,
|
|
310
|
+
generation: group.generation,
|
|
311
|
+
caseId: group.caseId,
|
|
312
|
+
revision: group.caseRevision,
|
|
313
|
+
target: group.target,
|
|
314
|
+
targetRevision: group.targetRevision,
|
|
315
|
+
startedAt: group.startedAt,
|
|
316
|
+
planned: group.planned
|
|
317
|
+
};
|
|
318
|
+
const matches = {
|
|
319
|
+
flow: group.flow === flow,
|
|
320
|
+
generation: group.generation === input.generation,
|
|
321
|
+
requestedCaseId: group.caseId === input.caseId,
|
|
322
|
+
revision: group.caseRevision === input.revision,
|
|
323
|
+
...entry && {
|
|
324
|
+
entryCaseId: group.caseId === entry.caseId,
|
|
325
|
+
target: Boolean(entry.target) && group.target === entry.target
|
|
326
|
+
},
|
|
327
|
+
...input.targetRevision !== void 0 && {
|
|
328
|
+
targetRevision: input.targetRevision === group.targetRevision
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
conditions.matches = matches;
|
|
332
|
+
if (!Object.values(matches).every(Boolean)) return deny("trial-conditions-mismatch");
|
|
333
|
+
if (!isDeepStrictEqual(receipt.groupPolicy, expectedGroupPolicy))
|
|
334
|
+
return deny("trial-policy-mismatch");
|
|
335
|
+
const summary = summarizeTrial(history);
|
|
336
|
+
conditions.trials = {
|
|
337
|
+
finishedAt: summary.finishedAt,
|
|
338
|
+
firstPassed: summary.first.passed,
|
|
339
|
+
firstEligible: summary.first.n,
|
|
340
|
+
finalPassed: summary.final.passed,
|
|
341
|
+
finalEligible: summary.final.n,
|
|
342
|
+
completed: summary.completed,
|
|
343
|
+
comparable: summary.confidence.comparable
|
|
344
|
+
};
|
|
345
|
+
if (entry && group.startedAt < entry.at || group.startedAt > at || !summary.finishedAt || summary.completed !== group.planned || summary.counts.canceled > 0 || summary.finishedAt < group.startedAt || summary.finishedAt > at || summary.finishedAt < at - policy.evidenceMaxAgeHours * 36e5)
|
|
346
|
+
return deny("trial-incomplete-or-expired");
|
|
347
|
+
if (summary.first.passed !== summary.first.n || summary.final.passed !== summary.final.n || summary.final.n < minimumPassedTrials || !summary.confidence.comparable)
|
|
348
|
+
return deny("trial-policy-not-met");
|
|
349
|
+
const updated = await client.query(
|
|
350
|
+
"UPDATE qa.flow_statuses SET status='active',flaky_streak=0 WHERE project_id=$1 AND flow=$2 RETURNING *",
|
|
351
|
+
key
|
|
352
|
+
);
|
|
353
|
+
await write("released");
|
|
354
|
+
return { ok: true, status: projectRow(updated.rows[0]) };
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
async appendDecision(client, flow, key, decision) {
|
|
358
|
+
await client.query(
|
|
359
|
+
"INSERT INTO qa.audit_decisions(project_id,subject,key,document) VALUES($1,$2,$3,$4)",
|
|
360
|
+
[this.projectId, quarantineSubject(flow), key, JSON.stringify(decision)]
|
|
136
361
|
);
|
|
137
|
-
return rows[0] ? projectRow(rows[0]) : void 0;
|
|
138
362
|
}
|
|
139
363
|
async states(flows) {
|
|
140
364
|
for (const flow of flows) flowKey.parse(flow);
|
package/src/db/queries.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type BatchUsage, type RunUsage, type FinishRun, type CreateRun } from "@open-qa/qa-engine";
|
|
2
|
-
import type
|
|
2
|
+
import { type Verdict } from "@open-qa/qa-engine/protocol";
|
|
3
3
|
import { QaDatabase } from "./database.js";
|
|
4
4
|
import type { ResourceReference } from "./resources.js";
|
|
5
5
|
export interface StoredRun {
|
|
@@ -53,6 +53,29 @@ export declare class PgQueries implements RunQueries, ResourceQueries {
|
|
|
53
53
|
private readonly project;
|
|
54
54
|
constructor(db: QaDatabase, project: string);
|
|
55
55
|
getRun(id: string): Promise<StoredRun | undefined>;
|
|
56
|
+
reportAttempts(id: string, batch: boolean): Promise<{
|
|
57
|
+
quarantined?: boolean | undefined;
|
|
58
|
+
batchId: string | null;
|
|
59
|
+
findings: {
|
|
60
|
+
eventSeqs: number[];
|
|
61
|
+
shots: string[];
|
|
62
|
+
actor: string;
|
|
63
|
+
step: string;
|
|
64
|
+
category: "scope" | "other";
|
|
65
|
+
severity: "low" | "medium" | "high";
|
|
66
|
+
description: string;
|
|
67
|
+
}[];
|
|
68
|
+
run: CreateRun;
|
|
69
|
+
eventIndex: {
|
|
70
|
+
bytes: number;
|
|
71
|
+
count: number;
|
|
72
|
+
lastSeq: number;
|
|
73
|
+
lastT: number;
|
|
74
|
+
};
|
|
75
|
+
result?: Pick<FinishRun, "verdict" | "finishedAt" | "reason" | "usage" | "errorReason"> & {
|
|
76
|
+
costStatus: "recorded" | "unavailable";
|
|
77
|
+
};
|
|
78
|
+
}[]>;
|
|
56
79
|
listRuns(filter?: RunFilter): Promise<StoredRun[]>;
|
|
57
80
|
recentUsage(flow: string): Promise<RunUsage[]>;
|
|
58
81
|
batchUsage(batchId: string): Promise<BatchUsage>;
|
package/src/db/queries.js
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
batchUsageSchema,
|
|
4
4
|
runUsageSchema
|
|
5
5
|
} from "@open-qa/qa-engine";
|
|
6
|
+
import { findingSchema } from "@open-qa/qa-engine/protocol";
|
|
6
7
|
import { publicId } from "./database.js";
|
|
7
8
|
function toStoredRun(row) {
|
|
8
9
|
return {
|
|
@@ -47,6 +48,27 @@ class PgQueries {
|
|
|
47
48
|
);
|
|
48
49
|
return rows[0] ? toStoredRun(rows[0]) : void 0;
|
|
49
50
|
}
|
|
51
|
+
async reportAttempts(id, batch) {
|
|
52
|
+
publicId.parse(id);
|
|
53
|
+
const { rows } = await this.db.pool.query(
|
|
54
|
+
`SELECT r.*, COALESCE((SELECT jsonb_agg(jsonb_build_object(
|
|
55
|
+
'actor', f.actor, 'step', f.step, 'category', f.category, 'severity', f.severity,
|
|
56
|
+
'description', f.description, 'eventSeqs', f.event_seqs, 'shots', f.shots
|
|
57
|
+
) ORDER BY f.ordinal) FROM qa.findings f
|
|
58
|
+
WHERE f.project_id=r.project_id AND f.run_id=r.id), '[]'::jsonb) AS findings, fr.quarantined
|
|
59
|
+
FROM qa.runs r LEFT JOIN qa.flow_results fr ON fr.project_id=r.project_id AND fr.execution_id=r.id
|
|
60
|
+
WHERE r.project_id=$1 AND
|
|
61
|
+
(($3::boolean AND (r.batch_id=$2 OR r.metadata->>'batchId'=$2 OR r.metadata->'resultTrace'->>'batchId'=$2))
|
|
62
|
+
OR (NOT $3::boolean AND r.flow=(SELECT flow FROM qa.runs WHERE project_id=$1 AND id=$2)))`,
|
|
63
|
+
[this.project, id, batch]
|
|
64
|
+
);
|
|
65
|
+
return rows.map((row) => ({
|
|
66
|
+
...toStoredRun(row),
|
|
67
|
+
batchId: row.batch_id,
|
|
68
|
+
findings: row.findings.map((finding) => findingSchema.parse(finding)),
|
|
69
|
+
...row.quarantined !== null && { quarantined: row.quarantined === 1 }
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
50
72
|
async listRuns(filter = {}) {
|
|
51
73
|
const limit = filter.limit ?? 20;
|
|
52
74
|
if (!Number.isInteger(limit) || limit < 0 || limit > 1e3)
|