fix: allocate unique browser challenge workspaces
This commit is contained in:
@@ -132,11 +132,11 @@ def prepare_trial_workspace(
|
|||||||
source_root: Path = EXAMPLE_SOURCE_ROOT,
|
source_root: Path = EXAMPLE_SOURCE_ROOT,
|
||||||
) -> TrialWorkspace:
|
) -> TrialWorkspace:
|
||||||
"""Copy the authoring template into a clean ignored per-trial directory."""
|
"""Copy the authoring template into a clean ignored per-trial directory."""
|
||||||
root = workspaces_dir / f"{_safe_model_name(model)}-trial-{index:03d}"
|
root = _next_trial_workspace_root(
|
||||||
if root.exists():
|
workspaces_dir=workspaces_dir,
|
||||||
# Stale scratch files can leak answers between trials, so reset only
|
model=model,
|
||||||
# the ignored per-trial directory before copying the template.
|
index=index,
|
||||||
shutil.rmtree(root)
|
)
|
||||||
shutil.copytree(template_dir, root)
|
shutil.copytree(template_dir, root)
|
||||||
workspace = TrialWorkspace(
|
workspace = TrialWorkspace(
|
||||||
root=root,
|
root=root,
|
||||||
@@ -147,6 +147,24 @@ def prepare_trial_workspace(
|
|||||||
return 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:
|
def write_trial_config(config_path: Path, *, source_root: Path) -> None:
|
||||||
"""Write a per-trial config with Python source path relative to config."""
|
"""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()
|
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"
|
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,
|
tmp_path: Path,
|
||||||
) -> None:
|
) -> None:
|
||||||
template = tmp_path / "template"
|
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 = tmp_path / "browser_click_workflow"
|
||||||
source_root.mkdir()
|
source_root.mkdir()
|
||||||
workspaces = tmp_path / "workspaces"
|
workspaces = tmp_path / "workspaces"
|
||||||
stale = workspaces / "opencode_mimo-v2.5-free-trial-001" / "old-answer.json"
|
first = workspaces / "opencode_mimo-v2.5-free-trial-001"
|
||||||
stale.parent.mkdir(parents=True)
|
stale = first / "old-answer.json"
|
||||||
|
first.mkdir(parents=True)
|
||||||
stale.write_text("stale", encoding="utf-8")
|
stale.write_text("stale", encoding="utf-8")
|
||||||
|
|
||||||
prepared = prepare_trial_workspace(
|
prepared = prepare_trial_workspace(
|
||||||
@@ -307,8 +308,9 @@ def test_prepare_trial_workspace_removes_stale_previous_attempt(
|
|||||||
source_root=source_root,
|
source_root=source_root,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
assert prepared.root == workspaces / "opencode_mimo-v2.5-free-trial-001-r002"
|
||||||
assert prepared.root.exists()
|
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:
|
def test_wf_command_prefix_for_config_uses_repo_relative_path() -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user