Files
AetherForge/server/web/src/help/accessDepth.test.ts
AetherForge 50ebfe53cb Add Android APK fleet nodes with Crucible UI integration and tests.
APK wrapper registers platform=android via AETHERFORGE_PLATFORM; fleet UI shows robot icons, Android Access Depth probes, and a shortened mining onion timeline.
2026-06-07 02:44:29 -07:00

103 lines
3.0 KiB
TypeScript

/**
* @vitest-environment node
*/
import { describe, expect, it } from 'vitest';
import {
buildAccessDepthModel,
parseAccessDepthDiagnostics,
parseAccessDepthServerPolicy,
} from './accessDepth';
import type { Agent } from '../types';
function agent(partial: Partial<Agent>): Agent {
return {
id: 'x',
name: 'n',
wallet: '',
ip: '1.1.1.1',
version: '1',
status: 'online',
cpu_cores: 4,
memory_gb: 8,
last_seen: '',
created_at: '',
hashrate_15s: 0,
hashrate_1m: 0,
hashrate_15m: 0,
shares_total: 0,
shares_good: 0,
shares_bad: 0,
cpu_usage_pct: 0,
memory_usage_pct: 0,
uptime_seconds: 0,
...partial,
};
}
describe('parseAccessDepthServerPolicy', () => {
it('reads lotl_onion_tiers and triple onion from config', () => {
const p = parseAccessDepthServerPolicy({
server: {
lotl_onion_tiers: ['docker', 'smb'],
triple_onion_policy: { recon_tiers: ['a'], deploy_lanes: ['b'] },
},
});
expect(p.lotl_onion_tiers).toEqual(['docker', 'smb']);
expect(p.triple_onion?.recon_tiers).toEqual(['a']);
});
});
describe('buildAccessDepthModel atlas skips', () => {
it('marks tiers skipped_by_atlas and lists atlas summary', () => {
const model = buildAccessDepthModel(
agent({ platform: 'windows' }),
parseAccessDepthDiagnostics({
tier_chain_order: ['exe_subprocess', 'ps_inmemory', 'cpu_inprocess'],
atlas_skips: [{ tier: 'ps_inmemory', condition: 'defender_on', reason: '5 failures with Defender on' }],
}),
);
expect(model.atlasSkips).toHaveLength(1);
expect(model.miningOnion.find((r) => r.tier === 'ps_inmemory')?.status).toBe('skipped_by_atlas');
});
});
describe('buildAccessDepthModel pending chain', () => {
it('marks skipped tiers and pending remainder', () => {
const model = buildAccessDepthModel(
agent({ platform: 'windows' }),
parseAccessDepthDiagnostics({
tier_chain_order: ['a', 'b', 'c'],
tier_chain_skipped: ['a'],
lotl_attempts: [{ tier: 'b', ok: false, error: 'nope' }],
}),
);
expect(model.pendingTiers).toEqual(['c']);
expect(model.miningOnion.find((r) => r.tier === 'a')?.status).toBe('skipped');
expect(model.failed).toHaveLength(1);
});
});
describe('buildAccessDepthModel android', () => {
it('uses android platform label and probes', () => {
const model = buildAccessDepthModel(
agent({ platform: 'android', os_version: '14', arch: 'arm64' }),
parseAccessDepthDiagnostics({
environment_probes: {
wifi: true,
battery: true,
foreground_service: true,
},
tier_chain_order: ['foreground_service', 'cpu_inprocess'],
}),
);
expect(model.platformLabel).toBe('Android');
expect(model.probes.map((p) => p.label)).toEqual(['Wi-Fi', 'Battery', 'Foreground svc']);
expect(model.miningOnion.map((r) => r.tier)).toEqual([
'foreground_service',
'cpu_inprocess',
'desktop_tiers_skipped',
]);
expect(model.spreadOnion).toEqual([]);
});
});