fix(cli): address reviewer issues in project switch command
CI / push-validation (pull_request) Successful in 30s
CI / build (pull_request) Successful in 45s
CI / lint (pull_request) Successful in 47s
CI / helm (pull_request) Successful in 49s
CI / typecheck (pull_request) Successful in 1m2s
CI / quality (pull_request) Successful in 1m17s
CI / security (pull_request) Successful in 1m23s
CI / unit_tests (pull_request) Successful in 5m5s
CI / docker (pull_request) Successful in 1m39s
CI / coverage (pull_request) Successful in 9m30s
CI / integration_tests (pull_request) Failing after 22m22s
CI / status-check (pull_request) Has been cancelled

- Narrow except Exception to NotFoundError in switch() to avoid masking
  unrelated errors when the project lookup fails
- Fix shell injection risk in _write_active_project: use single-quoted
  export with embedded single-quote escaping instead of double-quoted
  f-string which would allow shell metacharacters in project names to
  execute arbitrary commands when the file is sourced
- Pass command= keyword to format_output in switch non-rich path so the
  JSON/YAML envelope includes the originating command name per spec

ISSUES CLOSED: #8675
This commit is contained in:
2026-06-15 00:58:36 -04:00
committed by Forgejo
parent 365be3a3cf
commit 0276acb4f2
+4 -3
View File
@@ -1040,7 +1040,7 @@ def switch(
# Validate project exists
try:
proj = svc.get_project(project)
except Exception as exc:
except NotFoundError as exc:
err_console.print(f"[red]Project not found:[/red] {project}")
raise typer.Exit(1) from exc
@@ -1086,7 +1086,7 @@ def switch(
"description": proj.description,
"updated_at": datetime.now(tz=UTC).isoformat(),
}
console.print(format_output(data, output_format))
console.print(format_output(data, output_format, command="project switch"))
def _write_active_project(namespaced_name: str) -> None:
@@ -1100,8 +1100,9 @@ def _write_active_project(namespaced_name: str) -> None:
home = Path.home() / ".cleveragents"
home.mkdir(parents=True, exist_ok=True)
helper_path = home / "active-project.sh"
safe_name = namespaced_name.replace("'", "'\\''")
helper_path.write_text(
f'export CLEVERAGENTS_PROJECT="{namespaced_name}"\n', encoding="utf-8"
f"export CLEVERAGENTS_PROJECT='{safe_name}'\n", encoding="utf-8"
)
# Also update the in-memory environment for the current process and any