refactor: use regular_category_names in command and import wizard
Updates `CommitFormula` and `ImportPipeline` to use `regular_category_names` instead of `category_names` . This ensures that these components do not target or default to virtual categories (_Index, _Dim) when no regular categories are present. Includes updated tests for `CommitFormula` to verify it correctly handles cases with no regular categories. Co-Authored-By: fiddlerwoaroof/git-smart-commit (unsloth/gemma-4-26B-A4B-it-GGUF:UD-Q5_K_XL)
This commit is contained in:
@ -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 ────────────────────────────────────────────
|
||||
|
||||
@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user