Skip redirected external-agent migration destinations (#39221)

## Why

Repository-scoped imports must not follow redirected Codex paths and write
generated configuration outside the repository.

## What changed

- Reject repository migration scopes when generated configuration paths are
  symlinks or, on Windows, reparse points.
- Recheck hook and subagent destinations during import, skipping redirected
  directories, files, and dangling links without reporting them as imported.

## Testing

Add service and app-server coverage for redirected generated destinations,
including a repository path replaced with a symlink after detection.

GitOrigin-RevId: 3afb521ead9d76250f0e967eccfdd1dc194f027a
This commit is contained in:
jif authored and copyberry committed 2026-08-18 16:05:51 +00:00
1 parent 76ceaddb29
commit 2a30972fcb
5 files changed
+202 -5

No files matched your search

@@ -1,4 +1,5 @@
use crate::invalid_data_error;
use crate::scope::is_redirected_destination;
use crate::utils::is_missing_or_empty_text_file;
use serde_json::Value as JsonValue;
use std::fs;
@@ -250,6 +251,9 @@ pub(super) fn copy_hook_scripts(
}
fn copy_dir_recursive_skip_existing(source: &Path, target: &Path) -> io::Result<()> {
if is_redirected_destination(target)? {
return Ok(());
}
fs::create_dir_all(target)?;
for entry in fs::read_dir(source)? {
let entry = entry?;
@@ -258,7 +262,10 @@ fn copy_dir_recursive_skip_existing(source: &Path, target: &Path) -> io::Result<
let file_type = entry.file_type()?;
if file_type.is_dir() {
copy_dir_recursive_skip_existing(&source_path, &target_path)?;
} else if file_type.is_file() && !target_path.exists() {
} else if file_type.is_file()
&& !target_path.exists()
&& !is_redirected_destination(&target_path)?
{
fs::copy(source_path, target_path)?;
}
}