Skip to content

feat(cli): check the version negotiation headers in cg check spec - #1418

Merged
karinamzalez merged 8 commits into
CORE-v0.6.0from
karina/1390-version-headers-in-cg-check
Nov 20, 2026
Merged

karinamzalez merged 8 commits into
CORE-v0.6.0from
karina/1390-version-headers-in-cg-check

Conversation

@karinamzalez

@karinamzalez karinamzalez commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

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 (fix(cli): refresh v0.4.0 and v0.5.0 base specs from core #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.

Sort the bundled base spec versions by version number instead of by string,
so 0.10.0 comes before 0.9.0 and becomes the default for `cg check spec`.
Extract a pure `parseBaseVersions` helper from `getAvailableBaseVersions`
that skips file names whose version isn't a clean semver (such as
`openapi.latest.yaml` or `openapi.v0.5.0.yaml`) instead of breaking the sort.
Adds `semver` as a runtime dependency of the CLI.

Refs #1390

Files changed:
- lib/cli/src/commands/check/check-args.ts
- lib/cli/src/__tests__/commands/check/check-args.test.ts
- lib/cli/package.json
- pnpm-lock.yaml
Bundle the protocol 0.6.0 base spec with the CLI so
`cg check spec --protocol-version 0.6.0` works, and 0.6.0 becomes the
default when no flag is passed. The bundled 0.4.0 and 0.5.0 specs are left
as committed so checks against 0.1.0 to 0.5.0 behave as today. The 0.6.0
spec currently carries the version headers only; it will be regenerated
once the version errors and discovery route land in core.

Refs #1390

Files changed:
- lib/cli/lib/openapi/openapi.0.6.0.yaml
- lib/cli/src/__tests__/commands/check/check-service-file.test.ts
- lib/cli/src/__tests__/commands/check/check-args.test.ts
Make `cg check spec` compare headers on routes that exist in both specs.
A header parameter the base declares, such as `CG-Version`, must appear on
the implementation's operation or path item, and a response header the base
marks required, such as `CG-Version-Served` on 200, must appear on the same
status code. Missing headers are reported as errors, and names match
case-insensitively. The expectations come from the base spec, so checks
against 0.1.0 to 0.5.0, which declare no version headers, are unchanged.

Refs #1390

Files changed:
- lib/cli/src/commands/check/utils/check-matching-routes.ts
- lib/cli/src/commands/check/utils/types.ts
- lib/cli/src/commands/check/utils/error-utils.ts
- lib/cli/src/commands/check/README.md
- lib/cli/src/__tests__/commands/check/utils/check-matching-routes.test.ts
- lib/cli/src/__tests__/commands/check/check-service-file.test.ts
When an implementation puts the protocol version in its CommonGrants paths,
such as `/v0.6/common-grants/opportunities` or
`/common-grants/v0.6/opportunities`, `cg check spec` now reports one error
saying versions go in the `CG-Version` request header (ADR 0032) and stops
there, instead of listing every base route as missing. Only a dotted
protocol version directly before or after `/common-grants/` counts, and only
when removing it gives a base route the implementation doesn't also serve
unversioned. A host API's own path versioning, such as
`/api/v2/common-grants/`, isn't flagged.

Refs #1390

Files changed:
- lib/cli/src/commands/check/utils/check-path-versioning.ts
- lib/cli/src/commands/check/check-service.ts
- lib/cli/src/commands/check/utils/error-utils.ts
- lib/cli/src/commands/check/utils/types.ts
- lib/cli/src/commands/check/README.md
- lib/cli/src/__tests__/commands/check/utils/check-path-versioning.test.ts
- lib/cli/src/__tests__/commands/check/check-service-file.test.ts
- Treat only HTTP methods on a path item as routes, so a header declared
  once at the path level (or a path `summary`) no longer shows up as an
  extra `PARAMETERS` or `SUMMARY` route.
- Check the version headers on routes the base tags `experimental` too.
  They still skip the other checks, but 15 of the 21 routes in 0.6.0 are
  experimental and would otherwise pass without the headers.
- Only point to the `CG-Version` header in the path versioning error when
  the base spec declares it, so checks against 0.1.0 to 0.5.0 just say to
  serve routes under `/common-grants/` with no version segment.

Refs #1390

Files changed:
- lib/cli/src/commands/check/utils/check-extra-routes.ts
- lib/cli/src/commands/check/utils/check-matching-routes.ts
- lib/cli/src/commands/check/utils/check-path-versioning.ts
- lib/cli/src/commands/check/README.md
- lib/cli/src/__tests__/commands/check/check-service-file.test.ts
- lib/cli/src/__tests__/commands/check/utils/check-extra-routes.test.ts
- lib/cli/src/__tests__/commands/check/utils/check-matching-routes.test.ts
- lib/cli/src/__tests__/commands/check/utils/check-path-versioning.test.ts
@github-actions github-actions Bot added cli Issue or PR related to the @common-grants/cli library dependencies Pull requests that update a dependency file typescript Issue or PR related to TypeScript tooling labels Nov 19, 2026
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Website Preview Deployed!

Preview your changes at: https://pr-1418-common-grants.agile6.workers.dev

Built from commit 407513f

@karinamzalez karinamzalez linked an issue Nov 19, 2026 that may be closed by this pull request
4 tasks
…covery route

Picks up #1414 (version errors) and #1399 (versions discovery route) from CORE-v0.6.0.

Files changed:
- lib/cli/lib/openapi/openapi.0.6.0.yaml
Mirrors #1412 from main, which isn't on CORE-v0.6.0 yet: astro ~7.4.12 for
GHSA-r3h5-4585-7x3w and @astrojs/check ^0.9.12. The lockfile starts from main's
so @emnapi/runtime 1.x stays hoisted; a fresh resolve hoists the 2.0 beta and
breaks astro check.

Files changed:
- website/package.json
- pnpm-lock.yaml
@github-actions github-actions Bot added the website Issues related to the website label Nov 20, 2026
@karinamzalez
karinamzalez merged commit 256302d into CORE-v0.6.0 Nov 20, 2026
11 checks passed
@karinamzalez
karinamzalez deleted the karina/1390-version-headers-in-cg-check branch November 20, 2026 19:55
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 dependencies Pull requests that update a dependency file typescript Issue or PR related to TypeScript tooling website Issues related to the website

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CLI] Check the version headers in cg check

2 participants