Files
2026-12-01 06:21:47 +11:00

15 KiB
Raw Permalink Blame History

Milestone 6 change note (for QA)

Author: the developer. Scope: PLAN story 10 (self-hosting), DESIGN build-order step 6, and the decisions-log entries for Nginx Proxy Manager, security headers and invisible users in voice. Also adds the "no silent skips" rule from the decisions log (REQUIRE_LIVEKIT) and a 320/375 px pass over the voice UI.

Deliverable

  • npm run package builds dist/doghouse-<version>.zip and a .sha256 file next to it. The zip's single top folder is doghouse-<version>/. It holds:
    • README.md, CHANGES-M6.md and deploy/.
    • The source the image is built from: root package.json, package-lock.json, tsconfig.base.json, .dockerignore, packages/shared, apps/server, apps/web (sources, configs and public/).
    • Never included: node_modules, dist, coverage, *.test.ts, e2e/, qa/, data, .env, .git.
  • Building on the server: Justin runs docker compose up -d --build in deploy/. No prebuilt image and no registry.
  • Zip writer: written in Node, so packaging needs no zip tool. Unix permissions are kept, so docker-entrypoint.sh stays executable.

deploy/

File What
Dockerfile Three stages on node:22-alpine. build: npm ci + npm run build. deps: npm ci --omit=dev --workspace=apps/server, so only the server's production deps are installed, as musl binaries. runtime: the compiled server, shared and web dist, and the prod node_modules. Runs as the node user, uses tini, and has a HEALTHCHECK (wget /api/health)
docker-entrypoint.sh Starts as root only to chown a fresh ./data bind mount (Docker creates it root-owned), then su-exec node. The app never runs as root
docker-compose.yml Project doghouse. doghouse-app is built from .., takes env_file: .env, mounts ./data:/data, and publishes no ports. doghouse-livekit uses the pinned livekit/livekit-server:v1.13.9 image (the version e2e tests against), mounts ./livekit.yaml read-only and publishes 7881/tcp, 50000-50100/udp and 3478/udp. Both containers are on the external network doghouse_net with restart: unless-stopped
livekit.yaml Signal port 7880. RTC: TCP 7881, UDP 50000-50100, use_external_ip: true. TURN: enabled on UDP 3478, TLS off. Webhook to http://doghouse-app:3000/api/livekit/webhook. No keys in the file
.env.example APP_NAME, PUBLIC_URL, LIVEKIT_PUBLIC_URL, LIVEKIT_TURN_DOMAIN, NODE_ENV=production, TRUST_PROXY_HOPS=1, MAX_UPLOAD_MB=25, PRESENCE_GRACE_MS, SESSION_TTL_DAYS, AUTH_RATE_LIMIT_MAX, LOG_LEVEL. LiveKit key and secret are empty, with the command to generate them
npm-advanced.conf Pasted into NPM's Advanced tab: client_max_body_size 30m, and location /livekit/ to doghouse-livekit:7880 (prefix stripped, Upgrade/Connection headers, 86400 s timeouts)
nginx-raw.conf Appendix for plain nginx. A full server block that overwrites X-Forwarded-For/X-Real-IP with $remote_addr and covers /, /ws and /livekit/

How keys reach LiveKit:

  • livekit.yaml can't read env vars, but LiveKit takes every config field from LIVEKIT_* env vars.
  • Compose sets LIVEKIT_KEYS="${LIVEKIT_API_KEY}: ${LIVEKIT_API_SECRET}", LIVEKIT_WEBHOOK_API_KEY=${LIVEKIT_API_KEY} and LIVEKIT_TURN_DOMAIN from .env.
  • With an empty key, compose refuses to start (${LIVEKIT_API_SECRET:?…}), so there are no default keys (TESTPLAN 10).

NPM resolves LiveKit per request: the Advanced block proxies through a variable plus Docker's resolver 127.0.0.11. So NPM still loads its config when doghouse-livekit doesn't exist yet, and that route returns 502 until it does. A literal hostname would make nginx refuse to start.

X-Forwarded-For with NPM: NPM appends to it. With TRUST_PROXY_HOPS=1 the app uses the rightmost entry, which NPM sets from the real connection. Verified (see "Verified here").

App changes

  • Security headers come from the app (apps/server/src/lib/security.ts) and are sent on every response; attachments keep their stricter sandbox CSP. The policy:

    • default-src 'self'; script-src 'self' (no inline, no eval).
    • style-src 'self' 'unsafe-inline': Svelte style attributes and transitions. Styles can't run code.
    • img-src 'self' data: blob:; media-src 'self' blob:; font-src 'self'.
    • connect-src 'self' plus the wss:// and https:// origins of PUBLIC_URL and LIVEKIT_PUBLIC_URL.
    • worker-src 'self' blob:; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'.

    Other headers:

    • X-Content-Type-Options: nosniff.
    • Referrer-Policy: same-origin.
    • Permissions-Policy: microphone=(self), display-capture=(self), fullscreen=(self), autoplay=(self), camera=(), geolocation=(), payment=(), usb=().
    • X-Frame-Options: DENY.
    • Cross-Origin-Opener-Policy: same-origin.
  • CSP fix: zod probed new Function. Zod 4's JIT does this, and the browser logged it as a CSP violation (script-src blocked eval) on every page load. The e2e CSP guard caught it. packages/shared now sets z.config({ jitless: true }). Theme boot was already an external file (/theme-boot.js), and a test asserts index.html has no inline scripts or handlers.

  • MAX_UPLOAD_MB (new, default 25, range 1-1024) is both the default and the ceiling for the upload limit, so the proxy's client_max_body_size always fits.

    • Admins can lower it with PATCH /api/admin/settings. A value above the ceiling gets 400 "at most N MB (MAX_UPLOAD_MB in .env)".
    • Migration 003 drops the old seeded max_upload_mb=25 row so the env value applies.
    • There's no admin UI for this setting; there wasn't one before either.
  • Invisible users in voice (decisions log):

    • They show in that voice channel's participant list (channel list and voice view), which never had presence dots.
    • The member list now keeps them in Offline, not in the "In voice" group. DMs and presence still show them as offline.
    • They disappear from voice as soon as they leave.
    • New test, socket.test.ts, "invisible in voice": a server-mate gets voice:state with them and still no presence. A user in a different server with no DM gets no socket event mentioning them at all (onAny capture), nothing in /api/presence, and 404 on that server's /voice. Leaving empties the channel at once.
  • Responsive fix (320 px): in the channel drawer, a long name next to the LIVE badge pushed the badge past the drawer edge, where it was clipped. The voice-people list now stays inside its row, the name truncates and the flags never shrink.

    • Checked at 320×640 and 375×812 with 3 people in a call and a screen share: voice view, focused share, and the drawer with the voice bar.
    • scrollWidth equals the viewport width and no element extends past the right edge in any of them. Screenshots were reviewed.

Tests and "no silent skips" (decisions log)

  • npm test = scripts/test.mjs:
    • Runs Vitest per workspace, then prints a summary table (files, passed, failed, skipped per suite) and lists every skipped test by name.
    • Prints whether REQUIRE_LIVEKIT was set, and the server coverage figures.
  • New apps/server/test/livekit.integration.test.ts:
    • Starts the real livekit-server binary.
    • Checks the app's real RoomServiceClient calls: the startup rebuild deletes rooms of unknown channels and keeps ours, and a stranger's join leads to a removeParticipant whose 404 is ignored.
    • Deleting a voice channel deletes its room.
  • Without the binary, it is skipped with a warning and listed in the summary.
  • With REQUIRE_LIVEKIT=1, it fails with "REQUIRE_LIVEKIT=1 but no livekit-server binary was found…".
  • e2e: with REQUIRE_LIVEKIT=1 and no binary, e2e/server.mjs exits with a clear error and the run fails. The voice spec also throws instead of skipping if voice turns out to be disabled.
  • LIVEKIT_BIN, if set, is the only path tried. This makes "missing" testable.
  • e2e now runs the production configuration: NODE_ENV=production (strict Origin check) with the full CSP. Every e2e page records securitypolicyviolation events and fails on any. This covers the smoke specs, the realtime spec, and voice with a screen share.
  • npm run validate:deploy (part of npm run check):
    • Parses all the YAML.
    • Validates docker-compose.yml against the official compose-spec JSON schema (vendored as scripts/compose-spec.json) after interpolating .env.example.
    • Enforces the decisions-log rules: container names, no app ports, pinned LiveKit image, exact published ports, external network, volumes, restart policy, no keys in livekit.yaml and empty keys in .env.example, client_max_body_size above MAX_UPLOAD_MB, /livekit/ rewrite plus upgrade headers, XFF overwrite in the raw appendix, and the Dockerfile basics.
    • Checked that it fails when the app publishes a port or the compose file has an unknown key.

Results (all on Node v20.19.2)

REQUIRE_LIVEKIT=1 npm run check at the M6 commit, copied from its summary:

┌─────────┬───────────────────┬───────┬────────┬────────┬─────────┐
│ (index) │ suite             │ files │ passed │ failed │ skipped │
├─────────┼───────────────────┼───────┼────────┼────────┼─────────┤
│ 0       │ 'packages/shared' │ 3     │ 22     │ 0      │ 0       │
│ 1       │ 'apps/server'     │ 14    │ 187    │ 0      │ 0       │
│ 2       │ 'apps/web'        │ 7     │ 205    │ 0      │ 0       │
└─────────┴───────────────────┴───────┴────────┴────────┴─────────┘
Skipped tests: 0
REQUIRE_LIVEKIT=1
Server coverage: statements 98.12%, branches 92.35%, functions 99.29%, lines 99.19%

(The coverage line is Vitest's coverage-summary.json for apps/server, which is the same as the "All files" row.)

About the M5 coverage figure (QA measured 96.6% statements, my M5 report said 97.6%):

  • A fresh cd apps/server && npx vitest run --coverage on a clean checkout of 5c8f45b gives All files | 97.62 | 91.76 | 98.09 | 98.62 (180 tests, 0 skipped).
  • At M5 no server test depended on LiveKit (they all used a fake), so skipping can't explain a 1-point gap then. I couldn't reproduce 96.6%. QA-REPORT records 181 server tests for the QA run against 180 at 5c8f45b, so that tree had something extra (perhaps a local probe test), and that's the likeliest cause. A different Node version (V8 counts coverage slightly differently) is the other candidate.
  • From M6 on, skipping does matter. Without the binary (LIVEKIT_BIN=/nope npx vitest run --coverage) the run shows 186 passed, 1 skipped, and All files | 97.66 | 91.84 | 98.12 | 98.65, because defaultLivekitApi in app.ts (lines 65-72) is then never exercised. So quote coverage from REQUIRE_LIVEKIT=1 runs.

e2e: REQUIRE_LIVEKIT=1 npm run e2e, run twice in full: both times 10 passed, 4 skipped (the multi-user specs only run in the desktop project, by design, including voice), 0 failed. LIVEKIT_BIN=/nope REQUIRE_LIVEKIT=1 fails as intended: [WebServer] e2e: REQUIRE_LIVEKIT=1 but no livekit-server binary was found …, then Process from config.webServer was not able to start. Exit code: 1.

Verified here (no Docker on this machine)

  • Alpine/musl runtime, built from the zip. The zip was unpacked into an Alpine 3.22 root filesystem with Node 22.23.2 and npm 11 (the same musl/Node base as node:22-alpine), run with bwrap. Inside it:
    • The Dockerfile's commands were repeated by hand: npm ci + npm run build, then npm ci --omit=dev --workspace=apps/server, giving 157 packages.
    • sharp loads its musl build (libvips 8.18.7), better-sqlite3 uses its musl prebuild (SQLite 3.53.0) and @node-rs/argon2 hashes with its musl binary. This closes QA's "sharp Alpine build" item, short of the real image.
  • Production stack behind an NPM-like nginx. The production app from that tree (as a non-root uid, NODE_ENV=production) ran behind nginx 1.28 configured like an NPM proxy host (Websockets on, XFF appended, our npm-advanced.conf included). LiveKit 1.13.9 ran with deploy/livekit.yaml, with keys, webhook key and TURN domain passed only through the env vars compose sets. Results:
    • The e2e realtime and voice specs pass through nginx: join, speaking, mute and deafen, screen share received, kick. Webhooks arrive signed with the env-provided key, and there were no CSP violations.
    • Headers are present on every response.
    • The QA-1 spoof check passes: 12 logins with forged X-Forwarded-For values still hit the per-IP limit (10 × 401, then 429).
    • A cross-origin POST gets 403.
    • A 31 MB upload is rejected by nginx with 413 (client_max_body_size 30m).
    • /livekit/ answers OK through the proxy, and 502 (nginx still running) while LiveKit is down.
  • nginx -t passes for nginx-raw.conf (syntax OK; binding to 80/443 isn't possible here without root).
  • The zip passes unzip -t. Its listing contains no node_modules, dist, tests, .env, data or .git, and docker-entrypoint.sh keeps mode 755.

Not verified (needs a machine with Docker; for QA's step 6)

  • docker compose config and a real docker compose build / up. Checks to make there:
    • The image's HEALTHCHECK turns healthy.
    • The entrypoint's chown + su-exec on a fresh ./data.
    • tini signal handling (docker compose stop should be quick).
    • Data survives down && up.
  • The real livekit/livekit-server:v1.13.9 image. It was tested only as the same-version binary. Two things to confirm: its entrypoint accepts --config and generate-keys (README step 4), and use_external_ip: true finds the public IP. On this machine STUN is blocked, and LiveKit then hangs at startup without logging anything. The README's troubleshooting covers this: set node_ip instead.
  • Nginx Proxy Manager itself (only an equivalent nginx config was tested): the Advanced-tab location merging, Let's Encrypt, Force SSL, HTTP/2 and HSTS.
  • TURN relaying from outside, router forwards, and real phones (iOS audio after tapping Join is still a manual item from M5).
  • arm64 (e.g. a Raspberry Pi). Prebuilt musl arm64 packages exist for sharp and argon2, and the Dockerfile includes g++ as a fallback for better-sqlite3, but none of this was tried.

Known gaps / notes

  • The root package.json version is still 0.1.0, so the zip is doghouse-0.1.0.zip. Bump the version before the real release if wanted.
  • npm installs the glibc variants of sharp and argon2 alongside the musl ones. The deps stage deletes them, saving about 19 MB. After that, sharp still encoded a JPEG and argon2 still hashed in the Alpine root filesystem. The runtime node_modules is about 95 MB.