Add tiered LOTL mining onion and fleet recon so agents can fallback across execution tiers while operators see spread and vuln posture in Crucible. Includes triple-onion chain, spread cred graph, and full Go/TS/E2E test validation.
This commit is contained in:
94
server/web/src/help/warRoomTelemetry.test.ts
Normal file
94
server/web/src/help/warRoomTelemetry.test.ts
Normal file
@@ -0,0 +1,94 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { mockAgent } from '../test/fixtures';
|
||||
import {
|
||||
aggregateCampaignTelemetry,
|
||||
effectiveMiningHashrate,
|
||||
hashHeatIntensity,
|
||||
lotlTierLabel,
|
||||
maxTelemetryHashrate,
|
||||
mergeCampaignWithLiveTelemetry,
|
||||
} from './warRoomTelemetry';
|
||||
import type { WarRoomCampaign } from '../types';
|
||||
|
||||
describe('effectiveMiningHashrate', () => {
|
||||
it('prefers mining_hashrate when present', () => {
|
||||
expect(
|
||||
effectiveMiningHashrate(mockAgent({ mining_hashrate: 900, hashrate_15m: 100, gpu_hashrate_15m: 50 })),
|
||||
).toBe(900);
|
||||
});
|
||||
|
||||
it('falls back to CPU + GPU hashrate', () => {
|
||||
expect(
|
||||
effectiveMiningHashrate(mockAgent({ hashrate_15m: 400, gpu_hashrate_15m: 100 })),
|
||||
).toBe(500);
|
||||
});
|
||||
});
|
||||
|
||||
describe('aggregateCampaignTelemetry', () => {
|
||||
it('groups online agents by campaign and sums hashrate', () => {
|
||||
const map = aggregateCampaignTelemetry([
|
||||
mockAgent({ id: 'a1', campaign: 'linkedin', status: 'online', mining_hashrate: 300 }),
|
||||
mockAgent({ id: 'a2', campaign: 'linkedin', status: 'online', hashrate_15m: 200 }),
|
||||
mockAgent({ id: 'a3', campaign: 'usb', status: 'offline', hashrate_15m: 999 }),
|
||||
]);
|
||||
const linkedin = map.get('linkedin');
|
||||
expect(linkedin?.online).toBe(2);
|
||||
expect(linkedin?.hashrate).toBe(500);
|
||||
expect(linkedin?.mining).toBe(2);
|
||||
expect(map.get('usb')?.hashrate).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('mergeCampaignWithLiveTelemetry', () => {
|
||||
const base: WarRoomCampaign = {
|
||||
campaign: 'linkedin',
|
||||
hits: 10,
|
||||
downloads: 5,
|
||||
agents: 2,
|
||||
online: 0,
|
||||
hashrate: 0,
|
||||
conversion_pct: 20,
|
||||
daily_hits: [1, 2, 3],
|
||||
};
|
||||
|
||||
it('overlays live hashrate and online counts', () => {
|
||||
const merged = mergeCampaignWithLiveTelemetry(base, {
|
||||
hashrate: 1200,
|
||||
online: 2,
|
||||
mining: 1,
|
||||
agents: [],
|
||||
});
|
||||
expect(merged.hashrate).toBe(1200);
|
||||
expect(merged.online).toBe(2);
|
||||
expect(merged.hits).toBe(10);
|
||||
});
|
||||
});
|
||||
|
||||
describe('hashHeatIntensity', () => {
|
||||
it('returns 0 for zero hashrate', () => {
|
||||
expect(hashHeatIntensity(0, 1000)).toBe(0);
|
||||
});
|
||||
|
||||
it('scales relative to fleet max', () => {
|
||||
expect(hashHeatIntensity(500, 1000)).toBe(0.5);
|
||||
expect(hashHeatIntensity(2000, 1000)).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('lotlTierLabel', () => {
|
||||
it('returns uppercase tier or null', () => {
|
||||
expect(lotlTierLabel(' tier-2 ')).toBe('TIER-2');
|
||||
expect(lotlTierLabel('')).toBeNull();
|
||||
expect(lotlTierLabel(undefined)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('maxTelemetryHashrate', () => {
|
||||
it('finds peak campaign hashrate', () => {
|
||||
const map = aggregateCampaignTelemetry([
|
||||
mockAgent({ campaign: 'a', status: 'online', mining_hashrate: 100 }),
|
||||
mockAgent({ campaign: 'b', status: 'online', mining_hashrate: 450 }),
|
||||
]);
|
||||
expect(maxTelemetryHashrate(map)).toBe(450);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user