import { describe, expect, it } from 'vitest';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const EXT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', 'extension');

describe('plugin patcher LOGIC_VERSION lockstep', () => {
  it('both scripts declare the same LOGIC_VERSION', () => {
    const sh = fs.readFileSync(path.join(EXT, 'MacOS-Linux-Plugin-Patcher.sh'), 'utf8');
    const ps1 = fs.readFileSync(path.join(EXT, 'Windows-Plugin-Patcher.ps1'), 'utf8');
    const shM = /^LOGIC_VERSION="([^"]+)"/m.exec(sh);
    const psM = /^\$LOGIC_VERSION\s*=\s*'([^']+)'/m.exec(ps1);
    expect(shM?.[1]).toBeTruthy();
    expect(psM?.[1]).toBeTruthy();
    expect(shM![1]).toBe(psM![1]);
  });

  it('both scripts exist at extension root (zip root)', () => {
    expect(fs.existsSync(path.join(EXT, 'MacOS-Linux-Plugin-Patcher.sh'))).toBe(true);
    expect(fs.existsSync(path.join(EXT, 'Windows-Plugin-Patcher.ps1'))).toBe(true);
  });
});
