Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(crd): add generic OAuth carril (source:'generic') to mcpserver CRD (S3.1)
Diego Zacarias1065b2d273ed
diff --git a/charts/clerum-crds/crds/mcpserver.yaml b/charts/clerum-crds/crds/mcpserver.yamlindex 12a39b164..69b3af8f5 100644--- a/charts/clerum-crds/crds/mcpserver.yaml+++ b/charts/clerum-crds/crds/mcpserver.yaml@@ -206,12 +206,15 @@ spec:change in place which identity is exercised.source:type: string- enum: [remote]+ enum: [remote, generic]description: >-Carril discriminator. ABSENT = baked (a known-shape adaptervia spec.oauth.provider). 'remote' = a discovery-configuredclient (control-api remote-MCP install) whose pinned endpoints- below replace the baked provider. Immutable; the carril cannot flip.+ below replace the baked provider. 'generic' = self-hosted+ knob-configured client (operator-pinned endpoints + wire knobs;+ client_id IS spec.oauth.id unless clientIdRef is set). Immutable;+ the carril cannot flip.clientMode:type: stringenum: [public, confidential]@@ -222,11 +225,11 @@ spec:authorizationEndpoint:type: stringmaxLength: 2048- description: REMOTE only. Pinned discovery authorize URL. Immutable.+ description: REMOTE and GENERIC. Pinned discovery authorize URL. Immutable.tokenEndpoint:type: stringmaxLength: 2048- description: REMOTE only. Pinned discovery token URL. Immutable.+ description: REMOTE and GENERIC. Pinned discovery token URL. Immutable.registrationEndpoint:type: stringmaxLength: 2048@@ -238,7 +241,7 @@ spec:resource:type: stringmaxLength: 2048- description: REMOTE only. RFC 8707 resource sent on authorize+token. Immutable.+ description: REMOTE and GENERIC. RFC 8707 resource sent on authorize+token. Immutable.issForCallback:type: stringmaxLength: 2048@@ -254,9 +257,41 @@ spec:supportsRefresh:type: booleandescription: >-- REMOTE only (D-8), fail-closed. false ⇒ never attempt refresh.+ REMOTE and GENERIC (D-8), fail-closed. false ⇒ never attempt refresh.No default (required-by-CEL for remote). Immutable (pinned atinstall; runtime never re-derives).+ tokenRequestFormat:+ type: string+ enum: [form, json]+ description: "GENERIC only. Token/refresh POST body encoding."+ tokenAuthMethod:+ type: string+ enum: [body, basic]+ description: "GENERIC only. client_secret placement: form body vs HTTP Basic."+ scopeSeparator:+ type: string+ enum: [space, comma]+ description: "GENERIC only. Separator joining scopes on the authorize URL."+ sendScope:+ type: boolean+ description: "GENERIC only. Whether to emit the scope parameter at all."+ usePkce:+ type: boolean+ description: "GENERIC only. PKCE S256 on authorize + code_verifier on exchange."+ includeResponseType:+ type: boolean+ description: "GENERIC only. Emit response_type=code on the authorize URL."+ refreshEndpoint:+ type: string+ maxLength: 2048+ description: "GENERIC only, optional. Defaults to tokenEndpoint when absent. Immutable."+ extraAuthorizeParams:+ type: object+ maxProperties: 16+ additionalProperties:+ type: string+ maxLength: 1024+ description: "GENERIC only, optional. Static extra query params appended to the authorize URL. Immutable."serverConfig:type: objectdescription: Operational configuration for the MCP server runtime.@@ -597,23 +632,28 @@ spec:# `required` is gone; requiredness is carril-specific and enforced# here so each carril rejects the other's shape.#- # Baked-only slug re-narrow: the structural `pattern` moved to CEL so+ # Baked+generic slug re-narrow: the structural `pattern` moved to CEL so# the remote carril can carry an AS-assigned client_id (arbitrary- # charset). Gated on baked (has(self.oauth.source) short-circuits for- # remote) so remote ids are not re-narrowed.- - rule: "!has(self.oauth) || has(self.oauth.source) || !has(self.oauth.id) || self.oauth.id.matches('^[a-z0-9-]{1,63}$')"- message: "baked spec.oauth.id must match ^[a-z0-9-]{1,63}$"+ # charset). Exempts ONLY remote (source == 'remote' short-circuits);+ # baked (source absent) AND generic get the slug narrow, since a+ # generic client_id IS spec.oauth.id and must be a callback-path-safe slug.+ - rule: "!has(self.oauth) || (has(self.oauth.source) && self.oauth.source == 'remote') || !has(self.oauth.id) || self.oauth.id.matches('^[a-z0-9-]{1,63}$')"+ message: "baked/generic spec.oauth.id must match ^[a-z0-9-]{1,63}$"# BAKED-REQ: baked (no source) requires the classic adapter quartet.- rule: "!has(self.oauth) || has(self.oauth.source) || (has(self.oauth.id) && has(self.oauth.provider) && has(self.oauth.clientIdRef) && has(self.oauth.clientSecretRef))"message: "baked spec.oauth (no source) requires id, provider, clientIdRef and clientSecretRef"# REMOTE-REQ: remote requires the pinned discovery client shape.- - rule: "!has(self.oauth) || !has(self.oauth.source) || (has(self.oauth.clientMode) && has(self.oauth.authorizationEndpoint) && has(self.oauth.tokenEndpoint) && has(self.oauth.issuer) && has(self.oauth.resource) && has(self.oauth.bearerInBody) && has(self.oauth.supportsRefresh))"+ # Re-gated on source == 'remote' (via source != 'remote' short-circuit)+ # so the generic carril does not fall into the remote required set.+ - rule: "!has(self.oauth) || !has(self.oauth.source) || self.oauth.source != 'remote' || (has(self.oauth.clientMode) && has(self.oauth.authorizationEndpoint) && has(self.oauth.tokenEndpoint) && has(self.oauth.issuer) && has(self.oauth.resource) && has(self.oauth.bearerInBody) && has(self.oauth.supportsRefresh))"message: "remote spec.oauth requires clientMode, authorizationEndpoint, tokenEndpoint, issuer, resource, bearerInBody and supportsRefresh"# REMOTE-FORBID-PROVIDER: source 'remote' replaces the baked adapter.- rule: "!has(self.oauth) || !has(self.oauth.source) || !has(self.oauth.provider)"message: "remote spec.oauth must not set provider; source 'remote' replaces the baked adapter"# BAKED-FORBID-REMOTE-FIELDS: baked must not carry remote-only fields.- - rule: "!has(self.oauth) || has(self.oauth.source) || (!has(self.oauth.clientMode) && !has(self.oauth.authorizationEndpoint) && !has(self.oauth.tokenEndpoint) && !has(self.oauth.registrationEndpoint) && !has(self.oauth.issuer) && !has(self.oauth.resource) && !has(self.oauth.issForCallback) && !has(self.oauth.bearerInBody) && !has(self.oauth.supportsRefresh))"+ # The forbidden set is extended with the generic knobs + refreshEndpoint+ # so baked (source absent) rejects both remote-only and generic-only shape.+ - rule: "!has(self.oauth) || has(self.oauth.source) || (!has(self.oauth.clientMode) && !has(self.oauth.authorizationEndpoint) && !has(self.oauth.tokenEndpoint) && !has(self.oauth.registrationEndpoint) && !has(self.oauth.issuer) && !has(self.oauth.resource) && !has(self.oauth.issForCallback) && !has(self.oauth.bearerInBody) && !has(self.oauth.supportsRefresh) && !has(self.oauth.tokenRequestFormat) && !has(self.oauth.tokenAuthMethod) && !has(self.oauth.scopeSeparator) && !has(self.oauth.sendScope) && !has(self.oauth.usePkce) && !has(self.oauth.includeResponseType) && !has(self.oauth.refreshEndpoint) && !has(self.oauth.extraAuthorizeParams))"message: "baked spec.oauth (no source) must not set remote-only fields"# IMM-3: id presence is immutable — closes the drop/re-add two-step# that would otherwise let an UPDATE add or remove id under a@@ -636,8 +676,52 @@ spec:# bearerInBody/supportsRefresh are present, so those accesses cannot# CEL-error. registrationEndpoint/issForCallback are optional even on# remote → presence-pinned + guarded value-equality.- - rule: "!has(oldSelf.oauth) || !has(self.oauth) || !has(oldSelf.oauth.source) || !has(self.oauth.source) || (oldSelf.oauth.clientMode == self.oauth.clientMode && oldSelf.oauth.authorizationEndpoint == self.oauth.authorizationEndpoint && oldSelf.oauth.tokenEndpoint == self.oauth.tokenEndpoint && oldSelf.oauth.issuer == self.oauth.issuer && oldSelf.oauth.resource == self.oauth.resource && oldSelf.oauth.bearerInBody == self.oauth.bearerInBody && oldSelf.oauth.supportsRefresh == self.oauth.supportsRefresh && (has(oldSelf.oauth.registrationEndpoint) == has(self.oauth.registrationEndpoint)) && (!has(oldSelf.oauth.registrationEndpoint) || oldSelf.oauth.registrationEndpoint == self.oauth.registrationEndpoint) && (has(oldSelf.oauth.issForCallback) == has(self.oauth.issForCallback)) && (!has(oldSelf.oauth.issForCallback) || oldSelf.oauth.issForCallback == self.oauth.issForCallback))"+ # Double-source-VALUE-guarded (source != 'remote' short-circuits on+ # BOTH revisions) so the remote value-block only dereferences remote-only+ # fields when BOTH revisions are remote; a generic→generic UPDATE+ # short-circuits before touching clientMode/issuer/... and cannot CEL-ERROR.+ - rule: "!has(oldSelf.oauth) || !has(self.oauth) || !has(oldSelf.oauth.source) || oldSelf.oauth.source != 'remote' || !has(self.oauth.source) || self.oauth.source != 'remote' || (oldSelf.oauth.clientMode == self.oauth.clientMode && oldSelf.oauth.authorizationEndpoint == self.oauth.authorizationEndpoint && oldSelf.oauth.tokenEndpoint == self.oauth.tokenEndpoint && oldSelf.oauth.issuer == self.oauth.issuer && oldSelf.oauth.resource == self.oauth.resource && oldSelf.oauth.bearerInBody == self.oauth.bearerInBody && oldSelf.oauth.supportsRefresh == self.oauth.supportsRefresh && (has(oldSelf.oauth.registrationEndpoint) == has(self.oauth.registrationEndpoint)) && (!has(oldSelf.oauth.registrationEndpoint) || oldSelf.oauth.registrationEndpoint == self.oauth.registrationEndpoint) && (has(oldSelf.oauth.issForCallback) == has(self.oauth.issForCallback)) && (!has(oldSelf.oauth.issForCallback) || oldSelf.oauth.issForCallback == self.oauth.issForCallback))"message: "remote spec.oauth pinned endpoints/clientMode/quirks are immutable; delete and recreate to change them"+ # GENERIC-REQ: generic requires id (its client_id), both endpoints and+ # the required wire knobs. usePkce/includeResponseType/sendScope/+ # supportsRefresh are booleans → required-by-CEL (has() presence), the+ # install path writes each explicitly (no CRD default).+ - rule: "!has(self.oauth) || !has(self.oauth.source) || self.oauth.source != 'generic' || (has(self.oauth.id) && has(self.oauth.authorizationEndpoint) && has(self.oauth.tokenEndpoint) && has(self.oauth.tokenRequestFormat) && has(self.oauth.tokenAuthMethod) && has(self.oauth.scopeSeparator) && has(self.oauth.sendScope) && has(self.oauth.supportsRefresh) && has(self.oauth.usePkce) && has(self.oauth.includeResponseType))"+ message: "generic spec.oauth requires id, authorizationEndpoint, tokenEndpoint, tokenRequestFormat, tokenAuthMethod, scopeSeparator, sendScope, supportsRefresh, usePkce and includeResponseType"+ # GENERIC-FORBID-REMOTE-FIELDS: generic reuses endpoints/resource/+ # supportsRefresh but must not carry the remote-only discovery fields.+ - rule: "!has(self.oauth) || !has(self.oauth.source) || self.oauth.source != 'generic' || (!has(self.oauth.clientMode) && !has(self.oauth.issuer) && !has(self.oauth.registrationEndpoint) && !has(self.oauth.issForCallback) && !has(self.oauth.bearerInBody))"+ message: "generic spec.oauth must not set remote-only fields (clientMode, issuer, registrationEndpoint, issForCallback, bearerInBody)"+ # REMOTE-FORBID-GENERIC-KNOBS: remote must not carry the generic wire knobs.+ - rule: "!has(self.oauth) || !has(self.oauth.source) || self.oauth.source != 'remote' || (!has(self.oauth.tokenRequestFormat) && !has(self.oauth.tokenAuthMethod) && !has(self.oauth.scopeSeparator) && !has(self.oauth.sendScope) && !has(self.oauth.usePkce) && !has(self.oauth.includeResponseType) && !has(self.oauth.refreshEndpoint) && !has(self.oauth.extraAuthorizeParams))"+ message: "remote spec.oauth must not set generic-only knobs"+ # GENERIC-SECRET-PAIRING: public = neither ref (client_id IS spec.oauth.id,+ # no secret); confidential = both refs. Mixed pairing is rejected.+ - rule: "!has(self.oauth) || !has(self.oauth.source) || self.oauth.source != 'generic' || (has(self.oauth.clientIdRef) == has(self.oauth.clientSecretRef))"+ message: "generic spec.oauth must set clientIdRef and clientSecretRef together (confidential) or neither (public)"+ # SOURCE-VALUE-IMM: IMM-5 pins source PRESENCE; this pins the VALUE so a+ # generic⇄remote flip in place is rejected even though both keep source set.+ - rule: "!has(oldSelf.oauth) || !has(self.oauth) || !has(oldSelf.oauth.source) || !has(self.oauth.source) || oldSelf.oauth.source == self.oauth.source"+ message: "spec.oauth.source value is immutable; delete and recreate to change the carril"+ # GENERIC-IMM: pin generic endpoints + knobs. Double-source-VALUE-guarded+ # (source != 'generic' short-circuits on BOTH revisions) so it only+ # dereferences generic fields when BOTH revisions are generic; GENERIC-REQ+ # then guarantees the required knobs are present. resource/refreshEndpoint/+ # extraAuthorizeParams are optional → presence-pinned + guarded value-equality.+ - rule: "!has(oldSelf.oauth) || !has(self.oauth) || !has(oldSelf.oauth.source) || oldSelf.oauth.source != 'generic' || !has(self.oauth.source) || self.oauth.source != 'generic' || (oldSelf.oauth.authorizationEndpoint == self.oauth.authorizationEndpoint && oldSelf.oauth.tokenEndpoint == self.oauth.tokenEndpoint && oldSelf.oauth.tokenRequestFormat == self.oauth.tokenRequestFormat && oldSelf.oauth.tokenAuthMethod == self.oauth.tokenAuthMethod && oldSelf.oauth.scopeSeparator == self.oauth.scopeSeparator && oldSelf.oauth.sendScope == self.oauth.sendScope && oldSelf.oauth.supportsRefresh == self.oauth.supportsRefresh && oldSelf.oauth.usePkce == self.oauth.usePkce && oldSelf.oauth.includeResponseType == self.oauth.includeResponseType && (has(oldSelf.oauth.resource) == has(self.oauth.resource)) && (!has(oldSelf.oauth.resource) || oldSelf.oauth.resource == self.oauth.resource) && (has(oldSelf.oauth.refreshEndpoint) == has(self.oauth.refreshEndpoint)) && (!has(oldSelf.oauth.refreshEndpoint) || oldSelf.oauth.refreshEndpoint == self.oauth.refreshEndpoint) && (has(oldSelf.oauth.extraAuthorizeParams) == has(self.oauth.extraAuthorizeParams)) && (!has(oldSelf.oauth.extraAuthorizeParams) || oldSelf.oauth.extraAuthorizeParams == self.oauth.extraAuthorizeParams))"+ message: "generic spec.oauth pinned endpoints/knobs are immutable; delete and recreate to change them"+ # GENERIC-SECRET-IMM: generic has no clientMode; its public/confidential+ # posture is encoded by ref PRESENCE (GENERIC-SECRET-PAIRING pins that+ # within a revision, but not across UPDATE). Without this, an update-RBAC+ # actor could drop both refs (confidential→public, silently removing+ # client_secret from the token exchange), add them (public→confidential),+ # or repoint them at another Secret. Pin presence AND value of both refs on+ # generic — the transition analogue of clientMode's IMM-6 pin on remote.+ # Double-source-VALUE-guarded so it only dereferences generic refs when BOTH+ # revisions are generic; each value read is presence-guarded (a matching+ # presence-equality conjunct short-circuits before any absent deref).+ - rule: "!has(oldSelf.oauth) || !has(self.oauth) || !has(oldSelf.oauth.source) || oldSelf.oauth.source != 'generic' || !has(self.oauth.source) || self.oauth.source != 'generic' || ((has(oldSelf.oauth.clientIdRef) == has(self.oauth.clientIdRef)) && (has(oldSelf.oauth.clientSecretRef) == has(self.oauth.clientSecretRef)) && (!has(oldSelf.oauth.clientIdRef) || (oldSelf.oauth.clientIdRef.name == self.oauth.clientIdRef.name && oldSelf.oauth.clientIdRef.key == self.oauth.clientIdRef.key)) && (!has(oldSelf.oauth.clientSecretRef) || (oldSelf.oauth.clientSecretRef.name == self.oauth.clientSecretRef.name && oldSelf.oauth.clientSecretRef.key == self.oauth.clientSecretRef.key)))"+ message: "generic spec.oauth clientIdRef/clientSecretRef (secret posture) are immutable; delete and recreate to change them"status:type: objectproperties:diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex f7a852a71..457f61f6a 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.597",+ "version": "0.1.598","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.597",+ "version": "0.1.598","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",diff --git a/control-api/package.json b/control-api/package.jsonindex 82574c3bb..393630037 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.597",+ "version": "0.1.598","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/test/crd.mcpServerOauth.test.ts b/control-api/test/crd.mcpServerOauth.test.tsindex 4888586fb..01fa307e3 100644--- a/control-api/test/crd.mcpServerOauth.test.ts+++ b/control-api/test/crd.mcpServerOauth.test.ts@@ -55,11 +55,11 @@ describe('McpServer CRD — OAuth surface (U1)', () => {expect(bakedReq, 'BAKED-REQ rule present').toBeDefined()})- it('exposes source as an optional enum[remote] carril discriminator (no default, not required)', () => {+ it('exposes source as an optional enum[remote, generic] carril discriminator (no default, not required)', () => {const oauth = specSchema.properties.oauthconst source = oauth.properties.sourceexpect(source.type).toBe('string')- expect(source.enum).toEqual(['remote'])+ expect(source.enum).toEqual(['remote', 'generic'])expect(source).not.toHaveProperty('default')// Never in a (now-absent) block-level required list.expect(oauth.required).toBeUndefined()@@ -252,4 +252,263 @@ describe('McpServer CRD — OAuth surface (U1)', () => {expect(rule, 'contextRef immutability rule present and oauth/oldSelf-guarded').toBeDefined()expect(rule?.message).toMatch(/contextRef is immutable/)})++ // ---------------------------------------------------------------------------+ // S3.1 — the 'generic' self-hosted carril (source: 'generic'). Same+ // structural-assertion contract as the rest of this file: we parse the YAML+ // and assert the rule STRINGS and field shapes; no CEL evaluator is vendored.+ //+ // GUARD-SAFETY REASONING (why a generic UPDATE never CEL-ERRORs): every rule+ // that dereferences a generic-only field is double-source-VALUE-guarded — it+ // short-circuits on `self.oauth.source != 'generic'` (and, for transition+ // rules, `oldSelf.oauth.source != 'generic'`) BEFORE touching any generic+ // field, so it only evaluates the value block when the revision(s) are+ // actually generic. GENERIC-REQ then guarantees the required knobs are+ // present, so those accesses are safe. Symmetrically, the remote value blocks+ // (REMOTE-REQ, IMM-6) now short-circuit on `source != 'remote'`, so a+ // generic revision never falls into a remote dereference. This is the same+ // has()/value-guard discipline as the remote carril; SEMANTIC verification+ // (create passes / cross-carril flip fails / knob mutation fails) is+ // `kubectl --dry-run=server` at batch close, not here.+ // ---------------------------------------------------------------------------++ it('declares the generic-carril knob fields with the right types/enums', () => {+ const props = specSchema.properties.oauth.properties+ expect(props.tokenRequestFormat.type).toBe('string')+ expect(props.tokenRequestFormat.enum).toEqual(['form', 'json'])+ expect(props.tokenAuthMethod.type).toBe('string')+ expect(props.tokenAuthMethod.enum).toEqual(['body', 'basic'])+ expect(props.scopeSeparator.type).toBe('string')+ expect(props.scopeSeparator.enum).toEqual(['space', 'comma'])+ expect(props.sendScope.type).toBe('boolean')+ expect(props.usePkce.type).toBe('boolean')+ expect(props.includeResponseType.type).toBe('boolean')+ expect(props.refreshEndpoint.type).toBe('string')+ expect(props.refreshEndpoint.maxLength).toBe(2048)+ expect(props.extraAuthorizeParams.type).toBe('object')+ expect(props.extraAuthorizeParams.maxProperties).toBe(16)+ expect(props.extraAuthorizeParams.additionalProperties.type).toBe('string')+ expect(props.extraAuthorizeParams.additionalProperties.maxLength).toBe(1024)+ // No CRD default on any knob — the control-api install path writes every+ // knob explicitly, and a default would void the GENERIC-REQ presence check.+ for (const p of [+ 'tokenRequestFormat',+ 'tokenAuthMethod',+ 'scopeSeparator',+ 'sendScope',+ 'usePkce',+ 'includeResponseType',+ 'refreshEndpoint',+ 'extraAuthorizeParams',+ ]) {+ expect(props[p]).not.toHaveProperty('default')+ }+ })++ it('requires the generic client shape via CEL (GENERIC-REQ)', () => {+ const rule = specRules.find(+ r =>+ r.rule.includes("self.oauth.source != 'generic'") &&+ r.rule.includes('has(self.oauth.id)') &&+ r.rule.includes('has(self.oauth.authorizationEndpoint)') &&+ r.rule.includes('has(self.oauth.tokenEndpoint)') &&+ r.rule.includes('has(self.oauth.tokenRequestFormat)') &&+ r.rule.includes('has(self.oauth.tokenAuthMethod)') &&+ r.rule.includes('has(self.oauth.scopeSeparator)') &&+ r.rule.includes('has(self.oauth.sendScope)') &&+ r.rule.includes('has(self.oauth.supportsRefresh)') &&+ r.rule.includes('has(self.oauth.usePkce)') &&+ r.rule.includes('has(self.oauth.includeResponseType)')+ )+ expect(rule, 'GENERIC-REQ rule present').toBeDefined()+ })++ it('forbids remote-only fields on the generic carril (GENERIC-FORBID-REMOTE-FIELDS)', () => {+ const rule = specRules.find(+ r =>+ r.rule.includes("self.oauth.source != 'generic'") &&+ r.rule.includes('!has(self.oauth.clientMode)') &&+ r.rule.includes('!has(self.oauth.issuer)') &&+ r.rule.includes('!has(self.oauth.registrationEndpoint)') &&+ r.rule.includes('!has(self.oauth.issForCallback)') &&+ r.rule.includes('!has(self.oauth.bearerInBody)')+ )+ expect(rule, 'GENERIC-FORBID-REMOTE-FIELDS rule present').toBeDefined()+ })++ it('forbids generic-only knobs on the remote carril (REMOTE-FORBID-GENERIC-KNOBS)', () => {+ const rule = specRules.find(+ r =>+ r.rule.includes("self.oauth.source != 'remote'") &&+ r.rule.includes('!has(self.oauth.tokenRequestFormat)') &&+ r.rule.includes('!has(self.oauth.tokenAuthMethod)') &&+ r.rule.includes('!has(self.oauth.scopeSeparator)') &&+ r.rule.includes('!has(self.oauth.sendScope)') &&+ r.rule.includes('!has(self.oauth.usePkce)') &&+ r.rule.includes('!has(self.oauth.includeResponseType)') &&+ r.rule.includes('!has(self.oauth.refreshEndpoint)') &&+ r.rule.includes('!has(self.oauth.extraAuthorizeParams)')+ )+ expect(rule, 'REMOTE-FORBID-GENERIC-KNOBS rule present').toBeDefined()+ })++ it('pairs generic client_id/secret refs together (GENERIC-SECRET-PAIRING)', () => {+ const rule = specRules.find(+ r =>+ r.rule.includes("self.oauth.source != 'generic'") &&+ r.rule.includes('has(self.oauth.clientIdRef) == has(self.oauth.clientSecretRef)')+ )+ expect(rule, 'GENERIC-SECRET-PAIRING rule present').toBeDefined()+ })++ it('pins the source VALUE as immutable so the carril cannot flip in place (SOURCE-VALUE-IMM)', () => {+ const rule = specRules.find(+ r =>+ r.rule.includes('oldSelf.oauth.source == self.oauth.source') &&+ r.rule.includes('!has(oldSelf.oauth.source)') &&+ r.rule.includes('!has(self.oauth.source)') &&+ // Not IMM-5 (which pins presence via has()==has()).+ !r.rule.includes('has(oldSelf.oauth.source) == has(self.oauth.source)')+ )+ expect(rule, 'SOURCE-VALUE-IMM rule present').toBeDefined()+ })++ it('pins generic endpoints + knobs as immutable, double-guarded on source (GENERIC-IMM)', () => {+ const rule = specRules.find(+ r =>+ r.rule.includes("oldSelf.oauth.source != 'generic'") &&+ r.rule.includes("self.oauth.source != 'generic'") &&+ r.rule.includes(+ 'oldSelf.oauth.authorizationEndpoint == self.oauth.authorizationEndpoint'+ ) &&+ r.rule.includes('oldSelf.oauth.tokenRequestFormat == self.oauth.tokenRequestFormat') &&+ r.rule.includes('oldSelf.oauth.usePkce == self.oauth.usePkce') &&+ r.rule.includes('oldSelf.oauth.includeResponseType == self.oauth.includeResponseType')+ )+ expect(rule, 'GENERIC-IMM rule present').toBeDefined()+ // Optional generic fields are presence-pinned + guarded value-equality.+ expect(rule?.rule).toContain(+ 'has(oldSelf.oauth.refreshEndpoint) == has(self.oauth.refreshEndpoint)'+ )+ expect(rule?.rule).toContain(+ 'has(oldSelf.oauth.extraAuthorizeParams) == has(self.oauth.extraAuthorizeParams)'+ )+ })++ it('pins the generic secret posture (ref pair) as immutable across UPDATE (GENERIC-SECRET-IMM)', () => {+ // Generic has no clientMode; public/confidential is encoded by ref presence.+ // GENERIC-SECRET-PAIRING only pins that within a revision — this transition+ // rule pins it across UPDATE (presence + value of both refs), the analogue of+ // clientMode's IMM-6 pin on remote. Anchor on the unique message.+ const rule = specRules.find(r =>+ r.message?.includes('generic spec.oauth clientIdRef/clientSecretRef')+ )+ expect(rule, 'GENERIC-SECRET-IMM rule present').toBeDefined()+ // double-source-value-guarded on generic (both revisions)+ expect(rule?.rule).toContain("oldSelf.oauth.source != 'generic'")+ expect(rule?.rule).toContain("self.oauth.source != 'generic'")+ // presence-equality of both refs+ expect(rule?.rule).toContain('has(oldSelf.oauth.clientIdRef) == has(self.oauth.clientIdRef)')+ expect(rule?.rule).toContain(+ 'has(oldSelf.oauth.clientSecretRef) == has(self.oauth.clientSecretRef)'+ )+ // value-equality of the ref targets, presence-guarded+ expect(rule?.rule).toContain('oldSelf.oauth.clientIdRef.name == self.oauth.clientIdRef.name')+ expect(rule?.rule).toContain(+ 'oldSelf.oauth.clientSecretRef.key == self.oauth.clientSecretRef.key'+ )+ })++ it('reuses authorizationEndpoint/tokenEndpoint/resource/supportsRefresh for REMOTE and GENERIC', () => {+ const props = specSchema.properties.oauth.properties+ for (const p of ['authorizationEndpoint', 'tokenEndpoint', 'resource', 'supportsRefresh']) {+ expect(props[p].description).toMatch(/REMOTE and GENERIC/)+ }+ })++ // --- MODIFIED rules changed correctly ------------------------------------++ it('narrows the slug for baked AND generic, exempting only remote (SLUG re-gate)', () => {+ const rule = specRules.find(r => r.rule.includes("self.oauth.id.matches('^[a-z0-9-]{1,63}$')"))+ expect(rule, 'slug rule present').toBeDefined()+ // The exemption is now VALUE-gated on remote (not mere source presence), so+ // generic falls through to the slug narrow.+ expect(rule?.rule).toContain("has(self.oauth.source) && self.oauth.source == 'remote'")+ })++ it('re-gates REMOTE-REQ on source == remote so generic is not caught (REMOTE-REQ)', () => {+ // Anchor on the message: the positive `has(self.oauth.clientMode)` substring+ // also appears (negated) in BAKED-FORBID-REMOTE-FIELDS, so a rule-only match+ // is order-dependent. The message is unique to REMOTE-REQ.+ const rule = specRules.find(r => r.message?.includes('remote spec.oauth requires'))+ expect(rule, 'REMOTE-REQ rule present').toBeDefined()+ expect(rule?.rule).toContain("self.oauth.source != 'remote'")+ // and it still requires the full remote shape only for the remote carril+ expect(rule?.rule).toContain('has(self.oauth.clientMode)')+ expect(rule?.rule).toContain('has(self.oauth.bearerInBody)')+ })++ it('double-guards IMM-6 on source == remote so a generic update short-circuits (IMM-6)', () => {+ const imm6 = specRules.find(+ r =>+ r.rule.includes(+ 'oldSelf.oauth.authorizationEndpoint == self.oauth.authorizationEndpoint'+ ) && r.rule.includes('oldSelf.oauth.clientMode == self.oauth.clientMode')+ )+ expect(imm6, 'IMM-6 present').toBeDefined()+ expect(imm6?.rule).toContain("oldSelf.oauth.source != 'remote'")+ expect(imm6?.rule).toContain("self.oauth.source != 'remote'")+ })++ it('extends BAKED-FORBID-REMOTE-FIELDS with the generic knobs (BAKED-FORBID)', () => {+ const rule = specRules.find(+ r =>+ r.rule.includes('!has(self.oauth.clientMode)') &&+ r.rule.includes('!has(self.oauth.authorizationEndpoint)') &&+ r.rule.includes('!has(self.oauth.supportsRefresh)') &&+ r.rule.includes('!has(self.oauth.tokenRequestFormat)') &&+ r.rule.includes('!has(self.oauth.extraAuthorizeParams)')+ )+ expect(rule, 'BAKED-FORBID-REMOTE-FIELDS now forbids generic knobs').toBeDefined()+ })++ // --- FROZEN invariants still hold ----------------------------------------++ it('keeps the provider enum frozen at exactly the 8 baked adapters', () => {+ expect(specSchema.properties.oauth.properties.provider.enum).toEqual([+ 'salesforce',+ 'slack',+ 'notion',+ 'microsoft-graph',+ 'google',+ 'monday',+ 'clickup',+ 'vercel',+ ])+ })++ it('leaves BAKED-REQ unchanged (id/provider/clientIdRef/clientSecretRef quartet)', () => {+ const bakedReq = specRules.find(+ r =>+ r.rule.includes('has(self.oauth.source)') &&+ r.rule.includes('has(self.oauth.id)') &&+ r.rule.includes('has(self.oauth.provider)') &&+ r.rule.includes('has(self.oauth.clientIdRef)') &&+ r.rule.includes('has(self.oauth.clientSecretRef)') &&+ !r.rule.includes("self.oauth.source == 'remote'")+ )+ expect(bakedReq, 'BAKED-REQ unchanged').toBeDefined()+ expect(bakedReq?.message).toMatch(/baked spec\.oauth \(no source\) requires/)+ })++ it('leaves REMOTE-FORBID-PROVIDER unchanged', () => {+ const rule = specRules.find(+ r =>+ r.rule.includes('!has(self.oauth.source)') &&+ r.rule.includes('!has(self.oauth.provider)') &&+ !r.rule.includes('has(self.oauth.clientMode)')+ )+ expect(rule, 'REMOTE-FORBID-PROVIDER unchanged').toBeDefined()+ expect(rule?.message).toMatch(/must not set provider/)+ })})