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 buf = ctx.buffers.get("formula").cloned().unwrap_or_default();
|
||||||
let first_cat = ctx
|
let first_cat = ctx
|
||||||
.model
|
.model
|
||||||
.category_names()
|
.regular_category_names()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.next()
|
.next()
|
||||||
.map(String::from);
|
.map(String::from);
|
||||||
@ -3690,10 +3690,11 @@ mod tests {
|
|||||||
assert!(dbg.contains("FormulaPanel"), "Expected return to FormulaPanel, got: {dbg}");
|
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]
|
#[test]
|
||||||
fn commit_formula_without_categories_shows_status() {
|
fn commit_formula_without_regular_categories_shows_status() {
|
||||||
// Create an empty model (only virtual categories)
|
let m = Model::new("Empty"); // only has virtual _Index, _Dim
|
||||||
let m = Model::new("Empty");
|
|
||||||
let layout = make_layout(&m);
|
let layout = make_layout(&m);
|
||||||
let reg = default_registry();
|
let reg = default_registry();
|
||||||
let mut bufs = HashMap::new();
|
let mut bufs = HashMap::new();
|
||||||
@ -3702,11 +3703,15 @@ mod tests {
|
|||||||
ctx.buffers = &bufs;
|
ctx.buffers = &bufs;
|
||||||
let effects = CommitFormula.execute(&ctx);
|
let effects = CommitFormula.execute(&ctx);
|
||||||
let dbg = effects_debug(&effects);
|
let dbg = effects_debug(&effects);
|
||||||
// NOTE: Model::category_names() may include virtual categories (_Index, _Dim).
|
// Should NOT produce AddFormula targeting a virtual category
|
||||||
// If it does, this test needs to check the actual behavior rather than
|
assert!(
|
||||||
// assuming "no categories" means "no virtual ones either".
|
!dbg.contains("AddFormula"),
|
||||||
// Let's just verify it returns effects with FormulaPanel mode.
|
"Should not add formula when only virtual categories exist, got: {dbg}"
|
||||||
assert!(dbg.contains("FormulaPanel"), "Expected return to FormulaPanel, got: {dbg}");
|
);
|
||||||
|
assert!(
|
||||||
|
dbg.contains("Add at least one category first"),
|
||||||
|
"Expected status message, got: {dbg}"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Commit category add ────────────────────────────────────────────
|
// ── Commit category add ────────────────────────────────────────────
|
||||||
|
|||||||
@ -235,10 +235,9 @@ impl ImportPipeline {
|
|||||||
"Measure".to_string()
|
"Measure".to_string()
|
||||||
} else {
|
} else {
|
||||||
model
|
model
|
||||||
.categories
|
.regular_category_names()
|
||||||
.keys()
|
.first()
|
||||||
.next()
|
.map(|s| s.to_string())
|
||||||
.cloned()
|
|
||||||
.unwrap_or_else(|| "Measure".to_string())
|
.unwrap_or_else(|| "Measure".to_string())
|
||||||
};
|
};
|
||||||
for raw in &self.formulas {
|
for raw in &self.formulas {
|
||||||
|
|||||||
Reference in New Issue
Block a user