mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
Preserve legacy symlink scan behavior
This commit is contained in:
@@ -558,8 +558,24 @@ async fn discover_skills_under_root(
|
||||
}
|
||||
|
||||
let path = dir.join(&file_name);
|
||||
if entry.is_symlink {
|
||||
if follow_symlinks && entry.is_directory {
|
||||
let (is_directory, is_file, is_symlink) = match entry.is_symlink {
|
||||
Some(is_symlink) => (entry.is_directory, entry.is_file, is_symlink),
|
||||
None => {
|
||||
// Older remote exec servers omit symlink identity from directory entries.
|
||||
let path_uri = PathUri::from_abs_path(&path);
|
||||
let metadata = match fs.get_metadata(&path_uri, /*sandbox*/ None).await {
|
||||
Ok(metadata) => metadata,
|
||||
Err(e) => {
|
||||
error!("failed to stat skills path {}: {e:#}", path.display());
|
||||
continue;
|
||||
}
|
||||
};
|
||||
(metadata.is_directory, metadata.is_file, metadata.is_symlink)
|
||||
}
|
||||
};
|
||||
|
||||
if is_symlink {
|
||||
if follow_symlinks && is_directory {
|
||||
let resolved_dir = canonicalize_for_skill_identity(fs, &path).await;
|
||||
enqueue_dir(
|
||||
&mut queue,
|
||||
@@ -572,7 +588,7 @@ async fn discover_skills_under_root(
|
||||
continue;
|
||||
}
|
||||
|
||||
if entry.is_directory {
|
||||
if is_directory {
|
||||
let resolved_dir = canonicalize_for_skill_identity(fs, &path).await;
|
||||
enqueue_dir(
|
||||
&mut queue,
|
||||
@@ -584,7 +600,7 @@ async fn discover_skills_under_root(
|
||||
continue;
|
||||
}
|
||||
|
||||
if entry.is_file && file_name == SKILLS_FILENAME {
|
||||
if is_file && file_name == SKILLS_FILENAME {
|
||||
match parse_skill_file(fs, &path, scope, plugin_id, plugin_root.as_ref()).await {
|
||||
Ok(skill) => {
|
||||
outcome.skills.push(skill);
|
||||
|
||||
@@ -613,7 +613,7 @@ impl DirectFileSystem {
|
||||
file_name: entry.file_name().to_string_lossy().into_owned(),
|
||||
is_directory,
|
||||
is_file,
|
||||
is_symlink,
|
||||
is_symlink: Some(is_symlink),
|
||||
});
|
||||
}
|
||||
Ok(entries)
|
||||
|
||||
@@ -320,8 +320,8 @@ pub struct FsReadDirectoryEntry {
|
||||
pub file_name: String,
|
||||
pub is_directory: bool,
|
||||
pub is_file: bool,
|
||||
#[serde(default)]
|
||||
pub is_symlink: bool,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub is_symlink: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
@@ -496,6 +496,7 @@ mod base64_bytes {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::FsReadDirectoryEntry;
|
||||
use super::FsReadFileParams;
|
||||
use super::HttpRequestParams;
|
||||
use codex_file_system::FileSystemSandboxContext;
|
||||
@@ -503,6 +504,41 @@ mod tests {
|
||||
use codex_utils_path_uri::PathUri;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn read_directory_entry_preserves_unknown_legacy_symlink_state() {
|
||||
let entry: FsReadDirectoryEntry = serde_json::from_value(serde_json::json!({
|
||||
"fileName": "skill",
|
||||
"isDirectory": true,
|
||||
"isFile": false,
|
||||
}))
|
||||
.expect("legacy directory entry should deserialize");
|
||||
|
||||
assert_eq!(
|
||||
entry,
|
||||
FsReadDirectoryEntry {
|
||||
file_name: "skill".to_string(),
|
||||
is_directory: true,
|
||||
is_file: false,
|
||||
is_symlink: None,
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::to_value(FsReadDirectoryEntry {
|
||||
file_name: "linked-skill".to_string(),
|
||||
is_directory: true,
|
||||
is_file: false,
|
||||
is_symlink: Some(true),
|
||||
})
|
||||
.expect("current directory entry should serialize"),
|
||||
serde_json::json!({
|
||||
"fileName": "linked-skill",
|
||||
"isDirectory": true,
|
||||
"isFile": false,
|
||||
"isSymlink": true,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filesystem_protocol_accepts_legacy_absolute_paths_and_serializes_path_uris() {
|
||||
let legacy_path = std::env::current_dir()
|
||||
|
||||
@@ -343,13 +343,13 @@ async fn file_system_read_directory_lists_entries(
|
||||
file_name: "nested".to_string(),
|
||||
is_directory: true,
|
||||
is_file: false,
|
||||
is_symlink: false,
|
||||
is_symlink: Some(false),
|
||||
},
|
||||
ReadDirectoryEntry {
|
||||
file_name: "root.txt".to_string(),
|
||||
is_directory: false,
|
||||
is_file: true,
|
||||
is_symlink: false,
|
||||
is_symlink: Some(false),
|
||||
},
|
||||
]
|
||||
);
|
||||
|
||||
@@ -111,13 +111,13 @@ async fn file_system_read_directory_reports_symlink_target_kind(
|
||||
file_name: "directory-link".to_string(),
|
||||
is_directory: true,
|
||||
is_file: false,
|
||||
is_symlink: true,
|
||||
is_symlink: Some(true),
|
||||
},
|
||||
ReadDirectoryEntry {
|
||||
file_name: "file-link".to_string(),
|
||||
is_directory: false,
|
||||
is_file: true,
|
||||
is_symlink: true,
|
||||
is_symlink: Some(true),
|
||||
},
|
||||
]
|
||||
);
|
||||
|
||||
@@ -33,6 +33,7 @@ static NEXT_TEST_ROOT_ID: AtomicUsize = AtomicUsize::new(0);
|
||||
struct SyntheticFileSystem {
|
||||
alias_root: AbsolutePathBuf,
|
||||
canonical_root: AbsolutePathBuf,
|
||||
entry_is_symlink: Option<bool>,
|
||||
}
|
||||
|
||||
impl SyntheticFileSystem {
|
||||
@@ -60,14 +61,14 @@ impl SyntheticFileSystem {
|
||||
file_name: "skill".to_string(),
|
||||
is_directory: true,
|
||||
is_file: false,
|
||||
is_symlink: false,
|
||||
is_symlink: self.entry_is_symlink,
|
||||
}])
|
||||
} else if path == self.canonical_root.join("skill") {
|
||||
Ok(vec![ReadDirectoryEntry {
|
||||
file_name: "SKILL.md".to_string(),
|
||||
is_directory: false,
|
||||
is_file: true,
|
||||
is_symlink: false,
|
||||
is_symlink: self.entry_is_symlink,
|
||||
}])
|
||||
} else {
|
||||
Err(io::Error::new(io::ErrorKind::NotFound, "not found"))
|
||||
@@ -150,7 +151,7 @@ impl ExecutorFileSystem for SyntheticFileSystem {
|
||||
) -> ExecutorFileSystemFuture<'a, FileMetadata> {
|
||||
Box::pin(async move {
|
||||
let path = path.to_abs_path()?;
|
||||
if path == self.canonical_root {
|
||||
if path == self.canonical_root || self.entry_is_symlink.is_none() {
|
||||
self.metadata(&path)
|
||||
} else {
|
||||
Err(io::Error::new(
|
||||
@@ -206,6 +207,7 @@ async fn skill_loading_and_reads_use_the_supplied_executor_file_system() {
|
||||
file_system: Arc::new(SyntheticFileSystem {
|
||||
alias_root,
|
||||
canonical_root: canonical_root.clone(),
|
||||
entry_is_symlink: Some(false),
|
||||
}),
|
||||
plugin_id: None,
|
||||
plugin_root: None,
|
||||
@@ -227,6 +229,41 @@ async fn skill_loading_and_reads_use_the_supplied_executor_file_system() {
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn skill_loading_falls_back_for_legacy_directory_entries() {
|
||||
let test_root = std::env::temp_dir().join(format!(
|
||||
"codex-legacy-executor-skill-fs-{}",
|
||||
std::process::id()
|
||||
));
|
||||
let alias_root = AbsolutePathBuf::from_absolute_path_checked(test_root.join("alias"))
|
||||
.expect("absolute path");
|
||||
let canonical_root = AbsolutePathBuf::from_absolute_path_checked(test_root.join("canonical"))
|
||||
.expect("absolute path");
|
||||
|
||||
let outcome = load_skills_from_roots([SkillRoot {
|
||||
path: alias_root.clone(),
|
||||
scope: SkillScope::User,
|
||||
file_system: Arc::new(SyntheticFileSystem {
|
||||
alias_root,
|
||||
canonical_root,
|
||||
entry_is_symlink: None,
|
||||
}),
|
||||
plugin_id: None,
|
||||
plugin_root: None,
|
||||
}])
|
||||
.await;
|
||||
|
||||
assert_eq!(outcome.errors, Vec::new());
|
||||
assert_eq!(
|
||||
outcome
|
||||
.skills
|
||||
.iter()
|
||||
.map(|skill| skill.name.as_str())
|
||||
.collect::<Vec<_>>(),
|
||||
vec!["synthetic"]
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn selected_root_id_distinguishes_identical_executor_paths() {
|
||||
let test_root = create_local_skill_root("root-identity").expect("create local skill root");
|
||||
|
||||
@@ -54,7 +54,8 @@ pub struct ReadDirectoryEntry {
|
||||
pub file_name: String,
|
||||
pub is_directory: bool,
|
||||
pub is_file: bool,
|
||||
pub is_symlink: bool,
|
||||
/// `None` when the backing filesystem cannot report symlink identity.
|
||||
pub is_symlink: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
|
||||
Reference in New Issue
Block a user