@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
|
@@ -1,58 +1,136 @@
|
|
|
1
1
|
import type { PoolClient } from "pg";
|
|
2
|
-
import type
|
|
3
|
-
import { type Classification } from "@open-qa/qa-engine/protocol";
|
|
2
|
+
import { type ClassificationStore, type ProjectClassificationRegistry } from "@open-qa/qa-engine";
|
|
3
|
+
import { type Classification, type ClassificationCorrection } from "@open-qa/qa-engine/protocol";
|
|
4
4
|
import { QaDatabase } from "../db/database.js";
|
|
5
|
+
export declare function savePgClassificationInTransaction(client: PoolClient, scope: ProjectClassificationRegistry, id: string, value: Classification, preservePrediction?: boolean): Promise<void>;
|
|
5
6
|
export declare class PgClassificationStore implements ClassificationStore {
|
|
6
7
|
private readonly db;
|
|
7
8
|
private readonly project;
|
|
8
9
|
private readonly guard?;
|
|
9
|
-
|
|
10
|
+
private readonly scope;
|
|
11
|
+
constructor(db: QaDatabase, project: string, guard?: ((client: PoolClient) => Promise<unknown>) | undefined, scope?: ProjectClassificationRegistry | null);
|
|
10
12
|
private read;
|
|
11
13
|
getClassification(id: string): Promise<{
|
|
12
14
|
classification: {
|
|
13
|
-
category:
|
|
15
|
+
category: string | null;
|
|
14
16
|
confidence: number;
|
|
15
17
|
reason: string;
|
|
16
|
-
source: "model" | "
|
|
18
|
+
source: "model" | "rule" | "fallback" | "human";
|
|
19
|
+
origin?: "unknown" | "judge" | "product" | "harness" | "infra" | undefined;
|
|
20
|
+
cause?: string | undefined;
|
|
21
|
+
taxonomy?: {
|
|
22
|
+
project: string;
|
|
23
|
+
version: string;
|
|
24
|
+
} | undefined;
|
|
25
|
+
flakiness?: "unknown" | "observed" | undefined;
|
|
26
|
+
needsReview?: boolean | undefined;
|
|
27
|
+
classifierVersion?: string | undefined;
|
|
28
|
+
rawPrediction?: {
|
|
29
|
+
category: string | null;
|
|
30
|
+
confidence: number;
|
|
31
|
+
reason: string;
|
|
32
|
+
origin?: "unknown" | "judge" | "product" | "harness" | "infra" | undefined;
|
|
33
|
+
cause?: string | undefined;
|
|
34
|
+
modelVersion?: string | undefined;
|
|
35
|
+
} | undefined;
|
|
17
36
|
} | null;
|
|
18
37
|
labels: {
|
|
19
|
-
category: "env" | "agent" | "product-bug" | "test-case" | "flaky";
|
|
20
38
|
reason: string;
|
|
39
|
+
category: string;
|
|
21
40
|
modifiedBy: string;
|
|
22
41
|
modifiedAt: number;
|
|
23
42
|
predicted: {
|
|
24
|
-
category:
|
|
43
|
+
category: string | null;
|
|
25
44
|
confidence: number;
|
|
26
45
|
reason: string;
|
|
27
|
-
source: "model" | "
|
|
46
|
+
source: "model" | "rule" | "fallback" | "human";
|
|
47
|
+
origin?: "unknown" | "judge" | "product" | "harness" | "infra" | undefined;
|
|
48
|
+
cause?: string | undefined;
|
|
49
|
+
taxonomy?: {
|
|
50
|
+
project: string;
|
|
51
|
+
version: string;
|
|
52
|
+
} | undefined;
|
|
53
|
+
flakiness?: "unknown" | "observed" | undefined;
|
|
54
|
+
needsReview?: boolean | undefined;
|
|
55
|
+
classifierVersion?: string | undefined;
|
|
56
|
+
rawPrediction?: {
|
|
57
|
+
category: string | null;
|
|
58
|
+
confidence: number;
|
|
59
|
+
reason: string;
|
|
60
|
+
origin?: "unknown" | "judge" | "product" | "harness" | "infra" | undefined;
|
|
61
|
+
cause?: string | undefined;
|
|
62
|
+
modelVersion?: string | undefined;
|
|
63
|
+
} | undefined;
|
|
28
64
|
} | null;
|
|
65
|
+
origin?: "unknown" | "judge" | "product" | "harness" | "infra" | undefined;
|
|
66
|
+
cause?: string | undefined;
|
|
67
|
+
flakiness?: "unknown" | "observed" | undefined;
|
|
68
|
+
taxonomy?: {
|
|
69
|
+
project: string;
|
|
70
|
+
version: string;
|
|
71
|
+
} | undefined;
|
|
29
72
|
}[];
|
|
30
73
|
} | undefined>;
|
|
31
|
-
private lock;
|
|
32
|
-
private write;
|
|
33
74
|
saveClassification(id: string, value: Classification): Promise<void>;
|
|
34
|
-
labelClassification(id: string, input: {
|
|
35
|
-
category: Classification["category"];
|
|
36
|
-
reason: string;
|
|
37
|
-
modifiedBy: string;
|
|
38
|
-
}): Promise<{
|
|
75
|
+
labelClassification(id: string, input: ClassificationCorrection): Promise<{
|
|
39
76
|
classification: {
|
|
40
|
-
category:
|
|
77
|
+
category: string | null;
|
|
41
78
|
confidence: number;
|
|
42
79
|
reason: string;
|
|
43
|
-
source: "model" | "
|
|
80
|
+
source: "model" | "rule" | "fallback" | "human";
|
|
81
|
+
origin?: "unknown" | "judge" | "product" | "harness" | "infra" | undefined;
|
|
82
|
+
cause?: string | undefined;
|
|
83
|
+
taxonomy?: {
|
|
84
|
+
project: string;
|
|
85
|
+
version: string;
|
|
86
|
+
} | undefined;
|
|
87
|
+
flakiness?: "unknown" | "observed" | undefined;
|
|
88
|
+
needsReview?: boolean | undefined;
|
|
89
|
+
classifierVersion?: string | undefined;
|
|
90
|
+
rawPrediction?: {
|
|
91
|
+
category: string | null;
|
|
92
|
+
confidence: number;
|
|
93
|
+
reason: string;
|
|
94
|
+
origin?: "unknown" | "judge" | "product" | "harness" | "infra" | undefined;
|
|
95
|
+
cause?: string | undefined;
|
|
96
|
+
modelVersion?: string | undefined;
|
|
97
|
+
} | undefined;
|
|
44
98
|
};
|
|
45
99
|
labels: {
|
|
46
|
-
category: "env" | "agent" | "product-bug" | "test-case" | "flaky";
|
|
47
100
|
reason: string;
|
|
101
|
+
category: string;
|
|
48
102
|
modifiedBy: string;
|
|
49
103
|
modifiedAt: number;
|
|
50
104
|
predicted: {
|
|
51
|
-
category:
|
|
105
|
+
category: string | null;
|
|
52
106
|
confidence: number;
|
|
53
107
|
reason: string;
|
|
54
|
-
source: "model" | "
|
|
108
|
+
source: "model" | "rule" | "fallback" | "human";
|
|
109
|
+
origin?: "unknown" | "judge" | "product" | "harness" | "infra" | undefined;
|
|
110
|
+
cause?: string | undefined;
|
|
111
|
+
taxonomy?: {
|
|
112
|
+
project: string;
|
|
113
|
+
version: string;
|
|
114
|
+
} | undefined;
|
|
115
|
+
flakiness?: "unknown" | "observed" | undefined;
|
|
116
|
+
needsReview?: boolean | undefined;
|
|
117
|
+
classifierVersion?: string | undefined;
|
|
118
|
+
rawPrediction?: {
|
|
119
|
+
category: string | null;
|
|
120
|
+
confidence: number;
|
|
121
|
+
reason: string;
|
|
122
|
+
origin?: "unknown" | "judge" | "product" | "harness" | "infra" | undefined;
|
|
123
|
+
cause?: string | undefined;
|
|
124
|
+
modelVersion?: string | undefined;
|
|
125
|
+
} | undefined;
|
|
55
126
|
} | null;
|
|
127
|
+
origin?: "unknown" | "judge" | "product" | "harness" | "infra" | undefined;
|
|
128
|
+
cause?: string | undefined;
|
|
129
|
+
flakiness?: "unknown" | "observed" | undefined;
|
|
130
|
+
taxonomy?: {
|
|
131
|
+
project: string;
|
|
132
|
+
version: string;
|
|
133
|
+
} | undefined;
|
|
56
134
|
}[];
|
|
57
135
|
}>;
|
|
58
136
|
}
|
|
@@ -1,19 +1,71 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import {
|
|
3
|
+
ClassificationRegistryError,
|
|
4
|
+
loadClassificationRegistry
|
|
5
|
+
} from "@open-qa/qa-engine";
|
|
1
6
|
import {
|
|
2
7
|
classificationSchema,
|
|
3
|
-
classificationLabelSchema
|
|
8
|
+
classificationLabelSchema,
|
|
9
|
+
readClassification
|
|
4
10
|
} from "@open-qa/qa-engine/protocol";
|
|
5
11
|
import { assertPostgresText, publicId } from "../db/database.js";
|
|
6
12
|
import { Conflict } from "../server/repository.js";
|
|
13
|
+
import { classificationCorrection, validateClassificationWrite } from "./classification-write.js";
|
|
14
|
+
const { taxonomy, origin, cause, flakiness } = classificationLabelSchema.shape;
|
|
15
|
+
const labelDetailsSchema = z.object({ taxonomy, origin, cause, flakiness });
|
|
16
|
+
async function lockClassifiableRun(client, project, id) {
|
|
17
|
+
publicId.parse(id);
|
|
18
|
+
const { rows } = await client.query(
|
|
19
|
+
"SELECT verdict,metadata->'failureClassification' AS previous FROM qa.runs WHERE project_id=$1 AND id=$2 FOR UPDATE",
|
|
20
|
+
[project, id]
|
|
21
|
+
);
|
|
22
|
+
if (!rows[0] || !["failed", "error"].includes(rows[0].verdict ?? ""))
|
|
23
|
+
throw new Conflict("Only failed/error runs can be classified");
|
|
24
|
+
return readClassification(rows[0].previous);
|
|
25
|
+
}
|
|
26
|
+
async function writeClassification(client, project, id, value) {
|
|
27
|
+
await client.query(
|
|
28
|
+
"UPDATE qa.runs SET classification=$3,metadata=jsonb_set(COALESCE(metadata,'{}'::jsonb),'{failureClassification}',$4::jsonb) WHERE project_id=$1 AND id=$2",
|
|
29
|
+
[project, id, value.category, JSON.stringify(value)]
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
async function savePgClassificationInTransaction(client, scope, id, value, preservePrediction = false) {
|
|
33
|
+
const project = scope.project;
|
|
34
|
+
const classification = validateClassificationWrite(scope, value);
|
|
35
|
+
assertPostgresText(classification);
|
|
36
|
+
const previous = await lockClassifiableRun(client, project, id);
|
|
37
|
+
const labels = await client.query(
|
|
38
|
+
"SELECT 1 FROM qa.classification_labels WHERE project_id=$1 AND run_id=$2 LIMIT 1",
|
|
39
|
+
[project, id]
|
|
40
|
+
);
|
|
41
|
+
if (labels.rowCount) return;
|
|
42
|
+
if (preservePrediction && previous) {
|
|
43
|
+
classification.rawPrediction = previous.rawPrediction ?? (previous.source === "model" ? {
|
|
44
|
+
category: previous.category,
|
|
45
|
+
confidence: previous.confidence,
|
|
46
|
+
reason: previous.reason,
|
|
47
|
+
origin: previous.origin,
|
|
48
|
+
cause: previous.cause,
|
|
49
|
+
modelVersion: previous.classifierVersion
|
|
50
|
+
} : void 0);
|
|
51
|
+
}
|
|
52
|
+
await writeClassification(client, project, id, classification);
|
|
53
|
+
}
|
|
7
54
|
class PgClassificationStore {
|
|
8
|
-
constructor(db, project, guard)
|
|
55
|
+
constructor(db, project, guard, scope = loadClassificationRegistry().findProject(
|
|
56
|
+
project
|
|
57
|
+
) ?? null) {
|
|
9
58
|
this.db = db;
|
|
10
59
|
this.project = project;
|
|
11
60
|
this.guard = guard;
|
|
61
|
+
this.scope = scope;
|
|
12
62
|
publicId.parse(project);
|
|
63
|
+
if (scope && scope.project !== project) throw new Error("Classification project mismatch");
|
|
13
64
|
}
|
|
14
65
|
db;
|
|
15
66
|
project;
|
|
16
67
|
guard;
|
|
68
|
+
scope;
|
|
17
69
|
async read(client, id) {
|
|
18
70
|
publicId.parse(id);
|
|
19
71
|
const { rows } = await client.query("SELECT classification,metadata FROM qa.runs WHERE project_id=$1 AND id=$2", [
|
|
@@ -22,19 +74,22 @@ class PgClassificationStore {
|
|
|
22
74
|
]);
|
|
23
75
|
if (!rows[0]) return void 0;
|
|
24
76
|
const labels = await client.query(
|
|
25
|
-
'SELECT category,reason,modified_by AS "modifiedBy",modified_at AS "modifiedAt",predicted FROM qa.classification_labels WHERE project_id=$1 AND run_id=$2 ORDER BY ordinal',
|
|
77
|
+
'SELECT category,reason,modified_by AS "modifiedBy",modified_at AS "modifiedAt",predicted,details FROM qa.classification_labels WHERE project_id=$1 AND run_id=$2 ORDER BY ordinal',
|
|
26
78
|
[this.project, id]
|
|
27
79
|
);
|
|
28
80
|
const category = rows[0].classification;
|
|
29
|
-
const metadata = rows[0].metadata?.failureClassification;
|
|
81
|
+
const metadata = readClassification(rows[0].metadata?.failureClassification);
|
|
30
82
|
return {
|
|
31
|
-
classification: metadata
|
|
83
|
+
classification: metadata ?? (category ? classificationSchema.parse({
|
|
32
84
|
category,
|
|
33
85
|
confidence: 0,
|
|
34
86
|
source: "fallback",
|
|
35
87
|
reason: "Legacy classification"
|
|
36
|
-
}) : null,
|
|
37
|
-
labels: labels.rows.map((row) =>
|
|
88
|
+
}) : null),
|
|
89
|
+
labels: labels.rows.map(({ details, ...row }) => {
|
|
90
|
+
const parsed = labelDetailsSchema.safeParse(details);
|
|
91
|
+
return classificationLabelSchema.parse({ ...parsed.success ? parsed.data : {}, ...row });
|
|
92
|
+
})
|
|
38
93
|
};
|
|
39
94
|
}
|
|
40
95
|
getClassification(id) {
|
|
@@ -47,44 +102,28 @@ class PgClassificationStore {
|
|
|
47
102
|
return this.read(client, id);
|
|
48
103
|
});
|
|
49
104
|
}
|
|
50
|
-
async lock(client, id) {
|
|
51
|
-
publicId.parse(id);
|
|
52
|
-
const { rows } = await client.query(
|
|
53
|
-
"SELECT verdict FROM qa.runs WHERE project_id=$1 AND id=$2 FOR UPDATE",
|
|
54
|
-
[this.project, id]
|
|
55
|
-
);
|
|
56
|
-
if (!rows[0] || !["failed", "error"].includes(rows[0].verdict ?? ""))
|
|
57
|
-
throw new Conflict("Only failed/error runs can be classified");
|
|
58
|
-
}
|
|
59
|
-
async write(client, id, value) {
|
|
60
|
-
await client.query(
|
|
61
|
-
"UPDATE qa.runs SET classification=$3,metadata=jsonb_set(COALESCE(metadata,'{}'::jsonb),'{failureClassification}',$4::jsonb) WHERE project_id=$1 AND id=$2",
|
|
62
|
-
[this.project, id, value.category, JSON.stringify(value)]
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
105
|
async saveClassification(id, value) {
|
|
66
|
-
|
|
67
|
-
|
|
106
|
+
const scope = this.scope;
|
|
107
|
+
if (!scope) throw new ClassificationRegistryError("Project has no classification taxonomy");
|
|
68
108
|
await this.db.transaction(async (client) => {
|
|
69
109
|
await this.guard?.(client);
|
|
70
|
-
await
|
|
71
|
-
const record = await this.read(client, id);
|
|
72
|
-
if (record.labels.length) return;
|
|
73
|
-
await this.write(client, id, value);
|
|
110
|
+
await savePgClassificationInTransaction(client, scope, id, value);
|
|
74
111
|
});
|
|
75
112
|
}
|
|
76
113
|
async labelClassification(id, input) {
|
|
114
|
+
const scope = this.scope;
|
|
115
|
+
if (!scope) throw new ClassificationRegistryError("Project has no classification taxonomy");
|
|
77
116
|
assertPostgresText(input);
|
|
78
117
|
return this.db.transaction(async (client) => {
|
|
79
|
-
await
|
|
118
|
+
await lockClassifiableRun(client, this.project, id);
|
|
80
119
|
const record = await this.read(client, id);
|
|
81
|
-
const label =
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
120
|
+
const { label, classification } = classificationCorrection(
|
|
121
|
+
scope,
|
|
122
|
+
input,
|
|
123
|
+
record.classification?.source === "human" ? record.labels[0]?.predicted ?? null : record.classification
|
|
124
|
+
);
|
|
86
125
|
await client.query(
|
|
87
|
-
"INSERT INTO qa.classification_labels(project_id,run_id,ordinal,category,reason,modified_by,modified_at,predicted) VALUES($1,$2,$3,$4,$5,$6,$7,$8)",
|
|
126
|
+
"INSERT INTO qa.classification_labels(project_id,run_id,ordinal,category,reason,modified_by,modified_at,predicted,details) VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9)",
|
|
88
127
|
[
|
|
89
128
|
this.project,
|
|
90
129
|
id,
|
|
@@ -93,20 +132,21 @@ class PgClassificationStore {
|
|
|
93
132
|
label.reason,
|
|
94
133
|
label.modifiedBy,
|
|
95
134
|
label.modifiedAt,
|
|
96
|
-
label.predicted
|
|
135
|
+
label.predicted,
|
|
136
|
+
{
|
|
137
|
+
taxonomy: label.taxonomy,
|
|
138
|
+
origin: label.origin,
|
|
139
|
+
cause: label.cause,
|
|
140
|
+
flakiness: label.flakiness
|
|
141
|
+
}
|
|
97
142
|
]
|
|
98
143
|
);
|
|
99
|
-
|
|
100
|
-
category: label.category,
|
|
101
|
-
reason: label.reason,
|
|
102
|
-
confidence: 1,
|
|
103
|
-
source: "human"
|
|
104
|
-
};
|
|
105
|
-
await this.write(client, id, classification);
|
|
144
|
+
await writeClassification(client, this.project, id, classification);
|
|
106
145
|
return { classification, labels: [...record.labels, label] };
|
|
107
146
|
});
|
|
108
147
|
}
|
|
109
148
|
}
|
|
110
149
|
export {
|
|
111
|
-
PgClassificationStore
|
|
150
|
+
PgClassificationStore,
|
|
151
|
+
savePgClassificationInTransaction
|
|
112
152
|
};
|
|
@@ -32,6 +32,7 @@ export declare class PgRunStore implements RunStore {
|
|
|
32
32
|
/** Persist batchId across retries. Different content under that ID is always rejected. */
|
|
33
33
|
appendChunk(runId: string, batchId: string, input: readonly RunEvent[]): Promise<void>;
|
|
34
34
|
finishRun(runId: string, input: FinishRun): Promise<void>;
|
|
35
|
+
recordClassifierUsage(runId: string, samples: Parameters<NonNullable<RunStore["recordClassifierUsage"]>>[1]): Promise<void>;
|
|
35
36
|
readFindings(runId: string): Promise<{
|
|
36
37
|
eventSeqs: number[];
|
|
37
38
|
shots: string[];
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
+
import { classifierAuditUpdate } from "../attempt-audit.js";
|
|
1
2
|
import { randomUUID } from "node:crypto";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
withExecutionObservation,
|
|
6
|
+
withExecutionBrowserViews
|
|
6
7
|
} from "@open-qa/qa-engine";
|
|
7
8
|
import {
|
|
8
9
|
findingSchema,
|
|
9
10
|
jsonObjectSchema,
|
|
10
11
|
millisecondsSchema,
|
|
11
12
|
verdictSchema,
|
|
12
|
-
runUsageSchema
|
|
13
|
+
runUsageSchema,
|
|
14
|
+
withResultDetails
|
|
13
15
|
} from "@open-qa/qa-engine/protocol";
|
|
14
16
|
import { publicId, assertPostgresText } from "../db/database.js";
|
|
15
17
|
import { assertFence } from "../db/fencing.js";
|
|
@@ -19,6 +21,7 @@ import {
|
|
|
19
21
|
readChunk
|
|
20
22
|
} from "../db/event-chunks.js";
|
|
21
23
|
import { PgQueries } from "../db/queries.js";
|
|
24
|
+
import { assertNewRunMetadata } from "./run-metadata.js";
|
|
22
25
|
const createSchema = z.strictObject({
|
|
23
26
|
id: publicId,
|
|
24
27
|
flow: z.string().min(1),
|
|
@@ -51,8 +54,7 @@ class PgRunStore {
|
|
|
51
54
|
async createRun(input) {
|
|
52
55
|
const run = createSchema.parse(input);
|
|
53
56
|
assertPostgresText(run);
|
|
54
|
-
|
|
55
|
-
throw new Error("Invalid execution snapshot");
|
|
57
|
+
assertNewRunMetadata(run.metadata);
|
|
56
58
|
try {
|
|
57
59
|
await this.db.pool.query(
|
|
58
60
|
`INSERT INTO qa.runs(project_id,id,flow,started_at,metadata) VALUES($1,$2,$3,$4,$5)`,
|
|
@@ -139,7 +141,15 @@ class PgRunStore {
|
|
|
139
141
|
}
|
|
140
142
|
async finishRun(runId, input) {
|
|
141
143
|
publicId.parse(runId);
|
|
142
|
-
const {
|
|
144
|
+
const {
|
|
145
|
+
executionObservation,
|
|
146
|
+
browserViews,
|
|
147
|
+
findings: rawFindings = [],
|
|
148
|
+
outcome: resultOutcome,
|
|
149
|
+
evidence,
|
|
150
|
+
attemptAudit,
|
|
151
|
+
...outcome
|
|
152
|
+
} = input;
|
|
143
153
|
const findings = z.array(findingSchema).parse(rawFindings);
|
|
144
154
|
assertPostgresText(findings);
|
|
145
155
|
const result = outcomeSchema.parse(outcome);
|
|
@@ -166,8 +176,21 @@ class PgRunStore {
|
|
|
166
176
|
]
|
|
167
177
|
);
|
|
168
178
|
}
|
|
169
|
-
const
|
|
170
|
-
|
|
179
|
+
const observedMetadata = executionObservation ? withExecutionObservation(run.metadata ?? void 0, executionObservation) : run.metadata;
|
|
180
|
+
const metadata = withResultDetails(
|
|
181
|
+
withExecutionBrowserViews(observedMetadata ?? void 0, browserViews),
|
|
182
|
+
{
|
|
183
|
+
engineResult: {
|
|
184
|
+
verdict: result.verdict,
|
|
185
|
+
reason: result.reason ?? null,
|
|
186
|
+
finishedAt: result.finishedAt
|
|
187
|
+
},
|
|
188
|
+
...resultOutcome && { outcome: resultOutcome },
|
|
189
|
+
...evidence && { evidence }
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
const updatedMetadata = attemptAudit ? { ...metadata, attemptAudit } : metadata;
|
|
193
|
+
assertPostgresText(updatedMetadata);
|
|
171
194
|
await client.query(
|
|
172
195
|
`UPDATE qa.runs SET verdict=$3,finished_at=$4,reason=$5,metadata=$6,usage=$7,error_reason=$8,cost_usd=COALESCE(($7::jsonb->>'costUsd')::double precision,cost_usd),phase='finished',heartbeat_at=clock_timestamp()
|
|
173
196
|
WHERE project_id=$1 AND id=$2`,
|
|
@@ -177,7 +200,7 @@ class PgRunStore {
|
|
|
177
200
|
result.verdict,
|
|
178
201
|
result.finishedAt,
|
|
179
202
|
result.reason,
|
|
180
|
-
|
|
203
|
+
updatedMetadata,
|
|
181
204
|
result.usage ? JSON.stringify(result.usage) : null,
|
|
182
205
|
result.errorReason
|
|
183
206
|
]
|
|
@@ -193,6 +216,44 @@ class PgRunStore {
|
|
|
193
216
|
);
|
|
194
217
|
});
|
|
195
218
|
}
|
|
219
|
+
async recordClassifierUsage(runId, samples) {
|
|
220
|
+
if (!samples.length) return;
|
|
221
|
+
await this.db.transaction(async (client) => {
|
|
222
|
+
const run = await this.lockRun(client, publicId.parse(runId));
|
|
223
|
+
await this.authorize(client, run);
|
|
224
|
+
if (!run.verdict) throw new Error("Classifier usage requires a finished attempt");
|
|
225
|
+
const receipt = JSON.stringify(samples);
|
|
226
|
+
const inserted = await client.query(
|
|
227
|
+
"INSERT INTO qa.audit_decisions(project_id,subject,key,document) VALUES($1,$2,'classifier-usage',$3) ON CONFLICT DO NOTHING",
|
|
228
|
+
[this.project, `attempt:${runId}`, receipt]
|
|
229
|
+
);
|
|
230
|
+
if (!inserted.rowCount) {
|
|
231
|
+
const { rowCount } = await client.query(
|
|
232
|
+
"SELECT 1 FROM qa.audit_decisions WHERE project_id=$1 AND subject=$2 AND key='classifier-usage' AND document=$3::jsonb",
|
|
233
|
+
[this.project, `attempt:${runId}`, receipt]
|
|
234
|
+
);
|
|
235
|
+
if (!rowCount) throw new Error("Conflicting immutable classifier usage");
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const updated = classifierAuditUpdate(
|
|
239
|
+
run.metadata ?? void 0,
|
|
240
|
+
run.usage ?? void 0,
|
|
241
|
+
samples
|
|
242
|
+
);
|
|
243
|
+
if (!updated) return;
|
|
244
|
+
assertPostgresText(updated.metadata);
|
|
245
|
+
await client.query(
|
|
246
|
+
"UPDATE qa.runs SET metadata=$3,usage=$4,cost_usd=COALESCE($5,cost_usd) WHERE project_id=$1 AND id=$2",
|
|
247
|
+
[
|
|
248
|
+
this.project,
|
|
249
|
+
runId,
|
|
250
|
+
updated.metadata,
|
|
251
|
+
JSON.stringify(updated.usage),
|
|
252
|
+
updated.usage?.costUsd
|
|
253
|
+
]
|
|
254
|
+
);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
196
257
|
async readFindings(runId) {
|
|
197
258
|
publicId.parse(runId);
|
|
198
259
|
const { rows } = await this.db.pool.query(
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { readExecutionSnapshot } from "@open-qa/qa-engine/protocol";
|
|
2
|
+
function assertNewRunMetadata(metadata) {
|
|
3
|
+
if (metadata?.failureClassification !== void 0)
|
|
4
|
+
throw new Error("Set failure classification through the classification store");
|
|
5
|
+
if (metadata?.executionSnapshot !== void 0 && readExecutionSnapshot(metadata.executionSnapshot).status !== "recorded")
|
|
6
|
+
throw new Error("Invalid execution snapshot");
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
assertNewRunMetadata
|
|
10
|
+
};
|
|
@@ -20,10 +20,10 @@ export interface CloudCredentialOptions {
|
|
|
20
20
|
}
|
|
21
21
|
declare const identitySchema: z.ZodObject<{
|
|
22
22
|
trigger: z.ZodEnum<{
|
|
23
|
+
deployment: "deployment";
|
|
23
24
|
developer: "developer";
|
|
24
25
|
"pr-label": "pr-label";
|
|
25
26
|
schedule: "schedule";
|
|
26
|
-
deployment: "deployment";
|
|
27
27
|
}>;
|
|
28
28
|
createdBy: z.ZodOptional<z.ZodString>;
|
|
29
29
|
requestedBy: z.ZodOptional<z.ZodString>;
|