Skip to content

Help examples, error suggestions, and test cleanup#8

Merged
alexkroman merged 29 commits into
mainfrom
help-examples-and-error-suggestions
Jun 5, 2026
Merged

Help examples, error suggestions, and test cleanup#8
alexkroman merged 29 commits into
mainfrom
help-examples-and-error-suggestions

Conversation

@alexkroman

Copy link
Copy Markdown
Collaborator

Summary

  • Add an Examples epilog to every leaf command's --help, with a tree-derived coverage guard (test_help_examples_coverage.py) and full --help snapshots (test_cli_output_snapshots.py) so new commands are automatically required to carry examples.
  • Carry an actionable Suggestion: line on user-facing errors (auth, usage, missing ffmpeg/yt-dlp/sounddevice, bad profile names, etc.) and render it in both human and JSON output.
  • Test cleanup: consolidate the two duplicate Typer-tree walkers into a shared tests/_cli_tree.py; remove the ~12 per-command *_help_has_examples tests now subsumed by the generalized guards; drop redundant inline imports / CliRunner() re-instantiation in the error-suggestion tests; cache the install test's PyPI reachability probe.
  • Expanded coverage: AMS auth flows, init runner (ports/launch/setup), config_builder error paths, and duplex audio.

Test plan

  • ruff check + ruff format --check: clean
  • mypy + pyright: clean (0 errors)
  • pytest -m "not e2e and not install": all pass, 27 snapshots pass, coverage 95% (gate 90%)
  • install-marked test collects correctly

🤖 Generated with Claude Code

alexkroman-assembly and others added 29 commits June 4, 2026 17:55
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Addresses code-review feedback: CliRunner/app are already imported at
module scope in each test file; remove the duplicated in-function imports
and normalize blank lines.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Addresses code-review feedback: replace constructor-only contract tests
with assertions on the real raise sites (flow.run_login_flow timeout,
client.resolve_audio_source), checking message and suggestion separately.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Golden tests pin the exact rendered CLI surface: every leaf command's --help
(usage + options + Examples epilog) and the human/JSON forms of errors
(including the Suggestion: line). The command list is derived from the live
Typer tree, so new commands are automatically required to have a snapshot.
Refresh intentionally with: pytest --snapshot-update

Requires the syrupy>=4.0 dev dependency.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Parametrized over every init template: build a clean venv with uv, install
its requirements.txt, and import api/index.py in that venv. Catches the one
drift the static contract tests can't — a dependency listed but uninstallable,
a missing transitive pin, or an import that only fails with the real packages
present.

Gated behind a new `install` marker (slow; needs network + uv) and excluded
from the default run and precommit gate; skips rather than fails when uv is
absent or PyPI is unreachable.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add pyright as a dev dependency and gate on it in scripts/check.sh
(after mypy), scoped via a new [tool.pyright] section to the same
aai_cli + tests sources mypy already covers. pyright resolves
third-party types mypy ignores, so it surfaces a stricter class of
issues; fix all 120 it reported so the gate lands green.

Source fixes:
- config_builder: type the dynamic SDK-kwargs dicts as dict[str, Any]
  at the construct_* unpack sites (the honest type for values bound
  for the SDK constructor).
- microphone: broaden stream_factory to Callable[..., Iterable[bytes]]
  — the source only iterates the result + getattr(close), never needs
  Iterator.
- scaffold: import Traversable from importlib.abc to match the protocol
  resources.files() actually returns.
- transcribe template: guard the None transcript id before returning.
- youtube: scoped ignore for yt-dlp's private _Params TypedDict.
- llm/auth: tighten Any returns to ChatCompletion / Mapping now that
  pyright sees the real types.

Test fixes: annotate TypedDict literals, narrow Optional fakes via
local + assert, type stand-in modules as Any, and cast duck-typed
stand-ins (CLIError, ChatCompletion, TextIO, Generator) to the API
type they impersonate. Add numpy dev dep (e2e resampling) and wrap
the over-long stream example line.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Consolidate the two duplicate Typer-tree walkers into a shared
tests/_cli_tree.py and drop the ~12 per-command *_help_has_examples
tests now subsumed by the tree-derived examples-coverage guard plus the
full --help snapshot. Remove redundant inline imports / CliRunner()
re-instantiation in the error-suggestion tests, and cache the install
test's PyPI reachability probe.

Also add coverage for AMS auth, init runner, config_builder error
paths, and duplex audio, and tidy output.emit_error's suggestion render.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Reformat output.py (collapse the Suggestion: print onto one line).
- Exclude tests/__snapshots__/ from trailing-whitespace/end-of-file-fixer:
  syrupy stores .ambr blank lines as "  ", so trimming them desyncs the
  goldens from the live render and breaks all snapshot tests in CI.
- Bump ruff-pre-commit to v0.15.16 to match the project's ruff dev pin.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
`uv run` does not install [project.optional-dependencies] by default, so the
uv-managed env lacked pytest/hypothesis/fastapi/numpy/etc. mypy hid this via
ignore_missing_imports, but pyright reported 44 reportMissingImports errors and
failed CI. Run the type-checkers and pytest with `uv run --extra dev`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
GitHub runners set FORCE_COLOR, which overrides NO_COLOR in Rich, so the
--help renders carried SGR escape codes the plain goldens don't have — 17
snapshot tests failed only on CI. _normalize now strips ANSI before comparing
(no-op for the already-plain error renders), making the goldens color-env
independent.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Move dev deps from [project.optional-dependencies].dev to
[dependency-groups].dev, which uv installs by default for uv run/uv sync.
This drops the `uv run --extra dev` band-aid in check.sh and makes a plain
.venv correct for editors, so [tool.pyright] is pinned to .venv — Pylance and
the CLI now resolve imports identically.

The code already required 3.11 (config.py imports stdlib `tomllib`, added in
3.11), so requires-python, the mypy/pyright/ruff targets, doctor's runtime
gate, install.sh, and the README all move to 3.11 — making pyright resolve
tomllib under the new venv pin. CI installs the group via
`pip install --group dev` (needs pip >= 25.1; upgraded in the pre-commit job);
the check.sh job just needs uv on PATH.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@alexkroman alexkroman merged commit e775f02 into main Jun 5, 2026
5 checks passed
@alexkroman alexkroman deleted the help-examples-and-error-suggestions branch June 5, 2026 03:43
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.

2 participants