import { describe, expect, test } from 'bun:test';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import { acceptFindings, BUZZWORDS, CRAFT_IDS, checkCraft, formatCraft, parseCraftExceptions, visibleText } from '../lib/design-craft';
import { catalogEntry, DESIGN_SLOP_CATALOG, detectorSlopEntries, judgmentTellEntries, renderCatalog, selectCatalog } from '../lib/design-catalog';
import { autoFixEntries, checklistSlopEntries } from '../scripts/resolvers/design-checklist';
import { selectTests } from './helpers/test-selection';
import { E2E_TOUCHFILES, LLM_JUDGE_TOUCHFILES } from './helpers/touchfiles-data';
const ROOT = path.resolve(import.meta.dir, '..');
const BIN = path.join(ROOT, 'bin', 'gstack-design-craft');
const DIRTY = `
Elevate your workflow seamlessly
Trusted by Acme and John Doe. 99.99% uptime, 50% faster, 10,000+ happy users. [Needs proof: logo]

Oops! Something broke. Lorem ipsum.
`;
const CLEAN = `Ledgerline: close the books in 2 days
Skip to contentPricing
Close the books in 2 days, not 9
Teams at Halvorsen Freight cut month-end by 47.2%. Save 20% yearly. 100% open source. 30-day refund.
`;
function run(file?: string, ...extra: string[]) {
const r = Bun.spawnSync([BIN, ...(file ? [file] : []), ...extra], { stdout: 'pipe', stderr: 'pipe', timeout: 30_000 });
return { code: r.exitCode, out: r.stdout.toString(), err: r.stderr.toString() };
}
describe('design-craft check', () => {
test('a page with every tell reports each one with its count', () => {
const counts = Object.fromEntries(checkCraft(DIRTY).map(f => [f.id, f.count]));
expect(counts).toEqual({
'placeholder-name': 1, 'placeholder-brand': 1, lorem: 1, 'marketing-buzzword': 2, 'round-number': 3, 'needs-proof': 1, oops: 1,
'scroll-listener': 1, 'layout-transition': 1, 'dead-link': 1, alert: 1, 'img-no-alt': 1, 'vh-height': 1,
'missing-title': 1, 'missing-meta-description': 1, 'missing-favicon': 1,
'missing-skip-link': 1, 'missing-aria-current': 1,
});
});
test('a finished page is clean: CSS 100%, a 100vh line with its 100dvh fallback, in-page anchors, a showAlert helper and inlined Pretext are not flagged', () => {
expect(checkCraft(CLEAN)).toEqual([]);
const pretext = fs.readFileSync(path.join(ROOT, 'design-html', 'vendor', 'pretext.js'), 'utf-8');
expect(checkCraft(CLEAN.replace('