fix(app): set lone-surrogate texts aside or refuse them with a message (L1)

A draft the core refuses as lone_surrogate is unreadable content: it
goes to osteo:quarantine:draft verbatim with the existing notice. An
import is refused as ImportError('lone_surrogate') with the owner's
wording (home.import.error_lone_surrogate, FR/EN), the file untouched.
The publish gate reads the kind as invalid_shape. Tests on the real
core: quarantine keeps the exact text, an editor action leaves the
report as it was, normal text with pairs and literal backslashes reads
unchanged.
This commit is contained in:
bchanot committed 2026-10-14 21:49:39 +02:00
1 parent 20d03cf7fd
commit da8a0370cb
12 files changed
+151 -11

No files matched your search

+48 -1
View File
@@ -1,7 +1,8 @@
/**
* R2 plan P12 (rev 2): a draft or an archive the running build cannot read is
* set aside under a quarantine key, never dropped; only the content failures
* of the core (`invalid`, `unsupported_version`) quarantine, any other failure
* of the core (`invalid`, `unsupported_version`, `lone_surrogate`: L1, a text
* the core would alter) quarantine, any other failure
* leaves both keys where they were; the source key is removed only once the
* quarantine write succeeded; a draft rebased with unresolved items keeps its
* raw pre-rebase text.
@@ -57,6 +58,18 @@ describe('an unreadable draft', () => {
expect(useReportStore.getState().report).toBeNull()
})
it('with a lone surrogate (L1) is moved verbatim, the surrogate kept', () => {
const raw = JSON.stringify(minimalReport(sheet, { conclusion: 'a\ud800b' }))
expect(raw).toContain('\\ud800')
sessionStorage.setItem(DRAFT_KEY, raw)
expect(restore()).toEqual({ kind: 'quarantined' })
const kept = sessionStorage.getItem(QUARANTINE_KEYS.draft)
expect(kept).toBe(raw)
expect(JSON.parse(kept!).conclusion).toBe('a\ud800b')
expect(sessionStorage.getItem(DRAFT_KEY)).toBeNull()
expect(useReportStore.getState().report).toBeNull()
})
it('stays where it is when the quarantine write fails (storage full)', () => {
const raw = JSON.stringify({ version: 7 })
sessionStorage.setItem(DRAFT_KEY, raw)
@@ -108,6 +121,40 @@ describe('an unreadable archive beside a readable draft', () => {
})
})
describe('a lone surrogate (L1) beside a readable draft or in the open report', () => {
it('sets the archive aside verbatim while the draft restores', () => {
sessionStorage.setItem(
DRAFT_KEY,
JSON.stringify(minimalReport(sheet, { conclusion: 'kept' })),
)
const archive = JSON.stringify({ format: 'x', note: '\udc00' })
sessionStorage.setItem(ARCHIVE_KEY, archive)
expect(restore()).toMatchObject({ kind: 'restored' })
expect(useReportStore.getState().report?.conclusion).toBe('kept')
expect(sessionStorage.getItem(QUARANTINE_KEYS.archive)).toBe(archive)
})
it('refuses a core action and leaves the report as it was', () => {
const report = minimalReport(sheet, { conclusion: 'a\ud800b' })
useReportStore.setState({ report })
expect(useReportStore.getState().addObservation()).toEqual({ ok: false })
expect(useReportStore.getState().report).toBe(report)
expect(useReportStore.getState().report?.conclusion).toBe('a\ud800b')
})
it('leaves normal text with pairs and literal backslashes unchanged', () => {
const text = 'é 😀 \\ud800 \ufffd'
sessionStorage.setItem(
DRAFT_KEY,
JSON.stringify(minimalReport(sheet, { conclusion: text })),
)
expect(restore()).toMatchObject({ kind: 'restored' })
expect(useReportStore.getState().report?.conclusion).toBe(text)
expect(useReportStore.getState().addObservation()).toEqual({ ok: true })
expect(useReportStore.getState().report?.conclusion).toBe(text)
})
})
describe('a draft rebased onto the loaded sheet', () => {
const OTHER_SHA = 'c'.repeat(64)