feat(admin): add backend-authoritative orchestration command center and usage view
This commit is contained in:
1 parent
e5c83e87fe
commit
c8a3f35b0a
16 files changed
+510
-373
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import {render,screen,fireEvent} from '@testing-library/react';
|
||||
import {it,expect,vi} from 'vitest';
|
||||
import api from './api';
|
||||
import {routerUsage} from './routerUsage';
|
||||
import RouterUsagePanel from '../components/RouterUsagePanel';
|
||||
vi.mock('./api',()=>({default:{get:vi.fn()}}));
|
||||
const metrics={requests:20,inputTokens:100,outputTokens:50,cacheReadTokens:0,cacheWriteTokens:null,reasoningTokens:null,errors:null};
|
||||
const snapshot={source:'9router',period:'7d',status:'available',reason:null,attribution:{scope:'9router_total',hermes:null,additive:false},freshness:{retrievedAt:'2026-10-22T12:00:00Z',sourceUpdatedAt:null,stale:null},data:{totals:metrics,providers:[{provider:'provider-a',...metrics}],models:[{model:'model-b',provider:'provider-a',...metrics}],accounts:[{accountId:'opaque-1',provider:'provider-a',model:'model-b',...metrics,quota:{status:'unknown',remaining:null,resetAt:null,reason:'upstream_quota_get_mutates_credentials'}}]}};
|
||||
it('renders concrete backend contract, unknown quota and source freshness; period selects backend filter',async()=>{
|
||||
vi.mocked(api.get).mockResolvedValue({data:snapshot});render(<RouterUsagePanel/>);
|
||||
expect(await screen.findByText('opaque-1')).toBeInTheDocument();
|
||||
expect(screen.getByText('Gateway totals (includes Hermes)')).toBeInTheDocument();
|
||||
expect(screen.getByText('Hermes attribution: Unknown — not reported; do not add to gateway totals.')).toBeInTheDocument();
|
||||
expect(screen.getByText('9router')).toBeInTheDocument();
|
||||
expect(screen.getAllByText('Unknown — not reported').length).toBeGreaterThan(0);
|
||||
expect(screen.getAllByText('0').length).toBeGreaterThan(0);
|
||||
expect(api.get).toHaveBeenCalledWith('/admin/router-usage',{params:{period:'7d'}});
|
||||
fireEvent.change(screen.getByLabelText('Usage period'),{target:{value:'today'}});
|
||||
await screen.findByText('opaque-1');
|
||||
expect(api.get).toHaveBeenLastCalledWith('/admin/router-usage',{params:{period:'today'}});
|
||||
});
|
||||
it('rejects missing provenance instead of inventing freshness',async()=>{
|
||||
vi.mocked(api.get).mockResolvedValue({data:{accounts:[]}});
|
||||
await expect(routerUsage.snapshot()).rejects.toThrow(/Invalid/);
|
||||
});
|
||||
it('shows unavailable configuration honestly and discards arbitrary credential properties',async()=>{
|
||||
vi.mocked(api.get).mockResolvedValueOnce({data:{...snapshot,status:'unavailable',reason:'not_configured',data:null}});
|
||||
await expect(routerUsage.snapshot()).rejects.toThrow('not_configured');
|
||||
vi.mocked(api.get).mockResolvedValueOnce({data:{...snapshot,token:'secret',data:{...snapshot.data,credentials:'secret'}}});
|
||||
expect(JSON.stringify(await routerUsage.snapshot())).not.toContain('secret');
|
||||
});
|
||||
Reference in new issue
Block a user