4.8 KiB
Goal: # Fix: DaytonaSandbox concurrent test failures from set_current_dir poisoning
Context
Two Daytona integration tests (daytona_computer_use_browser_screenshot and daytona_playwright_mcp_sandbox_transport) call std::env::set_current_dir(tmp.path()) to make detect_repo_info() fail so the sandbox skips cloning. Since set_current_dir is process-global, any concurrent test calling initialize() sees the changed cwd, causing detect_repo_info to fail and the sandbox to get an empty directory with no git repo. This makes git rev-parse HEAD return exit code 128.
The fix follows the existing ExeSandbox/SshSandbox pattern: move clone params out of initialize() and into the constructor so callers control whether cloning happens.
Changes
1. lib/crates/fabro-daytona/src/lib.rs — Core refactor
- Add a
GitCloneParamsstruct withurl: Stringandbranch: Option<String>fields - Change
DaytonaSandboxfield fromclone_branch: Option<String>toclone_params: Option<GitCloneParams> - Update
new()signature: last param changes fromclone_branch: Option<String>toclone_params: Option<GitCloneParams> - Update
reconnect()(line 84):clone_params: None - Refactor
initialize():- Remove
let cwd = std::env::current_dir()(line 392) - Replace
match detect_repo_info(&cwd)(line 448) withif let Some(ref params) = self.clone_params Somearm: useparams.url/params.branchdirectly (already HTTPS, nossh_url_to_httpsneeded inside initialize)Nonearm: create empty working directory (existingErrarm logic, lines 607-618)- Remove
self.clone_branch.clone().or(detected_branch)merge — caller provides the final branch
- Remove
2. lib/crates/fabro-cli/src/commands/run.rs — Production callers
-
Line 1017 (main
runpath): ConstructGitCloneParamsfromorigin_urlanddetected_base_branch(already extracted at line 557):let clone_params = origin_url.as_ref().map(|url| fabro_daytona::GitCloneParams { url: fabro_github::ssh_url_to_https(url), branch: detected_base_branch.clone(), });Pass
clone_paramsas the last arg toDaytonaSandbox::new() -
Line 2133 (doctor path): Currently passes
Noneforclone_branch. Under the new API,Noneforclone_paramsmeans "skip clone" — same behavior, just update the type. No logic change needed.
3. lib/crates/fabro-workflows/tests/daytona_integration.rs — Test fixes
-
create_env_with_github_app(line 30): Detect repo and buildGitCloneParamsbefore callingnew():let cwd = std::env::current_dir().unwrap(); let clone_params = fabro_daytona::detect_repo_info(&cwd) .ok() .map(|(url, branch)| fabro_daytona::GitCloneParams { url: fabro_github::ssh_url_to_https(&url), branch, }); DaytonaSandbox::new(DaytonaConfig::default(), github_app, None, clone_params)This preserves cloning for all tests that use
create_env()/create_env_with_github_app(). -
daytona_snapshot_sandbox(line 252) andrun_daytona_cli_test(line 927): Currently passNoneasclone_branch. Under new API,Noneforclone_params= skip clone. These tests don't need repo contents (snapshot checksrg --version, CLI tests install tools independently). No logic change needed. -
daytona_computer_use_browser_screenshot(line 1855-1857): Removetempfile::tempdir()andset_current_dir(). Already passesNoneas last arg → skip clone. -
daytona_playwright_mcp_sandbox_transport(line 2015-2017): Same — removetempfile::tempdir()andset_current_dir().
Verification
cargo build --workspace— confirms all callers updated (compiler catches type mismatch)cargo test -p fabro-workflows --test daytona_integration -- --ignored --test-threads=4— the previously-failing git tests should pass with concurrent execution- Specifically verify the 5 previously-failing tests pass:
daytona_full_lifecycle,daytona_git_checkpoint_remote_emits_events,daytona_git_checkpoint_with_shadow_branch,daytona_git_push_run_branch_to_origin,daytona_parallel_git_branching_e2e
Completed stages
- toolchain: success
- Script:
command -v cargo >/dev/null || { curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && sudo ln -sf $HOME/.cargo/bin/* /usr/local/bin/; }; cargo --version 2>&1 - Stdout:
cargo 1.94.0 (85eff7c80 2026-01-15) - Stderr: (empty)
- Script:
- preflight_compile: success
- Script:
cargo check -q --workspace 2>&1 - Stdout: (empty)
- Stderr: (empty)
- Script:
- preflight_lint: success
- Script:
cargo clippy -q --workspace -- -D warnings 2>&1 - Stdout: (empty)
- Stderr: (empty)
- Script:
Read the plan file referenced in the goal and implement every step. Make all the code changes described in the plan. Use red/green TDD.