Skip to content

Commit 77fe11d

Browse files
committed
fix(config): let a global opt-out reach a repo-loaded config
Toggling Refine (or Annotations, or the metadata pass) off in the app stuck for as long as no repository was loaded, then silently flipped back on. The app writes only the global config, but a config loaded from a repo directory merged the two enable flags with OR — and those flags are plain bools defaulting to true, so a repo that never mentions refinement contributes true and the global false can never win. Every repo without a .diffcore.toml hit this, which is most of them. Merge with AND instead: these passes cost the user money, so either side may switch one off and neither can force it back on. A repo opting out still wins, which it did before. annotations_enabled was not merged at all, leaving its toggle equally stuck, so it joins the other two.
1 parent 0b037cb commit 77fe11d

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

‎crates/diffcore-core/src/config.rs‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,14 @@ impl DiffcoreConfig {
665665
None
666666
}
667667

668+
/// Fold the global LLM config into this (repo-local) one.
669+
///
670+
/// Optional settings take the local value when it is set and fall back to
671+
/// the global one. The enable flags are plain bools defaulting to `true`,
672+
/// so "the repo never mentioned this" and "the repo asked for it" are the
673+
/// same value — an OR would make a global opt-out unreachable for the many
674+
/// repos with no `.diffcore.toml` at all. These passes cost the user money,
675+
/// so either side may switch one off and neither can force it back on.
668676
fn apply_global_llm_defaults(&mut self, global: &Self) {
669677
self.llm.provider = self
670678
.llm
@@ -678,8 +686,10 @@ impl DiffcoreConfig {
678686
.clone()
679687
.or_else(|| global.llm.key_cmd.clone());
680688
self.llm.key = self.llm.key.clone().or_else(|| global.llm.key.clone());
689+
self.llm.annotations_enabled =
690+
self.llm.annotations_enabled && global.llm.annotations_enabled;
681691

682-
self.llm.refinement.enabled = self.llm.refinement.enabled || global.llm.refinement.enabled;
692+
self.llm.refinement.enabled = self.llm.refinement.enabled && global.llm.refinement.enabled;
683693
self.llm.refinement.provider = self
684694
.llm
685695
.refinement
@@ -699,7 +709,7 @@ impl DiffcoreConfig {
699709
.clone()
700710
.or_else(|| global.llm.refinement.key_cmd.clone());
701711

702-
self.llm.metadata.enabled = self.llm.metadata.enabled || global.llm.metadata.enabled;
712+
self.llm.metadata.enabled = self.llm.metadata.enabled && global.llm.metadata.enabled;
703713
self.llm.metadata.provider = self
704714
.llm
705715
.metadata
@@ -903,6 +913,24 @@ paths = ["dist/**"]
903913
assert_eq!(merged.llm.refinement.provider, Some("claude".to_string()));
904914
}
905915

916+
#[test]
917+
fn global_opt_out_survives_a_repo_that_never_mentions_the_flag() {
918+
// The desktop app only ever writes the global config, so turning a pass
919+
// off there must not be undone by a repo whose .diffcore.toml is silent
920+
// on the subject.
921+
let mut global = DiffcoreConfig::default();
922+
global.llm.annotations_enabled = false;
923+
global.llm.refinement.enabled = false;
924+
global.llm.metadata.enabled = false;
925+
926+
let mut merged = DiffcoreConfig::default();
927+
merged.apply_global_llm_defaults(&global);
928+
929+
assert!(!merged.llm.annotations_enabled, "annotations should stay off");
930+
assert!(!merged.llm.refinement.enabled, "refinement should stay off");
931+
assert!(!merged.llm.metadata.enabled, "metadata should stay off");
932+
}
933+
906934
#[test]
907935
fn test_save_global_roundtrip_via_custom_home() {
908936
let home = tempfile::tempdir().unwrap();

0 commit comments

Comments
 (0)