mirror of
https://github.com/openai/codex.git
synced 2026-12-03 00:41:03 +00:00
## What changed Add `resolve_root_git_project_uri_for_trust` to resolve repository trust roots through `ExecutorFileSystem` using executor path conventions. Share repository and linked-worktree validation with native lookup while preserving native ancestry for paths with opaque URI representations. Extract `ProjectTrustLookup` to match merged project settings using supplied path spellings and an explicit path convention. Preserve canonical-before-original and cwd-before-repository-root precedence, including cwd entries without a trust level, with ASCII case-insensitive matching for Windows. ## Testing Add coverage for POSIX, Windows drive and UNC trust roots, project-key precedence and case handling, and native/URI lookup parity. Extend environment-config coverage to verify returned `projects` entries include entries without a trust level. GitOrigin-RevId: 315434802e86cceee85b14bc1c3767a45e3139f5
82 lines
2.4 KiB
Rust
82 lines
2.4 KiB
Rust
//! Exercises project-key precedence and map matching across path conventions.
|
|
|
|
use super::*;
|
|
use codex_protocol::config_types::TrustLevel;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
fn config_with_projects(entries: &[(&str, Option<TrustLevel>)]) -> ConfigToml {
|
|
ConfigToml {
|
|
projects: Some(
|
|
entries
|
|
.iter()
|
|
.map(|(key, trust_level)| {
|
|
(
|
|
key.to_string(),
|
|
ProjectConfig {
|
|
trust_level: *trust_level,
|
|
},
|
|
)
|
|
})
|
|
.collect(),
|
|
),
|
|
..Default::default()
|
|
}
|
|
}
|
|
|
|
fn assert_lookup_order(lookup: &ProjectTrustLookup, entries: &[(&str, Option<TrustLevel>)]) {
|
|
let mut config = config_with_projects(entries);
|
|
for (key, trust_level) in entries {
|
|
assert_eq!(
|
|
config.get_active_project_for_lookup(lookup),
|
|
Some(ProjectConfig {
|
|
trust_level: *trust_level
|
|
}),
|
|
);
|
|
config.projects.as_mut().unwrap().remove(*key);
|
|
}
|
|
assert_eq!(config.get_active_project_for_lookup(lookup), None);
|
|
assert_eq!(
|
|
ConfigToml::default().get_active_project_for_lookup(lookup),
|
|
None
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn posix_lookup_preserves_cwd_root_alias_order_and_case() {
|
|
let lookup = ProjectTrustLookup::from_paths(
|
|
PathConvention::Posix,
|
|
[
|
|
("/alias/src".into(), Some("/repo/src".into())),
|
|
("/alias".into(), Some("/repo".into())),
|
|
],
|
|
);
|
|
assert_lookup_order(
|
|
&lookup,
|
|
&[
|
|
("/repo/src", None),
|
|
("/alias/src", Some(TrustLevel::Trusted)),
|
|
("/repo", Some(TrustLevel::Untrusted)),
|
|
("/alias", Some(TrustLevel::Trusted)),
|
|
],
|
|
);
|
|
assert_eq!(
|
|
config_with_projects(&[("/Repo/src", Some(TrustLevel::Trusted))])
|
|
.get_active_project_for_lookup(&lookup),
|
|
None,
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn windows_prefers_exact_normalized_key_then_sorted_aliases() {
|
|
let lookup =
|
|
ProjectTrustLookup::from_paths(PathConvention::Windows, [(r"C:\Repo".into(), None)]);
|
|
assert_lookup_order(
|
|
&lookup,
|
|
&[
|
|
(r"c:\repo", Some(TrustLevel::Trusted)),
|
|
(r"C:\REPO", Some(TrustLevel::Untrusted)),
|
|
(r"C:\Repo", Some(TrustLevel::Trusted)),
|
|
],
|
|
);
|
|
}
|