mirror of
https://github.com/openai/codex.git
synced 2026-11-20 22:40:37 +00:00
Merge operation-scoped config authorization into exact staging
# Conflicts: # codex-rs/git-utils/src/safe_git.rs # codex-rs/git-utils/src/safe_git_tests.rs
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
use super::*;
|
||||
use crate::apply::ApplyGitRequest;
|
||||
use crate::apply::apply_git_patch;
|
||||
use crate::git_command::GitRunner;
|
||||
use crate::git_config::GitConfigScope;
|
||||
use crate::guarded_config::GuardedGitConfig;
|
||||
#[cfg(unix)]
|
||||
use crate::patch_paths::stage_paths;
|
||||
use pretty_assertions::assert_eq;
|
||||
@@ -156,7 +158,9 @@ fn filter_snapshot_retains_required_without_treating_it_as_executable() {
|
||||
"true",
|
||||
));
|
||||
assert_eq!(
|
||||
executable_filter_drivers(&entries).expect("executable drivers"),
|
||||
executable_filter_drivers(&entries)
|
||||
.expect("executable drivers")
|
||||
.0,
|
||||
BTreeSet::from(["demo".to_string()])
|
||||
);
|
||||
let selected = BTreeMap::from([(b"file.txt".to_vec(), "demo".to_string())]);
|
||||
@@ -165,14 +169,11 @@ fn filter_snapshot_retains_required_without_treating_it_as_executable() {
|
||||
.expect("Git add filter policy"),
|
||||
None
|
||||
);
|
||||
let neutralization = GitFilterNeutralization {
|
||||
git_config_args: Vec::new(),
|
||||
_config_dir: None,
|
||||
filter_config: entries,
|
||||
};
|
||||
assert_eq!(
|
||||
neutralization.filter_value("demo", "required"),
|
||||
Some("true")
|
||||
entries
|
||||
.get("filter.demo.required")
|
||||
.map(|entry| entry.value.as_str()),
|
||||
Some("true"),
|
||||
);
|
||||
|
||||
let required_only = filter_entries(
|
||||
@@ -302,9 +303,12 @@ fn sentinel_special_states_and_literal_driver_names_remain_distinct() {
|
||||
let root = repo.path();
|
||||
configure_marker_filter(root, driver);
|
||||
let git = GitRunner::for_cwd_io(root).expect("trusted Git");
|
||||
let mut config =
|
||||
GuardedGitConfig::authorize(&git, root, Vec::new()).expect("authorized config sources");
|
||||
|
||||
std::fs::write(root.join(".gitattributes"), special_rule).expect("write special attribute");
|
||||
ensure_no_selected_executable_git_filters(&git, root, &["file.txt".to_string()], &[])
|
||||
config
|
||||
.authorize_filter_paths(&["file.txt".to_string()])
|
||||
.expect("allow special attribute state");
|
||||
assert!(!marker_filter_ran(root), "special {driver}");
|
||||
|
||||
@@ -313,8 +317,9 @@ fn sentinel_special_states_and_literal_driver_names_remain_distinct() {
|
||||
format!("file.txt filter={driver}\n"),
|
||||
)
|
||||
.expect("write literal attribute");
|
||||
let result =
|
||||
ensure_no_selected_executable_git_filters(&git, root, &["file.txt".to_string()], &[]);
|
||||
let mut literal_config = GuardedGitConfig::authorize(&git, root, Vec::new())
|
||||
.expect("authorize literal-attribute operation");
|
||||
let result = literal_config.authorize_filter_paths(&["file.txt".to_string()]);
|
||||
let error = match result {
|
||||
Ok(_) => panic!("accepted literal sentinel-named driver {driver}"),
|
||||
Err(error) => error,
|
||||
@@ -335,9 +340,12 @@ fn sentinel_probe_neutralizes_every_known_driver_after_attribute_swap() {
|
||||
.expect("write initial attribute");
|
||||
|
||||
let git = GitRunner::for_cwd_io(root).expect("trusted Git");
|
||||
let entries = read_filter_config(&git, root, &[]).expect("filter config");
|
||||
let config =
|
||||
GuardedGitConfig::authorize(&git, root, Vec::new()).expect("authorized config sources");
|
||||
let entries = read_filter_config(&config).expect("filter config");
|
||||
let executable_drivers = executable_filter_drivers(&entries).expect("executable drivers");
|
||||
let neutralization = executable_filter_guard(&git, root, entries, &executable_drivers)
|
||||
let neutralization = config
|
||||
.build_filter_override(&executable_drivers)
|
||||
.expect("filter neutralization");
|
||||
let output = run_git_success(root, &["check-attr", "-z", "filter", "--", "file.txt"]);
|
||||
let attributes = parse_filter_attributes(&output.stdout, &[b"file.txt".to_vec()])
|
||||
@@ -349,10 +357,8 @@ fn sentinel_probe_neutralizes_every_known_driver_after_attribute_swap() {
|
||||
)
|
||||
.expect("swap attribute after snapshot");
|
||||
let resolved = resolve_filter_attribute_sentinels(
|
||||
&git,
|
||||
root,
|
||||
&config,
|
||||
attributes,
|
||||
&[],
|
||||
&executable_drivers,
|
||||
&neutralization,
|
||||
)
|
||||
@@ -368,9 +374,12 @@ fn high_cardinality_ordinary_sentinels_stop_at_hard_child_probe_budget() {
|
||||
let root = repo.path();
|
||||
configure_marker_filter(root, "unspecified");
|
||||
let git = GitRunner::for_cwd_io(root).expect("trusted Git");
|
||||
let entries = read_filter_config(&git, root, &[]).expect("filter config");
|
||||
let config =
|
||||
GuardedGitConfig::authorize(&git, root, Vec::new()).expect("authorized config sources");
|
||||
let entries = read_filter_config(&config).expect("filter config");
|
||||
let executable_drivers = executable_filter_drivers(&entries).expect("executable drivers");
|
||||
let neutralization = executable_filter_guard(&git, root, entries, &executable_drivers)
|
||||
let neutralization = config
|
||||
.build_filter_override(&executable_drivers)
|
||||
.expect("filter neutralization");
|
||||
let attributes = (0..=SentinelFilterProbeBudget::max_probes())
|
||||
.map(|index| {
|
||||
@@ -382,10 +391,8 @@ fn high_cardinality_ordinary_sentinels_stop_at_hard_child_probe_budget() {
|
||||
.collect();
|
||||
|
||||
let error = resolve_filter_attribute_sentinels(
|
||||
&git,
|
||||
root,
|
||||
&config,
|
||||
attributes,
|
||||
&[],
|
||||
&executable_drivers,
|
||||
&neutralization,
|
||||
)
|
||||
@@ -398,36 +405,31 @@ fn high_cardinality_ordinary_sentinels_stop_at_hard_child_probe_budget() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unrelated_sentinel_probe_failures_remain_generic_and_fail_closed() {
|
||||
fn sentinel_probe_rejects_non_sentinel_driver_before_launch() {
|
||||
let repo = init_filter_repo();
|
||||
let root = repo.path();
|
||||
configure_marker_filter(root, "set");
|
||||
std::fs::write(root.join(".gitattributes"), "file.txt filter\n")
|
||||
.expect("write special attribute");
|
||||
let git = GitRunner::for_cwd_io(root).expect("trusted Git");
|
||||
let entries = read_filter_config(&git, root, &[]).expect("filter config");
|
||||
let config =
|
||||
GuardedGitConfig::authorize(&git, root, Vec::new()).expect("authorized config sources");
|
||||
let entries = read_filter_config(&config).expect("filter config");
|
||||
let executable_drivers = executable_filter_drivers(&entries).expect("executable drivers");
|
||||
let neutralization = executable_filter_guard(&git, root, entries, &executable_drivers)
|
||||
let neutralization = config
|
||||
.build_filter_override(&executable_drivers)
|
||||
.expect("filter neutralization");
|
||||
let mut budget = SentinelFilterProbeBudget::default();
|
||||
let malformed_config = ["-c".to_string(), "=".to_string()];
|
||||
|
||||
let error = sentinel_spelling_selects_filter_driver(
|
||||
&git,
|
||||
root,
|
||||
&config,
|
||||
b"file.txt",
|
||||
"set",
|
||||
&malformed_config,
|
||||
"ordinary",
|
||||
&neutralization,
|
||||
&mut budget,
|
||||
)
|
||||
.expect_err("malformed config must fail both probes");
|
||||
assert_eq!(error.kind(), io::ErrorKind::Other);
|
||||
assert!(
|
||||
error
|
||||
.to_string()
|
||||
.starts_with("git filter attribute selection probe failed with required status")
|
||||
);
|
||||
.expect_err("reject non-sentinel probe");
|
||||
assert_eq!(error.kind(), io::ErrorKind::InvalidInput);
|
||||
assert!(!marker_filter_ran(root));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user