- Notifications
You must be signed in to change notification settings - Fork 0
Prevent global command settings mutation from auto-registered commands #671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
WalkthroughIntroduces DefaultCommandStateService to manage command auto-registration state with override capability, replacing a local inline state holder. Adds getters and setters for prefix, failover routes, API key redaction, and interactive commands. Wires the service into command population. Adds unit tests validating session-local overrides without mutating underlying settings. Changes
Sequence Diagram(s)sequenceDiagram autonumber actor Caller participant State as DefaultCommandStateService participant Settings as ICommandSettingsService Caller->>State: get_command_prefix() alt Override set State-->>Caller: return override value else No override State->>Settings: get_command_prefix() Settings-->>State: default prefix State-->>Caller: return default prefix end Caller->>State: update_command_prefix(prefix) State-->>Caller: store override Caller->>State: get_api_key_redaction_enabled() alt Override set State-->>Caller: return override else No override State->>Settings: get_api_key_redaction_enabled() Settings-->>State: default State-->>Caller: return default end Caller->>State: update_api_key_redaction(enabled) State-->>Caller: store override Caller->>State: get_failover_routes() alt Override set State-->>Caller: routes override else No override State->>Settings: get_failover_routes() Settings-->>State: default routes State-->>Caller: return default routes end Caller->>State: update_failover_routes(routes) State-->>Caller: store override Caller->>State: get_disable_interactive_commands() alt Override set State-->>Caller: return override else No override State->>Settings: get_disable_interactive_commands() Settings-->>State: default State-->>Caller: return default end Caller->>State: update_interactive_commands(enabled) State-->>Caller: store override Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/core/app/stages/command.py
(2 hunks)tests/unit/core/app/test_default_command_state_service.py
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
**/*.py
: Avoid using emojis in Python code comments or docstrings
Follow PEP 8 and use type hints for all functions
Import order must be: standard library, third-party, then local imports, separated by blank lines
Naming conventions: snake_case for variables and functions; PascalCase for classes
Error handling: use specific exceptions and include meaningful error messages
Prefer f-strings for string formatting
Files:
src/core/app/stages/command.py
tests/unit/core/app/test_default_command_state_service.py
src/**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
src/**/*.py
: Catch specific exceptions; avoid broad except Exception blocks
If a broad exception must be caught, log with exc_info=True and re-raise a specific custom exception
Use the most specific exception class from src.core.common.exceptions that accurately describes the error
Provide clear, helpful error messages and include relevant details in the details dictionary of custom exceptions
Files:
src/core/app/stages/command.py
🧬 Code graph analysis (2)
src/core/app/stages/command.py (5)
src/core/interfaces/command_settings_interface.py (1)
ICommandSettingsService
(13-50)src/core/interfaces/state_provider_interface.py (10)
ISecureStateAccess
(27-44)ISecureStateModification
(47-64)get_command_prefix
(31-32)get_failover_routes
(43-44)update_failover_routes
(63-64)get_api_key_redaction_enabled
(35-36)get_disable_interactive_commands
(39-40)update_command_prefix
(51-52)update_api_key_redaction
(55-56)update_interactive_commands
(59-60)src/core/services/application_state_service.py (4)
get_command_prefix
(38-44)get_failover_routes
(196-209)get_api_key_redaction_enabled
(52-58)get_disable_interactive_commands
(74-80)src/core/services/app_settings_service.py (3)
get_command_prefix
(193-203)get_failover_routes
(171-183)get_disable_interactive_commands
(233-243)src/core/services/secure_state_service.py (8)
get_command_prefix
(36-39)get_failover_routes
(51-54)update_failover_routes
(96-121)get_api_key_redaction_enabled
(41-44)get_disable_interactive_commands
(46-49)update_command_prefix
(57-72)update_api_key_redaction
(74-83)update_interactive_commands
(85-94)
tests/unit/core/app/test_default_command_state_service.py (2)
src/core/app/stages/command.py (7)
DefaultCommandStateService
(30-69)update_command_prefix
(61-63)get_command_prefix
(40-43)update_api_key_redaction
(65-66)get_api_key_redaction_enabled
(51-54)update_interactive_commands
(68-69)get_disable_interactive_commands
(56-59)src/core/services/command_settings_service.py (1)
CommandSettingsService
(17-110)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: test (3.10)
- GitHub Check: Analyze (python)
def update_command_prefix(self, prefix: str) -> None: | ||
if isinstance(prefix, str) and prefix: | ||
self._command_prefix_override = prefix | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preserve command-prefix validation parity
Line 62 now accepts any truthy string, so a value like " "
becomes the session prefix and all commands stop matching. The old SecureStateService.update_command_prefix
rejected blank/whitespace prefixes; we need the same guard here.
def update_command_prefix(self, prefix: str) -> None: - if isinstance(prefix, str) and prefix: - self._command_prefix_override = prefix + if not isinstance(prefix, str): + return + + trimmed = prefix.strip() + if not trimmed: + return + + self._command_prefix_override = trimmed
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
def update_command_prefix(self, prefix: str) -> None: | |
if isinstance(prefix, str) and prefix: | |
self._command_prefix_override = prefix | |
def update_command_prefix(self, prefix: str) -> None: | |
if not isinstance(prefix, str): | |
return | |
trimmed = prefix.strip() | |
if not trimmed: | |
return | |
self._command_prefix_override = trimmed |
🤖 Prompt for AI Agents
In src/core/app/stages/command.py around lines 61 to 64, the current setter accepts any truthy string so a whitespace-only value like " " becomes the prefix and breaks command matching; change the guard to require a non-empty string after trimming whitespace (e.g., keep the isinstance(prefix, str) check but also require prefix.strip() to be truthy) so blank/whitespace-only prefixes are rejected and the previous validation parity with SecureStateService.update_command_prefix is preserved.
Summary
Testing
python -m pytest --override-ini addopts='' tests/unit/core/app/test_default_command_state_service.py
python -m pytest --override-ini addopts=''
https://chatgpt.com/codex/tasks/task_e_68ec25089a4c8333a7c641442c526119
Summary by CodeRabbit