Skip to content

fix(cli): clarify exception diagnostics#2602

Open
darion-yaphet wants to merge 1 commit into
github:mainfrom
darion-yaphet:improve-exception-diagnostics
Open

fix(cli): clarify exception diagnostics#2602
darion-yaphet wants to merge 1 commit into
github:mainfrom
darion-yaphet:improve-exception-diagnostics

Conversation

@darion-yaphet
Copy link
Copy Markdown
Contributor

Description

Improves CLI error diagnostics for broad exception and best-effort paths.

This PR keeps the existing fail-fast behavior for real setup failures, but makes user-facing errors more actionable by including the operation phase, target
integration/preset/workflow, and underlying exception detail where available. It also keeps optional best-effort failures as warnings with clearer context, so users
can understand what failed and what continued.

It also fixes workflow tests that could accidentally invoke a real local agent CLI, such as gemini, causing uv run pytest to hang on developer machines where that
CLI is installed.

Testing

  • Tested locally with uv run specify --help
  • Ran existing tests with uv run pytest
  • Ran lint with uvx ruff check src/
  • Tested with a sample project (if applicable)

Results:

  • uvx ruff check src/ passed
  • uv run pytest passed: 2917 passed, 34 skipped, 19 warnings

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (describe below)

Used AI assistance to identify broad CLI exception-handling paths, implement clearer diagnostics, add regression coverage, and run/fix local verification.

Consolidate the CLI diagnostic plan, implementation, and test hardening into one reviewable change. The CLI now reports phase and target context for broad failure paths while preserving existing fail-fast behavior for real setup failures and warning-only behavior for optional best-effort work.

The workflow unit tests also avoid discovering real local agent CLIs, so developer machines with tools such as gemini installed do not hang pytest during metadata-only assertions.

Constraint: CLI setup failures must remain fail-fast, while optional preset and cleanup paths should continue with clear warnings.

Rejected: Replace broad handlers across the whole codebase in one pass | too broad for a targeted CLI diagnostic fix

Rejected: Add runtime timeouts to workflow agent dispatch | dispatch may legitimately be long-running and the observed hang was test isolation

Confidence: high

Scope-risk: moderate

Directive: Keep future best-effort CLI warnings tied to the failed phase and target so users can diagnose setup state.

Tested: uvx ruff check src/; uv run pytest tests/integrations/test_cli.py -v; uv run pytest tests/test_workflows.py::TestCommandStep::test_step_override_integration tests/test_workflows.py::TestPromptStep::test_execute_with_step_integration tests/test_workflows.py::TestPromptStep::test_execute_with_model -vv; uv run pytest

Not-tested: Real Nacos/PG/Redis-style external service failure injection; real interactive workflow dispatch against installed gemini CLI
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves Spec Kit CLI diagnostics by standardizing exception detail formatting and adding phase/target context for both fatal and best-effort failure paths, plus hardens workflow step tests to avoid accidentally invoking real agent CLIs on developer machines.

Changes:

  • Add internal helpers to format exception details and phase/target labels, and use them in init, integration install/switch/upgrade error and warning output.
  • Improve best-effort warning messages (e.g., optional preset install, extension artifact cleanup) to include actionable context while still continuing execution.
  • Update workflow step tests to patch CLI detection (shutil.which) so locally installed CLIs (e.g., gemini) don’t get executed during pytest.
Show a summary per file
File Description
src/specify_cli/__init__.py Introduces _cli_error_detail, _cli_phase_label, _print_cli_warning and applies them to key CLI exception paths for clearer diagnostics.
tests/integrations/test_cli.py Adds regression tests asserting the new diagnostic formatting and phase/target reporting behaviors.
tests/test_workflows.py Patches CLI detection in step tests to prevent unintended real CLI invocation/hangs.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants