#799: add equivalence proof that should_rediscover == original pre-scan
Enumerates all 64 flag combinations and asserts should_rediscover matches the verbatim pre-refactor inline logic for every case except the one intended fix (manual_match beating a stale wing_it_fallback). Guarantees the auto Playlist Pipeline behaves identically post-refactor — no regression.
This commit is contained in:
parent
c20150e370
commit
0f3c374137
1 changed files with 76 additions and 0 deletions
|
|
@ -175,3 +175,79 @@ def test_manual_match_wins_even_without_other_fields():
|
|||
# Lean Fix-popup save shape (no track_number/album) must still be honored.
|
||||
extra = {'discovered': True, 'manual_match': True, 'wing_it_fallback': True}
|
||||
assert should_rediscover(extra) is False
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Equivalence guard: should_rediscover must match the ORIGINAL inline pre-scan
|
||||
# logic for EVERY flag combination except the one intended fix (manual_match
|
||||
# beating a stale wing_it_fallback). This pins that the auto Playlist Pipeline
|
||||
# behaves identically post-refactor — no regression.
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
import itertools
|
||||
|
||||
|
||||
def _original_pre_scan(extra):
|
||||
"""Verbatim reproduction of the pre-refactor playlist.py branch logic.
|
||||
Returns True = re-discover (undiscovered_tracks), False = skip."""
|
||||
if extra.get('discovered'):
|
||||
if extra.get('wing_it_fallback'):
|
||||
return True
|
||||
elif extra.get('manual_match'):
|
||||
return False
|
||||
else:
|
||||
md = extra.get('matched_data', {})
|
||||
album = md.get('album', {})
|
||||
has_track_num = md.get('track_number')
|
||||
has_release = album.get('release_date') if isinstance(album, dict) else None
|
||||
has_album_id = album.get('id') if isinstance(album, dict) else None
|
||||
if has_track_num and (has_release or has_album_id):
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
elif extra.get('unmatched_by_user'):
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
_MATCHED_VARIANTS = {
|
||||
'absent': None, # key omitted
|
||||
'complete': {'track_number': 1, 'album': {'release_date': '2020'}},
|
||||
'incomplete': {'name': 'x'},
|
||||
}
|
||||
|
||||
|
||||
def test_should_rediscover_matches_original_logic_for_all_combinations():
|
||||
bools = [True, False]
|
||||
diverged = 0
|
||||
for discovered, wing, manual, unmatched, md_key in itertools.product(
|
||||
bools, bools, bools, bools, _MATCHED_VARIANTS
|
||||
):
|
||||
extra = {}
|
||||
if discovered:
|
||||
extra['discovered'] = True
|
||||
if wing:
|
||||
extra['wing_it_fallback'] = True
|
||||
if manual:
|
||||
extra['manual_match'] = True
|
||||
if unmatched:
|
||||
extra['unmatched_by_user'] = True
|
||||
if _MATCHED_VARIANTS[md_key] is not None:
|
||||
extra['matched_data'] = _MATCHED_VARIANTS[md_key]
|
||||
|
||||
new = should_rediscover(extra)
|
||||
old = _original_pre_scan(extra)
|
||||
|
||||
# The single intended divergence: a discovered track carrying BOTH a
|
||||
# stale wing_it_fallback AND a manual_match. Old re-discovered (the
|
||||
# bug); new skips (manual is authoritative).
|
||||
is_intended_fix = discovered and wing and manual
|
||||
if is_intended_fix:
|
||||
assert old is True and new is False, (extra, old, new)
|
||||
diverged += 1
|
||||
else:
|
||||
assert new == old, (extra, new, old)
|
||||
|
||||
# Sanity: the fix actually triggered on the expected subset.
|
||||
assert diverged > 0
|
||||
|
|
|
|||
Loading…
Reference in a new issue