fix(audit): expose verified visit exports and export-only recovery

This commit is contained in:
2026-10-20 21:20:06 +01:00
parent f87e1ed488
commit ca78b24f47
14 changed files with 359 additions and 59 deletions
+38 -1
View File
@@ -468,12 +468,49 @@ export function artifactViewerPositionLabel(index, count, contentType) {
* that recorded no export, whose export name is blank, or whose file is missing
* from a truncated listing yields null. Mirrors SessionExport.kt sessionExportFile.
*/
export function effectiveSessionExport(step) {
const recorded = step?.session_export ?? null;
const id = String(step?.session_id || recorded?.session_id || "");
const original = recorded?.session_id && id && recorded.session_id !== id ? null : recorded;
const repairs = [...(step?.session_export_repairs ?? [])].reverse()
.filter((entry) => id !== "" && entry?.session_id === id);
const hasFile = (entry) => Boolean(entry?.html) && (step?.artifacts ?? []).some((file) => file?.name === entry.html && file.size_bytes > 0);
// A failed later attempt must not hide an earlier, verified full repair.
const isComplete = (entry) => entry?.status === "complete" && entry.messages > 0 &&
entry.html_bytes > 0 && !entry.truncated && !entry.diagnostic && hasFile(entry);
return repairs.find(isComplete) ?? (isComplete(original) ? original : null) ?? repairs.find(hasFile) ?? (hasFile(original) ? original : null) ?? repairs[0] ?? original ?? null;
}
export function sessionExportArtifact(step) {
const html = step?.session_export?.html;
const html = effectiveSessionExport(step)?.html;
if (typeof html !== "string" || html.trim() === "") return null;
return (step?.artifacts ?? []).find((artifact) => artifact?.name === html) ?? null;
}
/** A recorded ID and an exported document are different facts. Never call a
* recorded session "not recorded" just because its export is missing. */
export function sessionCaptureState(step) {
const evidence = effectiveSessionExport(step);
const sessionId = String(step?.session_id || evidence?.session_id || "");
const artifact = sessionExportArtifact(step);
if (artifact) return { sessionId, evidence, artifact, message: "" };
if (sessionId) {
const recovery = step?.session_export_recovery;
const status = recovery?.status === "pending" || recovery?.status === "running"
? "pending recovery" : evidence?.status === "complete" ? "not available in the artifact inventory" : evidence?.status || "not yet available";
return { sessionId, evidence, artifact: null,
message: `Session ${sessionId} is recorded. Its export is ${status}.${evidence?.diagnostic ? ` ${evidence.diagnostic}` : ""}` };
}
const model = Boolean(step?.model || step?.provider);
const skipped=step?.status==="skipped" || step?.outcome==="skipped";
const stopped=["canceled","interrupted"].includes(step?.status);
return { sessionId, evidence, artifact: null, message: skipped ? "This visit was skipped; no harness session was started." : stopped ? "The stage stopped before a harness session was recorded." : model
? step?.status === "running" ? "The stage session is being created."
: step?.status === "failed" ? `The stage did not create a harness session.${step?.diagnostic ? ` ${step.diagnostic}` : ""}`
: "Runtime error: this model stage has no recorded session identity."
: "This visit has no harness session." };
}
/**
* The absolute url a gallery artifact can be opened at, or null when it cannot
* be resolved against the configured server (blank or invalid). The one place a