@@ -1369,6 +1369,95 @@ def test_dry_run_explicit_scope_receipt_and_idempotence(self):
13691369 self .assertEqual ((self .target / "a.py" ).exists (), dry_run )
13701370 self .assertEqual ((self .target / "unselected" ).read_text (), "keep" )
13711371
1372+ def test_junction_components_reject_the_whole_batch (self ):
1373+ before = {
1374+ name : (self .target / name ).read_bytes ()
1375+ for name in self .document ["removals" ]
1376+ }
1377+ for junction in (
1378+ self .source ,
1379+ self .source .parent ,
1380+ self .source / "data" ,
1381+ self .target ,
1382+ self .target .parent ,
1383+ self .target / "data" ,
1384+ ):
1385+ for dry_run in (True , False ):
1386+ with self .subTest (junction = junction , dry_run = dry_run ):
1387+ self .assertFalse (junction .is_symlink ())
1388+ with (
1389+ patch .object (
1390+ Path ,
1391+ "is_junction" ,
1392+ autospec = True ,
1393+ side_effect = lambda path : path == junction ,
1394+ ),
1395+ self .assertRaisesRegex (ValueError , "[Jj]unction" ),
1396+ ):
1397+ self .run_removal (dry_run )
1398+ self .assertEqual (
1399+ {name : (self .target / name ).read_bytes () for name in before },
1400+ before ,
1401+ )
1402+
1403+ def test_junction_revalidation_prevents_partial_removal (self ):
1404+ for junction in (self .target / "data" , self .source / "data" ):
1405+ checks = 0
1406+
1407+ def becomes_junction (path ):
1408+ nonlocal checks
1409+ if path == junction :
1410+ checks += 1
1411+ return checks > 1
1412+ return False
1413+
1414+ with self .subTest (junction = junction ):
1415+ with (
1416+ patch .object (
1417+ Path , "is_junction" , autospec = True , side_effect = becomes_junction
1418+ ),
1419+ self .assertRaisesRegex (ValueError , "[Jj]unction" ),
1420+ ):
1421+ self .run_removal ()
1422+ self .assertEqual (checks , 2 )
1423+ self .assertEqual ((self .target / "a.py" ).read_bytes (), b"old\n " )
1424+ self .assertEqual ((self .target / "data/z.bin" ).read_bytes (), b"\x00 \xff " )
1425+
1426+ def test_utf8_manifest_ignores_non_utf8_default_encoding (self ):
1427+ name = "caf\u00e9 .py"
1428+ target = self .target / name
1429+ target .write_bytes (b"old\n " )
1430+ self .document ["removals" ][name ] = dict (self .document ["removals" ]["a.py" ])
1431+ self .manifest .write_bytes (
1432+ json .dumps (self .document , ensure_ascii = False ).encode ("utf-8" )
1433+ )
1434+ with (
1435+ patch (
1436+ "pathlib.io.text_encoding" ,
1437+ side_effect = lambda encoding , * args : (
1438+ "latin-1" if encoding is None else encoding
1439+ ),
1440+ ),
1441+ contextlib .chdir (self .target .parents [2 ]),
1442+ contextlib .redirect_stdout (io .StringIO ()),
1443+ ):
1444+ self .assertNotEqual (
1445+ self .manifest .read_text (), self .manifest .read_text (encoding = "utf-8" )
1446+ )
1447+ for dry_run , expected in (
1448+ (True , "would_remove" ),
1449+ (False , "removed" ),
1450+ (False , "already_absent" ),
1451+ ):
1452+ receipt = remove_canonical_files (
1453+ self .source , self .manifest , dry_run = dry_run
1454+ )
1455+ self .assertEqual (
1456+ set (receipt ["removals" ]), set (self .document ["removals" ])
1457+ )
1458+ self .assertEqual (receipt ["removals" ][name ]["status" ], expected )
1459+ self .assertEqual (target .exists (), dry_run )
1460+
13721461 def test_cli_dry_run_never_migrates_or_changes_destination_bytes (self ):
13731462 def snapshot ():
13741463 return {
0 commit comments