Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
feat: self-host Inter and IBM Plex Mono so themed typography survives an offline install (#3812)
[._.]/ Adam Eivy5f72b1c9be4f
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 3fb82db8f6..3c662a0b3e 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -98,3 +98,4 @@- **A fresh install's prompt migrations stopped silently skipping the character-foundation upgrades they exist to apply.** Several stage prompts are targeted by more than one hash-driven migration, and each one names the body it expects to end at. When later migrations re-shipped `pipeline-character-foundation.md`, `pipeline-judge-foundation.md`, and `universe-character-expand.md`, the earlier migrations that also target those files were left naming the superseded body as current — so on a fresh install they saw today's shipped prompt, classified it as "customized by the user", and skipped rather than upgraded: exactly the silent no-op the drift assertions exist to catch, and the reason the migration suites were failing on `main`. Migrations 027, 171, 240, 241, 243, 248, and 255 now point at the live bodies and carry every superseded hash in their accepted-old sets, so an install stopped at any intermediate body still upgrades. A new repo-wide guard sweeps every numbered migration against `data.reference` in one pass — including migrations that ship no test of their own — and fails with the full list of stale entries, so the next prompt edit that strands its predecessors names them all at once instead of hiding until CI turns red.- **A server test run no longer drops fixture directories into the checkout.** Three AI-toolkit suites rooted their scratch directories at `process.cwd()` (`server/test-data`, `server/test-data-status`, `server/test-data-cli-resolve`), and their `afterEach` cleanup only ran when the worker survived the file — so a timed-out or killed worker left untracked cruft behind, one `git add -A` away from an unrelated commit (it reached a claim branch once). They now allocate a per-test temp directory under the OS temp dir, and the test-isolation guard grew a companion rule so a cwd-rooted fixture path fails the suite rather than the next `git status`. Reading cwd as a value — handing the checkout to code under test — stays legal.- **A prompt change that skips the drift baseline no longer reddens `main` with an unreadable failure.** The stage-drift baseline is a deliberately independent hand-mirror of what the migrations export, so a prompt migration that ships a new body without carrying the baseline with it breaks a required check for every open PR — and the deep-equal it broke on reported only `expected { …(28) } to deeply equal { …(28) }`, which reads as the PR's own regression rather than an inherited one (three PRs were triaged past it before it was traced to `main`). The baseline now names the three stage prompts whose hashes moved, and the assertion reports the drifted files with their before/after hashes plus the fix to apply. The mirror stays hand-maintained on purpose: deriving it from the migrations' own exports would make it agree with them by construction and delete the guard.+- **PortOS now renders its intended typography with no route to the public internet, because the fonts ship with it.** #3808 stopped the app shell's Google Fonts stylesheet from blanking the page for ~60s on an install that can't reach Google, by loading it non-blocking — but non-blocking only meant the fonts failed *quietly*. They still never arrived, and this turned out to be broader than that fix assumed: four theme stacks in `themes/portosThemes.js` front Inter and one fronts IBM Plex Mono, so on the private-Tailscale deployment PortOS is designed for, five themes silently rendered in a system fallback and the typography was simply never seen. Both families are now vendored under `client/public/fonts/` as `woff2` and declared with `@font-face` in `client/src/index.css`, exactly as `GeistPixel-*` already was for CyberCity — scoped to the weights the stacks actually use (Inter 400/500/600/700, IBM Plex Mono 400/500/600) to keep the whole addition near 275KB. Both are SIL Open Font License 1.1, so each family's license text ships beside the files. The stylesheet `<link>`, its `<noscript>` fallback, and both `preconnect` hints are gone from `client/index.html`, which removes a third-party request from every boot; the service worker's dedicated cache for the Google font hosts went with them, since same-origin `/fonts/` was already covered by its static-asset path, and dropping it from the current-cache set means the stale one is deleted on activate. Verified in a headless browser against the built client with every external host blocked: all seven faces load, they measure differently from their fallbacks, and the page attempts zero external requests.diff --git a/client/index.html b/client/index.htmlindex 9d84344ee6..afb3fcc33a 100644--- a/client/index.html+++ b/client/index.html@@ -10,38 +10,14 @@<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" /><link rel="manifest" href="/manifest.json" /><meta name="theme-color" content="#01051F" />- <link rel="preconnect" href="https://fonts.googleapis.com" />- <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />- <!-- Webfonts load NON-render-blocking. Only the `lumen-glass-day` theme puts- Inter / IBM Plex Mono at the front of its font stack, and every stack in- portosThemes.js falls back to system fonts — so these are a progressive- enhancement, never a boot dependency.-- A plain `<link rel="stylesheet">` here is render-blocking against a- THIRD-PARTY host, which is the wrong trade for PortOS: an install runs on- a private Tailscale network and is expected to work with no route to the- public internet (that is the whole point of the offline app-shell service- worker in public/sw.js). When fonts.googleapis.com is unreachable — no- WAN, a DNS sinkhole, an outbound firewall — the browser holds rendering- until the request times out, so the app is a blank white page for ~60s on- EVERY load, service worker or not.-- `media="print"` makes the stylesheet non-matching, so it downloads- without blocking the first paint; `onload` flips it to `all` to apply it- once it actually arrives. If it never arrives, nothing is delayed and the- system-font fallback stands. -->- <link- rel="stylesheet"- href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap"- media="print"- onload="this.media='all'; this.onload=null;"- />- <noscript>- <link- rel="stylesheet"- href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap"- />- </noscript>+ <!-- No webfont <link> here, deliberately. Inter and IBM Plex Mono are+ SELF-HOSTED from /fonts/ and declared with @font-face in src/index.css+ (same as GeistPixel for CyberCity). A PortOS install runs on a private+ Tailscale network with no assumed route to the public internet, so a+ font pulled from a public CDN simply never arrives and four theme+ stacks silently fall back to system fonts. Same-origin fonts are served+ by the install itself, so the intended typography renders with zero WAN+ — and every boot drops a third-party request. See #3812. --></head><body><div id="root"></div>diff --git a/client/public/fonts/IBMPlexMono-Medium.woff2 b/client/public/fonts/IBMPlexMono-Medium.woff2new file mode 100644index 0000000000..a6add261f6Binary files /dev/null and b/client/public/fonts/IBMPlexMono-Medium.woff2 differdiff --git a/client/public/fonts/IBMPlexMono-OFL.txt b/client/public/fonts/IBMPlexMono-OFL.txtnew file mode 100644index 0000000000..01497cc60d--- /dev/null+++ b/client/public/fonts/IBMPlexMono-OFL.txt@@ -0,0 +1,93 @@+Copyright © 2017 IBM Corp. with Reserved Font Name "Plex"++This Font Software is licensed under the SIL Open Font License, Version 1.1.++This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL+++-----------------------------------------------------------+SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007+-----------------------------------------------------------++PREAMBLE+The goals of the Open Font License (OFL) are to stimulate worldwide+development of collaborative font projects, to support the font creation+efforts of academic and linguistic communities, and to provide a free and+open framework in which fonts may be shared and improved in partnership+with others.++The OFL allows the licensed fonts to be used, studied, modified and+redistributed freely as long as they are not sold by themselves. The+fonts, including any derivative works, can be bundled, embedded,+redistributed and/or sold with any software provided that any reserved+names are not used by derivative works. The fonts and derivatives,+however, cannot be released under any other type of license. The+requirement for fonts to remain under this license does not apply+to any document created using the fonts or their derivatives.++DEFINITIONS+"Font Software" refers to the set of files released by the Copyright+Holder(s) under this license and clearly marked as such. This may+include source files, build scripts and documentation.++"Reserved Font Name" refers to any names specified as such after the+copyright statement(s).++"Original Version" refers to the collection of Font Software components as+distributed by the Copyright Holder(s).++"Modified Version" refers to any derivative made by adding to, deleting,+or substituting -- in part or in whole -- any of the components of the+Original Version, by changing formats or by porting the Font Software to a+new environment.++"Author" refers to any designer, engineer, programmer, technical+writer or other person who contributed to the Font Software.++PERMISSION & CONDITIONS+Permission is hereby granted, free of charge, to any person obtaining+a copy of the Font Software, to use, study, copy, merge, embed, modify,+redistribute, and sell modified and unmodified copies of the Font+Software, subject to the following conditions:++1) Neither the Font Software nor any of its individual components,+in Original or Modified Versions, may be sold by itself.++2) Original or Modified Versions of the Font Software may be bundled,+redistributed and/or sold with any software, provided that each copy+contains the above copyright notice and this license. These can be+included either as stand-alone text files, human-readable headers or+in the appropriate machine-readable metadata fields within text or+binary files as long as those fields can be easily viewed by the user.++3) No Modified Version of the Font Software may use the Reserved Font+Name(s) unless explicit written permission is granted by the corresponding+Copyright Holder. This restriction only applies to the primary font name as+presented to the users.++4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font+Software shall not be used to promote, endorse or advertise any+Modified Version, except to acknowledge the contribution(s) of the+Copyright Holder(s) and the Author(s) or with their explicit written+permission.++5) The Font Software, modified or unmodified, in part or in whole,+must be distributed entirely under this license, and must not be+distributed under any other license. The requirement for fonts to+remain under this license does not apply to any document created+using the Font Software.++TERMINATION+This license becomes null and void if any of the above conditions are+not met.++DISCLAIMER+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL+DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM+OTHER DEALINGS IN THE FONT SOFTWARE.diff --git a/client/public/fonts/IBMPlexMono-Regular.woff2 b/client/public/fonts/IBMPlexMono-Regular.woff2new file mode 100644index 0000000000..996cdc014bBinary files /dev/null and b/client/public/fonts/IBMPlexMono-Regular.woff2 differdiff --git a/client/public/fonts/IBMPlexMono-SemiBold.woff2 b/client/public/fonts/IBMPlexMono-SemiBold.woff2new file mode 100644index 0000000000..806963880aBinary files /dev/null and b/client/public/fonts/IBMPlexMono-SemiBold.woff2 differdiff --git a/client/public/fonts/Inter-Bold.woff2 b/client/public/fonts/Inter-Bold.woff2new file mode 100644index 0000000000..3f4272df35Binary files /dev/null and b/client/public/fonts/Inter-Bold.woff2 differdiff --git a/client/public/fonts/Inter-Medium.woff2 b/client/public/fonts/Inter-Medium.woff2new file mode 100644index 0000000000..24ccc514b4Binary files /dev/null and b/client/public/fonts/Inter-Medium.woff2 differdiff --git a/client/public/fonts/Inter-OFL.txt b/client/public/fonts/Inter-OFL.txtnew file mode 100644index 0000000000..21f6aff961--- /dev/null+++ b/client/public/fonts/Inter-OFL.txt@@ -0,0 +1,93 @@+Copyright 2020 The Inter Project Authors (https://github.com/rsms/inter)++This Font Software is licensed under the SIL Open Font License, Version 1.1.+This license is copied below, and is also available with a FAQ at:+https://scripts.sil.org/OFL+++-----------------------------------------------------------+SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007+-----------------------------------------------------------++PREAMBLE+The goals of the Open Font License (OFL) are to stimulate worldwide+development of collaborative font projects, to support the font creation+efforts of academic and linguistic communities, and to provide a free and+open framework in which fonts may be shared and improved in partnership+with others.++The OFL allows the licensed fonts to be used, studied, modified and+redistributed freely as long as they are not sold by themselves. The+fonts, including any derivative works, can be bundled, embedded,+redistributed and/or sold with any software provided that any reserved+names are not used by derivative works. The fonts and derivatives,+however, cannot be released under any other type of license. The+requirement for fonts to remain under this license does not apply+to any document created using the fonts or their derivatives.++DEFINITIONS+"Font Software" refers to the set of files released by the Copyright+Holder(s) under this license and clearly marked as such. This may+include source files, build scripts and documentation.++"Reserved Font Name" refers to any names specified as such after the+copyright statement(s).++"Original Version" refers to the collection of Font Software components as+distributed by the Copyright Holder(s).++"Modified Version" refers to any derivative made by adding to, deleting,+or substituting -- in part or in whole -- any of the components of the+Original Version, by changing formats or by porting the Font Software to a+new environment.++"Author" refers to any designer, engineer, programmer, technical+writer or other person who contributed to the Font Software.++PERMISSION & CONDITIONS+Permission is hereby granted, free of charge, to any person obtaining+a copy of the Font Software, to use, study, copy, merge, embed, modify,+redistribute, and sell modified and unmodified copies of the Font+Software, subject to the following conditions:++1) Neither the Font Software nor any of its individual components,+in Original or Modified Versions, may be sold by itself.++2) Original or Modified Versions of the Font Software may be bundled,+redistributed and/or sold with any software, provided that each copy+contains the above copyright notice and this license. These can be+included either as stand-alone text files, human-readable headers or+in the appropriate machine-readable metadata fields within text or+binary files as long as those fields can be easily viewed by the user.++3) No Modified Version of the Font Software may use the Reserved Font+Name(s) unless explicit written permission is granted by the corresponding+Copyright Holder. This restriction only applies to the primary font name as+presented to the users.++4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font+Software shall not be used to promote, endorse or advertise any+Modified Version, except to acknowledge the contribution(s) of the+Copyright Holder(s) and the Author(s) or with their explicit written+permission.++5) The Font Software, modified or unmodified, in part or in whole,+must be distributed entirely under this license, and must not be+distributed under any other license. The requirement for fonts to+remain under this license does not apply to any document created+using the Font Software.++TERMINATION+This license becomes null and void if any of the above conditions are+not met.++DISCLAIMER+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL+DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM+OTHER DEALINGS IN THE FONT SOFTWARE.diff --git a/client/public/fonts/Inter-Regular.woff2 b/client/public/fonts/Inter-Regular.woff2new file mode 100644index 0000000000..70dd51eb57Binary files /dev/null and b/client/public/fonts/Inter-Regular.woff2 differdiff --git a/client/public/fonts/Inter-SemiBold.woff2 b/client/public/fonts/Inter-SemiBold.woff2new file mode 100644index 0000000000..283b13a7e0Binary files /dev/null and b/client/public/fonts/Inter-SemiBold.woff2 differdiff --git a/client/public/sw.js b/client/public/sw.jsindex 1f56d54fa1..93c188b26e 100644--- a/client/public/sw.js+++ b/client/public/sw.js@@ -49,9 +49,13 @@ const CACHE_VERSION = 'v1';const SHELL_CACHE = `portos-shell-${CACHE_VERSION}`;const ASSET_CACHE = `portos-assets-${CACHE_VERSION}`;const STATIC_CACHE = `portos-static-${CACHE_VERSION}`;-const FONT_CACHE = `portos-fonts-${CACHE_VERSION}`;-const CURRENT_CACHES = new Set([SHELL_CACHE, ASSET_CACHE, STATIC_CACHE, FONT_CACHE]);+// No font cache: the webfonts are self-hosted under /fonts/ (see+// src/index.css), so they are same-origin and already covered by+// STATIC_PATH_RE below. The old `portos-fonts-*` cache existed only for the+// public font CDN this no longer talks to; leaving it out of CURRENT_CACHES+// means the activate-time cleanup deletes whatever is left in it.+const CURRENT_CACHES = new Set([SHELL_CACHE, ASSET_CACHE, STATIC_CACHE]);// Stable key the offline shell is stored under, independent of the request URL// (every SPA navigation resolves to the same index.html on the server).@@ -109,11 +113,6 @@ const ASSET_CACHE_MAX_ENTRIES = 120;const STATIC_PATH_RE = /^\/(fonts|sky)\//;const STATIC_FILE_RE = /^\/(manifest\.json|favicon\.(?:ico|svg)|apple-touch-icon\.png|icon-\d+\.png|portos-logo\.png)$/;-// External font hosts — cache-first is a big low-bandwidth win (Google serves-// these with long max-age already, but the browser HTTP cache is evicted more-// aggressively than a named SW cache).-const FONT_HOSTS = new Set(['fonts.googleapis.com', 'fonts.gstatic.com']);-// Matches the `/assets/...` references (entry chunk + modulepreload deps + CSS)// in the shell HTML. The set these produce is the boot JS/CSS the app can't// start without.@@ -203,16 +202,10 @@ self.addEventListener('fetch', (event) => {return; // Malformed URL — let the browser handle it.}- const isSameOrigin = url.origin === self.location.origin;-- // External font stylesheets + font files: cache-first.- if (FONT_HOSTS.has(url.hostname)) {- event.respondWith(cacheFirst(request, FONT_CACHE));- return;- }-- // Never touch other cross-origin requests.- if (!isSameOrigin) return;+ // Never touch cross-origin requests. Nothing the app loads is cross-origin+ // any more now that the webfonts are self-hosted, so this is a hard bail+ // rather than a branch on the way to one.+ if (url.origin !== self.location.origin) return;// Never cache dynamic / real-time / large-media routes. Let them hit the// network directly (also preserves HTTP Range for /data media).@@ -346,9 +339,10 @@ async function cacheFirst(request, cacheName, maxEntries) {const cached = await cache.match(request);if (cached) return cached;const response = await fetch(request);- // Cache successful basic/opaque responses. Opaque (cross-origin fonts) can't- // be inspected but are safe to store and replay.- if (response && (response.ok || response.type === 'opaque')) {+ // Every caller is same-origin now (the cross-origin font hosts are gone —+ // the webfonts are self-hosted), so responses are always inspectable and+ // `ok` is the whole test; an opaque response can no longer reach here.+ if (response && response.ok) {await cache.put(request, response.clone());if (maxEntries) trimCache(cache, maxEntries);}diff --git a/client/src/index.css b/client/src/index.cssindex 90e3e26c10..e2bae66dd2 100644--- a/client/src/index.css+++ b/client/src/index.css@@ -112,6 +112,80 @@--port-chart-grid: 64 64 64;}+/* Self-hosted UI/mono webfonts.+ *+ * Four theme stacks in themes/portosThemes.js front `Inter`, and one fronts+ * `IBM Plex Mono`. These used to come from fonts.googleapis.com, which never+ * resolves on the private-Tailscale install PortOS is designed for — so the+ * intended typography was simply never seen offline. Vendored under+ * public/fonts/ instead (see #3812), matching the GeistPixel precedent below.+ *+ * Only the weights the stacks actually use are shipped (Inter 400/500/600/700,+ * IBM Plex Mono 400/500/600), woff2 only — every browser PortOS targets+ * supports it. Both families are SIL Open Font License 1.1; each family's+ * license text sits beside the files as public/fonts/<Family>-OFL.txt.+ *+ * Subsetting: latin + latin-ext, the same tradeoff Google's default subset+ * makes, to keep the payload near 275KB total. A character outside that range+ * falls back per-glyph to the next family in the stack (every stack in+ * portosThemes.js ends in a system font), so it degrades rather than tofus.+ */+@font-face {+ font-family: 'Inter';+ src: url('/fonts/Inter-Regular.woff2') format('woff2');+ font-weight: 400;+ font-style: normal;+ font-display: swap;+}++@font-face {+ font-family: 'Inter';+ src: url('/fonts/Inter-Medium.woff2') format('woff2');+ font-weight: 500;+ font-style: normal;+ font-display: swap;+}++@font-face {+ font-family: 'Inter';+ src: url('/fonts/Inter-SemiBold.woff2') format('woff2');+ font-weight: 600;+ font-style: normal;+ font-display: swap;+}++@font-face {+ font-family: 'Inter';+ src: url('/fonts/Inter-Bold.woff2') format('woff2');+ font-weight: 700;+ font-style: normal;+ font-display: swap;+}++@font-face {+ font-family: 'IBM Plex Mono';+ src: url('/fonts/IBMPlexMono-Regular.woff2') format('woff2');+ font-weight: 400;+ font-style: normal;+ font-display: swap;+}++@font-face {+ font-family: 'IBM Plex Mono';+ src: url('/fonts/IBMPlexMono-Medium.woff2') format('woff2');+ font-weight: 500;+ font-style: normal;+ font-display: swap;+}++@font-face {+ font-family: 'IBM Plex Mono';+ src: url('/fonts/IBMPlexMono-SemiBold.woff2') format('woff2');+ font-weight: 600;+ font-style: normal;+ font-display: swap;+}+/* Geist Pixel font for CyberCity */@font-face {font-family: 'GeistPixelSquare';diff --git a/client/src/test/appShell.test.js b/client/src/test/appShell.test.jsindex 8c22bcf872..de840635f3 100644--- a/client/src/test/appShell.test.js+++ b/client/src/test/appShell.test.js@@ -8,22 +8,29 @@* unreachable (no WAN, DNS sinkhole, outbound firewall) the browser holds the* first paint until the request times out, so the app is a blank white page for* ~60s on every load — with or without the service worker, because the SW's own- * `fetch` for the stylesheet hangs the same way.+ * `fetch` for the stylesheet hangs the same way. #3808 fixed that symptom by+ * loading the Google Fonts sheet non-blocking.*- * The webfonts are a progressive enhancement: only the `lumen-glass-day` theme- * puts Inter / IBM Plex Mono at the front of its stack, and every stack in- * `themes/portosThemes.js` falls back to system fonts. So they must load- * non-blocking (`media="print"` + `onload="this.media='all'"`), never as a boot- * dependency.+ * #3812 removed the third-party host entirely: Inter and IBM Plex Mono are now+ * self-hosted under `public/fonts/` and declared with `@font-face` in+ * `src/index.css`. That is what makes the themed typography actually *render*+ * offline rather than merely fail quietly — four stacks in+ * `themes/portosThemes.js` front Inter and one fronts IBM Plex Mono, and a font+ * that never arrives silently degrades every one of them to a system fallback.+ *+ * So these guards cover both halves: the shell must not reach for a font CDN,+ * and every `@font-face` it relies on must resolve to a file that is really in+ * the tree.*/import { describe, it, expect } from 'vitest';-import { readFileSync } from 'fs';+import { existsSync, readFileSync } from 'fs';import { join, dirname } from 'path';import { fileURLToPath } from 'url';const CLIENT_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..', '..');const html = readFileSync(join(CLIENT_ROOT, 'index.html'), 'utf8');+const css = readFileSync(join(CLIENT_ROOT, 'src', 'index.css'), 'utf8');// `<noscript>` content is inert while JS is enabled, so a blocking stylesheet// in there can't stall the app's boot. With JS off the SPA can't render at all,@@ -57,23 +64,87 @@ describe('client/index.html — boot must not depend on a third-party host', ()expect(offenders).toEqual([]);});- it('loads the Google Fonts stylesheet non-blocking and applies it on load', () => {- const fontTag = activeLinkTags.find(- (t) => isStylesheet(t) && (attr(t, 'href') || '').includes('fonts.googleapis.com')- );- // The webfonts are optional — if a future change drops them entirely, the- // guard above still holds and there is nothing left to assert here.- if (!fontTag) return;+ it('references no Google Fonts host at all — not even non-blocking', () => {+ // Non-blocking was the #3808 stopgap; it kept boot fast but left the fonts+ // permanently unreachable offline. Self-hosting made every reference dead,+ // including the `<noscript>` fallback and both `preconnect` hints. Scanned+ // RAW (comments included) — Vite copies HTML comments into dist, so a+ // commented-out `<link>` would ship the hostname to every install and is+ // one uncomment away from regressing.+ expect(html).not.toMatch(/fonts\.googleapis\.com/);+ expect(html).not.toMatch(/fonts\.gstatic\.com/);+ });+});++describe('self-hosted webfonts', () => {+ // Every `url('/fonts/…')` in index.css, in source order.+ const fontUrls = [...css.matchAll(/url\(\s*['"]?(\/fonts\/[^'")]+)['"]?\s*\)/g)].map((m) => m[1]);++ it('resolves every @font-face url to a file that exists in public/', () => {+ expect(fontUrls.length).toBeGreaterThan(0);++ const missing = fontUrls.filter((u) => !existsSync(join(CLIENT_ROOT, 'public', u)));++ expect(missing).toEqual([]);+ });++ it('declares the exact family/weight pairs the theme stacks front', () => {+ // themes/portosThemes.js fronts `Inter` in four `--port-font-ui` stacks and+ // `IBM Plex Mono` in one `--port-font-mono` stack. A weight declared in a+ // stack but missing here gets synthesized by the browser (faux bold), which+ // is the subtle regression this pins.+ const declared = [...css.matchAll(/@font-face\s*\{([^}]*)\}/g)]+ .map((m) => m[1])+ .map((block) => ({+ family: block.match(/font-family:\s*'([^']+)'/)?.[1],+ weight: Number(block.match(/font-weight:\s*(\d+)/)?.[1]),+ }))+ .filter((d) => d.family === 'Inter' || d.family === 'IBM Plex Mono');- expect(attr(fontTag, 'media')).toBe('print');- expect(attr(fontTag, 'onload')).toMatch(/this\.media\s*=\s*'all'/);+ const weightsFor = (family) =>+ declared+ .filter((d) => d.family === family)+ .map((d) => d.weight)+ .sort((a, b) => a - b);++ expect(weightsFor('Inter')).toEqual([400, 500, 600, 700]);+ expect(weightsFor('IBM Plex Mono')).toEqual([400, 500, 600]);});- it('keeps a <noscript> fallback so the webfonts still apply without JS', () => {- const noscript = html.match(/<noscript>(.*?)<\/noscript>/s)?.[1] || '';- const hasFontLink = /<link\b[^>]*fonts\.googleapis\.com/s.test(noscript);- const shellHasFonts = html.includes('fonts.googleapis.com/css2');+ it('uses font-display: swap on every self-hosted face', () => {+ // Without `swap` a face that is slow to load blocks its own text for the+ // browser's block period — the local-server equivalent of the blank-page+ // failure this whole guard file exists for.+ const faces = [...css.matchAll(/@font-face\s*\{([^}]*)\}/g)].map((m) => m[1]);+ const withoutSwap = faces.filter((block) => !/font-display:\s*swap/.test(block));++ expect(withoutSwap).toEqual([]);+ });++ it('ships an OFL license beside each vendored family', () => {+ // Inter and IBM Plex Mono are both SIL Open Font License 1.1, which permits+ // vendoring only with the license text alongside.+ for (const license of ['Inter-OFL.txt', 'IBMPlexMono-OFL.txt']) {+ const path = join(CLIENT_ROOT, 'public', 'fonts', license);+ expect(existsSync(path)).toBe(true);+ expect(readFileSync(path, 'utf8')).toMatch(/SIL OPEN FONT LICENSE/i);+ }+ });+});++describe('client/public/sw.js — no dead font-host caching', () => {+ const sw = readFileSync(join(CLIENT_ROOT, 'public', 'sw.js'), 'utf8');++ it('no longer routes requests to the Google font hosts', () => {+ // `public/sw.js` is copied to dist verbatim, comments and all — same+ // reasoning as the shell above, so this is a raw scan too.+ expect(sw).not.toMatch(/fonts\.googleapis\.com/);+ expect(sw).not.toMatch(/fonts\.gstatic\.com/);+ });- expect(hasFontLink).toBe(shellHasFonts);+ it('still caches same-origin /fonts/ as a static asset', () => {+ // The self-hosted files ride the existing static-asset path, so dropping+ // the dedicated font cache costs nothing offline.+ expect(sw).toMatch(/STATIC_PATH_RE\s*=\s*\/\^\\\/\(fonts\|/);});});