Skip to content

fix(cli): refresh v0.4.0 and v0.5.0 base specs from core - #1417

Open
karinamzalez wants to merge 1 commit into
mainfrom
karina/refresh-cli-base-specs
Open

karinamzalez wants to merge 1 commit into
mainfrom
karina/refresh-cli-base-specs

Conversation

@karinamzalez

@karinamzalez karinamzalez commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

cg check spec checks an API against the CLI's own copy of the protocol spec for the version you pick. The CLI's copies of the 0.4.0 and 0.5.0 specs had fallen out of date. This PR replaces them with fresh copies generated from the current core library. The 0.6.0 spec is out of scope; #1390 adds it.

Changes proposed

Context for reviewers

Look most closely at what changes for cg check spec --protocol-version 0.4.0:

  • Before: the checker mostly skipped awards endpoints because they were experimental.
  • After: if your API has awards endpoints, they get fully checked. If it doesn't, you get a warning, not an error.

This is intended. The core library doesn't set these labels per version, so the v0.5.0 change applies to 0.4.0 too, and the v0.5.0 release notes say so.

To verify:

  1. Run pnpm --filter @common-grants/cli run ci. It should pass.
  2. Run git status. The build should leave no changes in lib/cli/lib/openapi/, which means the committed copies match what the build generates.
  3. Run diff website/public/openapi/openapi.0.4.0.yaml lib/cli/lib/openapi/openapi.0.4.0.yaml, then the same for 0.5.0. There should be no output, which means the CLI now matches the specs the website publishes.

Additional information

pnpm --filter @common-grants/cli run ci (checks, build, tests):

 Test Files  18 passed (18)
      Tests  135 passed (135)

CLI spec copies compared with the website's published copies:

openapi.0.4.0.yaml: identical
openapi.0.5.0.yaml: identical

Regenerates the committed base specs so they match what the CLI build
produces and what the website publishes. For v0.4.0, the awards routes
are now tagged optional instead of experimental, matching the promotion
in the v0.5.0 core release (#1268). Other changes are description and
example values only.
@github-actions github-actions Bot added cli Issue or PR related to the @common-grants/cli library typescript Issue or PR related to TypeScript tooling labels Nov 19, 2026
karinamzalez added a commit that referenced this pull request Nov 20, 2026
)

### Summary

- Fixes #1390
- Time to review: 30 minutes

Makes `cg check spec` check the version negotiation headers from ADR
0032 against the 0.6.0 spec, and adds a single clear error for APIs that
put the version in their paths. Checking that multi-version servers
publish the discovery route is out of scope, since route tags can't
express that rule.

> [!IMPORTANT]
> This targets `CORE-v0.6.0`. The bundled 0.6.0 spec is regenerated from
the latest `CORE-v0.6.0`, so it includes the version headers (#1401),
the version errors (#1414), and the versions discovery route (#1399).

### Changes proposed

- Sort protocol versions as version numbers, so 0.10.0 comes after
0.9.0:
- `lib/cli/src/commands/check/check-args.ts`: new `parseBaseVersions`
sorts with `semver` and skips file names that aren't a clean version
- `lib/cli/package.json`, `pnpm-lock.yaml`: add `semver` and
`@types/semver`
- `lib/cli/lib/openapi/openapi.0.6.0.yaml`: bundle the 0.6.0 base spec
(version headers, version errors, and the `/common-grants/versions`
discovery route), which becomes the default when no `--protocol-version`
is passed
- `lib/cli/src/commands/check/utils/check-matching-routes.ts`:
- Report a missing header parameter (such as `CG-Version`) and a missing
required response header (such as `CG-Version-Served`) as errors. Names
match regardless of case, and a header declared once on the path item
counts.
- Check headers on routes tagged `experimental` too, which still skip
the other checks
- Only treat HTTP methods on a path item as routes, so path-level
`parameters` aren't checked as a route
- `lib/cli/src/commands/check/utils/check-extra-routes.ts`: same fix, so
path-level `parameters` or `summary` aren't reported as extra routes
- `lib/cli/src/commands/check/utils/check-path-versioning.ts`: new check
that reports one error when routes put a protocol version like `v0.6`
right before or after `/common-grants/`. It only mentions `CG-Version`
when the base spec declares it, and leaves a host API's own versioning
like `/api/v2/common-grants/` alone.
- `lib/cli/src/commands/check/check-service.ts`: run the path versioning
check first and stop there if it fires, instead of listing every route
as missing
- `lib/cli/src/commands/check/utils/types.ts`, `utils/error-utils.ts`:
new error types and their labels in the output
- `lib/cli/src/commands/check/README.md`: document the header and path
versioning checks
- `lib/cli/src/__tests__/commands/check/`: unit tests for each check,
plus end-to-end tests that edit the bundled specs

### Context for reviewers

Look most closely at `check-matching-routes.ts`: header expectations
come from the base spec rather than a version check in code, which is
why checks against 0.1.0 to 0.5.0 are unchanged.

To verify:

1. Build the CLI and run its tests: `pnpm --filter @common-grants/cli
run ci`. Expect 171 passing tests. The build also regenerates the 0.1.0
to 0.5.0 specs, so run `git checkout lib/cli/lib/openapi` afterwards
(#1417 refreshes 0.4.0 and 0.5.0 separately).
2. From `lib/cli`, check the 0.5.0 spec against 0.5.0: `node
dist/index.js check spec lib/openapi/openapi.0.5.0.yaml
--protocol-version 0.5.0`. Expect `Spec is valid and compliant with base
spec`, the same as today.
3. Check the same spec with no version: `node dist/index.js check spec
lib/openapi/openapi.0.5.0.yaml`. Expect it to fail, with `Header
parameter missing` and `Response header missing` on each route, plus a
warning that the optional `GET /common-grants/versions` route is
missing, because 0.6.0 is now the default.

### Additional information

Output from the built CLI. `missing-headers.yaml` is the 0.6.0 spec with
`CG-Version` removed from one route and `CG-Version-Served` removed from
another. `versioned-paths.yaml` is the 0.6.0 spec with every route under
`/v0.6`.

```
$ cg check spec missing-headers.yaml --protocol-version 0.6.0
Validation error: Spec validation failed:
2 errors
=================================
Route conflicts
  GET /common-grants/opportunities
    1 issues found:
    Header parameter missing
      Message: Missing header parameter [CG-Version]
  GET /common-grants/opportunities/{oppId}
    1 issues found:
    Response header missing
      Status code: 200
      Message: Missing response header [CG-Version-Served] for status code [200]
```

```
$ cg check spec versioned-paths.yaml
Validation error: Spec validation failed:
1 errors
=================================
Version in path
  Routes put the protocol version in the path, such as '/v0.6/common-grants/applications/search'. Serve CommonGrants routes under '/common-grants/' with no version segment and select the version with the 'CG-Version' request header (ADR 0032).
```

```
$ pnpm --filter @common-grants/cli run ci
All matched files use Prettier code style!
Compilation completed successfully.
 Test Files  19 passed (19)
      Tests  171 passed (171)
```

Release note: the FastAPI template's CI runs `cg check spec
openapi.yaml` with no version against the published CLI. Once CLI 0.6.0
is released, that job will fail until the template adds the version
headers or pins `--protocol-version 0.5.0`.

This branch has not been deployed

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

Labels

cli Issue or PR related to the @common-grants/cli library typescript Issue or PR related to TypeScript tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants