Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(np08): close authority coverage gaps

Alfredo Lopezab87e7bbaf72
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 2b3b57e0e..a9498bea7 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.475",
+ "version": "0.1.476",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.475",
+ "version": "0.1.476",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/image-policy": "file:../packages/image-policy",
diff --git a/control-api/package.json b/control-api/package.json
index 6c4b4cf04..71c56655a 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.475",
+ "version": "0.1.476",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/test/mcpHostJwtToken.hostRefs.test.ts b/control-api/test/mcpHostJwtToken.hostRefs.test.ts
index b15474411..530815bd4 100644
--- a/control-api/test/mcpHostJwtToken.hostRefs.test.ts
+++ b/control-api/test/mcpHostJwtToken.hostRefs.test.ts
@@ -95,6 +95,31 @@ describe('mcpHostJwtToken — hostRefs JWT claim', () => {
}
})
+ it('accepts the HCC access boundary and leaves HCC refresh TTL uncapped', () => {
+ const previousAccessTtl = config.mcpHostJwtAccessTtlSec
+ const previousRefreshTtl = config.mcpHostJwtRefreshTtlSec
+ config.mcpHostJwtAccessTtlSec = MCP_HOST_HCC_ACCESS_MAX_TTL_SECONDS
+ config.mcpHostJwtRefreshTtlSec = MCP_HOST_HCC_ACCESS_MAX_TTL_SECONDS + 300
+ try {
+ const access = issueMcpHostAccessJwt(config.hostsNamespace, 'standalone', ['chatllm'], {
+ hccCredential: { hostUid: 'host-uid-chatllm' },
+ })
+ const refresh = issueMcpHostRefreshJwt(config.hostsNamespace, 'standalone', ['chatllm'], {
+ hccCredential: { hostUid: 'host-uid-chatllm' },
+ })
+ const refreshClaims = jwt.decode(refresh.token) as Record<string, unknown>
+
+ expect(access.expiresInSeconds).toBe(MCP_HOST_HCC_ACCESS_MAX_TTL_SECONDS)
+ expect(refresh.expiresInSeconds).toBe(MCP_HOST_HCC_ACCESS_MAX_TTL_SECONDS + 300)
+ expect((refreshClaims.exp as number) - (refreshClaims.iat as number)).toBe(
+ MCP_HOST_HCC_ACCESS_MAX_TTL_SECONDS + 300
+ )
+ } finally {
+ config.mcpHostJwtAccessTtlSec = previousAccessTtl
+ config.mcpHostJwtRefreshTtlSec = previousRefreshTtl
+ }
+ })
+
it('rejects workflow-only tokens that inject HCC-only claims', () => {
const token = jwt.sign(
{
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index e10918442..ddb7b7473 100644
--- a/host-context-controller/package-lock.json
+++ b/host-context-controller/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-host-context-controller",
- "version": "0.1.230",
+ "version": "0.1.231",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.230",
+ "version": "0.1.231",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@clerum/image-policy": "file:../packages/image-policy",
diff --git a/host-context-controller/package.json b/host-context-controller/package.json
index 5206c61af..8c999b0d9 100644
--- a/host-context-controller/package.json
+++ b/host-context-controller/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-host-context-controller",
- "version": "0.1.230",
+ "version": "0.1.231",
"description": "Host Context Controller - provides McpServer CRDs to mcp-host via REST API",
"main": "dist/main.js",
"engines": {
diff --git a/host-context-controller/src/k8sClient.test.ts b/host-context-controller/src/k8sClient.test.ts
index 362c5954b..53518b889 100644
--- a/host-context-controller/src/k8sClient.test.ts
+++ b/host-context-controller/src/k8sClient.test.ts
@@ -423,6 +423,79 @@ describe('MCP authorization store Kubernetes 404 normalization', () => {
expect(metadata).not.toHaveProperty('data')
expect(JSON.stringify(metadata)).not.toContain('credential-bytes-must-not-cross-this-boundary')
})
+
+ it('projects successful Host, Context, and McpServer authority reads from live Kubernetes objects', async () => {
+ const provider = {
+ getAllServerInfos: () => [
+ {
+ name: 'server-a',
+ status: { deployed: true, ready: true, authoritative: true },
+ },
+ ],
+ } as unknown as Parameters<typeof createMcpAuthorizationStore>[0]
+ const objects: Record<string, unknown> = {
+ 'hosts/host-a': {
+ metadata: {
+ name: 'host-a',
+ namespace: 'mcp-host',
+ uid: 'host-uid-a',
+ resourceVersion: '11',
+ },
+ spec: { contextRef: 'context-a' },
+ },
+ 'contexts/context-a': {
+ metadata: {
+ name: 'context-a',
+ namespace: 'mcp-server',
+ uid: 'context-uid-a',
+ resourceVersion: '12',
+ },
+ spec: { mcpServers: ['server-a'] },
+ },
+ 'mcpservers/server-a': {
+ metadata: {
+ name: 'server-a',
+ namespace: 'mcp-server',
+ uid: 'server-uid-a',
+ resourceVersion: '13',
+ },
+ spec: {
+ description: 'Server A',
+ transport: { type: 'streamableHttp', url: 'http://server-a/mcp', port: 8080 },
+ auth: { type: 'bearer', secretRef: 'server-a-auth', secretKey: 'token' },
+ enabled: true,
+ },
+ },
+ }
+ mocks.getNamespacedCustomObject.mockImplementation(
+ async ({ plural, name }: { plural: string; name: string }) => objects[`${plural}/${name}`]
+ )
+
+ const store = createMcpAuthorizationStore(provider)
+
+ await expect(store.readHost('host-a')).resolves.toEqual({
+ name: 'host-a',
+ namespace: 'mcp-host',
+ metadata: { uid: 'host-uid-a', resourceVersion: '11' },
+ contextRef: 'context-a',
+ })
+ await expect(store.readContext('context-a')).resolves.toEqual({
+ name: 'context-a',
+ namespace: 'mcp-server',
+ metadata: { uid: 'context-uid-a', resourceVersion: '12' },
+ mcpServers: ['server-a'],
+ })
+ await expect(store.readMcpServer('server-a')).resolves.toEqual({
+ name: 'server-a',
+ namespace: 'mcp-server',
+ metadata: { uid: 'server-uid-a', resourceVersion: '13' },
+ description: 'Server A',
+ transport: { type: 'streamableHttp', url: 'http://server-a/mcp', port: 8080 },
+ auth: { type: 'bearer', secretRef: 'server-a-auth', secretKey: 'token' },
+ enabled: true,
+ status: { deployed: true, ready: true, authoritative: true },
+ })
+ })
})
describe('McpServerWatcher startup', () => {
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index 51dfa9140..908000646 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.274",
+ "version": "0.1.275",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.274",
+ "version": "0.1.275",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@anthropic-ai/sdk": "^0.32.0",
diff --git a/mcp-host/package.json b/mcp-host/package.json
index af8f046f9..9e8a37131 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.274",
+ "version": "0.1.275",
"description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude",
"main": "dist/main.js",
"engines": {
diff --git a/mcp-host/src/__tests__/main.mcpInitialization.test.ts b/mcp-host/src/__tests__/main.mcpInitialization.test.ts
index 42e1255cb..c918ded98 100644
--- a/mcp-host/src/__tests__/main.mcpInitialization.test.ts
+++ b/mcp-host/src/__tests__/main.mcpInitialization.test.ts
@@ -1,7 +1,10 @@
import { describe, expect, it, vi } from 'vitest'
+import { config } from '../config'
+import { ContextMapperRequestError } from '../contextMapperClient'
import {
admitDevelopmentMcpServers,
createCoalescedPollRunner,
+ createMcpAuthorityPollFailureOptions,
createMcpAuthorityStalenessDeadline,
isMcpAuthorityStale,
startContextMapperPolling,
@@ -14,6 +17,7 @@ import {
replaceAuthoritativeMcpFleet,
runAuthoritativeMcpInitialization,
} from '../mcp/authoritativeFleet'
+import { handleMcpAuthorityPollFailure } from '../mcp/authorityLifecycle'
import { McpManager } from '../mcp/manager'
import type { McpServerInfo } from '../types'
@@ -525,6 +529,51 @@ describe('authoritative poll publication fence', () => {
})
describe('context-mapper polling lifecycle', () => {
+ it('wires the live manager and configured staleness ceiling into poll failure handling', () => {
+ const manager = {}
+ const revoke = vi.fn()
+ const onCallerAuthorizationRejected = vi.fn()
+ const onInventoryAuthorityRevoked = vi.fn()
+ const onUnavailable = vi.fn()
+ const options = createMcpAuthorityPollFailureOptions({
+ getManager: () => manager,
+ lastSuccessAt: () => 1_000,
+ now: () => 61_000,
+ revoke,
+ onCallerAuthorizationRejected,
+ onInventoryAuthorityRevoked,
+ onUnavailable,
+ })
+
+ expect(options.maxStalenessMs).toBe(config.hccAuthorityMaxStalenessMs)
+ const disposition = handleMcpAuthorityPollFailure(
+ new ContextMapperRequestError(503, 'inventory', false),
+ options
+ )
+
+ expect(disposition).toBe('authority_stale')
+ expect(revoke).toHaveBeenCalledWith('authority_stale', true)
+ expect(onUnavailable).toHaveBeenCalledTimes(1)
+ expect(onCallerAuthorizationRejected).not.toHaveBeenCalled()
+ expect(onInventoryAuthorityRevoked).not.toHaveBeenCalled()
+
+ const noManagerRevoke = vi.fn()
+ const noManagerDisposition = handleMcpAuthorityPollFailure(
+ new ContextMapperRequestError(503, 'inventory', false),
+ createMcpAuthorityPollFailureOptions({
+ getManager: () => null,
+ lastSuccessAt: () => 1_000,
+ now: () => 61_000,
+ revoke: noManagerRevoke,
+ onCallerAuthorizationRejected: vi.fn(),
+ onInventoryAuthorityRevoked: vi.fn(),
+ onUnavailable: vi.fn(),
+ })
+ )
+ expect(noManagerDisposition).toBe('unavailable')
+ expect(noManagerRevoke).not.toHaveBeenCalled()
+ })
+
it('keeps exactly one interval producer when polling is started again', () => {
vi.useFakeTimers()
try {
diff --git a/mcp-host/src/main.ts b/mcp-host/src/main.ts
index cbdb7a4d8..c549f166d 100644
--- a/mcp-host/src/main.ts
+++ b/mcp-host/src/main.ts
@@ -84,6 +84,7 @@ import {
isMcpAuthorityStale,
revokeMcpAuthorityState,
} from './mcp/authorityLifecycle'
+import type { HandleMcpAuthorityPollFailureOptions } from './mcp/authorityLifecycle'
import { McpStatusHeartbeat } from './mcp/statusHeartbeat'
import { startMcpInitializationInBackground } from './mcpBackgroundInit'
import { IncomingMessageHandler, PendingTaskEntry } from './messageHandler'
@@ -812,6 +813,36 @@ function ensureAuthenticatedContextMapperClient(): ContextMapperClient {
export { createMcpAuthorityStalenessDeadline, isMcpAuthorityStale }
+type McpAuthorityPollFailureCallbacks = Pick<
+ HandleMcpAuthorityPollFailureOptions,
+ 'revoke' | 'onCallerAuthorizationRejected' | 'onInventoryAuthorityRevoked' | 'onUnavailable'
+>
+
+/**
+ * Build the fail-closed polling options from the live main-process state.
+ * Keeping this adapter explicit gives the wiring a small, deterministic test
+ * seam instead of leaving the staleness/revocation callbacks as an untested
+ * inline object inside the timer callback.
+ */
+export function createMcpAuthorityPollFailureOptions(
+ dependencies: McpAuthorityPollFailureCallbacks & {
+ getManager: () => unknown | null
+ lastSuccessAt: () => number
+ now?: () => number
+ }
+): HandleMcpAuthorityPollFailureOptions {
+ return {
+ hasPublishedManager: () => dependencies.getManager() !== null,
+ lastSuccessAt: dependencies.lastSuccessAt,
+ now: dependencies.now ?? Date.now,
+ maxStalenessMs: config.hccAuthorityMaxStalenessMs,
+ revoke: dependencies.revoke,
+ onCallerAuthorizationRejected: dependencies.onCallerAuthorizationRejected,
+ onInventoryAuthorityRevoked: dependencies.onInventoryAuthorityRevoked,
+ onUnavailable: dependencies.onUnavailable,
+ }
+}
+
const mcpAuthorityStalenessDeadline = createMcpAuthorityStalenessDeadline(
config.hccAuthorityMaxStalenessMs,
() => {
@@ -959,18 +990,19 @@ async function pollContextMapper(): Promise<void> {
recordMcpAuthoritySuccess()
}
} catch (error) {
- handleMcpAuthorityPollFailure(error, {
- hasPublishedManager: () => mcpManager !== null,
- lastSuccessAt: () => mcpAuthorityLastSuccessAt,
- now: Date.now,
- maxStalenessMs: config.hccAuthorityMaxStalenessMs,
- revoke: revokeMcpAuthority,
- onCallerAuthorizationRejected: () =>
- console.warn('[Main] HCC poll rejected caller authority'),
- onInventoryAuthorityRevoked: () =>
- console.warn('[Main] HCC inventory no longer resolves live Host authority'),
- onUnavailable: () => console.error('[Main] HCC authority poll failed (reason=unavailable)'),
- })
+ handleMcpAuthorityPollFailure(
+ error,
+ createMcpAuthorityPollFailureOptions({
+ getManager: () => mcpManager,
+ lastSuccessAt: () => mcpAuthorityLastSuccessAt,
+ revoke: revokeMcpAuthority,
+ onCallerAuthorizationRejected: () =>
+ console.warn('[Main] HCC poll rejected caller authority'),
+ onInventoryAuthorityRevoked: () =>
+ console.warn('[Main] HCC inventory no longer resolves live Host authority'),
+ onUnavailable: () => console.error('[Main] HCC authority poll failed (reason=unavailable)'),
+ })
+ )
}
}