Checkpoint first-party source parser pilot
This commit is contained in:
1 parent
605fa5b9d8
commit
c5a92282a9
9 files changed
+320
-43
No files matched your search
@@ -0,0 +1,67 @@
|
||||
'use strict';
|
||||
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { createServer } = require('../plugins/worker');
|
||||
const { parse } = require('../plugins/registry');
|
||||
const { parseSource } = require('../plugins/client');
|
||||
const { discoverWeebCatalog, discoverWeebChapter } = require('../adapters/weebcentral');
|
||||
|
||||
const seriesUrl = 'https://weebcentral.com/series/ABC/title';
|
||||
const chapterUrl = 'https://weebcentral.com/chapters/XYZ';
|
||||
const seriesHtml = '<h1>Test Manga</h1><div hx-get="/series/ABC/full-chapter-list"></div>';
|
||||
const listHtml = '<a href="/chapters/XYZ">Chapter 1</a><a href="/chapters/LMN">Log. 2</a>';
|
||||
const chapterHtml = '<time datetime="2026-01-01"></time>';
|
||||
const imagesHtml = '<img src="https://img.example/1.jpg"><img data-src="https://img.example/2.jpg">';
|
||||
|
||||
test('first-party registry rejects unknown plugins and malformed input', () => {
|
||||
assert.throws(() => parse('remote-module', 'catalog', { html: listHtml, url: seriesUrl }), /Unknown/);
|
||||
assert.throws(() => parse('weebcentral', 'catalog', { html: listHtml, url: 'file:///tmp/x' }), /Invalid source URL/);
|
||||
assert.throws(() => parse('weebcentral', 'catalog', { html: listHtml, url: 'https://other.example/series/a' }), /does not belong/);
|
||||
assert.equal(parse('weebcentral', 'catalog', { html: listHtml, url: seriesUrl }).chapters.length, 2);
|
||||
});
|
||||
|
||||
test('isolated parser preserves WeebCentral catalog and page discovery', async () => {
|
||||
const server = createServer();
|
||||
await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
|
||||
const previous = process.env.SOURCE_PLUGIN_URL;
|
||||
process.env.SOURCE_PLUGIN_URL = `http://127.0.0.1:${server.address().port}`;
|
||||
const requested = [];
|
||||
const http = { async get(url) {
|
||||
requested.push(url);
|
||||
const body = url === seriesUrl ? seriesHtml
|
||||
: url.endsWith('/full-chapter-list') ? listHtml
|
||||
: url === chapterUrl ? chapterHtml
|
||||
: imagesHtml;
|
||||
return { text: async () => body };
|
||||
} };
|
||||
try {
|
||||
const catalog = await discoverWeebCatalog(seriesUrl, http);
|
||||
assert.equal(catalog.title, 'Test Manga');
|
||||
assert.deepEqual(catalog.chapters.map(chapter => chapter.number), ['1', '2']);
|
||||
const chapter = await discoverWeebChapter(catalog.chapters[0], http);
|
||||
assert.equal(chapter.pages.length, 2);
|
||||
assert.equal(chapter.added, '2026-01-01');
|
||||
assert.equal(requested.length, 4);
|
||||
const response = await fetch(`${process.env.SOURCE_PLUGIN_URL}/v1/parse`, {
|
||||
method: 'POST', headers: { 'content-type': 'application/json' },
|
||||
body: JSON.stringify({ plugin: 'unapproved', operation: 'catalog', input: { html: listHtml, url: seriesUrl } }),
|
||||
});
|
||||
assert.equal(response.status, 400);
|
||||
} finally {
|
||||
if (previous === undefined) delete process.env.SOURCE_PLUGIN_URL;
|
||||
else process.env.SOURCE_PLUGIN_URL = previous;
|
||||
await new Promise(resolve => server.close(resolve));
|
||||
}
|
||||
});
|
||||
|
||||
test('configured worker failure does not fall back to local parsing', async () => {
|
||||
const previous = process.env.SOURCE_PLUGIN_URL;
|
||||
process.env.SOURCE_PLUGIN_URL = 'http://127.0.0.1:1';
|
||||
try {
|
||||
await assert.rejects(parseSource('weebcentral', 'catalog', { html: listHtml, url: seriesUrl }));
|
||||
} finally {
|
||||
if (previous === undefined) delete process.env.SOURCE_PLUGIN_URL;
|
||||
else process.env.SOURCE_PLUGIN_URL = previous;
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user