import test from 'node:test';import assert from 'node:assert/strict'; import {createPanel} from '../control-panel/server.mjs'; import {LocalD1} from './d1-adapter.mjs'; test('quest and organisation browser import graphs are served through the real CP asset routes',async()=>{ const db=new LocalD1(),app=createPanel(db),origin='https://cp.dunerealms.com',seen=new Set(),queue=['/proclamations-view.mjs','/v2/cp-v2-item-register.mjs','/v2/cp-v2-progression.mjs','/v2/cp-v2-organisation-shell.mjs','/v2/cp-v2-play-workspaces.mjs','/v2/cp-v2-exchange-design.mjs']; try{while(queue.length){const path=queue.shift();if(seen.has(path))continue;seen.add(path);assert(seen.size<400,'Unexpectedly unbounded browser module graph'); const response=await app(new Request(origin+path));assert.equal(response.status,200,path);assert.match(response.headers.get('content-type')||'',/javascript/,path);const source=await response.text(); for(const match of source.matchAll(/\b(?:from\s*|import\s*(?:\(\s*)?)['"]([^'"]+)['"]/g)){ const spec=match[1];if(!spec.startsWith('.'))continue;const url=new URL(spec,origin+path);if(url.origin===origin&&/\.(?:mjs|js)$/.test(url.pathname))queue.push(url.pathname); } } assert(seen.has('/political-decision-policy.mjs'));assert(seen.has('/action-cooldown-policy.mjs'));assert(seen.has('/faith-pol-policy.mjs')); for(const path of ['/action-cooldown-policy.mjs','/faith-pol-policy.mjs']){const head=await app(new Request(origin+path,{method:'HEAD'}));assert.equal(head.status,200);assert.equal(await head.text(),'');} const theme=await app(new Request(origin+'/v2/faith-theme.css'));assert.equal(theme.status,200);assert.match(await theme.text(),/new-faith/); for(const path of ['/not-a-public-module.mjs','/node/progression-runtime.mjs'])assert.equal((await app(new Request(origin+path))).status,404); }finally{db.close();} });