Hardens the upload path check and the deploy verification
A remote of . or .. could have made the cleanup pass delete the wrong folder, so such paths are refused before anything runs. A connection error now ends in the normal summary instead of aborting the check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
- **Feature Slug**: prerendering
|
||||
- **Project Type**: Brownfield
|
||||
- **Start Date**: 2026-10-31T14:15:01Z
|
||||
- **Current Stage**: CONSTRUCTION - Code Generation (unit 3: hosting-and-targets): B0 to B6 done; CI proof of parity running
|
||||
- **Current Stage**: CONSTRUCTION - Code Generation (unit 3: hosting-and-targets): B0 to B7 done; B8 final measurement running
|
||||
- **Branch**: feature/prerendering (from master c4c2f83); commits and pushes allowed for this feature (owner, 2026-10-31); workflow dispatch without deploy allowed; deploy to test after all units (owner, 2026-11-01), after the nginx config is placed
|
||||
- **Worktree**: K:\Development\SlpSoftware\Projects\AndreaSlopFotografie-prerendering
|
||||
|
||||
|
||||
+1
-1
@@ -19,4 +19,4 @@ Status values: OK, BLOCKED, DEVIATION, WITHDRAWN, OPEN.
|
||||
| V11 | `verify-deployment.sh` fails against a copy of the old nginx config (home page for `/over-mij`) and passes against the new one | 13 | OK against stubs: verify-deployment.sh exits 1 against a stub that imitates the old nginx config (index.html with 200 for every path), with the messages "/over-mij: antwoord is niet gelijk aan over-mij.html", "status 200, verwacht 404" and "/over-mij/: status 200, verwacht 301"; it exits 0 against a stub with the new rules (also with a trailing slash on the URL) and against the preview server on the fixture site. Also fails per missing security header, with --test without X-Robots-Tag or gzip; gzip missing only warns without --test. Not run against the real old or new nginx file on the Pi (nothing is contacted); the first deploy-test run shows it against the new config. | pnpm exec vitest run --config vitest.e2e.config.ts e2e/deployScripts.e2e.ts: 22 passed, 5 skipped (lftp) | OK (stubs) |
|
||||
| V12 | CI: the `lighthouse` job (or a new `server-rules` job) installs nginx, `pnpm e2e` includes `serverRules.e2e.ts`, and the job fails if nginx is missing | 5, 16 | OK: the lighthouse job installs nginx and lftp, Browsertests runs with CI=true, serverRules ran with nginx present. The missing-nginx failure path was proven locally (CI=true without nginx fails with "nginx ontbreekt in CI (BR-HST-24)"). | CI run 593 (commit 8cb9185), job lighthouse, step Browsertests, nginx/1.24.0 (Ubuntu) on the Pi runner (container, root); e2e/serverRules.e2e.ts: 134 tests, all passed, none skipped (2088 ms), 67 per mime variant (.js as text/javascript and as application/javascript); the run totals 348 tests with 341 passed and 7 failed, all 7 in images.e2e.ts and reveal.e2e.ts (timeouts, unrelated); the test prints "[serverRules] nginx -v: nginx version: nginx/1.24.0 (Ubuntu)" once per variant. Earlier cycles found and fixed three defects through this proof: workers as www-data could not read the mkdtemp fixture (harness, run 592: 403), map plain keys ignore case so /Over-Mij was not redirected (generator), and /%5Cevil.example/ produced Location /evil.example (generator, BR-HST-06). The install step in run 593 uses policy-rc.d to keep the package from starting a service. | OK |
|
||||
| V13 | `lighthouserc.cjs`: the exception table is empty on delivery unless an owner decision exists; P-HST-11 passes; `pnpm lighthouse` still starts the preview with `--audit-route` and `Local` appears for `startServerReadyPattern` | 11, 12 | Exception table holds the 8 carried-over entries (targets unchanged by plan; decision text "tijdelijk, tot de eindmeting van prerendering" until the owner decides); effective per-URL assertions identical before/after for mobile and desktop, performance level error and warn; `config/lighthouserc.test.ts` + `src/app.test.tsx` 55 tests green; start command has `--audit-route` | OK: `pnpm exec lhci collect --url=http://localhost:4173/__audit/404 --numberOfRuns=1` started `pnpm preview --port 4173 --strictPort --audit-route`, the `Local` line was seen, Lighthouse audited the page with status 200 and no run warning (mobile: performance 0.96, accessibility 1, best-practices 1, seo 0.58 because the page is noindex; one run, indicative only). Port 4173 was free before and after |
|
||||
| V14 | The generated header comment fits the Pi: install path `/etc/nginx/conf.d/andreaslop-test.conf` (included from `nginx.conf:38`), no `sites-enabled`, no global `nginx.conf` change; the file works for a first install and for an update of an existing file | 3 | Header comment rewritten: install path /etc/nginx/conf.d/andreaslop-test.conf, included in http {} from nginx.conf, no sites-enabled, no global nginx.conf change, own gzip block because the Pi has none, works behind an HTTP/1.0 proxy, 444 from 00-default.conf for an unknown host (old WordPress remark removed), server_name and root adaptable, no default_server. The same file serves a first install and an update (it replaces the existing file in place). | Generated deploy/nginx/andreaslop-test.conf (lines 1-12); equals nginxTestConf() (serverConfig.test.ts sync test green) | OK |
|
||||
| V14 | The generated header comment fits the Pi: install path `/etc/nginx/conf.d/andreaslop-test.conf` (included from `nginx.conf:38`), no `sites-enabled`, no global `nginx.conf` change; the file works for a first install and for an update of an existing file | 3 | Header comment rewritten: install path /etc/nginx/conf.d/andreaslop-test.conf, included in http {} from nginx.conf, no sites-enabled, no global nginx.conf change, own gzip block because the Pi has none, works behind an HTTP/1.0 proxy, 444 from 00-default.conf for an unknown host (old WordPress remark removed), server_name and root adaptable, no default_server. The same file serves a first install and an update (it replaces the existing file in place). | Generated deploy/nginx/andreaslop-test.conf (lines 1-12); equals nginxTestConf() (serverConfig.test.ts sync test green) Fit check against pi-install-instructions.md (final conf, 2026-11-01): (1) backup lives outside conf.d, no `.bak` in documents or generated comments: OK. (2) install path, `root /var/www/html/andreaslop-test` = DEPLOY_PATH_TEST, header mentions 00-default.conf and 444: OK. (3) every location repeats the full set of seven headers, `/assets/` has one Cache-Control, no `etag` directive, `/robots.txt` is a test-only location, no map rule matches `/404` or `/404.html`: OK. (4) proxy checks are the owner's, nothing in the code depends on them: OK. Expected results of the instructions hold in the conf by reading. Not run against a real nginx here. | OK |
|
||||
|
||||
+2
-2
@@ -243,7 +243,7 @@ The preview server keeps its gzip (BR-SRV-08). Lighthouse therefore measures com
|
||||
|
||||
| Rule | Statement |
|
||||
|---|---|
|
||||
| BR-HST-12 | `/assets/*` (hashed names): `public, max-age=31536000, immutable`. Everything else, including HTML, `robots.txt`, `sitemap.xml`, `favicon.png` and unhashed images: `no-cache`. 301 responses carry no extra cache header (browsers may keep a 301; acceptable because the redirect set is fixed by the page list) |
|
||||
| BR-HST-12 | `/assets/*` (hashed names): `public, max-age=31536000, immutable`. Everything else, including HTML, `robots.txt`, `sitemap.xml`, `favicon.png` and unhashed images: `no-cache`. 301 responses set no cache header of their own (browsers may keep a 301; acceptable because the redirect set is fixed by the page list). On nginx the 301s from the server-level `if` and `rewrite` do inherit the server-level `Cache-Control: no-cache`; that is harmless (a 301 is revalidated instead of kept) and needs no config change. Known difference: the preview server sends no `Cache-Control` on its 301s, so a parity test must not compare that header on redirects |
|
||||
| BR-HST-13 | The five security headers of `securityHeaders('production')` are present on every response: 200, 301, 404, the 404 page, 405 and error responses. Test adds `X-Robots-Tag`. nginx uses `add_header ... always` in every location and at server level; IIS uses `customHeaders`; the preview server merges them in `send()` |
|
||||
|
||||
Only `/assets` is long-cached (owner decision O3). `robots.txt`, `sitemap.xml`, the favicon and other unhashed files revalidate: a long lifetime would keep a stale `robots.txt` after go-live, and a 304 is cheap with `ETag`. Lighthouse's cache audit is informational and does not weigh in the score.
|
||||
@@ -281,7 +281,7 @@ The webhost package has **not been purchased** (owner, 2026-11-01). The `web.con
|
||||
|
||||
| Id | Unverified point | Consequence if it fails |
|
||||
|---|---|---|
|
||||
| U1 | URL Rewrite `CustomResponse` 404 (rules 6 and 8) together with `httpErrors` `ExecuteURL` to `/404.html`: whether rule 6 re-fires on the executed child request (empty 404 body) and whether `existingResponse="Replace"` is honoured | Unknown URLs or `/404.html` return an empty or default 404. Options then: drop rule 6 (`/404.html` serves the page with 200, `noindex`), or accept the host's generic 404 page. The owner decides when a host exists (this covers the former O4 and O5) |
|
||||
| U1 | URL Rewrite `CustomResponse` 404 (rules 6 and 8) together with `httpErrors` `ExecuteURL` to `/404.html`: whether rule 6 re-fires on the executed child request (empty 404 body); in particular `/404.html` is answered by rule 6 as a 404 and then executed through `ExecuteURL`, so if rewrite rules also run on that child request, the 404 page could come back empty and whether `existingResponse="Replace"` is honoured | Unknown URLs or `/404.html` return an empty or default 404. Options then: drop rule 6 (`/404.html` serves the page with 200, `noindex`), or accept the host's generic 404 page. The owner decides when a host exists (this covers the former O4 and O5) |
|
||||
| U2 | Directory handling: rule 7 before the handler's own directory redirect, rule 8 for directory-only names (`/assets`), `/soorten-fotoshoots` next to its directory | A redirect loop, or a directory redirect instead of the page |
|
||||
| U3 | `httpCompression` is server level and can not be set in `web.config`; only `urlCompression` can | No compression on production unless the host enables it for HTML, JS, CSS, SVG, JSON, XML. FR-PR-23 then depends on the host |
|
||||
| U4 | 500.19 risk: any locked or missing section (`rewrite`, `httpErrors`, `customHeaders`, `staticContent`, `urlCompression`) makes IIS answer every request under that folder with 500, static files included | Whole site down until a valid `web.config` is uploaded. Remove the offending section once the host names it |
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ The final commands with full paths go into the draft in the `server-ops` reposit
|
||||
| `map` and `$andreaslop_canonical` | No clash. The only other map in `/etc/nginx` is `$connection_upgrade` in `nginx.conf`. All `conf.d` files are included in `http` (`nginx.conf` line 38), so a map at the top of the file is at http level |
|
||||
| `root` | `/var/www/html` is a symlink to `/mnt/storage1/www/html/`; `/var/www/html/andreaslop-test` exists (`webadmin:www-data`, 775). The owner confirmed `DEPLOY_PATH_TEST` is `/var/www/html/andreaslop-test`, which equals this `root` |
|
||||
| gzip and headers from other vhosts | gzip is on nowhere, and `nginx.conf` has no http-level `add_header`. gzip in this server block changes no other site |
|
||||
| Default block | Since 2026-10-21, `/etc/nginx/conf.d/00-default.conf` answers an unknown host with 444. The current comment that nginx would fall back to WordPress is out of date; correct it in the generator |
|
||||
| Default block | Since 2026-10-21, `/etc/nginx/conf.d/00-default.conf` answers an unknown host with 444. The generated header says so |
|
||||
| nginx 1.30.6 | Every directive in the sketch is standard there. `if` with only `return` at server level is safe |
|
||||
| `map` matching | Plain string keys in `map` compare case-insensitively, so `/over-mij ""` also matched `/Over-Mij` and blocked its redirect (found by the real nginx in CI). Canonical forms are therefore case-sensitive regex keys placed before the variant regexes; the first regex that matches wins and no loop arises. The draft must use the regenerated config |
|
||||
| `error_page` | Its internal redirect runs server-level rewrite and `if` again with `$uri=/404.html`. That matches no map rule. **Keep it so: no map rule may match `/404` or `/404.html`** |
|
||||
|
||||
+6
-3
@@ -419,14 +419,15 @@ The riskiest mechanism is the nginx block (a `map`, a server-level `if` and `rew
|
||||
|
||||
## Part H: Finish (batch B7)
|
||||
|
||||
### Step 19: Comments, naming, formatting review [ ]
|
||||
### 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 [ ]
|
||||
### 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:
|
||||
@@ -438,13 +439,15 @@ The riskiest mechanism is the nginx block (a `map`, a server-level `if` and `rew
|
||||
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) [ ]
|
||||
### 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).
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -13,10 +13,88 @@ fi
|
||||
dist="${1%/}"
|
||||
remote="${2%/}"
|
||||
|
||||
# De paden komen in een lftp-opdracht; daarom geen spaties of quotes
|
||||
# De paden komen in een lftp-opdracht; daarom geen spaties of quotes. Ook geen
|
||||
# '.' of '..' (ronde 3 verwijdert: '.' is de FTP-thuismap, '..' de map erboven),
|
||||
# geen lege segmenten en niets dat met '-' begint (zou een optie worden).
|
||||
safe='^[A-Za-z0-9._/-]+$'
|
||||
valid_path() {
|
||||
local value="$1" segment
|
||||
[[ "$value" =~ $safe ]] || return 1
|
||||
[[ "$value" != -* ]] || return 1
|
||||
[[ "$value" != *//* ]] || return 1
|
||||
local IFS=/
|
||||
for segment in ${value#/}; do
|
||||
case "$segment" in . | ..) return 1 ;; esac
|
||||
done
|
||||
}
|
||||
for value in "$dist" "$remote"; do
|
||||
if ! [[ "$value" =~ $safe ]]; then
|
||||
if ! valid_path "$value"; then
|
||||
echo "Ongeldig pad: '$value'" >&2
|
||||
exit 2
|
||||
fi
|
||||
done
|
||||
|
||||
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
bash "$here/check-artifact.sh" "$dist"
|
||||
cp "$here/iis/web.config" "$dist/web.config"
|
||||
|
||||
pass="${UPLOAD_PASS:-all}"
|
||||
case "$pass" in
|
||||
all | 1 | 2 | 3) ;;
|
||||
*) echo "Ongeldige UPLOAD_PASS: '$pass'" >&2; exit 2 ;;
|
||||
esac
|
||||
wants() { [ "$pass" = all ] || [ "$pass" = "$1" ]; }
|
||||
|
||||
settings="set ftp:ssl-force true; set ftp:ssl-protect-data true; set net:max-retries 3;"
|
||||
|
||||
# Elke opdracht krijgt een eigen lftp-sessie, zodat het script bij een mislukte
|
||||
# ronde stopt (set -e) voordat de volgende ronde begint: de HTML gaat nooit
|
||||
# omhoog na een mislukte asset-ronde (FR-PR-18).
|
||||
run_lftp() {
|
||||
local commands="$settings $1 quit"
|
||||
if [ -n "${LFTP_OPEN:-}" ]; then
|
||||
lftp -e "$commands" "$LFTP_OPEN"
|
||||
else
|
||||
: "${FTP_HOST:?FTP_HOST ontbreekt}" "${FTP_USER:?FTP_USER ontbreekt}"
|
||||
: "${LFTP_PASSWORD:?LFTP_PASSWORD ontbreekt}"
|
||||
lftp --env-password -u "$FTP_USER" "$FTP_HOST" -e "$commands"
|
||||
fi
|
||||
}
|
||||
|
||||
# Ronde 1: alles behalve HTML en web.config, dus ook /assets. Nieuwe
|
||||
# bestanden met hash in de naam storen de oude release niet.
|
||||
if wants 1; then
|
||||
echo "== Ronde 1: alles behalve HTML en web.config"
|
||||
run_lftp "mirror --reverse --verbose --exclude-glob '*.html' --exclude-glob web.config $dist/ $remote/;"
|
||||
fi
|
||||
# Ronde 2: web.config vlak voor de HTML (de regels passen bij de nieuwe
|
||||
# bestanden), dan alle HTML, ook de geneste pagina's en 404.html. Pas nu
|
||||
# verwijst iets naar de nieuwe assets.
|
||||
if wants 2; then
|
||||
echo "== Ronde 2: web.config en alle HTML"
|
||||
run_lftp "put -O $remote $dist/web.config;"
|
||||
run_lftp "mirror --reverse --verbose --include-glob '*.html' $dist/ $remote/;"
|
||||
fi
|
||||
# Ronde 3: opruimen als laatste, zodat bezoekers met de oude HTML hun oude
|
||||
# assets nog vinden tot de nieuwe HTML helemaal staat.
|
||||
if wants 3; then
|
||||
echo "== Ronde 3: oude bestanden opruimen"
|
||||
run_lftp "mirror --reverse --delete --verbose $dist/ $remote/;"
|
||||
fi
|
||||
|
||||
valid_path() {
|
||||
local value="$1" segment
|
||||
[[ "$value" =~ $safe ]] || return 1
|
||||
[[ "$value" != -* ]] || return 1
|
||||
# Het eerste segment van een absoluut pad is leeg; dat is toegestaan
|
||||
for segment in ${value#/}; do :; done
|
||||
local rest="${value#/}" IFS=/
|
||||
for segment in $rest; do
|
||||
case "$segment" in '' | . | ..) return 1 ;; esac
|
||||
done
|
||||
}
|
||||
for value in "$dist" "$remote"; do
|
||||
if ! valid_path "$value"; then
|
||||
echo "Ongeldig pad: '$value'" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
@@ -49,8 +49,13 @@ fetch() {
|
||||
shift
|
||||
: > "$work/headers"
|
||||
: > "$work/body"
|
||||
status="$(curl -sS --max-time 30 -o "$work/body" -D "$work/headers" \
|
||||
-w '%{http_code}' "$@" "$base$path")"
|
||||
# Geen verbinding of antwoord telt als fout; het script loopt door tot de
|
||||
# samenvatting in plaats van af te breken
|
||||
if ! status="$(curl -sS --max-time 30 -o "$work/body" -D "$work/headers" \
|
||||
-w '%{http_code}' "$@" "$base$path")"; then
|
||||
status="000"
|
||||
fail "$path: geen antwoord van de server (curl faalde)"
|
||||
fi
|
||||
}
|
||||
|
||||
# Waarde van een header uit de laatst opgehaalde respons (hoofdletterongevoelig)
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
} from 'node:http';
|
||||
import type { AddressInfo } from 'node:net';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { dirname, join, resolve } from 'node:path';
|
||||
import { basename, delimiter, dirname, join, resolve } from 'node:path';
|
||||
import { gzipSync } from 'node:zlib';
|
||||
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
||||
import { startPreviewServer } from '../config/previewServer.ts';
|
||||
@@ -81,12 +81,17 @@ function runScript(
|
||||
script: string,
|
||||
args: string[],
|
||||
env: Record<string, string> = {},
|
||||
cwd?: string,
|
||||
): Promise<Run> {
|
||||
return new Promise((done) => {
|
||||
execFile(
|
||||
bashBin ?? 'bash',
|
||||
[`${deployDir}/${script}`, ...args],
|
||||
{ env: { ...process.env, ...env }, maxBuffer: 16 * 1024 * 1024 },
|
||||
{
|
||||
cwd,
|
||||
env: { ...process.env, ...env },
|
||||
maxBuffer: 16 * 1024 * 1024,
|
||||
},
|
||||
(error, stdout, stderr) =>
|
||||
done({
|
||||
code: error ? Number(error.code ?? 1) : 0,
|
||||
@@ -195,6 +200,8 @@ interface StubOptions {
|
||||
omitHeader?: string;
|
||||
gzip?: boolean;
|
||||
robots?: boolean;
|
||||
// Pad waarvan de verbinding wordt verbroken, zonder antwoord
|
||||
drop?: string;
|
||||
}
|
||||
|
||||
async function startStub(
|
||||
@@ -240,6 +247,10 @@ async function startStub(
|
||||
|
||||
const server: Server = createServer((request, response) => {
|
||||
const path = (request.url ?? '/').split('?')[0];
|
||||
if (path === options.drop) {
|
||||
request.socket.destroy();
|
||||
return;
|
||||
}
|
||||
void (async () => {
|
||||
if (options.behaviour === 'old') {
|
||||
// Oude nginx: bestaand bestand, anders de homepage met 200
|
||||
@@ -418,6 +429,23 @@ describe.skipIf(toolsMissing)('verify-deployment.sh', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('telt een verbroken verbinding als fout en eindigt met de samenvatting', async () => {
|
||||
await withStub(
|
||||
{ behaviour: 'new', drop: '/over-mij' },
|
||||
async (origin) => {
|
||||
const run = await runScript('verify-deployment.sh', [
|
||||
origin,
|
||||
dist,
|
||||
]);
|
||||
expect(run.code).toBe(1);
|
||||
expect(run.stderr).toContain(
|
||||
'/over-mij: geen antwoord van de server',
|
||||
);
|
||||
expect(run.stderr).toContain('Controle mislukt');
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it.each(['', 'ftp://example.nl', 'http://a b', 'example.nl'])(
|
||||
'weigert de ongeldige URL %j',
|
||||
async (url) => {
|
||||
@@ -529,3 +557,89 @@ describe.skipIf(toolsMissing || lftpMissing)('upload-production.sh', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// Pad-controle van upload-production.sh: een nep-lftp laat zien of er iets
|
||||
// gestart is. Ronde 3 verwijdert, dus '.' of '..' als doel mag nooit door.
|
||||
describe.skipIf(toolsMissing)('upload-production.sh (padcontrole)', () => {
|
||||
async function withFakeLftp<T>(
|
||||
action: (env: Record<string, string>, marker: string) => Promise<T>,
|
||||
) {
|
||||
const bin = await makeTemp('andreaslop-fakebin-');
|
||||
const marker = join(bin, 'gestart');
|
||||
await writeFile(
|
||||
join(bin, 'lftp'),
|
||||
`#!/bin/sh
|
||||
touch '${slash(marker)}'
|
||||
`,
|
||||
{ mode: 0o755 },
|
||||
);
|
||||
return action(
|
||||
{
|
||||
PATH: `${bin}${delimiter}${process.env.PATH ?? ''}`,
|
||||
LFTP_OPEN: 'file:///',
|
||||
},
|
||||
marker,
|
||||
);
|
||||
}
|
||||
|
||||
it.each([
|
||||
'.',
|
||||
'..',
|
||||
'../x',
|
||||
'a/../b',
|
||||
'./x',
|
||||
'a/./b',
|
||||
'-x',
|
||||
'',
|
||||
'/',
|
||||
'a//b',
|
||||
])('weigert de doelmap %j en start niets', async (remote) => {
|
||||
const dist = await makeDist();
|
||||
await withFakeLftp(async (env, marker) => {
|
||||
const run = await runScript(
|
||||
'upload-production.sh',
|
||||
[slash(dist), remote],
|
||||
env,
|
||||
);
|
||||
expect(run.code).toBe(2);
|
||||
expect(run.stderr).toContain('Ongeldig pad');
|
||||
expect(existsSync(marker)).toBe(false);
|
||||
});
|
||||
expect(existsSync(join(dist, 'web.config'))).toBe(false);
|
||||
});
|
||||
|
||||
it.each(['.', '..', '-d', 'a/../dist'])(
|
||||
'weigert de dist-map %j en start niets',
|
||||
async (dist) => {
|
||||
await withFakeLftp(async (env, marker) => {
|
||||
const run = await runScript(
|
||||
'upload-production.sh',
|
||||
[dist, 'wwwroot'],
|
||||
env,
|
||||
);
|
||||
expect(run.code).toBe(2);
|
||||
expect(run.stderr).toContain('Ongeldig pad');
|
||||
expect(existsSync(marker)).toBe(false);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it.each(['wwwroot', 'sites/andreaslop.nl', '/srv/site', 'wwwroot/'])(
|
||||
'laat de doelmap %j door',
|
||||
async (remote) => {
|
||||
const dist = await makeDist();
|
||||
await withFakeLftp(async (env, marker) => {
|
||||
// Relatief aan de map erboven: een Windows-pad met een
|
||||
// stationsletter haalt de padcontrole niet
|
||||
const run = await runScript(
|
||||
'upload-production.sh',
|
||||
[basename(dist), remote],
|
||||
env,
|
||||
dirname(dist),
|
||||
);
|
||||
expect(run.code).toBe(0);
|
||||
expect(existsSync(marker)).toBe(true);
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@ import { afterEach, vi } from 'vitest';
|
||||
// breakpoint hooks (min-width queries) and prefers-reduced-motion behave as
|
||||
// in a browser. jsdom has no layout and ignores @media rules, so the
|
||||
// responsive display of the desktop list and the mobile menu is applied by a
|
||||
// style element here (the browser check is Step 17). The stub is undone by
|
||||
// style element here (the browser tests in e2e/ check the real layout). The stub is undone by
|
||||
// vi.restoreAllMocks() in the global afterEach.
|
||||
const styleId = 'nav-viewport-style';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user