refactor(lab): canonize selected evidence reports
This commit is contained in:
@@ -0,0 +1,157 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { after, before, test } from "node:test";
|
||||
import { readFile } from "node:fs/promises";
|
||||
|
||||
import { createServer } from "vite";
|
||||
|
||||
let server;
|
||||
let fetchLaboratoryValueReviewIndex;
|
||||
let fetchLaboratoryEvidenceReport;
|
||||
|
||||
before(async () => {
|
||||
server = await createServer({ server: { middlewareMode: true }, appType: "custom" });
|
||||
({ fetchLaboratoryValueReviewIndex } = await server.ssrLoadModule(
|
||||
"/src/core/laboratory/valueReviewIndex.ts",
|
||||
));
|
||||
({ fetchLaboratoryEvidenceReport } = await server.ssrLoadModule(
|
||||
"/src/core/laboratory/evidenceReport.ts",
|
||||
));
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await server?.close();
|
||||
});
|
||||
|
||||
function payload(overrides = {}) {
|
||||
return {
|
||||
schema_version: "missioncore.laboratory-value-review-index/v1",
|
||||
reviewed_at_utc: "2026-08-05T08:30:00Z",
|
||||
items: [
|
||||
{
|
||||
catalog_id: "e46j-raw-fisheye-realtime",
|
||||
evidence_id: `e46j-raw-fisheye-realtime-${"a".repeat(64)}`,
|
||||
signal: "progress",
|
||||
lifecycle: "current",
|
||||
visual_evidence: "available",
|
||||
access: "read-only",
|
||||
},
|
||||
],
|
||||
access: "read-only",
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
test("LAB value-review index preserves the reviewed evidence identity", async () => {
|
||||
const index = await fetchLaboratoryValueReviewIndex({
|
||||
fetcher: async () => new Response(JSON.stringify(payload()), { status: 200 }),
|
||||
});
|
||||
|
||||
assert.equal(index.items[0].catalogId, "e46j-raw-fisheye-realtime");
|
||||
assert.match(index.items[0].evidenceId, /^e46j-raw-fisheye-realtime-[a-f0-9]{64}$/);
|
||||
assert.equal(index.items[0].signal, "progress");
|
||||
});
|
||||
|
||||
test("LAB value-review index rejects extra fields instead of trusting presentation data", async () => {
|
||||
const document = payload();
|
||||
document.items[0] = { ...document.items[0], renderer: "local" };
|
||||
|
||||
await assert.rejects(
|
||||
fetchLaboratoryValueReviewIndex({
|
||||
fetcher: async () => new Response(JSON.stringify(document), { status: 200 }),
|
||||
}),
|
||||
/состав полей/,
|
||||
);
|
||||
});
|
||||
|
||||
test("selected LAB evidence report preserves proof, telemetry and canonical JSON", async () => {
|
||||
const workId = "e46j-raw-fisheye-realtime";
|
||||
const resultId = `e46j-raw-fisheye-realtime-${"b".repeat(64)}`;
|
||||
const report = await fetchLaboratoryEvidenceReport({
|
||||
workId,
|
||||
resultId,
|
||||
fetcher: async () => new Response(JSON.stringify({
|
||||
schema_version: "missioncore.laboratory-evidence-report/v1",
|
||||
work_id: workId,
|
||||
result_id: resultId,
|
||||
created_at_utc: "2026-08-04T19:37:51.841Z",
|
||||
access: "read-only",
|
||||
proof: {
|
||||
document_schema_version: "missioncore.e46j-result/v1",
|
||||
document_sha256: "c".repeat(64),
|
||||
identity_sha256: "b".repeat(64),
|
||||
report_schema_version: "missioncore.e46j-report/v1",
|
||||
report_sha256: "d".repeat(64),
|
||||
artifact_count: 1,
|
||||
verified_artifact_count: 1,
|
||||
},
|
||||
completeness: {
|
||||
identity: "recorded",
|
||||
source: "recorded",
|
||||
configuration: "recorded",
|
||||
method: "recorded",
|
||||
execution: "recorded",
|
||||
resources: "recorded",
|
||||
metrics: "recorded",
|
||||
gates: "recorded",
|
||||
decision: "recorded",
|
||||
limitations: "recorded",
|
||||
authority: "recorded",
|
||||
artifacts: "recorded",
|
||||
visual_evidence: "recorded",
|
||||
},
|
||||
identity: { profile_sha256: "e".repeat(64) },
|
||||
source: { frame_count: 4489, stream_sha256: "f".repeat(64) },
|
||||
configuration: { detector: { config_sha256: "8".repeat(64) } },
|
||||
method: { components: [{ kind: "model", identity_sha256: "a".repeat(64) }] },
|
||||
execution: { worker_host: "worker-006", gpu_name: "RTX 4090" },
|
||||
resources: { gpu_utilization_percent: { p95: 49 } },
|
||||
metrics: { core_capacity_fps: 47.84, core_path_p95_ms: 25.35 },
|
||||
gates: { passed: true },
|
||||
decision: { provider_promoted: false },
|
||||
limitations: ["No temporal identity."],
|
||||
authority: { commands_enabled: false },
|
||||
artifacts: [{
|
||||
kind: "visual-overlay-video",
|
||||
path: "overlay.mp4",
|
||||
byte_length: 150563706,
|
||||
sha256: "9".repeat(64),
|
||||
schema_version: null,
|
||||
media_type: "video/mp4",
|
||||
verified: true,
|
||||
}],
|
||||
visual_evidence: { review: { completed: true }, artifacts: [] },
|
||||
raw_report: { schema_version: "missioncore.e46j-report/v1", metrics: { frame_count: 4489 } },
|
||||
}), { status: 200 }),
|
||||
});
|
||||
|
||||
assert.equal(report.workId, workId);
|
||||
assert.equal(report.resultId, resultId);
|
||||
assert.equal(report.resources.gpu_utilization_percent.p95, 49);
|
||||
assert.equal(report.artifacts[0].verified, true);
|
||||
assert.equal(report.canonicalJson.raw_report.metrics.frame_count, 4489);
|
||||
});
|
||||
|
||||
test("LAB report UI uses the panel header contract and canonical controls", async () => {
|
||||
const root = new URL("../src/", import.meta.url);
|
||||
const [workspace, header, report, presentation, styles] = await Promise.all([
|
||||
readFile(new URL("workspaces/laboratory/LaboratoryArchiveWorkspace.tsx", root), "utf8"),
|
||||
readFile(new URL("components/laboratory/useLaboratoryAnnotationHeader.tsx", root), "utf8"),
|
||||
readFile(new URL("workspaces/laboratory/LaboratoryEvidenceReportView.tsx", root), "utf8"),
|
||||
readFile(new URL("components/laboratory/LaboratoryPresentation.tsx", root), "utf8"),
|
||||
readFile(new URL("styles/laboratory-evidence-report.css", root), "utf8"),
|
||||
]);
|
||||
|
||||
assert.match(workspace, /useLaboratoryViewMode/);
|
||||
assert.match(workspace, /<LaboratoryEvidenceReportView/);
|
||||
assert.match(workspace, /selectedCatalog/);
|
||||
assert.match(header, /Отчёт|viewAction\.label/);
|
||||
assert.match(header, /<Button/);
|
||||
assert.doesNotMatch(header, /size="compact"[^>]*viewAction/);
|
||||
assert.match(report, /CANONICAL JSON/);
|
||||
assert.match(report, /verifiedArtifactCount/);
|
||||
assert.doesNotMatch(report, /Открыть LAB/);
|
||||
assert.match(presentation, /className="laboratory-status-dot"/);
|
||||
assert.doesNotMatch(presentation, /<Icon name="circle"/);
|
||||
assert.match(styles, /background: currentcolor/);
|
||||
assert.doesNotMatch(styles, /#[a-f0-9]{3,8}/i);
|
||||
});
|
||||
Reference in New Issue
Block a user