Adds a preview server that follows the real server rules
Lighthouse and the browser tests need a real 404 status, the .html mapping and the production headers, which vite preview does not give. It is not wired into the scripts yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+20
-17
@@ -224,21 +224,21 @@ The unknowns that can invalidate the design come first. Steps 3 to 6 prove Start
|
||||
|
||||
Files are new `config/*` files and `src/test/htmlArbitraries.ts`. Config files are Dutch-commented like their neighbours. They run under Node type stripping: relative imports with `.ts`, no aliases.
|
||||
|
||||
### Step 7: `config/pageFiles.ts` [ ]
|
||||
### Step 7: `config/pageFiles.ts` [x]
|
||||
|
||||
- Executor: Sonnet.
|
||||
- Implements: BR-BLD-02, 03; domain-entities `config/pageFiles.ts`.
|
||||
- Do: create the pure module with `NOT_FOUND_PATH = '/404'`, `NOT_FOUND_FILE = '404.html'`, `pageFile(path: string): string` (`/` gives `index.html`; otherwise the path without its leading slash plus `.html`) and `pagePath(file: string): string | undefined` (inverse; `undefined` for `404.html` and anything that is not a `.html` page file). Comment on why one mapping serves `vite.config.ts`, the runner and the preview server.
|
||||
- Done when: `pnpm exec tsc --noEmit` clean. (Switching `vite.config.ts` to import it happens in Step 24, to keep B2 off B1's files.)
|
||||
|
||||
### Step 8: `config/inlineScripts.ts` [ ]
|
||||
### Step 8: `config/inlineScripts.ts` [x]
|
||||
|
||||
- Executor: Sonnet.
|
||||
- Implements: BR-SCR-01 to 11, 22 (nothing to build for 22); FR-PR-19, 20; D2, D3.
|
||||
- Do: create the module with the exports of component-methods.md (`MovedScript`, `ExternalizeResult`, `externalizeInlineScripts`, `findExecutableInlineScripts`) and no dependency except `node:crypto` for SHA-256. Implement one internal scanner (BR-SCR-02) that yields script elements with their range, verbatim attribute text and body; the classification of flowchart 1.1 (BR-SCR-04: `src` attribute in any form, empty body, type list, `module`); the unsupported-form checks that throw (BR-SCR-05: `async`/`defer` on a classic script, `<!--` in the body, relative specifier in a module body; error type or message with the codes `UNSUPPORTED_SCRIPT` and `UNTERMINATED_SCRIPT` so the runner can map them); naming (BR-SCR-07, 08; first 12 hex of SHA-256 of the UTF-8 body); the replacement `<script` + attribute text + ` src="/assets/inline-<hash>.js"` + `></script>` (BR-SCR-06). Parse attributes with quote awareness; compare tag and attribute names case-insensitively. A header comment explains why this step exists (NFR-PR-Q-05, BR-BLD-12): the strict `script-src 'self'` blocks Start's inline scripts.
|
||||
- Done when: `pnpm exec tsc --noEmit` clean; a quick manual call on the worked-example table of business-logic-model.md § 3.1 gives the listed outputs (the real tests come in Step 9).
|
||||
|
||||
### Step 9: Tests for `inlineScripts` (P1 to P9) [ ]
|
||||
### Step 9: Tests for `inlineScripts` (P1 to P9) [x]
|
||||
|
||||
- Executor: Sonnet.
|
||||
- Implements: NFR-PR-Q-02; PBT-02 to 05, 07, 08, 10; P1 to P9.
|
||||
@@ -248,7 +248,7 @@ Files are new `config/*` files and `src/test/htmlArbitraries.ts`. Config files a
|
||||
2. `inlineScripts.test.ts`: example-based tests for every row of business-logic-model.md § 3.1 and for each branch of BR-SCR-04 (type list incl. `type=""`, uppercase, `module`; `src` present without value), BR-SCR-05 (a, b, c), BR-SCR-03 (unterminated), attribute retention, trailing `/` in the tag, `>` inside a quoted attribute, uppercase tag names, duplicate bodies. Property tests with titles carrying the category: P1 (invariant), P2 (invariant), P3 (round-trip), P4 (idempotent), P5 (invariant), P6 (invariant), P7 (oracle, `findExecutableInlineScripts` against the model), P8 (invariant), P9 (split and join).
|
||||
- Done when: `pnpm exec vitest run config/inlineScripts.test.ts` passes; the shrunk counterexample and seed would be printed on failure (do not catch or disable).
|
||||
|
||||
### Step 10: Tests for `pageFiles` (P10) [ ]
|
||||
### Step 10: Tests for `pageFiles` (P10) [x]
|
||||
|
||||
- Executor: Sonnet.
|
||||
- Implements: PBT-02, 10; P10.
|
||||
@@ -256,7 +256,7 @@ Files are new `config/*` files and `src/test/htmlArbitraries.ts`. Config files a
|
||||
- Do: examples for `/`, `/over-mij`, `/soorten-fotoshoots/newborn`, `404.html`, a non-page file; property (round-trip): `pagePath(pageFile(p)) === p` for every key of `sitePages` and for generated route-like paths (`routePath` from `arbitraries.ts`); invariant: the file never starts with `/` and ends with `.html`.
|
||||
- Done when: `pnpm exec vitest run config/pageFiles.test.ts` passes.
|
||||
|
||||
### Step 11: Runner `config/externalizeInlineScripts.ts` [ ]
|
||||
### Step 11: Runner `config/externalizeInlineScripts.ts` [x]
|
||||
|
||||
- Executor: Sonnet.
|
||||
- Implements: BR-SCR-12 to 21, BR-MAIL-10, BR-SEC-02, 03, BR-BLD-04, 09 (check part); FR-PR-03, 19, 20, 22; NFR-PR-SEC-03, 04.
|
||||
@@ -267,7 +267,7 @@ Files are new `config/*` files and `src/test/htmlArbitraries.ts`. Config files a
|
||||
Import `sitePages`, `siteContent`, `emailAddress`, `sitemapXml`, `seo` constants with relative `.ts` paths. A header comment explains why the step exists (BR-BLD-12).
|
||||
- Done when: `pnpm exec tsc --noEmit` clean; running `node config/externalizeInlineScripts.ts` on the Step 4 output prints violations (expected at this point: EMAIL_IN_OUTPUT until Step 17) and writes nothing.
|
||||
|
||||
### Step 12: Tests for the runner core (P11 to P13) [ ]
|
||||
### Step 12: Tests for the runner core (P11 to P13) [x]
|
||||
|
||||
- Executor: Sonnet.
|
||||
- Implements: NFR-PR-Q-02; PBT-04, 05, 07, 08, 10; P11 to P13.
|
||||
@@ -275,7 +275,7 @@ Files are new `config/*` files and `src/test/htmlArbitraries.ts`. Config files a
|
||||
- Do: example-based test for each violation code and for the success path (including a second run being a no-op and a `404.html` present); use `anySiteContent`/`validEmail` from `arbitraries.ts` for addresses; a temp-directory test for `externalizeOutput` (writes script files first, writes nothing on violation, exit code via a returned or thrown result you can assert). Properties: P11 (idempotent: apply the plan's writes to the file map, plan again: no writes, no violations), P12 (oracle: violations equal a simple model), P13 (oracle for `containsAddress` with all encodings and random insertion; clean text never flagged).
|
||||
- Done when: `pnpm exec vitest run config/externalizeInlineScripts.test.ts` passes.
|
||||
|
||||
### Step 13: Run the script step on the real output (V3, V4, V13, V17) [ ]
|
||||
### Step 13: Run the script step on the real output (V3, V4, V13, V17) [x]
|
||||
|
||||
- Executor: Sonnet.
|
||||
- Implements: FR-PR-19, 20; BR-SCR-17; V3, V4, V13, V17.
|
||||
@@ -289,7 +289,7 @@ Files are new `config/*` files and `src/test/htmlArbitraries.ts`. Config files a
|
||||
|
||||
Disjoint from B2 and B4. Runs only targeted `vitest run` commands. The editing order inside the batch is the step order.
|
||||
|
||||
### Step 14: `lib` changes for the e-mail address [ ]
|
||||
### Step 14: `lib` changes for the e-mail address [x]
|
||||
|
||||
- Executor: Sonnet.
|
||||
- Implements: BR-MAIL-07, 08; FR-PR-22.
|
||||
@@ -297,7 +297,7 @@ Disjoint from B2 and B4. Runs only targeted `vitest run` commands. The editing o
|
||||
- Do: add `isEmailAddressValid(parts: EmailAddress): boolean`; `emailAddress` reuses it (same results as today). `contactChannels(email, socials, assemble)` with the third parameter: `assemble` false and valid parts give `{ kind: 'email-pending' }` first (no `href`, no `label`); `assemble` true gives the existing email channel; invalid parts none. Extend the `ContactChannel` union (and `external: false` stays on the email kind only). Existing callers are updated in Step 17. Comments in English like the file.
|
||||
- Done when: `pnpm exec tsc --noEmit` reports only the call sites to be fixed in Step 17 (note them), nothing else.
|
||||
|
||||
### Step 15: Tests for the `lib` changes (P14, P15) [ ]
|
||||
### Step 15: Tests for the `lib` changes (P14, P15) [x]
|
||||
|
||||
- Executor: Sonnet.
|
||||
- Implements: NFR-PR-Q-01, Q-02; PBT-03, 05, 10; P14, P15; 100% coverage of `src/lib`.
|
||||
@@ -305,7 +305,7 @@ Disjoint from B2 and B4. Runs only targeted `vitest run` commands. The editing o
|
||||
- Do: examples for each branch of the new parameter and the new function. P15 (oracle): `isEmailAddressValid(p) === (emailAddress(p) !== null)` over `anyEmail`. P14 (invariant): with `assemble` false, `JSON.stringify(contactChannels(...))` never contains the assembled address, and the channel count equals the count with `assemble` true, over `anySiteContent`/`validEmail` and `socialLink` lists.
|
||||
- Done when: `pnpm exec vitest run src/lib/emailAddress.test.ts src/lib/contactChannels.test.ts` passes.
|
||||
|
||||
### Step 16: Search gating, navigation, not found [ ]
|
||||
### Step 16: Search gating, navigation, not found [x]
|
||||
|
||||
- Executor: Sonnet.
|
||||
- Implements: BR-HYD-10, 11, 12, 13; BR-404-04, 05; FR-PR-06, 07, 15.
|
||||
@@ -315,8 +315,9 @@ Disjoint from B2 and B4. Runs only targeted `vitest run` commands. The editing o
|
||||
- Navigation: all top-level `NavLink`s in `NavigationBar` and the plain `RouterLink`s in `MobileNav` get `activeOptions={{ exact: true, includeSearch: false }}` (a shared constant per file like `NavSubmenu` has).
|
||||
- `NotFound`: use `hydrated && isShootSectionPath(pathname)`. Keep the in-body `<title>` and `noindex` meta.
|
||||
- Done when: `pnpm exec tsc --noEmit` clean; the old tests of these files pass (`pnpm exec vitest run src/app.test.tsx src/navSubmenu.test.tsx src/components/NavigationBar src/components/StatusPage`); tests that fail because they assumed the first-render search are adapted per BR-TST-02 and listed in the Record line.
|
||||
- Record (2026-10-31): no old test needed a change; new test cases in `NavigationBar.test.tsx`, `NotFound.test.tsx`, `src/routes/hydration.test.tsx`.
|
||||
|
||||
### Step 17: Footer and e-mail components [ ]
|
||||
### Step 17: Footer and e-mail components [x]
|
||||
|
||||
- Executor: Sonnet.
|
||||
- Implements: BR-HYD-14; BR-MAIL-01 to 06, 09 (placeholders only); FR-PR-22; V10 (first sizing).
|
||||
@@ -329,8 +330,9 @@ Disjoint from B2 and B4. Runs only targeted `vitest run` commands. The editing o
|
||||
- `ContactForm`: use `useEmailAddress` instead of `emailAddress(email)`; the failed-state link unchanged otherwise. `shownAt` unchanged (BR-HYD-16).
|
||||
- Update the call sites that Step 14 broke.
|
||||
- Done when: `pnpm exec tsc --noEmit` clean; `pnpm lint` clean; `renderToString` of `Footer`, `ContactDetails`, `ContactFormGate` with the real `siteContent` contains no `@andreaslop.nl`/`info@` (quick manual check; the tests come in Step 21). Placeholder sizes are first estimates; they are measured in Steps 27 and 34 (V10).
|
||||
- Record (2026-10-31): placeholder sizes are estimates, see V10 in the verification log. `src/test/hydrate.tsx` (new) is the shared hydration test helper. `useInView.ts` got a guard in the effect (see Step 19).
|
||||
|
||||
### Step 18: Testimonials in the HTML [ ]
|
||||
### Step 18: Testimonials in the HTML [x]
|
||||
|
||||
- Executor: Sonnet.
|
||||
- Implements: BR-LZY-02; FR-PR-01; NFR-PR-S-02; V9 (code part).
|
||||
@@ -338,15 +340,16 @@ Disjoint from B2 and B4. Runs only targeted `vitest run` commands. The editing o
|
||||
- Do: `CarouselPlaceholder` renders every visible testimonial as a `TestimonialSlide`: the longest in normal flow as today (it sets the height), the others in a wrapper that is visually hidden (use Chakra's visually hidden recipe/`srOnly`-style props used elsewhere in the repo), `aria-hidden="true"` and `inert`. Do not change the carousel itself, the single-review path, or `inView` logic. Update the comment.
|
||||
- Done when: `pnpm exec tsc --noEmit` clean; `renderToString` of `Testimonials` with the real testimonials contains every quote text (manual check; test in Step 21).
|
||||
|
||||
### Step 19: Tests for hooks (hydration phases) [ ]
|
||||
### Step 19: Tests for hooks (hydration phases) [x]
|
||||
|
||||
- Executor: Sonnet.
|
||||
- Implements: BR-HYD-02 to 05, 09; BR-TST-02; NFR-PR-Q-01; PBT: "No PBT properties identified" for hooks (business-logic-model.md § 9), example-based only.
|
||||
- Files: new or extended `web/src/hooks/useHydrated.test.tsx`, `usePageLoaded.test.tsx`, `useInView.test.tsx` (new), `useReveal.test.tsx`, `web/src/components/Hero/useHeroSlider.test.tsx`.
|
||||
- Do: for each hook test (a) `renderToString` (server snapshot value), (b) hydrating a server-rendered markup with `hydrateRoot` shows the server value in the hydrating render and the real value afterwards, (c) a plain `render` (client mount) shows the real value at once. Cases: `useHydrated` false/true; `usePageLoaded` false then `load` event; `useInView` without `IntersectionObserver` (true after hydration, `skip` respected) and with a fake observer (`src/test/fakeIntersectionObserver.ts`); `useReveal` first-render `reducedMotion` false; `useHeroSlider` `hidden` from `visibilitychange`. Keep all existing tests of these files.
|
||||
- Done when: `pnpm exec vitest run src/hooks src/components/Hero` passes.
|
||||
- Record (2026-10-31): found while testing: the effect of the hydrating render still sees `unsupported` false and threw `ReferenceError` without `IntersectionObserver`; `useInView.ts` now checks `typeof IntersectionObserver` in the effect too. No old test changed.
|
||||
|
||||
### Step 20: Tests for routes, navigation and not found [ ]
|
||||
### Step 20: Tests for routes, navigation and not found [x]
|
||||
|
||||
- Executor: Sonnet.
|
||||
- Implements: BR-HYD-10 to 13; BR-404-04, 05; FR-PR-06, 07, 15; NFR-PR-Q-01.
|
||||
@@ -354,7 +357,7 @@ Disjoint from B2 and B4. Runs only targeted `vitest run` commands. The editing o
|
||||
- Do: direct load simulation (`renderApp('/contact?pakket=...')`) still preselects the package and tidies the address bar; `/?pakket=` still scrolls/focuses via the `ContactSection` effect; `/portfolio?shoot=gezin` filters and filter clicks still navigate with `replace`; `NotFound` shows one button while hydrating and the two extra buttons under `/soorten-fotoshoots/` after (use `hydrateRoot`), and on a plain mount at once; no navigation link is current on an unknown sub-path such as `/over-mij/x`, current on real pages and with a search.
|
||||
- Done when: the touched test files pass with targeted `vitest run`.
|
||||
|
||||
### Step 21: Tests for Footer, e-mail components and Testimonials [ ]
|
||||
### Step 21: Tests for Footer, e-mail components and Testimonials [x]
|
||||
|
||||
- Executor: Sonnet.
|
||||
- Implements: BR-HYD-14; BR-MAIL-01 to 07; BR-LZY-02; FR-PR-22; V9 (test part); NFR-PR-Q-01.
|
||||
@@ -366,14 +369,14 @@ Disjoint from B2 and B4. Runs only targeted `vitest run` commands. The editing o
|
||||
|
||||
## Part E: Preview server (batch B4, Sonnet; parallel with B2 and B3)
|
||||
|
||||
### Step 22: `config/previewServer.ts` [ ]
|
||||
### Step 22: `config/previewServer.ts` [x]
|
||||
|
||||
- Executor: Sonnet.
|
||||
- Implements: BR-SRV-01 to 08; D10; NFR-PR-SEC-01; FR-PR-14 (preview part).
|
||||
- Do: create `resolveRequest(path, fileExists)` per BR-SRV-01 to 07 (decode once; reject NUL, backslash, `..` segments; `/` to `index.html`; no-dot last segment through `pageFile` when the file exists; dot last segment is a file request; else `404.html` with status 404; trailing slash and `/404` interim behaviour exactly as BR-SRV-07 says, with a comment "final rule in unit 3 Infrastructure Design"; never returns `{ redirect }`). `startPreviewServer(clientDir, port)` with Node `http`: `GET`/`HEAD` only (405 otherwise), `securityHeaders('production')` on every response, `Cache-Control: no-cache` for HTML, content types from the extension, bind `127.0.0.1`, prints a line containing `Local` with the URL (matches `startServerReadyPattern` in `lighthouserc.cjs`), CLI entry parses `--port` (default 4173), `--strictPort` (fail if taken), and an optional `--dir` (default `dist/client`). Import `pageFile` from `./pageFiles.ts` (Step 7; if B2 has not finished, wait for it) and `securityHeaders` from `./securityHeaders.ts`. Dutch header comment explaining why a own server (D10: real 404 and `.html` mapping, no Node server in production).
|
||||
- Done when: `pnpm exec tsc --noEmit` clean; starting it manually on the Step 4 output answers `curl -I http://127.0.0.1:4173/over-mij` with 200 and the CSP header, and `/nope` with 404 (stop the server afterwards; skip this check while Lighthouse is running anywhere).
|
||||
|
||||
### Step 23: Tests for the preview server (P16, P17) [ ]
|
||||
### Step 23: Tests for the preview server (P16, P17) [x]
|
||||
|
||||
- Executor: Sonnet.
|
||||
- Implements: PBT-03, 05, 07, 08, 10; P16, P17; SECURITY-11 misuse case.
|
||||
|
||||
+2
-2
@@ -33,8 +33,8 @@ Notes:
|
||||
| V6 | Code splitting; router plugin unused | 4 (30 later) | Start's plugin includes `tanstackRouterGenerator` and `tanStackRouterCodeSplitter` itself (client and server environments), so route code splitting is on without an option and `@tanstack/router-plugin` is not needed as a direct dependency. Removed with `pnpm remove @tanstack/router-plugin`; only Start's own copy (1.168.48) remains. | Client build has one chunk per route (`over-mij-*.js`, `contact-*.js`, `portfolio-*.js`, `newborn-*.js`, ..., `_-*.js` for the catch-all), plus `ContactForm`, `Lightbox`, `TestimonialCarousel` chunks. Step 30 re-checks. | OK |
|
||||
| V7 | Sitemap in the client environment only | 4 | `this.environment.name === 'client'` identifies the client build in `generateBundle` (Vite 8.3.1, Start environments `client` and `ssr`). | `dist/client/sitemap.xml` exists once (10 `<loc>`, no `/privacyverklaring`, no `/404`); `find dist -name sitemap.xml` gives only that file; `public/` has no `sitemap.xml`. | OK |
|
||||
| V8 | Lazy `ContactForm` in HTML and hydration | 27 | open (first look: `contact.html` contains `data-testid="contact-form"` and its fields; `/contact` hydrates in Chrome without console output) | | open |
|
||||
| V9 | Testimonials in HTML, hidden slides | 21, 27 | open | | open |
|
||||
| V10 | Placeholder sizes, CLS below 0.01 | 17, 34 | open | | open |
|
||||
| V9 | Testimonials in HTML, hidden slides | 21, 27 | Code part (step 18, 21): `renderToString` of `Testimonials` holds the quote of every visible review; the copies besides the longest sit in a `VisuallyHidden` wrapper with `aria-hidden` and `inert`; axe has no violations in jsdom with the placeholder showing. Layout and reading order in a browser: step 27. | `Testimonials.test.tsx` (4 new tests) | open |
|
||||
| V10 | Placeholder sizes, CLS below 0.01 | 17, 34 | First estimates (step 17), not measured: footer item `minH` 44px below `lg`, `1lh` from `lg` (one line of the list item); contact card item `minH` 44px; gate notice inline block `38ch` (lead " Mail me voor nu op " 20 + address 18 characters, from the parts without assembling) plus a hidden button with the recipe and label. To be measured in 27 and 34. | `Footer.tsx`, `ContactDetails.tsx`, `ContactFormGate.tsx` | open |
|
||||
| V11 | One title, one noindex meta | 4 (normal pages), 27 (`404.html`) | Normal pages in the prerendered HTML: one `<title>`, one `description`, one `canonical`, no `data-fallback`, a robots meta only on `/privacyverklaring`. `404.html`: one `<title>` ("Pagina niet gevonden \| Andrea Slop Fotografie") and one `<meta name="robots" content="noindex">`, no description or canonical. React writes `<meta charSet="utf-8">` with a capital S (valid, attribute names are case-insensitive). | `scripts.mjs` counts per file. After hydration in Chrome: `/`, `/over-mij`, `/contact` still 1 title. Caution for Step 27: `/soorten-fotoshoots/onbekend` showed 2 titles and 2 robots metas after React error #418 (the two extra 404 buttons render before hydration; Step 16 fixes that); `/onbekend` is clean. | OK (normal pages); `404.html` source OK, final check in 27 |
|
||||
| V12 | 404 hydration with real shell | 27 | open (first look, before Step 16: `/onbekend` hydrates clean; `/soorten-fotoshoots/onbekend` gives #418, which Step 16 `hydrated && isShootSectionPath` should remove) | | open |
|
||||
| V13 | Timestamps and build paths | 4, 13 | Repeated on the final output of the runner (HTML plus the 16 moved script files plus all JS/CSS/XML/TXT/JSON): no build timestamp (`YYYY-MM-DDTHH:MM`) in any text file, no `.map` file, no repository root path (forward slashes, backslashes or doubled backslashes) in any text file. File names are content hashes, so they cannot carry a timestamp. | Scan in the scratch run (`repoPathFiles: 0`, `timestampFiles: 0`, `maps: 0`); the runner's own BUILD_PATH_LEAK check reported nothing. | OK |
|
||||
|
||||
Reference in New Issue
Block a user