import test from 'node:test';import assert from 'node:assert/strict';import {randomUUID} from 'node:crypto'; import {KEY_TYPES,keyPolicy,privateKeyPresentation} from '../node/organisation-key-policy.mjs'; import {companyFixture} from './company-deed-fixture.mjs';import {STAFF_OFFICE_ACCOUNT_ID} from '../node/organisation-keys.mjs'; test('every registered key has one explicit family and operation; dev keys are absent',()=>{ for(const policy of Object.values(KEY_TYPES)){assert(['player','system'].includes(policy.family));assert(['redeem','execute','record'].includes(policy.operation));assert.equal(policy.playerRedeemable,policy.family==='player');assert.equal(Object.isFrozen(policy),true);} assert.throws(()=>keyPolicy('dev-batch'));assert.throws(()=>keyPolicy('__proto__')); for(const type of ['economy-snapshot','gazette-news','quest','quest-milestone','political-clan'])assert.equal(privateKeyPresentation(type).showCode,false); for(const type of ['clan-founding','company-founding','xp-correction','xp-transfer'])assert.equal(privateKeyPresentation(type).showCode,true); }); test('news instruments cannot be issued as player rewards or redeemed through consume',async()=>{ const {db,keys,people}=await companyFixture();try{ const scopeId='news:'+randomUUID()+':v1'; await assert.rejects(keys.issue({accountId:people.Owner.id,keyType:'gazette-news',scopeId,authorize:async()=>{}}),/system publication/); const record=await keys.issue({accountId:STAFF_OFFICE_ACCOUNT_ID,keyType:'gazette-news',scopeId,authorize:async()=>{}}); await assert.rejects(keys.consume({accountId:STAFF_OFFICE_ACCOUNT_ID,keyType:'gazette-news',code:record.code,targetId:randomUUID(),requestId:randomUUID(),apply:async()=>{throw Error('Must not run');}}),/cannot be redeemed/); }finally{db.close();} });