[fix](cli): fill in the model name and path in kt model remove/edit warnings (#2220)

This commit is contained in:
Mohammad Hijjawi
2026-10-12 05:44:24 +01:00
committed by GitHub
parent 5d048e5165
commit 44fbb184d5
2 changed files with 47 additions and 5 deletions
+5 -5
View File
@@ -1550,8 +1550,8 @@ def edit_model(
elif choice == "3":
# Delete model
console.print()
console.print(f"[bold yellow]{t('model_edit_delete_warning')}[/bold yellow]")
console.print(f" {t('model_edit_delete_note')}")
console.print(f"[bold yellow]{t('model_edit_delete_warning', name=model.name)}[/bold yellow]")
console.print(f" {t('model_edit_delete_note', path=model.path)}")
console.print()
if Confirm.ask(t("model_edit_delete_confirm", name=model.name), default=False):
@@ -1936,8 +1936,8 @@ def remove_model(
raise typer.Exit(1)
console.print()
console.print(f"[bold yellow]{t('model_remove_warning')}[/bold yellow]")
console.print(f" {t('model_remove_note')}")
console.print(f"[bold yellow]{t('model_remove_warning', name=name)}[/bold yellow]")
console.print(f" {t('model_remove_note', path=model.path)}")
console.print(f" [dim]Path: {model.path}[/dim]")
console.print()
@@ -1983,7 +1983,7 @@ def remove_model(
print_success(t("model_removed", name=name))
console.print()
else:
print_error(t("model_remove_failed", name=name))
print_error(t("model_remove_failed", error=name))
raise typer.Exit(1)
@@ -0,0 +1,42 @@
import os
import sys
import unittest
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mock import patch
from typer.testing import CliRunner
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
from ci.ci_register import register_cpu_ci
register_cpu_ci(est_time=0.1, suite="default")
from kt_kernel.cli.commands import model as model_cmd
from kt_kernel.cli.utils import user_model_registry
from kt_kernel.cli.utils.user_model_registry import UserModel, UserModelRegistry
class TestModelRemove(unittest.TestCase):
def test_remove_prints_model_name_and_path(self):
with TemporaryDirectory() as tmp:
registry_file = Path(tmp) / "user_models.yaml"
model_path = str(Path(tmp) / "my-model")
UserModelRegistry(registry_file).add_model(UserModel(name="my-model", path=model_path, format="gguf"))
with (
patch.dict(os.environ, {"KT_LANG": "en", "COLUMNS": "400"}),
patch.object(user_model_registry, "USER_MODELS_FILE", registry_file),
):
result = CliRunner().invoke(model_cmd.app, ["remove", "my-model", "--yes"])
self.assertEqual(result.exit_code, 0, result.output)
self.assertNotIn("{name}", result.output)
self.assertNotIn("{path}", result.output)
self.assertIn("Remove model 'my-model' from registry?", result.output)
self.assertIn(model_path, result.output.split("Model files will NOT be deleted from")[1])
self.assertEqual(UserModelRegistry(registry_file).list_models(), [])
if __name__ == "__main__":
unittest.main()