fix: remove profile aliases

This commit is contained in:
Keisuke Hirata 2026-05-30 03:20:34 +09:00
parent 31620257cd
commit 4773be702a
No known key found for this signature in database
4 changed files with 7 additions and 126 deletions

View File

@ -112,7 +112,7 @@ pub fn user_manifest_path_with_env_override() -> Option<PathBuf> {
user_manifest_path_from_env(std::env::var_os(USER_MANIFEST_ENV)).or_else(user_manifest_path)
}
/// `<config_dir>/profiles.toml` — user profile registry/default/alias configuration.
/// `<config_dir>/profiles.toml` — user profile registry/default configuration.
///
/// This is application/profile selection configuration, not a Pod manifest
/// layer. It deliberately ignores [`USER_MANIFEST_ENV`].

View File

@ -153,13 +153,12 @@ impl ProfileRegistryEntry {
}
/// Discovered profile registry. User/project `profiles.toml` files contribute
/// only profile discovery metadata (entries, aliases, defaults); those files are
/// only profile discovery metadata (entries and defaults); those files are
/// application/project UX configuration, not Pod runtime manifests and are not
/// merged into the selected profile's runtime manifest.
#[derive(Debug, Clone, Default)]
pub struct ProfileRegistry {
entries: Vec<ProfileRegistryEntry>,
aliases: Vec<ProfileAlias>,
default: Option<ProfileDefault>,
}
@ -194,25 +193,6 @@ impl ProfileRegistry {
source: Option<ProfileRegistrySource>,
name: &str,
) -> Result<&ProfileRegistryEntry, ProfileError> {
let alias_matches: Vec<_> = self
.aliases
.iter()
.filter(|alias| alias.name == name && source.is_none_or(|s| s == alias.source))
.collect();
match alias_matches.as_slice() {
[alias] => return self.select_named(alias.target_source, &alias.target_name),
[] => {}
_ => {
return Err(ProfileError::AmbiguousProfileName {
name: name.to_string(),
matches: alias_matches
.iter()
.map(|alias| format!("{}:{}", alias.source, alias.name))
.collect(),
});
}
}
let matches: Vec<_> = self
.entries
.iter()
@ -237,10 +217,6 @@ impl ProfileRegistry {
self.entries.push(entry);
}
fn push_alias(&mut self, alias: ProfileAlias) {
self.aliases.push(alias);
}
fn set_default(&mut self, default: ProfileDefault) {
self.default = Some(default);
}
@ -260,14 +236,6 @@ impl ProfileRegistry {
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
struct ProfileAlias {
source: ProfileRegistrySource,
name: String,
target_source: Option<ProfileRegistrySource>,
target_name: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
struct ProfileDefault {
source: Option<ProfileRegistrySource>,
@ -520,8 +488,6 @@ struct ProfileRegistryDocument {
default: Option<String>,
#[serde(default, alias = "entries")]
profile: BTreeMap<String, ProfileEntryConfig>,
#[serde(default, alias = "aliases")]
alias: BTreeMap<String, String>,
}
#[derive(Debug, Deserialize)]
@ -574,16 +540,6 @@ fn load_profile_registry_file(
});
}
for (name, target) in config.alias {
let (target_source, target_name) = parse_profile_ref(&target);
registry.push_alias(ProfileAlias {
source,
name,
target_source: target_source.or(Some(source)),
target_name,
});
}
if let Some(default) = config.default {
let (default_source, default_name) = parse_profile_ref(&default);
registry.set_default(ProfileDefault {
@ -1109,49 +1065,7 @@ description = "Project coder"
}
#[test]
fn config_alias_unqualified_target_resolves_within_declaring_source() {
let tmp = TempDir::new().unwrap();
let user_config = tmp.path().join("profiles.toml");
let project_dir = tmp.path().join("project/.insomnia");
std::fs::create_dir_all(&project_dir).unwrap();
let project_config = project_dir.join("profiles.toml");
std::fs::write(
&user_config,
r#"
[profile]
coder = "profiles/user-coder.nix"
"#,
)
.unwrap();
std::fs::write(
&project_config,
r#"
[profile]
coder = "profiles/project-coder.nix"
[alias]
default-coder = "coder"
"#,
)
.unwrap();
let registry =
ProfileDiscovery::with_sources(None, Some(user_config), Some(project_config))
.discover()
.unwrap();
let selected = registry
.select(&ProfileSelector::source_named(
ProfileRegistrySource::Project,
"default-coder",
))
.unwrap();
assert_eq!(selected.source, ProfileRegistrySource::Project);
assert_eq!(selected.name, "coder");
assert!(selected.path.ends_with("profiles/project-coder.nix"));
}
#[test]
fn config_default_alias_marks_resolved_default_entry() {
fn default_marks_direct_profile_entry() {
let tmp = TempDir::new().unwrap();
let project_dir = tmp.path().join("project/.insomnia");
std::fs::create_dir_all(&project_dir).unwrap();
@ -1159,11 +1073,9 @@ default-coder = "coder"
std::fs::write(
&project_config,
r#"
default = "work"
default = "coder"
[profile]
coder = "profiles/coder.nix"
[alias]
work = "coder"
"#,
)
.unwrap();
@ -1215,30 +1127,4 @@ work = "coder"
.unwrap();
assert_eq!(selected.path, PathBuf::from("/project/coder.nix"));
}
#[test]
fn aliases_resolve_within_their_source() {
let mut registry = ProfileRegistry::default();
registry.push_entry(ProfileRegistryEntry {
source: ProfileRegistrySource::Project,
name: "coder".to_string(),
path: PathBuf::from("/project/coder.nix"),
description: None,
is_default: false,
});
registry.push_alias(ProfileAlias {
source: ProfileRegistrySource::Project,
name: "default-coder".to_string(),
target_source: Some(ProfileRegistrySource::Project),
target_name: "coder".to_string(),
});
let selected = registry
.select(&ProfileSelector::source_named(
ProfileRegistrySource::Project,
"default-coder",
))
.unwrap();
assert_eq!(selected.name, "coder");
}
}

View File

@ -901,7 +901,7 @@ permission = "write"
}
#[test]
fn profile_choices_use_project_registry_default_alias() {
fn profile_choices_use_project_registry_default() {
let temp = tempfile::tempdir().unwrap();
let project = temp.path().join("project");
let insomnia = project.join(".insomnia");
@ -909,11 +909,9 @@ permission = "write"
std::fs::write(
insomnia.join("profiles.toml"),
r#"
default = "work"
default = "coder"
[profile]
coder = "profiles/coder.nix"
[alias]
work = "coder"
"#,
)
.unwrap();

View File

@ -51,9 +51,6 @@ default = "coder"
[profile]
coder = "profiles/coder.nix"
reviewer = "profiles/reviewer.nix"
[alias]
work = "project:coder"
```
Table entries can carry descriptions:
@ -64,7 +61,7 @@ path = "profiles/coder.nix"
description = "Project coding assistant"
```
Relative registry paths are resolved against the `profiles.toml` file that declares them. Discovery checks bundled builtin profiles, then the user registry at `<config_dir>/profiles.toml`, then the nearest project registry at `.insomnia/profiles.toml`. Later defaults override earlier defaults, so a project default wins over a user default. Unqualified alias/default targets resolve within the declaring source by default. Unqualified ambiguous names fail closed:
Relative registry paths are resolved against the `profiles.toml` file that declares them. Discovery checks bundled builtin profiles, then the user registry at `<config_dir>/profiles.toml`, then the nearest project registry at `.insomnia/profiles.toml`. Later defaults override earlier defaults, so a project default wins over a user default. Unqualified defaults resolve within the declaring source by default. Unqualified ambiguous names fail closed:
```sh
insomnia --profile coder # fails if both user:coder and project:coder exist