Skip to content

fix: oa validate accepts a bare spec path (#94) - #98

Merged
sgriffiths merged 1 commit into
mainfrom
fix/94-validate-bare-path
Jul 27, 2026
Merged

sgriffiths merged 1 commit into
mainfrom
fix/94-validate-bare-path

Conversation

@sgriffiths

Copy link
Copy Markdown
Contributor

What changed

oa validate <spec.yaml> — the form most people reach for first — now works. Previously it failed with No such command '<path>' because validate is a command group (for oa validate aac) and Click resolves a bare positional as a subcommand name before the callback's --spec option is ever considered.

The fix is a small custom TyperGroup: a leading *.yaml/*.yml token that isn't a known subcommand is rewritten to --spec before parsing. Everything else is preserved:

  • oa validate aac (and its flags) route exactly as before — suffix-gating means aac is never touched.
  • oa validate --spec path unchanged.
  • Passing both a bare path and --spec is an explicit error ("not both"), rather than one silently winning.
  • A genuine typo (oa validate acc) or non-YAML argument still errors, and the message now names the valid forms: oa validate <spec.yaml>, oa validate --spec <path>, oa validate aac.

README examples now show the shorter form as primary (with --spec noted as still supported).

One implementation note for review: the issue's sketch (an optional typer.Argument on the group callback) can't work — a group-level positional is consumed before subcommand resolution, so it would swallow aac. Hence the group-level rewrite instead. Also, typer ≥0.26 vendors its own click fork, so the group raises errors via ctx.fail() rather than raising click.UsageError directly — the public click exception classes don't match what typer's error rendering catches (raising the public class produces a raw traceback instead of the error panel).

Why

Closes #94. With an external project about to implement against the spec, the first command a newcomer runs shouldn't dead-end with a misleading error.

How tested

  • All existing tests pass (pytest tests/ — 513 passed, 3 skipped)
  • New tests added — tests/test_cli_validate.py, 8 cases: bare .yaml path, bare .yml path, --spec unchanged, both-forms error, missing-file bare path is a validation error (not "No such command"), aac still routes, typo and non-YAML arguments name the valid forms

Also: ruff check . clean, ruff format --check clean, mypy oas_cli clean. Manually exercised every form against the venv-installed CLI, including --help and no-args.

Type of change

  • Bug fix

Checklist

  • Code follows project style (ruff check . && ruff format --check .)
  • Self-review completed
  • Version bumped if needed — not needed; changelog entry added under Unreleased → Fixed

@sgriffiths
sgriffiths requested a review from aswhitehouse as a code owner July 26, 2026 23:41
@vercel

vercel Bot commented Jul 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
open-agent-spec Ready Ready Preview, Comment Jul 27, 2026 1:45am

Request Review

oa validate <spec.yaml> failed with "No such command '<path>'" because
validate is a command group and a bare positional is resolved as a
subcommand name. A custom group now rewrites a leading *.yaml/*.yml
token that isn't a known subcommand to --spec before parsing, so the
form most people reach for first just works.

aac routing, --spec, and typo errors are unchanged; passing both a bare
path and --spec is an explicit error; the no-such-command message now
names the valid invocation forms.

Note: typer vendors its own click fork, so the group raises via
ctx.fail() rather than raising click.UsageError directly — the public
click exception classes don't match what typer's error rendering
catches.

@aswhitehouse aswhitehouse left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed at 29bb9fd. The custom group rewrite is narrowly gated to leading YAML/YML paths, preserves aac and explicit --spec routing, rejects ambiguous dual input, and improves genuine typo errors. The focused CLI tests cover the important parsing paths, and CI is green. Approved.

@sgriffiths

Copy link
Copy Markdown
Contributor Author

npm parity follow-up filed as #100 (bare spec path in the npm CLI, same guardrails). The no-suffix behaviour is indeed intentional — suffix-gating is what keeps aac routing and typo errors intact.

@sgriffiths
sgriffiths merged commit 305b2f0 into main Jul 27, 2026
4 checks passed
@sgriffiths
sgriffiths deleted the fix/94-validate-bare-path branch July 27, 2026 06:31
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.

oa validate: bare spec path fails with "No such command"; treat *.yaml/*.yml argument as implicit --spec

3 participants