Files
relicario/docs/superpowers/specs/2026-11-06-lastpass-import-hardening-design.md
adlee-was-taken 80dabac414 test(import): LastPass CSV fixture set + generator + hardening spec
Synthetic, deterministic fixtures (BOM, legacy 7-col, CRLF, latin-1, hostile,
NoteType notes, ragged rows) with an expected.json oracle, plus the
handoff spec for the hardening work. Large/huge stress files are gitignored.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SpjhsvZuNPDw84Hc1J72X6
2026-11-06 20:48:13 -05:00

97 lines
9.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# LastPass import hardening (vault tab + core) — design / handoff spec
**Date:** 2026-11-06 · **Status:** approved by user for planning · **Path:** bounded (existing flow, QA + fixes)
**Worktree:** `/home/alee/Sources/relicario-worktrees/lastpass-import-hardening` · **Branch:** `feature/lastpass-import-hardening` (from `main` @ `bb88f6a`)
## Hard rules for every agent that touches this (read first)
- `WORKTREE: /home/alee/Sources/relicario-worktrees/lastpass-import-hardening. cd there first; never edit under /home/alee/Sources/relicario/ (the main checkout; it has the owner's uncommitted WIP).`
- Verify before your first edit: `git -C <worktree> rev-parse --show-toplevel` prints the worktree path.
- **Do NOT merge into main or any other branch, do NOT push, do NOT open a PR, do NOT remove the worktree. Leave the branch and worktree and stop.** Record `git rev-parse main` before the run (expect `bb88f6aa3ca0dd433b82e5c1fb0c2303544aef59`) and compare after.
- Ask the user before any `rm`, `git reset --hard`, `git push --force`, `git branch -D`.
- A test of code that calls an external service fakes it at the boundary (`fetch`, `chrome.runtime`), never by replacing the project's own wrapper.
- CLI / extension parity: a behaviour fix in `relicario-core` serves both; do not ship an extension-only divergence without saying so.
- Commit per task with a conventional message (`fix(core): ...`, `test(ext): ...`). Never squash; git history is the audit log.
## Goal
The vault tab's **Import → LastPass CSV** flow is untested against realistic exports and probably has bugs. Find them with fixtures, fix them test-first, and leave a repeatable test asset behind. Scope is import only; other vault-tab operations are a separate follow-up sweep.
## What already exists (read, don't rewrite)
| Layer | File |
|---|---|
| Parser (shared by CLI + WASM) | `crates/relicario-core/src/import_lastpass.rs` (`parse_lastpass_csv`, `EXPECTED_HEADER`, `ImportWarning`) |
| WASM bridge | `crates/relicario-wasm/src/lib.rs` ~563 (`parse_lastpass_csv_json`) |
| SW handlers | `extension/src/service-worker/router/popup-only.ts` (`parse_lastpass_csv`, `import_lastpass_commit` ~601) |
| UI | `extension/src/vault/components/import-panel.ts`, route in `vault-router.ts`, link from `popup/components/settings-vault.ts:200` |
| Existing tests | `extension/src/service-worker/__tests__/import.test.ts`, `vault/components/__tests__/import-panel.test.ts`, `crates/relicario-core/tests/import_lastpass.rs`, `crates/relicario-cli/tests/import_lastpass.rs` |
| Binary transport | `extension/src/shared/message-binary.ts` (base64 envelope; SW decodes inbound at `service-worker/index.ts:82`) |
Prior design: `docs/superpowers/specs/2026-04-27-relicario-import-export-design.md`.
## Fixtures (already generated — the test asset)
`tests/fixtures/lastpass/*.csv` + `expected.json` (the oracle), produced by `tools/lastpass-fixtures/gen.py` (deterministic; `--large N` and `--huge-note MB` add gitignored stress files). `expected.json` states the CORRECT outcome per file plus a `status`: `baseline` (should pass today), `suspect` (believed to fail today), `needs_decision` (product call, default below). **Treat a failing `baseline` as a regression to explain, a failing `suspect` as the bug to fix.**
## Task list (order matters)
**T0 — Baseline.** In the worktree: `cargo build && cargo test -p relicario-core -p relicario-cli`; `cd extension && npm ci && npm run build:all && npm test`. Record pass counts as evidence. Red baseline = stop and report, do not proceed.
**T1 — Characterize (tests first, no fixes).**
- Rust: new `crates/relicario-core/tests/import_lastpass_fixtures.rs` that loads every committed fixture + `expected.json` and asserts `fatal` / login count / note count / warning rows. (`serde_json` is already a dependency.) Fixtures needing a decision are asserted against the **default below**.
- Extension: a vitest that feeds the same fixtures through the SW `parse_lastpass_csv` handler → `import_lastpass_commit`, with the git host faked at the **HTTP boundary**, asserting what is written (item blobs + manifest) and the response.
- Run, and write the red/green table into the evidence file. Expected red: `03-bom`, `04-legacy-7col`, `10-hostile` (js/data URLs), possibly `08-latin1`.
**T2 — Core fixes (parser).** Make T1's red tests green, minimal diffs:
1. Strip a leading UTF-8 BOM before header validation.
2. Accept the legacy 7-column header by mapping columns **by name** (not position); still reject unrecognised headers with the existing clear error. The 8-col path must be byte-for-byte unchanged in behaviour.
3. Non-UTF-8 row → one warning naming the row, rest of the file imports (verify; fix only if broken).
4. `url` with scheme `javascript:`, `data:`, `vbscript:`, `file:`, `blob:` → import the login **without** URL plus a warning (same shape as the existing invalid-URL warning). Keep every other scheme.
5. Add a CLI integration case so `relicario import` shares the fixes (parity).
**T3 — Extension commit path.** Read `import_lastpass_commit` critically; the suspects are:
- One git commit per item then a final manifest commit: a failure midway leaves encrypted item blobs with no manifest entry (invisible), a retry mints fresh IDs and duplicates them, and `state.manifest` (in memory) was already mutated.
- No progress signal, and no timing data for large files.
Required invariants (design the mechanism yourself, smallest thing that satisfies them):
- On failure the in-memory manifest is restored to its pre-import state **or** the manifest was durably checkpointed to match what was written — never "blobs written, manifest silent".
- The response on failure says how many items were committed and which was first not committed.
- Progress reaches the UI (count so far).
- Measure `large-3000.csv` end to end against the faked host; record call count and wall time. If it is unreasonable (> 2× per-item call overhead of a single `add_item`), propose and implement chunked manifest checkpoints (recommended every 50 items). Do not invent a new git-host write API.
- `huge-note-2mb.csv`: must either import or fail with a clear message — no hang, no silent truncation.
- `chrome.runtime.sendMessage` boundary test: a real multi-hundred-KB CSV `ArrayBuffer` survives the envelope into the handler (expected to already work; prove it).
**T4 — Panel UI.** Known by reading the code, confirm with a DOM test then fix:
- `import-panel.ts:115` sets `cancelBt.disabled = true` and the success path never re-enables it, so **"Done" is dead**. Re-enable; "Done" resets the panel to idle (clears file input, preview, warnings).
- Re-picking the same file after Done/Cancel must work (clear `fileEl.value`).
- "Reload the sidebar to see them" is a bug-in-waiting: refresh the list/sidebar counts after a successful import instead.
- Zero importable items (`06-header-only`, all-rows-skipped): explicit "nothing to import" message, Import stays disabled.
- Header/format error (`05-wrong-format`): the message names the expected format and what was found (already close; keep it accurate and readable), no stack-ish text.
- 3000 warnings must not freeze the page: cap the rendered list (e.g. first 200 + "and N more", with the total) and keep it scrollable.
- Titles/groups/notes from `10-hostile.csv` render as text everywhere the import UI echoes them (the panel uses `escapeText`; assert it, including the preview and the warning list).
- Accessibility basics: file input labelled, progress in a `role="status"` live region, buttons keep focus order.
**T5 — Docs and tracking.**
- Add an **Extension → Import** section to the manual test plan (`docs/` copy, not the gitignored `BUGS/`) listing each fixture with expected outcome; this is the runbook for the live-browser pass.
- Update `STATUS.md`, `extension/ARCHITECTURE.md` (only if the message protocol changed, e.g. a progress message), and `CHANGELOG.md` unreleased entry. Tick any plan checkboxes touched.
**T6 — Final wave.** Full gate: `cargo test`, `cargo clippy -- -D warnings`, `cd extension && npm run build:all && npm test`. Paste `git log --oneline main..HEAD` and each task's commit. Leave everything on the branch. **Stop. Do not merge.**
## Defaults for the open decisions (user may veto before planning)
| Fixture | Decision | Default |
|---|---|---|
| `04-legacy-7col` | accept legacy header? | **Accept**, map by name |
| `08-latin1` | non-UTF-8 row? | **Warn and skip that row**, no encoding guessing |
| `10-hostile` | js:/data: URLs? | **Import login without URL + warning** |
| `09-notetypes` | map `NoteType:Credit Card` etc. to Card/Key types? | **No** — keep raw secure notes, assert nothing is dropped; log mapping as a roadmap idea |
## Out of scope
Restyling; mapping NoteType notes to typed items; other vault-tab operations (separate sweep); org-vault import; any change to wire formats (`docs/FORMATS.md`). If a fix would touch a wire format, stop and report.
## Manual gate after the agents finish (user + Claude, not the agents)
Live run in real Chrome against a **throwaway** vault repo: import `01-basic`, `02-warnings`, `10-hostile`, then `large-3000`; confirm items appear, the manifest is consistent after a deliberately interrupted import, and the CLI can read what the extension wrote.