Skip to content

Commit e090662

Browse files
test: have the local stack remove only the sandboxes its own process made (#584)
Co-authored-by: Claude <noreply@anthropic.com>
1 parent ebfced2 commit e090662

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

‎tst/integration/store/local_parallel_deploy_test.py‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from agent_env.store.image_store import LocalRegistryImageStore
2727
from agent_env.task import Task
2828
from agent_env.task.store import get_task_instance_store
29+
from agent_env.providers.sandbox_providers.local_docker.provider import LocalSandbox
2930
from agent_env.task_step.task_steps.deploy_env import DeployEnvTaskStep
3031
from tst.integration.utils.registry import REGISTRY_IMAGE
3132
from tst.task import journal_invariants as journal
@@ -80,6 +81,15 @@ def local_stack_at(monkeypatch: pytest.MonkeyPatch, path: Path):
8081
_docker("rm", "-f", reg_name)
8182
pytest.skip("local registry did not become ready")
8283

84+
# The sandboxes this process makes while the stack is up, whose containers alone it removes: another process's,
85+
# as another pytest worker's, share this machine's Docker and its names.
86+
made, init = [], LocalSandbox.__init__
87+
88+
def recorded(self, *args, **kwargs):
89+
init(self, *args, **kwargs)
90+
made.append(self.sandbox_id)
91+
92+
monkeypatch.setattr(LocalSandbox, "__init__", recorded)
8393
monkeypatch.chdir(path)
8494
for var in ("DOCUMENT", "OBJECT", "IMAGE"):
8595
monkeypatch.setenv(f"AGENT_ENV_{var}_STORE", "local")
@@ -89,8 +99,9 @@ def local_stack_at(monkeypatch: pytest.MonkeyPatch, path: Path):
8999
try:
90100
yield host
91101
finally:
92-
for cid in _docker("ps", "-aq", "--filter", "name=agent-env-local-").stdout.split():
93-
_docker("rm", "-f", cid)
102+
for sandbox_id in set(made):
103+
for cid in _docker("ps", "-aq", "--filter", f"name=agent-env-{sandbox_id}-").stdout.split():
104+
_docker("rm", "-f", cid)
94105
reset_artifact_store()
95106
reset_config()
96107
_docker("rm", "-f", reg_name)

0 commit comments

Comments
 (0)