]> git.ipfire.org Git - thirdparty/rsync.git/commitdiff
testsuite: verify the negotiated compressor/checksum selection
authorAndrew Tridgell <andrew@tridgell.net>
Sun, 24 May 2026 22:02:41 +0000 (08:02 +1000)
committerAndrew Tridgell <andrew@tridgell.net>
Mon, 25 May 2026 21:43:00 +0000 (07:43 +1000)
compress-options only checked that each requested algorithm yielded
byte-identical output, which proves parsing/non-corruption but not that the
advertised algorithm was actually used -- the test would pass if the choice
were silently ignored. Capture --debug=NSTR (compat.c / checksum.c) and assert
the selected compressor, compress level, and checksum match the request
(anchored so zlib != zlibx). --skip-compress / --checksum-seed stay content
checks: they have no comparable negotiation-string signal.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
testsuite/compress-options_test.py

index 74e0877121e11b40a0ecee048482360f422ca571..c11741e67d7a2a353b4de3bec5fb23befc5f94fe 100644 (file)
@@ -9,10 +9,11 @@ algorithm is exercised for a clean, byte-identical transfer of a >=3-deep tree
 """
 
 import json
+import re
 
 from rsyncfns import (
     FROMDIR, TODIR,
-    assert_same, make_tree, rmtree, run_rsync, walk_files,
+    assert_same, make_tree, rmtree, run_rsync, test_fail, walk_files,
 )
 
 src = FROMDIR
@@ -34,14 +35,25 @@ def verify(rels, label):
 
 
 # --- --compress-choice for every advertised compressor ----------------------
+# Byte-identical output alone proves only that the option didn't corrupt data;
+# assert via --debug=NSTR (compat.c) that the requested compressor was actually
+# selected for the transfer. The trailing " (level" anchors so zlib != zlibx.
 for algo in compressors:
     rels = fresh()
-    run_rsync('-az', f'--compress-choice={algo}', f'{src}/', f'{TODIR}/')
+    proc = run_rsync('-az', f'--compress-choice={algo}', '--debug=NSTR',
+                     f'{src}/', f'{TODIR}/', capture_output=True)
+    if not re.search(rf'compress: {re.escape(algo)} \(level', proc.stdout):
+        test_fail(f"--compress-choice={algo} was not the selected compressor; "
+                  f"--debug=NSTR output:\n{proc.stdout}")
     verify(rels, f'--compress-choice={algo}')
 
-# --- --compress-level -------------------------------------------------------
+# --- --compress-level (the requested level reaches the compressor) ----------
 rels = fresh()
-run_rsync('-az', '--compress-level=9', f'{src}/', f'{TODIR}/')
+proc = run_rsync('-az', '--compress-level=9', '--debug=NSTR',
+                 f'{src}/', f'{TODIR}/', capture_output=True)
+if not re.search(r'compress: \S+ \(level 9\)', proc.stdout):
+    test_fail("--compress-level=9 was not applied; "
+              f"--debug=NSTR output:\n{proc.stdout}")
 verify(rels, '--compress-level=9')
 
 # --- --skip-compress (the file must still arrive intact) --------------------
@@ -52,9 +64,15 @@ assert_same(TODIR / 'd1' / 'd2' / 'x.gz', src / 'd1' / 'd2' / 'x.gz',
             label='--skip-compress gz')
 
 # --- --checksum-choice for every advertised checksum ------------------------
+# As above: assert via --debug=NSTR (checksum.c) that the requested checksum was
+# the one negotiated, not merely that the transfer succeeded.
 for algo in checksums:
     rels = fresh()
-    run_rsync('-a', '-c', f'--checksum-choice={algo}', f'{src}/', f'{TODIR}/')
+    proc = run_rsync('-a', '-c', f'--checksum-choice={algo}', '--debug=NSTR',
+                     f'{src}/', f'{TODIR}/', capture_output=True)
+    if not re.search(rf'checksum: {re.escape(algo)}\b', proc.stdout):
+        test_fail(f"--checksum-choice={algo} was not the selected checksum; "
+                  f"--debug=NSTR output:\n{proc.stdout}")
     verify(rels, f'--checksum-choice={algo}')
 
 # --- --checksum-seed --------------------------------------------------------