import test from 'node:test'; import assert from 'node:assert/strict'; import {readFile} from 'node:fs/promises'; import {LocalD1} from './d1-adapter.mjs'; import {createPanel} from '../control-panel/server.mjs'; import {NATIVE_SERVICES,nativeServiceAccess} from '../control-panel/public/cp-v2/cp-v2-native-services.mjs'; test('actual CP router serves the dedicated clan page and assets without requiring the full CP shell',async()=>{ const db=new LocalD1(),app=createPanel(db); try{ for(const [file,mime]of [['clan-center.html','text/html'],['clan-center-entry.mjs','javascript'],['clan-center.css','text/css']]){ const response=await app(new Request('https://cp.dunerealms.com/'+file));assert.equal(response.status,200,file);assert.ok(response.headers.get('content-type').includes(mime)); if(file.endsWith('.html')){const html=await response.text();assert.match(html,/id="dashboard"/);assert.doesNotMatch(html,/v2\/v2\.js|src="\/panel\.js"|id="portals"/);} } }finally{db.close();} }); test('clan portal and User navigation target the isolated functional clan workspace',async()=>{ const spec=NATIVE_SERVICES.clans;assert.equal(spec.url,'https://cp.dunerealms.com/clan-center.html#clans');assert.equal(spec.selfResize,true); assert.equal(nativeServiceAccess({permissions:['web.menu.game']},spec),true);assert.equal(nativeServiceAccess({permissions:[]},spec),false); const html=await readFile(new URL('../ops/clan-center-index.html',import.meta.url),'utf8');assert.match(html,/src="https:\/\/cp\.dunerealms\.com\/clan-cp#clan\/clan-overview"/);assert.doesNotMatch(html,/\?embedded=1#clans/); }); test('Clan CP retains shared workspace routes without duplicated public chrome',async()=>{ const {workspacesForSurface}=await import('../control-panel/public/cp-v2/cp-v2-surface.mjs'); const source=await readFile(new URL('../control-panel/public/cp-v2/v2.js',import.meta.url),'utf8'),menu=JSON.parse(source.slice(source.indexOf('=')+1,source.indexOf(';'))); assert.deepEqual(workspacesForSurface(menu.workspaces,true).map(w=>w.id),['clan','quests','kits','events']); assert.deepEqual(workspacesForSurface(menu.workspaces,false).map(w=>w.id),['realm','bureau','forge','post','bank','market','quests','events']); const db=new LocalD1(),app=createPanel(db);try{ const res=await app(new Request('https://cp.dunerealms.com/clan-cp'));assert.equal(res.status,200);const html=await res.text();assert.match(html,/data-cp-mode="clan"/);assert.doesNotMatch(html,/class="command-banner"/);assert.match(html,/cp-v2-clan-shell.css/);assert.match(html,/id="sidebar-right"/);assert.doesNotMatch(html,/class="dune-site-header"|portal-navigation.js|class="site-footer"/); assert.equal((await app(new Request('https://cp.dunerealms.com/clan-cp',{method:'POST'}))).status,405); assert.equal((await app(new Request('https://cp.dunerealms.com/v2/cp-v2-clan-size.mjs'))).status,200); }finally{db.close();} });