diff --git a/src/command/cmd.rs b/src/command/cmd.rs index 47ca668..d47d1c8 100644 --- a/src/command/cmd.rs +++ b/src/command/cmd.rs @@ -1819,7 +1819,7 @@ impl Cmd for CommitFormula { let buf = ctx.buffers.get("formula").cloned().unwrap_or_default(); let first_cat = ctx .model - .category_names() + .regular_category_names() .into_iter() .next() .map(String::from); @@ -3690,10 +3690,11 @@ mod tests { assert!(dbg.contains("FormulaPanel"), "Expected return to FormulaPanel, got: {dbg}"); } + /// Regression: CommitFormula must not target virtual categories (_Index, _Dim) + /// when no regular categories exist. It should show "Add at least one category first." #[test] - fn commit_formula_without_categories_shows_status() { - // Create an empty model (only virtual categories) - let m = Model::new("Empty"); + fn commit_formula_without_regular_categories_shows_status() { + let m = Model::new("Empty"); // only has virtual _Index, _Dim let layout = make_layout(&m); let reg = default_registry(); let mut bufs = HashMap::new(); @@ -3702,11 +3703,15 @@ mod tests { ctx.buffers = &bufs; let effects = CommitFormula.execute(&ctx); let dbg = effects_debug(&effects); - // NOTE: Model::category_names() may include virtual categories (_Index, _Dim). - // If it does, this test needs to check the actual behavior rather than - // assuming "no categories" means "no virtual ones either". - // Let's just verify it returns effects with FormulaPanel mode. - assert!(dbg.contains("FormulaPanel"), "Expected return to FormulaPanel, got: {dbg}"); + // Should NOT produce AddFormula targeting a virtual category + assert!( + !dbg.contains("AddFormula"), + "Should not add formula when only virtual categories exist, got: {dbg}" + ); + assert!( + dbg.contains("Add at least one category first"), + "Expected status message, got: {dbg}" + ); } // ── Commit category add ──────────────────────────────────────────── diff --git a/src/import/wizard.rs b/src/import/wizard.rs index de7c86b..04e2f62 100644 --- a/src/import/wizard.rs +++ b/src/import/wizard.rs @@ -235,10 +235,9 @@ impl ImportPipeline { "Measure".to_string() } else { model - .categories - .keys() - .next() - .cloned() + .regular_category_names() + .first() + .map(|s| s.to_string()) .unwrap_or_else(|| "Measure".to_string()) }; for raw in &self.formulas {