Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(wrc): pin the inner set-size guard the property tests masked
Alfredo Lopez1acb539dfa5d
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.jsonindex aa4238fa6..6704209ff 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.287",+ "version": "0.1.288","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-host-context-controller",- "version": "0.1.287",+ "version": "0.1.288","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.jsonindex 53fc757ae..ac6bbd4bb 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.287",+ "version": "0.1.288","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.ts b/host-context-controller/src/k8sClient.tsindex 374113ff0..216143451 100644--- a/host-context-controller/src/k8sClient.ts+++ b/host-context-controller/src/k8sClient.ts@@ -4338,7 +4338,11 @@ export class McpServerWatcher implements McpServerProvider {// Keep the cached object identity when desired revision did not move.// Scoped revoke uses `contexts.get(name) === selectedContext`; replacing// the entry on every label/status MODIFIED aborts an in-flight pass.- if (desiredStateChanged || previous === undefined) {+ // `desiredStateChanged` was just computed as+ // `previous === undefined || !sameContextDesiredRevision(...)`, so the+ // bootstrap case already implies it; a second disjunct here was dead+ // (#568 review, jozer-rami minors).+ if (desiredStateChanged) {this.contexts.set(context.name, context)}} else if (type === 'DELETED') {diff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.jsonindex 6f0ac98c7..01e3c4c04 100644--- a/workflow-recipes/package-lock.json+++ b/workflow-recipes/package-lock.json@@ -1,12 +1,12 @@{"name": "workload-recipes-controller",- "version": "0.1.342",+ "version": "0.1.343","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "workload-recipes-controller",- "version": "0.1.342",+ "version": "0.1.343","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 c105fced2..5919cba14 100644--- a/workflow-recipes/package.json+++ b/workflow-recipes/package.json@@ -1,6 +1,6 @@{"name": "workload-recipes-controller",- "version": "0.1.342",+ "version": "0.1.343","description": "Workload Recipes Controller (WRC) - WorkloadRecipe lifecycle management and MCP server interface","main": "dist/main.js","engines": {diff --git a/workflow-recipes/src/reconciler/mcpDelegation.test.ts b/workflow-recipes/src/reconciler/mcpDelegation.test.tsindex 3f2152c65..cdae9d57f 100644--- a/workflow-recipes/src/reconciler/mcpDelegation.test.ts+++ b/workflow-recipes/src/reconciler/mcpDelegation.test.ts@@ -1074,6 +1074,53 @@ describe('ensureRecipeContext', () => {expect(written).toEqual(['existing-server', 'test-recipe-redis-mcp'])})+ it('does not silently drop a new server when a duplicate makes the lengths match', async () => {+ // The gap the first duplicate test did not close, found by the @claude+ // re-audit of #568 and confirmed by mutation: deleting the INNER+ // `leftSet.size !== rightSet.size` guard left the whole suite green.+ //+ // The other dup test compares 3 live entries against 2 merged ones, so the+ // OUTER length guard catches it and line 137 never runs. This case makes the+ // lengths equal on purpose:+ //+ // live ['server-a','server-a'] vs merged ['server-a','server-b']+ // outer: 2 === 2 -> passes+ // leftSet {server-a} (1) rightSet {a,b} (2) -> only the inner guard sees it+ //+ // Without that guard, "every member of leftSet is in rightSet" is true, the+ // sets compare EQUAL, the plan is null and the pass skips — so `server-b` is+ // never authorized and the duplicate never heals. A silently dropped server+ // is worse than the duplicate the length check was added for.+ //+ // The property tests cannot catch this: they all bail on `plan === null`+ // before asserting, which is exactly the state the mutation produces, so+ // no-shrink and no-duplicates pass vacuously on the corrupted input.+ const recipe = makeRecipe({ spec: { ...makeRecipe().spec, contextRef: 'context1' } })+ const mockCustomApi = {+ createNamespacedCustomObject: vi.fn().mockRejectedValueOnce({ code: 409 }),+ getNamespacedCustomObject: vi.fn().mockResolvedValue({+ metadata: { resourceVersion: '9', labels: { 'clerum.io/managed-by': 'wrc' } },+ spec: { contextId: 'context1', mcpServers: ['server-a', 'server-a'] },+ }),+ replaceNamespacedCustomObject: vi.fn().mockResolvedValue({}),+ }+ const deps: DelegationDeps = {+ customApi: mockCustomApi as unknown as DelegationDeps['customApi'],+ coreApi: {} as DelegationDeps['coreApi'],+ }++ await ensureRecipeContext(deps, recipe, ['server-b'], 'mcp-server', ownerRef, 'sandbox-recipes')++ // Witness: the pre-read happened, so a skip here would be a real decision+ // rather than a path that never executed.+ expect(mockCustomApi.getNamespacedCustomObject).toHaveBeenCalledTimes(1)+ expect(mockCustomApi.replaceNamespacedCustomObject).toHaveBeenCalledTimes(1)+ const written =+ mockCustomApi.replaceNamespacedCustomObject.mock.calls[0][0].body.spec.mcpServers+ // The new server lands AND the duplicate is gone, in the same write.+ expect(written).toEqual(['server-a', 'server-b'])+ })+it('H04b — writes on 409 when live Context has no mcpServers (empty→filled is not a skip)', async () => {const mockCustomApi = {createNamespacedCustomObject: vi.fn().mockRejectedValueOnce({ code: 409 }),diff --git a/workflow-recipes/src/reconciler/mcpDelegation.ts b/workflow-recipes/src/reconciler/mcpDelegation.tsindex 498d337e3..16e6b0e4e 100644--- a/workflow-recipes/src/reconciler/mcpDelegation.ts+++ b/workflow-recipes/src/reconciler/mcpDelegation.ts@@ -968,6 +968,11 @@ export async function ensureRecipeContext(throw replaceError}}+ // Unreachable: every iteration returns or throws, so the loop cannot fall+ // through. Kept because TypeScript's control-flow analysis does not prove+ // that and the function must return `{ wrote: boolean }` on every path+ // (#568 review, jozer-rami minors). Not dead code to delete — deleting it+ // is a compile error, not a cleanup.throw new Error(`failed to update Context "${contextName}" after conflict retries`)}