* docs: design spec for manga library type (host sub-project) Forks the ebooks library type into a 'manga' type: series detected from the folder tree as a first-class type='manga' item, .cbz/.cbr chapters stay readable ebook items linked via a new manga_chapters table, browse shows series cards, enrichment targets the series item at content level 'manga'. Hands off to a follow-on plugin spec for the manga metadata source. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * docs: implementation plan for manga library type (host) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(scanner): manga filename index/volume parser * feat(scanner): manga series-name-from-folder detection Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * docs(plan): align manga DB/scanner tasks to scanner pure-planner pattern (no test-DB) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test(scanner): manga parser corpus regression Add TestParseMangaIndexCorpus — 36 real-world scanlation filenames covering bare chapter, decimal chapter, v/vol-prefix volume, and c/ch-prefix chapter patterns; asserts <5% miss rate. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat(db): manga_chapters link table Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat(scanner): manga_chapters repository + pure chapter-write mapping Adds mangaChapterWrite (pure, unit-tested), upsertMangaChapter, and listMangaChapters following the ebook/audiobook thin-SQL pattern. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat(scanner): recognize manga library type Add isMangaLibraryType helper (unexported, matching the style of isEbookLibraryType / isAudiobookLibraryType) with a corresponding TestIsMangaLibraryType unit test. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat(api): manga library content level Map library type "manga" to content level ["manga"] in metadataContentLevelsForLibraryType so that seedDefaultChain seeds a manga-level metadata provider chain when a manga library is created. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat(scanner): route manga libraries to a manga scan path Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(scanner): group manga chapters under a manga series item Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(scanner): give manga series item a library membership so it browses Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(catalog): browse manga libraries as series Accept "manga" as a valid media_scope so a manga library browses only its type='manga' series items; the per-chapter type='ebook' items are naturally excluded because MediaScopeItemTypes("manga") expands to {"manga"}. Add the manga default library sections (scoped to media_scope='manga') so the library feed shows series cards. Refresh the two media_scope validation error messages. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(catalog): manga series detail lists chapters For a type='manga' item, attach its chapters to the detail response via a new MangaDetailExtension. fetchMangaChapters joins manga_chapters to media_items on the chapter content ID, scopes to the series, and orders by chapter_index (NULLS LAST) then sort_title — matching the scanner's chapter ordering. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(web): manga detail types + library browse scoping Add MangaChapter/MangaDetailExtension TS types mirroring the host catalog structs, wire manga? onto ItemDetail, and admit "manga" as a QueryDefinition.media_scope. Scope manga libraries to media_scope=manga in browse (host expands it to type=manga series items) while reusing the ebook sort universe via getLibrarySortRelevanceScope. Add isMangaLibraryType. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(web): manga series detail with volume-grouped chapter list Add MangaContent detail view: a DetailHero series header plus a chapter list grouped by volume. groupMangaChapters (pure, unit-tested) buckets chapters by their volume token, orders chapters within a group by chapter_index (nulls last) and orders groups by their minimum index; loose (volume-less) chapters collapse into a trailing "Chapters" group. Each chapter links to the existing ebook reader by content_id alone (file_id is optional — the reader resolves the file server-side), reusing buildMediaPlayHref. Admit "manga" into ItemDetail.type and wire the detail switch. Continue-reading is deferred (needs per-chapter progress fan-out / a last-read timestamp not in the current payload). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(web): handle manga in playable-type + collection filter-scope unions Adding "manga" to the shared ItemDetail["type"] and QueryDefinition["media_scope"] unions leaked into consumers with narrower local types, breaking the production tsc build. Fixes: - mediaNavigation: admit "manga" into PlayableMediaType. Manga series are not directly playable (you open the detail page and read a chapter, itself an ebook item), so buildMediaPlayHref falls through to the item href for them, like series/season. - FilterRuleEditor: add "manga" to FilterRuleMediaScope and relabel "watched" -> "Read" for manga as well as ebook (manga is read). - CollectionGuidedRulesEditor: add "manga" to GuidedFormState.mediaScope, a "Manga" media-type option, ebook-like "Read Status" labels, and map manga -> ebook sort-relevance scope (manga has no dedicated sort scope). - CatalogFilterBar (cascading leak surfaced after the above): add a "Manga" scope option and map manga -> ebook sort-relevance scope in both scope handlers. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(web): offer manga as a library type in the create dialog Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(scanner): strip scene-release junk from manga series names Add cleanMangaSeriesName which repeatedly strips trailing parenthetical groups (year, year-range, Digital, release-group tags) then trims any dangling dash, so folder names like "404 Demons (Digital) (Oak)" resolve to "404 Demons". Wire it into mangaSeriesFromPath so both the series title and the mangaSeriesGroupKey identity key use the cleaned value. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(web): flat volume/chapter manga list; nest only multi-chapter volumes Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(scanner): parse manga index after stripping series-name prefix Numbers inside a series title (e.g. "404 Demons", "365 Days to the Wedding") were wrongly grabbed as the chapter number because parseMangaIndex matched the first bare number in the full filename. mangaIndexForFile now strips the series-name prefix before delegating to parseMangaIndex, so only the number that follows the title is used. reconcileMangaFile in manga_scan.go is updated to call mangaIndexForFile instead of parseMangaIndex directly. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(scanner): stop missing-file reconcile from deleting manga series items Manga series items are file-less virtual parents; the shared ReconcileFolderMembership swept them every scan because they have no media_file. Exclude type='manga' from file-presence membership reconciliation, and add a manga-scan step that deletes only series with zero remaining chapters. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(ebooks): exclude manga chapters from individual ebook enrichment Manga chapters are type='ebook' parts of a series; the ebook enrichment sweep was searching each one against book sources (Gutenberg/Anna's/etc.) and failing in a pointless storm. Exclude items with a manga_chapters link; series-level enrichment is handled separately. * docs: design spec for manga metadata plugin + series enrichment (sub-project 2) New silo-plugin-manga-metadata (AniList, high-confidence matching) + a host MangaEnricher for type='manga' series; default-enabled metadata source for manga libraries. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * docs: implementation plan for manga metadata plugin + series enrichment Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(db): manga_enrichment_state table Mirrors ebook_enrichment_state: dedicated failure counter for the manga enrichment sweep so it does not contend with media_items.refresh_failures. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat(manga): series enricher (claims type='manga', resolves manga chain) * feat(manga): sync_manga_metadata task + enricher wiring * feat(catalog): expose manga chapter/volume counts in browse Add manga_chapter_count and manga_volume_count to browse cards so the frontend can render a Vols N / Ch N chip on manga series. The counts come from two index-backed correlated subqueries over manga_chapters in the browse SELECT (mangaCountColumns), scanned positionally before added_at and nilled out for non-manga rows. Threaded through models.MediaItem and exposed on the itemListResponse JSON card. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(sections): scope manga home recent sections to type=manga series A manga library mixes type='manga' series with type='ebook' chapters, so the auto-generated home 'Recently Added/Released in <Library>' rows surfaced the junk chapter filenames. Add GeneratedHomeLibraryRecentConfigScoped which emits the modern QueryDefinition shape (library_ids + media_scope) so a manga library's generated home rows filter to type='manga' only. Other library types are unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(catalog): exclude manga chapters from browse/section/search surfaces Manga CHAPTER items (type='ebook' rows linked into a type='manga' series via manga_chapters) were leaking into catalog browse, section resolution, and search as standalone items showing junk filenames. They are internal sub-units of the series and only the series should appear. There is no single shared item-listing chokepoint: browse, the query/preview executor, and search each build their own WHERE. Add a shared, index-backed anti-join predicate (manga_chapters.chapter_content_id is the PK) via mangaChapterExclusionWhere and wire it into all three builders. By-id fetch paths that legitimately resolve chapters (ebook reader, continue-reading, series detail chapter list) use separate queries and are unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(scanner): use #NN as the manga volume for Vol.YYYY #NN releases mangaVolYearIssue early-return was returning the year token (e.g. "Vol.2003") as the volume label, which the frontend couldn't prettify to "Volume N". Now returns "v<issue>" (e.g. "v04") so the existing frontend regex ^v?(\d+)$ renders it as "Volume 4" correctly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat(web): manga count chip on posters Add an optional manga_chapter_count / manga_volume_count to the browse item type and render a top-right "Vols N" / "Ch N" chip on ItemCard, strictly gated on type==='manga'. The label prefers "Vols" when the volume count dominates, "Ch" otherwise; the chip is hidden when the chapter count is missing or non-positive. No other card type renders it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(web): manga reader back returns to series (no loop) The ebook reader's back action defaulted to the chapter's own item detail (/item/<chapter>), whose back returned to the reader — an infinite loop for manga chapters. The reader now honors an explicit backTo search param when present, navigating there instead. Absent for normal ebooks, so their back behavior is unchanged. Only manga chapter rows pass backTo, keeping the fix manga-only. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(web): manga chapter row actions (read/mark-read/download) Each manga chapter/volume row now offers Read (the existing reader link, now carrying a backTo to the series), Mark-read (the shared watched-state mutation per chapter content_id), and Download (lazily fetches the chapter's file versions on demand and opens the shared DownloadVersionPicker, gated on user.download_allowed). The volume-unit / loose-chapter / section structure from buildMangaList is unchanged. Scoped to MangaContent only; EbookContent is untouched. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(web): validate reader backTo param is a safe in-app relative path Prevents open-redirect / javascript:-URI XSS from a crafted ?backTo= URL. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(catalog): include per-chapter read state in manga detail Manga chapters are ebook items, so a chapter is "read" when the viewer's ebook_reader_progress row crosses the finished threshold. fetchMangaChapters now LEFT JOINs that table scoped to the AccessFilter's user_id/profile_id and exposes a per-chapter Read bool on MangaChapter, threaded through buildMangaExtension. The detail payload previously carried no read state, so the row toggle always started unread. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(web): manga rows reflect read state on load MangaChapter now carries an optional read flag from the detail payload, and MangaRow seeds its mark-read toggle from chapter.read instead of always starting unread. The optimistic toggle + shared watched mutation are unchanged; only the initial value is seeded. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(sections): exclude manga chapters from recently-added/released/random + other library-listing sections Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(sections): manga recently-added/released cards show the latest volume's cover * fix(manga): keep enrichment honest about no-match vs enriched, batch 50->200 - sweep stats now separate enriched / no_match / failed: a stamped no-match was counted (and logged) as an enrichment, which masked a collapse of the real match rate during the backfill - batch size 50 -> 200 (SILO_MANGA_ENRICH_BATCH overrides): with the plugin serving GetMetadata from its search cache an item costs one rate-limited AniList request, so a sweep still fits the 5-minute task interval Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(manga): size enrich batch to the 5-minute interval at AniList's real budget 140 items x ~2.1s/request fits the interval; an overlong sweep makes the task manager drop the next trigger and the effective rate falls below the AniList budget. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(catalog): manga count chip data missing from library browse manga_chapter_count/manga_volume_count were only added to BrowseRepository, but /library/{id}?tab=library flows through previewQuerySource -> QueryExecutor.PreviewPage, which selects qualifiedListItemColumns and scans with scanItems - so manga cards never carried the counts and the Vols/Ch poster chip stayed hidden. Append mangaCountColumns to the preview-page SELECT and scan them via a new scanItemsWithMangaCounts (nil for non-manga rows, mirroring scanBrowseItems). Extract listItemScanDests so the three scan variants share one destination list instead of duplicating the 48-column scan. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(web): manga chip reads 'X Volumes · X Chapters', menu verbs say Read - chip: show distinct-volume and loose-chapter counts side by side instead of the single 'Vols N'/'Ch N' heuristic; mangaCountColumns now counts DISTINCT volume tokens (rows sharing a volume are one volume) and only un-volumed rows as chapters - watched-state labels: type='manga' fell through to the video default, so the card dot menu and detail page said 'Mark Watched' - manga now uses the ebook reading verbs (Mark Read / Mark Unread, 'Marked as read' toast) - format MangaContent.test.tsx (pre-existing prettier miss) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(manga): backdrop enrichment - banner hero art + backdrop-only backfill - cache remote backdrops like posters (cacheRemoteImages generalizes the poster-only path; failures keep the provider URL, which still renders) - claim arm for enriched items missing a backdrop: fetched by stored provider ID (search skipped - no rate spend, no re-match risk) and only the backdrop is written; stamping after the attempt keeps banner-less series from being re-claimed every sweep - backfill = one-time SQL clearing last_refreshed for poster-set/ backdrop-empty manga Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(manga): reading-loop UX - continue CTA, next chapter, series-aware cards, file details Fixes the four high-priority findings from the manga UX review plus a file-inspector request: - H1: series hero gets a Continue / Start Reading / Read Again CTA targeting the first unread chapter (firstUnreadChapter over the ordered list), plus an overflow menu (View Details, admin Refresh Metadata) - H2: the reader resolves its owning manga series (chapter detail now carries series_id/series_title) and offers next-chapter navigation: a header next button and an end-of-book floating CTA at >=99.5% progress; back defaults to the series even without a backTo param - H3: chapter rows show a persistent read check + muted title, and the mark-read mutation carries series_id so the series detail cache invalidates (read states no longer revert on revisit) - H4: continue-reading cards for manga chapters present the series: sections payload resolves chapter->series linkage, the card heading/image link to the series, and meta lines launch the reader - View Details: manga series menus (card dot menu + detail overflow) open a file inspector showing folder paths and per-chapter file names/sizes via GET /catalog/items/{id}/manga-files; paths are stripped for viewers without file-path visibility (item-versions policy) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(manga): UX mediums - richer detail page, smarter list, manga sort scope Second batch from the manga UX review (M1-M7): - M1: multi-chapter volume sections are collapsible (fully read sections start collapsed) with sticky headers, and long series get a 'Jump to <next unread>' anchor above the list - M2: the series hero shows the author line (HeroCrewLine learns Author credits with person links; DetailHero now renders crewLine and genre chips independently) and Volumes/Chapters badges - M3: browse-card count chip abbreviates to '12 Vol - 3 Ch' so it fits narrow cards without occluding covers - M4: manga gets its own sort scope: Duration/Bitrate (meaningless for file-less series rows) disappear, reading labels (Date Read / Reads) apply, Author stays - M5: global search labels manga results 'Manga' instead of the raw type - M6: chapters carry the viewer's reading fraction; part-read rows show an inline progress bar + percent - M7: chapter rows show the extracted cover thumbnail (presigned poster_url on the chapters payload) instead of a generic icon Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(manga): UX lows - volume token dedupe, comic reader chrome, empty-state hint - buildMangaList buckets volumes by canonical numeric token so mixed release naming (v01 + 1) yields one Volume 1 instead of duplicates - cbz/cbr readers start with the side panel closed and hide prose-only chrome (reading ruler, TTS, typography/font controls, hyphenation, writing mode) while keeping comic-relevant settings (theme, brightness, margin, right-to-left, spread, flow) - manga empty state mentions chapters appear after the library scan Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(manga): publication status badge via new SDK status field - vendor the unpublished plugin SDK (adds MetadataItem.status) under internal/compat/ with a relative go.mod replace, following the zishang520-webtransport-go convention; swap to the published module before the upstream PR - map plugin status into MetadataResult.ShowStatus, persist it during manga enrichment, and show it as the hero status badge (show_status was already on the detail payload and MetadataBadges) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(manga): generalize backdrop pass to secondary fields (backdrop + status) The backdrop-only claim arm becomes a secondary-fields pass: enriched items missing a backdrop and/or publication status are claimed, fetched by stored provider ID, and only the missing secondary fields are written. Lets the new status field backfill across the already-enriched library instead of applying only to future enrichments. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(metadata): merge ShowStatus through MergeMetadata/MergeGlobalMetadata The new MetadataResult.ShowStatus never reached the accumulated result the manga enricher persists from - the field-by-field merges didn't know it, so the status backfill pass obtained nothing. Regression-tested on both paths. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(manga): keep scanner identity IDs out of the metadata flow filterMangaProviderIDs passed the scanner's manga_series identity row through, so the search-skip-when-already-matched guard saw provider IDs on every item and never searched: unmatched items went straight to a by-ID fetch with no usable ID and were stamped as terminal no-match without a single provider request (and the MangaDex fallback was never consulted). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * chore: gitignore docker-compose.override.yml (local deployment override) The override unpublishes the bundled redis/postgres host ports (ports: !override []). It is a per-deployment, local-only file: ignoring it keeps a rebase from main and git clean -fd from disturbing it, and keeps it out of any PR. Its accidental absence once exposed Redis to the internet. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(manga): code-review fixes — no-match guard, sort comparator, volume-count consistency - enrichWithProviders: set accumulator.HasMetadata after a provider result merges (MergeMetadata doesn't propagate it). Without this, a confident match carrying only genres/authors/status/year but no cover and no overview failed the no-match check and was discarded + terminally stamped. - byChapterIndex: both un-indexed chapters yield POSITIVE_INFINITY, so the subtraction was Infinity-Infinity=NaN (Array.sort treats NaN as 0, leaving order undefined). Compare explicitly for a stable order. - MangaContent volume/chapter badges: derive counts from the rendered buildMangaList entries (which canonicalize v01 ≡ 1) instead of raw distinct volume tokens, so the badge can no longer say '2 Volumes' over one row. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * docs(manga): clarify the enrichment claim's secondary arm is admin-reset-only The secondary arm (poster present, backdrop/status missing) requires last_refreshed IS NULL, so it is only reachable when an operator resets last_refreshed to backfill a newly-added field — not an automatic periodic re-check (which would re-fetch banner-less series every sweep). Documents the intent so it does not read as dead code. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(manga): collapse continue-reading chapters per series; batch provider-id lookup - Continue Reading now collapses multiple in-progress chapters of the same manga into one card (most recently read kept), mirroring the episode→series collapse. The reading section resolves chapter→series linkage into itemMeta (applyMangaChapterSeriesMeta) and runs the shared collapseContinueWatchingSeriesCandidates, which the reading path previously skipped. - claimBatch resolves provider IDs for the whole batch in one query via the new ProviderIDRepository.GetByContentIDs (content_id = ANY), replacing the per-item GetByContentID N+1. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(web): manga publication-status chip on browse cards + more legible chips - Color-coded publication status pill (Ongoing/Completed/Hiatus/Cancelled/ Upcoming) in the manga card's top-left corner, mirroring the vol/chapter count chip top-right. Strictly manga-gated; show_status was already on the browse payload. - New .glass-chip (78% surface vs glass-subtle's 40%) for the manga count + status pills so the labels stay legible over busy cover art. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * build(manga): depend on published silo-plugin-sdk v0.7.0 Replace the vendored internal/compat/silo-plugin-sdk copy with a normal dependency on the published SDK module at v0.7.0, which adds MetadataItem.status (publication/airing status) consumed by the manga status badge at internal/metadata/plugin_provider.go. - go.mod: pin v0.7.0, drop the local-path replace directive - remove the vendored internal/compat/silo-plugin-sdk tree - Dockerfile: drop the vendored-SDK COPY - strip the manga design docs/plans from docs/superpowers (internal) Requires Silo-Server/silo-plugin-sdk#4 merged and tagged v0.7.0. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(manga): exclude chapters from the matcher's unmatched-item lister Manga chapters are type='ebook' items that stay status='pending' by design - provider metadata lives on the type='manga' series item. The scan-final RetryUnmatchedItemsByFolderAndPathPrefix listed all of them and ran a rate-limited ebook-plugin search per chapter: 31,564 chapters x ~1s = 8h46m appended to a 2-minute manga library scan (observed live), every one a guaranteed no-match. Earlier runs never survived to completion, so the library's last_scanned_at stayed NULL forever. Add the same manga_chapters NOT EXISTS guard the ebook enricher's claim query already uses. Verified live: the same library now scans in 27s with retried_items=0. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(scanner): never probe-repair ebook/comic files (ebook+manga detail-page killer) NeedsCriticalProbeRepair was always true for BaseType 'ebook' files (epub, pdf, cbz, cbr — incl. manga chapters): buildEbookMediaFile leaves ProbeUpdatedAt nil and they have no audio/video, so probeEnsurer.Ensure spawned ffprobe per file on every detail/watch load and never converged (ffprobe errors on zip/rar, result never persisted). Short-circuit probe-repair for ebook base type — they're read directly and never use the transcode/playback probe pipeline. SHARED fix: benefits both the ebooks and manga library types. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * perf+fix(ebooks): parallelize detail extension + preserve finished read-state - buildEbookExtension ran its 3 related-content queries (series, also-by-author, similar) sequentially; run them concurrently like buildAudiobookExtension so ebook detail latency is the slowest query, not their sum. - PGEbookReaderProgressStore.Upsert did an unconditional SET progress=EXCLUDED; a routine autosave (e.g. reopening a finished book) could drop it below the 0.9 finished threshold and silently un-mark it read (and clear the manga chapter checkmark, which rides on the same row). Guard: once finished, progress only moves on an explicit unread (row delete); below threshold it tracks freely. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * perf(manga): batch chapter presign, index volume counts, quiet scan log - fetchMangaChapters presigned each chapter poster individually; a long-running series has hundreds of chapters. Batch them in one PresignImageURLs call, and add the missing rows.Err() check (was silently returning partial lists). - The browse manga count chip's count(DISTINCT volume) subquery wasn't covered by manga_chapters_series (series_content_id, chapter_index); add idx_manga_chapters_series_volume (series_content_id, volume) so both count subqueries are index-only. - Downgrade the per-chapter "manga scan: indexed" log from Info to Debug (one line per .cbz; the 500-file progress log already covers operator visibility). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(manga): address PR #138 code-review findings Folds PR #142 into the manga branch (already done via fast-forward) and remediates the issues surfaced in the #138 code review. Correctness: - Preserve the scanner's manga_series identity anchor through enrichment. ReplaceByContentID's DELETE was unconditional, so the first successful enrichment wiped the manga_series provider-id row the scanner relies on for idempotency, causing duplicate series + metadata loss on the next scan. excludedProviderIDs now also means "not deleted", and the DELETE preserves those rows. (internal/catalog/provider_id_repo.go) - Fall back to the series cover when the latest chapter has no poster. Poster columns default to '' (not NULL), so the manga series-card poster override blanked cards via a plain COALESCE; wrap operands in NULLIF. (internal/sections/fetcher.go) - Keep backTo a real query param on reader links when libraryId is absent. It was string-concatenated with '&', producing a malformed URL on deep-links; route it through the query helper instead. (web/src/lib/mediaNavigation.ts, EbookReader.tsx, MangaContent.tsx) Quality: - Hide manga chapters from favorites/watchlist browse, matching the exclusion enforced on every other listing surface. (internal/catalog/favorites_browse.go) - Centralize the manga chapter exclusion predicate into a single exported catalog.MangaChapterExclusionWhere, removing four duplicated copies. (catalog, sections, ebooks) - Skip the two manga count subqueries on browse scopes that cannot contain manga (non-manga type filters), substituting NULL placeholders. (internal/catalog/browse.go) - Normalize provider publication status (AniList/MangaDex/SDK variants) into a stable label set so show_status carries one manga value-domain. (internal/manga/enrichment.go) Adds unit tests for the poster NULLIF contract, browse gating, and status normalization. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * chore: regenerate go.sum after rebase onto main Drops stale silo-plugin-sdk v0.6.0 and other leftover hashes from the intermediate rebased states; go.mod is now on the published v0.7.0 tag. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(scanner): adapt manga scan to ebookFileShouldSkip 3-value signature main changed ebookFileShouldSkip to also return the existing content ID; the manga scan path only needs the unchanged flag, so discard the new return. Resolves a silent semantic conflict from the rebase onto main. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Silo Server Developer <warmasterx555@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
609 lines
22 KiB
Go
609 lines
22 KiB
Go
package sections
|
||
|
||
import (
|
||
"encoding/json"
|
||
"testing"
|
||
|
||
"github.com/Silo-Server/silo-server/internal/catalog"
|
||
"github.com/Silo-Server/silo-server/internal/models"
|
||
)
|
||
|
||
func TestDefaultHomeSectionsWithoutLibraries(t *testing.T) {
|
||
sections := DefaultHomeSections(nil)
|
||
// 1 continue-watching + 3 recipe-rich defaults (hidden_gems, trending, seasonal-auto-cycle)
|
||
if len(sections) != 4 {
|
||
t.Fatalf("expected 4 default home sections, got %d", len(sections))
|
||
}
|
||
if sections[0].SectionType != SectionContinueWatching {
|
||
t.Fatalf("expected continue watching, got %s", sections[0].SectionType)
|
||
}
|
||
assertContinueType(t, sections[0].Config, ContinueTypeWatching)
|
||
}
|
||
|
||
func TestDefaultHomeSectionsWithLibraries(t *testing.T) {
|
||
libraries := []*models.MediaFolder{
|
||
{ID: 7, Name: "Movies", Type: "movies", SortOrder: 1},
|
||
{ID: 9, Name: "Shows", Type: "series", SortOrder: 2},
|
||
}
|
||
|
||
got := DefaultHomeSections(libraries)
|
||
// 1 continue-watching + 2 libraries × 2 types + 3 recipe-rich defaults
|
||
if len(got) != 8 {
|
||
t.Fatalf("expected 8 default home sections, got %d", len(got))
|
||
}
|
||
|
||
tests := []struct {
|
||
index int
|
||
id string
|
||
sectionType SectionType
|
||
title string
|
||
position int
|
||
libraryID int
|
||
}{
|
||
{index: 0, id: "default-continue-watching", sectionType: SectionContinueWatching, title: "Continue Watching", position: 0},
|
||
{index: 1, id: "default-home-recently_added-library-7", sectionType: SectionRecentlyAdded, title: "Recently Added in Movies", position: 1, libraryID: 7},
|
||
{index: 2, id: "default-home-recently_released-library-7", sectionType: SectionRecentlyReleased, title: "Recently Released in Movies", position: 2, libraryID: 7},
|
||
{index: 3, id: "default-home-recently_added-library-9", sectionType: SectionRecentlyAdded, title: "Recently Added in Shows", position: 3, libraryID: 9},
|
||
{index: 4, id: "default-home-recently_released_episodes-library-9", sectionType: SectionCustomFilter, title: "Recently Released Episodes in Shows", position: 4, libraryID: 9},
|
||
}
|
||
|
||
for _, tt := range tests {
|
||
section := got[tt.index]
|
||
if section.ID != tt.id {
|
||
t.Fatalf("section %d id = %q, want %q", tt.index, section.ID, tt.id)
|
||
}
|
||
if section.SectionType != tt.sectionType {
|
||
t.Fatalf("section %d type = %q, want %q", tt.index, section.SectionType, tt.sectionType)
|
||
}
|
||
if section.Title != tt.title {
|
||
t.Fatalf("section %d title = %q, want %q", tt.index, section.Title, tt.title)
|
||
}
|
||
if section.Position != tt.position {
|
||
t.Fatalf("section %d position = %d, want %d", tt.index, section.Position, tt.position)
|
||
}
|
||
if tt.libraryID == 0 {
|
||
assertContinueType(t, section.Config, ContinueTypeWatching)
|
||
continue
|
||
}
|
||
libraryID, ok := ParseGeneratedHomeLibraryRecentConfig(section.Config)
|
||
if !ok {
|
||
t.Fatalf("section %d expected generated home config", tt.index)
|
||
}
|
||
if libraryID != tt.libraryID {
|
||
t.Fatalf("section %d config library id = %d, want %d", tt.index, libraryID, tt.libraryID)
|
||
}
|
||
}
|
||
|
||
assertQueryDefinition(t, got[4].Config, catalog.QueryDefinition{
|
||
LibraryIDs: []int{9},
|
||
MediaScope: "episode",
|
||
Match: "all",
|
||
Groups: []catalog.QueryGroup{},
|
||
Sort: catalog.QuerySort{Field: "release_date", Order: "desc"},
|
||
})
|
||
}
|
||
|
||
func TestDefaultHomeSectionsWithAudiobookLibrary(t *testing.T) {
|
||
libraries := []*models.MediaFolder{
|
||
{ID: 7, Name: "Movies", Type: "movies", SortOrder: 1},
|
||
{ID: 10, Name: "Books", Type: "audiobooks", SortOrder: 2},
|
||
}
|
||
|
||
got := DefaultHomeSections(libraries)
|
||
if len(got) != 9 {
|
||
t.Fatalf("expected 9 default home sections, got %d", len(got))
|
||
}
|
||
|
||
tests := []struct {
|
||
index int
|
||
id string
|
||
title string
|
||
position int
|
||
continueType ContinueType
|
||
}{
|
||
{index: 0, id: "default-continue-watching", title: "Continue Watching", position: 0, continueType: ContinueTypeWatching},
|
||
{index: 1, id: "default-continue-listening", title: "Continue Listening", position: 1, continueType: ContinueTypeListening},
|
||
}
|
||
for _, tt := range tests {
|
||
section := got[tt.index]
|
||
if section.ID != tt.id {
|
||
t.Fatalf("section %d id = %q, want %q", tt.index, section.ID, tt.id)
|
||
}
|
||
if section.Title != tt.title {
|
||
t.Fatalf("section %d title = %q, want %q", tt.index, section.Title, tt.title)
|
||
}
|
||
if section.Position != tt.position {
|
||
t.Fatalf("section %d position = %d, want %d", tt.index, section.Position, tt.position)
|
||
}
|
||
assertContinueType(t, section.Config, tt.continueType)
|
||
}
|
||
|
||
if got[2].Position != 2 || got[2].Title != "Recently Added in Movies" {
|
||
t.Fatalf("first generated library row = position %d title %q", got[2].Position, got[2].Title)
|
||
}
|
||
}
|
||
|
||
func TestDefaultLibrarySectionsForTypeMovies(t *testing.T) {
|
||
libraryID := 42
|
||
got := DefaultLibrarySectionsForType(&libraryID, "movies")
|
||
|
||
if len(got) != 6 {
|
||
t.Fatalf("expected 6 movie default sections, got %d", len(got))
|
||
}
|
||
|
||
tests := []struct {
|
||
index int
|
||
id string
|
||
sectionType SectionType
|
||
title string
|
||
position int
|
||
}{
|
||
{index: 0, id: "default-continue-watching", sectionType: SectionContinueWatching, title: "Continue Watching", position: 0},
|
||
{index: 1, id: "default-recently-added-movies", sectionType: SectionRecentlyAdded, title: "Recently Added Movies", position: 1},
|
||
{index: 2, id: "default-recently-released-movies", sectionType: SectionRecentlyReleased, title: "Recently Released Movies", position: 2},
|
||
{index: 3, id: "default-top-rated-movies", sectionType: SectionCustomFilter, title: "Top Rated Movies", position: 3},
|
||
{index: 4, id: "default-recommended-for-you", sectionType: SectionRecommendedForYou, title: "Recommended for You", position: 4},
|
||
{index: 5, id: "default-random-movies", sectionType: SectionRandom, title: "Random Picks", position: 5},
|
||
}
|
||
|
||
for _, tt := range tests {
|
||
section := got[tt.index]
|
||
if section.ID != tt.id {
|
||
t.Fatalf("section %d id = %q, want %q", tt.index, section.ID, tt.id)
|
||
}
|
||
if section.SectionType != tt.sectionType {
|
||
t.Fatalf("section %d type = %q, want %q", tt.index, section.SectionType, tt.sectionType)
|
||
}
|
||
if section.Title != tt.title {
|
||
t.Fatalf("section %d title = %q, want %q", tt.index, section.Title, tt.title)
|
||
}
|
||
if section.Position != tt.position {
|
||
t.Fatalf("section %d position = %d, want %d", tt.index, section.Position, tt.position)
|
||
}
|
||
if section.Featured {
|
||
t.Fatalf("section %d featured = true, want false", tt.index)
|
||
}
|
||
}
|
||
assertContinueType(t, got[0].Config, ContinueTypeWatching)
|
||
|
||
assertQueryDefinition(t, got[1].Config, catalog.QueryDefinition{
|
||
MediaScope: "movie",
|
||
Match: "all",
|
||
Groups: []catalog.QueryGroup{},
|
||
Sort: catalog.QuerySort{Field: "added_at", Order: "desc"},
|
||
})
|
||
assertQueryDefinition(t, got[3].Config, catalog.QueryDefinition{
|
||
MediaScope: "movie",
|
||
Match: "all",
|
||
Groups: []catalog.QueryGroup{},
|
||
Sort: catalog.QuerySort{Field: "rating_imdb", Order: "desc"},
|
||
})
|
||
assertEmptyJSON(t, got[4].Config)
|
||
assertQueryDefinition(t, got[5].Config, catalog.QueryDefinition{
|
||
MediaScope: "movie",
|
||
Match: "all",
|
||
Groups: []catalog.QueryGroup{},
|
||
Sort: catalog.QuerySort{Field: "added_at", Order: "desc"},
|
||
})
|
||
}
|
||
|
||
func TestDefaultLibrarySectionsForTypeSeries(t *testing.T) {
|
||
libraryID := 17
|
||
got := DefaultLibrarySectionsForType(&libraryID, "series")
|
||
|
||
if len(got) != 6 {
|
||
t.Fatalf("expected 6 series default sections, got %d", len(got))
|
||
}
|
||
|
||
tests := []struct {
|
||
index int
|
||
id string
|
||
sectionType SectionType
|
||
title string
|
||
position int
|
||
}{
|
||
{index: 0, id: "default-continue-watching", sectionType: SectionContinueWatching, title: "Continue Watching", position: 0},
|
||
{index: 1, id: "default-recently-added-tv", sectionType: SectionRecentlyAdded, title: "Recently Added TV", position: 1},
|
||
{index: 2, id: "default-recently-released-episodes", sectionType: SectionCustomFilter, title: "Recently Released Episodes", position: 2},
|
||
{index: 3, id: "default-top-rated-tv", sectionType: SectionCustomFilter, title: "Top Rated TV", position: 3},
|
||
{index: 4, id: "default-recommended-for-you", sectionType: SectionRecommendedForYou, title: "Recommended for You", position: 4},
|
||
{index: 5, id: "default-random-tv", sectionType: SectionRandom, title: "Random Picks", position: 5},
|
||
}
|
||
|
||
for _, tt := range tests {
|
||
section := got[tt.index]
|
||
if section.ID != tt.id {
|
||
t.Fatalf("section %d id = %q, want %q", tt.index, section.ID, tt.id)
|
||
}
|
||
if section.SectionType != tt.sectionType {
|
||
t.Fatalf("section %d type = %q, want %q", tt.index, section.SectionType, tt.sectionType)
|
||
}
|
||
if section.Title != tt.title {
|
||
t.Fatalf("section %d title = %q, want %q", tt.index, section.Title, tt.title)
|
||
}
|
||
if section.Position != tt.position {
|
||
t.Fatalf("section %d position = %d, want %d", tt.index, section.Position, tt.position)
|
||
}
|
||
if section.Featured {
|
||
t.Fatalf("section %d featured = true, want false", tt.index)
|
||
}
|
||
}
|
||
assertContinueType(t, got[0].Config, ContinueTypeWatching)
|
||
|
||
assertQueryDefinition(t, got[1].Config, catalog.QueryDefinition{
|
||
MediaScope: "series",
|
||
Match: "all",
|
||
Groups: []catalog.QueryGroup{},
|
||
Sort: catalog.QuerySort{Field: "added_at", Order: "desc"},
|
||
})
|
||
assertQueryDefinition(t, got[2].Config, catalog.QueryDefinition{
|
||
MediaScope: "episode",
|
||
Match: "all",
|
||
Groups: []catalog.QueryGroup{},
|
||
Sort: catalog.QuerySort{Field: "release_date", Order: "desc"},
|
||
})
|
||
assertQueryDefinition(t, got[3].Config, catalog.QueryDefinition{
|
||
MediaScope: "series",
|
||
Match: "all",
|
||
Groups: []catalog.QueryGroup{},
|
||
Sort: catalog.QuerySort{Field: "rating_imdb", Order: "desc"},
|
||
})
|
||
assertEmptyJSON(t, got[4].Config)
|
||
assertQueryDefinition(t, got[5].Config, catalog.QueryDefinition{
|
||
MediaScope: "series",
|
||
Match: "all",
|
||
Groups: []catalog.QueryGroup{},
|
||
Sort: catalog.QuerySort{Field: "added_at", Order: "desc"},
|
||
})
|
||
}
|
||
|
||
func TestDefaultLibrarySectionsForTypeAudiobooks(t *testing.T) {
|
||
libraryID := 10
|
||
got := DefaultLibrarySectionsForType(&libraryID, "audiobooks")
|
||
|
||
if len(got) != 6 {
|
||
t.Fatalf("expected 6 audiobook default sections, got %d", len(got))
|
||
}
|
||
|
||
tests := []struct {
|
||
index int
|
||
id string
|
||
sectionType SectionType
|
||
title string
|
||
position int
|
||
featured bool
|
||
}{
|
||
{index: 0, id: "default-continue-listening", sectionType: SectionContinueWatching, title: "Continue Listening", position: 0, featured: true},
|
||
{index: 1, id: "default-next-in-series", sectionType: SectionNextInSeries, title: "Next in Your Series", position: 1},
|
||
{index: 2, id: "default-recently-added-audiobooks", sectionType: SectionRecentlyAdded, title: "Recently Added Audiobooks", position: 2},
|
||
{index: 3, id: "default-recently-released-audiobooks", sectionType: SectionRecentlyReleased, title: "Recently Released Audiobooks", position: 3},
|
||
{index: 4, id: "default-recommended-for-you", sectionType: SectionRecommendedForYou, title: "Recommended for You", position: 4},
|
||
{index: 5, id: "default-random-audiobooks", sectionType: SectionRandom, title: "Random Picks", position: 5},
|
||
}
|
||
|
||
for _, tt := range tests {
|
||
section := got[tt.index]
|
||
if section.ID != tt.id {
|
||
t.Fatalf("section %d id = %q, want %q", tt.index, section.ID, tt.id)
|
||
}
|
||
if section.SectionType != tt.sectionType {
|
||
t.Fatalf("section %d type = %q, want %q", tt.index, section.SectionType, tt.sectionType)
|
||
}
|
||
if section.Title != tt.title {
|
||
t.Fatalf("section %d title = %q, want %q", tt.index, section.Title, tt.title)
|
||
}
|
||
if section.Position != tt.position {
|
||
t.Fatalf("section %d position = %d, want %d", tt.index, section.Position, tt.position)
|
||
}
|
||
if section.Featured != tt.featured {
|
||
t.Fatalf("section %d featured = %v, want %v", tt.index, section.Featured, tt.featured)
|
||
}
|
||
}
|
||
assertContinueType(t, got[0].Config, ContinueTypeListening)
|
||
|
||
assertEmptyJSON(t, got[1].Config)
|
||
assertQueryDefinition(t, got[2].Config, catalog.QueryDefinition{
|
||
MediaScope: "audiobook",
|
||
Match: "all",
|
||
Groups: []catalog.QueryGroup{},
|
||
Sort: catalog.QuerySort{Field: "added_at", Order: "desc"},
|
||
})
|
||
assertQueryDefinition(t, got[3].Config, catalog.QueryDefinition{
|
||
MediaScope: "audiobook",
|
||
Match: "all",
|
||
Groups: []catalog.QueryGroup{},
|
||
Sort: catalog.QuerySort{Field: "added_at", Order: "desc"},
|
||
})
|
||
assertEmptyJSON(t, got[4].Config)
|
||
assertQueryDefinition(t, got[5].Config, catalog.QueryDefinition{
|
||
MediaScope: "audiobook",
|
||
Match: "all",
|
||
Groups: []catalog.QueryGroup{},
|
||
Sort: catalog.QuerySort{Field: "added_at", Order: "desc"},
|
||
})
|
||
}
|
||
|
||
func TestDefaultLibrarySectionsForTypeEbooks(t *testing.T) {
|
||
libraryID := 11
|
||
got := DefaultLibrarySectionsForType(&libraryID, "ebooks")
|
||
|
||
if len(got) != 5 {
|
||
t.Fatalf("expected 5 ebook default sections, got %d", len(got))
|
||
}
|
||
|
||
tests := []struct {
|
||
index int
|
||
id string
|
||
sectionType SectionType
|
||
title string
|
||
position int
|
||
}{
|
||
{index: 0, id: "default-continue-reading", sectionType: SectionContinueWatching, title: "Continue Reading", position: 0},
|
||
{index: 1, id: "default-recently-added-ebooks", sectionType: SectionRecentlyAdded, title: "Recently Added Ebooks", position: 1},
|
||
{index: 2, id: "default-recently-released-ebooks", sectionType: SectionRecentlyReleased, title: "Recently Released Ebooks", position: 2},
|
||
{index: 3, id: "default-recommended-for-you", sectionType: SectionRecommendedForYou, title: "Recommended for You", position: 3},
|
||
{index: 4, id: "default-random-ebooks", sectionType: SectionRandom, title: "Random Picks", position: 4},
|
||
}
|
||
|
||
for _, tt := range tests {
|
||
section := got[tt.index]
|
||
if section.ID != tt.id {
|
||
t.Fatalf("section %d id = %q, want %q", tt.index, section.ID, tt.id)
|
||
}
|
||
if section.SectionType != tt.sectionType {
|
||
t.Fatalf("section %d type = %q, want %q", tt.index, section.SectionType, tt.sectionType)
|
||
}
|
||
if section.Title != tt.title {
|
||
t.Fatalf("section %d title = %q, want %q", tt.index, section.Title, tt.title)
|
||
}
|
||
if section.Position != tt.position {
|
||
t.Fatalf("section %d position = %d, want %d", tt.index, section.Position, tt.position)
|
||
}
|
||
if section.Featured {
|
||
t.Fatalf("section %d featured = true, want false", tt.index)
|
||
}
|
||
}
|
||
|
||
assertContinueType(t, got[0].Config, ContinueTypeReading)
|
||
assertQueryDefinition(t, got[1].Config, catalog.QueryDefinition{
|
||
MediaScope: "ebook",
|
||
Match: "all",
|
||
Groups: []catalog.QueryGroup{},
|
||
Sort: catalog.QuerySort{Field: "added_at", Order: "desc"},
|
||
})
|
||
assertQueryDefinition(t, got[2].Config, catalog.QueryDefinition{
|
||
MediaScope: "ebook",
|
||
Match: "all",
|
||
Groups: []catalog.QueryGroup{},
|
||
Sort: catalog.QuerySort{Field: "added_at", Order: "desc"},
|
||
})
|
||
assertEmptyJSON(t, got[3].Config)
|
||
assertQueryDefinition(t, got[4].Config, catalog.QueryDefinition{
|
||
MediaScope: "ebook",
|
||
Match: "all",
|
||
Groups: []catalog.QueryGroup{},
|
||
Sort: catalog.QuerySort{Field: "added_at", Order: "desc"},
|
||
})
|
||
}
|
||
|
||
func TestDefaultLibrarySectionsForTypeManga(t *testing.T) {
|
||
libraryID := 13
|
||
got := DefaultLibrarySectionsForType(&libraryID, "manga")
|
||
|
||
if len(got) != 5 {
|
||
t.Fatalf("expected 5 manga default sections, got %d", len(got))
|
||
}
|
||
|
||
tests := []struct {
|
||
index int
|
||
id string
|
||
sectionType SectionType
|
||
title string
|
||
position int
|
||
}{
|
||
{index: 0, id: "default-continue-reading", sectionType: SectionContinueWatching, title: "Continue Reading", position: 0},
|
||
{index: 1, id: "default-recently-added-manga", sectionType: SectionRecentlyAdded, title: "Recently Added Manga", position: 1},
|
||
{index: 2, id: "default-recently-released-manga", sectionType: SectionRecentlyReleased, title: "Recently Released Manga", position: 2},
|
||
{index: 3, id: "default-recommended-for-you", sectionType: SectionRecommendedForYou, title: "Recommended for You", position: 3},
|
||
{index: 4, id: "default-random-manga", sectionType: SectionRandom, title: "Random Picks", position: 4},
|
||
}
|
||
|
||
for _, tt := range tests {
|
||
section := got[tt.index]
|
||
if section.ID != tt.id {
|
||
t.Fatalf("section %d id = %q, want %q", tt.index, section.ID, tt.id)
|
||
}
|
||
if section.SectionType != tt.sectionType {
|
||
t.Fatalf("section %d type = %q, want %q", tt.index, section.SectionType, tt.sectionType)
|
||
}
|
||
if section.Title != tt.title {
|
||
t.Fatalf("section %d title = %q, want %q", tt.index, section.Title, tt.title)
|
||
}
|
||
if section.Position != tt.position {
|
||
t.Fatalf("section %d position = %d, want %d", tt.index, section.Position, tt.position)
|
||
}
|
||
}
|
||
|
||
// The manga library browses only its series items: every query section is
|
||
// scoped to media_items.type='manga', so the per-chapter ebook items are
|
||
// excluded from the library feed.
|
||
assertContinueType(t, got[0].Config, ContinueTypeReading)
|
||
mangaScope := catalog.QueryDefinition{
|
||
MediaScope: "manga",
|
||
Match: "all",
|
||
Groups: []catalog.QueryGroup{},
|
||
Sort: catalog.QuerySort{Field: "added_at", Order: "desc"},
|
||
}
|
||
assertQueryDefinition(t, got[1].Config, mangaScope)
|
||
assertQueryDefinition(t, got[2].Config, mangaScope)
|
||
assertEmptyJSON(t, got[3].Config)
|
||
assertQueryDefinition(t, got[4].Config, mangaScope)
|
||
}
|
||
|
||
func TestDefaultLibrarySectionsForTypeMixed(t *testing.T) {
|
||
libraryID := 99
|
||
got := DefaultLibrarySectionsForType(&libraryID, "mixed")
|
||
|
||
if len(got) != 3 {
|
||
t.Fatalf("expected 3 mixed default sections, got %d", len(got))
|
||
}
|
||
|
||
tests := []struct {
|
||
index int
|
||
id string
|
||
sectionType SectionType
|
||
title string
|
||
position int
|
||
}{
|
||
{index: 0, id: "default-continue-watching", sectionType: SectionContinueWatching, title: "Continue Watching", position: 0},
|
||
{index: 1, id: "default-recently-added", sectionType: SectionRecentlyAdded, title: "Recently Added", position: 1},
|
||
{index: 2, id: "default-recently-released", sectionType: SectionRecentlyReleased, title: "Recently Released", position: 2},
|
||
}
|
||
|
||
for _, tt := range tests {
|
||
section := got[tt.index]
|
||
if section.ID != tt.id {
|
||
t.Fatalf("section %d id = %q, want %q", tt.index, section.ID, tt.id)
|
||
}
|
||
if section.SectionType != tt.sectionType {
|
||
t.Fatalf("section %d type = %q, want %q", tt.index, section.SectionType, tt.sectionType)
|
||
}
|
||
if section.Title != tt.title {
|
||
t.Fatalf("section %d title = %q, want %q", tt.index, section.Title, tt.title)
|
||
}
|
||
if section.Position != tt.position {
|
||
t.Fatalf("section %d position = %d, want %d", tt.index, section.Position, tt.position)
|
||
}
|
||
}
|
||
assertContinueType(t, got[0].Config, ContinueTypeWatching)
|
||
}
|
||
|
||
func assertQueryDefinition(t *testing.T, raw json.RawMessage, want catalog.QueryDefinition) {
|
||
t.Helper()
|
||
|
||
got, err := ParseQueryDefinition(raw)
|
||
if err != nil {
|
||
t.Fatalf("ParseQueryDefinition() error = %v", err)
|
||
}
|
||
|
||
got = got.Normalize()
|
||
want = want.Normalize()
|
||
|
||
if got.MediaScope != want.MediaScope {
|
||
t.Fatalf("media_scope = %q, want %q", got.MediaScope, want.MediaScope)
|
||
}
|
||
if got.Match != want.Match {
|
||
t.Fatalf("match = %q, want %q", got.Match, want.Match)
|
||
}
|
||
if got.Sort != want.Sort {
|
||
t.Fatalf("sort = %+v, want %+v", got.Sort, want.Sort)
|
||
}
|
||
if len(got.Groups) != len(want.Groups) {
|
||
t.Fatalf("groups len = %d, want %d", len(got.Groups), len(want.Groups))
|
||
}
|
||
for i := range want.Groups {
|
||
if got.Groups[i].Match != want.Groups[i].Match {
|
||
t.Fatalf("groups[%d].match = %q, want %q", i, got.Groups[i].Match, want.Groups[i].Match)
|
||
}
|
||
if len(got.Groups[i].Rules) != len(want.Groups[i].Rules) {
|
||
t.Fatalf("groups[%d].rules len = %d, want %d", i, len(got.Groups[i].Rules), len(want.Groups[i].Rules))
|
||
}
|
||
for j := range want.Groups[i].Rules {
|
||
if got.Groups[i].Rules[j] != want.Groups[i].Rules[j] {
|
||
t.Fatalf("groups[%d].rules[%d] = %+v, want %+v", i, j, got.Groups[i].Rules[j], want.Groups[i].Rules[j])
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
func assertEmptyJSON(t *testing.T, raw json.RawMessage) {
|
||
t.Helper()
|
||
if string(raw) != "{}" {
|
||
t.Fatalf("config = %s, want {}", string(raw))
|
||
}
|
||
}
|
||
|
||
func assertContinueType(t *testing.T, raw json.RawMessage, want ContinueType) {
|
||
t.Helper()
|
||
got, err := ParseContinueType(raw)
|
||
if err != nil {
|
||
t.Fatalf("ParseContinueType(%s): %v", string(raw), err)
|
||
}
|
||
if got != want {
|
||
t.Fatalf("continue_type = %q, want %q (config %s)", got, want, string(raw))
|
||
}
|
||
}
|
||
|
||
func TestHomeDefaultsIncludeRecipeRichSet(t *testing.T) {
|
||
defs := DefaultHomeSections(nil)
|
||
want := []SectionType{
|
||
SectionContinueWatching,
|
||
SectionHiddenGems,
|
||
SectionTrendingOnServer,
|
||
SectionSeasonalThemed,
|
||
}
|
||
for _, w := range want {
|
||
found := false
|
||
for _, d := range defs {
|
||
if d.SectionType == w {
|
||
found = true
|
||
break
|
||
}
|
||
}
|
||
if !found {
|
||
t.Errorf("default home sections missing %s", w)
|
||
}
|
||
}
|
||
}
|
||
|
||
func TestGeneratedHomeLibraryRecentDefaultsMangaScope(t *testing.T) {
|
||
got := generatedHomeLibraryRecentDefaults(7, "Manga", "manga")
|
||
if len(got) != 2 {
|
||
t.Fatalf("expected 2 generated manga home sections, got %d", len(got))
|
||
}
|
||
|
||
wantTitles := map[SectionType]string{
|
||
SectionRecentlyAdded: "Recently Added in Manga",
|
||
SectionRecentlyReleased: "Recently Released in Manga",
|
||
}
|
||
for _, sec := range got {
|
||
wantTitle, ok := wantTitles[sec.SectionType]
|
||
if !ok {
|
||
t.Fatalf("unexpected section type %s", sec.SectionType)
|
||
}
|
||
if sec.Title != wantTitle {
|
||
t.Fatalf("section %s title = %q, want %q", sec.SectionType, sec.Title, wantTitle)
|
||
}
|
||
|
||
def, err := ParseQueryDefinition(sec.Config)
|
||
if err != nil {
|
||
t.Fatalf("ParseQueryDefinition(%s) error = %v", sec.SectionType, err)
|
||
}
|
||
if def.MediaScope != "manga" {
|
||
t.Fatalf("section %s media_scope = %q, want manga", sec.SectionType, def.MediaScope)
|
||
}
|
||
if len(def.LibraryIDs) != 1 || def.LibraryIDs[0] != 7 {
|
||
t.Fatalf("section %s library_ids = %v, want [7]", sec.SectionType, def.LibraryIDs)
|
||
}
|
||
if id, ok := ParseGeneratedHomeLibraryRecentConfig(sec.Config); !ok || id != 7 {
|
||
t.Fatalf("section %s generated config id = %d ok = %v, want 7 true", sec.SectionType, id, ok)
|
||
}
|
||
}
|
||
}
|
||
|
||
func TestGeneratedHomeLibraryRecentDefaultsNonMangaNoScope(t *testing.T) {
|
||
got := generatedHomeLibraryRecentDefaults(7, "Movies", "movies")
|
||
if len(got) != 2 {
|
||
t.Fatalf("expected 2 generated movies home sections, got %d", len(got))
|
||
}
|
||
for _, sec := range got {
|
||
def, err := ParseQueryDefinition(sec.Config)
|
||
if err != nil {
|
||
t.Fatalf("ParseQueryDefinition(%s) error = %v", sec.SectionType, err)
|
||
}
|
||
if def.MediaScope == "manga" {
|
||
t.Fatalf("section %s unexpectedly carries manga media_scope", sec.SectionType)
|
||
}
|
||
}
|
||
}
|