@@ -112,6 +112,48 @@ async def test_unix_local_snapshot_round_trips_hardlinks(
112112 await session .shutdown ()
113113
114114
115+ @pytest .mark .asyncio
116+ @pytest .mark .parametrize ("target_kind" , ["directory" , "file" , "missing" ])
117+ async def test_unix_local_snapshot_resume_removes_stale_link_without_following_target (
118+ tmp_path : Path , target_kind : str
119+ ) -> None :
120+ workspace = tmp_path / "workspace"
121+ external = tmp_path / "external"
122+ external .mkdir ()
123+ sentinel = external / "keep.txt"
124+ sentinel .write_bytes (b"external data" )
125+ target = external if target_kind == "directory" else external / target_kind
126+ if target_kind == "file" :
127+ target .write_bytes (b"external file" )
128+ client = UnixLocalSandboxClient (inherit_host_environment = False )
129+ session = await client .create (
130+ manifest = Manifest (
131+ root = str (workspace ), extra_path_grants = (SandboxPathGrant (path = str (external )),)
132+ ),
133+ snapshot = LocalSnapshotSpec (base_path = tmp_path / "snapshots" ),
134+ )
135+ await session .start ()
136+ (workspace / "original.txt" ).write_bytes (b"snapshot content" )
137+ await session .stop ()
138+ (workspace / "original.txt" ).write_bytes (b"changed after snapshot" )
139+ stale_link = workspace / "stale-link"
140+ stale_link .symlink_to (target , target_is_directory = target_kind == "directory" )
141+ resumed = await client .resume (session .state )
142+ try :
143+ await resumed .start ()
144+ assert (workspace / "original.txt" ).read_bytes () == b"snapshot content"
145+ assert sentinel .read_bytes () == b"external data"
146+ if target_kind == "file" :
147+ assert target .read_bytes () == b"external file"
148+ elif target_kind == "missing" :
149+ assert not target .exists ()
150+ assert not stale_link .is_symlink ()
151+ assert not stale_link .exists ()
152+ finally :
153+ await resumed .shutdown ()
154+ await session .shutdown ()
155+
156+
115157@pytest .mark .asyncio
116158@pytest .mark .parametrize ("invalid_kind" , ["hardlink" , "external_symlink" , "invalid_tar" ])
117159async def test_unix_local_resume_rejects_invalid_snapshot_before_clearing_workspace (
0 commit comments