fix: allocate unique browser challenge workspaces

This commit is contained in:
lda
2026-06-15 06:36:06 +07:00 Verified
parent 3b19884919
commit 48e155d048
2 changed files with 29 additions and 9 deletions
@@ -132,11 +132,11 @@ def prepare_trial_workspace(
source_root: Path = EXAMPLE_SOURCE_ROOT,
) -> TrialWorkspace:
"""Copy the authoring template into a clean ignored per-trial directory."""
root = workspaces_dir / f"{_safe_model_name(model)}-trial-{index:03d}"
if root.exists():
# Stale scratch files can leak answers between trials, so reset only
# the ignored per-trial directory before copying the template.
shutil.rmtree(root)
root = _next_trial_workspace_root(
workspaces_dir=workspaces_dir,
model=model,
index=index,
)
shutil.copytree(template_dir, root)
workspace = TrialWorkspace(
root=root,
@@ -147,6 +147,24 @@ def prepare_trial_workspace(
return workspace
def _next_trial_workspace_root(
*,
workspaces_dir: Path,
model: str,
index: int,
) -> Path:
stem = f"{_safe_model_name(model)}-trial-{index:03d}"
first = workspaces_dir / stem
if not first.exists():
return first
suffix = 2
while True:
candidate = workspaces_dir / f"{stem}-r{suffix:03d}"
if not candidate.exists():
return candidate
suffix += 1
def write_trial_config(config_path: Path, *, source_root: Path) -> None:
"""Write a per-trial config with Python source path relative to config."""
relative_source = Path(os.path.relpath(source_root, config_path.parent)).as_posix()
@@ -286,7 +286,7 @@ def test_prepare_trial_workspace_copies_template_to_model_trial_dir(
assert (prepared.root / ".gitignore").read_text(encoding="utf-8") == ".wf_store/\n"
def test_prepare_trial_workspace_removes_stale_previous_attempt(
def test_prepare_trial_workspace_uses_next_available_directory(
tmp_path: Path,
) -> None:
template = tmp_path / "template"
@@ -295,8 +295,9 @@ def test_prepare_trial_workspace_removes_stale_previous_attempt(
source_root = tmp_path / "browser_click_workflow"
source_root.mkdir()
workspaces = tmp_path / "workspaces"
stale = workspaces / "opencode_mimo-v2.5-free-trial-001" / "old-answer.json"
stale.parent.mkdir(parents=True)
first = workspaces / "opencode_mimo-v2.5-free-trial-001"
stale = first / "old-answer.json"
first.mkdir(parents=True)
stale.write_text("stale", encoding="utf-8")
prepared = prepare_trial_workspace(
@@ -307,8 +308,9 @@ def test_prepare_trial_workspace_removes_stale_previous_attempt(
source_root=source_root,
)
assert prepared.root == workspaces / "opencode_mimo-v2.5-free-trial-001-r002"
assert prepared.root.exists()
assert not stale.exists()
assert stale.read_text(encoding="utf-8") == "stale"
def test_wf_command_prefix_for_config_uses_repo_relative_path() -> None: