feat(home): import messages open with a full-restoration or partial-recovery headline; BDR-040 recorded
This commit is contained in:
1 parent
de2bd0437e
commit
62b8a43e09
7 files changed
+106
-23
No files matched your search
@@ -334,4 +334,12 @@ Status: closed; awaiting user validation of Step 5.
|
||||
|
||||
User-validated design (docs/development/STEP6_PDF_ARCHIVE_ANALYSIS.md Part II). Attachment = envelope v1 `{format, envelopeVersion, exportedAt, locale, report v3, sheetSnapshot, branding, labels}` in one `osteo-report.json`, SVG inline as text. Snapshot = `{status, ref, document, assets}` where document = valid lean `AnatomicalSheetDocument` (all views/annotations/categories/regions, finding zones kept by id, trees pruned to used paths with ancestor labels, references emptied) → reuses sheet index, layer renderer, 21 integrity rules; no dedicated schema. Branding (logos base64/svg, credits, URLs) + label dict (fr+en) archived so future logo/wording changes never alter a re-render (user D7 adjustment). Engine `packages/pdf`: explicit inputs `{report, sheet, branding, labels, locale, rasterizer, exportedAt}`, no DOM lib, xmldom composition promoted from curation app-review, Rasterizer adapter (browser Image/canvas; resvg devDep for tests), per-view/per-logo degradation, export-side validation (caps, integrity, sheet invariant). Read = layered: report first (v3/v2 existing dispatch), envelope metadata tolerant, snapshot strict → `snapshotRejected` enum, report never lost; `attachment_stripped` via Info.Keywords stamp. Session: imported archive kept immutable (`osteo:archive`), working copy rebased explicitly on the loaded sheet (`rebaseReportOnSheet`, unresolved flags + labels from archived snapshot) (user D8 adjustment); re-export of the kept archive = technical support only, UX submitted after step. No CLI, no page change, no original v2 JSON re-embedded.
|
||||
Alt rejected: dedicated SheetSnapshotSchema (rewrites lookups, loses integrity rules); separate embedded files per asset (first-EmbeddedFile reader, stripping risk); pruning views/annotations (saves ~0 KB, breaks trigger titles); snapshot discarded on import (user: keep for faithful re-read); crypto hash check of assets (self-referential; sha copied from catalog manifest as provenance pointer instead).
|
||||
Status: open (implementation in progress on feature/step-06-pdf-archives).
|
||||
Status: closed (Step 6 validated by user 2026-10-11; D8 finalised in BDR-040).
|
||||
|
||||
---
|
||||
|
||||
## BDR-040 | 2026-10-11 | Step 6 closure: no "re-export the original archive" button, visible rebase, BLK-009 gate
|
||||
|
||||
User decisions after manual validation (logos and picker text confirmed OK on their side; Step 6 VALIDATED). (1) Re-export of the imported archive from the UI REFUSED permanently: the practitioner already holds the original PDF; no second button, no dedicated UX flow. Keep the archived snapshot, its integrity and the autonomy tests (engine `exportFromEnvelope` stays as the proof + future server use); the UI exports only the open working report. Do not propose this feature again. (2) Rebase on draft restore shown to the user (`editor.draft_rebased`) approved; import messages approved on principle with an explicit "full restoration" vs "partial recovery" headline. (3) BLK-009 treated now: byte-scan attachment extraction without pdf-lib load on import + export without object streams; remaining risks (worker/server import, pdf-lib replacement, read caps) stay an explicit BLOCKER gate before any external user import; never declared solved by passing tests alone.
|
||||
Alt rejected: a re-export action on the home screen after import (same objection); a toast system for import feedback (no component, alert pattern kept).
|
||||
Status: closed.
|
||||
@@ -18,11 +18,11 @@ import { useT } from '@/i18n/useT'
|
||||
type Translate = ReturnType<typeof useT>
|
||||
|
||||
/**
|
||||
* The lines of the one alert shown after a successful import (STEP6 §16):
|
||||
* a lossy v2 migration, the archive kept, the snapshot dropped with its
|
||||
* The detail lines of the import alert (STEP6 §16), in a fixed order: a
|
||||
* lossy v2 migration, the archive kept, the snapshot dropped with its
|
||||
* reason, the rebase onto the current sheet. Empty when nothing applies.
|
||||
*/
|
||||
function importMessages(
|
||||
function importDetailLines(
|
||||
outcome: ArchiveReadOutcome,
|
||||
rebase: RebaseOutcome,
|
||||
t: Translate,
|
||||
@@ -48,6 +48,42 @@ function importMessages(
|
||||
return lines
|
||||
}
|
||||
|
||||
/**
|
||||
* Degraded recovery: something the practitioner must check. A rejected
|
||||
* snapshot, a migration or a rebase that lost items. A rebase that resolved
|
||||
* everything is a complete restoration on a different sheet.
|
||||
*/
|
||||
function isDegradedImport(
|
||||
outcome: ArchiveReadOutcome,
|
||||
rebase: RebaseOutcome,
|
||||
): boolean {
|
||||
const lost = outcome.unresolvedFindings + outcome.unresolvedZones
|
||||
const rebaseLost = rebase.unresolvedZones + rebase.unresolvedFindings
|
||||
return (
|
||||
outcome.snapshotRejected !== undefined ||
|
||||
(outcome.migrated && lost > 0) ||
|
||||
(rebase.rebased && rebaseLost > 0)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The one alert shown after a successful import: a headline that says
|
||||
* whether the restoration is complete or partial, then the detail lines.
|
||||
* Empty (no alert) when there is nothing to say: a bare v3 on the same sheet.
|
||||
*/
|
||||
function importMessages(
|
||||
outcome: ArchiveReadOutcome,
|
||||
rebase: RebaseOutcome,
|
||||
t: Translate,
|
||||
): string[] {
|
||||
const details = importDetailLines(outcome, rebase, t)
|
||||
if (details.length === 0) return []
|
||||
const headline = isDegradedImport(outcome, rebase)
|
||||
? t('home.import.degraded')
|
||||
: t('home.import.complete')
|
||||
return [headline, ...details]
|
||||
}
|
||||
|
||||
/** The error line under the import button, by ImportError kind. */
|
||||
function importErrorMessage(err: unknown, t: Translate): string {
|
||||
if (!(err instanceof ImportError)) return t('home.import.error_generic')
|
||||
|
||||
@@ -30,6 +30,9 @@ export const en: Dict = {
|
||||
'This PDF was not generated by Faunosteo (no data detected).',
|
||||
'home.import.error_incompatible_version':
|
||||
'This PDF uses format v{version}, which this version of the application cannot read (accepted formats: v2 and v3).',
|
||||
'home.import.complete': 'Full restoration.',
|
||||
'home.import.degraded':
|
||||
'Partial recovery: check the items flagged below.',
|
||||
'home.import.migrated':
|
||||
'Report imported from an older format. Findings not found in the current sheet: {count} (kept with their labels).',
|
||||
'home.import.archive_ok':
|
||||
|
||||
@@ -32,6 +32,9 @@ export const fr: Dict = {
|
||||
"Ce PDF n'a pas été généré par Faunosteo (pas de données détectées).",
|
||||
'home.import.error_incompatible_version':
|
||||
"Ce PDF est au format v{version}, que cette version de l'application ne sait pas lire (formats acceptés : v2 et v3).",
|
||||
'home.import.complete': 'Restauration complète.',
|
||||
'home.import.degraded':
|
||||
'Récupération partielle : vérifiez les éléments signalés.',
|
||||
'home.import.migrated':
|
||||
'Bilan importé depuis un ancien format. Constats non retrouvés dans la fiche actuelle : {count} (conservés avec leurs libellés).',
|
||||
'home.import.archive_ok':
|
||||
|
||||
@@ -16,6 +16,8 @@ const REQUIRED = [
|
||||
'home.import.error_generic',
|
||||
'home.import.error_attachment_stripped',
|
||||
'home.import.archive_ok',
|
||||
'home.import.complete',
|
||||
'home.import.degraded',
|
||||
'home.import.snapshot_reason.unsupported_envelope',
|
||||
'home.import.snapshot_reason.schema',
|
||||
'home.import.snapshot_reason.caps',
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
/**
|
||||
* T15 (STEP6 §7, §16): the home route on Step 6 archives, with
|
||||
* `importReportFromPdf` mocked. Same sheet: archive kept in the store and
|
||||
* mirrored, archive_ok alert. Other sheet: the report is rebased on the
|
||||
* `importReportFromPdf` mocked. Every alert opens with a headline: complete
|
||||
* restoration or partial recovery. Same sheet: archive kept in the store and
|
||||
* mirrored, complete + archive_ok. Other sheet: the report is rebased on the
|
||||
* loaded sheet (unresolved flags, labels from the archived snapshot, sheet
|
||||
* ref updated) and the alert says so with the count. Snapshot rejected: the
|
||||
* ref updated) and the alert says degraded with the count; a rebase that
|
||||
* resolved everything stays complete. Snapshot rejected: degraded with the
|
||||
* reason label. Attachment stripped: its error message.
|
||||
*/
|
||||
import {
|
||||
@@ -159,7 +161,9 @@ async function mountAndPickPdf(): Promise<void> {
|
||||
}
|
||||
|
||||
const alertMock = () => vi.mocked(window.alert)
|
||||
const alertText = () => alertMock().mock.calls[0]![0] as string
|
||||
/** The alert split on its blank lines: headline first, then the detail lines. */
|
||||
const alertLines = () =>
|
||||
(alertMock().mock.calls[0]![0] as string).split('\n\n')
|
||||
const errorText = () => screen.queryByText(/./, { selector: 'p.text-red-700' })
|
||||
|
||||
describe('HomeRoute import of a Step 6 archive', () => {
|
||||
@@ -176,7 +180,10 @@ describe('HomeRoute import of a Step 6 archive', () => {
|
||||
report.id,
|
||||
)
|
||||
expect(alertMock()).toHaveBeenCalledTimes(1)
|
||||
expect(alertText()).toBe(fr['home.import.archive_ok'])
|
||||
expect(alertLines()).toEqual([
|
||||
fr['home.import.complete'],
|
||||
fr['home.import.archive_ok'],
|
||||
])
|
||||
})
|
||||
|
||||
it('other sheet: rebases onto the loaded sheet, labels from the archived snapshot, alert with the count', async () => {
|
||||
@@ -200,12 +207,32 @@ describe('HomeRoute import of a Step 6 archive', () => {
|
||||
// The archive stays as exported, never rebased.
|
||||
expect(useReportStore.getState().archive).toEqual(archive)
|
||||
expect(alertMock()).toHaveBeenCalledTimes(1)
|
||||
expect(alertText()).toBe(
|
||||
[
|
||||
fr['home.import.archive_ok'],
|
||||
fr['home.import.rebased']!.replace('{count}', '2'),
|
||||
].join('\n\n'),
|
||||
)
|
||||
expect(alertLines()).toEqual([
|
||||
fr['home.import.degraded'],
|
||||
fr['home.import.archive_ok'],
|
||||
fr['home.import.rebased']!.replace('{count}', '2'),
|
||||
])
|
||||
})
|
||||
|
||||
it('other sheet, everything resolved: complete headline, the rebased line says 0', async () => {
|
||||
const report = minimalReport(sheet, {
|
||||
sheet: { ...sheet.sheet.ref, documentSha256: OTHER_SHA },
|
||||
observations: reportWithHip().observations,
|
||||
})
|
||||
const archive = archiveEnvelope(sheet, report)
|
||||
archive.sheetSnapshot.ref.documentSha256 = OTHER_SHA
|
||||
importMock.mockResolvedValue(archived(report, archive))
|
||||
await mountAndPickPdf()
|
||||
await screen.findByTestId('editor-route')
|
||||
const opened = useReportStore.getState().report!
|
||||
expect(opened.sheet).toEqual(sheet.sheet.ref)
|
||||
expect(opened.observations[0]!.zones[0]!.unresolved).toBeUndefined()
|
||||
expect(alertMock()).toHaveBeenCalledTimes(1)
|
||||
expect(alertLines()).toEqual([
|
||||
fr['home.import.complete'],
|
||||
fr['home.import.archive_ok'],
|
||||
fr['home.import.rebased']!.replace('{count}', '0'),
|
||||
])
|
||||
})
|
||||
|
||||
it('snapshot rejected: the report opens, the alert names the reason, no archive kept', async () => {
|
||||
@@ -219,12 +246,13 @@ describe('HomeRoute import of a Step 6 archive', () => {
|
||||
expect(useReportStore.getState().archive).toBeNull()
|
||||
expect(sessionStorage.getItem(ARCHIVE_KEY)).toBeNull()
|
||||
expect(alertMock()).toHaveBeenCalledTimes(1)
|
||||
expect(alertText()).toBe(
|
||||
expect(alertLines()).toEqual([
|
||||
fr['home.import.degraded'],
|
||||
fr['home.import.snapshot_rejected']!.replace(
|
||||
'{reason}',
|
||||
fr['home.import.snapshot_reason.caps']!,
|
||||
),
|
||||
)
|
||||
])
|
||||
})
|
||||
|
||||
it('attachment_stripped → its error message, nothing opened', async () => {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* Step 6 Phase 0 characterisation of the import flow on the home route, with
|
||||
* `importReportFromPdf` mocked: the migration alert with its count, the three
|
||||
* ImportError kinds plus the generic error mapped to the FR messages, and
|
||||
* the navigation to /editor on success. Kept green unchanged by Step 6.
|
||||
* `importReportFromPdf` mocked: the migration alert (degraded headline, then
|
||||
* the count), the three ImportError kinds plus the generic error mapped to
|
||||
* the FR messages, and the navigation to /editor on success.
|
||||
*/
|
||||
import {
|
||||
describe,
|
||||
@@ -110,7 +110,7 @@ describe('HomeRoute import: success paths', () => {
|
||||
expect(alertMock()).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('alerts with the unresolved count (zones + findings) after a lossy migration', async () => {
|
||||
it('alerts "degraded" then the unresolved count (zones + findings) after a lossy migration', async () => {
|
||||
importMock.mockResolvedValue(
|
||||
outcome({ migrated: true, unresolvedZones: 1, unresolvedFindings: 1 }),
|
||||
)
|
||||
@@ -118,8 +118,11 @@ describe('HomeRoute import: success paths', () => {
|
||||
await screen.findByTestId('editor-route')
|
||||
expect(alertMock()).toHaveBeenCalledTimes(1)
|
||||
const message = alertMock().mock.calls[0]![0] as string
|
||||
expect(message).toBe(fr['home.import.migrated']!.replace('{count}', '2'))
|
||||
expect(message).toContain('2')
|
||||
const [headline, ...lines] = message.split('\n\n')
|
||||
expect(headline).toBe(fr['home.import.degraded'])
|
||||
expect(lines).toEqual([
|
||||
fr['home.import.migrated']!.replace('{count}', '2'),
|
||||
])
|
||||
})
|
||||
|
||||
it('stays silent on a migration that lost nothing', async () => {
|
||||
|
||||
Reference in new issue
Block a user