Files
FabledCurator/tests/test_series_match.py
T
bvandeusen c0fd80e694
CI / lint (push) Successful in 3s
CI / backend-lint-and-test (push) Successful in 26s
CI / frontend-build (push) Successful in 27s
CI / integration (push) Successful in 3m8s
feat(series): assisted-continuation matcher + suggestion queue — backend (FC-6.3)
Confirm-only "this post may continue this series" matcher.

- series_suggestion table (post_id, series_tag_id, score, signals jsonb, status
  pending|added|dismissed, UNIQUE(post,series)); migration 0041 + two settings
  knobs (series_suggest_enabled, series_suggest_threshold).
- series_match_service: weighted additive score (title-stem / same-artist /
  page-continuity / shared-distinctive-tags), no single signal gating. The title
  "pattern" is derived on the fly from the post titles already in a series, so it
  sharpens as more are confirmed (no persisted state to drift). Candidates are
  bounded to the post's artist. match_post upserts pending suggestions (UNIQUE +
  on-conflict, respecting prior added/dismissed decisions).
- accept reuses add_post_as_chapter then marks 'added'; dismiss marks 'dismissed'.
- rescan_series_suggestions_task: settings-gated, time-boxed + self-resuming from
  a post-id cursor (maintenance_long lane), like normalize_tags_task.
- API: GET /series/suggestions, POST .../<id>/accept|dismiss, POST .../rescan.
- Settings: enabled + threshold exposed via /settings/import.
- Tests: pure scoring helpers + matcher/accept/dismiss/rescan lifecycle + UNIQUE
  dedup.

Frontend (Suggestions tab + settings card) lands next.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-07 18:58:18 -04:00

49 lines
1.6 KiB
Python

"""Pure scoring helpers for the series continuation matcher (FC-6.3)."""
from backend.app.services.series_match_service import (
normalize_title,
pages_signal,
tags_signal,
title_signal,
weighted_score,
)
def test_normalize_title_strips_installment_markers():
assert normalize_title("Story pages 9-12") == "story"
assert normalize_title("Bunker Diaries 04") == "bunker diaries"
assert normalize_title("My Comic [3/8]") == "my comic"
assert normalize_title("") == ""
assert normalize_title(None) == ""
def test_title_signal():
# Same stem after stripping page markers → full match.
assert title_signal(["Story pages 1-4"], "Story pages 9-12") == 1.0
# Unrelated → no overlap.
assert title_signal(["My Comic"], "Other Thing") == 0.0
# No data → 0.
assert title_signal([], "x") == 0.0
def test_pages_signal():
assert pages_signal(8, 9) == 1.0 # clean continuation
assert pages_signal(8, 10) == 0.5 # near (diff 2)
assert pages_signal(8, 11) == 0.5 # near (diff 3)
assert pages_signal(8, 20) == 0.0 # far
assert pages_signal(8, 5) == 0.0 # before / overlap
assert pages_signal(None, 9) == 0.0
def test_tags_signal():
assert tags_signal(0) == 0.0
assert tags_signal(3) == 1.0
assert tags_signal(6) == 1.0 # capped
assert round(tags_signal(1), 3) == 0.333
def test_weighted_score():
assert weighted_score({"title": 1, "artist": 1, "pages": 1, "tags": 1}) == 1.0
assert weighted_score({}) == 0.0
assert weighted_score({"title": 1.0, "artist": 1.0}) == 0.6