Use AbsolutePathBuf in skill loading and codex_home (#17407)

Helps with FS migration later
This commit is contained in:
pakrym-oai
2026-04-13 10:26:51 -07:00
committed by GitHub
Unverified
parent d25a9822a7
commit ac82443d07
86 changed files with 850 additions and 625 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ pub(crate) fn list_tool_suggest_discoverable_plugins(
return Ok(Vec::new());
}
let plugins_manager = PluginsManager::new(config.codex_home.clone());
let plugins_manager = PluginsManager::new(config.codex_home.to_path_buf());
let configured_plugin_ids = config
.tool_suggest
.discoverables
+26 -23
View File
@@ -168,7 +168,7 @@ pub struct PluginDetail {
pub installed: bool,
pub enabled: bool,
pub skills: Vec<SkillMetadata>,
pub disabled_skill_paths: HashSet<PathBuf>,
pub disabled_skill_paths: HashSet<AbsolutePathBuf>,
pub apps: Vec<AppConnectorId>,
pub mcp_server_names: Vec<String>,
}
@@ -423,7 +423,7 @@ impl PluginsManager {
&self,
config_layer_stack: &ConfigLayerStack,
plugins_feature_enabled: bool,
) -> Vec<PathBuf> {
) -> Vec<AbsolutePathBuf> {
if !plugins_feature_enabled {
return Vec::new();
}
@@ -587,7 +587,7 @@ impl PluginsManager {
if let Some(analytics_events_client) = analytics_events_client {
analytics_events_client.track_plugin_installed(plugin_telemetry_metadata_from_root(
&result.plugin_id,
result.installed_path.as_path(),
&result.installed_path,
));
}
@@ -983,7 +983,7 @@ impl PluginsManager {
let manifest_paths = &manifest.paths;
let skill_config_rules = skill_config_rules_from_stack(&config.config_layer_stack);
let resolved_skills = load_plugin_skills(
source_path.as_path(),
&source_path,
manifest_paths,
self.restriction_product,
&skill_config_rules,
@@ -1061,7 +1061,7 @@ impl PluginsManager {
roots: &[AbsolutePathBuf],
) {
let mut roots = roots.to_vec();
roots.sort_unstable_by(|left, right| left.as_path().cmp(right.as_path()));
roots.sort_unstable();
roots.dedup();
if roots.is_empty() {
return;
@@ -1238,7 +1238,7 @@ impl PluginsManager {
{
roots.push(curated_repo_root);
}
roots.sort_unstable_by(|left, right| left.as_path().cmp(right.as_path()));
roots.sort_unstable();
roots.dedup();
roots
}
@@ -1703,9 +1703,9 @@ fn load_plugin(
.map(str::to_string)
.or_else(|| Some(manifest.name.clone()));
loaded_plugin.manifest_description = manifest.description.clone();
loaded_plugin.skill_roots = plugin_skill_roots(plugin_root.as_path(), manifest_paths);
loaded_plugin.skill_roots = plugin_skill_roots(&plugin_root, manifest_paths);
let resolved_skills = load_plugin_skills(
plugin_root.as_path(),
&plugin_root,
manifest_paths,
restriction_product,
skill_config_rules,
@@ -1734,7 +1734,7 @@ fn load_plugin(
struct ResolvedPluginSkills {
skills: Vec<SkillMetadata>,
disabled_skill_paths: HashSet<PathBuf>,
disabled_skill_paths: HashSet<AbsolutePathBuf>,
had_errors: bool,
}
@@ -1750,7 +1750,7 @@ impl ResolvedPluginSkills {
}
fn load_plugin_skills(
plugin_root: &Path,
plugin_root: &AbsolutePathBuf,
manifest_paths: &PluginManifestPaths,
restriction_product: Option<Product>,
skill_config_rules: &SkillConfigRules,
@@ -1778,17 +1778,20 @@ fn load_plugin_skills(
}
}
fn plugin_skill_roots(plugin_root: &Path, manifest_paths: &PluginManifestPaths) -> Vec<PathBuf> {
fn plugin_skill_roots(
plugin_root: &AbsolutePathBuf,
manifest_paths: &PluginManifestPaths,
) -> Vec<AbsolutePathBuf> {
let mut paths = default_skill_roots(plugin_root);
if let Some(path) = &manifest_paths.skills {
paths.push(path.to_path_buf());
paths.push(path.clone());
}
paths.sort_unstable();
paths.dedup();
paths
}
fn default_skill_roots(plugin_root: &Path) -> Vec<PathBuf> {
fn default_skill_roots(plugin_root: &AbsolutePathBuf) -> Vec<AbsolutePathBuf> {
let skills_dir = plugin_root.join(DEFAULT_SKILLS_DIR_NAME);
if skills_dir.is_dir() {
vec![skills_dir]
@@ -1815,8 +1818,8 @@ fn default_mcp_config_paths(plugin_root: &Path) -> Vec<AbsolutePathBuf> {
{
paths.push(default_path);
}
paths.sort_unstable_by(|left, right| left.as_path().cmp(right.as_path()));
paths.dedup_by(|left, right| left.as_path() == right.as_path());
paths.sort_unstable();
paths.dedup();
paths
}
@@ -1848,8 +1851,8 @@ fn default_app_config_paths(plugin_root: &Path) -> Vec<AbsolutePathBuf> {
{
paths.push(default_path);
}
paths.sort_unstable_by(|left, right| left.as_path().cmp(right.as_path()));
paths.dedup_by(|left, right| left.as_path() == right.as_path());
paths.sort_unstable();
paths.dedup();
paths
}
@@ -1894,18 +1897,18 @@ fn load_apps_from_paths(
pub fn plugin_telemetry_metadata_from_root(
plugin_id: &PluginId,
plugin_root: &Path,
plugin_root: &AbsolutePathBuf,
) -> PluginTelemetryMetadata {
let Some(manifest) = load_plugin_manifest(plugin_root) else {
let Some(manifest) = load_plugin_manifest(plugin_root.as_path()) else {
return PluginTelemetryMetadata::from_plugin_id(plugin_id);
};
let manifest_paths = &manifest.paths;
let has_skills = !plugin_skill_roots(plugin_root, manifest_paths).is_empty();
let mut mcp_server_names = Vec::new();
for path in plugin_mcp_config_paths(plugin_root, manifest_paths) {
for path in plugin_mcp_config_paths(plugin_root.as_path(), manifest_paths) {
mcp_server_names.extend(
load_mcp_servers_from_file(plugin_root, &path)
load_mcp_servers_from_file(plugin_root.as_path(), &path)
.mcp_servers
.into_keys(),
);
@@ -1921,7 +1924,7 @@ pub fn plugin_telemetry_metadata_from_root(
description: None,
has_skills,
mcp_server_names,
app_connector_ids: load_plugin_apps(plugin_root),
app_connector_ids: load_plugin_apps(plugin_root.as_path()),
}),
}
}
@@ -1951,7 +1954,7 @@ pub fn installed_plugin_telemetry_metadata(
return PluginTelemetryMetadata::from_plugin_id(plugin_id);
};
plugin_telemetry_metadata_from_root(plugin_id, plugin_root.as_path())
plugin_telemetry_metadata_from_root(plugin_id, &plugin_root)
}
fn load_mcp_servers_from_file(
+12 -9
View File
@@ -17,6 +17,7 @@ use codex_app_server_protocol::ConfigLayerSource;
use codex_config::types::McpServerTransportConfig;
use codex_login::CodexAuth;
use codex_protocol::protocol::Product;
use codex_utils_absolute_path::test_support::PathBufExt;
use pretty_assertions::assert_eq;
use std::fs;
use tempfile::TempDir;
@@ -164,7 +165,7 @@ fn load_plugins_loads_default_skills_and_mcp_servers() {
),
root: AbsolutePathBuf::try_from(plugin_root.clone()).unwrap(),
enabled: true,
skill_roots: vec![plugin_root.join("skills")],
skill_roots: vec![plugin_root.join("skills").abs()],
disabled_skill_paths: HashSet::new(),
has_enabled_skills: true,
mcp_servers: HashMap::from([(
@@ -205,7 +206,7 @@ fn load_plugins_loads_default_skills_and_mcp_servers() {
);
assert_eq!(
outcome.effective_skill_roots(),
vec![plugin_root.join("skills")]
vec![plugin_root.join("skills").abs()]
);
assert_eq!(outcome.effective_mcp_servers().len(), 1);
assert_eq!(
@@ -243,7 +244,9 @@ enabled = false
enabled = true
"#;
let outcome = load_plugins_from_config(config_toml, codex_home.path());
let skill_path = dunce::canonicalize(skill_path).expect("skill path should canonicalize");
let skill_path = dunce::canonicalize(skill_path)
.expect("skill path should canonicalize")
.abs();
assert_eq!(
outcome.plugins()[0].disabled_skill_paths,
@@ -325,7 +328,7 @@ fn plugin_telemetry_metadata_uses_default_mcp_config_path() {
let metadata = plugin_telemetry_metadata_from_root(
&PluginId::parse("sample@test").expect("plugin id should parse"),
&plugin_root,
&plugin_root.abs(),
);
assert_eq!(
@@ -490,8 +493,8 @@ fn load_plugins_uses_manifest_configured_component_paths() {
assert_eq!(
outcome.plugins()[0].skill_roots,
vec![
plugin_root.join("custom-skills"),
plugin_root.join("skills")
plugin_root.join("custom-skills").abs(),
plugin_root.join("skills").abs()
]
);
assert_eq!(
@@ -599,7 +602,7 @@ fn load_plugins_ignores_manifest_component_paths_without_dot_slash() {
assert_eq!(
outcome.plugins()[0].skill_roots,
vec![plugin_root.join("skills")]
vec![plugin_root.join("skills").abs()]
);
assert_eq!(
outcome.plugins()[0].mcp_servers,
@@ -799,7 +802,7 @@ fn capability_index_filters_inactive_and_zero_capability_plugins() {
};
let outcome = PluginLoadOutcome::from_plugins(vec![
LoadedPlugin {
skill_roots: vec![codex_home.path().join("skills-plugin/skills")],
skill_roots: vec![codex_home.path().join("skills-plugin/skills").abs()],
has_enabled_skills: true,
..plugin("skills@test", "skills-plugin", "skills-plugin")
},
@@ -816,7 +819,7 @@ fn capability_index_filters_inactive_and_zero_capability_plugins() {
plugin("empty@test", "empty-plugin", "empty-plugin"),
LoadedPlugin {
enabled: false,
skill_roots: vec![codex_home.path().join("disabled-plugin/skills")],
skill_roots: vec![codex_home.path().join("disabled-plugin/skills").abs()],
apps: vec![connector("connector_hidden")],
..plugin("disabled@test", "disabled-plugin", "disabled-plugin")
},