diff --git a/.claude/tasks/contracts/2026-10-14-r2-maintenance-verify.md b/.claude/tasks/contracts/2026-10-14-r2-maintenance-verify.md index 617c8dbd..db290355 100644 --- a/.claude/tasks/contracts/2026-10-14-r2-maintenance-verify.md +++ b/.claude/tasks/contracts/2026-10-14-r2-maintenance-verify.md @@ -10,6 +10,10 @@ B. Fix the case where an unreadable archive or draft cannot be quarantined for l C. Remove `supabase/.temp/cli-latest` from git tracking while keeping the local copy; add the relevant .gitignore rules so Supabase temporary files are not tracked again; do not delete files needed for migrations or reproducibility. Document the fixes briefly. +## CLARIFICATIONS +- `supabase/.temp/cli-latest` leaves the index by REQUEST C (the Supabase CLI version cache, not a test file; the floor classifier matches "test" inside "cli-latest"). +- Pass 2 (after verifier pass 1): a refused archive write at a session edge removes the replaced session's archive instead of leaving it beside the new draft (test added); counts below updated. + ## ACCEPTANCE CRITERIA 1. rustls is at 0.23.46 or later in the lock and the RustSec advisories check is clean. CHECK: grep -A1 'name = "rustls"' Cargo.lock | tail -1; . scripts/rust-env.sh && cargo deny check advisories 2>&1 | tail -1 @@ -37,10 +41,10 @@ Document the fixes briefly. EXPECT: 19/19 / fr.ts:1 en.ts:1 / 0 9. The tests cover quota errors, refused writes, an occupied slot, corrupted data (non-JSON, unknown version, lone surrogate), the pair rollback, the pre-rebase original, an orphan archive, later overwriting actions (new report, import, reset, unrelated store changes) and the panel flows. CHECK: grep -cE "^\s+it\(" apps/app/tests/unit/state.heldSession.test.ts apps/app/tests/unit/routes.heldSession.test.tsx; grep -c "expectEveryLaterActionRefused(before)" apps/app/tests/unit/state.heldSession.test.ts - EXPECT: state.heldSession.test.ts:19 routes.heldSession.test.tsx:6 / ≥ 5 -10. The Node gate is green on the rebuilt module (typecheck, every suite, lint 0 warnings, build), the app at 345 tests. + EXPECT: state.heldSession.test.ts:20 routes.heldSession.test.tsx:6 / ≥ 5 +10. The Node gate is green on the rebuilt module (typecheck, every suite, lint 0 warnings, build), the app at 346 tests. CHECK: bash scripts/wasm-build.sh > /dev/null 2>&1; ./node_modules/.bin/pnpm check > /tmp/maint-verify-check.log 2>&1; echo "exit $?"; grep "apps/app test:run: Tests" /tmp/maint-verify-check.log - EXPECT: exit 0 / Tests 345 passed (345) + EXPECT: exit 0 / Tests 346 passed (346) 11. The fixes are documented. CHECK: grep -c "maintenance after R2" CHANGELOG.md; grep -c "maintenance B" docs/development/RUST.md EXPECT: 2 / ≥ 2 diff --git a/apps/app/src/state/reportStore.ts b/apps/app/src/state/reportStore.ts index be94c62d..c73d94e4 100644 --- a/apps/app/src/state/reportStore.ts +++ b/apps/app/src/state/reportStore.ts @@ -266,7 +266,9 @@ export function createReportStore( ) { /** The archive mirror is explicit: these actions are the session's edges. */ const withArchive = (patch: Patch, archive: ReportArchiveEnvelope | null) => { - archives.save(archive) + // A refused write must not leave the replaced session's archive beside the new draft: + // the next restore would pair them. That archive belongs to the session being replaced. + if (!archives.save(archive)) archives.save(null) return { ...patch, archive } } diff --git a/apps/app/tests/unit/state.heldSession.test.ts b/apps/app/tests/unit/state.heldSession.test.ts index 28352e0c..693cb6fe 100644 --- a/apps/app/tests/unit/state.heldSession.test.ts +++ b/apps/app/tests/unit/state.heldSession.test.ts @@ -301,6 +301,16 @@ describe('the draft mirror', () => { expect(sessionStorage.getItem(DRAFT_KEY)).toBe('{"unread":true}') }) + it('never leaves the replaced archive beside a new draft when the archive write is refused', () => { + const first = minimalReport(sheet, { conclusion: 'first' }) + store().hydrateImport({ report: first, archive: archiveEnvelope(sheet, first) }, sheet) + refuseWrites((key) => key === ARCHIVE_KEY) + const second = minimalReport(sheet, { conclusion: 'second' }) + store().hydrateImport({ report: second, archive: archiveEnvelope(sheet, second) }, sheet) + expect(sessionStorage.getItem(ARCHIVE_KEY)).toBeNull() + expect(JSON.parse(sessionStorage.getItem(DRAFT_KEY)!).conclusion).toBe('second') + }) + it('a deletion request is ignored while a report is open', () => { store().initReport(newDraft(), sheet.sheet.ref, sheet) store().discardSessionText('draft') diff --git a/docs/development/RUST.md b/docs/development/RUST.md index b2e45891..2aac2477 100644 --- a/docs/development/RUST.md +++ b/docs/development/RUST.md @@ -637,7 +637,9 @@ application itself builds. readable one is replaced as before. The draft mirror is written only when the report changes (an unrelated store change never removes it); a refused write keeps the previous text and shows the `editor.save_failed` - banner until a write succeeds. + banner until a write succeeds; a refused archive write at a new session + removes the replaced session's archive rather than leave it paired with + the new draft. 4. A core that cannot load leaves the editor on the degraded notice (before R2 a failed sheet chunk left it on "loading"). 5. Home and `/new` no longer load the sheet into memory on mount.