/** * Tests for live-accept.mjs — the deterministic accept/discard helper. * Run with: node --test tests/live-accept.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 ACCEPT = resolve(__dirname, '..', 'skill/scripts/live-accept.mjs'); const WRAP = resolve(__dirname, '..', 'skill/scripts/live-wrap.mjs'); function runAccept(cwd, args) { try { const out = execFileSync('node', [ACCEPT, ...args], { cwd, encoding: 'utf-8', 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-accept — style-element edge cases', () => { let tmp; beforeEach(() => { tmp = mkdtempSync(join(tmpdir(), 'impeccable-accept-test-')); }); afterEach(() => { rmSync(tmp, { recursive: true, force: true }); }); // Historical bug: extractVariant flipped into "inStyle" mode on block should also be treated as a // single skipped unit; the line has both open and close tags. it('finds the accepted variant after a single-line block', () => { const html = `
original
variant one
original
variant one
variant one
variant two
variant one
variant two
Body
ORIGINAL CONTENT
variant one
Variant one