From 0fc1a7b52aa88c8fda126df9498c1be64d891571 Mon Sep 17 00:00:00 2001 From: Codex Date: Tue, 13 Oct 2026 22:01:57 +0200 Subject: [PATCH] Mark sparse MangaDex hosted catalogs as partial --- scraper/adapters/mangadex.js | 6 +++++- scraper/test/mangadex-specials.test.js | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/scraper/adapters/mangadex.js b/scraper/adapters/mangadex.js index 2723beb..92638bf 100644 --- a/scraper/adapters/mangadex.js +++ b/scraper/adapters/mangadex.js @@ -72,6 +72,10 @@ function availabilitySummary(attributes, releases, chapters, externalReleases = const numbered = chapters.filter(ref => !ref.special); const expected = chapterNumber(attributes.lastChapter); const maximum = numbered.length ? Math.max(...numbered.map(ref => Number(ref.number))) : null; + // Reaching the final chapter number is not full coverage when the catalog + // contains fewer distinct numbered releases than the expected chapter span. + const expectedCount = expected && /^\d+$/.test(expected) ? Number(expected) : null; + const sparse = expectedCount && numbered.length < expectedCount; const reason = chapters.length ? null : externalReleases > 0 ? 'external-only' : Array.isArray(attributes.availableTranslatedLanguages) && !attributes.availableTranslatedLanguages.includes('en') ? 'no-english' : 'no-hosted-pages'; const message = reason === 'external-only' ? `MangaDex lists ${externalReleases} English external-link releases, but no hosted English pages. External links are not downloaded.` @@ -80,7 +84,7 @@ function availabilitySummary(attributes, releases, chapters, externalReleases = return { language: 'en', hostedReleases: releases.filter(r => !r.attributes?.externalUrl && Number(r.attributes?.pages) > 0).length, selectedChapters: chapters.length, numberedChapters: numbered.length, specialReleases: chapters.length - numbered.length, externalReleases, expectedLastChapter: expected, highestHostedChapter: maximum, - coverage: expected && (maximum === null || maximum < Number(expected)) ? 'partial' : 'unknown', reason, message }; + coverage: expected && (maximum === null || maximum < Number(expected) || sparse) ? 'partial' : 'unknown', reason, message }; } async function jsonGet(http, url) { diff --git a/scraper/test/mangadex-specials.test.js b/scraper/test/mangadex-specials.test.js index 5c70207..796b9d9 100644 --- a/scraper/test/mangadex-specials.test.js +++ b/scraper/test/mangadex-specials.test.js @@ -39,7 +39,9 @@ test('availability distinguishes no English, external-only, and partial hosted c const chapters = selectChapterReleases([release('regular-fixture', '336')]); const summary = availabilitySummary({ lastChapter: '686' }, [release('regular-fixture', '336')], chapters); assert.equal(summary.coverage, 'partial'); assert.equal(summary.selectedChapters, 1); - assert.equal(availabilitySummary({ lastChapter: '336' }, [], chapters).coverage, 'unknown', 'Highest number alone does not prove completeness'); + assert.equal(availabilitySummary({ lastChapter: '336' }, [], chapters).coverage, 'partial', 'One late chapter does not cover the earlier 335'); + const full = selectChapterReleases(['1', '2', '3'].map((number, index) => release(`full-${index}`, number))); + assert.equal(availabilitySummary({ lastChapter: '3' }, [], full).coverage, 'unknown', 'A plausible count is still not proof of whole-series completeness'); }); test('catalog uses separate external-only feed only when hosted selections are empty', async () => { @@ -130,6 +132,7 @@ test('inspection waits for confirmation, survives restart, and uses one normal s test('edition change after confirmation cannot silently download another edition', async () => { const service = Object.create(ScraperService.prototype); service.persist = async () => {}; + service.state = { sourceLedger: {} }; const item = { title: 'slug', confirmedSourceTitle: 'Pilot edition' }; await assert.rejects(service.recordCatalog(item, { title: 'Main edition', chapters: [] }), /edition title changed/); });