21 lines
1.6 KiB
JavaScript
21 lines
1.6 KiB
JavaScript
// Local renderer contract: no browser, real accounts, provider or auth material.
|
|
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { readFileSync } from 'node:fs';
|
|
import { runInNewContext } from 'node:vm';
|
|
const source=readFileSync(new URL('../src/public/bus.js',import.meta.url),'utf8');
|
|
const start=source.indexOf(' function tokenUsage(value) {'),end=source.indexOf('\n // Row 155',start);
|
|
const render=runInNewContext(`const txt=v=>String(v??'').replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));${source.slice(start,end)};tokenUsage`);
|
|
const counts={input:2,output:3,cacheWrite:4,cacheRead:5,unknownTurns:0};
|
|
test('P5 Console displays stack count per safe key separately from optional proxy account numbers',()=>{
|
|
const native={total:counts,byKey:[{modelKeyId:'012345abcdef',...counts}]};
|
|
const off=render(native);assert.match(off,/Key: 012345abcdef/);assert.doesNotMatch(off,/Proxy-reported/);
|
|
const on=render({...native,proxy:{source:'proxy',state:'available',byAccount:[{accountId:'abcdef012345',input:99,output:7,cacheWrite:0,cacheRead:0,requests:2,failures:1}]}});
|
|
assert.match(on,/Proxy-reported/);assert.match(on,/abcdef012345/);assert.match(on,/telemetry.*quota/i);assert.match(on,/>99</);
|
|
assert.match(on,/Key: 012345abcdef/);assert.doesNotMatch(on,/msk-|upstream-canary/);
|
|
});
|
|
test('P5 Console escapes hostile labels and labels unavailable telemetry without presenting a fresh zero',()=>{
|
|
const page=render({total:counts,byKey:[{modelKeyId:'<img src=x>',...counts}],proxy:{source:'proxy',state:'unavailable',byAccount:[]}});
|
|
assert.doesNotMatch(page,/<img/);assert.match(page,/unavailable/);
|
|
});
|