feat(summary): send complete articles within user budget (#39)
This commit is contained in:
@ -15,13 +15,14 @@ test('no broad article/main or JSON-LD content fallback; paragraph normalization
|
||||
assert.equal(extractArticle('<script type="application/ld+json">{"@type":"NewsArticle","articleBody":"excluded"}</script>').content, '')
|
||||
assert.equal(extractArticle(basic('one two<script>excluded</script>') .replace('</div></article>', `<p class="${paragraph}"> three\n four </p></div></article>`)).content, 'one two\n\nthree four')
|
||||
})
|
||||
test('oversized non-ASCII content is deterministically bounded on UTF-8 boundaries', () => {
|
||||
test('large non-ASCII editorial content remains complete without truncation', () => {
|
||||
const html = basic('é漢🙂'.repeat(MAX_CONTENT_BYTES))
|
||||
const first = extractArticle(html)
|
||||
assert.equal(first.content, extractArticle(html).content)
|
||||
assert.ok(Buffer.byteLength(first.content) <= MAX_CONTENT_BYTES)
|
||||
assert.equal(first.content, 'é漢🙂'.repeat(MAX_CONTENT_BYTES))
|
||||
assert.ok(!first.content.includes('\ufffd'))
|
||||
assert.equal(first.content_truncated, true)
|
||||
assert.equal(first.content_truncated, false)
|
||||
assert.equal(first.content_state, 'complete')
|
||||
})
|
||||
test('enrichment deduplicates loads, bounds concurrency and preserves input order', async () => {
|
||||
const urls = ['a', 'b', 'a', 'c'].map(id => `https://www.bloomberg.com/news/articles/${id}`)
|
||||
@ -90,3 +91,9 @@ test('editorial descendants preserve document order and exclude non-editorial an
|
||||
const html = `<article><div class="FeatureContent_body__NTf8M"><div><section><p class="${paragraph}">one</p></section></div><aside><div><p class="${paragraph}">excluded</p></div></aside><div hidden><p class="${paragraph}">excluded</p></div><div data-component="related-stories"><p class="${paragraph}">excluded</p></div><div><div><p class="${paragraph}">two</p></div></div></div></article>`
|
||||
assert.equal(extractArticle(html).content,'one\n\ntwo')
|
||||
})
|
||||
|
||||
test('full editorial extraction preserves headings, list items and quotations', () => {
|
||||
const html = basic('First paragraph.').replace('</div></article>', '<h2>Editorial heading</h2><ul><li>Editorial list item</li></ul><blockquote>Editorial quotation</blockquote></div></article>')
|
||||
const result = extractArticle(html)
|
||||
for (const text of ['First paragraph.', 'Editorial heading', 'Editorial list item', 'Editorial quotation']) assert.ok(result.content.includes(text))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user