Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test: split Grok policy and Host admission cases out of Codex files
Jose Gabriel Ramirez Encinas59d626d294fd
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex bbf4e6598..d7b668dfc 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.567",+ "version": "0.1.568","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.567",+ "version": "0.1.568","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 9b5fe517e..9d7efcced 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.567",+ "version": "0.1.568","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/test/hostSpecValidation.codexSubscription.test.ts b/control-api/test/hostSpecValidation.codexSubscription.test.tsindex 01ffbbb5b..69d190824 100644--- a/control-api/test/hostSpecValidation.codexSubscription.test.ts+++ b/control-api/test/hostSpecValidation.codexSubscription.test.ts@@ -9,21 +9,9 @@ const crdsDir = resolve(dirname(fileURLToPath(import.meta.url)), '../../charts/cafterEach(() => {delete process.env.CONTROL_API_CODEX_SUBSCRIPTION_ENABLED- delete process.env.CONTROL_API_GROK_SUBSCRIPTION_ENABLED})describe('codex-subscription Host admission', () => {- it('rejects a Grok target when the Grok management flag is absent or false', async () => {- const isModelAllowed = vi.fn().mockResolvedValue(true)- const res = await validateHostSpec(- { model: { provider: 'grok-subscription', name: 'grok-4.6' } },- { isModelAllowed }- )- expect(res).not.toBeNull()- expect(res!.errors[0].message).toMatch(/CONTROL_API_GROK_SUBSCRIPTION_ENABLED/)- expect(isModelAllowed).not.toHaveBeenCalled()- })-it('rejects a Codex target when the management flag is absent or false', async () => {const isModelAllowed = vi.fn().mockResolvedValue(true)const res = await validateHostSpec(@@ -153,39 +141,6 @@ describe('codex-subscription Host admission', () => {expect(isModelAllowed).toHaveBeenCalledWith('codex-subscription', 'gpt-5.3-codex', 'team-plus')})- it('does not tolerate switching a Grok Host onto a revoked connectionRef with the same model', async () => {- process.env.CONTROL_API_GROK_SUBSCRIPTION_ENABLED = 'true'- const isModelAllowed = vi.fn(async (_provider, _model, connectionRef) => {- return connectionRef === 'team-grok'- })- const tolerations: Array<Record<string, unknown>> = []- const res = await validateHostSpec(- {- model: {- provider: 'grok-subscription',- name: 'grok-4.6',- connectionRef: 'revoked-grok',- },- },- { isModelAllowed },- {- stored: {- model: {- provider: 'grok-subscription',- name: 'grok-4.6',- connectionRef: 'team-grok',- },- },- hostRef: { namespace: 'mcp-host', name: 'agent-g' },- tolerations,- }- )- expect(res).not.toBeNull()- expect(res!.errors[0].message).toContain('model_not_allowed')- expect(tolerations).toEqual([])- expect(isModelAllowed).toHaveBeenCalledWith('grok-subscription', 'grok-4.6', 'revoked-grok')- })-it('does not tolerate switching to a revoked connectionRef with the same model', async () => {process.env.CONTROL_API_CODEX_SUBSCRIPTION_ENABLED = 'true'const isModelAllowed = vi.fn(async (_provider, _model, connectionRef) => {diff --git a/control-api/test/hostSpecValidation.grokSubscription.test.ts b/control-api/test/hostSpecValidation.grokSubscription.test.tsnew file mode 100644index 000000000..80ba89856--- /dev/null+++ b/control-api/test/hostSpecValidation.grokSubscription.test.ts@@ -0,0 +1,52 @@+import { afterEach, describe, expect, it, vi } from 'vitest'+import { validateHostSpec } from '../src/routes/admin/hostSpecValidation.js'++afterEach(() => {+ delete process.env.CONTROL_API_GROK_SUBSCRIPTION_ENABLED+})++describe('grok-subscription Host admission', () => {+ it('rejects a Grok target when the Grok management flag is absent or false', async () => {+ const isModelAllowed = vi.fn().mockResolvedValue(true)+ const res = await validateHostSpec(+ { model: { provider: 'grok-subscription', name: 'grok-4.6' } },+ { isModelAllowed }+ )+ expect(res).not.toBeNull()+ expect(res!.errors[0].message).toMatch(/CONTROL_API_GROK_SUBSCRIPTION_ENABLED/)+ expect(isModelAllowed).not.toHaveBeenCalled()+ })++ it('does not tolerate switching a Grok Host onto a revoked connectionRef with the same model', async () => {+ process.env.CONTROL_API_GROK_SUBSCRIPTION_ENABLED = 'true'+ const isModelAllowed = vi.fn(async (_provider, _model, connectionRef) => {+ return connectionRef === 'team-grok'+ })+ const tolerations: Array<Record<string, unknown>> = []+ const res = await validateHostSpec(+ {+ model: {+ provider: 'grok-subscription',+ name: 'grok-4.6',+ connectionRef: 'revoked-grok',+ },+ },+ { isModelAllowed },+ {+ stored: {+ model: {+ provider: 'grok-subscription',+ name: 'grok-4.6',+ connectionRef: 'team-grok',+ },+ },+ hostRef: { namespace: 'mcp-host', name: 'agent-g' },+ tolerations,+ }+ )+ expect(res).not.toBeNull()+ expect(res!.errors[0].message).toContain('model_not_allowed')+ expect(tolerations).toEqual([])+ expect(isModelAllowed).toHaveBeenCalledWith('grok-subscription', 'grok-4.6', 'revoked-grok')+ })+})diff --git a/scripts/tests/test-codex-subscription-t0.sh b/scripts/tests/test-codex-subscription-t0.shindex 01f4fb9a4..25594c85f 100755--- a/scripts/tests/test-codex-subscription-t0.sh+++ b/scripts/tests/test-codex-subscription-t0.sh@@ -223,6 +223,7 @@ run_group "control-api" "control-api" \"test/services.recipeCodexGrantIdentity.test.ts" \"test/crd.llmProviderEnums.test.ts" \"test/hostSpecValidation.codexSubscription.test.ts" \+ "test/hostSpecValidation.grokSubscription.test.ts" \"test/llmProviders.test.ts" \"test/services.codexSubscriptionConnection.test.ts" \"test/services.llmAllowedModelsConfigMap.test.ts" \@@ -292,6 +293,7 @@ run_group "workflow-recipes" "workflow-recipes" \"src/workflow/sdkOnlyCodexBinding.test.ts" \"src/workflow/sdkOnlyGrokBinding.test.ts" \"src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts" \+ "src/workflow/pluginWorkloadSdkProvisioner.grokPolicy.test.ts" \"src/reconciler/pluginWorkloadSdkValidator.test.ts" \"tests/unit/workflow/modelConfigHandler.test.ts" \"tests/unit/workflow/modelConfigHandler.pluginSdkBroker.test.ts"diff --git a/scripts/tests/test-grok-subscription-t0.sh b/scripts/tests/test-grok-subscription-t0.shindex 4fa0d3721..7c590ed68 100755--- a/scripts/tests/test-grok-subscription-t0.sh+++ b/scripts/tests/test-grok-subscription-t0.sh@@ -103,7 +103,7 @@ require_file control-api/test/services.llmProviderAttemptAuthorizer.grok.test.tsrequire_file control-api/test/subscriptionGrantIdentity.test.tsrequire_file control-api/test/routes.adminPluginWorkloadSdk.test.tsrequire_file control-api/test/services.recipeCodexGrantIdentity.test.ts-require_file control-api/test/hostSpecValidation.codexSubscription.test.ts+require_file control-api/test/hostSpecValidation.grokSubscription.test.tsrequire_file control-api/test/crd.llmProviderEnums.test.tsrequire_file control-api/test/routes.mcp-host.plugin-workload-sdk.test.tsrequire_file mcp-host/src/pluginWorkloadSdk/promptBridge/controlApiClient.test.ts@@ -114,7 +114,7 @@ require_file scripts/tests/test-grok-llm-proxy-deploy-contract.shrequire_file tests/e2e/fixtures/grok-subscription/sanitized-upstream-contract.jsonrequire_file workflow-recipes/src/workflow/codexRecipeVerdict.test.tsrequire_file workflow-recipes/src/workflow/sdkOnlyGrokBinding.test.ts-require_file workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts+require_file workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.grokPolicy.test.tsrequire_file workflow-recipes/tests/unit/workflow/modelConfigHandler.pluginSdkBroker.test.tsrequire_file mcp-host/src/pluginWorkloadSdk/bootstrapIdentity.test.tsrequire_file packages/codex-catalog-projection/index.test.cjs@@ -156,10 +156,10 @@ run_group "grok-llm-proxy tsc" \bash -lc "cd '${ROOT}/grok-llm-proxy' && npx tsc --noEmit && echo 'pass 1'"run_group "control-api grok grant/oauth/redeem/authorize" \- bash -lc "cd '${ROOT}/control-api' && npx vitest run test/db.grokSubscriptionMigration.test.ts test/services.grokSubscriptionConnection.test.ts test/services.grokSubscriptionOAuth.test.ts test/services.grokSubscriptionCatalog.test.ts test/services.grokProviderAttemptRedemption.test.ts test/services.grokProviderAttemptTicket.test.ts test/services.llmProviderAttemptAuthorizer.grok.test.ts test/subscriptionGrantIdentity.test.ts test/routes.adminPluginWorkloadSdk.test.ts test/services.recipeCodexGrantIdentity.test.ts test/hostSpecValidation.codexSubscription.test.ts test/crd.llmProviderEnums.test.ts test/routes.mcp-host.plugin-workload-sdk.test.ts --no-file-parallelism"+ bash -lc "cd '${ROOT}/control-api' && npx vitest run test/db.grokSubscriptionMigration.test.ts test/services.grokSubscriptionConnection.test.ts test/services.grokSubscriptionOAuth.test.ts test/services.grokSubscriptionCatalog.test.ts test/services.grokProviderAttemptRedemption.test.ts test/services.grokProviderAttemptTicket.test.ts test/services.llmProviderAttemptAuthorizer.grok.test.ts test/subscriptionGrantIdentity.test.ts test/routes.adminPluginWorkloadSdk.test.ts test/services.recipeCodexGrantIdentity.test.ts test/hostSpecValidation.grokSubscription.test.ts test/crd.llmProviderEnums.test.ts test/routes.mcp-host.plugin-workload-sdk.test.ts --no-file-parallelism"run_group "workflow-recipes grok SDK" \- bash -lc "cd '${ROOT}/workflow-recipes' && npx vitest run src/workflow/codexRecipeVerdict.test.ts src/workflow/sdkOnlyGrokBinding.test.ts src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts src/reconciler/pluginWorkloadSdkValidator.test.ts tests/unit/workflow/modelConfigHandler.pluginSdkBroker.test.ts --no-file-parallelism"+ bash -lc "cd '${ROOT}/workflow-recipes' && npx vitest run src/workflow/codexRecipeVerdict.test.ts src/workflow/sdkOnlyGrokBinding.test.ts src/workflow/pluginWorkloadSdkProvisioner.grokPolicy.test.ts src/reconciler/pluginWorkloadSdkValidator.test.ts tests/unit/workflow/modelConfigHandler.pluginSdkBroker.test.ts --no-file-parallelism"run_group "mcp-host grok bootstrap" \bash -lc "cd '${ROOT}/mcp-host' && npx vitest run src/pluginWorkloadSdk/bootstrapIdentity.test.ts src/pluginWorkloadSdk/promptBridge/controlApiClient.test.ts src/pluginWorkloadSdk/promptBridge/llmBridge.failover.test.ts --no-file-parallelism"diff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.jsonindex 131e1b300..e5bd2b010 100644--- a/workflow-recipes/package-lock.json+++ b/workflow-recipes/package-lock.json@@ -1,12 +1,12 @@{"name": "workload-recipes-controller",- "version": "0.1.357",+ "version": "0.1.358","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "workload-recipes-controller",- "version": "0.1.357",+ "version": "0.1.358","license": "SEE LICENSE IN LICENSE","dependencies": {"@aws-sdk/client-s3": "^3.1009.0",diff --git a/workflow-recipes/package.json b/workflow-recipes/package.jsonindex a8106ffd3..078ba637e 100644--- a/workflow-recipes/package.json+++ b/workflow-recipes/package.json@@ -1,6 +1,6 @@{"name": "workload-recipes-controller",- "version": "0.1.357",+ "version": "0.1.358","description": "Workload Recipes Controller (WRC) - WorkloadRecipe lifecycle management and MCP server interface","main": "dist/main.js","engines": {diff --git a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.tsindex d569e2c91..e9f9f597f 100644--- a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts+++ b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.codexPolicy.test.ts@@ -1,6 +1,4 @@import { describe, expect, it, vi } from 'vitest'-import { computeGrokPolicyHash } from '@clerum/grok-provider-attempt-contract'-import { computeCodexPolicyHash } from '@clerum/llm-provider-attempt-contract'import type { WorkflowRecipeSpec } from '../types'import type { CodexRecipeVerdict } from './codexRecipeVerdict'import {@@ -8,88 +6,48 @@ import {type PluginWorkloadSdkProvisionerDeps,} from './pluginWorkloadSdkProvisioner'import {- buildMcpHostPod,- pluginWorkloadSdkRuntimeContractHash,- recipeDeclaresGrokSubscription,-} from './podFactory'-import type { WorkflowRuntimePlan } from './runtimePlan'+ EAGER_SDK_RUNTIME,+ EAGER_SDK_SANDBOX_NS,+ EAGER_SDK_TEST_IMAGE,+ eagerSdkRuntimeContractHash,+ eagerSdkTestConfig,+ ineligibleGrokProjection,+} from './pluginWorkloadSdkProvisioner.testFixtures'import type { PluginWorkloadSdkCodexBindingProof } from './sdkOnlyCodexBinding'-import type { WorkflowConfig } from './types'+import { mintSdkOnlyCodexBindingProof } from './sdkOnlyCodexBinding'-const SANDBOX_NS = 'sandbox-recipes'-const IMAGE = 'registry.example/clerum/mcp-host-slim:sha-current'const RECIPE = 'codex-sdk'const MODEL = 'gpt-5.3-codex'-const GROK_RECIPE = 'grok-sdk'-const GROK_MODEL = 'grok-4.6'--const RUNTIME = {} as unknown as WorkflowRuntimePlan--const TEST_CONFIG = {- coordinatorImage: 'registry.example/coordinator:current',- mcpHostImage: IMAGE,- wrcEndpoint: 'http://workflow-recipes.example',- sandboxNamespace: SANDBOX_NS,- mcpServerNamespace: 'mcp-server',- imagePullPolicy: 'IfNotPresent',- maxWorkflowSteps: 10,- pluginWorkloadSdkEnabled: true,-} as unknown as WorkflowConfig+const TEST_CONFIG = eagerSdkTestConfig()const CODEX_SPEC = {agent: { provider: 'codex-subscription', model: MODEL },pluginWorkloadSdk: { promptBridge: {} },} as unknown as WorkflowRecipeSpec-const GROK_SPEC = {- agent: { provider: 'grok-subscription', model: GROK_MODEL },- pluginWorkloadSdk: { promptBridge: {} },-} as unknown as WorkflowRecipeSpec-function codexBinding(overrides: Partial<Omit<PluginWorkloadSdkCodexBindingProof, 'bindingHash'>> = {}): PluginWorkloadSdkCodexBindingProof {- const fields = {+ return mintSdkOnlyCodexBindingProof({connectionKey: 'team-plus',catalogRevision: 4,credentialRevision: 2,model: MODEL,...overrides,- }- return { ...fields, bindingHash: computeCodexPolicyHash(fields) }+ })}const MINTED = codexBinding()-/** Build the one verdict the provisioner reads, from a case's intent. */-function grokBindingProof(- overrides: Partial<Omit<PluginWorkloadSdkCodexBindingProof, 'bindingHash'>> = {}-): PluginWorkloadSdkCodexBindingProof {- const fields = {- connectionKey: 'team-grok',- catalogRevision: 5,- credentialRevision: 2,- model: GROK_MODEL,- ...overrides,- }- return { ...fields, bindingHash: computeGrokPolicyHash(fields) }-}--const GROK_MINTED = grokBindingProof()-function verdictFor(opts: {codexBinding?: PluginWorkloadSdkCodexBindingProof | nullcodexBindingUndecidable?: boolean- grokBinding?: PluginWorkloadSdkCodexBindingProof | null- grokBindingUndecidable?: boolean}): CodexRecipeVerdict {const undecidable = opts.codexBindingUndecidable === true- const grokUndecidable = opts.grokBindingUndecidable === trueconst binding = opts.codexBinding ?? null- const grokBinding = opts.grokBinding ?? nullreturn {- provenance: undecidable || grokUndecidable ? 'uncertain' : 'authoritative',- provenanceReason: undecidable || grokUndecidable ? 'parent_spec_unavailable' : 'standalone',+ provenance: undecidable ? 'uncertain' : 'authoritative',+ provenanceReason: undecidable ? 'parent_spec_unavailable' : 'standalone',connectionKey: 'team-plus',projection: {targets: [],@@ -105,25 +63,9 @@ function verdictFor(opts: {},hostBinding: binding,hostBindingReason: binding ? 'eligible' : 'unassigned',- grokProjection: {- targets: [],- eligibleTargets: [],- derivedScopes: grokBinding ? ['llm:grok:execute'] : [],- requiresCodexProxyEgress: false,- requiresGrokProxyEgress: Boolean(grokBinding) && !grokUndecidable,- catalogContentHash: null,- catalogRevision: null,- connectionRevision: null,- eligibility: grokUndecidable ? 'uncertain' : grokBinding ? 'eligible' : 'ineligible',- reason: grokUndecidable ? 'provenance_uncertain' : grokBinding ? 'eligible' : 'static_only',- driftHashInput: '{}',- },- grokBinding: grokUndecidable ? null : grokBinding,- grokBindingReason: grokUndecidable- ? 'provenance_uncertain'- : grokBinding- ? 'eligible'- : 'static_only',+ grokProjection: ineligibleGrokProjection(),+ grokBinding: null,+ grokBindingReason: 'static_only',}}@@ -149,78 +91,13 @@ function readyBootstrapBody(binding: PluginWorkloadSdkCodexBindingProof | null)}}-function desiredRuntimeContractHash(): string {- return pluginWorkloadSdkRuntimeContractHash(- buildMcpHostPod(- RECIPE,- CODEX_SPEC.agent,- TEST_CONFIG,- RECIPE,- SANDBOX_NS,- undefined,- undefined,- undefined,- {- mountWorkflowOutput: false,- pluginWorkloadSdkCapabilities: ['promptBridge'],- pluginWorkloadSdkRuntimeMode: 'sdk-only',- grokSubscriptionEnabled: TEST_CONFIG.grokSubscriptionEnabled === true,- recipeAgentProvider: CODEX_SPEC.agent.provider,- recipeDeclaresGrok: recipeDeclaresGrokSubscription(CODEX_SPEC),- }- )- )-}--function grokRuntimeContractHash(): string {- return pluginWorkloadSdkRuntimeContractHash(- buildMcpHostPod(- GROK_RECIPE,- GROK_SPEC.agent,- TEST_CONFIG,- GROK_RECIPE,- SANDBOX_NS,- undefined,- undefined,- undefined,- {- mountWorkflowOutput: false,- pluginWorkloadSdkCapabilities: ['promptBridge'],- pluginWorkloadSdkRuntimeMode: 'sdk-only',- grokSubscriptionEnabled: TEST_CONFIG.grokSubscriptionEnabled === true,- recipeAgentProvider: GROK_SPEC.agent.provider,- recipeDeclaresGrok: recipeDeclaresGrokSubscription(GROK_SPEC),- }- )- )-}--function readyGrokBootstrapBody(binding: PluginWorkloadSdkCodexBindingProof | null) {- return {- status: 202,- body: {- configured: true,- ready: true,- provider: 'grok-subscription',- model: GROK_MODEL,- contractVersion: 3,- policyReady: true,- policyState: 'active',- policyRevision: 7,- policyHash: 'b'.repeat(64),- defaultTargetRef: 'target/grok',- defaultProvider: 'grok-subscription',- defaultModel: GROK_MODEL,- ...(binding ? { subscriptionBinding: binding } : {}),- },- }-}--function makeHarness(configureResult: unknown, spec: WorkflowRecipeSpec = CODEX_SPEC) {+function makeHarness(configureResult: unknown) {let podUid = 'pod-uid-1'- const recipeName = spec === GROK_SPEC ? GROK_RECIPE : RECIPE- const runtimeContractHash =- spec === GROK_SPEC ? grokRuntimeContractHash() : desiredRuntimeContractHash()+ const runtimeContractHash = eagerSdkRuntimeContractHash({+ recipeName: RECIPE,+ spec: CODEX_SPEC,+ config: TEST_CONFIG,+ })const readNamespacedPod = vi.fn().mockImplementation(async () => ({metadata: {uid: podUid,@@ -228,7 +105,7 @@ function makeHarness(configureResult: unknown, spec: WorkflowRecipeSpec = CODEX_'clerum.io/plugin-workload-sdk-runtime-contract-hash': runtimeContractHash,},},- spec: { containers: [{ name: 'mcp-host', image: IMAGE }] },+ spec: { containers: [{ name: 'mcp-host', image: EAGER_SDK_TEST_IMAGE }] },status: {phase: 'Running',conditions: [{ type: 'Ready', status: 'True' }],@@ -253,23 +130,17 @@ function makeHarness(configureResult: unknown, spec: WorkflowRecipeSpec = CODEX_} as unknown as PluginWorkloadSdkProvisionerDepsconst provisioner = new PluginWorkloadSdkProvisioner(deps)- // The provisioner now takes ONE verdict instead of a binding plus a- // derived boolean. These helpers keep each existing case's semantics: a- // minted binding means eligible+authoritative, and "undecidable" means the- // projection itself could not decide.const reconcile = (opts: {codexBinding?: PluginWorkloadSdkCodexBindingProof | nullcodexBindingUndecidable?: boolean- grokBinding?: PluginWorkloadSdkCodexBindingProof | null- grokBindingUndecidable?: boolean}) =>provisioner.ensureEagerSdkMcpHost(- recipeName,+ RECIPE,'recipe-uid',- SANDBOX_NS,- recipeName,- spec,- RUNTIME,+ EAGER_SDK_SANDBOX_NS,+ RECIPE,+ CODEX_SPEC,+ EAGER_SDK_RUNTIME,{mcpHostPhase: 'Running',codexVerdict: verdictFor(opts),@@ -469,131 +340,3 @@ describe('eager Codex policy gate', () => {expect(harness.provisioner.getBootstrapProof(RECIPE)).toBeUndefined()})})--describe('eager Grok policy gate', () => {- it('injects Grok proxy env when the WRC flag is on and the recipe declares grok-subscription', () => {- const pod = buildMcpHostPod(- GROK_RECIPE,- GROK_SPEC.agent,- TEST_CONFIG,- GROK_RECIPE,- SANDBOX_NS,- undefined,- undefined,- undefined,- {- mountWorkflowOutput: false,- pluginWorkloadSdkCapabilities: ['promptBridge'],- pluginWorkloadSdkRuntimeMode: 'sdk-only',- grokSubscriptionEnabled: true,- recipeAgentProvider: GROK_SPEC.agent.provider,- recipeDeclaresGrok: recipeDeclaresGrokSubscription(GROK_SPEC),- }- )- const env = pod.spec?.containers?.[0].env ?? []- expect(env).toContainEqual({ name: 'MCP_HOST_GROK_SUBSCRIPTION_ENABLED', value: 'true' })- expect(env).toContainEqual({- name: 'GROK_LLM_PROXY_RUNTIME_URL',- value: 'http://grok-llm-proxy.control-plane.svc.cluster.local:8080',- })- })-- it('omits Grok proxy env when the WRC flag is off', () => {- const pod = buildMcpHostPod(- GROK_RECIPE,- GROK_SPEC.agent,- TEST_CONFIG,- GROK_RECIPE,- SANDBOX_NS,- undefined,- undefined,- undefined,- {- mountWorkflowOutput: false,- pluginWorkloadSdkCapabilities: ['promptBridge'],- pluginWorkloadSdkRuntimeMode: 'sdk-only',- grokSubscriptionEnabled: false,- recipeAgentProvider: GROK_SPEC.agent.provider,- recipeDeclaresGrok: recipeDeclaresGrokSubscription(GROK_SPEC),- }- )- const env = pod.spec?.containers?.[0].env ?? []- expect(env).not.toContainEqual({- name: 'MCP_HOST_GROK_SUBSCRIPTION_ENABLED',- value: 'true',- })- })-- it('accepts a Grok hash on subscriptionBinding and reports ready', async () => {- const harness = makeHarness(readyGrokBootstrapBody(GROK_MINTED), GROK_SPEC)- expect(await harness.reconcile({ grokBinding: GROK_MINTED })).toBe('ready')- expect(harness.configure).toHaveBeenCalledWith(- 'grok-subscription',- GROK_MODEL,- expect.any(String),- 'configure-token',- 'promptBridge',- GROK_MINTED- )- expect(harness.provisioner.getBootstrapProof(GROK_RECIPE)).toMatchObject({- contractVersion: 3,- provider: 'grok-subscription',- subscriptionBinding: GROK_MINTED,- policyReady: true,- })- })-- it('skips reconfigure when Grok provenance is uncertain and the same pod still holds the binding', async () => {- const harness = makeHarness(readyGrokBootstrapBody(GROK_MINTED), GROK_SPEC)- expect(await harness.reconcile({ grokBinding: GROK_MINTED })).toBe('ready')- expect(harness.configure).toHaveBeenCalledTimes(1)- expect(- await harness.reconcile({ grokBinding: GROK_MINTED, grokBindingUndecidable: true })- ).toBe('ready')- expect(harness.configure).toHaveBeenCalledTimes(1)- })-- it('rejects a Grok bootstrap whose hash is a Codex digest', async () => {- // Minted and echoed hashes MUST be the same Codex digest. If parse used- // computeCodexPolicyHash, the echo would match and this would report ready.- const forged = {- connectionKey: 'team-grok',- catalogRevision: 5,- credentialRevision: 2,- model: GROK_MODEL,- bindingHash: computeCodexPolicyHash({- model: GROK_MODEL,- catalogRevision: 5,- credentialRevision: 2,- connectionKey: 'team-grok',- }),- }- const harness = makeHarness(readyGrokBootstrapBody(forged), GROK_SPEC)- expect(await harness.reconcile({ grokBinding: forged })).toBe('deploying')- expect(harness.provisioner.getBootstrapProof(GROK_RECIPE)).toBeUndefined()- expect(harness.configure).toHaveBeenCalled()- })-- it('accepts execution_binding_missing as awaiting_policy when Grok has no grant', async () => {- const harness = makeHarness(- {- status: 202,- body: {- configured: true,- ready: true,- provider: 'grok-subscription',- model: GROK_MODEL,- contractVersion: 3,- policyState: 'binding_missing',- policyReason: 'execution_binding_missing',- },- },- GROK_SPEC- )- expect(await harness.reconcile({ grokBinding: null })).toBe('awaiting_policy')- expect(harness.provisioner.getBootstrapProof(GROK_RECIPE)).toMatchObject({- policyReady: false,- policyReason: 'execution_binding_missing',- })- })-})diff --git a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.grokPolicy.test.ts b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.grokPolicy.test.tsnew file mode 100644index 000000000..04e677aed--- /dev/null+++ b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.grokPolicy.test.ts@@ -0,0 +1,258 @@+import { describe, expect, it, vi } from 'vitest'+import { computeCodexPolicyHash } from '@clerum/llm-provider-attempt-contract'+import type { WorkflowRecipeSpec } from '../types'+import type { CodexRecipeVerdict } from './codexRecipeVerdict'+import {+ PluginWorkloadSdkProvisioner,+ type PluginWorkloadSdkProvisionerDeps,+} from './pluginWorkloadSdkProvisioner'+import {+ EAGER_SDK_RUNTIME,+ EAGER_SDK_SANDBOX_NS,+ EAGER_SDK_TEST_IMAGE,+ buildEagerSdkPolicyPod,+ eagerSdkRuntimeContractHash,+ eagerSdkTestConfig,+ ineligibleCodexProjection,+} from './pluginWorkloadSdkProvisioner.testFixtures'+import type { PluginWorkloadSdkCodexBindingProof } from './sdkOnlyCodexBinding'+import { mintSdkOnlyGrokBindingProof } from './sdkOnlyGrokBinding'++const RECIPE = 'grok-sdk'+const MODEL = 'grok-4.6'+const TEST_CONFIG = eagerSdkTestConfig({ grokSubscriptionEnabled: true })++const GROK_SPEC = {+ agent: { provider: 'grok-subscription', model: MODEL },+ pluginWorkloadSdk: { promptBridge: {} },+} as unknown as WorkflowRecipeSpec++const MINTED = mintSdkOnlyGrokBindingProof({+ connectionKey: 'team-grok',+ catalogRevision: 5,+ credentialRevision: 2,+ model: MODEL,+})++function verdictFor(opts: {+ grokBinding?: PluginWorkloadSdkCodexBindingProof | null+ grokBindingUndecidable?: boolean+}): CodexRecipeVerdict {+ const undecidable = opts.grokBindingUndecidable === true+ const binding = opts.grokBinding ?? null+ return {+ provenance: undecidable ? 'uncertain' : 'authoritative',+ provenanceReason: undecidable ? 'parent_spec_unavailable' : 'standalone',+ connectionKey: 'unassigned',+ projection: ineligibleCodexProjection(),+ hostBinding: null,+ hostBindingReason: 'unassigned',+ grokProjection: {+ targets: [],+ eligibleTargets: [],+ derivedScopes: binding ? ['llm:grok:execute'] : [],+ requiresCodexProxyEgress: false,+ requiresGrokProxyEgress: Boolean(binding) && !undecidable,+ catalogContentHash: null,+ catalogRevision: null,+ connectionRevision: null,+ eligibility: undecidable ? 'uncertain' : binding ? 'eligible' : 'ineligible',+ reason: undecidable ? 'provenance_uncertain' : binding ? 'eligible' : 'static_only',+ driftHashInput: '{}',+ },+ grokBinding: undecidable ? null : binding,+ grokBindingReason: undecidable ? 'provenance_uncertain' : binding ? 'eligible' : 'static_only',+ }+}++function readyBootstrapBody(binding: PluginWorkloadSdkCodexBindingProof | null) {+ return {+ status: 202,+ body: {+ configured: true,+ ready: true,+ provider: 'grok-subscription',+ model: MODEL,+ contractVersion: 3,+ policyReady: true,+ policyState: 'active',+ policyRevision: 7,+ policyHash: 'b'.repeat(64),+ defaultTargetRef: 'target/grok',+ defaultProvider: 'grok-subscription',+ defaultModel: MODEL,+ ...(binding ? { subscriptionBinding: binding } : {}),+ },+ }+}++function makeHarness(configureResult: unknown) {+ let podUid = 'pod-uid-1'+ const runtimeContractHash = eagerSdkRuntimeContractHash({+ recipeName: RECIPE,+ spec: GROK_SPEC,+ config: TEST_CONFIG,+ })+ const readNamespacedPod = vi.fn().mockImplementation(async () => ({+ metadata: {+ uid: podUid,+ annotations: {+ 'clerum.io/plugin-workload-sdk-runtime-contract-hash': runtimeContractHash,+ },+ },+ spec: { containers: [{ name: 'mcp-host', image: EAGER_SDK_TEST_IMAGE }] },+ status: {+ phase: 'Running',+ conditions: [{ type: 'Ready', status: 'True' }],+ containerStatuses: [],+ },+ }))+ const deleteNamespacedPod = vi.fn().mockResolvedValue({})+ const createNamespacedPod = vi.fn().mockResolvedValue({})+ const configure = vi.fn().mockResolvedValue(configureResult)+ const signWrcConfigureToken = vi.fn().mockResolvedValue('configure-token')+ const deps = {+ coreApi: { readNamespacedPod, deleteNamespacedPod, createNamespacedPod },+ config: TEST_CONFIG,+ tokenFactory: { signWrcConfigureToken },+ modelConfigHandler: { configurePluginWorkloadSdkBootstrap: configure },+ log: { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() },+ ensureMcpHostSecrets: vi.fn().mockResolvedValue(undefined),+ applyWorkflowNetworkPolicies: vi.fn().mockResolvedValue(undefined),+ ensureMcpHostHeadlessService: vi.fn().mockResolvedValue(undefined),+ createIfNotExists: vi.fn().mockResolvedValue(true),+ safeDelete: vi.fn().mockResolvedValue(undefined),+ } as unknown as PluginWorkloadSdkProvisionerDeps+ const provisioner = new PluginWorkloadSdkProvisioner(deps)++ const reconcile = (opts: {+ grokBinding?: PluginWorkloadSdkCodexBindingProof | null+ grokBindingUndecidable?: boolean+ }) =>+ provisioner.ensureEagerSdkMcpHost(+ RECIPE,+ 'recipe-uid',+ EAGER_SDK_SANDBOX_NS,+ RECIPE,+ GROK_SPEC,+ EAGER_SDK_RUNTIME,+ {+ mcpHostPhase: 'Running',+ codexVerdict: verdictFor(opts),+ }+ )++ return {+ provisioner,+ reconcile,+ configure,+ }+}++describe('eager Grok policy gate', () => {+ it('pins MCP_HOST_GROK_SUBSCRIPTION_ENABLED on the SDK pod contract', () => {+ const pod = buildEagerSdkPolicyPod({+ recipeName: RECIPE,+ spec: GROK_SPEC,+ config: TEST_CONFIG,+ })+ const env = pod.spec?.containers?.[0].env ?? []+ expect(env).toContainEqual({ name: 'MCP_HOST_GROK_SUBSCRIPTION_ENABLED', value: 'true' })+ expect(env).toContainEqual({+ name: 'GROK_LLM_PROXY_RUNTIME_URL',+ value: 'http://grok-llm-proxy.control-plane.svc.cluster.local:8080',+ })+ expect(+ eagerSdkRuntimeContractHash({ recipeName: RECIPE, spec: GROK_SPEC, config: TEST_CONFIG })+ ).not.toBe(+ eagerSdkRuntimeContractHash({+ recipeName: RECIPE,+ spec: GROK_SPEC,+ config: eagerSdkTestConfig({ grokSubscriptionEnabled: false }),+ })+ )+ })++ it('omits Grok proxy env when the WRC flag is off', () => {+ const pod = buildEagerSdkPolicyPod({+ recipeName: RECIPE,+ spec: GROK_SPEC,+ config: eagerSdkTestConfig({ grokSubscriptionEnabled: false }),+ })+ const env = pod.spec?.containers?.[0].env ?? []+ expect(env).not.toContainEqual({+ name: 'MCP_HOST_GROK_SUBSCRIPTION_ENABLED',+ value: 'true',+ })+ })++ it('accepts a Grok hash on subscriptionBinding and reports ready', async () => {+ const harness = makeHarness(readyBootstrapBody(MINTED))+ expect(await harness.reconcile({ grokBinding: MINTED })).toBe('ready')+ expect(harness.configure).toHaveBeenCalledWith(+ 'grok-subscription',+ MODEL,+ expect.any(String),+ 'configure-token',+ 'promptBridge',+ MINTED+ )+ expect(harness.provisioner.getBootstrapProof(RECIPE)).toMatchObject({+ contractVersion: 3,+ provider: 'grok-subscription',+ subscriptionBinding: MINTED,+ policyReady: true,+ })+ })++ it('skips reconfigure when Grok provenance is uncertain and the same pod still holds the binding', async () => {+ const harness = makeHarness(readyBootstrapBody(MINTED))+ expect(await harness.reconcile({ grokBinding: MINTED })).toBe('ready')+ expect(harness.configure).toHaveBeenCalledTimes(1)+ expect(await harness.reconcile({ grokBinding: MINTED, grokBindingUndecidable: true })).toBe(+ 'ready'+ )+ expect(harness.configure).toHaveBeenCalledTimes(1)+ })++ it('rejects a Grok bootstrap whose hash is a Codex digest', async () => {+ // Minted and echoed hashes MUST be the Grok digest. If parse used+ // computeCodexPolicyHash, the echo would match and this would report ready.+ const forged: PluginWorkloadSdkCodexBindingProof = {+ connectionKey: 'team-grok',+ catalogRevision: 5,+ credentialRevision: 2,+ model: MODEL,+ bindingHash: computeCodexPolicyHash({+ model: MODEL,+ catalogRevision: 5,+ credentialRevision: 2,+ connectionKey: 'team-grok',+ }),+ }+ const harness = makeHarness(readyBootstrapBody(forged))+ expect(await harness.reconcile({ grokBinding: forged })).toBe('deploying')+ expect(harness.provisioner.getBootstrapProof(RECIPE)).toBeUndefined()+ expect(harness.configure).toHaveBeenCalled()+ })++ it('accepts execution_binding_missing as awaiting_policy when Grok has no grant', async () => {+ const harness = makeHarness({+ status: 202,+ body: {+ configured: true,+ ready: true,+ provider: 'grok-subscription',+ model: MODEL,+ contractVersion: 3,+ policyState: 'binding_missing',+ policyReason: 'execution_binding_missing',+ },+ })+ expect(await harness.reconcile({ grokBinding: null })).toBe('awaiting_policy')+ expect(harness.provisioner.getBootstrapProof(RECIPE)).toMatchObject({+ policyReady: false,+ policyReason: 'execution_binding_missing',+ })+ })+})diff --git a/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.testFixtures.ts b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.testFixtures.tsnew file mode 100644index 000000000..7c05e11c3--- /dev/null+++ b/workflow-recipes/src/workflow/pluginWorkloadSdkProvisioner.testFixtures.ts@@ -0,0 +1,91 @@+import type { CodexExecutionProjection } from '@clerum/codex-catalog-projection'+import type { WorkflowRecipeSpec } from '../types'+import { resolveEagerSdkMcpHostAgent } from './agentResolution'+import type { CodexRecipeVerdict } from './codexRecipeVerdict'+import {+ buildMcpHostPod,+ declaredPluginWorkloadSdkCapabilities,+ pluginWorkloadSdkRuntimeContractHash,+ recipeDeclaresGrokSubscription,+} from './podFactory'+import type { WorkflowRuntimePlan } from './runtimePlan'+import type { WorkflowConfig } from './types'++export const EAGER_SDK_SANDBOX_NS = 'sandbox-recipes'+export const EAGER_SDK_TEST_IMAGE = 'registry.example/clerum/mcp-host-slim:sha-current'++export const EAGER_SDK_RUNTIME = {} as unknown as WorkflowRuntimePlan++export function eagerSdkTestConfig(overrides: Partial<WorkflowConfig> = {}): WorkflowConfig {+ return {+ coordinatorImage: 'registry.example/coordinator:current',+ mcpHostImage: EAGER_SDK_TEST_IMAGE,+ wrcEndpoint: 'http://workflow-recipes.example',+ sandboxNamespace: EAGER_SDK_SANDBOX_NS,+ mcpServerNamespace: 'mcp-server',+ imagePullPolicy: 'IfNotPresent',+ maxWorkflowSteps: 10,+ pluginWorkloadSdkEnabled: true,+ ...overrides,+ } as unknown as WorkflowConfig+}++export function ineligibleCodexProjection(): CodexExecutionProjection {+ return {+ targets: [],+ eligibleTargets: [],+ derivedScopes: [],+ requiresCodexProxyEgress: false,+ catalogContentHash: null,+ catalogRevision: null,+ connectionRevision: null,+ eligibility: 'ineligible',+ reason: 'unassigned',+ driftHashInput: '{}',+ }+}++export function ineligibleGrokProjection(): CodexRecipeVerdict['grokProjection'] {+ return {+ ...ineligibleCodexProjection(),+ reason: 'static_only',+ requiresGrokProxyEgress: false,+ }+}++/** Same buildMcpHostPod options the provisioner uses for the eager SDK pod. */+export function buildEagerSdkPolicyPod(input: {+ recipeName: string+ spec: WorkflowRecipeSpec+ config: WorkflowConfig+}) {+ const agent = resolveEagerSdkMcpHostAgent(input.spec)+ return buildMcpHostPod(+ input.recipeName,+ agent,+ input.config,+ input.recipeName,+ input.config.sandboxNamespace,+ undefined,+ undefined,+ undefined,+ {+ mountWorkflowOutput: false,+ pluginWorkloadSdkCapabilities: declaredPluginWorkloadSdkCapabilities(+ input.spec.pluginWorkloadSdk+ ),+ pluginWorkloadSdkRuntimeMode: 'sdk-only',+ grokSubscriptionEnabled: input.config.grokSubscriptionEnabled === true,+ recipeAgentProvider: agent?.provider,+ recipeDeclaresGrok: recipeDeclaresGrokSubscription(input.spec),+ }+ )+}++export function eagerSdkRuntimeContractHash(input: {+ recipeName: string+ spec: WorkflowRecipeSpec+ config: WorkflowConfig+}): string {+ return pluginWorkloadSdkRuntimeContractHash(buildEagerSdkPolicyPod(input))+}