import { describe, expect, it } from 'vitest';
import { generateLlmsTxt, sanitizeLlmsText } from '../../seo/llms-txt.js';
describe('sanitizeLlmsText', () => {
    it('collapses newlines and whitespace into single spaces', () => {
        expect(sanitizeLlmsText('a\n\nb\t c   d', 200)).toBe('a b c d');
    });
    it('strips markdown link-breaking characters', () => {
        expect(sanitizeLlmsText('foo [bar] (baz)', 200)).toBe('foo bar baz');
    });
    it('removes control and zero-width characters', () => {
        expect(sanitizeLlmsText('clean\u0000\u200btext', 200)).toBe('clean text');
    });
    it('caps length on a word boundary', () => {
        const out = sanitizeLlmsText('alpha beta gamma delta', 12);
        expect(out.length).toBeLessThanOrEqual(12);
        expect(out).toBe('alpha beta');
    });
    it('returns empty string for nullish input', () => {
        expect(sanitizeLlmsText(undefined, 200)).toBe('');
        expect(sanitizeLlmsText(null, 200)).toBe('');
    });
});
describe('generateLlmsTxt per-section cap', () => {
    it('limits entries per section to maxPerSection', () => {
        const pages = Array.from({ length: 6 }, (_, i) => ({
            title: `Page ${i}`,
            url: `https://acme.test/p${i}`,
            collection: 'pages',
        }));
        const out = generateLlmsTxt({ siteName: 'Acme', siteUrl: 'https://acme.test', maxPerSection: 3 }, pages);
        const items = (out.match(/^- \[Page /gm) ?? []).length;
        expect(items).toBe(3);
    });
    it('sanitizes the site summary into a single-line blockquote', () => {
        const out = generateLlmsTxt({ siteName: 'Acme', siteUrl: 'https://acme.test', siteDescription: 'Multi\nline\nsummary' }, []);
        expect(out).toContain('> Multi line summary');
    });
});
describe('generateLlmsTxt curation (Phase 1)', () => {
    const base = { siteName: 'Acme', siteUrl: 'https://acme.test' };
    it('routes optional entries into a reserved ## Optional section', () => {
        const out = generateLlmsTxt(base, [
            { title: 'Main', url: 'https://acme.test/main', collection: 'pages' },
            { title: 'Side', url: 'https://acme.test/side', collection: 'pages', optional: true },
        ]);
        const optionalIdx = out.indexOf('## Optional');
        expect(optionalIdx).toBeGreaterThan(-1);
        // The optional item appears under ## Optional, not the main Pages section.
        expect(out.indexOf('Side')).toBeGreaterThan(optionalIdx);
        expect(out.indexOf('Main')).toBeLessThan(optionalIdx);
    });
    it('honors an explicit section override', () => {
        const out = generateLlmsTxt(base, [
            { title: 'A Guide', url: 'https://acme.test/g', collection: 'pages', section: 'Guides' },
        ]);
        expect(out).toContain('## Guides');
        expect(out).not.toContain('## Pages');
    });
    it('sorts within a section by priority (higher first)', () => {
        const out = generateLlmsTxt(base, [
            { title: 'Low', url: 'https://acme.test/low', collection: 'pages', priority: 1 },
            { title: 'High', url: 'https://acme.test/high', collection: 'pages', priority: 10 },
        ]);
        expect(out.indexOf('High')).toBeLessThan(out.indexOf('Low'));
    });
    it('emits an intro block after the summary and drops stray headings', () => {
        const out = generateLlmsTxt({ ...base, siteDescription: 'Summary', intro: 'Context line.\n# Not a heading\nMore.' }, []);
        expect(out).toContain('> Summary');
        expect(out).toContain('Context line.');
        expect(out).toContain('More.');
        expect(out).not.toContain('# Not a heading');
    });
});
//# sourceMappingURL=llms-sanitize.test.js.map