chore(memory+docs): /ship-feature B3 capitalize — BDR-014/015 + LRN-017..019 + EVAL-002 + journal + TODO
Memory registry capitalization after B3 i18n FR/EN ship. - decisions.md +BDR-014 (PDF locale = render preference, store-driven, not Report schema field — dual label snapshot already carried). - decisions.md +BDR-015 (typed ImportError discriminant kind + foundVersion; UI resolves message via dict; review caught hardcoded FR in domain layer). - learnings.md +LRN-017 (i18n dict parity test: Object.keys().sort() equality + non-empty value assertion — cheapest drift guard). - learnings.md +LRN-018 (useT hook pattern: selector subscribe + dict closure-per-render, no prop drilling, missing-key dev-warn + key-literal fallback). - learnings.md +LRN-019 (exhaustive-deps trap when closures over store values appear inside useMemo deps — inline or useCallback). - evals.md +EVAL-002 (B3 review caught critical FR leak in pdf/import.ts + attachment.ts that grep+analyzer both missed — i18n migrations must enumerate ALL string-emitting files including error paths). - journal.md session 3 entry under 2026-05-20. - TODO.md B3 subsection rewritten as DONE with checked checkboxes + cross-refs. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
1 parent
9916c42484
commit
31bd82de58
7 files changed
+111
-21
No files matched your search
@@ -107,3 +107,21 @@ SVG data-anno-id values stay opaque generator strings (point-mpb..., zone-...).
|
||||
Alt rejected: rename SVG data-anno-id to JSON keys — couples opaque SVG generator output to human-meaningful catalog, brittle across SVG re-exports.
|
||||
Alt rejected: add new `data-anno-finding-zone` attribute on every hitbox — forces SVG edit per species, double-source for the same info already in name_fr/en.
|
||||
Status: closed.
|
||||
|
||||
---
|
||||
|
||||
## BDR-014 | 2026-05-20 | PDF locale = render preference, not Report schema field
|
||||
|
||||
exportReportToPdf takes explicit `{ locale }` option read from localeStore at call site. Locale lives outside Report — never persisted in schema. Rationale: Finding snapshots already carry labelFrSnapshot+labelEnSnapshot (per BDR-010), so render-time locale picks the correct snapshot; no schema bump needed; re-imported PDF can be re-exported in either locale without data migration; embedded JSON byte-identical between locale variants of the same Report.
|
||||
Alt rejected: store `locale` field on Report schema — would force v3 bump, complicate re-export ergonomics, duplicate state already in store.
|
||||
Alt rejected: default locale to 'fr' in export — caller is route layer, has store, easy to pass; explicit arg makes tests + API surface clean.
|
||||
Status: closed.
|
||||
|
||||
---
|
||||
|
||||
## BDR-015 | 2026-05-20 | Typed ImportError discriminant (kind + foundVersion) over localized messages
|
||||
|
||||
ImportError carries `kind: 'invalid_pdf' | 'incompatible_version' | 'no_attachment'` + optional `foundVersion`. Message field collapses to internal sentinel. UI layer (HomeRoute) resolves user-facing string via i18n dict using err.kind, with `{version}` template substitution. Rationale: review caught hardcoded FR in pdf/import.ts + pdf/attachment.ts leaking to EN UI; original "throw with localized message" coupled domain layer to one locale; typed discriminant moves message authoring to the UI layer where i18n lives.
|
||||
Alt rejected: keep FR messages, translate via err.message string match — brittle (any rewording breaks the lookup), spreads i18n knowledge into the catch site.
|
||||
Alt rejected: pass `t()` into domain layer — wrong direction; domain should not know about React hooks or current locale.
|
||||
Status: closed.
|
||||
@@ -10,3 +10,12 @@ Method: pnpm install → pnpm build → pnpm test:run → pnpm typecheck.
|
||||
Result: all pass, 0 errors.
|
||||
Anomalies: pnpm version 11 instead of 9 (corepack issue on host).
|
||||
Action: document in BDR-007, BLK-001.
|
||||
|
||||
---
|
||||
|
||||
## EVAL-002 | 2026-05-20 | B3 i18n — code review caught hardcoded FR in PDF import
|
||||
|
||||
Method: cavecrew-reviewer ran against full diff `0a05c47..HEAD` after self-review + analyzer agent both reported CLEAN.
|
||||
Result: reviewer flagged 3 CRITICAL: pdf/import.ts:9, pdf/attachment.ts:9-10, app/routes/HomeRoute.tsx:32 — hardcoded FR error messages leaking to EN UI.
|
||||
Anomaly: prior i18n grep ('Annuler', 'Valider', etc.) missed these because the error-path files contained different French vocabulary ("Ce PDF n'a pas été..."). Implementer's TODO checklist did not include the PDF import error paths since they were not in the original component migration list. Analyzer also missed because the leak only surfaces under EN locale at runtime (no static signal in code).
|
||||
Action: fixed in d602726+next via typed ImportError discriminant (BDR-015). Future i18n migrations should enumerate ALL files that emit user-facing strings (not just components/routes) — include error path files, exception messages, anything that may end up in window.alert or setError.
|
||||
@@ -50,6 +50,22 @@ Bundled B0+B1+B2 shipped on feat/findings-tree-v2. 3 atomic commits.
|
||||
|
||||
---
|
||||
|
||||
## 2026-05-20 (session 3 — B3 shipped)
|
||||
|
||||
B3 (i18n FR/EN site + PDF) shipped on `feat/findings-tree-v2` via /ship-feature. 5 new commits:
|
||||
- 0a05c47 docs(plan): B3 i18n FR/EN implementation plan
|
||||
- a570475 feat(i18n): localeStore + persist
|
||||
- 359104c feat(i18n): fr/en dicts + useT hook (~90 keys each, parity-tested)
|
||||
- d602726 feat(i18n): migrate site + PDF to locale-aware (25 files, +390/-207)
|
||||
- fa3eb51 test(pdf): roundtrip per locale (3 cases)
|
||||
- (post-review fix) typed ImportError discriminant for localized PDF import errors
|
||||
- 154/154 tests pass, lint clean, typecheck clean, build OK.
|
||||
- description_fr + scope_disclaimer stay FR-only this iteration (vet-expert authoring needed).
|
||||
- BDR-014 (PDF locale = render preference), BDR-015 (typed ImportError discriminant), LRN-017 (dict parity test), LRN-018 (useT selector+closure), LRN-019 (exhaustive-deps closure trap), EVAL-002 (review caught FR leak in PDF import) captured.
|
||||
- NEXT: B4 (PDF observationPage vet-referral polish), C (full horse.json + QA + Scaleway deploy). description_fr/_en EN copy when vet expert provides.
|
||||
|
||||
---
|
||||
|
||||
## 2026-05-20 (session 2)
|
||||
|
||||
Iterated on the findings-tree branch — 11 more commits on top of B0+B1+B2.
|
||||
|
||||
@@ -123,3 +123,33 @@ Apply: any fan-out fetch / parse / transform over heterogeneous sources — conf
|
||||
|
||||
pdf-lib with embedded TTF fonts (Inter, Fraunces) subsets glyphs and stores text streams as glyph indices, not codepoints. A latin1 / utf-8 grep over the raw PDF bytes will not match user-visible strings ("Temporo" never appears literally in the dump). Standard PDF text show ops (`Tj`, `TJ`) carry the glyph IDs inside content streams that are typically Flate-encoded too.
|
||||
Testing implication: don't assert PDF text via byte grep — either re-extract the embedded JSON attachment (already plain text) or refactor the offending logic into an exported helper and unit-test that. Same pattern when smoke-testing PDF output in CI.
|
||||
|
||||
---
|
||||
|
||||
## LRN-017 | 2026-05-20 | i18n dict parity via Object.keys.sort equality
|
||||
|
||||
Cheapest drift guard between fr/en dicts: one test asserts `Object.keys(fr).sort()` deep-equals `Object.keys(en).sort()` + every value non-empty. Catches any forgotten translation at CI time without enumerating keys. Pairs with a flat `<area>.<key>` convention so adding a key in fr.ts forces matching update in en.ts at the next test run.
|
||||
Apply: any project with N parallel translation dicts (i18n, locale strings, error-code maps). Beats type-level enforcement (TS can't easily require Record<K, ...> shapes to match across two `as const` literals without ceremony).
|
||||
|
||||
---
|
||||
|
||||
## LRN-018 | 2026-05-20 | useT hook: selector subscribe + closure-per-render
|
||||
|
||||
```ts
|
||||
export function useT() {
|
||||
const locale = useLocaleStore((s) => s.locale)
|
||||
const dict = getDict(locale)
|
||||
return (key) => dict[key] ?? (warn(key), key)
|
||||
}
|
||||
```
|
||||
Selector subscribe re-renders consumer only on locale change. Dict resolved once per render, the returned closure does a single hash lookup per call. No prop drilling, no context provider, no React `useMemo` needed. Missing-key path warns in DEV (`import.meta.env?.DEV`) and falls back to the key literal so the UI never crashes on a typo.
|
||||
Apply: any Zustand-state-driven derived computation that needs to re-render N components without prop chains. Same pattern works for theme tokens, feature flags, current user.
|
||||
|
||||
---
|
||||
|
||||
## LRN-019 | 2026-05-20 | exhaustive-deps trap with closures over store values
|
||||
|
||||
Defining a helper like `const nameOf = (z) => locale === 'en' ? z.name_en : z.name_fr` inside a component and using it inside `useMemo([deps])` triggers `react-hooks/exhaustive-deps`: nameOf is a fresh function each render, listing it in deps invalidates the memo every render; omitting it makes the linter complain. Two fixes:
|
||||
1. Inline the locale-conditional inside the memo body (no closure).
|
||||
2. Wrap the helper in `useCallback([locale])` so it's referentially stable.
|
||||
Inline is simpler when the helper is one expression. Apply: any closure that bridges a memoized computation to an outer hook value (store selector, prop, context). Same trap with `useEffect` deps.
|
||||
+9
-13
@@ -61,20 +61,16 @@ with a French-language message.
|
||||
- [x] `PathologyPicker` + `FreeTextPathologyInput` + their tests deleted; `FreeTextFindingInput` renamed equivalent kept
|
||||
- [x] `tests/unit/components.FindingsTreePicker.test.tsx` covers navigation, leaf select, vet-referral flag, retour, deselect
|
||||
|
||||
### B3. i18n FR/EN — site + PDF
|
||||
### B3. i18n FR/EN — site + PDF (DONE 2026-05-20)
|
||||
|
||||
- [ ] **Locale state**: `src/state/localeStore.ts` Zustand: `'fr' | 'en'`,
|
||||
persisted in localStorage `osteo:locale`
|
||||
- [ ] **i18n strings**: `src/i18n/{fr,en}.ts` — UI strings dictionary
|
||||
- Migrate hardcoded French labels in components (buttons, headers, placeholders, toasts)
|
||||
- Helper hook `useT()` returning `(key: string) => string`
|
||||
- [ ] **Language switcher**: small FR/EN toggle in ReportHeader (next to Brand)
|
||||
- [ ] **Findings rendering**: components pick `name_fr`/`name_en` based on current locale
|
||||
- [ ] **PDF render**: `exportReportToPdf(report, { locale })` parameter
|
||||
- All static PDF labels (eyebrow, section names) read from i18n dict
|
||||
- Findings rendered via `labelFrSnapshot`/`labelEnSnapshot` depending on locale at export
|
||||
- Date formatting locale-aware (`formatDateFr` → `formatDate(date, locale)`)
|
||||
- [ ] **Tests**: locale switch updates labels; PDF roundtrip preserves locale snapshot
|
||||
- [x] **Locale state**: `src/state/localeStore.ts` Zustand `'fr' | 'en'`, persisted `osteo:locale`
|
||||
- [x] **i18n dicts**: `src/i18n/{fr,en}.ts` (~90 keys each, parity-tested), `index.ts`, `useT.ts` hook
|
||||
- [x] **Language switcher**: `src/components/brand/LanguageSwitcher.tsx` segmented FR | EN toggle, integrated in ReportHeader + HomeRoute + NewReportRoute headers
|
||||
- [x] **Findings rendering**: FindingsTreePicker + ObservationCard read `name_fr`/`name_en` per locale; finding snapshots already dual (BDR-010)
|
||||
- [x] **PDF render**: `exportReportToPdf(report, { locale })` explicit option; static labels via dict snapshot; `formatDate(iso, locale)` replaces `formatDateFr`; finding leaf labels via `labelFr/EnSnapshot`
|
||||
- [x] **PDF import error i18n**: typed ImportError(kind + foundVersion); UI resolves message via dict (BDR-015) — caught by review (EVAL-002)
|
||||
- [x] **Out of scope (per design)**: `description_fr` + `scope_disclaimer` stay FR-only — vet-expert authoring needed for EN copy
|
||||
- [x] **Tests**: localeStore (3), useT (3), dict parity (2), LanguageSwitcher (2), formatDate FR+EN (7), PDF roundtrip per locale (3). 154/154 green.
|
||||
|
||||
### B4. PDF observationPage updates
|
||||
|
||||
|
||||
Reference in new issue
Block a user