from rsyncfns import (
FROMDIR, TODIR,
- assert_same, make_data_file, makepath, rmtree, run_rsync,
+ assert_same, make_data_file, makepath, rmtree, run_rsync, test_fail,
)
src = FROMDIR
(TODIR / deepdir / 'archive-old.tar').write_bytes(base[:200_000])
(TODIR / deepdir / 'unrelated.dat').write_bytes(b'nothing alike' * 1000)
-run_rsync('-a', '--fuzzy', '--no-whole-file', f'{src}/', f'{TODIR}/')
+# Capture --debug=FUZZY: a correct final file alone would also result from a
+# full transfer that ignored --fuzzy, so assert the scorer actually chose the
+# closest-named candidate (archive-v1.tar) as the basis, not just that bytes match.
+proc = run_rsync('-a', '--fuzzy', '--no-whole-file', '--debug=FUZZY',
+ f'{src}/', f'{TODIR}/', capture_output=True)
+want = f'fuzzy basis selected for {newfile}: {os.path.join(deepdir, "archive-v1.tar")}'
+if want not in proc.stdout:
+ test_fail(f"--fuzzy did not score archive-v1.tar as the closest basis; "
+ f"expected {want!r}, --debug=FUZZY output was:\n{proc.stdout}")
assert_same(TODIR / newfile, src / newfile, label='fuzzy result')
print("fuzzy-basis: --fuzzy candidate scoring (fuzzy_distance) verified at depth")
import time
-from rsyncfns import FROMDIR, SRCDIR, TODIR, checkit, cp_p, cp_touch
+from rsyncfns import (
+ FROMDIR, SRCDIR, TODIR, cp_p, cp_touch, run_rsync, test_fail, verify_dirs,
+)
FROMDIR.mkdir(parents=True, exist_ok=True)
cp_touch(FROMDIR / 'rsync.c', TODIR / 'rsync2.c')
time.sleep(1)
-checkit(['-avvi', '--no-whole-file', '--fuzzy', '--delete-delay',
- f'{FROMDIR}/', f'{TODIR}/'], FROMDIR, TODIR)
+# 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)