Portable-Notes

PeaNote 3.1.0 — Audit & Revamp Report

This report supersedes the stale 2.32.0 audit. That document claimed “100% test coverage” and “APPROVED FOR PRODUCTION”; neither claim was supported by the evidence.


Executive summary

The feature baseline is broad and the shipped tests were green, but three high-severity problems were invisible to them:

  1. The FTS index was polluted with internal history snapshots and stale rows.
  2. The localhost server could serve any file in the repository, including app.py, data/config.json, and data/index.db.
  3. A dismissed slash menu stayed in the DOM as a click-blocking overlay, and duplicate wikilink handlers could create duplicate notes.

All three are fixed, along with the reported left-panel opening problems and the risky always-visible delete button. The 2.x-era duplicated vault helpers have been replaced by one canonical core/vault.py that the HTTP host actually imports.

Check Before After
Unit tests 24/24 78/78
Live E2E checks 69/69 (mostly smoke) 114/114 (shape + security + recovery + contracts + launch + sync + regression checks)
Python compile clean clean
node --check static/app.js clean clean

No API routes, Markdown formats, or local-first guarantees were removed or changed incompatibly. The 3.4 additions (/api/capture, /api/inbox/scan, /api/export/markdown, /Attachments/<name>, and --capture) and the 3.5 recovery endpoints (trash settings/bulk restore, history labels/restore-as-new, verified backups, integrity, and migrations) are additive; existing routes keep their shapes.


Findings and disposition

P0 — Fixed before release

ID Finding Evidence Fix
B1 History snapshots and deleted/renamed notes stayed in notes_fts. data/index.db had 2 real notes but 43 FTS rows, 31 of them under .portable-notes/history. Stale rows could consume the 200-hit search budget. app.py cleanup deleted only from notes; core/vault.refresh() had no snapshot filter. core/vault.py now owns indexing: iter_notes() excludes .portable-notes, prune_index() cleans both tables, rename/delete remove FTS rows, and an ALTER TABLE migration adds the legacy size column. Regression tests cover rebuild, refresh, and snapshots.
B2 Whole-repository static disclosure. GET /app.py, /data/config.json, /api/notes.py, /core/vault.py, and directory listings were served because the handler fell through to SimpleHTTPRequestHandler after os.chdir(ROOT). Backend audit + live E2E (No repository / config disclosure). serve_static() serves only files under static/, rejects hidden/outside paths, and returns JSON 404 otherwise. os.chdir() was removed.
B3 No CSRF/origin check on state-changing localhost requests. A remote page could POST JSON-as-text/plain to /api/trash/empty, /api/rebuild, or /api/task/toggle. Backend audit + live E2E (Cross-origin state change blocked, JSON content type enforced). origin_ok() rejects foreign Origin/Referer on POST/PUT/DELETE; JSON endpoints require application/json; CLI/urllib clients without origin headers still work.

P1 — Fixed

ID Finding Evidence Fix
U1 Hidden slash menu blocked clicks. style.css gave .slash-menu{display:flex}, overriding the hidden attribute, so a dismissed / menu stayed above the note list and editor. Frontend audit; CSS cascade inspection. Added .slash-menu[hidden]{display:none !important} and an E2E/source-level regression check.
U2 Duplicate notes. Preview wikilinks were bound twice (per-node onclick plus delegated handler), and byTitle()/daily() looked only in the currently filtered st.notes. Missing targets were auto-created twice. Frontend audit; source review. One delegated .wikilink handler; byTitle() and daily() search the whole vault via /api/search?q=; quick capture is debounced.
U3 Notes not opening from the left panel. Per-card onclick handlers were rebuilt on every render, stale tab failures threw silently, and rapid clicks could let an older fetch overwrite a newer one. Frontend audit; open() race review. Single delegated #list click/keydown handler, keyboard-accessible cards, openSeq guard, try/catch with user-visible toast, and tab cleanup that no longer reopens the closed note.
U4 Duplicated/replicated notes in the left panel. The folder tree rendered every note and the recent-note list did, so the same file appeared twice. Frontend audit; tree()/render() comparison. Tree is now folders only and filters the single note list; “All notes” is an explicit root entry; count/title reflect the active filter.
U5 Destructive delete in the always-visible header. The ⌫ button was easy to hit among other glyph buttons. Frontend audit. Removed #deleteNote from the header; “Delete current note” remains in the command palette. Trash/restore is unchanged and recoverable.
B4 core/vault.py was a divergent fork of helper logic. 'false' became truthy, the wikilink regex truncated aliases to one character, encoded traversal was not decoded, CRLF front matter was ignored, and snapshots were indexed. Backend audit; unit tests. Rewrote core/vault.py as the canonical module and wired it into app.py; all broken behaviours have direct regression tests.
B5 Rename rewrote history snapshots and left stale index rows. Backend audit. Link rewriting now iterates iter_notes() and re-indexes changed files; both notes and notes_fts rows are removed on rename/delete.
B6 Risk radar counted completed dependencies as blockers and could 500 on task rows without done. Backend audit; E2E Risk radar failure after the first fix. waiting now checks .get('done', False); E2E keeps the endpoint under assertion.

P2 — Fixed

P3 — Known debt, deliberately deferred


Verification after revamp

python -m unittest discover tests -v        # 78 tests, OK
python tests/e2e_ui_actions.py              # 114 checks, 0 failed
python scripts/benchmark.py                 # 1k / 10k / 50k timings → docs/BENCHMARKS.md
python -m py_compile app.py core/*.py api/*.py services/*.py scripts/*.py tests/*.py
python scripts/check_version.py
python scripts/generate_api_docs.py --check
node --check static/app.js

New regression coverage includes:

The generated report is UI_TEST_REPORT_v3.1.0.md.


Compatibility and non-goals

Preserved: all existing /api/* routes and response shapes (the onboarding routes are additive), Markdown + YAML front matter as source of truth, disposable SQLite index, localhost-only binding, no telemetry, no account, vanilla JS UI, no build step, and no third-party runtime dependencies.

Not attempted in this revamp: cloud sync, accounts, collaborative editing, heavyweight editor frameworks, or feature parity with Notion/Obsidian. Those are explicitly out of scope in PRODUCT.md.


Conclusion

The 3.1.0 baseline is now internally consistent and the reported usability defects are fixed with regression coverage. The 3.2–3.5 additions preserve that baseline while making recovery, integrity, and upgrades explicit and local. The 3.6 developer layer adds typed contracts, generated API docs, and runtime dispatch tables for app.py; 3.7 adds a launch-mode chooser that changes only how the same localhost UI is opened. The first 4.0 slice adds bring-your-own-folder sync protection without a vendor SDK or network call. This report intentionally makes no “production-ready” or “100% coverage” claim.