fix(scraper): verify complete article evidence (#40)

This commit is contained in:
2026-11-24 19:24:29 +01:00
parent 70ffe41cfb
commit a55dc2e189
27 changed files with 833 additions and 132 deletions

View File

@ -5,7 +5,8 @@ const paragraph = 'ArticleBodyText_articleBodyContent__17wqE typography_articleB
const basic = text => `<article class="articleLayout_basic__gcpQk"><div class="body-content"><p class="${paragraph}">${text}</p><div class="placeholder"><p class="${paragraph}">excluded placeholder</p></div></div></article>`
test('observed basic and feature layouts extract only editorial paragraphs within the observed root', () => {
for (const html of [basic(' First <em>synthetic</em> paragraph. '), `<article><div class="FeatureContent_body__NTf8M"><p class="${paragraph}"> First <em>synthetic</em> paragraph. </p></div></article>`]) {
const result = extractArticle(`<nav>excluded navigation</nav><meta name="iso-8601-publish-date" content="2026-01-02T03:04:05Z">${html}`)
const identity = "https://www.bloomberg.com/news/articles/fixture"
const result = extractArticle(`<link rel="canonical" href="${identity}"><nav>excluded navigation</nav><meta name="iso-8601-publish-date" content="2026-01-02T03:04:05Z">${html}`, identity)
assert.equal(result.content, 'First synthetic paragraph.')
assert.equal(result.published_at, '2026-01-02T03:04:05.000Z')
}
@ -16,9 +17,10 @@ test('no broad article/main or JSON-LD content fallback; paragraph normalization
assert.equal(extractArticle(basic('one&nbsp; two<script>excluded</script>') .replace('</div></article>', `<p class="${paragraph}"> three\n four </p></div></article>`)).content, 'one two\n\nthree four')
})
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)
const identity = 'https://www.bloomberg.com/news/articles/fixture'
const html = `<link rel="canonical" href="${identity}">` + basic('é漢🙂'.repeat(MAX_CONTENT_BYTES)).replace(/<div class="placeholder">.*?<\/div>/, '')
const first = extractArticle(html, identity)
assert.equal(first.content, extractArticle(html, identity).content)
assert.equal(first.content, 'é漢🙂'.repeat(MAX_CONTENT_BYTES))
assert.ok(!first.content.includes('\ufffd'))
assert.equal(first.content_truncated, false)
@ -48,7 +50,8 @@ test('failure and ignored cancellation stay bounded without reusing occupied slo
test('JSON-LD belonging to another article cannot supply this article date', () => {
const html = basic('synthetic paragraph') + '<script type="application/ld+json">{"@type":"NewsArticle","url":"https://www.bloomberg.com/news/articles/other","datePublished":"2026-01-02T03:04:05Z"}</script>'
const result = extractArticle(html, 'https://www.bloomberg.com/news/articles/current')
assert.equal(result.content, 'synthetic paragraph')
assert.equal(result.content, '')
assert.equal(result.content_state, 'unavailable')
assert.equal(result.published_at, null)
})