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
make an unmounted asset directory fail a test instead of 404ing silently (#4688)
[._.]/ Adam Eivyad4110902feb
diff --git a/server/lib/assetMounts.js b/server/lib/assetMounts.jsindex 75f07a6f9c..02cd40e0e3 100644--- a/server/lib/assetMounts.js+++ b/server/lib/assetMounts.js@@ -6,10 +6,9 @@* out inline, so nothing could enumerate what was served without regexing the* source. This is the `server/lib/navManifest.js` pattern the root CLAUDE.md* recommends for exactly that drift problem: one table, iterated by the thing- * that mounts and read as data by the guards. The route strings themselves live- * one level down in `assetRoutePrefixes.js`, an import-free leaf that- * `client/vite.config.js` also reads — that is what keeps the dev proxy from- * falling behind the mounts.+ * that mounts and read as data by the guard. The route strings themselves live+ * one level down in `assetRoutePrefixes.js`, alongside the namespaces the+ * terminator closes, so a new server prefix is one edit rather than two.** `dir` is a thunk, not a string: `wrWorksDir()` derives its path at call time,* and a test that re-roots `PATHS.data` at a temp tree needs every entry to@@ -38,8 +37,9 @@ const writersRoomDraftBodiesOnly = (req, res, next) => {next();};-// Keyed by route so the mount order stays owned by `ASSET_ROUTE_PREFIXES` — the-// list `client/vite.config.js` reads — rather than being restated here.+// Keyed by route so the mount ORDER stays owned by `ASSET_ROUTE_PREFIXES` rather+// than being restated here. A key present here but missing there would never be+// mounted at all — silently — so `assetMounts.test.js` pins the two together.const ASSET_DIRS = {'/data/images': () => PATHS.images,// Reference images (multi-ref upload inputs + generated character reference@@ -76,6 +76,11 @@ const ASSET_DIRS = {const ASSET_GATES = { '/data/writers-room/works': writersRoomDraftBodiesOnly };+/** The routes `ASSET_DIRS` knows a directory for — exported so a key that never+ * reaches `ASSET_ROUTE_PREFIXES` (and is therefore never mounted) fails a test+ * instead of silently not being served. */+export const ASSET_DIR_ROUTES = Object.keys(ASSET_DIRS);+/** Every asset mount as `{ route, dir, gate? }`, in mount order. */export const ASSET_MOUNTS = ASSET_ROUTE_PREFIXES.map((route) => ({route,diff --git a/server/lib/assetMounts.test.js b/server/lib/assetMounts.test.jsindex 5db216c249..f49ffd026c 100644--- a/server/lib/assetMounts.test.js+++ b/server/lib/assetMounts.test.js@@ -31,7 +31,7 @@ afterAll(() => rmSync(tempRoot, { recursive: true, force: true }));// Dynamic, not a static import: the `vi.mock` factory above closes over// `tempRoot`, and a static import would be hoisted above that binding.-const { ASSET_MOUNTS, mountAssetRoutes } = await import('./assetMounts.js');+const { ASSET_DIR_ROUTES, ASSET_MOUNTS, mountAssetRoutes } = await import('./assetMounts.js');// Stand-in for the SPA fallback `server/index.js` installs after the asset// mounts — same extension guard, so the test exercises the real interaction@@ -126,4 +126,13 @@ describe('ASSET_MOUNTS', () => {expect(ASSET_MOUNTS.length).toBeGreaterThan(5);expect(ASSET_MOUNTS.filter(({ route }) => !route.startsWith('/data/'))).toEqual([]);});++ it('mounts every route it knows a directory for', () => {+ // The mount list is built by walking `ASSET_ROUTE_PREFIXES`, so a directory+ // added to `ASSET_DIRS` alone is never mounted and nothing else notices —+ // the asset just 404s. (The reverse fails loudly: a prefix with no dir+ // throws at boot.)+ expect([...ASSET_DIR_ROUTES].sort()).toEqual([...ASSET_MOUNTS.map((m) => m.route)].sort());+ expect(ASSET_MOUNTS.every(({ dir }) => typeof dir === 'function')).toBe(true);+ });});