/** * Tests for live-inject.mjs — script-tag insert/remove round-trip. * Run with: node --test tests/live-inject.test.mjs */ import { describe, it, beforeEach, afterEach } from 'node:test'; import assert from 'node:assert/strict'; import { mkdtempSync, writeFileSync, readFileSync, rmSync } from 'node:fs'; import { dirname, join, resolve } from 'node:path'; import { tmpdir } from 'node:os'; import { fileURLToPath } from 'node:url'; import { execFileSync } from 'node:child_process'; const __dirname = dirname(fileURLToPath(import.meta.url)); const INJECT = resolve(__dirname, '..', 'source/skills/impeccable/scripts/live-inject.mjs'); function runInject(cwd, configPath, args) { try { const out = execFileSync('node', [INJECT, ...args], { cwd, encoding: 'utf-8', env: { ...process.env, IMPECCABLE_LIVE_CONFIG: configPath }, stdio: ['ignore', 'pipe', 'pipe'], }); return JSON.parse(out.trim()); } catch (err) { const body = err.stdout?.toString().trim() || err.stderr?.toString().trim() || ''; return JSON.parse(body || '{}'); } } describe('live-inject — insert/remove round-trip preserves file bytes', () => { let tmp; beforeEach(() => { tmp = mkdtempSync(join(tmpdir(), 'impeccable-inject-test-')); }); afterEach(() => { rmSync(tmp, { recursive: true, force: true }); }); it('round-trips an HTML file without mangling indentation', () => { const original = `