fix: mark resolved default profile aliases
This commit is contained in:
parent
ba9e924c89
commit
d77a86d550
|
|
@ -248,11 +248,13 @@ impl ProfileRegistry {
|
|||
let Some(default) = self.default.clone() else {
|
||||
return;
|
||||
};
|
||||
let Some(source) = default.source else {
|
||||
let Ok(default_entry) = self.select_named(default.source, &default.name) else {
|
||||
return;
|
||||
};
|
||||
let source = default_entry.source;
|
||||
let name = default_entry.name.clone();
|
||||
for entry in &mut self.entries {
|
||||
entry.is_default = entry.source == source && entry.name == default.name;
|
||||
entry.is_default = entry.source == source && entry.name == name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1005,6 +1007,42 @@ default-coder = "coder"
|
|||
assert!(selected.path.ends_with("profiles/project-coder.nix"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_default_alias_marks_resolved_default_entry() {
|
||||
let tmp = TempDir::new().unwrap();
|
||||
let project_dir = tmp.path().join("project/.insomnia");
|
||||
std::fs::create_dir_all(&project_dir).unwrap();
|
||||
let project_manifest = project_dir.join("manifest.toml");
|
||||
std::fs::write(
|
||||
&project_manifest,
|
||||
r#"
|
||||
[profiles]
|
||||
default = "work"
|
||||
[profiles.profile]
|
||||
coder = "profiles/coder.nix"
|
||||
[profiles.alias]
|
||||
work = "coder"
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let registry = ProfileDiscovery::with_sources(None, None, Some(project_manifest))
|
||||
.discover()
|
||||
.unwrap();
|
||||
let default = registry.default_entry().unwrap();
|
||||
assert_eq!(default.source, ProfileRegistrySource::Project);
|
||||
assert_eq!(default.name, "coder");
|
||||
assert!(default.is_default);
|
||||
assert_eq!(
|
||||
registry
|
||||
.entries()
|
||||
.iter()
|
||||
.filter(|entry| entry.is_default)
|
||||
.count(),
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unqualified_ambiguous_names_fail_closed() {
|
||||
let mut registry = ProfileRegistry::default();
|
||||
|
|
|
|||
|
|
@ -342,14 +342,6 @@ fn initial_profile_index(
|
|||
choices.len() - 1
|
||||
}
|
||||
|
||||
fn default_profile_selection(cwd: &Path) -> Option<ProfileChoice> {
|
||||
let (choices, default_index) = profile_choices_for_cwd(cwd);
|
||||
choices
|
||||
.get(default_index)
|
||||
.filter(|choice| choice.selector.is_some())
|
||||
.cloned()
|
||||
}
|
||||
|
||||
fn user_manifest_path_for_spawn(
|
||||
env_value: Option<OsString>,
|
||||
default_user_manifest: Option<PathBuf>,
|
||||
|
|
@ -908,7 +900,7 @@ permission = "write"
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn default_profile_selection_uses_project_registry_default() {
|
||||
fn profile_choices_use_project_registry_default_alias() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let project = temp.path().join("project");
|
||||
let insomnia = project.join(".insomnia");
|
||||
|
|
@ -917,14 +909,18 @@ permission = "write"
|
|||
insomnia.join("manifest.toml"),
|
||||
r#"
|
||||
[profiles]
|
||||
default = "coder"
|
||||
default = "work"
|
||||
[profiles.profile]
|
||||
coder = "profiles/coder.nix"
|
||||
[profiles.alias]
|
||||
work = "coder"
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let selected = default_profile_selection(&project).unwrap();
|
||||
let (choices, default_index) = profile_choices_for_cwd(&project);
|
||||
assert_eq!(default_index, 1);
|
||||
let selected = &choices[default_index];
|
||||
assert_eq!(selected.selector.as_deref(), Some("project:coder"));
|
||||
assert_eq!(selected.label, "project:coder (default)");
|
||||
assert!(selected.is_default);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user