Test extractor transport contracts
This commit is contained in:
@@ -13,7 +13,8 @@
|
||||
"build": "tsc -b && vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview",
|
||||
"test": "playwright test"
|
||||
"test:contracts": "node --experimental-strip-types tests/extractor-pipeline.contract.mjs",
|
||||
"test": "npm run test:contracts && playwright test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tanstack/react-query": "^5.90.0",
|
||||
|
||||
54
tests/extractor-pipeline.contract.mjs
Normal file
54
tests/extractor-pipeline.contract.mjs
Normal file
@@ -0,0 +1,54 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
DEFAULT_TAB_PIPELINE_CONTROLS,
|
||||
extractorPlanForUrl,
|
||||
isExtractionTransportId,
|
||||
resolveExtractionSettingsSnapshot,
|
||||
tabExtractorsFromLegacy,
|
||||
} from '../src/extractor-pipeline.ts';
|
||||
|
||||
const base = resolveExtractionSettingsSnapshot(
|
||||
'manual',
|
||||
undefined,
|
||||
DEFAULT_TAB_PIPELINE_CONTROLS,
|
||||
undefined,
|
||||
);
|
||||
|
||||
const redgifs = resolveExtractionSettingsSnapshot(
|
||||
'redgifs-suggested',
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
{
|
||||
extractors: { 'reddit-gallery': false },
|
||||
controls: { maxDepth: 9 },
|
||||
crawlerOptions: { redgifsSuggestedSteps: 0, redgifsWaitAfterScrollMs: 0, unknownSetting: true },
|
||||
},
|
||||
);
|
||||
|
||||
assert.equal(redgifs.extractors['reddit-gallery'], false);
|
||||
assert.equal(redgifs.extractors['site-scroll'], false, 'site-scroll is a transport-only operation');
|
||||
assert.equal(redgifs.controls.maxDepth, 9);
|
||||
assert.equal(redgifs.crawlerOptions.redgifsSuggestedSteps, 1, 'crawler bounds must reject zero passes');
|
||||
assert.equal(redgifs.crawlerOptions.redgifsWaitAfterScrollMs, 0, 'zero delays must remain valid');
|
||||
assert.equal('unknownSetting' in redgifs.crawlerOptions, false, 'unknown crawler settings must not enter a job snapshot');
|
||||
assert.notEqual(redgifs.fingerprint, base.fingerprint);
|
||||
assert.equal(redgifs.fingerprint, resolveExtractionSettingsSnapshot('redgifs-suggested', undefined, undefined, undefined, {
|
||||
extractors: { 'reddit-gallery': false },
|
||||
controls: { maxDepth: 9 },
|
||||
crawlerOptions: { redgifsSuggestedSteps: 0, redgifsWaitAfterScrollMs: 0, unknownSetting: true },
|
||||
}).fingerprint, 'equivalent snapshots need a stable fingerprint');
|
||||
|
||||
for (const transport of ['tab-pipeline', 'manual', 'site-scroll', 'redgifs-suggested', 'page-collector', 'm3u8', 'reddit-sequence']) {
|
||||
assert.equal(isExtractionTransportId(transport), true);
|
||||
}
|
||||
assert.equal(isExtractionTransportId('not-a-transport'), false);
|
||||
|
||||
assert.deepEqual(extractorPlanForUrl('https://www.redgifs.com/watch/example').slice(0, 2), ['redgifs-suggested', 'redgifs-post']);
|
||||
assert.equal(extractorPlanForUrl('https://www.redgifs.com/users/example')[0], 'redgifs-uploader');
|
||||
assert.deepEqual(extractorPlanForUrl('https://www.reddit.com/r/test/comments/abc/title').slice(0, 3), ['reddit-post', 'reddit-gallery', 'external-source']);
|
||||
assert.equal(extractorPlanForUrl('https://www.youtube.com/watch?v=abc')[0], 'youtube-video');
|
||||
assert.equal(extractorPlanForUrl('https://cdn.example.test/file.mp4')[0], 'direct-media');
|
||||
assert.equal(tabExtractorsFromLegacy({ redgifsSuggested: false })['redgifs-suggested'], false);
|
||||
|
||||
console.log('extractor pipeline contract checks passed');
|
||||
Reference in New Issue
Block a user