import './setup.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
import { load } from './setup.mjs';

const { analyzePowerShellCompatibility } = await load('../services/powershellCompatibilityService.js');
const { normalizeOsFamily } = await load('../utils/osFamily.js');

test('normalizeOsFamily maps legacy and unknown host values into supported OS types', () => {
  assert.equal(normalizeOsFamily('Windows Server 2022'), 'windows');
  assert.equal(normalizeOsFamily('Ubuntu Linux'), 'linux');
  assert.equal(normalizeOsFamily('network'), 'other');
  assert.equal(normalizeOsFamily('api'), 'other');
});

test('PowerShell compatibility analyzer is quiet when no Linux targets are selected', () => {
  const result = analyzePowerShellCompatibility('Get-WmiObject Win32_OperatingSystem', [{ osFamily: 'windows' }]);
  assert.equal(result.hasLinuxTargets, false);
  assert.deepEqual(result.findings, []);
});

test('PowerShell compatibility analyzer flags Windows-only patterns for Linux targets', () => {
  const result = analyzePowerShellCompatibility([
    'Get-WmiObject Win32_OperatingSystem',
    'Get-Item HKLM:\\Software\\Contoso',
    'msiexec.exe /i C:\\Temp\\setup.msi',
    'dir C:\\Temp'
  ].join('\n'), [{ osFamily: 'linux' }]);

  assert.equal(result.hasLinuxTargets, true);
  assert.ok(result.findings.some((finding) => finding.id === 'wmi-or-win32-class'));
  assert.ok(result.findings.some((finding) => finding.id === 'windows-registry-provider'));
  assert.ok(result.findings.some((finding) => finding.id === 'windows-executable'));
  assert.ok(result.findings.some((finding) => finding.id === 'alias-dir'));
});
