import assert from 'assert';
import { postProcessV2, migratePage } from '../src/migrations';
import { AgentCompletion, PromptCompletionArgs } from '../src/models/types';
// ---------------------------------------------------------------------------
// postProcessV2
// ---------------------------------------------------------------------------
describe('postProcessV2', () => {
const baseV2 = `
Test
Content
`;
it('injects theme-info.js when missing', () => {
const html = `Test`;
const result = postProcessV2(html);
assert.ok(result.includes('src="/api/theme-info.js"'));
});
it('does not duplicate theme-info.js when already present', () => {
const result = postProcessV2(baseV2);
const matches = result.match(/theme-info\.js/g);
assert.strictEqual(matches?.length, 1);
});
it('injects theme.css when missing', () => {
const html = `Test`;
const result = postProcessV2(html);
assert.ok(result.includes('href="/api/theme.css"'));
});
it('does not duplicate theme.css when already present', () => {
const result = postProcessV2(baseV2);
const matches = result.match(/theme\.css/g);
assert.strictEqual(matches?.length, 1);
});
it('strips shared CSS selectors from style blocks', () => {
const html = ``;
const result = postProcessV2(html);
assert.ok(!result.includes('.chat-panel {'));
assert.ok(!result.includes('.viewer-panel {'));
assert.ok(result.includes('.my-custom'));
});
it('removes empty style blocks after stripping', () => {
const html = ``;
const result = postProcessV2(html);
// The style block should be removed since it only had shared CSS
assert.ok(!result.includes('