diff --git a/internal/server/session_export_repair_test.go b/internal/server/session_export_repair_test.go index 21a2c992..ce629bc9 100644 --- a/internal/server/session_export_repair_test.go +++ b/internal/server/session_export_repair_test.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "errors" + "fmt" "net/http/httptest" "os" "path/filepath" @@ -13,6 +14,7 @@ import ( "git.a-wan.net/alan/pipelines/internal/cli" "git.a-wan.net/alan/pipelines/internal/pipeline" + "git.a-wan.net/alan/pipelines/internal/protocol" "git.a-wan.net/alan/pipelines/internal/stage" ) @@ -58,6 +60,12 @@ func TestRuntimeSessionExportRepairPreservesOriginalAndUsesRecordedOwner(t *test } // Restore readback availability; this is a fake native export CLI, not a // model stage, no generation/resumption/definition mutation is performed. + // A full user-artifact inventory must not consume mandatory audit capacity. + for i := 0; i < maxArtifactFiles; i++ { + if err := s.RecordDeliverable(context.Background(), id, 1, protocol.StageArtifact{Name: fmt.Sprintf("private/capture-%03d.png", i), SizeBytes: 100}); err != nil { + t.Fatal(err) + } + } sessionExportCLI(t) h.runner.exportSession = nil repaired, err := h.runner.repairSessionExport(context.Background(), id, 1) diff --git a/web/PARITY.md b/web/PARITY.md index cd08d9cd..80d70092 100644 --- a/web/PARITY.md +++ b/web/PARITY.md @@ -8,6 +8,25 @@ test, or a code change without a capture, is `partial` at best. Status legend: `todo` · `partial` (some of it works) · `done` (working + captured). +### Session capture and export recovery (2026-10-20) + +**Partial against the live-server gate.** The Session tab now distinguishes a +recorded session ID from its missing/failed export, selects a verified complete +repair for that same ID, and refreshes an already-open audit when evidence +changes. A failed or partial later repair does not hide a complete earlier one. +**Retry export only** reads the exact recorded visit; it never reruns its model +or tools. Versioned repairs stay in Audit, not the stage deliverables gallery. +Export-gated waits are nonterminal and show no human decision controls. + +`test/session-audit-browser.mjs` captures the recorded-but-failed state and the +successful export-only retry at 390px, with sandboxed iframe and unchanged-frame +checks. Captures: approved OpenCode temporary `session-audit-captures/`, +`01-recorded-identity-export-failed.png` and +`02-complete-repair-refreshes-open-audit.png`. These use fixture session data, +not a deployed-service claim. Separately, read-only API verification exported +all five original run #19 sessions completely (14/11/10/16/11 messages), without +rerunning stages. No deployment or live evidence mutation was performed. + ### Artifact browser hand-off (2026-10-20) Artifact opens now use one validated navigation helper across gallery/list, diff --git a/web/src/artifacts.js b/web/src/artifacts.js index fcc521d3..af94a033 100644 --- a/web/src/artifacts.js +++ b/web/src/artifacts.js @@ -165,12 +165,14 @@ export function isSystemArtifact(artifact) { /** A visit's stage-produced artifacts: everything except the system files. */ export function stageArtifacts(step) { - return presentedArtifacts(step).filter((artifact) => !isSystemArtifact(artifact)); + const repairs = new Set((step?.session_export_repairs ?? []).map((entry) => entry?.html).filter(Boolean)); + return presentedArtifacts(step).filter((artifact) => !isSystemArtifact(artifact) && !repairs.has(artifact?.name)); } /** A visit's system files, newest-listing order preserved. */ export function systemArtifacts(step) { - return presentedArtifacts(step).filter(isSystemArtifact); + const repairs = new Set((step?.session_export_repairs ?? []).map((entry) => entry?.html).filter(Boolean)); + return presentedArtifacts(step).filter((artifact) => isSystemArtifact(artifact) || repairs.has(artifact?.name)); } /** How many files the capture excluded for `step` (absent means none). */ diff --git a/web/src/views/runDetail.js b/web/src/views/runDetail.js index f299a209..e02d9501 100644 --- a/web/src/views/runDetail.js +++ b/web/src/views/runDetail.js @@ -116,25 +116,41 @@ export function createRunDetailView(rt) { const sessionRepairs = new Set(); function sessionExportRetry(step) { - const run=state.runDetail; + const run = state.runDetail; if (!run?.id || !step?.sequence || !(step.session_id || step.session_export?.session_id)) return null; - const key=`${run.id}:${step.sequence}`; - const running=step.agent_active || ["running","queued"].includes(run.status) || - (run.status==="waiting" && run.export_pending_sequence!==step.sequence); - const button=h("button",{class:"ghost session-export-retry",type:"button",disabled:running || sessionRepairs.has(key), - text:sessionRepairs.has(key)?"Exporting…":"Retry export only", - title:"Read the exact recorded session again. Does not rerun the stage or its tools."}); - button.addEventListener("click",async()=>{ + const key = `${run.id}:${step.sequence}`; + const running = step.agent_active || ["running", "queued"].includes(run.status) || + (run.status === "waiting" && run.export_pending_sequence !== step.sequence); + const button = h("button", { + class: "ghost session-export-retry", + type: "button", + disabled: running || sessionRepairs.has(key), + text: sessionRepairs.has(key) ? "Exporting…" : "Retry export only", + title: "Read the exact recorded session again. Does not rerun the stage or its tools.", + }); + button.addEventListener("click", async () => { if (sessionRepairs.has(key)) return; - sessionRepairs.add(key);button.disabled=true;button.textContent="Exporting…"; + sessionRepairs.add(key); + button.disabled = true; + button.textContent = "Exporting…"; try { - const detail=await repo.repairSessionExport(run.id,step.sequence); - if (state.runDetail?.id===run.id) { + const detail = await repo.repairSessionExport(run.id, step.sequence); + if (state.runDetail?.id === run.id) { if (rt.refreshRunDetail) rt.refreshRunDetail(run.id); - else {state.runDetail=detail;renderContent();} + else { + state.runDetail = detail; + renderContent(); + } } - } catch(error) {state.actionError=describeError(error);renderContent();} - finally {sessionRepairs.delete(key);button.disabled=Boolean(running);button.textContent="Retry export only";rt.views.dialogs.refreshStageAudit?.();} + } catch (error) { + state.actionError = describeError(error); + renderContent(); + } finally { + sessionRepairs.delete(key); + button.disabled = Boolean(running); + button.textContent = "Retry export only"; + rt.views.dialogs.refreshStageAudit?.(); + } }); return button; } diff --git a/web/test/sessionCapture.test.mjs b/web/test/sessionCapture.test.mjs index a4198454..8d7c3644 100644 --- a/web/test/sessionCapture.test.mjs +++ b/web/test/sessionCapture.test.mjs @@ -1,6 +1,6 @@ import test from "node:test"; import assert from "node:assert/strict"; -import { effectiveSessionExport, sessionExportArtifact, sessionCaptureState } from "../src/artifacts.js"; +import { effectiveSessionExport, sessionExportArtifact, sessionCaptureState, stageArtifacts, systemArtifacts } from "../src/artifacts.js"; const file = (name) => ({name,size_bytes:100,content_type:"text/html",url:`/artifacts/19/1/${name}`}); const complete = (html, id="ses_stage") => ({session_id:id,backend:"v2",status:"complete",messages:14,html,html_bytes:100}); @@ -37,6 +37,13 @@ test("a partial repair does not replace a complete original export", () => { assert.equal(effectiveSessionExport({session_id:"ses_stage",session_export:original,session_export_repairs:[partial],artifacts:[file(original.html),file(partial.html)]}),original); }); +test("versioned private and historical public repairs remain audit evidence, not deliverables", () => { + const repairs=[complete("session-repair-1-good.html"),complete("public/session-repair-1-old.html")]; + const step={session_export_repairs:repairs,artifacts:[...repairs.map(entry=>file(entry.html)),file("report.html")]}; + assert.deepEqual(stageArtifacts(step).map(entry=>entry.name),["report.html"]); + assert.deepEqual(systemArtifacts(step).map(entry=>entry.name),repairs.map(entry=>entry.html)); +}); + test("an original export naming another session is not selected", () => { const original=complete("session.html","ses_wrong"); assert.equal(sessionExportArtifact({session_id:"ses_stage",session_export:original,artifacts:[file("session.html")]}),null);