feat(auth): introduce typed AuthContext contract across the stack#411
Merged
feat(auth): introduce typed AuthContext contract across the stack#411
Conversation
Promote AuthContext from an opaque JsonObject pass-through to a first-class typed contract in host-contracts, propagated consistently through every layer that previously used JsonObject as a placeholder. - Add host-contracts/src/auth-context/ with Zod schema (.passthrough()), AuthContext type, parseAuthContext, and authContextContracts - Replace jsonObjectSchema with authContextSchema in all credential-store schemas (load output, save input/output, clear input/output) - Simplify credential-store types by removing the Omit/JsonObject override for authContext; credentialState override retained - Update DispatchRequest, kernel-contracts entrypoint-runtime and semantic-engine, app-runtime-facade-contracts invoke/subscribe schemas and AppRuntimeInteractionSessionWriteInput - Add authContextSchema.safeParse() validation at the surface boundary in load-credential-context.ts, symmetric with existing principal validation; respects fail_closed / degrade_to_anonymous policy - Update runtime types: kernel-runtime/entrypoint/types.ts, domain-runtime/execution-core/context.ts - Remove local AuthContext interface from expresso-std auth-helpers.ts; import from host-contracts and replace blind cast with safeParse - Update all four credential-store payload files (cookie, redis, memory, local-storage) to use AuthContext - Tighten conformance fixture types from unknown[] to (AuthContext | undefined)[] - Full workspace typecheck passes; all authContext conformance tests pass
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f07ef3920f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
products/contracts/host-contracts/src/auth-context/auth-context.ts
Outdated
Show resolved
Hide resolved
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
authContextwas typed asJsonObjectat every contract boundary — dispatch requests, credential-store I/O, kernel contracts, app-runtime-facade-contracts, and runtime internals. It is now typed asAuthContext(from newhost-contracts/src/auth-context/) everywhere, consistent with howPrincipalContextwas already handled.load-credential-context.tsnow callsauthContextSchema.safeParse()on the value returned from a credential store'sload, mirroring the existingprincipalInputvalidation — failing closed or degrading to anonymous per the configured policy.getAuthContext()previously returnedauth as AuthContextwith no verification. It now usesauthContextSchema.safeParse(auth)and returnsundefinedon failure, making policy operator failures explicit rather than silently incorrect.What changed
host-contracts/src/auth-context/authContextSchema(Zod,.passthrough()),AuthContexttype,parseAuthContext,authContextContractsbarrelsurface-contractscredential-store schemasjsonObjectSchema→authContextSchemasurface-contractscredential-store typesOmit<…, "authContext"> & { authContext?: JsonObject }override on 5 typessurface-contractsdispatch requestauthContextSchema.optional()+DispatchRequest.authContext?: AuthContextkernel-contractsentrypoint-runtime + semantic-engineauthContext?: AuthContextapp-runtime-facade-contractscreate + subscribeAppRuntimeInteractionSessionWriteInputinterfacesurface-adapters/load-credential-context.tssafeParsevalidation block after principal validationkernel-runtime/entrypoint/types.ts+domain-runtime/execution-core/context.tsauthContext?: AuthContextexpresso-std/auth/auth-helpers.tshost-contracts, replace cast withsafeParseAuthContextunknown[]→(AuthContext | undefined)[]Test plan
bun run typecheck— all 75 packages passbun test products/quality/conformance/test/credential-store-auth-context-*.test.ts— all 4 tests passgetAuthContext()in expresso-std returnsundefinedfor objects that don't match any known AuthContext fields (regression: previously would cast and return them)authContext(e.g.{ roles: "not-an-array" }) is rejected at the surface boundary underfail_closedpolicy and degraded underdegrade_to_anonymousNotes
authContextSchemauses.passthrough()intentionally — JWT payloads commonly includeaud,iss,jtiand other standard claims not enumerated in our schema. Extra fields are preserved, not stripped.credentialStateon the credential-store types was left asJsonObject— it is genuinely freeform state that varies per store implementation and has no shared semantics across the system.Issue Link
No linked issues detected from commit messages.