repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

extensions/diff-review/FEATURE-PARITY.md

Raw

Feature Parity: Browser SPA → SSR

Source of truth: browser/index.ts features

# Feature Browser impl SSR plan Test strategy
1 File tree FileTree web-component with search, expand, git status colors, rename decorations @pierre/trees/ssr preloadFileTree + serializeFileTreeSsrPayload Unit: assert serialized HTML contains all paths, git status attributes, search input. E2E: Playwright clicks a file, asserts diff scrolls into view.
2 Diff rendering FileDiff web-component, split view, syntax highlight, hover highlight, line selection @pierre/diffs/ssr preloadPatchDiff per file or preloadMultiFileDiff Unit: assert prerenderedHTML contains changed lines, line numbers, syntax tokens. E2E: Playwright asserts split columns exist.
3 Line selection onLineSelected / onGutterUtilityClick / onLineClick / onLineNumberClick callbacks → floating form Inline <form> below each diff file, or server-rendered <dialog>; data attributes on lines for minimal JS targeting Unit: POST /finding with line range → server stores finding. E2E: Playwright clicks line → form appears, fills, submits → finding visible in drawer.
4 Finding form Floating <section> with severity, category, comment, notes Inline form or modal; POST to server Unit: validation tests (existing validateFinding route). E2E: submit form → finding appears in findings list.
5 Findings list Drawer with numbered items, severity/category pills, remove button Server-rendered findings panel; remove via POST or htmx Unit: assert findings HTML renders pills. E2E: add finding → remove → count updates.
6 Review notes <textarea id="notes"> <textarea name="notes"> in submit form Unit: POST /submit passes notes to onSubmit. E2E: fill notes → submit → payload contains notes.
7 Search Client-side regex search across all diff lines, 200-result cap, keyboard nav, highlight animation Server endpoint GET /search?q=... returns HTML partial with links to file+line Unit: searchCode function extracted to shared module, tested in isolation. E2E: type query → results dropdown → click → jumps to line.
8 Theme localStorage + matchMedia → CSS custom properties on :host light-dark() CSS + prefers-color-scheme media query; optional cookie toggle Unit: assert HTML contains color-scheme meta. E2E: toggle → background color changes.
9 Pane resize/collapse Pointer events + localStorage layout state CSS grid with resize on <aside>; or minimal inline JS + localStorage E2E: drag splitter → width changes. Collapse button → pane hidden.
10 Meta display Round chip, source label, file stats, skipped files Inline server-rendered <div> Unit: assert HTML contains round number, source label, stats.
11 Carried findings renderAnnotations shows existing findings on diff lines Pass annotations array to preloadPatchDiff options Unit: assert preloaded HTML contains annotation chips.
12 Heartbeat setInterval POST /api/heartbeat Unchanged — SPA JS still polls, or server SSE Unit: existing heartbeat test passes.
13 Review polling / diff refresh setInterval GET /api/review, re-renders if hash changes HTMX poll or meta refresh, or manual refresh button Unit: refreshDiff called on submit. E2E: change file → refresh → diff updates.
14 Submit POST /api/submit JSON → clears findings, shows status POST /submit form → redirects or returns success HTML Unit: onSubmit called with findings + notes. E2E: submit → success message.
15 Cancel POST /api/cancel → window.close() hint POST /cancel → close page or redirect Unit: server closes, result promise resolves.

Test layers

  1. Unit (vitest) — Shared logic: searchCode, renderPage, renderFindings, form parsing, theme CSS.
  2. Integration (vitest + Node http) — Spin up startReviewServer, hit all routes, assert HTML/JSON responses, state mutations.
  3. E2E (Playwright) — Start dev server with fixture diff, automate Chrome/Firefox: add finding, search, submit, cancel, theme toggle, pane resize.
  4. Pi harness (existing) — harness.test.ts validates extension loads, commands work, no UI mutation after shutdown.

Migration checklist

Markdown source
File outline
# Feature Parity: Browser SPA → SSR

## Source of truth: browser/index.ts features

| #  | Feature                           | Browser impl                                                                                              | SSR plan                                                                                                               | Test strategy                                                                                                                                          |
| -- | --------------------------------- | --------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 1  | **File tree**                     | `FileTree` web-component with search, expand, git status colors, rename decorations                       | `@pierre/trees/ssr` `preloadFileTree` + `serializeFileTreeSsrPayload`                                                  | Unit: assert serialized HTML contains all paths, git status attributes, search input. E2E: Playwright clicks a file, asserts diff scrolls into view.   |
| 2  | **Diff rendering**                | `FileDiff` web-component, split view, syntax highlight, hover highlight, line selection                   | `@pierre/diffs/ssr` `preloadPatchDiff` per file or `preloadMultiFileDiff`                                              | Unit: assert `prerenderedHTML` contains changed lines, line numbers, syntax tokens. E2E: Playwright asserts split columns exist.                       |
| 3  | **Line selection**                | `onLineSelected` / `onGutterUtilityClick` / `onLineClick` / `onLineNumberClick` callbacks → floating form | Inline `<form>` below each diff file, or server-rendered `<dialog>`; data attributes on lines for minimal JS targeting | Unit: POST `/finding` with line range → server stores finding. E2E: Playwright clicks line → form appears, fills, submits → finding visible in drawer. |
| 4  | **Finding form**                  | Floating `<section>` with severity, category, comment, notes                                              | Inline form or modal; POST to server                                                                                   | Unit: validation tests (existing `validateFinding` route). E2E: submit form → finding appears in findings list.                                        |
| 5  | **Findings list**                 | Drawer with numbered items, severity/category pills, remove button                                        | Server-rendered findings panel; remove via POST or htmx                                                                | Unit: assert findings HTML renders pills. E2E: add finding → remove → count updates.                                                                   |
| 6  | **Review notes**                  | `<textarea id="notes">`                                                                                   | `<textarea name="notes">` in submit form                                                                               | Unit: POST `/submit` passes notes to `onSubmit`. E2E: fill notes → submit → payload contains notes.                                                    |
| 7  | **Search**                        | Client-side regex search across all diff lines, 200-result cap, keyboard nav, highlight animation         | Server endpoint `GET /search?q=...` returns HTML partial with links to file+line                                       | Unit: `searchCode` function extracted to shared module, tested in isolation. E2E: type query → results dropdown → click → jumps to line.               |
| 8  | **Theme**                         | `localStorage` + `matchMedia` → CSS custom properties on `:host`                                          | `light-dark()` CSS + `prefers-color-scheme` media query; optional cookie toggle                                        | Unit: assert HTML contains `color-scheme` meta. E2E: toggle → background color changes.                                                                |
| 9  | **Pane resize/collapse**          | Pointer events + `localStorage` layout state                                                              | CSS `grid` with `resize` on `<aside>`; or minimal inline JS + `localStorage`                                           | E2E: drag splitter → width changes. Collapse button → pane hidden.                                                                                     |
| 10 | **Meta display**                  | Round chip, source label, file stats, skipped files                                                       | Inline server-rendered `<div>`                                                                                         | Unit: assert HTML contains round number, source label, stats.                                                                                          |
| 11 | **Carried findings**              | `renderAnnotations` shows existing findings on diff lines                                                 | Pass `annotations` array to `preloadPatchDiff` options                                                                 | Unit: assert preloaded HTML contains annotation chips.                                                                                                 |
| 12 | **Heartbeat**                     | `setInterval` POST `/api/heartbeat`                                                                       | Unchanged — SPA JS still polls, or server SSE                                                                          | Unit: existing heartbeat test passes.                                                                                                                  |
| 13 | **Review polling / diff refresh** | `setInterval` GET `/api/review`, re-renders if hash changes                                               | HTMX poll or meta refresh, or manual refresh button                                                                    | Unit: `refreshDiff` called on submit. E2E: change file → refresh → diff updates.                                                                       |
| 14 | **Submit**                        | POST `/api/submit` JSON → clears findings, shows status                                                   | POST `/submit` form → redirects or returns success HTML                                                                | Unit: `onSubmit` called with findings + notes. E2E: submit → success message.                                                                          |
| 15 | **Cancel**                        | POST `/api/cancel` → `window.close()` hint                                                                | POST `/cancel` → close page or redirect                                                                                | Unit: server closes, `result` promise resolves.                                                                                                        |

## Test layers

1. **Unit (vitest)** — Shared logic:
   `searchCode`, `renderPage`, `renderFindings`, form parsing, theme CSS.
2. **Integration (vitest + Node `http`)** — Spin up `startReviewServer`, hit all
   routes, assert HTML/JSON responses, state mutations.
3. **E2E (Playwright)** — Start dev server with fixture diff, automate
   Chrome/Firefox:
   add finding, search, submit, cancel, theme toggle, pane resize.
4. **Pi harness (existing)** — `harness.test.ts` validates extension loads,
   commands work, no UI mutation after shutdown.

## Migration checklist

- [x] `ssr-spike.test.ts` passes (Phase 0)
- [x] `__tests__/server-html.test.ts` covers routes 1-14 (Phase 1)
- [x] `render.ts` module created with `renderPage`, `renderFindings` (Phase 2)
- [x] `server.ts` serves HTML instead of static bundle (Phase 3)
- [x] `index.ts` removes `ensureBrowserBundle` (Phase 4)
- [x] Cleanup:
      `bundle.ts`, `browser/`, old `scripts/` deleted (Phase 5)
- [x] `scripts/dev-server.ts` starts fixture server for manual Chrome/Firefox
      testing (Phase 6)
- [x] Full `vitest run` passes (15/15)
- [x] Manual smoke verified via `curl` + dev server
- [x] Line selection / inline finding form interactivity
- [x] Form-based submit/cancel
- [x] Remove finding
- [x] Search endpoint
- [x] Theme toggle (system/dark/light cookie)
- [x] Carried findings annotations on diff lines
- [x] Pane resize/collapse
- [x] Playwright E2E spec