@riddledc/riddle-proof 0.8.77 → 0.8.78
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/README.md +65 -3
- package/dist/advanced/index.d.cts +1 -1
- package/dist/advanced/index.d.ts +1 -1
- package/dist/advanced/proof-run-engine.d.cts +1 -1
- package/dist/advanced/proof-run-engine.d.ts +1 -1
- package/dist/change-proof.cjs +744 -85
- package/dist/change-proof.d.cts +100 -8
- package/dist/change-proof.d.ts +100 -8
- package/dist/change-proof.js +15 -1
- package/dist/{chunk-B2DP2LET.js → chunk-5IFZSUPF.js} +52 -13
- package/dist/chunk-6VFS2JFR.js +886 -0
- package/dist/{chunk-IY4W6STC.js → chunk-7N6X54WG.js} +116 -17
- package/dist/{chunk-GG2D3MFZ.js → chunk-FCSJZBC5.js} +26 -1
- package/dist/{chunk-H25IDX76.js → chunk-HSGZV2NK.js} +206 -35
- package/dist/chunk-MEVVL4TI.js +258 -0
- package/dist/{chunk-UE4I7RTI.js → chunk-RQPCKRKT.js} +1 -1
- package/dist/cli/index.js +7 -6
- package/dist/cli.cjs +2009 -1058
- package/dist/cli.js +7 -6
- package/dist/index.cjs +932 -122
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +42 -14
- package/dist/pr-comment.cjs +416 -17
- package/dist/pr-comment.d.cts +6 -1
- package/dist/pr-comment.d.ts +6 -1
- package/dist/pr-comment.js +6 -1
- package/dist/profile/index.cjs +26 -1
- package/dist/profile/index.js +1 -1
- package/dist/profile-suggestions.js +2 -2
- package/dist/profile.cjs +26 -1
- package/dist/profile.d.cts +7 -0
- package/dist/profile.d.ts +7 -0
- package/dist/profile.js +1 -1
- package/dist/{proof-run-engine-MiKZt9oY.d.ts → proof-run-engine-CsQshTUX.d.ts} +3 -3
- package/dist/{proof-run-engine-Baiv6l3A.d.cts → proof-run-engine-DmUqh7Cw.d.cts} +3 -3
- package/dist/proof-run-engine.d.cts +1 -1
- package/dist/proof-run-engine.d.ts +1 -1
- package/dist/receipts.cjs +286 -0
- package/dist/receipts.d.cts +115 -0
- package/dist/receipts.d.ts +115 -0
- package/dist/receipts.js +15 -0
- package/dist/riddle-client.cjs +98 -13
- package/dist/riddle-client.d.cts +18 -5
- package/dist/riddle-client.d.ts +18 -5
- package/dist/riddle-client.js +4 -1
- package/dist/runtime/index.cjs +98 -13
- package/dist/runtime/index.d.cts +5 -1
- package/dist/runtime/index.d.ts +5 -1
- package/dist/runtime/index.js +4 -1
- package/dist/runtime/riddle-client.cjs +98 -13
- package/dist/runtime/riddle-client.d.cts +5 -1
- package/dist/runtime/riddle-client.d.ts +5 -1
- package/dist/runtime/riddle-client.js +4 -1
- package/package.json +7 -2
- package/dist/chunk-BILL3UC2.js +0 -488
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
// src/receipts.ts
|
|
2
|
+
var RIDDLE_PREVIEW_RECEIPT_VERSION = "riddle.preview-receipt.v1";
|
|
3
|
+
var RIDDLE_PROOF_OBSERVATION_RECEIPT_VERSION = "riddle-proof.observation-receipt.v1";
|
|
4
|
+
function isRecord(value) {
|
|
5
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
6
|
+
}
|
|
7
|
+
function requiredString(record, key, context) {
|
|
8
|
+
const value = record[key];
|
|
9
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
10
|
+
throw new Error(`${context}.${key} must be a non-empty string.`);
|
|
11
|
+
}
|
|
12
|
+
return value.trim();
|
|
13
|
+
}
|
|
14
|
+
function normalizedSourceIdentity(value) {
|
|
15
|
+
if (!isRecord(value)) return {};
|
|
16
|
+
return {
|
|
17
|
+
git_revision: typeof value.git_revision === "string" && value.git_revision.trim() ? value.git_revision.trim() : void 0,
|
|
18
|
+
repository: typeof value.repository === "string" && value.repository.trim() ? value.repository.trim() : void 0,
|
|
19
|
+
dirty: typeof value.dirty === "boolean" ? value.dirty : void 0,
|
|
20
|
+
label: typeof value.label === "string" && value.label.trim() ? value.label.trim() : void 0
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function parseRiddlePreviewReceipt(value) {
|
|
24
|
+
if (!isRecord(value)) throw new Error("Preview receipt must be an object.");
|
|
25
|
+
if (value.version !== RIDDLE_PREVIEW_RECEIPT_VERSION) {
|
|
26
|
+
throw new Error(`Unsupported Preview receipt version ${String(value.version || "missing")}.`);
|
|
27
|
+
}
|
|
28
|
+
if (!isRecord(value.source)) throw new Error("Preview receipt source must be an object.");
|
|
29
|
+
const expiresAt = requiredString(value, "expires_at", "preview receipt");
|
|
30
|
+
const publishedAt = requiredString(value, "published_at", "preview receipt");
|
|
31
|
+
const contentDigest = requiredString(value, "content_digest", "preview receipt");
|
|
32
|
+
if (!contentDigest.startsWith("sha256:") || contentDigest.length <= "sha256:".length) {
|
|
33
|
+
throw new Error("preview receipt.content_digest must be a sha256 digest.");
|
|
34
|
+
}
|
|
35
|
+
if (!Number.isFinite(Date.parse(expiresAt)) || !Number.isFinite(Date.parse(publishedAt))) {
|
|
36
|
+
throw new Error("Preview receipt timestamps must be valid ISO date strings.");
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
version: RIDDLE_PREVIEW_RECEIPT_VERSION,
|
|
40
|
+
preview_id: requiredString(value, "preview_id", "preview receipt"),
|
|
41
|
+
url: requiredString(value, "url", "preview receipt"),
|
|
42
|
+
expires_at: expiresAt,
|
|
43
|
+
content_digest: contentDigest,
|
|
44
|
+
source: normalizedSourceIdentity(value.source),
|
|
45
|
+
published_at: publishedAt
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function comparableArtifactName(value) {
|
|
49
|
+
return (value || "").split(/[/?#]/).pop()?.toLowerCase().replace(/\.(png|jpe?g|gif|webp|avif|svg)$/u, "").replace(/[^a-z0-9_-]+/gu, "-").replace(/^-+|-+$/g, "") || "";
|
|
50
|
+
}
|
|
51
|
+
function artifactMatchesLabel(artifact, label) {
|
|
52
|
+
const expected = comparableArtifactName(label);
|
|
53
|
+
if (!expected) return false;
|
|
54
|
+
return [artifact.name, artifact.url, artifact.path].map(comparableArtifactName).some((name) => name === expected || name.endsWith(`-${expected}`));
|
|
55
|
+
}
|
|
56
|
+
function artifactLooksLikeScreenshot(ref) {
|
|
57
|
+
const text = [ref.name, ref.url, ref.path, ref.kind, ref.content_type].filter(Boolean).join(" ").toLowerCase();
|
|
58
|
+
return /screenshot|\bimage\b/.test(text) || /\.(png|jpe?g|gif|webp|avif|svg)(\?|#|$)/.test(text);
|
|
59
|
+
}
|
|
60
|
+
function finalScreenshotLabels(result) {
|
|
61
|
+
const explicit = result.artifacts.canonical_screenshots || [];
|
|
62
|
+
if (explicit.length) return explicit;
|
|
63
|
+
const fromEvidence = (result.evidence?.viewports || []).map((viewport) => viewport.screenshot_label).filter((label) => typeof label === "string" && Boolean(label.trim()));
|
|
64
|
+
if (fromEvidence.length) return fromEvidence;
|
|
65
|
+
return (result.artifacts.screenshots || []).slice(0, 1);
|
|
66
|
+
}
|
|
67
|
+
function setupScreenshotLabels(result) {
|
|
68
|
+
const explicit = result.artifacts.setup_screenshots || [];
|
|
69
|
+
if (explicit.length) return explicit;
|
|
70
|
+
return (result.evidence?.viewports || []).flatMap(
|
|
71
|
+
(viewport) => (viewport.setup_action_results || []).filter((action) => action.action === "screenshot" && action.ok !== false && typeof action.screenshot_label === "string").map((action) => String(action.screenshot_label))
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
function observationArtifactFromRef(ref, canonicalLabels, setupLabels) {
|
|
75
|
+
const base = {
|
|
76
|
+
name: ref.name,
|
|
77
|
+
role: ref.role || "artifact",
|
|
78
|
+
url: ref.url,
|
|
79
|
+
path: ref.path,
|
|
80
|
+
kind: ref.kind,
|
|
81
|
+
content_type: ref.content_type,
|
|
82
|
+
source: ref.source
|
|
83
|
+
};
|
|
84
|
+
if (!artifactLooksLikeScreenshot(ref)) return base;
|
|
85
|
+
if (canonicalLabels.some((label) => artifactMatchesLabel(base, label))) {
|
|
86
|
+
return { ...base, role: "canonical_screenshot" };
|
|
87
|
+
}
|
|
88
|
+
if (setupLabels.some((label) => artifactMatchesLabel(base, label))) {
|
|
89
|
+
return { ...base, role: "setup_screenshot" };
|
|
90
|
+
}
|
|
91
|
+
return { ...base, role: "diagnostic" };
|
|
92
|
+
}
|
|
93
|
+
function profileObservationArtifacts(result) {
|
|
94
|
+
const canonicalLabels = finalScreenshotLabels(result);
|
|
95
|
+
const setupLabels = setupScreenshotLabels(result);
|
|
96
|
+
const artifacts = [];
|
|
97
|
+
const seen = /* @__PURE__ */ new Set();
|
|
98
|
+
const add = (artifact) => {
|
|
99
|
+
const key = artifact.url || artifact.path || `${artifact.role}:${artifact.name}`;
|
|
100
|
+
if (!artifact.name || seen.has(key)) return;
|
|
101
|
+
seen.add(key);
|
|
102
|
+
artifacts.push(artifact);
|
|
103
|
+
};
|
|
104
|
+
for (const ref of result.artifacts.riddle_artifacts || []) {
|
|
105
|
+
add(observationArtifactFromRef(ref, canonicalLabels, setupLabels));
|
|
106
|
+
}
|
|
107
|
+
for (const label of canonicalLabels) {
|
|
108
|
+
if (!artifacts.some((artifact) => artifactMatchesLabel(artifact, label))) {
|
|
109
|
+
add({ name: label, path: label, role: "canonical_screenshot", kind: "image" });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
for (const label of setupLabels) {
|
|
113
|
+
if (!artifacts.some((artifact) => artifactMatchesLabel(artifact, label))) {
|
|
114
|
+
add({ name: label, path: label, role: "setup_screenshot", kind: "image" });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
for (const label of result.artifacts.screenshots || []) {
|
|
118
|
+
if (!artifacts.some((artifact) => artifactMatchesLabel(artifact, label))) {
|
|
119
|
+
add({ name: label, path: label, role: "diagnostic", kind: "image" });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return artifacts;
|
|
123
|
+
}
|
|
124
|
+
function mergeObservationArtifacts(profileArtifacts, suppliedArtifacts) {
|
|
125
|
+
const artifacts = [...profileArtifacts];
|
|
126
|
+
for (const supplied of suppliedArtifacts) {
|
|
127
|
+
const suppliedNames = [supplied.name, supplied.url, supplied.path].map(comparableArtifactName).filter(Boolean);
|
|
128
|
+
const existingIndex = artifacts.findIndex((artifact) => {
|
|
129
|
+
if (supplied.url && artifact.url === supplied.url) return true;
|
|
130
|
+
if (supplied.path && artifact.path === supplied.path) return true;
|
|
131
|
+
return [artifact.name, artifact.url, artifact.path].map(comparableArtifactName).some((name) => name && suppliedNames.includes(name));
|
|
132
|
+
});
|
|
133
|
+
if (existingIndex < 0) {
|
|
134
|
+
artifacts.push(supplied);
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
const existing = artifacts[existingIndex];
|
|
138
|
+
const role = supplied.role === "canonical_screenshot" || supplied.role === "setup_screenshot" ? supplied.role : existing.role === "canonical_screenshot" || existing.role === "setup_screenshot" ? existing.role : supplied.role === "artifact" ? existing.role : supplied.role;
|
|
139
|
+
artifacts[existingIndex] = {
|
|
140
|
+
...existing,
|
|
141
|
+
...supplied,
|
|
142
|
+
role
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
return artifacts;
|
|
146
|
+
}
|
|
147
|
+
function defaultObservationId(role, capturedAt) {
|
|
148
|
+
return `obs_${role}_${capturedAt.replace(/[^0-9]/g, "").slice(0, 17) || "unknown"}`;
|
|
149
|
+
}
|
|
150
|
+
function profileCheckCounts(result) {
|
|
151
|
+
const counts = { total: result.checks.length, passed: 0, failed: 0, skipped: 0, needs_human_review: 0 };
|
|
152
|
+
for (const check of result.checks) {
|
|
153
|
+
if (check.status === "passed") counts.passed += 1;
|
|
154
|
+
if (check.status === "failed") counts.failed += 1;
|
|
155
|
+
if (check.status === "skipped") counts.skipped += 1;
|
|
156
|
+
if (check.status === "needs_human_review") counts.needs_human_review += 1;
|
|
157
|
+
}
|
|
158
|
+
return counts;
|
|
159
|
+
}
|
|
160
|
+
function createRiddleProofObservationReceipt(input) {
|
|
161
|
+
const capturedAt = input.captured_at || input.profile_result?.captured_at || (/* @__PURE__ */ new Date()).toISOString();
|
|
162
|
+
const profileArtifacts = input.profile_result ? profileObservationArtifacts(input.profile_result) : [];
|
|
163
|
+
const requestedCanonical = input.canonical_screenshot ? { ...input.canonical_screenshot, role: "canonical_screenshot" } : void 0;
|
|
164
|
+
const artifacts = mergeObservationArtifacts(
|
|
165
|
+
profileArtifacts,
|
|
166
|
+
[...input.artifacts || [], ...requestedCanonical ? [requestedCanonical] : []]
|
|
167
|
+
);
|
|
168
|
+
const canonicalScreenshot = requestedCanonical ? artifacts.find((artifact) => artifact.role === "canonical_screenshot" && artifactMatchesLabel(artifact, requestedCanonical.name)) || requestedCanonical : artifacts.find((artifact) => artifact.role === "canonical_screenshot");
|
|
169
|
+
const target = input.target.kind === "preview" && input.target.preview ? { ...input.target, preview: parseRiddlePreviewReceipt(input.target.preview) } : input.target;
|
|
170
|
+
return {
|
|
171
|
+
version: RIDDLE_PROOF_OBSERVATION_RECEIPT_VERSION,
|
|
172
|
+
observation_id: input.observation_id || defaultObservationId(input.comparison_role, capturedAt),
|
|
173
|
+
comparison_role: input.comparison_role,
|
|
174
|
+
executor: input.executor,
|
|
175
|
+
target,
|
|
176
|
+
source: normalizedSourceIdentity(input.source || input.target.preview?.source),
|
|
177
|
+
captured_at: capturedAt,
|
|
178
|
+
artifacts,
|
|
179
|
+
canonical_screenshot: canonicalScreenshot,
|
|
180
|
+
profile_summary: input.profile_result ? {
|
|
181
|
+
profile_name: input.profile_result.profile_name,
|
|
182
|
+
status: input.profile_result.status,
|
|
183
|
+
summary: input.profile_result.summary,
|
|
184
|
+
route: input.profile_result.route,
|
|
185
|
+
checks: profileCheckCounts(input.profile_result)
|
|
186
|
+
} : void 0,
|
|
187
|
+
proof: input.profile_result ? {
|
|
188
|
+
profile_name: input.profile_result.profile_name,
|
|
189
|
+
result: input.profile_result
|
|
190
|
+
} : void 0,
|
|
191
|
+
publication: input.publication,
|
|
192
|
+
execution: input.execution,
|
|
193
|
+
metadata: input.metadata
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
function parseRiddleProofObservationReceipt(value) {
|
|
197
|
+
if (!isRecord(value)) throw new Error("Observation receipt must be an object.");
|
|
198
|
+
if (value.version !== RIDDLE_PROOF_OBSERVATION_RECEIPT_VERSION) {
|
|
199
|
+
throw new Error(`Unsupported Observation receipt version ${String(value.version || "missing")}.`);
|
|
200
|
+
}
|
|
201
|
+
if (!isRecord(value.executor)) throw new Error("Observation receipt executor must be an object.");
|
|
202
|
+
if (!isRecord(value.target)) throw new Error("Observation receipt target must be an object.");
|
|
203
|
+
if (!isRecord(value.source)) throw new Error("Observation receipt source must be an object.");
|
|
204
|
+
requiredString(value, "observation_id", "observation receipt");
|
|
205
|
+
requiredString(value, "captured_at", "observation receipt");
|
|
206
|
+
const executorKind = requiredString(value.executor, "kind", "observation receipt executor");
|
|
207
|
+
if (!"local_playwright,riddle_hosted,browser_api,other".split(",").includes(executorKind)) {
|
|
208
|
+
throw new Error(`Unsupported observation executor kind ${executorKind}.`);
|
|
209
|
+
}
|
|
210
|
+
if (value.executor.runner !== void 0) {
|
|
211
|
+
requiredString(value.executor, "runner", "observation receipt executor");
|
|
212
|
+
}
|
|
213
|
+
const role = requiredString(value, "comparison_role", "observation receipt");
|
|
214
|
+
if (!["before", "after", "standalone"].includes(role)) {
|
|
215
|
+
throw new Error(`Unsupported observation comparison role ${role}.`);
|
|
216
|
+
}
|
|
217
|
+
const targetKind = requiredString(value.target, "kind", "observation receipt target");
|
|
218
|
+
if (targetKind !== "url" && targetKind !== "preview") {
|
|
219
|
+
throw new Error(`Unsupported observation target kind ${targetKind}.`);
|
|
220
|
+
}
|
|
221
|
+
requiredString(value.target, "url", "observation receipt target");
|
|
222
|
+
if (targetKind === "preview") {
|
|
223
|
+
if (value.target.preview === void 0) {
|
|
224
|
+
throw new Error("Preview Observation target must include its Preview receipt.");
|
|
225
|
+
}
|
|
226
|
+
parseRiddlePreviewReceipt(value.target.preview);
|
|
227
|
+
}
|
|
228
|
+
if (!Array.isArray(value.artifacts)) throw new Error("Observation receipt artifacts must be an array.");
|
|
229
|
+
const artifactRoles = /* @__PURE__ */ new Set(["canonical_screenshot", "setup_screenshot", "data", "diagnostic", "artifact"]);
|
|
230
|
+
const artifacts = value.artifacts.map((artifact, index) => {
|
|
231
|
+
if (!isRecord(artifact)) throw new Error(`Observation receipt artifact ${index} must be an object.`);
|
|
232
|
+
requiredString(artifact, "name", `observation receipt artifact ${index}`);
|
|
233
|
+
const artifactRole = requiredString(artifact, "role", `observation receipt artifact ${index}`);
|
|
234
|
+
if (!artifactRoles.has(artifactRole)) {
|
|
235
|
+
throw new Error(`Unsupported observation artifact role ${artifactRole}.`);
|
|
236
|
+
}
|
|
237
|
+
return artifact;
|
|
238
|
+
});
|
|
239
|
+
if (value.canonical_screenshot !== void 0) {
|
|
240
|
+
if (!isRecord(value.canonical_screenshot) || value.canonical_screenshot.role !== "canonical_screenshot") {
|
|
241
|
+
throw new Error("Observation canonical_screenshot must have the canonical_screenshot role.");
|
|
242
|
+
}
|
|
243
|
+
const canonical = value.canonical_screenshot;
|
|
244
|
+
const included = artifacts.some((artifact) => artifact.role === "canonical_screenshot" && artifact.name === canonical.name && artifact.url === canonical.url && artifact.path === canonical.path);
|
|
245
|
+
if (!included) {
|
|
246
|
+
throw new Error("Observation canonical_screenshot must reference an artifact in the receipt.");
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return value;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export {
|
|
253
|
+
RIDDLE_PREVIEW_RECEIPT_VERSION,
|
|
254
|
+
RIDDLE_PROOF_OBSERVATION_RECEIPT_VERSION,
|
|
255
|
+
parseRiddlePreviewReceipt,
|
|
256
|
+
createRiddleProofObservationReceipt,
|
|
257
|
+
parseRiddleProofObservationReceipt
|
|
258
|
+
};
|
package/dist/cli/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import "../chunk-
|
|
2
|
-
import "../chunk-
|
|
1
|
+
import "../chunk-HSGZV2NK.js";
|
|
2
|
+
import "../chunk-5IFZSUPF.js";
|
|
3
3
|
import "../chunk-JFQXAJH2.js";
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
4
|
+
import "../chunk-7N6X54WG.js";
|
|
5
|
+
import "../chunk-RQPCKRKT.js";
|
|
6
|
+
import "../chunk-6VFS2JFR.js";
|
|
7
|
+
import "../chunk-MEVVL4TI.js";
|
|
8
|
+
import "../chunk-FCSJZBC5.js";
|
|
8
9
|
import "../chunk-KXLEN4SA.js";
|
|
9
10
|
import "../chunk-WLUMLHII.js";
|
|
10
11
|
import "../chunk-CGJX7LJO.js";
|