Repository navigation
feat(cli): check the version negotiation headers in cg check spec - #1418
Merged
karinamzalez merged 8 commits intoNov 20, 2026
Merged
Conversation
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
Contributor
|
🚀 Website Preview Deployed! Preview your changes at: https://pr-1418-common-grants.agile6.workers.dev Built from commit 407513f |
4 tasks
SnowboardTechie
approved these changes
Nov 20, 2026
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes
cg check speccheck 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 latestCORE-v0.6.0, so it includes the version headers (#1401), the version errors (#1414), and the versions discovery route (#1399).Changes proposed
lib/cli/src/commands/check/check-args.ts: newparseBaseVersionssorts withsemverand skips file names that aren't a clean versionlib/cli/package.json,pnpm-lock.yaml: addsemverand@types/semverlib/cli/lib/openapi/openapi.0.6.0.yaml: bundle the 0.6.0 base spec (version headers, version errors, and the/common-grants/versionsdiscovery route), which becomes the default when no--protocol-versionis passedlib/cli/src/commands/check/utils/check-matching-routes.ts:CG-Version) and a missing required response header (such asCG-Version-Served) as errors. Names match regardless of case, and a header declared once on the path item counts.experimentaltoo, which still skip the other checksparametersaren't checked as a routelib/cli/src/commands/check/utils/check-extra-routes.ts: same fix, so path-levelparametersorsummaryaren't reported as extra routeslib/cli/src/commands/check/utils/check-path-versioning.ts: new check that reports one error when routes put a protocol version likev0.6right before or after/common-grants/. It only mentionsCG-Versionwhen 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 missinglib/cli/src/commands/check/utils/types.ts,utils/error-utils.ts: new error types and their labels in the outputlib/cli/src/commands/check/README.md: document the header and path versioning checkslib/cli/src/__tests__/commands/check/: unit tests for each check, plus end-to-end tests that edit the bundled specsContext 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:
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 rungit checkout lib/cli/lib/openapiafterwards (fix(cli): refresh v0.4.0 and v0.5.0 base specs from core #1417 refreshes 0.4.0 and 0.5.0 separately).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. ExpectSpec is valid and compliant with base spec, the same as today.node dist/index.js check spec lib/openapi/openapi.0.5.0.yaml. Expect it to fail, withHeader parameter missingandResponse header missingon each route, plus a warning that the optionalGET /common-grants/versionsroute is missing, because 0.6.0 is now the default.Additional information
Output from the built CLI.
missing-headers.yamlis the 0.6.0 spec withCG-Versionremoved from one route andCG-Version-Servedremoved from another.versioned-paths.yamlis the 0.6.0 spec with every route under/v0.6.Release note: the FastAPI template's CI runs
cg check spec openapi.yamlwith 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.