Skip to content

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

TypeScript

test(hcc): close remaining Deployment no-op review gaps

Alfredo Lopez718b4bd36375
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index 317dddde4..66687218b 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.280",
+ "version": "0.1.281",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.280",
+ "version": "0.1.281",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@clerum/codex-catalog-projection": "file:../packages/codex-catalog-projection",
diff --git a/host-context-controller/package.json b/host-context-controller/package.json
index 193b0b3fe..cfd6aa0bb 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.280",
+ "version": "0.1.281",
"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/__tests__/asApiserverDeployment.ts b/host-context-controller/src/__tests__/asApiserverDeployment.ts
index 865a4b3c8..5a2f97d01 100644
--- a/host-context-controller/src/__tests__/asApiserverDeployment.ts
+++ b/host-context-controller/src/__tests__/asApiserverDeployment.ts
@@ -1,34 +1,27 @@
import type * as k8s from '@kubernetes/client-node'
/**
- * Apply documented apps/v1 defaulting onto a desired Deployment. Unlike
- * `asApiserverService`, this is not a recorded-blob overlay: it fills fields
- * the apiserver would default-fill, leaving every HCC-authored value intact.
- * Container `imagePullPolicy` follows kube `DefaultImagePullPolicy` (Always
- * for `:latest` / untagged; IfNotPresent otherwise). Refresh this function
- * when a live `kubectl get deploy -o json` reveals a default the fixture
- * does not model (PR G §8).
+ * Recorded kube-apiserver GET of an apps/v1 Deployment (`kubectl get deploy
+ * -o json` shape), not a field list copied from
+ * `normalizeDeploymentForComparison`. Stamp controller-owned identity and
+ * PodSpec via `asApiserverDeployment`. When a newer apiserver default-fills
+ * a field, refresh this blob so the suite goes red until the comparator or
+ * builder learns that default (PR G §8).
+ *
+ * Container `imagePullPolicy` is filled after overlay from kube
+ * `DefaultImagePullPolicy` (Always for `:latest` / untagged; IfNotPresent
+ * otherwise) because recorded containers are replaced by the desired list.
*/
const SERVER_TIME = new Date('2026-04-01T00:00:00.000Z')
const SERVER_UID = '11111111-2222-3333-4444-555555555555'
const SERVER_RESOURCE_VERSION = '1776125'
-export function asApiserverDeployment(desired: k8s.V1Deployment): k8s.V1Deployment {
- const live = structuredClone(desired)
- applyServerOwnedMetadata(live)
- applyDeploymentSpecDefaults(live.spec)
- return live
-}
-
-function applyServerOwnedMetadata(deployment: k8s.V1Deployment): void {
- const name = deployment.metadata?.name ?? 'unnamed'
- const namespace = deployment.metadata?.namespace ?? 'default'
- deployment.metadata = {
- ...deployment.metadata,
+export const RECORDED_APPSV1_DEPLOYMENT: k8s.V1Deployment = {
+ apiVersion: 'apps/v1',
+ kind: 'Deployment',
+ metadata: {
annotations: {
- ...deployment.metadata?.annotations,
- 'deployment.kubernetes.io/revision':
- deployment.metadata?.annotations?.['deployment.kubernetes.io/revision'] ?? '1',
+ 'deployment.kubernetes.io/revision': '1',
},
creationTimestamp: SERVER_TIME,
generation: 1,
@@ -42,18 +35,102 @@ function applyServerOwnedMetadata(deployment: k8s.V1Deployment): void {
time: SERVER_TIME,
},
],
+ name: 'recorded-deploy',
+ namespace: 'recorded-ns',
resourceVersion: SERVER_RESOURCE_VERSION,
uid: SERVER_UID,
- selfLink: `/apis/apps/v1/namespaces/${namespace}/deployments/${name}`,
- }
- deployment.status = {
+ selfLink: '/apis/apps/v1/namespaces/recorded-ns/deployments/recorded-deploy',
+ },
+ spec: {
+ replicas: 1,
+ progressDeadlineSeconds: 600,
+ revisionHistoryLimit: 10,
+ minReadySeconds: 0,
+ paused: false,
+ selector: { matchLabels: { app: 'recorded' } },
+ strategy: {
+ type: 'RollingUpdate',
+ rollingUpdate: { maxSurge: '25%', maxUnavailable: '25%' },
+ },
+ template: {
+ metadata: {
+ creationTimestamp: SERVER_TIME,
+ labels: { app: 'recorded' },
+ },
+ spec: {
+ restartPolicy: 'Always',
+ dnsPolicy: 'ClusterFirst',
+ schedulerName: 'default-scheduler',
+ terminationGracePeriodSeconds: 30,
+ enableServiceLinks: true,
+ preemptionPolicy: 'PreemptLowerPriority',
+ serviceAccountName: 'default',
+ containers: [
+ {
+ name: 'recorded',
+ image: 'recorded:1',
+ imagePullPolicy: 'IfNotPresent',
+ terminationMessagePath: '/dev/termination-log',
+ terminationMessagePolicy: 'File',
+ },
+ ],
+ },
+ },
+ },
+ status: {
observedGeneration: 1,
- replicas: deployment.spec?.replicas ?? 1,
+ replicas: 1,
readyReplicas: 0,
updatedReplicas: 0,
- unavailableReplicas: deployment.spec?.replicas ?? 1,
+ unavailableReplicas: 1,
conditions: [],
+ },
+}
+
+export function asApiserverDeployment(desired: k8s.V1Deployment): k8s.V1Deployment {
+ const live = overlayDefined(
+ structuredClone(RECORDED_APPSV1_DEPLOYMENT),
+ desired
+ ) as k8s.V1Deployment
+ const name = desired.metadata?.name ?? live.metadata?.name ?? 'unnamed'
+ const namespace = desired.metadata?.namespace ?? live.metadata?.namespace ?? 'default'
+ live.metadata = {
+ ...live.metadata,
+ selfLink: `/apis/apps/v1/namespaces/${namespace}/deployments/${name}`,
+ }
+ const replicas = live.spec?.replicas ?? 1
+ live.status = {
+ ...RECORDED_APPSV1_DEPLOYMENT.status,
+ replicas,
+ unavailableReplicas: replicas,
+ }
+ applyDeploymentSpecDefaults(live.spec)
+ return live
+}
+
+const REPLACE_OBJECT_KEYS = new Set([
+ 'selector',
+ 'labels',
+ 'matchLabels',
+ 'matchExpressions',
+ 'strategy',
+])
+
+/** Defined overlay keys win; omitted keys keep the recorded apiserver default. */
+function overlayDefined(base: unknown, overlay: unknown): unknown {
+ if (overlay === undefined) return base
+ if (overlay === null || typeof overlay !== 'object' || Array.isArray(overlay)) return overlay
+ if (base === null || typeof base !== 'object' || Array.isArray(base)) return overlay
+ const out: Record<string, unknown> = { ...(base as Record<string, unknown>) }
+ for (const [key, value] of Object.entries(overlay as Record<string, unknown>)) {
+ if (value === undefined) continue
+ if (REPLACE_OBJECT_KEYS.has(key) && typeof value === 'object' && !Array.isArray(value)) {
+ out[key] = value
+ continue
+ }
+ out[key] = overlayDefined((base as Record<string, unknown>)[key], value)
}
+ return out
}
function applyDeploymentSpecDefaults(spec: k8s.V1Deployment['spec']): void {
@@ -89,7 +166,7 @@ function applyPodSpecDefaults(podSpec: k8s.V1PodSpec | undefined): void {
if (podSpec.enableServiceLinks === undefined) podSpec.enableServiceLinks = true
if (podSpec.preemptionPolicy === undefined) podSpec.preemptionPolicy = 'PreemptLowerPriority'
if (!podSpec.serviceAccountName) podSpec.serviceAccountName = 'default'
- if (podSpec.serviceAccount === undefined) podSpec.serviceAccount = podSpec.serviceAccountName
+ podSpec.serviceAccount = podSpec.serviceAccountName
for (const container of [...(podSpec.initContainers ?? []), ...(podSpec.containers ?? [])]) {
applyContainerDefaults(container)
diff --git a/host-context-controller/src/__tests__/deploymentMatchesDesired.test.ts b/host-context-controller/src/__tests__/deploymentMatchesDesired.test.ts
index e5e0bbe46..93ac6cff3 100644
--- a/host-context-controller/src/__tests__/deploymentMatchesDesired.test.ts
+++ b/host-context-controller/src/__tests__/deploymentMatchesDesired.test.ts
@@ -18,7 +18,12 @@ import {
preserveDeploymentAnnotations,
} from '../utils'
import { asApiserverDeployment } from './asApiserverDeployment'
-import { cloneAndMutateLeaf, collectLeafPaths, formatLeafPath } from './mutateJsonLeaves'
+import {
+ cloneAndMutateLeaf,
+ collectLeafPaths,
+ collectLiveOnlySpecLeaves,
+ formatLeafPath,
+} from './mutateJsonLeaves'
vi.mock('../config', () => ({
config: {
@@ -118,6 +123,24 @@ function expectSweepDetectsEveryLeaf(desired: k8s.V1Deployment, existing: k8s.V1
expect(undetectable, `undetectable leaf path(s): ${undetectable.join(', ')}`).toEqual([])
}
+function expectSweepDetectsLiveOnlySpecLeaves(
+ desired: k8s.V1Deployment,
+ existing: k8s.V1Deployment
+): void {
+ const liveOnly = collectLiveOnlySpecLeaves(desired, existing)
+ expect(liveOnly.length, 'fixture added no spec-only leaves').toBeGreaterThan(0)
+ const undetectable: string[] = []
+ for (const path of liveOnly) {
+ const mutatedExisting = cloneAndMutateLeaf(existing, path) as k8s.V1Deployment
+ if (deploymentMatchesDesired(mergedForCompare(desired, mutatedExisting), mutatedExisting)) {
+ undetectable.push(formatLeafPath(path))
+ }
+ }
+ expect(undetectable, `undetectable live-only spec path(s): ${undetectable.join(', ')}`).toEqual(
+ []
+ )
+}
+
describe('asApiserverDeployment', () => {
it('FIXTURE-1: default-fills a sparse Deployment so it differs structurally', () => {
const desired = sparseDeployment()
@@ -137,6 +160,15 @@ describe('asApiserverDeployment', () => {
expect(asApiserverDeployment(desired)).not.toEqual(desired)
})
+ it('FIXTURE-1: omitted Deployment spec fields come from the recorded blob', () => {
+ const desired = sparseDeployment()
+ const existing = asApiserverDeployment(desired)
+ expect(existing.spec?.progressDeadlineSeconds).toBe(600)
+ expect(existing.spec?.revisionHistoryLimit).toBe(10)
+ expect(existing.spec?.template?.spec?.dnsPolicy).toBe('ClusterFirst')
+ expect(existing.spec?.template?.spec?.restartPolicy).toBe('Always')
+ })
+
it('FIXTURE-1: fills omitted imagePullPolicy the way apps/v1 defaults it', () => {
const containerOf = (desired: k8s.V1Deployment) =>
asApiserverDeployment(desired).spec?.template?.spec?.containers?.[0]
@@ -282,6 +314,11 @@ describe('deploymentMatchesDesired', () => {
expectSweepDetectsEveryLeaf(desired, asApiserverDeployment(desired))
})
+ it('Host mutation sweep: every live-only spec leaf is detectable', () => {
+ const desired = createReconciler().buildDeployment(makeHost())
+ expectSweepDetectsLiveOnlySpecLeaves(desired, asApiserverDeployment(desired))
+ })
+
it('channel-reader mutation sweep: every desired leaf is detectable', () => {
const desired = (createReconciler() as any).buildChannelReaderDeployment(
makeHost(),
@@ -289,4 +326,12 @@ describe('deploymentMatchesDesired', () => {
) as k8s.V1Deployment
expectSweepDetectsEveryLeaf(desired, asApiserverDeployment(desired))
})
+
+ it('channel-reader mutation sweep: every live-only spec leaf is detectable', () => {
+ const desired = (createReconciler() as any).buildChannelReaderDeployment(
+ makeHost(),
+ 'rev-abc'
+ ) as k8s.V1Deployment
+ expectSweepDetectsLiveOnlySpecLeaves(desired, asApiserverDeployment(desired))
+ })
})
diff --git a/host-context-controller/src/__tests__/deploymentWriterInventory.test.ts b/host-context-controller/src/__tests__/deploymentWriterInventory.test.ts
index cf9042e23..ec1e2db33 100644
--- a/host-context-controller/src/__tests__/deploymentWriterInventory.test.ts
+++ b/host-context-controller/src/__tests__/deploymentWriterInventory.test.ts
@@ -13,7 +13,8 @@ const GATED = new Set([
const EXEMPT = new Set(['k8s/gfsK8sApi.ts', 'statelessLifecycleExecutor.ts'])
-const CALL = /replaceNamespacedDeployment\s*\(\s*\{/g
+/** Any call, including `replace(params)` — not only inline `({ ... })`. */
+const CALL = /replaceNamespacedDeployment\s*\(/g
function productionTsFiles(dir: string): string[] {
const out: string[] = []
@@ -29,39 +30,93 @@ function productionTsFiles(dir: string): string[] {
return out
}
+function isCommentLine(line: string): boolean {
+ const trimmed = line.trim()
+ return trimmed.startsWith('//') || trimmed.startsWith('*') || trimmed.startsWith('/*')
+}
+
+function lineAt(source: string, index: number): string {
+ const start = source.lastIndexOf('\n', index - 1) + 1
+ const end = source.indexOf('\n', index)
+ return source.slice(start, end === -1 ? source.length : end)
+}
+
+function callSiteIndexes(source: string): number[] {
+ const indexes: number[] = []
+ for (const match of source.matchAll(CALL)) {
+ if (match.index === undefined) continue
+ if (isCommentLine(lineAt(source, match.index))) continue
+ indexes.push(match.index)
+ }
+ return indexes
+}
+
+function enclosingReplaceRetryBlock(source: string, callIndex: number): string | null {
+ let searchFrom = 0
+ let lastStart = -1
+ while (true) {
+ const idx = source.indexOf('replaceWithConflictRetry', searchFrom)
+ if (idx === -1 || idx > callIndex) break
+ lastStart = idx
+ searchFrom = idx + 1
+ }
+ if (lastStart === -1) return null
+ const paren = source.indexOf('(', lastStart)
+ if (paren === -1 || paren > callIndex) return null
+ let depth = 0
+ for (let i = paren; i < source.length; i++) {
+ if (source[i] === '(') depth += 1
+ else if (source[i] === ')') {
+ depth -= 1
+ if (depth === 0) {
+ if (i < callIndex) return null
+ return source.slice(lastStart, i + 1)
+ }
+ }
+ }
+ return null
+}
+
+function isDeploymentGated(block: string): boolean {
+ return /isUpToDate:/.test(block) && /deploymentMatchesDesired/.test(block)
+}
+
describe('Deployment writer inventory', () => {
it('every replaceNamespacedDeployment call is gated or explicitly exempt', () => {
const hits: Array<{ rel: string; count: number; gated: boolean }> = []
for (const file of productionTsFiles(SRC_ROOT)) {
const rel = relative(SRC_ROOT, file).replaceAll('\\', '/')
const source = readFileSync(file, 'utf8')
- const count = source.match(CALL)?.length ?? 0
- if (count === 0) continue
+ const sites = callSiteIndexes(source)
+ if (sites.length === 0) continue
const isGated = GATED.has(rel)
const isExempt = EXEMPT.has(rel)
expect(
isGated || isExempt,
- `${rel} calls replaceNamespacedDeployment ${count} time(s) but is on neither the gated nor the exempt list`
+ `${rel} calls replaceNamespacedDeployment ${sites.length} time(s) but is on neither the gated nor the exempt list`
).toBe(true)
- if (isGated) {
- expect(
- source.includes('deploymentMatchesDesired'),
- `${rel} is gated but does not reference deploymentMatchesDesired`
- ).toBe(true)
- const directGates = source.match(/isUpToDate:\s*deploymentMatchesDesired\b/g)?.length ?? 0
- const wrapperGates = source.match(/return deploymentMatchesDesired\s*\(/g)?.length ?? 0
- expect(
- directGates + wrapperGates,
- `${rel} has ${count} Deployment replace(s) but ${directGates + wrapperGates} isUpToDate gate(s)`
- ).toBe(count)
- }
- if (isExempt) {
- expect(
- source.includes('isUpToDate: deploymentMatchesDesired'),
- `${rel} is exempt and must not wire the Deployment no-op gate`
- ).toBe(false)
+
+ for (const index of sites) {
+ const block = enclosingReplaceRetryBlock(source, index)
+ if (isGated) {
+ expect(
+ block,
+ `${rel} call at index ${index} is not inside replaceWithConflictRetry`
+ ).not.toBeNull()
+ expect(
+ isDeploymentGated(block ?? ''),
+ `${rel} call at index ${index} is missing an isUpToDate deploymentMatchesDesired gate`
+ ).toBe(true)
+ }
+ if (isExempt) {
+ expect(
+ block !== null && isDeploymentGated(block),
+ `${rel} is exempt and must not wire the Deployment no-op gate`
+ ).toBe(false)
+ }
}
- hits.push({ rel, count, gated: isGated })
+
+ hits.push({ rel, count: sites.length, gated: isGated })
}
expect(hits.map(h => h.rel).sort()).toEqual([...GATED, ...EXEMPT].sort())
diff --git a/host-context-controller/src/__tests__/llmHookDeploymentNoopGate.test.ts b/host-context-controller/src/__tests__/llmHookDeploymentNoopGate.test.ts
index 1f5046d40..fcd66cc43 100644
--- a/host-context-controller/src/__tests__/llmHookDeploymentNoopGate.test.ts
+++ b/host-context-controller/src/__tests__/llmHookDeploymentNoopGate.test.ts
@@ -16,7 +16,13 @@ import { LlmHookReconciler, computePodKey } from '../llmHookReconciler'
import type { HostCRD, LlmHookCRD } from '../types'
import { deploymentMatchesDesired, preserveDeploymentAnnotations } from '../utils'
import { asApiserverDeployment } from './asApiserverDeployment'
-import { cloneAndMutateLeaf, collectLeafPaths, formatLeafPath } from './mutateJsonLeaves'
+import {
+ cloneAndMutateLeaf,
+ collectLeafPaths,
+ collectLiveOnlySpecLeaves,
+ formatLeafPath,
+ undetectableLiveOnlySpecLeaves,
+} from './mutateJsonLeaves'
vi.mock('../config', () => ({
config: {
@@ -111,6 +117,24 @@ describe('LlmHook ensureDeployment no-op gate', () => {
expect(undetectable, `undetectable leaf path(s): ${undetectable.join(', ')}`).toEqual([])
})
+ it('LlmHook mutation sweep: every live-only spec leaf is detectable', () => {
+ const desired = (reconciler as any).buildDeployment(
+ podKey,
+ members,
+ 'rev-1'
+ ) as k8s.V1Deployment
+ const existing = asApiserverDeployment(desired)
+ expect(collectLiveOnlySpecLeaves(desired, existing).length).toBeGreaterThan(0)
+ expect(
+ undetectableLiveOnlySpecLeaves(desired, existing, mutated =>
+ deploymentMatchesDesired(
+ mergedForCompare(desired, mutated as k8s.V1Deployment),
+ mutated as k8s.V1Deployment
+ )
+ )
+ ).toEqual([])
+ })
+
it('NOOP-LLMDEP-1: equivalent Deployment skips replace and Updated logs', async () => {
const desired = (reconciler as any).buildDeployment(
podKey,
diff --git a/host-context-controller/src/__tests__/mcpServerDeploymentNoopGate.test.ts b/host-context-controller/src/__tests__/mcpServerDeploymentNoopGate.test.ts
index 277b22b9e..19820ab5d 100644
--- a/host-context-controller/src/__tests__/mcpServerDeploymentNoopGate.test.ts
+++ b/host-context-controller/src/__tests__/mcpServerDeploymentNoopGate.test.ts
@@ -14,7 +14,13 @@ import { McpServerReconciler } from '../reconciler'
import type { McpServerCRD } from '../types'
import { deploymentMatchesDesired, preserveDeploymentAnnotations } from '../utils'
import { asApiserverDeployment } from './asApiserverDeployment'
-import { cloneAndMutateLeaf, collectLeafPaths, formatLeafPath } from './mutateJsonLeaves'
+import {
+ cloneAndMutateLeaf,
+ collectLeafPaths,
+ collectLiveOnlySpecLeaves,
+ formatLeafPath,
+ undetectableLiveOnlySpecLeaves,
+} from './mutateJsonLeaves'
vi.mock('../config', () => ({
config: {
@@ -118,6 +124,20 @@ describe('McpServer ensureDeployment no-op gate', () => {
expect(undetectable, `undetectable leaf path(s): ${undetectable.join(', ')}`).toEqual([])
})
+ it('McpServer mutation sweep: every live-only spec leaf is detectable', () => {
+ const desired = (reconciler as any).buildDeployment(server, 'rev-1') as k8s.V1Deployment
+ const existing = asApiserverDeployment(desired)
+ expect(collectLiveOnlySpecLeaves(desired, existing).length).toBeGreaterThan(0)
+ expect(
+ undetectableLiveOnlySpecLeaves(desired, existing, mutated =>
+ deploymentMatchesDesired(
+ mergedForCompare(desired, mutated as k8s.V1Deployment),
+ mutated as k8s.V1Deployment
+ )
+ )
+ ).toEqual([])
+ })
+
it('NOOP-MCPDEP-1: equivalent Deployment skips replace and Updated logs', async () => {
const desired = (reconciler as any).buildDeployment(server, 'rev-1') as k8s.V1Deployment
appsApi.readNamespacedDeployment.mockResolvedValue(asApiserverDeployment(desired))
@@ -221,6 +241,20 @@ describe('McpServer stdio ensureDeployment no-op gate', () => {
expect(undetectable, `undetectable leaf path(s): ${undetectable.join(', ')}`).toEqual([])
})
+ it('McpServer stdio mutation sweep: every live-only spec leaf is detectable', () => {
+ const desired = (reconciler as any).buildDeployment(server, 'rev-1') as k8s.V1Deployment
+ const existing = asApiserverDeployment(desired)
+ expect(collectLiveOnlySpecLeaves(desired, existing).length).toBeGreaterThan(0)
+ expect(
+ undetectableLiveOnlySpecLeaves(desired, existing, mutated =>
+ deploymentMatchesDesired(
+ mergedForCompare(desired, mutated as k8s.V1Deployment),
+ mutated as k8s.V1Deployment
+ )
+ )
+ ).toEqual([])
+ })
+
it('NOOP-MCPDEP-STDIO-1: equivalent stdio Deployment skips replace and Updated logs', async () => {
const desired = (reconciler as any).buildDeployment(server, 'rev-1') as k8s.V1Deployment
appsApi.readNamespacedDeployment.mockResolvedValue(asApiserverDeployment(desired))
diff --git a/host-context-controller/src/__tests__/mutateJsonLeaves.ts b/host-context-controller/src/__tests__/mutateJsonLeaves.ts
index 7e23f1359..07f8410ae 100644
--- a/host-context-controller/src/__tests__/mutateJsonLeaves.ts
+++ b/host-context-controller/src/__tests__/mutateJsonLeaves.ts
@@ -51,3 +51,25 @@ export function cloneAndMutateLeaf(root: unknown, path: string[]): unknown {
export function formatLeafPath(path: string[]): string {
return path.length === 0 ? '(root)' : path.join('.')
}
+
+/**
+ * Spec leaves the apiserver/fixture added that `desired` omitted.
+ * `creationTimestamp` is stripped unconditionally by the comparator.
+ */
+export function collectLiveOnlySpecLeaves(desired: unknown, existing: unknown): string[][] {
+ return collectLeafPaths(existing).filter(path => {
+ if (path[0] !== 'spec') return false
+ if (path.includes('creationTimestamp')) return false
+ return getAtPath(desired, path) === undefined
+ })
+}
+
+export function undetectableLiveOnlySpecLeaves(
+ desired: unknown,
+ existing: unknown,
+ isStillNoOp: (mutatedExisting: unknown) => boolean
+): string[] {
+ return collectLiveOnlySpecLeaves(desired, existing)
+ .filter(path => isStillNoOp(cloneAndMutateLeaf(existing, path)))
+ .map(formatLeafPath)
+}
diff --git a/host-context-controller/src/__tests__/sfsDeploymentNoopGate.test.ts b/host-context-controller/src/__tests__/sfsDeploymentNoopGate.test.ts
index 9411cacb2..bd4c8d6e8 100644
--- a/host-context-controller/src/__tests__/sfsDeploymentNoopGate.test.ts
+++ b/host-context-controller/src/__tests__/sfsDeploymentNoopGate.test.ts
@@ -5,7 +5,13 @@ import { SharedFileSystemReconciler } from '../sharedFileSystemReconciler'
import type { SharedFileSystemCRD } from '../types'
import { deploymentMatchesDesired, preserveDeploymentAnnotations } from '../utils'
import { asApiserverDeployment } from './asApiserverDeployment'
-import { cloneAndMutateLeaf, collectLeafPaths, formatLeafPath } from './mutateJsonLeaves'
+import {
+ cloneAndMutateLeaf,
+ collectLeafPaths,
+ collectLiveOnlySpecLeaves,
+ formatLeafPath,
+ undetectableLiveOnlySpecLeaves,
+} from './mutateJsonLeaves'
const RESTARTED_AT = 'kubectl.kubernetes.io/restartedAt'
const RESTART_STAMP = '2026-08-31T10:00:00Z'
@@ -118,6 +124,20 @@ describe('SFS Deployment no-op gate', () => {
expect(undetectable, `undetectable leaf path(s): ${undetectable.join(', ')}`).toEqual([])
})
+ it('SFS mutation sweep: every live-only spec leaf is detectable', () => {
+ const desired = buildDeployment(sfs, factoryConfig)
+ const existing = asApiserverDeployment(desired)
+ expect(collectLiveOnlySpecLeaves(desired, existing).length).toBeGreaterThan(0)
+ expect(
+ undetectableLiveOnlySpecLeaves(desired, existing, mutated =>
+ deploymentMatchesDesired(
+ mergedForCompare(desired, mutated as k8s.V1Deployment),
+ mutated as k8s.V1Deployment
+ )
+ )
+ ).toEqual([])
+ })
+
it('NOOP-SFS-1: equivalent Deployment skips replace', async () => {
const reconciler = makeReconciler()
const desired = buildDeployment(sfs, factoryConfig)
diff --git a/host-context-controller/src/reconciler.test.ts b/host-context-controller/src/reconciler.test.ts
index 5d1ea3130..3a6277eaf 100644
--- a/host-context-controller/src/reconciler.test.ts
+++ b/host-context-controller/src/reconciler.test.ts
@@ -1872,34 +1872,46 @@ describe('updateStatusConditions', () => {
it('does not log Updated status conditions when both writes were skipped', async () => {
const server = makeServer({ name: 'pg' })
- const identical = {
- status: {
- conditions: [
- {
- type: 'NetworkReady',
- status: 'True',
- reason: 'NetworkPoliciesApplied',
- message: 'NetworkPolicies and Service created',
- lastTransitionTime: '2020-01-02T00:00:00.000Z',
- },
- {
- type: 'DeploymentReady',
- status: 'True',
- reason: 'ReplicasAvailable',
- message: 'Deployment has ready replicas',
- lastTransitionTime: '2020-01-02T00:00:00.000Z',
- },
- ],
- },
- }
- customApi.getNamespacedCustomObjectStatus.mockResolvedValue(identical)
+ let liveStatus: { conditions?: unknown[] } | undefined
+ customApi.getNamespacedCustomObjectStatus.mockImplementation(async () => ({
+ metadata: { resourceVersion: '1' },
+ ...(liveStatus ? { status: liveStatus } : {}),
+ }))
+ customApi.patchNamespacedCustomObjectStatus.mockImplementation(
+ async (req: { body: Array<{ op?: string; path?: string; value?: unknown }> }) => {
+ const op = req.body.find(
+ candidate =>
+ candidate.op === 'add' &&
+ (candidate.path === '/status' || candidate.path === '/status/conditions')
+ )
+ if (!op) throw new Error('status condition add operation was not emitted')
+ liveStatus =
+ op.path === '/status'
+ ? (op.value as { conditions?: unknown[] })
+ : { conditions: op.value as unknown[] }
+ return {}
+ }
+ )
+
+ const updateStatusConditions = (
+ reconciler as unknown as {
+ updateStatusConditions(server: McpServerCRD, deploymentReady: boolean): Promise<void>
+ }
+ ).updateStatusConditions.bind(reconciler)
+
+ await updateStatusConditions(server, true)
+ expect(customApi.patchNamespacedCustomObjectStatus).toHaveBeenCalled()
+ expect(liveStatus?.conditions).toEqual(
+ expect.arrayContaining([
+ expect.objectContaining({ type: 'NetworkReady' }),
+ expect.objectContaining({ type: 'DeploymentReady' }),
+ ])
+ )
+
+ customApi.patchNamespacedCustomObjectStatus.mockClear()
const log = vi.spyOn(console, 'log').mockImplementation(() => {})
try {
- await (
- reconciler as unknown as {
- updateStatusConditions(server: McpServerCRD, deploymentReady: boolean): Promise<void>
- }
- ).updateStatusConditions(server, true)
+ await updateStatusConditions(server, true)
expect(customApi.patchNamespacedCustomObjectStatus).not.toHaveBeenCalled()
expect(log.mock.calls.flat().join('\n')).not.toContain('Updated status conditions')
} finally {