Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix(config): warn about a deprecated section the migration declined to rewrite (#4121)
Worktrunk Bot85de5c9aa587
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ea0ebb500..8738db321 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -44,6 +44,8 @@- **`wt config show` reports Claude Code's plugin and Gemini CLI's extension from those tools' own listings**: it read `installed_plugins.json` and the `~/.gemini/extensions/` directory, so a store either tool relocated read as an absence and the section said "not installed" over an installed plugin. Both answers now come from `claude plugin list --json` and `gemini extensions list -o json`. `wt config plugins claude uninstall` follows: it runs the plugin removal and the marketplace removal every time, each tolerating only the absence Claude Code itself reports, so it no longer exits early with `Plugin not installed` on a file read. ([#4054](https://github.com/max-sixty/worktrunk/pull/4054))+- **A deprecated config section the migration declines to rewrite now warns instead of vanishing**: `select = "not a table"`, or a `[select]` whose `[switch.picker]` destination is already set, is left in place so the value isn't dropped — but the unknown-field check skipped it too, so nothing read the setting and nothing said so. It now reports `unknown field select (will be ignored)`. Empty legacy sections stay silent. ([#4121](https://github.com/max-sixty/worktrunk/pull/4121))+## 0.77.0### Improveddiff --git a/src/config/deprecation.rs b/src/config/deprecation.rsindex 72b809821..9a0b09066 100644--- a/src/config/deprecation.rs+++ b/src/config/deprecation.rs@@ -1931,7 +1931,10 @@ pub fn scope_to_repo_note(other_description: &str, key: &str) -> Option<&'static/// Classification of an unknown config key for warning purposes.pub enum UnknownKeyKind {- /// Deprecated key in its correct config type — deprecation system handles it+ /// Deprecated key in its correct config type — the deprecation system+ /// owns the message. Registration is all this says: whether the migration+ /// actually ran is the caller's to check (see `collect_unknown_warnings`),+ /// since a declined rewrite leaves the key unread and unreported.DeprecatedHandled,/// Deprecated key in the wrong config typeDeprecatedWrongConfig {@@ -4739,6 +4742,75 @@ ff = true);}+ /// A deprecated section the migration declined to rewrite still carries+ /// live user intent that nothing reads, so the unknown-field channel has+ /// to speak for it — the deprecation channel stays silent by design when+ /// the rewrite is unsafe.+ #[test]+ fn test_unmigrated_deprecated_section_warns_as_unknown() {+ use crate::config::{UnknownWarning, UserConfig, collect_unknown_warnings};++ // Malformed: `select` is a scalar, so `migrate_select_table` leaves it+ // alone rather than dropping the user's value.+ let warnings = collect_unknown_warnings::<UserConfig>("select = \"not a table\"\n");+ assert!(+ matches!(+ warnings.as_slice(),+ [UnknownWarning::TopLevelUnknown { key }] if key == "select"+ ),+ "expected select → unknown field, got {warnings:?}"+ );++ // Destination already occupied: the rewrite is skipped so it cannot+ // clobber the live `[switch.picker]`, leaving `[select]` read by+ // nobody.+ let warnings = collect_unknown_warnings::<UserConfig>(+ "[switch.picker]\npager = \"delta\"\n\n[select]\npreview = \"p\"\n",+ );+ assert!(+ matches!(+ warnings.as_slice(),+ [UnknownWarning::TopLevelUnknown { key }] if key == "select"+ ),+ "expected occupied-destination select → unknown field, got {warnings:?}"+ );++ // A scalar occupant (`switch = "x"`) is a *type* error for a known+ // field, so the round-trip analysis is unreliable and serde's own+ // message is the diagnostic — this channel stays out of it.+ assert!(+ collect_unknown_warnings::<UserConfig>("switch = \"x\"\n\n[select]\npreview = \"p\"\n")+ .is_empty(),+ "a type error belongs to serde, not the unknown-field channel"+ );++ // An empty deprecated section contributes no config; it stays silent.+ assert!(+ collect_unknown_warnings::<UserConfig>("[select]\n").is_empty(),+ "empty [select] must stay silent"+ );++ // A section the migration did rewrite is handled — no second warning+ // from this channel.+ assert!(+ collect_unknown_warnings::<UserConfig>("[select]\npager = \"delta\"\n").is_empty(),+ "migrated [select] must not warn"+ );++ // The rule is the registry's, not `select`'s: a malformed+ // `commit-generation` is skipped by its own migration and needs the+ // same fallback. (`ci` is exempt — it is still a live+ // `ProjectConfig` field, so its leftovers already warn per key.)+ let warnings = collect_unknown_warnings::<UserConfig>("commit-generation = \"keep me\"\n");+ assert!(+ matches!(+ warnings.as_slice(),+ [UnknownWarning::TopLevelUnknown { key }] if key == "commit-generation"+ ),+ "expected malformed commit-generation → unknown field, got {warnings:?}"+ );+ }+#[test]fn test_nested_user_only_key_redirects_generally() {use crate::config::{ProjectConfig, UnknownWarning, UserConfig, collect_unknown_warnings};diff --git a/src/config/unknown_tree.rs b/src/config/unknown_tree.rsindex 5f3f06ad7..2e0b8054f 100644--- a/src/config/unknown_tree.rs+++ b/src/config/unknown_tree.rs@@ -238,6 +238,10 @@ impl<'a> OtherStatus<'a> {/// [`nested_key_belongs_in`](crate::config::nested_key_belongs_in) redirects/// still fire.///+/// A deprecated top-level section is left to the deprecation channel only+/// when migration removed it; one that survived non-empty is reported here+/// (see the private `deprecated_key_declined` helper).+////// Returns an empty vec if either analysis is unreliable — the load path/// surfaces parse/type errors elsewhere.pub fn collect_unknown_warnings<C: WorktrunkConfig>(raw_contents: &str) -> Vec<UnknownWarning> {@@ -250,6 +254,9 @@ pub fn collect_unknown_warnings<C: WorktrunkConfig>(raw_contents: &str) -> Vec<UUnknownAnalysis::Parsed(t) => t,UnknownAnalysis::Unreliable(_) => return Vec::new(),};+ // `compute_unknown_tree` reached `Parsed` above, so this parse cannot+ // fail; the fallback just keeps the path panic-free.+ let migrated_root = migrated.parse::<toml::Table>().unwrap_or_default();// The same content viewed as the *other* config type: a nested key absent// from this tree is valid there. Unreliable → no generalized redirect.let other_analysis = compute_unknown_tree::<C::Other>(&migrated);@@ -262,6 +269,9 @@ pub fn collect_unknown_warnings<C: WorktrunkConfig>(raw_contents: &str) -> Vec<Ufor key in &raw_tree.keys {use crate::config::UnknownKeyKind;let warning = match crate::config::classify_unknown_key::<C>(key) {+ UnknownKeyKind::DeprecatedHandled if deprecated_key_declined(&migrated_root, key) => {+ UnknownWarning::TopLevelUnknown { key: key.clone() }+ }UnknownKeyKind::DeprecatedHandled => continue,UnknownKeyKind::DeprecatedWrongConfig {other_description,@@ -290,6 +300,28 @@ pub fn collect_unknown_warnings<C: WorktrunkConfig>(raw_contents: &str) -> Vec<Uout}+/// Whether `key` — a registered deprecated section — still carries config+/// after migration.+///+/// [`classify_unknown_key`](crate::config::classify_unknown_key) answers from+/// the registry alone: the name is deprecated, so the deprecation channel owns+/// the message. That holds only when the rewrite actually ran. A migration+/// that declines — a malformed scalar (`select = "x"`), a destination already+/// occupied — deliberately leaves the key in place and emits nothing, and the+/// documented handoff is for the unknown-field message to speak instead. Left+/// suppressed, the setting is read by nobody and reported by no one.+///+/// An empty deprecated section is the one survivor that stays silent: it+/// contributes no config, which is why the migration leaves it alone in the+/// first place.+fn deprecated_key_declined(migrated: &toml::Table, key: &str) -> bool {+ match migrated.get(key) {+ Some(toml::Value::Table(t)) => !t.is_empty(),+ Some(_) => true,+ None => false,+ }+}+fn walk_nested<C: WorktrunkConfig>(tree: &UnknownTree,prefix: &str,