Skip to content

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

TypeScript

test(np-08): align fixtures after origin dev sync

Alfredo Lopez1772fd704124
diff --git a/host-context-controller/src/k8sClient.test.ts b/host-context-controller/src/k8sClient.test.ts
index c96d63ccd..472b15d00 100644
--- a/host-context-controller/src/k8sClient.test.ts
+++ b/host-context-controller/src/k8sClient.test.ts
@@ -225,9 +225,22 @@ describe('MCP authorization store Kubernetes 404 normalization', () => {
getAllServerInfos: () => [],
} as unknown as Parameters<typeof createMcpAuthorizationStore>[0]
- beforeEach(() => {
- mocks.getNamespacedCustomObject.mockReset()
+ const restoreDefaultReadMocks = () => {
+ mocks.getNamespacedCustomObject
+ .mockReset()
+ .mockRejectedValue(Object.assign(new Error('not found'), { code: 404 }))
mocks.readNamespacedSecret.mockReset()
+ }
+
+ beforeEach(() => {
+ restoreDefaultReadMocks()
+ })
+
+ afterEach(() => {
+ // These tests intentionally reset the shared Kubernetes read mocks. Restore
+ // the normal 404 default so later watcher tests still model an absent
+ // object instead of an accidentally resolved undefined response.
+ restoreDefaultReadMocks()
})
it('treats ApiException.code=404 as absent for every CR authority read', async () => {
diff --git a/host-context-controller/src/server.test.ts b/host-context-controller/src/server.test.ts
index d8227f713..87506e4f9 100644
--- a/host-context-controller/src/server.test.ts
+++ b/host-context-controller/src/server.test.ts
@@ -11,6 +11,7 @@ import {
McpAuthorizationService,
type McpAuthorizationStore,
} from './mcpAuthorization'
+import { resolveHostAuthoritativeFn, resolveProviderAuthoritativeFn } from './readinessGate'
import { ContextMapperServer, McpHostApiRateLimiter } from './server'
import type { McpServerInfo } from './types'
@@ -207,7 +208,10 @@ describe('ContextMapperServer', () => {
status: { deployed: true, ready: true, message: 'internal status detail' },
},
]),
- 0
+ 0,
+ undefined,
+ undefined,
+ () => true
)
server.setReady(true)
@@ -235,7 +239,7 @@ describe('ContextMapperServer', () => {
)
it('tombstones legacy Host-selected routes for every method before readiness and CORS', async () => {
- server = new ContextMapperServer(new FakeProvider(), 0)
+ server = new ContextMapperServer(new FakeProvider(), 0, undefined, undefined, () => true)
for (const [path, method] of [
['/api/v1/mcpservers/context/context-a', 'OPTIONS'],
@@ -267,7 +271,7 @@ describe('ContextMapperServer', () => {
})
it('keeps direct protected-route startup and not-found errors generic and non-cacheable', async () => {
- server = new ContextMapperServer(new FakeProvider(), 0)
+ server = new ContextMapperServer(new FakeProvider(), 0, undefined, undefined, () => true)
let response = await invoke(server, '/api/v2/hosts/self/mcpservers')
expect(response.statusCode).toBe(503)
@@ -370,6 +374,14 @@ describe('ContextMapperServer', () => {
})
describe('McpHostApiRateLimiter', () => {
+ let server: ContextMapperServer | null = null
+
+ afterEach(async () => {
+ await server?.stop()
+ server = null
+ vi.restoreAllMocks()
+ })
+
it('limits each signed Host identity/action independently and resets after one minute', () => {
let now = 1_000
const limiter = new McpHostApiRateLimiter(1, () => now)
diff --git a/host-context-controller/test/__fixtures__/testMocks.ts b/host-context-controller/test/__fixtures__/testMocks.ts
index 73a8bae2c..39ed5a5b9 100644
--- a/host-context-controller/test/__fixtures__/testMocks.ts
+++ b/host-context-controller/test/__fixtures__/testMocks.ts
@@ -201,15 +201,23 @@ export function createMockCustomApi(): MockCustomApi {
patchNamespacedCustomObject: vi.fn().mockResolvedValue({}),
patchNamespacedCustomObjectStatus: vi.fn().mockResolvedValue({}),
createNamespacedCustomObject: vi.fn().mockResolvedValue({}),
- getNamespacedCustomObject: vi.fn().mockResolvedValue({
- metadata: { name: 'stateless-host', namespace: 'mcp-host' },
- spec: {
- host: 'stateless-host',
- contextRef: 'context-a',
- secretRef: 'host-secret',
- lifecycle: { stateless: true },
- },
- status: { lifecycle: { state: 'suspended', wakeHandledGeneration: 0 } },
+ getNamespacedCustomObject: vi.fn(({ name }: { name?: string } = {}) => {
+ const hostName = name ?? 'stateless-host'
+ return Promise.resolve({
+ metadata: {
+ name: hostName,
+ namespace: 'mcp-host',
+ uid: `${hostName}-uid`,
+ resourceVersion: '42',
+ },
+ spec: {
+ host: hostName,
+ contextRef: 'context-a',
+ secretRef: 'host-secret',
+ lifecycle: { stateless: true },
+ },
+ status: { lifecycle: { state: 'suspended', wakeHandledGeneration: 0 } },
+ })
}),
getNamespacedCustomObjectStatus: vi.fn().mockResolvedValue({ status: { conditions: [] } }),
replaceNamespacedCustomObject: vi.fn().mockResolvedValue({}),
diff --git a/host-context-controller/test/hostReconciler.heartbeat.test.ts b/host-context-controller/test/hostReconciler.heartbeat.test.ts
index 4e6593024..c06ffe296 100644
--- a/host-context-controller/test/hostReconciler.heartbeat.test.ts
+++ b/host-context-controller/test/hostReconciler.heartbeat.test.ts
@@ -119,6 +119,16 @@ function createReconciler() {
const networkingApi = createMockNetworkingApi()
const rbacApi = createMockRbacApi()
const customApi = createMockCustomApi()
+ customApi.getNamespacedCustomObject.mockResolvedValue({
+ metadata: { name: 'stateless-host', namespace: 'mcp-host' },
+ spec: {
+ host: 'stateless-host',
+ contextRef: 'context-a',
+ secretRef: 'host-secret',
+ lifecycle: { stateless: true },
+ },
+ status: { lifecycle: { state: 'suspended', wakeHandledGeneration: 0 } },
+ })
const reconciler = new HostReconciler({} as k8s.KubeConfig, {
appsApi: asAppsApi(appsApi),
diff --git a/host-context-controller/test/hostReconciler.lifecycle.test.ts b/host-context-controller/test/hostReconciler.lifecycle.test.ts
index e47108673..7a799010f 100644
--- a/host-context-controller/test/hostReconciler.lifecycle.test.ts
+++ b/host-context-controller/test/hostReconciler.lifecycle.test.ts
@@ -633,7 +633,7 @@ describe('HostReconciler ensureDeployment — idempotent replacement', () => {
const stateless = makeStatelessHost({ name: 'transition-host' })
customApi.getNamespacedCustomObject.mockResolvedValue({
- metadata: { name: stateless.name, namespace: stateless.namespace },
+ metadata: { name: stateless.name, namespace: stateless.namespace, uid: stateless.uid },
spec: stateless.spec,
status: { lifecycle: { state: 'active', wakeHandledGeneration: 0 } },
})
@@ -667,7 +667,7 @@ describe('HostReconciler stateless lifecycle — env injection', () => {
const { reconciler, appsApi, customApi } = createReconciler()
const stateless = makeStatelessHost({ name: 'new-stateless-host' })
customApi.getNamespacedCustomObject.mockResolvedValue({
- metadata: { name: stateless.name, namespace: stateless.namespace },
+ metadata: { name: stateless.name, namespace: stateless.namespace, uid: stateless.uid },
spec: stateless.spec,
status: { lifecycle: { state: 'active', wakeHandledGeneration: 0 } },
})
@@ -1336,7 +1336,12 @@ describe('HostReconciler stateless lifecycle — rejection matrix', () => {
status: { lifecycle: { state: 'active', wakeHandledGeneration: 0 } },
})
customApi.getNamespacedCustomObject.mockResolvedValue({
- metadata: { name: host.name, namespace: host.namespace },
+ metadata: {
+ name: host.name,
+ namespace: host.namespace,
+ uid: host.uid,
+ resourceVersion: '42',
+ },
spec: host.spec,
status: host.status,
})
@@ -1422,7 +1427,18 @@ describe('HostReconciler stateless lifecycle — kill-switches', () => {
it('kill-switch: removing spec.lifecycle returns a suspended host to active', async () => {
const { reconciler, appsApi, customApi } = createReconciler()
- await reconciler.reconcile(makeHost({ name: 'stateless-host', status: suspendedStatus(2) }))
+ const host = makeHost({ name: 'stateless-host', status: suspendedStatus(2) })
+ customApi.getNamespacedCustomObject.mockResolvedValue({
+ metadata: {
+ name: host.name,
+ namespace: host.namespace,
+ uid: host.uid,
+ resourceVersion: '42',
+ },
+ spec: host.spec,
+ status: host.status,
+ })
+ await reconciler.reconcile(host)
expect(hostDeploymentBody(appsApi, 'stateless-host').spec?.replicas).toBe(1)
const writes = lifecycleStatusWrites(customApi)
@@ -1475,7 +1491,7 @@ describe('HostReconciler stateless lifecycle — status write idempotence', () =
// FIX 1 replicas guard: state the server-side truth explicitly — the
// fresh read must agree with the observed (converged) active status.
customApi.getNamespacedCustomObject.mockResolvedValue({
- metadata: { name: 'stateless-host', namespace: 'mcp-host' },
+ metadata: { name: 'stateless-host', namespace: 'mcp-host', uid: 'stateless-host-uid' },
spec: {
host: 'stateless-host',
contextRef: 'context-a',
@@ -1521,7 +1537,12 @@ describe('HostReconciler stateless lifecycle — AP-1 fresh-read status writer',
reason?: string
}) {
return {
- metadata: { name: 'stateless-host', namespace: 'mcp-host', resourceVersion: '42' },
+ metadata: {
+ name: 'stateless-host',
+ namespace: 'mcp-host',
+ uid: 'stateless-host-uid',
+ resourceVersion: '42',
+ },
spec: {
host: 'stateless-host',
contextRef: 'context-a',
diff --git a/host-context-controller/test/hostReconciler.wake.test.ts b/host-context-controller/test/hostReconciler.wake.test.ts
index 91306b462..4fc7ae2aa 100644
--- a/host-context-controller/test/hostReconciler.wake.test.ts
+++ b/host-context-controller/test/hostReconciler.wake.test.ts
@@ -165,6 +165,16 @@ function createReconciler() {
const networkingApi = createMockNetworkingApi()
const rbacApi = createMockRbacApi()
const customApi = createMockCustomApi()
+ customApi.getNamespacedCustomObject.mockResolvedValue({
+ metadata: { name: 'stateless-host', namespace: 'mcp-host' },
+ spec: {
+ host: 'stateless-host',
+ contextRef: 'context-a',
+ secretRef: 'host-secret',
+ lifecycle: { stateless: true },
+ },
+ status: { lifecycle: { state: 'suspended', wakeHandledGeneration: 0 }, conditions: [] },
+ })
const reconciler = new HostReconciler({} as k8s.KubeConfig, {
appsApi: asAppsApi(appsApi),