Skip to content

Commit 6d8ca2d

Browse files
jpalvarezlCopilot
andcommitted
Python: Wait for retired output cleanup in Hyperlight test
Assert the rejected sandbox entry is evicted, then drain asynchronous disposal before checking that its output directory is gone. Avoid racing a directory listing against background deletion without changing runtime behavior. Co-authored-by: Copilot <[email protected]>
1 parent 7442753 commit 6d8ca2d

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎python/packages/hyperlight/tests/hyperlight/test_hyperlight_codeact.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,17 +1293,20 @@ async def test_execute_code_tool_clears_output_after_rejection(
12931293
max_output_file_bytes=3,
12941294
)
12951295
config = execute_code._build_run_config()
1296-
output_root = Path(cast(Any, execute_code._registry)._get_or_create_entry(config).output_dir.name)
1296+
registry = cast(Any, execute_code._registry)
1297+
output_root = Path(registry._get_or_create_entry(config).output_dir.name)
12971298

12981299
try:
12991300
contents = await execute_code.invoke(arguments={"code": "create-memory-output"})
13001301

13011302
_assert_bounded_output_error(contents, "per-file output limit")
1302-
remaining_outputs = await asyncio.to_thread(lambda: list(output_root.iterdir()))
1303-
assert remaining_outputs == []
1303+
assert registry._entries == {}
13041304
finally:
1305+
# Closing waits for background disposal of the retired entry's directories.
13051306
_close_execute_code_registry(execute_code)
13061307

1308+
assert not await asyncio.to_thread(output_root.exists)
1309+
13071310

13081311
async def test_execute_code_tool_preserves_result_when_post_cleanup_fails(
13091312
tmp_path: Path,

0 commit comments

Comments
 (0)