1import { describe, expect, test } from 'bun:test';
2import { PROVIDERS } from '../../scripts/lib/transformers/providers.js';
3import { compileProviderBlocks, PROVIDER_BLOCK_TAGS } from '../../scripts/lib/utils.js';
4
5describe('compileProviderBlocks', () => {
6 test('keeps matching provider block bodies and removes tags', () => {
7 const content = [
8 'Before',
9 '<codex>',
10 'Codex-only guidance.',
11 '</codex>',
12 'After',
13 ].join('\n');
14
15 expect(compileProviderBlocks(content, ['codex'])).toBe([
16 'Before',
17 'Codex-only guidance.',
18 'After',
19 ].join('\n'));
20 });
21
22 test('removes non-matching provider blocks', () => {
23 const content = [
24 'Before',
25 '<codex>',
26 'Codex-only guidance.',
27 '</codex>',
28 'After',
29 ].join('\n');
30
31 expect(compileProviderBlocks(content, ['claude-code'])).toBe([
32 'Before',
33 '',
34 'After',
35 ].join('\n'));
36 });
37
38 test('does not leave extra blank lines around stripped blocks', () => {
39 const content = [
40 'Before',
41 '',
42 '<codex>',
43 'Codex-only guidance.',
44 '</codex>',
45 '',
46 'After',
47 ].join('\n');
48
49 expect(compileProviderBlocks(content, ['claude-code'])).toBe([
50 'Before',
51 '',
52 'After',
53 ].join('\n'));
54 });
55
56 test('preserves unknown standalone tags', () => {
57 const content = [
58 'Before',
59 '<aside>',
60 'Normal markdown HTML.',
61 '</aside>',
62 'After',
63 ].join('\n');
64
65 expect(compileProviderBlocks(content, ['codex'])).toBe(content);
66 });
67
68 test('keeps codex blocks for targets that opt into the codex tag', () => {
69 const content = [
70 '<codex>',
71 'Codex repo skill guidance.',
72 '</codex>',
73 ].join('\n');
74
75 expect(compileProviderBlocks(content, ['agents', 'codex'])).toBe('Codex repo skill guidance.');
76 });
77
78 test('all provider configs use known provider block tags', () => {
79 for (const config of Object.values(PROVIDERS)) {
80 expect(config.providerTags?.length).toBeGreaterThan(0);
81 for (const tag of config.providerTags) {
82 expect(PROVIDER_BLOCK_TAGS.has(tag)).toBe(true);
83 }
84 }
85 });
86});