148 lines
3.8 KiB
TypeScript
148 lines
3.8 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { agentStatsUnchanged, WS_LATEST_MESSAGE_TYPES } from './wsStatsCoalesce';
|
|
import { mockAgent } from '../test/fixtures';
|
|
|
|
describe('agentStatsUnchanged', () => {
|
|
it('returns true when payload matches current agent stats', () => {
|
|
const agent = mockAgent({
|
|
hashrate_15s: 100,
|
|
hashrate_1m: 90,
|
|
hashrate_15m: 80,
|
|
cpu_usage_pct: 12,
|
|
});
|
|
expect(
|
|
agentStatsUnchanged(agent, {
|
|
agent_id: agent.id,
|
|
hashrate_15s: 100,
|
|
hashrate_1m: 90,
|
|
hashrate_15m: 80,
|
|
cpu_usage_pct: 12,
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
|
|
it('returns false when hashrate changes', () => {
|
|
const agent = mockAgent({ hashrate_15s: 100, hashrate_1m: 90, hashrate_15m: 80, cpu_usage_pct: 12 });
|
|
expect(
|
|
agentStatsUnchanged(agent, {
|
|
agent_id: agent.id,
|
|
hashrate_15s: 101,
|
|
hashrate_1m: 90,
|
|
hashrate_15m: 80,
|
|
cpu_usage_pct: 12,
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
|
|
it('returns false when mining cascade fields change', () => {
|
|
const agent = mockAgent({
|
|
hashrate_15s: 100,
|
|
hashrate_1m: 90,
|
|
hashrate_15m: 80,
|
|
cpu_usage_pct: 12,
|
|
active_method: 'inprocess',
|
|
stratum_overlay: false,
|
|
});
|
|
expect(
|
|
agentStatsUnchanged(agent, {
|
|
agent_id: agent.id,
|
|
hashrate_15s: 100,
|
|
hashrate_1m: 90,
|
|
hashrate_15m: 80,
|
|
cpu_usage_pct: 12,
|
|
active_method: 'container',
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
agentStatsUnchanged(agent, {
|
|
agent_id: agent.id,
|
|
hashrate_15s: 100,
|
|
hashrate_1m: 90,
|
|
hashrate_15m: 80,
|
|
cpu_usage_pct: 12,
|
|
active_method: 'inprocess',
|
|
stratum_overlay: true,
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
|
|
it('returns false when mining_hashrate or lotl_tier change', () => {
|
|
const agent = mockAgent({
|
|
hashrate_15s: 100,
|
|
hashrate_1m: 90,
|
|
hashrate_15m: 80,
|
|
cpu_usage_pct: 12,
|
|
mining_hashrate: 500,
|
|
lotl_tier: 'tier-1',
|
|
});
|
|
expect(
|
|
agentStatsUnchanged(agent, {
|
|
agent_id: agent.id,
|
|
hashrate_15s: 100,
|
|
hashrate_1m: 90,
|
|
hashrate_15m: 80,
|
|
cpu_usage_pct: 12,
|
|
mining_hashrate: 600,
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
agentStatsUnchanged(agent, {
|
|
agent_id: agent.id,
|
|
hashrate_15s: 100,
|
|
hashrate_1m: 90,
|
|
hashrate_15m: 80,
|
|
cpu_usage_pct: 12,
|
|
lotl_tier: 'tier-2',
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
|
|
it('returns false when lotl_attempts change', () => {
|
|
const agent = mockAgent({
|
|
hashrate_15s: 100,
|
|
hashrate_1m: 90,
|
|
hashrate_15m: 80,
|
|
cpu_usage_pct: 12,
|
|
lotl_attempts: [{ tier: 'container', ok: false, duration_ms: 500 }],
|
|
});
|
|
expect(
|
|
agentStatsUnchanged(agent, {
|
|
agent_id: agent.id,
|
|
hashrate_15s: 100,
|
|
hashrate_1m: 90,
|
|
hashrate_15m: 80,
|
|
cpu_usage_pct: 12,
|
|
lotl_attempts: [{ tier: 'container', ok: true, duration_ms: 500 }],
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
|
|
it('returns false when spread genealogy watermark changes', () => {
|
|
const agent = mockAgent({
|
|
hashrate_15s: 100,
|
|
hashrate_1m: 90,
|
|
hashrate_15m: 80,
|
|
cpu_usage_pct: 12,
|
|
parent_agent_id: 'parent-1',
|
|
spread_generation: 1,
|
|
spread_strain: '#aabbcc',
|
|
});
|
|
expect(
|
|
agentStatsUnchanged(agent, {
|
|
agent_id: agent.id,
|
|
hashrate_15s: 100,
|
|
hashrate_1m: 90,
|
|
hashrate_15m: 80,
|
|
cpu_usage_pct: 12,
|
|
spread_generation: 2,
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('WS_LATEST_MESSAGE_TYPES', () => {
|
|
it('includes command_result so SoundBridge and Crucible backup path receive results', () => {
|
|
expect(WS_LATEST_MESSAGE_TYPES.has('command_result')).toBe(true);
|
|
});
|
|
});
|