import test from 'node:test';import assert from 'node:assert/strict'; import {LocalD1} from './d1-adapter.mjs'; import {CLAIM_REGISTRY_SCHEMA,seedWebClanClaimLocations,readClaimRegistry,webClanClaimSnapshot} from '../node/claim-registry.mjs'; import {worldGuardChunkCount,worldGuardHomeRegion} from '../node/claim-worldguard.mjs'; const id='11111111-1111-4111-8111-111111111111',other='22222222-2222-4222-8222-222222222222'; test('every active clan receives a persistent location without overwriting later progress',async()=>{ const db=new LocalD1(CLAIM_REGISTRY_SCHEMA+';CREATE TABLE site_clans(id TEXT,name TEXT,home_world TEXT,owner_id TEXT,active INTEGER);CREATE TABLE site_clan_members(clan_id TEXT,user_id TEXT,clan_role TEXT,minecraft_uuid TEXT);CREATE TABLE site_clan_institutions(clan_id TEXT,institution_key TEXT);');try{ for(const [clan,name]of [[id,'First'],[other,'Second']])db.sqlite.prepare('INSERT INTO site_clans VALUES(?,?,?,?,1)').run(clan,name,'kaladam','owner'); db.sqlite.prepare('INSERT INTO site_clan_members VALUES(?,?,?,?)').run(id,'owner','owner',other); assert.equal((await seedWebClanClaimLocations(db,{clock:()=>100})).inserted,2); const first=await readClaimRegistry(db,'clan',id),second=await readClaimRegistry(db,'clan',other); assert.notDeepEqual(first.homeBlock.position,second.homeBlock.position);assert.equal(worldGuardChunkCount(first.estates[0].worldguard),1); assert.deepEqual(Object.values(first.estates[0].worldguard.regions)[0].owners['unique-ids'],[other]); db.sqlite.prepare("UPDATE site_claim_registry SET snapshot_json=? WHERE organisation_id=?").run(JSON.stringify({...first,tier:'BC_T1'}),id); assert.equal((await seedWebClanClaimLocations(db)).inserted,0);assert.equal((await readClaimRegistry(db,'clan',id)).tier,'BC_T1'); }finally{db.close();} }); test('WorldGuard data retains UUID domains, inclusive chunks and negative coordinates',()=>{ const document=worldGuardHomeRegion(id,{x:-1,y:64,z:-1},{ownerUuid:other,memberUuids:[id,other]});const region=Object.values(document.regions)[0]; assert.equal(region.min.x,-16);assert.equal(region.max.x,-1);assert.equal(worldGuardChunkCount(document),1);assert.deepEqual(region.members['unique-ids'],[id]); region.min={x:0,y:-64,z:0};region.max={x:47,y:319,z:47};assert.equal(worldGuardChunkCount(document),9); assert.equal(webClanClaimSnapshot({id,name:'Protected',institution_key:'vaerkring'}).tier,'PBC_T0'); });