feat: 0.9 fuzzy_threshold config tunable - #13
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a fuzzy_threshold configuration key (default 85, range [0, 100]) so users can tune the RapidFuzz cross-source match cutoff used by compare-likes Stage 3 from ~/.like-surgeon/config.json. The default constant lives in compare.py and is imported by config.py to avoid drift between the dataclass default and the loader fallback. Invalid values produce a clean exit-2 via the existing _safe_config_load path.
Changes:
- New
_load_fuzzy_threshold/_validate_fuzzy_threshold/InvalidFuzzyThresholdErrorinconfig.py, plus afuzzy_threshold: intfield onConfig. cli._compare_and_persistforwardscfg.fuzzy_thresholdtoCompareInput(kwarg omitted whencfg is None);_safe_config_loadcatches the new error.- Docs (README, ARCHITECTURE.md, CLAUDE.md) updated; CLAUDE.md release checklist now requires bumping
__init__.pyin lockstep withpyproject.toml. Tests added intests/test_config.py(17) andtests/test_cli.py(3).
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/likesurgeon/compare.py | Extracts DEFAULT_FUZZY_THRESHOLD = 85 module constant; CompareInput.fuzzy_threshold now defaults to it. |
| src/likesurgeon/config.py | Adds validator, loader, error class, and fuzzy_threshold field on Config; imports default from compare.py. |
| src/likesurgeon/cli.py | _safe_config_load also catches InvalidFuzzyThresholdError; _compare_and_persist plumbs cfg.fuzzy_threshold into CompareInput. |
| tests/test_config.py | Validator/loader/integration tests + drift-invariant assertion that CompareInput().fuzzy_threshold == DEFAULT_FUZZY_THRESHOLD == 85. |
| tests/test_cli.py | Tests cfg→CompareInput wiring, default-when-cfg-None, and clean exit-2 for invalid config. |
| README.md | Adds 0.9 row to version table and config example for fuzzy_threshold. |
| docs/ARCHITECTURE.md | Adds 0.9 roadmap bullet referencing the motivating fuzzy-match case. |
| CLAUDE.md | Adds 0.9 sync-state-model note; updates release procedure to bump __init__.py together with pyproject.toml. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
fuzzy_thresholdconfig key in~/.like-surgeon/config.json(default85, integer in[0, 100]) tuning the RapidFuzz cross-source match cutoff used by Stage 3 ofcompare-likes.DEFAULT_FUZZY_THRESHOLDlives once incompare.py(next toCompareInput) and is imported byconfig.py— no drift risk between dataclass default and config fallback.bool(caught before theintcheck;True/Falseareintsubclass in Python), non-integers, and out-of-range values viaInvalidFuzzyThresholdError. Caught in_safe_config_loadso a bad value exits cleanly with code 2 (no traceback) — same UX asInvalidRegionError.cli._compare_and_persistpassescfg.fuzzy_thresholdintoCompareInputvia dict-spread (**({"fuzzy_threshold": cfg.fuzzy_threshold} if cfg is not None else {})) — kwarg literally omitted whencfg is None, so theCompareInputdataclass default (alsoDEFAULT_FUZZY_THRESHOLD) applies. No duplicate constants.Side fix (regression from v0.8.0)
CLAUDE.md "Releases" checklist updated: step 1 now requires bumping both
pyproject.tomlANDsrc/likesurgeon/__init__.pyin lockstep. v0.8.0 was tagged with__init__.pystale at0.7.1, solikesurgeon --versionprintedlikesurgeon 0.7.1after the tag. v0.9.0 release will fix this (jumps__init__.py0.7.1 → 0.9.0).Live e2e validation (operator run)
~/.like-surgeon/config.jsonset to{"region": "KR", "fuzzy_threshold": 80}.compare-likesagainst latest snapshots (YT #34 vs YTM #32) → Diagnosis #21:f9DzbpmWbMo↔RANoZl9UXJM("irucaice - Rainy Step feat. Hatsune Miku" ↔ "Rainy Step (feat. Hatsune Miku)") at score 82/100, confidence 0.817.sync --dry-runwith default--drift-min-confidence 0.95: the new pointer-drift correctly skipped (0.817 < 0.95). Two-stage safety net (compare-time fuzzy_threshold + sync-time drift-min-confidence) confirmed working.sync --yes --drift-min-confidence 0.80: applied the drift fix (yt_relike_like ok + yt_relike_unlike ok) — Diagnosis item flipped to'applied'. Siblingytm_likeitems hit an unrelated ytmusicapi verify-parse failure (not 0.9 related; YT-side rate calls succeeded).Tests
tests/test_config.py: validator boundaries, bool-before-int guard, loader fall-throughs (missing file / malformed JSON / non-dict / null / valid / out-of-range / non-int / JSONtrue-as-bool),Config.loadintegration with default vs override, drift-invariant assert thatCompareInput().fuzzy_threshold == DEFAULT_FUZZY_THRESHOLD == 85.tests/test_cli.py: cfg.fuzzy_threshold flows intoCompareInput, default applies whencfg=None, invalid config exits cleanly with"150"inresult.outputand noTraceback.Test plan
uv run pytest tests/(303 → 323 with new tests)uv run ruff format --check .uv run ruff checkConfig.load()with{"fuzzy_threshold": 80}→cfg.fuzzy_threshold == 80Config.load()with{"fuzzy_threshold": 150}→ exits 2, "150" in output, no tracebackcompare-likesat threshold 80 surfaces the f9DzbpmWbMo fuzzy matchsync --drift-min-confidence 0.80applies the drift fix end-to-end