feat(palette): comprehensive command library (32 commands, up from 11)
Added commands focused on ergonomics and mouse-free operation: View (window toggles, 12 new): toggle_text_viewer, toggle_diagnostics, toggle_usage_analytics, toggle_context_preview, toggle_tier1_strategy, toggle_tier2_tech_lead, toggle_tier3_workers, toggle_tier4_qa, toggle_external_tools, toggle_shader_editor, toggle_undo_redo_history, toggle_command_palette Layout (3 new): show_all_panels, hide_all_panels, save_workspace_profile, show_workspace_manager Theme (1 new): cycle_theme (Dark -> Light -> NERV cycle) Tools (2 new): undo, redo Project (1 new): save_all (flush to project + config + global config) Help (1 new): show_command_palette_help (opens docs/Readme.md in Text Viewer) Refactored: extracted _toggle_window and _toggle_attr helpers to reduce duplication and make commands safer (no-op if state is missing). Reset session now also clears comms and tool logs (matches the menu item behavior). Added 7 new unit tests for the expanded command library.
This commit is contained in:
@@ -52,3 +52,88 @@ def test_commands_registry_has_core_commands():
|
||||
assert "clear_discussion" in all_ids
|
||||
assert "trigger_hot_reload" in all_ids
|
||||
assert "show_documentation" in all_ids
|
||||
|
||||
|
||||
def test_commands_registry_has_view_toggles():
|
||||
"""The palette should expose all window toggle commands for keyboard ergonomics."""
|
||||
from src.commands import registry
|
||||
all_ids = {c.id for c in registry.all()}
|
||||
expected_toggles = [
|
||||
"toggle_text_viewer",
|
||||
"toggle_diagnostics",
|
||||
"toggle_usage_analytics",
|
||||
"toggle_context_preview",
|
||||
"toggle_tier1_strategy",
|
||||
"toggle_tier2_tech_lead",
|
||||
"toggle_tier3_workers",
|
||||
"toggle_tier4_qa",
|
||||
"toggle_external_tools",
|
||||
"toggle_shader_editor",
|
||||
"toggle_undo_redo_history",
|
||||
"toggle_command_palette",
|
||||
]
|
||||
for cmd_id in expected_toggles:
|
||||
assert cmd_id in all_ids, f"Missing window toggle command: {cmd_id}"
|
||||
|
||||
|
||||
def test_commands_registry_has_theme_commands():
|
||||
from src.commands import registry
|
||||
all_ids = {c.id for c in registry.all()}
|
||||
assert "switch_to_dark_theme" in all_ids
|
||||
assert "switch_to_light_theme" in all_ids
|
||||
assert "switch_to_nerv_theme" in all_ids
|
||||
assert "cycle_theme" in all_ids
|
||||
|
||||
|
||||
def test_commands_registry_has_layout_commands():
|
||||
from src.commands import registry
|
||||
all_ids = {c.id for c in registry.all()}
|
||||
assert "show_all_panels" in all_ids
|
||||
assert "hide_all_panels" in all_ids
|
||||
assert "save_workspace_profile" in all_ids
|
||||
|
||||
|
||||
def test_commands_registry_has_undo_redo_commands():
|
||||
from src.commands import registry
|
||||
all_ids = {c.id for c in registry.all()}
|
||||
assert "undo" in all_ids
|
||||
assert "redo" in all_ids
|
||||
|
||||
|
||||
def test_all_commands_have_actions():
|
||||
"""Every registered command must have a callable action."""
|
||||
from src.commands import registry
|
||||
for cmd in registry.all():
|
||||
assert cmd.id, f"Command missing id: {cmd}"
|
||||
assert cmd.title, f"Command {cmd.id} missing title"
|
||||
assert cmd.category, f"Command {cmd.id} missing category"
|
||||
assert cmd.action is not None, f"Command {cmd.id} missing action"
|
||||
assert callable(cmd.action), f"Command {cmd.id} action is not callable"
|
||||
|
||||
|
||||
def test_toggle_helpers_are_safe_with_missing_state():
|
||||
"""The _toggle_window and _toggle_attr helpers must not raise on missing state."""
|
||||
from unittest.mock import MagicMock
|
||||
from src.commands import _toggle_window, _toggle_attr
|
||||
|
||||
bare_app = MagicMock(spec=[])
|
||||
_toggle_window(bare_app, "Anything")
|
||||
_toggle_attr(bare_app, "anything")
|
||||
|
||||
partial_app = MagicMock()
|
||||
partial_app.show_windows = {}
|
||||
_toggle_window(partial_app, "NewPanel")
|
||||
assert partial_app.show_windows["NewPanel"] is True
|
||||
|
||||
|
||||
def test_undo_command_routes_to_handler():
|
||||
from unittest.mock import MagicMock
|
||||
from src.commands import registry
|
||||
|
||||
app = MagicMock()
|
||||
app._handle_undo = MagicMock()
|
||||
|
||||
undo_cmd = registry.get("undo")
|
||||
assert undo_cmd is not None
|
||||
undo_cmd.action(app)
|
||||
app._handle_undo.assert_called_once()
|
||||
|
||||
Reference in New Issue
Block a user