fix(store): drop the replaced archive when the new one cannot be written

This commit is contained in:
bchanot committed 2026-10-14 23:15:54 +02:00
1 parent e5e2211476
commit a37c50b9ee
4 files changed
+23 -5

No files matched your search

@@ -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. 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. 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 ## ACCEPTANCE CRITERIA
1. rustls is at 0.23.46 or later in the lock and the RustSec advisories check is clean. 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 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 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. 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 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 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 345 tests. 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 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. 11. The fixes are documented.
CHECK: grep -c "maintenance after R2" CHANGELOG.md; grep -c "maintenance B" docs/development/RUST.md CHECK: grep -c "maintenance after R2" CHANGELOG.md; grep -c "maintenance B" docs/development/RUST.md
EXPECT: 2 / ≥ 2 EXPECT: 2 / ≥ 2
+3 -1
View File
@@ -266,7 +266,9 @@ export function createReportStore(
) { ) {
/** The archive mirror is explicit: these actions are the session's edges. */ /** The archive mirror is explicit: these actions are the session's edges. */
const withArchive = (patch: Patch, archive: ReportArchiveEnvelope | null) => { 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 } return { ...patch, archive }
} }
@@ -301,6 +301,16 @@ describe('the draft mirror', () => {
expect(sessionStorage.getItem(DRAFT_KEY)).toBe('{"unread":true}') 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', () => { it('a deletion request is ignored while a report is open', () => {
store().initReport(newDraft(), sheet.sheet.ref, sheet) store().initReport(newDraft(), sheet.sheet.ref, sheet)
store().discardSessionText('draft') store().discardSessionText('draft')
+3 -1
View File
@@ -637,7 +637,9 @@ application itself builds.
readable one is replaced as before. The draft mirror is written only readable one is replaced as before. The draft mirror is written only
when the report changes (an unrelated store change never removes it); when the report changes (an unrelated store change never removes it);
a refused write keeps the previous text and shows the `editor.save_failed` 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 4. A core that cannot load leaves the editor on the degraded notice
(before R2 a failed sheet chunk left it on "loading"). (before R2 a failed sheet chunk left it on "loading").
5. Home and `/new` no longer load the sheet into memory on mount. 5. Home and `/new` no longer load the sheet into memory on mount.