Test auth-error, claims, and keyring contracts against the code - #26
Merged
Merged
Conversation
The package publishes five contract JSON files, but only principal-v1 and subject-derivation-v2 were tied to the implementation. Add conformance tests that read auth-error-envelope-v1, identity-jwt-claims-v1 and identity-keyring-v1 and exercise the real parser, verifier and keyring reader against them. The auth-error code set is now compared with the contract enum, so the literal code list in auth-error.test.ts is removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Gap
The package publishes five contract files under
contract/. Onlyprincipal-v1.jsonandsubject-derivation-v2.jsonhad tests tying them to the code. Nothing comparedauth-error-envelope-v1.json,identity-jwt-claims-v1.jsonoridentity-keyring-v1.jsonwith the implementation, so the code could drift from what downstream services (including non-TypeScript ones) read from those files.What each test proves
Each test reads the contract file and derives its expectations from it. The same pattern as
principal-contract.test.tsandsubject.test.ts.test/auth-error-contract.test.ts(auth-error-envelope-v1.json)CAIL_AUTH_ERROR_CODESequals the contract'scode.enum, and the parser accepts every enum value.createCailAuthError/serializeCailAuthErrorinto the contract shape (rootrequired, nestedrequired, only declared nested fields, message and launch satisfy the contract patterns).requiredfield, or adding an undeclared field at either level (additionalProperties: false), is rejected.isCailAuthLaunchaccept a value exactly when the contract'sminLength/pattern/oneOfpatterns do.test/identity-jwt-claims-contract.test.ts(identity-jwt-claims-v1.json)verifyIdentityJwt;suband every optional claim (log_sub→operationalSubject) are mapped.requiredclaim is rejected.minLength/patternare rejected.additionalProperties: true).test/identity-keyring-contract.test.ts(identity-keyring-v1.json)$comment; the contract examples read back throughreadIdentityKeyring.app_jwtis required: gateway-only headers yieldnull, app-only yields a one-leg keyring.readIdentityKeyringaccepts a header value exactly when the contract'sminLength/maxLength/patterndo (including the 8192/8193 boundary and comma-joined duplicates).$commentequalsCAIL_GATEWAY_AUDIENCE;verifyKeyringGatewayJwtaccepts a same-subject leg for that audience and rejects a different subject, an app-audience leg, and a non-gateway config.test/auth-error.test.tsno longer pinsCAIL_AUTH_ERROR_CODESwith a literal list; the contract comparison replaces it.Mutation results
Each mutation was applied to
src/, the relevant contract test run, then reverted (git diff src/clean afterwards).identity_verification_misconfiguredfromCAIL_AUTH_ERROR_CODES./-in launch segments/.hidden)?check inisSafeLaunchPath?expoptional (both checks)log_subtooperationalSubjectlog_subpattern checksubKEYRING_JWT_MAX_LENGTH8192 → 16384CAIL_GATEWAY_AUDIENCErenamedContract/code mismatches
None between the three contracts and the code. One packaging gap, left for a separate change:
contract/identity-keyring-v1.jsonships in the tarball but has noexportsentry inpackage.json, unlike the other four contracts, so consumers cannot import it by subpath.package.jsonis also touched by #23, so this PR does not change it.Validation
bun run check: rc=0 (14 files, 200 tests; typecheck, Lua vectors, pack dry run)bun run lint: rc=0git diff --check: rc=0src/,contract/, or Publish the tested cail-identity archive #23's files.🤖 Generated with Claude Code