Files
rsync/testsuite/fuzzy_test.py
Andrew Tridgell 034a4f3b1e testsuite: verify --fuzzy actually selects a basis
Both fuzzy tests asserted only that the final file content matched, which a
full transfer that ignored --fuzzy would also satisfy -- so a broken fuzzy
basis selection would pass undetected. Drive rsync directly with --debug=FUZZY
and assert the generator reports the expected basis ("fuzzy basis selected
for <f>: <basis>", generator.c find_fuzzy): rsync2.c for fuzzy, and the
closest-named candidate archive-v1.tar for fuzzy-basis. fuzzy switches from
checkit() to a manual run plus verify_dirs() so the output can be captured.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-26 07:43:00 +10:00

35 lines
1.4 KiB
Python

#!/usr/bin/env python3
# Python rewrite of testsuite/fuzzy.test.
#
# Test --fuzzy: with a matching-content file already in the destination
# under a different name, rsync should use it as a basis for the new name
# instead of re-transferring (and --delete-delay still removes the stale
# basis file at the end).
import time
from rsyncfns import (
FROMDIR, SRCDIR, TODIR, cp_p, cp_touch, run_rsync, test_fail, verify_dirs,
)
FROMDIR.mkdir(parents=True, exist_ok=True)
TODIR.mkdir(parents=True, exist_ok=True)
cp_p(SRCDIR / 'rsync.c', FROMDIR / 'rsync.c')
cp_touch(FROMDIR / 'rsync.c', TODIR / 'rsync2.c')
time.sleep(1)
# Drive rsync directly (rather than checkit) so we can capture --debug=FUZZY:
# a final tree match alone would also be produced by a full transfer that
# ignored --fuzzy, so assert the generator actually picked rsync2.c as the
# fuzzy basis for rsync.c (generator.c find_fuzzy / "fuzzy basis selected").
proc = run_rsync('-avvi', '--no-whole-file', '--fuzzy', '--delete-delay',
'--debug=FUZZY', f'{FROMDIR}/', f'{TODIR}/',
capture_output=True)
if 'fuzzy basis selected for rsync.c: rsync2.c' not in proc.stdout:
test_fail("--fuzzy did not select rsync2.c as the basis for rsync.c; "
f"--debug=FUZZY output was:\n{proc.stdout}")
# ...and --delete-delay still removes the stale basis, leaving TODIR == FROMDIR.
verify_dirs(FROMDIR, TODIR)