feat(scraper): bound article enrichment diagnostics (#40)
This commit is contained in:
@ -6,7 +6,7 @@ const vm = require('node:vm')
|
||||
const { createRequire } = require('node:module')
|
||||
const html = '<meta name="iso-8601-publish-date" content="2026-01-02T03:04:05Z"><article class="articleLayout_basic__gcpQk"><div class="body-content"><p class="ArticleBodyText_articleBodyContent__17wqE">Synthetic editorial paragraph.</p></div></article>'
|
||||
|
||||
async function request (byparr, failOne = false, poolSize = 2, authTimeout = false, httpDenied = false, loginOutcome = 'authenticated') {
|
||||
async function request (byparr, failOne = false, poolSize = 2, authTimeout = false, httpDenied = false, loginOutcome = 'authenticated', measure = false) {
|
||||
const routes = {}; const loads = []; const logs = []; const timers = []; let pages = 0; let closed = false; let active = 0; let peak = 0; let byparrCalls = 0; const typed = []
|
||||
const app = { use () {}, get () {}, post (url, handler) { routes[url] = handler }, listen () {} }
|
||||
const express = () => app; express.json = () => () => {}
|
||||
@ -47,7 +47,7 @@ async function request (byparr, failOne = false, poolSize = 2, authTimeout = fal
|
||||
})
|
||||
const urls = (poolSize === 2 ? ['a', 'b', 'a'] : Array.from({ length: poolSize }, (_, i) => `pool-${i}`)).map(id => `https://www.bloomberg.com/news/articles/${id}`)
|
||||
let result
|
||||
await routes['/bloomberg/enrich']({ body: { username: 'PRIVATE_USER', password: 'PRIVATE_SECRET', urls } }, { json (value) { result = value }, status () { return this } })
|
||||
await routes['/bloomberg/enrich']({ body: { username: 'PRIVATE_USER', password: 'PRIVATE_SECRET', urls, measure_fetches:measure } }, { json (value) { result = value }, status () { return this } })
|
||||
assert.deepEqual(result.articles.map(a => a.url), urls)
|
||||
assert.equal(loads.length, authTimeout || loginOutcome !== 'authenticated' ? 0 : poolSize)
|
||||
assert.ok(logs.every(line => !line.includes('PRIVATE') && !/https?:\/\//i.test(line) && !line.includes('Synthetic editorial')))
|
||||
@ -122,3 +122,30 @@ test('unexpected login origin stops before credential entry', async () => {
|
||||
assert.equal(typed.length,0);assert.equal(byparrCalls,0)
|
||||
assert.ok(result.articles.every(a => a.content_state==='unavailable' && a.content===''))
|
||||
})
|
||||
|
||||
test('aggregate metrics distinguish login-blocked no-fetch from article HTTP denial', async () => {
|
||||
const blocked=await request(true,false,2,false,false,'two_factor_required',true)
|
||||
assert.equal(blocked.result.fetch_metrics.supported,true)
|
||||
assert.equal(blocked.result.fetch_metrics.attempted,0)
|
||||
assert.equal(blocked.result.fetch_metrics.http.network,0)
|
||||
const denied=await request(true,false,2,false,true,'authenticated',true)
|
||||
assert.equal(denied.result.fetch_metrics.attempted,2) // duplicated listing is one fetch
|
||||
assert.equal(denied.result.fetch_metrics.http['4xx'],2)
|
||||
assert.equal(denied.result.fetch_metrics.editorial_root.not_evaluated,2)
|
||||
assert.equal(denied.result.fetch_metrics.blocking_marker.not_evaluated,2)
|
||||
assert.equal(denied.result.fetch_metrics.extracted_characters['0'],2)
|
||||
assert.equal(denied.result.fetch_metrics.completeness.unavailable,2)
|
||||
})
|
||||
|
||||
test('aggregate login classification preserves not-fetched without disclosing authentication details', async () => {
|
||||
for (const [outcome, expected] of [['access_denied','refused'],['auth_rejected','refused'],['two_factor_required','unconfirmed'],['challenge','unconfirmed'],['authentication_unconfirmed','unconfirmed'],['authenticated','confirmed']]) {
|
||||
const {result}=await request(true,false,2,false,false,outcome,true)
|
||||
assert.equal(result.fetch_metrics.login,expected)
|
||||
if (expected!=='confirmed') {
|
||||
assert.equal(result.fetch_metrics.attempted,0)
|
||||
assert.deepEqual(result.fetch_metrics.http,{'2xx':0,'3xx':0,'4xx':0,'5xx':0,network:0})
|
||||
}
|
||||
const raw=JSON.stringify(result.fetch_metrics)
|
||||
assert.ok(!/PRIVATE|https?:\/\/|Synthetic/.test(raw))
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user