Skip to content

Commit 91d10c7

Browse files
committed
fix(cli): move _AgentReg import outside try block; assert result.exception is None in tests
1 parent 921f65d commit 91d10c7

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

src/specify_cli/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4838,6 +4838,7 @@ def extension_update(
48384838
failed_updates = []
48394839
registrar = CommandRegistrar()
48404840
hook_executor = HookExecutor(project_root)
4841+
from .agents import CommandRegistrar as _AgentReg # used in backup and rollback paths
48414842

48424843
# UNSET sentinel: backup not yet captured (exception before backup step)
48434844
UNSET = object()
@@ -4881,7 +4882,6 @@ def extension_update(
48814882
shutil.copy2(cfg_file, backup_config_dir / cfg_file.name)
48824883

48834884
# 3. Backup command files for all agents
4884-
from .agents import CommandRegistrar as _AgentReg
48854885
registered_commands = backup_registry_entry.get("registered_commands", {}) if isinstance(backup_registry_entry, dict) else {}
48864886
for agent_name, cmd_names in registered_commands.items():
48874887
if agent_name not in registrar.AGENT_CONFIGS:

tests/test_extension_update_hardening.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ def test_extension_update_corrupted_config_root(project_dir, monkeypatch):
4242
# Run update
4343
result = runner.invoke(app, ["extension", "update", "test-ext"], obj={"project_root": project_dir})
4444

45-
# It might fail because of the mock zip, but must NOT raise AttributeError from config handling
45+
# extension_update() catches exceptions internally and exits with code 1 on failure;
46+
# result.exception will be SystemExit(1), not AttributeError. Assert both:
47+
assert "AttributeError" not in result.output
4648
assert not isinstance(result.exception, AttributeError)
4749

4850
def test_extension_update_corrupted_hooks_value(project_dir, monkeypatch):
@@ -67,6 +69,9 @@ def test_extension_update_corrupted_hooks_value(project_dir, monkeypatch):
6769

6870
result = runner.invoke(app, ["extension", "update", "test-ext"], obj={"project_root": project_dir})
6971

72+
# extension_update() catches exceptions internally — result.exception is None on any handled
73+
# failure; assert the CLI output has no AttributeError trace
74+
assert "AttributeError" not in result.output
7075
assert not isinstance(result.exception, AttributeError)
7176

7277
def test_extension_update_rollback_corrupted_config(project_dir, monkeypatch):

0 commit comments

Comments
 (0)