# Code Generation Plan - Unit 3: Hosting and targets Feature: prerendering. Unit: 3 "hosting-and-targets" (URL rules, real 404, nginx and IIS configuration, upload order, Lighthouse targets). This plan is the single source of truth for Code Generation (Part 2). Execute the steps in order, mark each checkbox `[x]` as soon as its "Done when" is met, and do not deviate from the plan. The plan stands alone, but the design documents in § 0.2 hold the reasons; read them before your first step. ## 0. Context an executor needs ### 0.1 What is built The site is React 19.3 + TanStack Start static prerendering + Chakra UI v3 in `web/`, hosted statically: nginx on the test host (two Raspberry Pis, the hosting Pi runs nginx 1.30.6) and IIS on production (webhost **not purchased yet**). A strict CSP is set by `config/securityHeaders.ts`. Units 1 and 2 are built: every page is a prerendered HTML file in `dist/client` (`index.html`, `x.html`, `soorten-fotoshoots/.html`, `404.html`), served in `pnpm preview` by `config/previewServer.ts` (Lighthouse and browser tests), and the server configuration is generated from `config/serverConfig.ts` into `web/deploy/`. Unit 3 does these things, in this order of risk: 1. **One URL contract** (BR-HST-01 to 08) on nginx, IIS and the preview server, from one page list: `/x` serves `x.html` (200, no redirect), `/` serves `index.html`, unknown URLs serve `404.html` with a real 404 (the SPA fallback goes away), a trailing slash and the variants `.html`, `/index`, letter case of a known page get one 301 to the canonical path with the query string kept, `/404` and `/404.html` answer 404. Directories next to page files (`soorten-fotoshoots/` next to `soorten-fotoshoots.html`) never redirect or list. 2. **A real nginx proves the nginx rules** (BR-HST-24): a test starts an unprivileged nginx with the generated block and compares it with the preview server. 3. **Compression** (FR-PR-23, BR-HST-09 to 11): the generated nginx block carries its own `gzip` configuration (the hosting Pi has no `gzip` active and nothing may be assumed from its global config); one shared type list feeds the preview server, nginx and the IIS MIME pins. 4. **IIS rules** are generated as designed (BR-HST-04, 07, 10) but are **unverified until a host exists**. No probe kit, fallback variants, `IIS_WEB_CONFIG_VARIANT` or rule simulator are built. IIS is tested only as generated text, as `serverConfig.test.ts` does today. 5. **Deployment** (FR-PR-17, 18; BR-HST-14 to 18): an artifact guard, a three-pass production upload with a tested lftp syntax, a shared post-deploy script, and the matching CI workflow edits. Nothing is deployed or dispatched. `deploy-production` stays dispatch-only (no host). 6. **Lighthouse** (NFR-PR-P-01, P-02, S-01; BR-HST-21 to 23): the preview gets an opt-in `/__audit/404` route used only by the Lighthouse start command (the 200 at `/404.html` goes away), `lighthouserc.cjs` becomes data-driven with a guard that every mobile exception has a recorded decision. **Targets do not change in this plan**; the final measurement (three runs, all pages, mobile and desktop) is reported for the owner's per-page decisions and the plan stops there. `numberOfRuns` stays 1. Out of scope (do not build, do not "prepare"): IIS probe kit, IIS fallback variants, an IIS simulator, a change to the generated proxy config `test.andreaslop.nl.proxy.conf` (keep it as it is), any change on the Pi, in the `server-ops` repository or at the webhost, a merge, router settings (`caseSensitive`; the router stays unchanged), responsive photos, any new dependency. If a step seems to need one of these, STOP. No user stories; traced to requirements. Depends on units 1 and 2 (done). ### 0.2 Files to read Design (under `aidlc-docs/features/prerendering/`): 1. `construction/hosting-and-targets/infrastructure-design/infrastructure-design.md` (all of it: rules BR-HST-01 to 24, § 3.1 result table, § 4.2 nginx sketch, § 4.3 IIS rules, properties P-HST-01 to 11, to-verify list V1 to V14, owner decisions O1 to O9). Rule ids in this plan refer to it. 2. `construction/hosting-and-targets/infrastructure-design/deployment-architecture.md` (upload order, CI changes, verification matrices). 3. `inception/requirements/requirements.md` (FR-PR-14 to 18, 23; NFR-PR-P-01, P-02, S-01). 4. `construction/start-migration/functional-design/business-rules.md` (BR-SRV, BR-404) and `construction/start-migration/code/code-summary.md`, `verification-log.md`; `construction/display-fallbacks/code/measurement-display.md` and `code-summary.md`. Code (read before changing): `web/config/serverConfig.ts` and `.test.ts`, `previewServer.ts` and `.test.ts`, `pageFiles.ts` and `.test.ts`, `securityHeaders.ts`, `writeServerConfig.ts`, `web/deploy/**`, `web/lighthouserc.cjs`, `lighthouserc.desktop.cjs`, `lighthouserc.d.cts`, `web/src/app.test.tsx` (the Lighthouse guard test near the end), `web/src/sitePages.ts`, `web/e2e/support/*`, `web/e2e/*.e2e.ts`, `web/vitest.e2e.config.ts`, `.gitea/workflows/continuous_integration.yaml`. ### 0.3 Locations and commands - Worktree (work only here): `K:\Development\SlpSoftware\Projects\AndreaSlopFotografie-prerendering`, branch `feature/prerendering`. It already has `node_modules`. Application code under `web/`, documentation under `aidlc-docs/`. Never put application code in `aidlc-docs/`. - Run commands from `web/`. Package manager: pnpm. Scripts: `pnpm lint`, `pnpm format:check` (fix with `pnpm exec prettier --write `), `pnpm test` (vitest with coverage and thresholds), `pnpm build` (tsc, Start build with prerender, script step), `pnpm e2e` (browser and server tests against `dist/client`), `pnpm server-config` (regenerates `web/deploy/`), `pnpm audit:deps`, `pnpm audit:dev`. - Targeted tests while working: `pnpm exec vitest run ` (no coverage). Full suite only at checkpoints. Server and browser tests: `pnpm exec vitest run --config vitest.e2e.config.ts `. - Shell is Git Bash on Windows (also PowerShell). In Git Bash a path argument starting with `/` is rewritten; set `MSYS_NO_PATHCONV=1` before commands that take URL paths such as `/over-mij`. Use plain `rm`/`cp`, never `git rm`/`git mv`. - Scratch work (probes, temporary files, logs) goes in a scratch folder outside the repository (for example `$env:TEMP\prerendering-hosting`). Tests that need temporary files create them with `fs.mkdtemp` under `os.tmpdir()` and remove them afterwards. - Verification points V1 to V14 of the design (§ 12 of infrastructure-design.md) are recorded in ONE file: `aidlc-docs/features/prerendering/construction/hosting-and-targets/code/verification-log.md` (created in Step 1: table with columns V#, Point, Step, Outcome, Evidence, Status OK/BLOCKED/DEVIATION/WITHDRAWN/OPEN). V6 is WITHDRAWN (IIS needs a host). Update the row in the step that settles it. - Reports and summaries are markdown only, in `aidlc-docs/features/prerendering/construction/hosting-and-targets/code/`. ### 0.4 Rules for every executor 1. **No git write commands** (`add`, `commit`, `push`, `stash`, `reset`, `checkout --`, `rm`, `mv`, branch operations). `git status`, `git diff`, `git log`, `git rev-parse` are allowed. The main session commits and pushes, only when the owner approved. Never edit `aidlc-docs/features/prerendering/audit.md`, `aidlc-state.md` or `inception/requirements/requirements.md`; the main session does. 2. **Install nothing and start nothing that is stopped.** No `pnpm install/add/remove` (no dependency is added; do not edit `pnpm-lock.yaml` or `pnpm-workspace.yaml`), no `scoop`/`winget`/`apt`/`choco` install, **no `podman machine start`**, no `wsl` distribution start, no container pull or run. Read-only checks (`where`, `Get-Command`, `podman machine list`, `scoop list`, `--version`) are allowed. 3. **Nothing leaves this PC.** Do not touch the Pi, the proxy Pi, the `server-ops` repository, the webhost, the Gitea API or the workflow runs; do not open a pull request, dispatch a workflow, merge, or run `curl` against `test.andreaslop.nl`, `andreaslop.nl` or any non-local host. Do not log in anywhere. Edits to `.gitea/workflows/continuous_integration.yaml` are file edits only. 4. **STOP rule.** If a verification point fails, a design rule cannot be implemented as written, a step's "Done when" cannot be reached, a fix would change a design decision (any BR-HST rule, any owner decision O1 to O9, any earlier decision D1 to D13), or **a tool call is denied**: stop at once. Write the finding in the verification log (Status BLOCKED or DEVIATION, with the exact error output and what you tried), leave the tree in a state where `pnpm exec tsc --noEmit` still runs (revert only your own unfinished edits of that step), do not continue with later steps, do not get the same result another way, and return a report to the main session naming the step, the V point or rule, the evidence, and what decision is needed. Steps marked **STOP-AND-ASK** end the run on purpose. 5. **Match the surrounding code.** Open the neighbouring files first and copy their idiom: 4-space indentation, single quotes, trailing commas (Prettier config in `web/.prettierrc`), relative imports with explicit `.ts` extension in `config/` and `e2e/`, `@/` alias only in `src/`. `config/` and `e2e/` comments and test titles are mostly Dutch; follow the file you are in. Comments explain why, not what. **No comment, test title or doc string may name a plan step or this plan** ("Step 7", "see the plan"); rule ids such as `BR-HST-03` are allowed, as in neighbouring code. 6. **Existing tests stay valid.** Change an existing test only where § 6 names it (or where Step 17 discovers a listed pattern), and say so in the step's Record. Never loosen an assertion to get green: a changed test must be at least as strict as before. 7. **Property-based tests** (fast-check, already a dependency): use the global seed from `config/testSeed.ts` (never set a `seed`, never disable shrinking), put domain generators in `src/test/urlArbitraries.ts` (reuse `src/test/arbitraries.ts`, for example `routePath`), label each property test with its category in the title like the existing ones (`(invariant)`, `(idempotent)`, `(metamorphic)`, `(oracle)`, `(round-trip)`), and keep an example-based test next to it. Property tests that make real HTTP requests use a bounded `numRuns` (at most 100). 8. **Tests never go in `src/routes/`.** The route generator reads every file there and treats a test as a route. Page-level tests live in `src/` root. 9. **`dist` must be a current build whenever `pnpm e2e` runs.** Run `pnpm build && pnpm e2e` in one command line after any source change under `src/`, `vite.config.ts` or `config/` that affects the build. The server-rule tests that use the fixture site (Steps 4, 16) do not need `dist`, but `globalSetup` still requires `dist/client/index.html` to exist. A stale `dist` gives false passes and false failures (it did in unit 1). 10. **Concurrent batches** (§ 2): while batches run in parallel, run only targeted `vitest run ` and `tsc --noEmit`, never `pnpm build`, `pnpm test`, `pnpm e2e` or a measurement, and only touch the files your batch owns. 11. **Background jobs.** Builds, e2e runs and Lighthouse may be started in the background, but an executor must wait for every job it started (poll the output file with an until-loop; do not `sleep`-chain) before reporting, and must stop every process it started (nginx test instances, preview servers) before reporting. **Leave nothing running at hand-back.** If you must report earlier, say in the first line that the report is **interim**, name the job and its output path. 12. **Measurement conditions** (Steps 22 and 23): port 4173 must be free (`Get-NetTCPConnection -LocalPort 4173` returns nothing); the main session claims and releases the port with peer sessions, an executor never kills a process on it and never claims it for itself; if it is busy, STOP and say so. No CPU-heavy work during a measurement: no build, test run, probe, install, editor indexing or other sub-agent. Same machine, power plan and Node version for all runs. 13. **Security habits for new scripts and rules.** No `eval`; quote every variable in shell; validate URL arguments; no secret in a file or log; redirect targets in nginx never come from a decoded `$uri` in `return` (BR-HST-06). 14. Mark the step `[x]` in this file when done and add one line under "Record" if the step asks for it. Keep the tree compiling after each step (`pnpm exec tsc --noEmit`). ## 1. Checkpoints | CP | After | State required | |---|---|---| | CP0 | Step 1 | Baseline green: lint, format, test, build, e2e on the untouched tree; verification log created; nginx and lftp availability recorded | | CP1 | Step 6 | **The nginx contract is proven by a real nginx** (locally, or by one CI run that the main session started) and V1 to V5 for nginx settled OK. Without a local nginx the run ends here (STOP-AND-ASK) | | CP2 | Step 15 | `pnpm exec tsc --noEmit`, `pnpm lint`, `pnpm format:check`, `pnpm test` (coverage thresholds), `pnpm build` green | | CP3 | Step 18 | `pnpm build && pnpm e2e` green with the parity, URL and adjusted tests (nginx tests run, or are skipped locally with the visible message; CP1 must be closed by then) | | CP4 | Step 21 | Full verification green: lint, format, test, build, e2e, audit:deps, audit:dev; fit with the Pi install instructions checked | | CP5 | Step 23 | Final measurement done, report written, `lighthouserc.cjs` targets unchanged (checksum equal to Step 21), `dist` rebuilt from the real code | | CP6 | Step 25 | Documents written. **STOP-AND-ASK**: report to the main session for the owner's per-page decisions | | CP7 | Step 27 | Only after the owner's decisions: targets applied, tests green, documents final | ## 2. Batches, executors and parallelism One sub-agent takes one batch. Haiku (H) does mechanical work, running checks and log keeping; Sonnet (S) does code, tests and documents that need judgement. The executor per step is repeated in the step. | Batch | Steps | Executor | Parallel with | Files owned | |---|---|---|---|---| | B0 Setup and baseline | 1 | H | none (exclusive: CPU) | verification log, baseline file | | B1 Early nginx proof | 2 to 6 | S for 2 to 5, H for 6 | none (sequential; riskiest first) | `config/canonicalUrls.ts` and test, `config/compressibleTypes.ts`, `config/serverConfig.ts` (nginx part), `deploy/nginx/*`, `src/test/urlArbitraries.ts`, `e2e/support/nginx.ts`, `e2e/support/fixtureSite.ts`, `e2e/serverRules.e2e.ts` (first version), the install step in `.gitea/workflows/continuous_integration.yaml` | | B2 Preview server | 7, 8 | S | B3, B4, B5 | `config/previewServer.ts` and test | | B3 IIS text and config tests | 9, 10 | S | B2, B4, B5 | `config/serverConfig.ts` (IIS part, helpers), `config/serverConfig.test.ts`, `deploy/iis/web.config`, `deploy/nginx/*` (regenerated) | | B4 Lighthouse | 11, 12 | S | B2, B3, B5 | `lighthouserc.cjs`, `lighthouserc.d.cts`, `config/lighthouserc.test.ts`, `src/app.test.tsx` (guard test only) | | B5 Deploy scripts and CI | 13 to 15 | S | B2, B3, B4 | `web/deploy/*.sh`, `e2e/deployScripts.e2e.ts`, `.gitea/workflows/continuous_integration.yaml` | | B6 Server and browser tests | 16 to 18 | S for 16 and 17, H for 18 | none (after CP2) | `e2e/**` | | B7 Finish | 19 to 21 | S for 19 and 20, H for 21 | none | comments in changed files, verification log | | B8 Measurement | 22, 23 | H for runs, S for the report | none (exclusive: port 4173 and CPU) | scratch folder, `measurement-final.md` | | B9 Documents | 24, 25 | S | none | `aidlc-docs/**` | | B10 After the owner's decisions | 26, 27 | S | none | `lighthouserc.cjs` exception table, documents | B2 to B5 may run at the same time because their files are disjoint (`serverConfig.ts` is owned by B1, then by B3; B3 starts after CP1). They all start only after CP1. In B6 the files of Steps 16 and 17 are disjoint and may be written in parallel, but they are run one process at a time and only against a current `dist` (rule 9); Step 18 runs them. ## 3. Traceability ### 3.1 Properties (PBT-01) to steps | Property | Subject | Category | Test step | |---|---|---|---| | P-HST-01 | `resolveRequest` total, `file` safe | Invariant | 8 | | P-HST-02 | Variants of a known page redirect to the canonical path | Invariant | 2 (function), 8 (resolver) | | P-HST-03 | Redirects terminate in at most 2 hops; canonical is a fixpoint | Idempotence | 2, 8 | | P-HST-04 | Redirect target safe (no `//`, `/\`, control characters) | Invariant | 2, 8 | | P-HST-05 | Query string kept byte for byte | Invariant | 8 (server level) | | P-HST-06 | Unknown paths give 404; `/404`, `/404.html` give 404 only; `/` never redirects | Invariant | 8 | | P-HST-07 | Generated config invariants (same page set, headers in every location, no `$uri/`, no `index`/`autoindex on`, no `return` from `$uri`, gzip types, IIS rule order, no SPA fallback) | Invariant over text | 10 | | P-HST-08 | `deploy/` files equal generator output | Round trip (existing) | 10 | | P-HST-09 | Preview server against real nginx | Oracle | 16 | | P-HST-10 | Withdrawn (no IIS simulator); a text test of the generated `web.config` replaces it | Example-based | 10 | | P-HST-11 | Lighthouse config invariants | Invariant | 12 | PBT-06 (stateful): none; the redirect function is stateless. PBT-07 (generators): `src/test/urlArbitraries.ts`. PBT-08: global seed, shrinking left on. PBT-10: each property test has its category label and an example-based sibling. ### 3.2 Verification points to steps | V | Settled in step | Recorded in | |---|---|---| | V1 nginx file loads in real nginx as an `http` include; directives against the nginx 1.30 documentation | 3 (documentation), 6 (real nginx) | verification log | | V2 server-level `if`/`rewrite` responses carry the five headers and `Cache-Control`; relative `Location`; `/` without `index` | 6, 16 | verification log | | V3 `/soorten-fotoshoots` next to its directory; `/assets`, `/assets/` | 6, 8, 16 | verification log | | V4 `/404`, `/404.html` give 404 with the page and headers; `error_page` keeps the status; HEAD | 6, 16 | verification log | | V5 HTTP/1.0 request gets gzip for every compressible type, not for fonts and images | 6, 16 | verification log | | V6 IIS behaviours | WITHDRAWN (no host) | verification log | | V7 new `resolveRequest` contract, tests of BR-SRV-07 updated | 7, 8 | verification log | | V8 Chrome follows the 301 with the query intact; hydrated page has 1 title | 17 | verification log | | V9 the 404 page through the audit route in Lighthouse | 23 | measurement-final.md | | V10 lftp passes (exclusion syntax) | 14 | verification log | | V11 `verify-deployment.sh` fails on old behaviour, passes on new | 13 | verification log | | V12 CI installs nginx; the server-rule test fails when nginx is missing in CI | 5, 16 | verification log | | V13 `lighthouserc.cjs` exception table, P-HST-11, `Local` pattern still matches | 11, 12 | verification log | | V14 generated header comment fits the Pi path | 3 | verification log | ### 3.3 Requirements and rules to steps | Requirement or rule | Steps | |---|---| | FR-PR-14 (404 on nginx, IIS, preview; noindex page) | 3, 7, 9, 16, 17 | | FR-PR-16 (URLs without slash, 200, no redirect for pages; generated config) | 2, 3, 7, 9, 10, 16 | | FR-PR-17 (only client output deployed) | 13, 15 | | FR-PR-18 (upload order, all HTML, caching) | 14, 15 | | FR-PR-23 (compression) | 2, 3, 7, 9, 16 | | NFR-PR-P-01, P-02, S-01 (Lighthouse targets) | 11, 12, 22, 23, 26 | | BR-HST-01 to 08 (URL contract) | 2, 3, 4, 7, 8, 9, 16, 17 | | BR-HST-09 to 11 (compression) | 2, 3, 7, 9, 16 | | BR-HST-12, 13 (cache, headers) | 3, 7, 9, 16 | | BR-HST-14 to 18 (deployment) | 13, 14, 15 | | BR-HST-19 (IIS scope: text only) | 9, 10, 25 | | BR-HST-21 to 23 (Lighthouse) | 11, 12, 22, 23, 26 | | BR-HST-24 (real nginx) | 4, 5, 6, 16 | | NFR-PR-SEC-01 (CSP unchanged), SECURITY-04, 09, 11 | 3, 7, 8, 10, 16 | | NFR-PR-Q-01, Q-05 | 21, 24, 25 | --- ## Part A: Setup and baseline (batch B0, Haiku, exclusive) ### Step 1: Confirm a green baseline and create the log [x] - Executor: Haiku. - Implements: NFR-PR-Q-01 (baseline), setup. - Do (in `web/`; install nothing): 1. `git rev-parse HEAD`, `git branch --show-current` (must be `feature/prerendering`), `git status --short` (expected: clean apart from untracked `web/.tanstack/` and docs; write what you see). 2. Read-only availability checks, written down verbatim: `node -v`, `pnpm -v`; `Get-Command nginx -ErrorAction SilentlyContinue`; `where.exe nginx`; existence of `C:\nginx\nginx.exe` and `C:\Users\Bryan\scoop\apps\nginx\current\nginx.exe`; `scoop list` (if scoop exists); `Get-Command lftp -ErrorAction SilentlyContinue`; `bash --version`; `curl --version`; `podman machine list` (read-only; do NOT start the machine). Also `echo $env:NGINX_BIN`. 3. Run `pnpm lint`, `pnpm format:check`, `pnpm test`, `pnpm build && pnpm e2e` in that order. Note test files and tests passed, the fast-check seed line, the e2e file and test counts. 4. Create `aidlc-docs/features/prerendering/construction/hosting-and-targets/code/verification-log.md` with the table header of § 0.3 and one row per V1 to V14 (Point copied from infrastructure-design.md § 12, Outcome and Evidence empty, Status `open`; V6 `WITHDRAWN`). 5. Record the SHA-256 of `web/lighthouserc.cjs` and `web/lighthouserc.desktop.cjs` in the baseline file (used to prove the targets did not change before the owner decides, Step 23). - Done when: **CP0**: all commands succeed on the untouched tree, otherwise STOP and report the output. - Record: create `aidlc-docs/features/prerendering/construction/hosting-and-targets/code/baseline-checks.md` with commit hash, date, Node and pnpm versions, counts, seed, `git status --short`, the availability results of 2 (state plainly: "nginx available locally: yes/no, path, version"; "lftp: yes/no"; "bash/curl: yes/no"), and the checksums. --- ## Part B: Early nginx proof (batch B1, Sonnet, sequential; Haiku for Step 6) The riskiest mechanism is the nginx block (a `map`, a server-level `if` and `rewrite`, `error_page` with an internal location, `try_files` without `$uri/`, a custom gzip setup behind a proxy). It is built in its real form and proven with a real nginx process before the rest. Reading the config is not a proof. ### Step 2: Shared URL and type modules (BR-HST-04, 06, 11) [x] - Executor: Sonnet. - Implements: BR-HST-03, 04, 06, 11; P-HST-02, 03, 04 (function level). - Files: create `web/config/canonicalUrls.ts`, `web/config/canonicalUrls.test.ts`, `web/config/compressibleTypes.ts`, `web/src/test/urlArbitraries.ts`. - Do: 1. `canonicalUrls.ts` (pure, no DOM, no I/O; imports `sitePages` from `../src/sitePages.ts`, which only has type imports; check that Node 24 type stripping can import it: `node -e "import('./config/canonicalUrls.ts')"` after writing). Exports: `pagePaths: readonly string[]` (`Object.keys(sitePages)`, `/` first); `canonicalRedirect(decodedPath: string): string | undefined`: for a decoded path starting with `/`, no query, returns the canonical target when the path is a non-canonical variant of a known page, otherwise `undefined`. A variant is: the page name compared case-insensitively, optionally followed by `.html`, optionally followed by one or more `/`; `/index`, `/index.html` and their variants (case, trailing slashes) go to `/`. A path that is already the canonical form returns `undefined`. `/404`, `/404.html` and anything unknown return `undefined`. `stripTrailingSlashes(decodedPath: string): string | undefined`: for a path longer than one character that ends in `/`, returns the path with all trailing slashes removed (never an empty string), else `undefined`. `escapeRegex(text: string): string`. Also export `redirectNames`: the page paths without `/`, and a function `variantPattern(path: string): string` that returns the case-insensitive regex source used by both generators (the page name escaped, then `(?:\.html)?/*`), so nginx and IIS take it from one place. 2. `compressibleTypes.ts`: one list `{ extension, mimeTypes: string[], previewContentType }` for `.html`, `.js`, `.css`, `.svg`, `.json`, `.xml`, `.txt` and the non-compressed types the preview server serves (png, jpg, webp, woff2, ico) in a second list. `.js` has both `text/javascript` and `application/javascript` in `mimeTypes` (nginx 1.24 and 1.25.2+ differ: the Pi runs 1.30.6 which uses `text/javascript`; `gzip_types` must contain both); `.xml` has `text/xml` and `application/xml`. `previewContentType` keeps today's values of `CONTENT_TYPES` in `previewServer.ts` exactly (Step 7 uses them). Export helpers `compressibleExtensions: ReadonlySet` and `gzipMimeTypes(): string[]` (unique, without `text/html`, which nginx always compresses). 3. `urlArbitraries.ts` (in `src/test/`): generators `knownPage` (from `pagePaths`), `caseVariant(path)` (random upper/lower per letter), `pageVariant` (page x case x optional `.html` x 0 to 3 trailing slashes, plus the `index` family), `unknownPath` (safe alphabet, 1 to 3 segments, not equal to a page in any variant), `hostilePath` (strings with `//host`, `/\host`, `%2e%2e`, NUL, CR/LF, very long, control characters), `queryString`. Document in a short comment what each guarantees. 4. `canonicalUrls.test.ts`: example-based table (the redirect rows of infrastructure-design.md § 3.1) and properties: P-HST-02 (every `pageVariant` returns the canonical page, `(invariant)`), P-HST-03 (the result is a fixpoint: `canonicalRedirect(result)` is `undefined`, and `stripTrailingSlashes(result)` is `undefined`, `(idempotent)`; the combined function used by the resolver needs at most 2 hops for any `pageVariant` or `unknownPath` plus slashes), P-HST-04 (a target starts with `/`, never `//` or `/\`, has no control characters, and is one of `pagePaths`, `(invariant)`; run it also over `hostilePath`: a non-`undefined` result is still one of `pagePaths`). - Done when: `pnpm exec vitest run config/canonicalUrls.test.ts` green; `pnpm exec tsc --noEmit`, `pnpm lint` clean; `pnpm exec prettier --check` on the new files clean. - Record: one line with the exported names. - Done. `canonicalUrls.ts`: pagePaths, redirectNames, escapeRegex, variantPattern, canonicalRedirect, stripTrailingSlashes. `compressibleTypes.ts`: FileType, compressibleTypes, plainTypes, compressibleExtensions, gzipMimeTypes. `src/test/urlArbitraries.ts`: knownPage, caseVariant, pageVariant, unknownPath, hostilePath, queryString. stripTrailingSlashes returns undefined when the stripped target would start with // or / or hold control characters (BR-HST-06), so the resolver treats such a path as unknown. ### Step 3: The nginx block (BR-HST-01 to 09, 11 to 13; V14) [x] - Executor: Sonnet. - Implements: BR-HST-01 to 09, 11 to 13; FR-PR-14, 16, 23; V1 (documentation part), V14. - Files: change `web/config/serverConfig.ts` (nginx part only); regenerate `web/deploy/nginx/andreaslop-test.conf` with `pnpm server-config`; change `web/config/serverConfig.test.ts` only where § 6 names it (full test work is Step 10). - Do: 1. Rewrite `nginxTestConf` per infrastructure-design.md § 4.2: signature `nginxTestConf(options?: { listen?: string; root?: string })` with defaults `'80'` and `/var/www/html/andreaslop-test` so the committed file keeps those lines; `server_name test.andreaslop.nl` stays (a lone server on a port answers any Host, so tests need no Host header). Content: the `map $uri $andreaslop_canonical` (exact canonical entries `""`, then one case-insensitive regex entry per page except `/`, using `variantPattern` and the `/index` family to `/`), `absolute_redirect off`, `autoindex off`, no `index` directive, the five security headers + `X-Robots-Tag` + `Cache-Control: no-cache` in the server block and in **every** location (`always`), the gzip block (`gzip on; gzip_vary on; gzip_proxied any; gzip_http_version 1.0; gzip_comp_level 5; gzip_min_length 256; gzip_types` from `gzipMimeTypes()`), `if ($andreaslop_canonical) { return 301 $andreaslop_canonical$is_args$args; }`, `rewrite ^/(.+?)/+$ /$1 permanent;`, `error_page 404 /404.html;`, and the locations: `= /robots.txt` (unchanged behaviour), `= /404` (`return 404`), `= /404.html` (`internal`), `/assets/` (immutable, `try_files $uri =404`), `= /` (`try_files /index.html =404`), `/` (`try_files $uri $uri.html =404`). No `$uri/` anywhere, no `return` or `rewrite` target built from `$uri` other than the `rewrite ... permanent`. **No map rule may match `/404` or `/404.html`**: `error_page`'s internal redirect runs the server-level `if` and `rewrite` again with `$uri=/404.html`, which must find no rule (otherwise the 404 page would turn into a redirect). **Header consistency**: `add_header` in a location replaces all server-level `add_header`, so every location that has any `add_header` repeats the whole set (five security headers, `X-Robots-Tag`, and its `Cache-Control`), and `/assets/` carries exactly one `Cache-Control` (`immutable`), not a second one from the server level. Build the locations from one helper that always emits the full set, so this holds by construction; `etag` stays at its default. 2. Replace the header comment of the generated file (Dutch, like now): state that the file is installed as `/etc/nginx/conf.d/andreaslop-test.conf` on the hosting Pi (included inside `http {}` from `nginx.conf`, no `sites-enabled`), that it needs no change to the global `nginx.conf` (it carries its own `gzip` settings, because the Pi has none active), that it works behind a proxy that talks HTTP/1.0 upstream, and that `server_name` and `root` may be adapted. Keep the existing remarks about the proxy, `absolute_redirect` and not being `default_server` (V14). **Correct the out-of-date remark** that nginx would fall back to the WordPress default block for an unknown host: since 2026-10-21 `/etc/nginx/conf.d/00-default.conf` on the Pi answers an unknown host with 444 (source: `infrastructure-design/pi-install-instructions.md`, table row "Default block"). Say that the block is chosen by `server_name` and that an unknown host gets 444 from that default block. 3. Check every directive used against the nginx 1.30 documentation (`https://nginx.org/en/docs/`; read-only web access is allowed for documentation; if a tool call is denied, STOP): `map` (context http), `if` with `return` (server), `rewrite` flags, `try_files`, `error_page`, `internal`, `absolute_redirect`, `autoindex`, all `gzip*` directives and their contexts (http, server, location). Write the result as one line per directive in the verification log V1 (documentation part). 4. Leave `nginxProxyConf` and `iisWebConfig` untouched in this step (the proxy config stays as it is; IIS is Step 9). 5. Run `pnpm server-config`. Update the three `serverConfig.test.ts` tests that § 6 lists for nginx (they assert the old SPA fallback and the location count) with stricter replacements; the rest of the test file is unchanged and must pass. - Done when: `pnpm exec vitest run config/serverConfig.test.ts` green (the IIS SPA-fallback test is still the old one and still passes because Step 9 has not run); the committed `deploy/nginx/andreaslop-test.conf` equals `nginxTestConf()`; `pnpm exec tsc --noEmit`, `pnpm lint` clean. - Record: verification log V1 (documentation), V14. - Done. V1 documentation part and V14 recorded. The three serverConfig tests of section 6 (noindex/try_files, location count) changed and are stricter. The nginx.org rewrite page does not document escaping of the replacement; BR-HST-06 relies on it and the real nginx test must show it. ### Step 4: Fixture site, nginx harness and the first contract test (BR-HST-24) [x] - Executor: Sonnet. - Implements: BR-HST-24; V1 to V5 (tests); P-HST-09 (first version). - Files: create `web/e2e/support/fixtureSite.ts`, `web/e2e/support/nginx.ts`, `web/e2e/serverRules.e2e.ts`. - Do: 1. `fixtureSite.ts`: `createFixtureSite(): Promise<{ dir: string; files: ... ; remove(): Promise }>` writes into `os.tmpdir()` a small site: `index.html`, one `x.html` for every page in `pagePaths` (with a unique marker text per page so the served file can be identified), `soorten-fotoshoots/newborn.html` etc. (so the **directory `soorten-fotoshoots/` exists next to `soorten-fotoshoots.html`**), `404.html`, `robots.txt`, `sitemap.xml`, `favicon.png` (a few bytes), `assets/index-AbC123xYz.js` (hash with upper-case letters, 4 KB of repetitive text), `assets/style-Qw9.css`, `assets/icon-Zz1.svg`, `assets/data.json`, `assets/font-Ab.woff2` (random bytes, 2 KB). 2. `nginx.ts`: `findNginx(): string | undefined` (order: `NGINX_BIN`, `nginx` on the PATH, the two known Windows paths of Step 1); `startNginx(options: { siteDir: string; mimeVariant?: 'new' | 'old' }): Promise<{ origin: string; version: string; stop(): Promise }>`. It creates a temp prefix directory, writes `nginx.conf` = `daemon off; pid /nginx.pid; error_log /error.log;` + `events {}` + `http { types { ... } client_body_temp_path/proxy_temp_path/fastcgi_temp_path/uwsgi_temp_path/scgi_temp_path /...; access_log off; include }` where the generated block is `nginxTestConf({ listen: '127.0.0.1:', root: siteDir })`. The `types` table is written inline (not the system `mime.types`) and has two variants: `old` maps `.js` to `application/javascript`, `new` maps it to `text/javascript` (nginx 1.24 against 1.30); both map `.xml` to `text/xml`, `.html` text/html, `.css`, `.svg` image/svg+xml, `.json`, `.txt`, `.png`, `.woff2`. Start with `spawn(bin, ['-p', tmp, '-c', conf, '-e', errorLog])`, wait until the port answers (poll `fetch`, at most 5 s), read the version with `bin -v`. `stop()` sends termination and waits for exit, then removes the temp directory; register it in `afterAll` and also on process exit so nothing stays running. On Windows use forward slashes in the config and `child.kill()`. 3. `serverRules.e2e.ts`: `describe.skipIf`-style gate: if `findNginx()` is undefined, then when `process.env.CI` is set the suite **fails** with the message "nginx ontbreekt in CI (BR-HST-24)", otherwise it is skipped and prints one visible line `nginx niet gevonden: serverregeltests overgeslagen (zie BR-HST-24)`. First version tests, against real nginx and the fixture: every row of infrastructure-design.md § 3.1 (status, `Location` path+query, which fixture file was served by the marker text, `404.html` body on 404); the five security headers + `Cache-Control` + `X-Robots-Tag` on 200, 301 and 404 responses (V2, V4); `/soorten-fotoshoots` serves the file and `/soorten-fotoshoots/` redirects (V3); `/` works without an `index` directive; HEAD on a page and on an unknown URL; `/robots.txt` returns `Disallow: /`; `Content-Encoding: gzip` for `.html`, `.js`, `.css`, `.svg`, `.json`, `.xml`, `.txt`, none for `.woff2` and `.png`, in both mime variants (V5); a raw HTTP/1.0 request over `node:net` with `Accept-Encoding: gzip` also gets gzip; `Vary: Accept-Encoding` present; `/assets/*` has exactly **one** `Cache-Control` header, `public, max-age=31536000, immutable` (count the raw header lines through `node:http` `rawHeaders`, not through the merged `fetch` Headers object), all else `no-cache`; the full header set is present on a 301, on the 404 page, on `/404` and `/404.html` (the `error_page` path) and on `/assets/*`; hostile paths (`//evil.example/`, `/\evil.example`) never yield a 3xx whose `Location` starts with `//` or `/\`. - Done when: `pnpm exec tsc --noEmit`, `pnpm lint` clean; `pnpm exec vitest run --config vitest.e2e.config.ts e2e/serverRules.e2e.ts` either passes against a local nginx (if Step 1 found one) or prints the skip line (no nginx locally) and exits 0 outside CI; with `CI=true` and no nginx it fails with the message above (run it once to prove the gate; then unset `CI`). - Record: which nginx version ran, or "skipped: no local nginx". - Skipped: no local nginx. Gate proven: without CI one visible skip line, exit 0; with CI=true the suite fails with "nginx ontbreekt in CI (BR-HST-24)". The harness has never started a real nginx (only type-checked), so a first CI run may still show harness defects. ### Step 5: Install nginx and lftp in the CI job (V12) [x] - Executor: Sonnet. - Implements: BR-HST-24; V12. - Files: `.gitea/workflows/continuous_integration.yaml` (file edit only; nothing is pushed or dispatched). - Do: in job `lighthouse`, before the `Browsertests` step add a step "Install nginx and lftp (serverregeltests)": `sudo apt-get update && sudo apt-get install -y nginx lftp`, then stop a service the package may have started (`sudo service nginx stop || true`), then `nginx -v`. Give the `Browsertests` step `CI: 'true'` in its `env` (so a missing nginx fails the job; do not rely on the runner setting it). Do not touch the deploy jobs yet (Step 15). Keep the file's Dutch comment style and explain why the packages are installed (the Ubuntu runner image carries nginx 1.24; the Pi runs 1.30.6; accepted gap, BR-HST-24). - Done when: the YAML parses (`pnpm exec prettier --check ../.gitea/workflows/continuous_integration.yaml` or, if prettier rejects the path, `node -e` with the `yaml` parser is NOT available: use `pnpm exec prettier --parser yaml --check` on the file contents via stdin); the diff shows only the new step and the env line. - Record: the exact diff. - Done: one new step "Install nginx and lftp (serverregeltests)" before Browsertests, plus `CI: 'true'` in the env of Browsertests, with Dutch comments. See `git diff .gitea`. ### Step 6: Checkpoint CP1: the nginx proof [x] STOP-AND-ASK if no local nginx - Executor: Haiku. - Implements: BR-HST-24; V1 to V5. - Do: 1. If Step 1/4 found a local nginx: run `pnpm exec vitest run --config vitest.e2e.config.ts e2e/serverRules.e2e.ts` with `NGINX_BIN` set if needed. Record in the verification log V1 to V5: nginx version, OS (note: a Windows nginx proves directive behaviour but not Linux file semantics, so CI still runs), pass counts, and any failure with the exact output. If any test fails: STOP and report (the failure is a finding about the generator or the design, not a reason to loosen the test); Sonnet fixes in Step 3 or 4 first only when the cause is a plain defect, otherwise the main session decides. 2. If no local nginx exists: **a local proof is impossible without an install or starting the stopped Podman machine, both of which need the owner's approval.** Do not install, do not start the machine. Do not continue with later steps. Return this report to the main session: - Steps 2 to 5 done; tests written; the nginx suite skipped locally. - First CI proof needed: a push to the branch triggers no CI; a pull request or a workflow dispatch does, and those are the main session's and owner's to start. The `lighthouse` job now installs nginx (Step 5) and runs `pnpm e2e`, which includes `serverRules.e2e.ts` with `CI=true`. Expect about 20 minutes per cycle. Ask for the CI log of that step (the `Browsertests` output), including `nginx -v`. - Alternatives that need the owner's approval first: (a) `scoop install nginx` for Windows (fast local loop; Windows nginx is case-insensitive on the file system, so only directive behaviour is proven); (b) `podman machine start` and an nginx 1.30 container (matches the Pi; the harness would need a small container mode, which a later step adds only if approved). - Recommendation: the CI cycle (needed in any case for the final proof), plus (a) if the owner wants a fast loop. - Whether the main session wants the run to continue with Parts C to F while the proof is pending: then CP1 stays OPEN and CP3 cannot close until it is closed. 3. **Resume rule**: when the main session returns a CI log, read it. If green: record V1 to V5 with the log excerpt and continue at Step 7. If red: fix the generator (Step 3) or harness (Step 4), update the tests only to make them correct (never looser), and return to the main session for another CI cycle; do not start Step 7 until green or until the main session says to continue with CP1 open. - Done when: **CP1**: V1 to V5 recorded OK from a real nginx (local or CI log), or the main session explicitly released the run with CP1 open. - Record: where the proof came from (local binary and version, or CI run link/identifier given by the main session). - CP1 closed by CI run 593 (commit 8cb9185), job lighthouse, step Browsertests: nginx/1.24.0, serverRules.e2e.ts 134 of 134 passed, 67 per mime variant, none skipped. V1 to V5 and V12 are OK in the verification log. Three defects were found and fixed along the way (harness permissions as root, case-insensitive map keys, backslash in Location). Unproven: nginx 1.30.6 on the Pi. --- ## Part C: Preview server (batch B2, Sonnet; parallel with B3, B4, B5) ### Step 7: New `resolveRequest` contract and audit route (BR-HST-01 to 08, 22; V7) [x] - Executor: Sonnet. - Implements: BR-HST-01 to 08, 11, 13, 22; FR-PR-14, 16, 23. - Files: change `web/config/previewServer.ts`. - Do: 1. `ResolvedRequest` becomes `{ file: string; status: 200 | 404 } | { redirect: string; status: 301 }`. `resolveRequest(path, fileExists, options?: { auditRoute?: boolean })` keeps its first checks (decode once; NUL, backslash, dot segments, drive letters give the 404 result; BR-SRV-06). Then, in this order: (a) `canonicalRedirect(decoded)` gives `{ redirect, status: 301 }`; (b) `stripTrailingSlashes(decoded)`: if the stripped path contains an empty segment (`//`) the result is the 404 result, else a redirect to it; (c) `/404` and `/404.html` give `{ file: '404.html', status: 404 }`; (d) with `auditRoute` on, `/__audit/404` gives `{ file: '404.html', status: 200 }`; (e) `/` gives `index.html`; (f) empty segments inside the path stay 404 (BR-SRV-07, outside the parity set); (g) the file/page lookup as today. Remove the interim 200 for `/404.html`. A redirect never has a target starting with `//` or `/\`. 2. `CONTENT_TYPES` and `COMPRESSIBLE` come from `compressibleTypes.ts` with unchanged values (the existing tests of content types and compression must pass untouched). 3. `handle()`: for a redirect send status 301 with `Location: `, where the raw search is the part of `request.url` from the first `?` (kept byte for byte; no hash), `Content-Length: 0`, the security headers (as `send()` does), `Cache-Control` not set; HEAD gives the same. All other behaviour stays (405 on other methods, gzip, no-cache for HTML, traversal lock). 4. `startPreviewServer(clientDir, port, options?: { auditRoute?: boolean })`; `parseArguments` accepts `--audit-route` (boolean) next to `--port`, `--strictPort`, `--dir`; unknown arguments are still ignored. Update the file's header comment: the 404 page is audited through the opt-in route; `/404.html` is a real 404. - Done when: `pnpm exec tsc --noEmit`, `pnpm lint` clean; the tests of § 6 for this file fail as expected and no others (they are rewritten in Step 8). - Record: one line naming the exported types. - Done: exported `FileResult`, `RedirectResult`, `ResolvedRequest` (union), `ResolveOptions`, `PreviewOptions`; `resolveRequest(path, fileExists, options?)` and `startPreviewServer(clientDir, port, options?)`. ### Step 8: Tests for the preview server (P-HST-01, 05, 06; V3, V7) [x] - Executor: Sonnet. - Implements: P-HST-01, 02, 03, 04, 05, 06; V3, V7. - Files: change `web/config/previewServer.test.ts`; use `src/test/urlArbitraries.ts`. - Do: 1. Update the tests § 6 names (the `tussenregels uit BR-SRV-07` group, the slash and `/404.html` cases) into the final rules, at least as strict. 2. Example-based: every row of infrastructure-design.md § 3.1 against `resolveRequest` with a file list that includes `soorten-fotoshoots.html`, `soorten-fotoshoots/newborn.html`, `assets/a.js`; the case that a directory name next to a page file never redirects; `//x` stays 404; `--audit-route` option on and off. 3. Properties (labelled): P-HST-01 total and safe over `hostilePath` and `pageVariant` (`(invariant)`: never throws, status in {200, 301, 404}, `file` never contains `..` or starts with `/`, redirect target never starts with `//` or `/\`); P-HST-02/03 at resolver level (`pageVariant` leads to the canonical page in at most 2 hops following redirects through `resolveRequest`, `(idempotent)`); P-HST-06 (`unknownPath` gives 404 and `404.html`; `/404` and `/404.html` give 404; `/` never redirects, `(invariant)`); keep the existing P16 and P17 properties passing (adjust the P17 model only where its generator now yields redirect inputs, and say so in the Record). 4. Server level with `startPreviewServer`: a redirect response has status 301, a relative `Location` with the query kept byte for byte (P-HST-05, `(invariant)` over `queryString`), the five security headers, no body, and works for HEAD; `/404.html` and `/404` answer 404 with the page and headers; `/__audit/404` is 404 without the option and 200 with it, and `/404.html` stays 404 with the option; `--audit-route` through the command-line tests (`previewServer als opdrachtregel`): with the flag the route answers 200. - Done when: `pnpm exec vitest run config/previewServer.test.ts` green; `pnpm exec tsc --noEmit`, `pnpm lint` clean. - Record: which existing tests changed (names), and the P17 note. - Done: changed the group `tussenregels uit BR-SRV-07` (now `regels uit BR-HST-03 tot 05`), `behandelt een laatste segment met een punt als bestandsverzoek` (`/over-mij.html` is a 301), the drive-letter assertion (now `toEqual(NOT_FOUND)`, stricter), `antwoordt op /404 met status 404` (now `/404` and `/404.html`, 404 with page and headers), `comprimeert elk teksttype` (requests `/over-mij` instead of `/over-mij.html`, same gzip assertions), P16 (redirect results are skipped, `file` checks unchanged) and P17 (the model returns the redirect for any input that `canonicalRedirect` maps, and `/404.html` is 404). `siteDir` gained `soorten-fotoshoots.html` and its directory. --- ## Part D: IIS text and config tests (batch B3, Sonnet; parallel with B2, B4, B5) ### Step 9: The IIS `web.config` text (BR-HST-04, 07, 10, 19) [x] - Executor: Sonnet. - Implements: BR-HST-02, 04, 06, 07, 10, 12, 13, 19; FR-PR-14, 16, 23. **These rules are unverified until a host exists; do not build any tooling to verify them.** - Files: change `web/config/serverConfig.ts` (IIS part only); regenerate `web/deploy/iis/web.config` with `pnpm server-config`. - Do: rewrite `iisWebConfig` per infrastructure-design.md § 4.3. Rule order inside ``: `www naar andreaslop.nl` and `HTTPS` unchanged; then `Index naar root`, `Pagina canoniek` (alternation of the page names built from `redirectNames` and `variantPattern`, condition `{R:0}` not matching the exact lower-case canonical form with `ignoreCase="false"`, `Redirect` to `/{ToLower:{R:1}}`, permanent), `Slash weg` (`^([^/\\].*?)/+$`, redirect `/{R:1}`), `404 direct` (`^404(?:\.html)?$`, `CustomResponse` 404), `Pagina bestand` (`^(.+)$`, condition `{REQUEST_FILENAME}.html` `IsFile`, rewrite `{R:1}.html`), `Map zonder pagina` (`^(.+)$`, condition `{REQUEST_FILENAME}` `IsDirectory`, `CustomResponse` 404). All with `stopProcessing="true"`. The "SPA fallback" rule is **removed**. After ``: `` with `` and ``; ``; in `staticContent` the existing `woff2` entry plus remove-then-add MIME pins for `.js` (`text/javascript`), `.svg`, `.json`, `.xml` (`text/xml`) taken from `compressibleTypes.ts`; `clientCache` and the `/assets` location block as now; `httpProtocol` headers as now. No `httpCompression`, no `directoryBrowse`, no `defaultDocument`. Escape all attribute values with the existing `xmlAttribute`. Update the header comment: the rules are generated from the page list; unverified until a host exists (open points U1 to U6 in infrastructure-design.md § 7.2). - Done when: the generated file is well-formed XML (parse it in a test, Step 10); `pnpm exec tsc --noEmit`, `pnpm lint` clean. - Record: one line listing the rule names in order. Record (done): www naar andreaslop.nl, HTTPS, Index naar root, Pagina canoniek, Slash weg, 404 direct, Pagina bestand, Map zonder pagina. Unverified until a host exists (V6 withdrawn). ### Step 10: Complete `serverConfig.test.ts` (P-HST-07, 08, 10) [x] - Executor: Sonnet. - Implements: P-HST-07, 08, 10; BR-HST-03, 04, 06, 07, 09 to 13, 19. - Files: change `web/config/serverConfig.test.ts`. - Do: 1. Keep all existing tests that still apply unchanged; the three that § 6 names get stricter replacements (done for nginx in Step 3, done now for IIS). The generator sync test (`%s is gelijk aan de generator`) stays and covers all three files; run `pnpm server-config` if a generated file is stale. 2. P-HST-07, labelled `(invariant)`, over the generated text: nginx map exact entries and regex entries equal the page set `pagePaths` minus `/`; the IIS page alternation equals the same set; every nginx `location` block and the server level contain all five headers; no `try_files` contains `$uri/`; no `index ` directive and no `autoindex on`; no `return` target contains `$uri` or `$1` and the only `rewrite` is the `permanent` slash rule; `error_page 404 /404.html`; `location = /404.html` is `internal`; `gzip_types` contains every entry of `gzipMimeTypes()`; `gzip_http_version 1.0`; **no map rule matches `/404` or `/404.html`** (evaluate every map regex and exact entry of the generated text against both paths with the JavaScript regex engine, case-insensitively where the entry is `~*`: none matches, `(invariant)`); **every `location` block that contains an `add_header` contains the full header set** (the five security headers and `X-Robots-Tag`), and the `/assets/` block contains exactly one `Cache-Control` and the server level exactly one; the header comment mentions `00-default.conf` and 444 and no longer says that nginx falls back to WordPress; the file contains no `include`, no `http {` wrapper and no `default_server`; the nginx file lists `X-Robots-Tag`; the proxy config is unchanged (`not.toContain('add_header')`, `proxy_set_header Host $host;`). 3. P-HST-10 replacement (example-based text test): `iisWebConfig()` parses as XML (use a small regex-free check with the built-in `DOMParser` via `// @vitest-environment jsdom`, or a string balance check if jsdom is not already used in this file; keep the environment of the file in mind), contains the rule names in the designed order, has no `SPA fallback` and no `index.html` rewrite, contains `ToLower` only inside the canonical rule, `[^/\\]` in the slash rule, `ExecuteURL`, `urlCompression`, and neither `httpCompression` nor `directoryBrowse`; the five headers appear as before. - Done when: `pnpm exec vitest run config/serverConfig.test.ts` green; the number of assertions in the file is higher than before. - Record: the names of replaced tests. Record (done): "IIS heeft een SPA-fallback en een HTTPS-redirect" became "IIS heeft een HTTPS-redirect en geen SPA-fallback" (stricter: also no index.html). The nginx replacements were already in place. 13 tests became 26. --- ## Part E: Lighthouse configuration (batch B4, Sonnet; parallel with B2, B3, B5) ### Step 11: Data-driven `lighthouserc.cjs` and the audit route (BR-HST-21 to 23) [x] - Executor: Sonnet. - Implements: BR-HST-21, 22, 23; NFR-PR-P-01, P-02, S-01; V13. - Files: change `web/lighthouserc.cjs`, `web/lighthouserc.d.cts`. `lighthouserc.desktop.cjs` is not edited (it inherits). - Do: 1. `notFoundPath = '/__audit/404'`; `startServerCommand: 'pnpm preview --port 4173 --strictPort --audit-route'`. Update the comments that describe the 404 URL and the server. 2. **Targets stay exactly as they are** (home 0.8, the seven photo pages 0.85, all other 0.9, quality categories 1, desktop 0.9, `numberOfRuns: 1`). Restructure only: replace `homeMobilePerformance`, `photoPageMobilePerformance`, `photoPagePaths` by `mobileExceptions`, an object keyed by path: `{ '/': { minScore: 0.8, decision: '...' }, '/over-mij': { minScore: 0.85, decision: '...' }, ... }` for the same pages and values. The `decision` text of each entry states that it is the temporary exception carried over from the frontend-shell feature (the existing comments in the file say why) and that the owner re-decides it after the unit 3 final measurement (Steps 23 to 26). The matrix builder creates one assertMatrix entry per page with an exception and one entry for all other indexed pages at 0.9; the noindex and not-found entries are unchanged. Export `mobileExceptions` and keep the existing exports (`indexedPaths`, `noindexPaths`, `notFoundPath`, `photoPagePaths` may be removed only if nothing else imports it: grep first; the desktop config and `src/app.test.tsx` import the module). 3. Update `lighthouserc.d.cts` for the new exports. 4. Keep the comment block that explains why performance is `warn` in CI; add one line that `numberOfRuns` is 1 on purpose and that a page exactly at 0.90 can fail `pnpm check` by chance (owner decision O6). - Done when: `node -e "const c=require('./lighthouserc.cjs'); console.log(Object.keys(c.mobileExceptions).length, c.notFoundPath, c.ci.collect.startServerCommand)"` prints 8, `/__audit/404` and the new command; the effective targets per URL are identical to before (compare the output of a small script that prints, per URL, the `minScore` of the matching mobile and desktop entries before (from `git stash`-free means: read the original file with `git show HEAD:web/lighthouserc.cjs` into the scratch folder and load both) and after: all equal); `pnpm exec tsc --noEmit`, `pnpm lint` clean. - Record: targets identical before and after (per URL, mobile and desktop, performance level error and warn): `/` 0.8; `/over-mij`, `/soorten-fotoshoots` and the five shoot pages 0.85; `/portfolio`, `/contact`, `/privacyverklaring` and the 404 page 0.9; desktop 0.9 everywhere. The 404 URL changed to `/__audit/404` as the plan prescribes. `photoPagePaths` is kept as a derived export because `src/app.test.tsx` imports it. ### Step 12: Tests for the Lighthouse configuration (P-HST-11, V13) [x] - Executor: Sonnet. - Implements: P-HST-11; BR-HST-22, 23; V13. - Files: create `web/config/lighthouserc.test.ts`; change `web/src/app.test.tsx` (only the Lighthouse guard test). - Do: 1. `app.test.tsx`: `expect(lighthouseConfig.notFoundPath).toBe('/__audit/404')` and update the comment (Lighthouse refuses an error status; the preview serves the 404 page with 200 only through the opt-in route; `/404.html` is a real 404). 2. `config/lighthouserc.test.ts` (loads the CJS module with `createRequire`): every exception has a non-empty `decision` string, `minScore < 0.9`, and names a path in `indexedPaths`; no URL of the collect list matches two assert-matrix entries and none matches zero (use each entry's `matchingUrlPattern` as a RegExp); `notFoundPath` is not in `indexedPaths` or `noindexPaths`; `startServerCommand` contains `--audit-route`; `numberOfRuns` is 1; the quality categories accessibility, best-practices, SEO have `minScore: 1` in every entry that has them; the desktop config sets every performance assertion to 0.9. Property-style (`(invariant)`) where useful: for any generated subset of exception entries the matrix builder (if exported as a function; otherwise test the produced matrix) covers each indexed page exactly once. Include an example-based test that a deliberately invalid exception (empty decision, `minScore` 0.9) would be rejected by the validation helper you extract (`validateExceptions` in the CJS file, exported and used by the module itself at load time so a bad table fails at import). - Done when: `pnpm exec vitest run config/lighthouserc.test.ts src/app.test.tsx` green; `pnpm exec tsc --noEmit`, `pnpm lint` clean. - Record: `config/lighthouserc.test.ts` added (invariants, validation helper, desktop); only the `notFoundPath` assertion and its comment changed in `src/app.test.tsx`; 55 tests green across both files. --- ## Part F: Deploy scripts and CI (batch B5, Sonnet; parallel with B2, B3, B4) ### Step 13: Artifact guard and post-deploy script (BR-HST-15, 18; V11) [x] - Executor: Sonnet. - Implements: BR-HST-15, 18; FR-PR-17; NFR-PR-SEC-03; V11. - Files: create `web/deploy/check-artifact.sh`, `web/deploy/verify-deployment.sh`, `web/e2e/deployScripts.e2e.ts`. - Do: 1. `check-artifact.sh ` (bash, `set -euo pipefail`): fails unless `index.html`, `404.html` and `over-mij.html` exist, no `server` directory exists, and no `*.map` file exists anywhere below the directory; prints what it found. 2. `verify-deployment.sh [--test]` per BR-HST-18: validates the URL (`https?://` and no whitespace), normalises a trailing slash, retries reachability like the current workflow (`--retry 5 --retry-delay 3`). Checks, each failing the script with a clear message: `/`, `/over-mij` and `/soorten-fotoshoots/newborn` return bytes identical to `index.html`, `over-mij.html`, `soorten-fotoshoots/newborn.html` of the dist directory (fetched without `Accept-Encoding`; compare with `cmp`); an unknown URL returns 404 with the bytes of `404.html`; `/over-mij/` returns 301 whose `Location` path is `/over-mij` and `/Over-Mij` returns 301 to `/over-mij` (accept absolute or relative `Location`); the five security headers on the 200, the 301 and the 404; with `--test` also `X-Robots-Tag` and `Content-Encoding: gzip` for the first `/assets/*.js` found in `index.html` (a missing gzip on test fails; without `--test` it only warns). No `eval`, quoted variables, no secrets. 3. `e2e/deployScripts.e2e.ts`: skipped with a visible line when `bash` or `curl` is missing outside CI (fails in CI). Tests: `check-artifact.sh` passes on a fixture dist and fails for each violation (missing file, `server/`, a `.map`); `verify-deployment.sh` passes against `startPreviewServer` on the fixture site (without `--test`) and **fails against a tiny stub server** that imitates the old behaviour (serves `index.html` with 200 for every path, no 404, no redirects) with a message naming the `/over-mij` byte check (V11); and fails when a security header is missing (stub). - Done when: `pnpm exec vitest run --config vitest.e2e.config.ts e2e/deployScripts.e2e.ts` green (or skipped with the visible line when bash is absent); `pnpm exec tsc --noEmit`, `pnpm lint` clean. - Record: V11 outcome. - Done: check-artifact.sh, verify-deployment.sh and e2e/deployScripts.e2e.ts written. V11: verify-deployment.sh fails against a stub with the old behaviour (homepage with 200 for every path) with "/over-mij: antwoord is niet gelijk aan over-mij.html", and passes against a stub with the new rules and against the preview server on the fixture site. Proven against stubs, not against the real old nginx file. Locally 22 passed, 5 skipped (the lftp tests). ### Step 14: Production upload script and the lftp passes (BR-HST-14; V10) [x] - Executor: Sonnet. - Implements: BR-HST-14, 15; FR-PR-18; V10. - Files: create `web/deploy/upload-production.sh`; extend `web/e2e/deployScripts.e2e.ts`. - Do: 1. `upload-production.sh `: runs `check-artifact.sh`, copies `deploy/iis/web.config` to `/web.config`, then runs lftp with three passes in this order: (1) `mirror --reverse --verbose` excluding every `*.html` and `web.config` (including nested HTML); (2) `put` of `web.config`, then `mirror --reverse --verbose` including only `*.html` (all HTML, nested, `404.html`, `index.html`); (3) `mirror --reverse --delete --verbose` of everything. Connection: by default `open` the FTP host from the environment as the workflow does now (`FTP_HOST`, `FTP_USER`, `LFTP_PASSWORD`, `ftp:ssl-force true`, `ftp:ssl-protect-data true`, `net:max-retries 3`); an environment override `LFTP_OPEN` (used only by the test) replaces the connection by a local target. No password on the command line or in logs. 2. Find the exact exclusion syntax in the lftp manual (`man lftp`, `lftp --help mirror`; only if lftp is installed locally, otherwise from the documentation on `https://lftp.yar.ru/`): `--exclude-glob GLOB`/`-X` and `--include-glob GLOB`/`-I`, or `--exclude RX`/`--include RX` with a regular expression. Decide which form matches nested files (the glob is matched against the path relative to the mirror root; confirm by test, not by assumption). 3. Test (in `deployScripts.e2e.ts`): if `lftp` is available (locally or CI), run the script against a temporary fixture dist (index.html, 404.html, over-mij.html, soorten-fotoshoots/newborn.html, assets/a.js, web.config absent in dist but present in `deploy/iis/`, robots.txt) with `LFTP_OPEN` pointing at a temporary local directory through lftp's `file:` protocol, plus a stale file in the target: assert pass 1 copied no `.html` and no `web.config` (check by parsing the `--verbose` output order and the directory state between passes: split the script into three callable functions or give it an env switch `UPLOAD_PASS=1|2|3` used only by the test), pass 2 copied all HTML including the nested one and `404.html`, pass 3 deleted only the stale file, the final tree equals the dist plus `web.config`, and every `assets/*` file was uploaded before the first `.html` in the full run's output (FR-PR-18). If `lftp` is not available: skip with a visible line (CI installs it in Step 5; the test must fail in CI when lftp is missing). 4. If `lftp` is not installed locally, the local test does not run and the syntax is **unverified until the first CI run**: state that plainly in the Record and in the verification log V10 (Status OPEN), and do not install lftp. - Done when: the script exists and passes `bash -n`; the test runs green with lftp, or V10 is recorded OPEN with the reason; `pnpm exec tsc --noEmit`, `pnpm lint` clean. - Record: V10 outcome and the chosen syntax with its source. - Done: upload-production.sh written (passes `bash -n`; command text checked with a fake lftp on the PATH). Chosen syntax: `--exclude-glob '*.html' --exclude-glob web.config` for pass 1 and `--include-glob '*.html'` for pass 2 (the design sketch; lftp manual at https://lftp.yar.ru/ not consulted offline). lftp is not installed locally, so V10 is OPEN: the syntax is unverified until the first CI run (the lighthouse job installs lftp and runs the test). Open question for that run: whether `--include-glob` alone includes only HTML and still descends into directories. ### Step 15: Workflow edits for the deploy jobs (BR-HST-14 to 18) [x] - Executor: Sonnet. - Implements: BR-HST-14 to 18; FR-PR-17, 18. - Files: `.gitea/workflows/continuous_integration.yaml` (file edit only; do not dispatch, push or read run state). - Do: 1. `deploy-test`: before the upload, run `bash deploy/check-artifact.sh dist`; replace the two `curl` lines of "Controle na deploy" by `bash deploy/verify-deployment.sh "$HEALTH_URL" dist --test`, keeping the "skipped when the variable is empty" behaviour and the success message. Keep the emptying of the test folder (BR-HST-16) and the WordPress guard unchanged. 2. `deploy-production`: drop the separate "IIS-configuratie toevoegen" step and the inline lftp block; replace them by one step that runs `bash deploy/upload-production.sh dist "$FTP_DIR"` with the same `env` as now; the post-deploy step runs `bash deploy/verify-deployment.sh "$HEALTH_URL" dist` (compression warns only). Keep the `if` condition: dispatch-only, only from `release/*`. Update the comments: three passes, why the order matters, and that the job can not run until a webhost exists. 3. Update the header comment of the workflow only if it states something that is now wrong. - Done when: the YAML is valid (same check as Step 5); the diff touches only the two deploy jobs; the lftp command text exists in exactly one place (`upload-production.sh`). - Record: the diff summary. - Done: deploy-test: new step "Controle van de build" (check-artifact.sh) before the upload; "Controle na deploy" runs verify-deployment.sh with --test. deploy-production: the web.config step and the inline lftp block are replaced by one call of upload-production.sh; the post-deploy step runs verify-deployment.sh; if-condition unchanged. YAML parses (yaml 1.10.3 from the pnpm store); no mirror/lftp command text left in the workflow. See `git diff .gitea`. **CP2** (merge point after Steps 7 to 15): run `pnpm exec tsc --noEmit`, `pnpm lint`, `pnpm format:check`, `pnpm test`, `pnpm build`, in that order, alone (no parallel batch running). All green, or STOP. --- ## Part G: Server and browser tests (batch B6, after CP2) ### Step 16: Parity and full contract against real nginx (P-HST-09; V2 to V5, V12) [x] - Executor: Sonnet. - Implements: P-HST-09; BR-HST-24; V2 to V5, V12. - Files: change `web/e2e/serverRules.e2e.ts`. - Do: 1. Add the parity property `(oracle)`: start the preview server on the fixture site and real nginx on the same fixture; for generated paths (`pageVariant`, `unknownPath`, `knownPage` + `queryString`, a fixed list of hostile paths; exclude paths with `//` inside and exclude `/robots.txt`) assert that both agree on status, on the `Location` path and query (normalised: strip scheme/host), and on which fixture file was served (marker text); both carry the five security headers **also on 301 and 404 responses**; only nginx carries `X-Robots-Tag`; each response has exactly one `Cache-Control` and one `Content-Security-Policy` (raw header count); gzip is applied to the same set of files when `Accept-Encoding: gzip` is sent. `numRuns` at most 100. Document in a short comment the intentional differences (405 text, `Server` header, MIME for `.js`, the test-only `robots.txt`). 2. A smoke test over the **real** `dist/client` (needs a current build): nginx serves every page of `pagePaths` with 200 and the same bytes as the file, `404.html` for an unknown URL with 404, the directory `dist/client/soorten-fotoshoots/` exists next to `soorten-fotoshoots.html` and `/soorten-fotoshoots` still returns the page. 3. The in-CI gate from Step 4 stays: no nginx in CI fails the suite (V12). 4. Print `nginx -v` once in the test output. - Done when: `pnpm build && pnpm exec vitest run --config vitest.e2e.config.ts e2e/serverRules.e2e.ts` green with a local nginx, or skipped with the visible line without one. With no local nginx, this step is written and type-checked only; its first real run is the CI cycle that closes CP1/CP3. - Record: whether it ran, with which nginx. - Written and type-checked; it did not run: no nginx on this PC, so the three new suites skip locally (the existing gate prints the skip line, and in CI a missing nginx fails the suite). First real run is the CI cycle. New in `e2e/serverRules.e2e.ts`: the parity suite (the rows of § 3.1, the fixture files, and a 100-run property over `pageVariant` and `unknownPath` with and without slash and query), a block "lege segmenten, buiten de pariteit", and a suite on the real `dist/client` (every page byte for byte, unknown URL, the directory next to `soorten-fotoshoots.html`, `/assets`). `get()` got a `raw` option because the URL parser rewrites a backslash to a slash. `nginx -v` is printed once. `vitest.e2e.config.ts` now also runs `config/testSeed.ts`, so the property test uses the global seed. Decisions: `//` and `///` (preview 301 to `/`, nginx 200) and every path with an empty segment are outside parity, pinned on both sides as safety checks; Cache-Control is compared only on HTML responses and not on a 301 (preview sends none, nginx sends no-cache), and the preview sets none on non-HTML files; `/%2e%2e/` and NUL are outside parity (nginx answers 400). ### Step 17: Browser tests for the new URL behaviour and adjusted tests (V8) [x] - Executor: Sonnet. - Implements: BR-HST-02, 05, 08, 22; FR-PR-14, 15, 16; V8. - Files: create `web/e2e/urls.e2e.ts`; change `web/e2e/support/server.ts` (an optional `startServer({ auditRoute })`), `web/e2e/rawHtml.e2e.ts`, `web/e2e/hydration.e2e.ts` and any other e2e file that fetches `/404.html` (grep `404.html` in `e2e/` and `src/`; apply § 6). - Do: 1. `urls.e2e.ts` (Chrome, against the preview server on the real `dist/client`): for `/Over-Mij`, `/Over-Mij?pakket=gezin`, `/over-mij/`, `/over-mij/?x=1`, `/soorten-fotoshoots/`, `/index.html`, `/over-mij.html`: Chrome follows one 301, ends on the canonical URL with the query intact, the page title is the page's own (1 `title`), no `meta[name=robots]` unless the page is `/privacyverklaring`, no console error, no hydration error (V8). `/onbekend` and `/404.html` and `/404` show the 404 page with status 404, 1 title, 1 `noindex`, no console error other than Chrome's own line for the 404 status of the document. `/__audit/404` hydrates cleanly under `startServer({ auditRoute: true })`. 2. Replace the observation test `URL die de server niet kent en de router wel (BR-404-07)` in `hydration.e2e.ts` by assertions that the two URLs now redirect (the mismatch cannot occur any more); keep the rest of the file's expectations. The raw-HTML test for `404.html` fetches it with status 404. 3. Any other e2e expectation that relied on `/404.html` returning 200 is adjusted to 404 (same strictness) and listed in the Record. - Done when: `pnpm exec tsc --noEmit`, `pnpm lint` clean; the files are written and each runs green on a current build in Step 18. - Record: the list of e2e files and tests that changed. - Created `e2e/urls.e2e.ts` (7 redirect rows, 3 404 rows, 2 audit-route tests). `e2e/support/server.ts`: `startServer({ auditRoute })`. `e2e/hydration.e2e.ts`: `expectedStatus` no longer gives 200 for `/404.html`; the late-chunk test on `/404.html` passes `expectNotFound: true`; the observation test `URL die de server niet kent en de router wel (BR-404-07)` is replaced by `URL die alleen de router kent wordt doorverwezen (BR-HST-08)` (`/Over-Mij` and `/over-mij/`: 301 to `/over-mij`, hydrated, no messages). `e2e/rawHtml.e2e.ts`: the test `heeft één titel, één noindex en geen beschrijving of canonical` fetches `/404.html` with status 404. `e2e/displayHtml.e2e.ts`: `fetchDocument` expects 404 for `/404.html` (it expected 200 for all). No other e2e file or `src/*.test.tsx` depended on 200 for `/404.html` (grep of `404` in `e2e` and `src`; `deployScripts.e2e.ts` already follows the new contract). ### Step 18: Run all server and browser tests on a current build (CP3) [x] - Executor: Haiku. - Do: from `web/`, in one command line `pnpm build && pnpm e2e`; no other job running. Wait for completion (rule 11). Fix nothing; report failures with output to Sonnet's steps (16, 17) or STOP. - Done when: **CP3**: all e2e files green (the nginx suite either ran green or printed the skip line; if CP1 is still open the report says so). Record counts in `code-summary.md` later. - Record: file and test counts, the nginx line. - Run on a current build (`pnpm build`, then `pnpm e2e`, seed 1174228318): 12 files passed, 248 tests passed, 204 skipped, 0 failed. The 204 skipped are the nginx suites (no nginx here). `pnpm test`: 132 files, 1390 tests passed, coverage thresholds met. CP3: nginx suites skipped locally; CP1 is closed by CI run 593, but the new parity and real-build suites have not yet run on a real nginx. --- ## Part H: Finish (batch B7) ### Step 19: Comments, naming, formatting review [x] - Executor: Sonnet. - Do: read `git diff` of `web/` and check: no comment or test title names a plan step or this plan; comments explain why; the file header of `previewServer.ts`, `serverConfig.ts`, `lighthouserc.cjs` and the generated files state the current truth (no mention of the 200 at `/404.html`, no "SPA fallback"); no leftover scratch code; no `console.log` in the new code except the intended skip line; `pnpm exec prettier --check` on every changed file; every new file has a short header comment saying why it exists. - Done when: `pnpm lint`, `pnpm format:check`, `pnpm exec tsc --noEmit` clean; the review notes are one line each in the Record. - Record: findings fixed. - Done. Review of the unit 3 files (previewServer.ts, canonicalUrls.ts, compressibleTypes.ts, lighthouserc.cjs, serverConfig.ts, the three deploy scripts, nginx conf, web.config, workflow): no comment or test title names a plan step, no SPA or `/404.html`-200 text, no scratch code, `console.log` only in the intended places (ready line, `writeServerConfig`, seed line, test names), every new file has a header. One fix: `src/test/navViewport.ts` named "Step 17" and is now timeless (an unit 2 file). Prettier, eslint and `tsc --noEmit` clean. Defects found in the line-by-line read are listed in the report to the main session, not fixed. ### Step 20: Fit with the Pi install instructions and hand-over notes [x] - Executor: Sonnet. - Do: `aidlc-docs/features/prerendering/construction/hosting-and-targets/infrastructure-design/pi-install-instructions.md` was written by the Pi-Main session through the main session. **Do not change it.** `infrastructure-design.md` § 13 links to it from H2, H4 and the rollback text (the main session edited them). Step 20 only verifies that the generated files fit it, and records the result: 1. The backup lives in `/mnt/storage1/backups/andreaslop-test-nginx/` (outside `conf.d`); no document and no generated comment says `.bak` beside the conf. 2. The generated file is installed as `/etc/nginx/conf.d/andreaslop-test.conf`; its `root` equals `DEPLOY_PATH_TEST` (`/var/www/html/andreaslop-test`); the header comment mentions `00-default.conf` and 444 (Step 3). 3. The "Points for the generated config" of the instructions hold in the generated text: every location with its own `add_header` repeats the full set, `/assets/` has exactly one `Cache-Control`, `etag` untouched, `location = /robots.txt` is test-only (production serves the build's `robots.txt` and `sitemap.xml`), and no map rule matches `/404` or `/404.html`. 4. The proxy checks of the instructions (table "Proxy Pi") are the owner's; nothing in the code depends on their outcome. The Pi-Main session requests the `server-ops` draft separately, with the generated text of `web/deploy/nginx/andreaslop-test.conf`; this plan only produces that file. **This plan does not touch the Pi, `server-ops` or the webhost, and does not merge.** Human tasks, listed so nobody mistakes them for plan steps: H2 (the owner places the config as the instructions say, after separate approval, and reloads), H3 (the deploy right after: a manual branch deploy or the merge, with the checks of the instructions and of deployment-architecture.md § 5), the optional proxy check/change H4, the first CI proof of Step 6, and everything about the webhost (Q1 to Q6, U1 to U6). Add one line to `code-summary.md` (Step 24) that references the instructions file. - Done when: the four points are recorded OK (or DEVIATION with the exact difference) in the verification log under V14; `pi-install-instructions.md` is unchanged by this plan. - Record: one line. - Done. All four points hold in the generated text (V14 updated). Findings for the owner are in the report to the main session; `pi-install-instructions.md` is untouched. ### Step 21: Full verification (Code Generation Step 13.5; CP4) [x] - Executor: Haiku. - Do: from `web/`, in order, each to completion: `pnpm lint`, `pnpm format:check`, `pnpm test`, `pnpm build && pnpm e2e`, `pnpm audit:deps`, `pnpm audit:dev`. Then record SHA-256 of `lighthouserc.cjs` targets file for Step 23: compute the effective target table of Step 11 again and compare it with the baseline from Step 11's Record (must be identical). - Done when: **CP4**: all green (audit:dev only reports). Counts, seed, durations in the Record. If any fails: STOP, report. - Record: counts; the targets comparison result. - Done (CP4). `pnpm lint`, `pnpm format:check`, `tsc --noEmit` clean; `pnpm test` 132 files, 1390 tests passed, seed 743185601, 75.9 s; fresh `pnpm build && pnpm e2e`: 12 files passed, 248 tests passed, 204 skipped (nginx and lftp not installed here; CI covers them), seed 1046879097, 202 s; `pnpm audit:deps` no known vulnerabilities; `pnpm audit:dev` reports 23 (2 low, 10 moderate, 11 high), non-blocking. Targets: `lighthouserc.cjs` SHA-256 `6e146472ed7a...` (mobile) and `lighthouserc.desktop.cjs` `f13d993389ba...` (unchanged from the baseline); the effective per-URL assertions (24 URL entries, mobile and desktop) of the baseline commit 4f32042 and of the current files are identical (0 differences; the 404 URL compared as the 404 page). --- ## Part I: Final measurement (batch B8; exclusive: rules 11 and 12) Preconditions for Part I: Step 21 green; the main session has confirmed that it holds port 4173 for this work; `git status --short` recorded to `/status-before.txt`; `pnpm build` just run. The method is the one of `construction/display-fallbacks/code/measurement-display.md`: `lhci collect`, **3 runs per URL**, median, same PC and Node version as units 1 and 2, `config/previewServer.ts` on port 4173. The configs are not edited for this (`numberOfRuns` stays 1 in the files; the 3 runs come from the command-line option). Runs may be backgrounded; wait for them. ### Step 22: Run the measurement, mobile and desktop, all pages [x] - Executor: Haiku for the runs, Sonnet for the script. - Implements: NFR-PR-P-01, P-02, S-01; V9. - Do: 1. Reuse or recreate the summary script of the display-fallbacks measurement (a Node script in the scratch folder that reads every `lhr-*.json` of a folder and prints, per URL, the median of performance score, FCP, LCP, TBT, CLS, the LCP element, and script transfer size; plus the scores of accessibility, best practices and SEO). Write it fresh in the scratch folder if it is gone. 2. Remove `.lighthouseci`. Mobile: `pnpm exec lhci collect --config=lighthouserc.cjs --numberOfRuns=3`, then move `.lighthouseci` to `/final/mobile`; desktop likewise with `lighthouserc.desktop.cjs` to `/final/desktop`. The URL list is the config's: the ten indexed pages, `/privacyverklaring`, and the not-found page through `/__audit/404` (the config starts the preview with `--audit-route`). All 12 URLs, both presets. 3. Check the 404 page result (V9): the median run has no runtime error, best practices 1, accessibility 1; if it does not, STOP-AND-ASK with the failing audits (the owner chose the audit route; a failure here is a finding, not something to fix by changing the targets). 4. Stop every process you started; confirm port 4173 is free again. - Done when: both folders contain 3 reports per URL (36 per preset); the script output exists. - Record: paths of the output folders. - Done. 36 reports per preset, no errors. Output: `C:\Users\Bryan\AppData\Local\Temp\claude\k--Development-SlpSoftware-Projects-AndreaSlopFotografie\bb0a550e-5427-462f-b99b-f9db012a172a\scratch\final\mobile` and `\final\desktop` (`.lighthouseci` inside), summaries `final-mobile-summary.txt` and `final-desktop-summary.txt` in the same scratch folder. V9: not-found page best practices 1, accessibility 1, no runtime error. ### Step 23: Measurement report for the owner's decisions [x] - Executor: Sonnet. - Implements: NFR-PR-P-01, P-02, S-01; BR-HST-21, 23. - Do: write `aidlc-docs/features/prerendering/construction/hosting-and-targets/code/measurement-final.md` in the format of `measurement-display.md`: method (commit, date, Node, 3 runs median, same PC); one table mobile and one desktop with per URL the score at **master / unit 1 (A) / unit 2 (U2) / final**, LCP and FCP likewise, the LCP element, TBT, CLS, script transfer; accessibility, best practices and SEO per URL (must be 1; list any that are not); the not-found row noting that earlier units measured `/404.html` served with 200 and this unit measures the same page through `/__audit/404`; a decision table with one row per page below 0.90 on mobile (score, LCP element, current exception value in `lighthouserc.cjs`) and the options for the owner (keep an exception at a stated floor, work on the page, accept a red `pnpm check`), plus the note that two pages sitting at 0.90 can flip with `numberOfRuns: 1`; a list of pages at 0.90 or higher that today still carry an exception (these would lose it). Neutral reading only; state no recommendation about lowering targets. Take the master, A and U2 figures from `construction/start-migration/code/measurement-gate.md` and `construction/display-fallbacks/code/measurement-display.md` and say which file each came from. Verify that `lighthouserc.cjs` and `lighthouserc.desktop.cjs` have the same SHA-256 as at Step 21 (targets unchanged) and that `git status --short` equals `/status-before.txt`; rebuild `dist` from the real code (`pnpm build`). - Done when: **CP5**: the report exists with all 12 URLs in both tables; checksums equal; `dist` current. - Record: one line with the number of pages below 0.90 on mobile. - Done (CP5). 3 pages below 0.90 on mobile (`/` 0.85, gezin 0.89, loveshoot 0.88); report `measurement-final.md`; checksums equal to Step 21; `git status --short` unchanged apart from the plan and the new report; `dist` current. --- ## Part J: Documents (batch B9) ### Step 24: Code summary and verification log [x] - Executor: Sonnet. - Do: write `aidlc-docs/features/prerendering/construction/hosting-and-targets/code/code-summary.md` in the format of `construction/display-fallbacks/code/code-summary.md`: status; commits (leave "to be filled by the main session"); files created, modified and removed (from `git status --short` and `git diff --stat`), grouped (URL modules, nginx generator, IIS generator, preview server, Lighthouse, deploy scripts, workflow, tests, documents) with the rule ids each implements; test inventory (files, counts, which properties P-HST-01 to 11 where, which existing tests changed and why: § 6 and the Step 17 record); the verification log V1 to V14 condensed (V6 WITHDRAWN; V10 OPEN if lftp was unavailable locally; V1 to V5 with the proof source); the Step 21 outcome; deviations; what is **unverified**: the IIS rules (U1 to U6 in infrastructure-design.md § 7.2), the nginx 1.24/1.30 gap, lftp syntax if not tested, the first CI run; open points for the owner; a pointer to `pi-install-instructions.md`. Complete the verification log (Outcome, Evidence, Status for every row). - Done when: both files exist and every file of the diff is listed. ### Step 25: Reverse-engineering delta and the temporary note [x] - Executor: Sonnet. - Implements: NFR-PR-Q-05. - Files: `aidlc-docs/_shared/reverse-engineering/code-structure.md`, `architecture.md`, `component-inventory.md`, `code-quality-assessment.md`, `business-overview.md` and others only where `grep` finds the topics below. - Do: minimal, line-level edits for this feature, marked in the style earlier edits of this feature use: new `config/canonicalUrls.ts`, `config/compressibleTypes.ts`, `deploy/check-artifact.sh`, `deploy/verify-deployment.sh`, `deploy/upload-production.sh`, `e2e/serverRules.e2e.ts`, `e2e/deployScripts.e2e.ts`, `e2e/urls.e2e.ts`, `e2e/support/{fixtureSite,nginx}.ts`, `src/test/urlArbitraries.ts`; the Deployment Model line in `architecture.md` ("server rules still to be changed in unit 3" becomes the new URL contract, gzip block, upload order and the statement that IIS rules are unverified); the CI/test description in `code-quality-assessment.md` (real nginx test in CI). **Remove the temporary note about Lighthouse's `/404.html` fallback** in favour of `/__audit/404`: `grep -rn "404.html" aidlc-docs/_shared web/config web/lighthouserc.cjs web/src/app.test.tsx` for any sentence saying Lighthouse audits `/404.html` with status 200 or that the preview serves it as a file with 200, and replace it with the audit-route statement (do not rewrite the historical unit 1 and unit 2 documents; they stay as records; mention the change once in `code-summary.md`). Do not touch the Lighthouse exception line in `code-quality-assessment.md` yet (it changes in Step 27 after the owner decides). - Done when: `git diff -- aidlc-docs/_shared/reverse-engineering` shows only line-level edits for this feature; the grep finds no remaining statement that Lighthouse audits `/404.html` with 200 outside historical records. ### Report to the main session (STOP-AND-ASK; CP6) [ ] - Executor: the Sonnet agent of Step 25 ends its run here, as an explicit hand-back. - Do: return a concise report: the steps done; test and e2e counts; V status; **what was not proven** (IIS, nginx 1.24 against 1.30, lftp if untested, the first CI run if CP1 was open); the measurement summary (pages below 0.90 on mobile, pages that would lose their exception); the human tasks that remain (H2 per pi-install-instructions.md, H3, merge, H4, webhost); and the question the owner must answer for the per-page targets (`measurement-final.md` decision table). **Do not change `lighthouserc.cjs` targets, do not commit, do not merge.** Wait for the main session. - Done when: the report is returned; nothing is running; `git status --short` shows only the intended changes. --- ## Part K: After the owner's decisions (batch B10, Sonnet; runs only when the main session passes the decisions) ### Step 26: Apply the owner's per-page decisions [x] - Executor: Sonnet. - Implements: NFR-PR-P-01; BR-HST-21, 23. - Do: with the decisions written in the main session's message (page, new `minScore` or "remove the exception", the date and where the decision is recorded): edit only the `mobileExceptions` table in `web/lighthouserc.cjs`: delete entries for pages that now meet 0.9, change or keep others with `decision` set to the owner's decision text and its record location; leave `numberOfRuns` at 1; do not edit `lighthouserc.desktop.cjs`. Update the comments in the file to match. If a decision is missing for a page below 0.90, STOP and ask; never choose for the owner. - Done when: `pnpm exec vitest run config/lighthouserc.test.ts src/app.test.tsx`, `pnpm lint`, `pnpm format:check`, `pnpm exec tsc --noEmit` green; the effective target table matches the decisions exactly. - Record: the final target table. - Done. Mobile: `/` 0.85; zwangerschap, gezin, loveshoot, portret 0.85; `/over-mij`, `/portfolio`, `/soorten-fotoshoots`, newborn, `/contact`, `/privacyverklaring`, `/__audit/404` 0.9. Desktop 0.9 everywhere. `lhci assert` on the existing final measurement: 12 of 12 pass, both presets. `photoPagePaths` removed (no longer true for every shoot page); `src/app.test.tsx` adjusted. ### Step 27: Final documents [x] - Executor: Sonnet. - Do: update `code-summary.md` (targets applied, decisions with their record), the Lighthouse exception line in `aidlc-docs/_shared/reverse-engineering/code-quality-assessment.md` and any other shared line that states the old exceptions, and `measurement-final.md` (a short "Owner decisions" section). Run `pnpm test` once for the summary counts. - Done when: **CP7**: the documents match the code; no statement about exceptions that contradicts `lighthouserc.cjs`. --- ## 4. Suggested logical commit boundaries (for the main session; commit and push only when the owner approves) 1. Docs: this plan and the verification log skeleton (aidlc-docs only). 2. URL and type modules with their tests and generators (Step 2). 3. nginx generator, regenerated `deploy/nginx`, `serverConfig.test.ts` nginx part, fixture and nginx harness with the server-rule test, the CI install step (Steps 3 to 5). This is the commit the first CI proof needs. 4. Preview server: contract, audit route, tests (Steps 7, 8). 5. IIS text, complete `serverConfig.test.ts`, regenerated `deploy/iis` (Steps 9, 10). 6. Lighthouse: data-driven config, audit route use, tests (Steps 11, 12). 7. Deploy scripts, their tests and the workflow edits (Steps 13 to 15). 8. Parity tests, URL browser tests, adjusted e2e (Steps 16, 17). 9. Docs: measurement report, code summary, verification log, reverse-engineering delta, Pi-instructions fit check (Steps 20, 23 to 25). 10. After the owner's decisions: Lighthouse targets and final docs (Steps 26, 27). ## 5. Open points for the main session (not plannable without a decision) - **The first real nginx proof (Step 6).** No nginx on this PC, the Podman machine is stopped; installs and starting it need the owner's approval. The default path is one CI cycle that the main session starts through a pull request or workflow dispatch (a push alone triggers nothing). If a local nginx is approved instead (scoop for Windows, or the Podman machine with a container), say so; the harness takes `NGINX_BIN` and a container mode is added only on request. - **Version gap.** CI nginx is 1.24 (Ubuntu runner image), the Pi runs 1.30.6. The mime table variants (`.js` as `application/javascript` or `text/javascript`) cover the known difference; the real check on 1.30.6 is `nginx -t` and the curl matrix during H2 and H3. - **lftp.** If lftp is not installed locally, the exclusion syntax stays unverified until the CI run (V10 OPEN). Installing lftp locally needs the owner's approval. - **Exceptions in `lighthouserc.cjs` carry a provisional `decision` text** until the owner decides (Steps 23, 26): the guard test needs a non-empty text, so today's entries say they are carried over from the frontend-shell feature. The main session should confirm this wording is acceptable or give a better record location. - **Owner decisions per page** after Step 23: which pages keep a mobile exception. Nothing is lowered or left in place without that answer. Two pages sit at exactly 0.90 with `numberOfRuns: 1`. - **H2 install instructions** are in `infrastructure-design/pi-install-instructions.md` (written by the Pi-Main session; the owner places the config; do not change the file). The `server-ops` draft is requested separately with the generated text. Timing: place and reload, then deploy right after (a manual branch deploy or the merge); the merge waits for H2. - **`deploy-production`** cannot run until a webhost exists; its YAML and `upload-production.sh` are tested only against a local `file:` target and a stub. - **IIS** is unverified: U1 to U6 and the questions Q1 to Q6 of infrastructure-design.md stay open until a host exists. - **Port 4173 and the CPU** are shared with peer sessions; the main session claims and releases them around Part I. ## 6. Existing tests that legitimately change (all others must pass unchanged) | Test | Change | Reason | Step | |---|---|---|---| | `config/serverConfig.test.ts` "de testsite wordt nooit geindexeerd" (asserts `try_files $uri $uri/ /index.html =404`) | Keeps the noindex and `Disallow` assertions; the `try_files` assertion becomes `try_files $uri $uri.html =404` plus a negative check for `/index.html` and `$uri/` | BR-HST-02, 07: no SPA fallback | 3 | | `serverConfig.test.ts` "elk nginx location-blok herhaalt de security headers" (`toHaveLength(3)`) | Counts the new locations (robots, 404, 404.html, assets, root, default) and still requires all headers in each | New locations | 3 | | `serverConfig.test.ts` "IIS heeft een SPA-fallback en een HTTPS-redirect" | The HTTPS part stays; the SPA assertion becomes "no SPA fallback and no rewrite to /index.html" | BR-HST-02 | 10 | | `config/previewServer.test.ts` group "tussenregels uit BR-SRV-07" (4 tests: trailing slash 404, `/404` status, `/404.html` as file with 200, `/index` and `/index.html` serve `index.html`, never a redirect) | Final rules: trailing slash 301, `/404` and `/404.html` 404, `/index` and `/index.html` 301 to `/`, redirects exist | BR-HST-03, 04, 05 | 8 | | `previewServer.test.ts` "geeft 404 voor een slash aan het eind, zonder redirect" and any test expecting 200 for `/404.html` | Updated as above, no looser | same | 8 | | `previewServer.test.ts` P16 and P17 properties | Only where a generated input now yields a redirect; the model gets the redirect rule | BR-HST-03, 04 | 8 | | `src/app.test.tsx` "loopt gelijk met de URLs van Lighthouse CI" | `notFoundPath` is `/__audit/404`; comment updated | BR-HST-22 | 12 | | `e2e/rawHtml.e2e.ts` "rauwe HTML van 404.html" | Fetches `/404.html` with status 404 instead of 200 | BR-HST-05 | 17 | | `e2e/hydration.e2e.ts` page lists containing `/404.html` and the BR-404-07 observation test | Status expectations follow 404; the observation test becomes assertions that `/Over-Mij` and `/over-mij/` redirect | BR-HST-04, 08 | 17 | | Other `e2e/*.e2e.ts` or `src/*.test.tsx` expecting `/404.html` to return 200 (found by `grep -rn "404.html" e2e src`) | Expect 404 | BR-HST-05 | 17 | Not changed (named so nobody loosens them): the security-header tests of `serverConfig.test.ts` (IIS and nginx contain every header), the www redirect tests, "het testblok claimt nooit de standaardserver", "houdt doorverwijzingen relatief", the proxy tests, the generator sync test, the compression and content-type tests of `previewServer.test.ts`, the traversal tests, all component tests.