import { describe, it, expect } from 'vitest';
import { extractReadableMarkdown, truncateForAgent } from './readability.js';
const ARTICLE_HTML = `
Test Article TitleSITE BANNER — SUBSCRIBE NOW — ADVERTISEMENT
The Main Heading
The first paragraph of the article body, with a helpful link inside it. This needs to be long enough that readability accepts it as real content rather than boilerplate noise.
A Subsection
first bullet point
second bullet point
third bullet point
Name
Value
alpha
1
beta
2
A closing paragraph with sufficient length so the readability heuristics treat this document as a genuine article and extract the body cleanly. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
A paragraph long enough to pass readability with a root relative link embedded so we can verify absolutization works correctly here. Lorem ipsum dolor sit amet consectetur.
`;
const md = extractReadableMarkdown(html, { baseUrl: 'https://site.example/blog/post' })!.markdown;
expect(md).toContain('https://site.example/docs/page');
expect(md).not.toContain('](/docs/page)');
});
});
describe('truncateForAgent', () => {
it('上限以下ならそのまま返す', () => {
expect(truncateForAgent('short', 100)).toBe('short');
});
it('上限超過で切り詰め、source 保存済みなら full 版の在処を案内する', () => {
const long = 'x'.repeat(50);
const out = truncateForAgent(long, 10, 'article.md');
expect(out.startsWith('x'.repeat(10))).toBe(true);
expect(out).toContain('full version saved to source/article.md');
});
it('上限超過で source 未保存なら素の truncated note を付ける', () => {
const out = truncateForAgent('y'.repeat(50), 10, null);
expect(out).toContain('... (truncated)');
expect(out).not.toContain('saved to source');
});
});