Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion cortex/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
print_all_preferences,
format_preference_value
)
from cortex.preflight_checker import PreflightChecker, format_report, export_report
from cortex.branding import (
console,
cx_print,
Expand Down Expand Up @@ -111,7 +112,12 @@
def _clear_line(self):
sys.stdout.write('\r\033[K')
sys.stdout.flush()


def install(self, software: str, execute: bool = False, dry_run: bool = False, simulate: bool = False):

Check warning on line 116 in cortex/cli.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the unused function parameter "dry_run".

See more on https://sonarcloud.io/project/issues?id=cortexlinux_cortex&issues=AZr9it4TOHUXk6syDWSt&open=AZr9it4TOHUXk6syDWSt&pullRequest=264

Check warning on line 116 in cortex/cli.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the unused function parameter "execute".

See more on https://sonarcloud.io/project/issues?id=cortexlinux_cortex&issues=AZr9it4TOHUXk6syDWSs&open=AZr9it4TOHUXk6syDWSs&pullRequest=264
# Handle simulation mode first - no API key needed
if simulate:
return self._run_simulation(software)

Comment on lines +116 to +120
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Duplicate install definitions cause a TypeError with --simulate

There are two CortexCLI.install methods:

  • Lines 116–120: a stub that only handles simulate and then returns.
  • Lines 185–303: the full install implementation that does not accept simulate.

Because Python uses the last definition, the stub at 116–120 is completely shadowed. The active signature is install(self, software, execute=False, dry_run=False). However, main() now calls:

return cli.install(args.software, execute=args.execute, dry_run=args.dry_run, simulate=args.simulate)

This will raise TypeError: install() got an unexpected keyword argument 'simulate' at runtime. The new tests don’t catch this because they patch CortexCLI.install.

You should consolidate to a single install method that supports simulate and remove the duplicate definition and unreachable elif args.command == 'install' branch. For example:

@@
-    def _clear_line(self):
-        sys.stdout.write('\r\033[K')
-        sys.stdout.flush()
-    
-    def install(self, software: str, execute: bool = False, dry_run: bool = False, simulate: bool = False):
-        # Handle simulation mode first - no API key needed
-        if simulate:
-            return self._run_simulation(software)
-       
+    def _clear_line(self):
+        sys.stdout.write('\r\033[K')
+        sys.stdout.flush()
@@
-    def install(self, software: str, execute: bool = False, dry_run: bool = False):
-        # Validate input first
+    def install(
+        self,
+        software: str,
+        execute: bool = False,
+        dry_run: bool = False,
+        simulate: bool = False,
+    ) -> int:
+        # Handle simulation mode first - no API key needed
+        if simulate:
+            return self._run_simulation(software)
+
+        # Validate input first
         is_valid, error = validate_install_request(software)
@@
-    try:
-        if args.command == 'install':
-            return cli.install(args.software, execute=args.execute, dry_run=args.dry_run, simulate=args.simulate)
+    try:
+        if args.command == 'install':
+            return cli.install(
+                args.software,
+                execute=args.execute,
+                dry_run=args.dry_run,
+                simulate=args.simulate,
+            )
@@
-        elif args.command == 'status':
-            return cli.status()
-        elif args.command == 'install':
-            return cli.install(args.software, execute=args.execute, dry_run=args.dry_run)
+        elif args.command == 'status':
+            return cli.status()

This preserves all existing behavior, fixes the --simulate runtime error, and resolves the static-analysis warnings about unused parameters in the stub.

Also applies to: 185-303, 660-669

🧰 Tools
🪛 GitHub Check: SonarCloud Code Analysis

[warning] 116-116: Remove the unused function parameter "dry_run".

See more on https://sonarcloud.io/project/issues?id=cortexlinux_cortex&issues=AZr9it4TOHUXk6syDWSt&open=AZr9it4TOHUXk6syDWSt&pullRequest=264


[warning] 116-116: Remove the unused function parameter "execute".

See more on https://sonarcloud.io/project/issues?id=cortexlinux_cortex&issues=AZr9it4TOHUXk6syDWSs&open=AZr9it4TOHUXk6syDWSs&pullRequest=264

🤖 Prompt for AI Agents
In cortex/cli.py around lines 116-120 (duplicate stub), lines 185-303 (full
implementation), and lines 660-669 (another duplicate), there are multiple
install() definitions causing a TypeError when --simulate is passed because the
active method signature lacks the simulate parameter; remove the duplicate
stub(s) and consolidate into a single install(self, software: str, execute: bool
= False, dry_run: bool = False, simulate: bool = False) implementation that
preserves the full install behavior and handles the simulate branch up front
(returning _run_simulation when simulate is True), and also delete the
now-unreachable elif args.command == 'install' branch to avoid dead code and
static-analysis warnings.

# --- New Notification Method ---
def notify(self, args):
"""Handle notification commands"""
Expand Down Expand Up @@ -310,6 +316,30 @@
history.update_installation(install_id, InstallationStatus.FAILED, str(e))
self._print_error(f"Unexpected error: {str(e)}")
return 1

def _run_simulation(self, software: str) -> int:
"""Run preflight simulation check for installation"""
try:
# Get API key for LLM-powered package info (optional).
api_key = os.environ.get('OPENAI_API_KEY') or os.environ.get('ANTHROPIC_API_KEY')
provider = self._get_provider() if api_key else 'openai'

# Create checker with optional API key for enhanced accuracy
checker = PreflightChecker(api_key=api_key, provider=provider)
report = checker.run_all_checks(software)

# Print formatted report
output = format_report(report, software)
print(output)

# Return error code if blocking issues found
if report.errors:
return 1
return 0

except Exception as e:
self._print_error(f"Simulation failed: {str(e)}")
return 1

def history(self, limit: int = 20, status: Optional[str] = None, show_id: Optional[str] = None):
"""Show installation history"""
Expand Down Expand Up @@ -577,6 +607,7 @@
install_parser.add_argument('software', type=str, help='Software to install')
install_parser.add_argument('--execute', action='store_true', help='Execute commands')
install_parser.add_argument('--dry-run', action='store_true', help='Show commands only')
install_parser.add_argument('--simulate', action='store_true', help='Simulate installation without making changes')

# History command
history_parser = subparsers.add_parser('history', help='View history')
Expand Down Expand Up @@ -626,6 +657,8 @@
cli = CortexCLI(verbose=args.verbose)

try:
if args.command == 'install':
return cli.install(args.software, execute=args.execute, dry_run=args.dry_run, simulate=args.simulate)
if args.command == 'demo':
return cli.demo()
elif args.command == 'wizard':
Expand Down
Loading
Loading