Skip to content

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

TypeScript

test(wrc): pin the post-conflict re-decision and the SDK-only summary pass-through

Alfredo Lopez2c2c3c83760c
diff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.json
index f4f6e5a1f..27c5cf150 100644
--- a/workflow-recipes/package-lock.json
+++ b/workflow-recipes/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "workload-recipes-controller",
- "version": "0.1.396",
+ "version": "0.1.397",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "workload-recipes-controller",
- "version": "0.1.396",
+ "version": "0.1.397",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@aws-sdk/client-s3": "^3.1009.0",
diff --git a/workflow-recipes/package.json b/workflow-recipes/package.json
index 2a2ce7ca3..0fcdb8692 100644
--- a/workflow-recipes/package.json
+++ b/workflow-recipes/package.json
@@ -1,6 +1,6 @@
{
"name": "workload-recipes-controller",
- "version": "0.1.396",
+ "version": "0.1.397",
"description": "Workload Recipes Controller (WRC) - WorkloadRecipe lifecycle management and MCP server interface",
"main": "dist/main.js",
"engines": {
diff --git a/workflow-recipes/src/reconciler/reconciler.test.ts b/workflow-recipes/src/reconciler/reconciler.test.ts
index 4082b075d..8e133cea1 100644
--- a/workflow-recipes/src/reconciler/reconciler.test.ts
+++ b/workflow-recipes/src/reconciler/reconciler.test.ts
@@ -1666,6 +1666,57 @@ describe('WorkflowRecipeReconciler', () => {
expect(terminal.networkPolicyOwnershipConditions).toEqual([])
expect(terminal.requeueAfterMs).toBeUndefined()
})
+
+ // Removing spec.pluginWorkloadSdk tears the runtime down and falls through
+ // to the transport return without an SDK runtime. No policy is managed any
+ // more, so the lane must send `[]` (clear), not undefined (keep).
+ it('clears a published condition once the SDK capability is removed from the spec', async () => {
+ const sdkOnly = stubSdkOnly({})
+ const cleanupPluginWorkloadSdk = vi.fn().mockResolvedValue(undefined)
+ ;(
+ reconciler as unknown as {
+ workflowReconciler: { cleanupPluginWorkloadSdk: typeof cleanupPluginWorkloadSdk }
+ }
+ ).workflowReconciler.cleanupPluginWorkloadSdk = cleanupPluginWorkloadSdk
+ const recipe = makeRecipe({
+ spec: {
+ workloads: [{ id: 'app', type: 'deployment', image: 'nginx:1.30.1-alpine', port: 8080 }],
+ },
+ status: {
+ phase: 'active',
+ pluginWorkloadSdk: { state: 'validated', promptBridge: true, clientNotifications: false },
+ conditions: [ownershipCondition],
+ },
+ } as Partial<WorkflowRecipeCRD>)
+
+ const result = await reconciler.reconcile(recipe)
+
+ // Liveness witness: the capability-removal teardown ran and the pass
+ // reached the transport return, not the SDK-only lane.
+ expect(cleanupPluginWorkloadSdk).toHaveBeenCalledTimes(1)
+ expect(cleanupPluginWorkloadSdk).toHaveBeenCalledWith('test-recipe', {
+ preserveWorkflowRuntime: false,
+ })
+ expect(sdkOnly).not.toHaveBeenCalled()
+ expect(result.phase).not.toBe('failed')
+ expect(result.networkPolicyOwnershipConditions).toEqual([])
+ expect(shouldPatchRecipeStatus(recipe, result)).toBe(true)
+ // The pass itself may patch an intermediate phase; the status write under
+ // test is the one patchStatus adds.
+ const patchesBefore = mockCustomApi.patchNamespacedCustomObjectStatus.mock.calls.length
+
+ await reconciler.patchStatus(recipe, result)
+
+ expect(mockCustomApi.patchNamespacedCustomObjectStatus).toHaveBeenCalledTimes(
+ patchesBefore + 1
+ )
+ const conditions = mockCustomApi.patchNamespacedCustomObjectStatus.mock.calls.at(-1)![0].body
+ .status.conditions as Array<{ type: string }>
+ expect(conditions.length).toBeGreaterThan(0)
+ expect(conditions.map(condition => condition.type)).not.toContain(
+ 'WorkflowNetworkPolicyOwnership'
+ )
+ })
})
// awaiting_policy waits for an operator grant. The grant arrives by event
diff --git a/workflow-recipes/src/workflow/workflowReconciler.test.ts b/workflow-recipes/src/workflow/workflowReconciler.test.ts
index e4165756f..d83040e7b 100644
--- a/workflow-recipes/src/workflow/workflowReconciler.test.ts
+++ b/workflow-recipes/src/workflow/workflowReconciler.test.ts
@@ -1715,6 +1715,51 @@ describe('WorkflowReconciler — Plugin Workload SDK eager mcp-host', () => {
expect(writesTo(foreignName)).toHaveLength(0)
})
+ // Every eager host status that is not `ready` still ran the apply when it
+ // carries a summary, so the SDK-only lane must hand that summary on: dropping
+ // it would read as "returned before applying" and keep a stale condition.
+ it.each([
+ { status: 'awaiting_policy', phase: 'awaiting_policy' },
+ { status: 'deploying', phase: 'deploying' },
+ { status: 'provider_unavailable', phase: 'provider_unavailable' },
+ { status: 'failed', phase: 'failed' },
+ ] as const)(
+ 'SDK-only lane passes the eager apply summary through on $status',
+ async ({ status, phase }) => {
+ const reconciler = new WorkflowReconciler(makeDeps())
+ const provisioner = (
+ reconciler as unknown as {
+ pluginWorkloadSdkProvisioner: {
+ ensureEagerSdkMcpHost: (...args: unknown[]) => unknown
+ }
+ }
+ ).pluginWorkloadSdkProvisioner
+ const foreignName = 'sdk-only-workload-to-mcp-host-sdk-ingress'
+ const ensure = vi.spyOn(provisioner, 'ensureEagerSdkMcpHost').mockResolvedValue({
+ status,
+ networkPolicies: {
+ conflicts: [{ policy: foreignName, reason: 'owner-reference-mismatch' }],
+ retryPending: true,
+ },
+ })
+
+ const result = await reconciler.reconcilePluginWorkloadSdkOnly(
+ 'sdk-only',
+ 'uid-sdk-only',
+ sandboxNamespace,
+ sdkSpec({ steps: undefined })
+ )
+
+ expect(ensure).toHaveBeenCalledTimes(1)
+ expect(ensure.mock.calls[0]?.[0]).toBe('sdk-only')
+ expect(result.phase).toBe(phase)
+ expect(result.networkPolicies).toEqual({
+ conflicts: [{ policy: foreignName, reason: 'owner-reference-mismatch' }],
+ retryPending: true,
+ })
+ }
+ )
+
it('workflow lane surfaces the conflict as a False condition and clears it on recovery', async () => {
const foreignName = 'sdk-recipe-workload-to-mcp-host-sdk-ingress'
foreignOnly(foreignName)
diff --git a/workflow-recipes/tests/unit/workflow/workflowReconciler.test.ts b/workflow-recipes/tests/unit/workflow/workflowReconciler.test.ts
index 01bb64826..66b91e46b 100644
--- a/workflow-recipes/tests/unit/workflow/workflowReconciler.test.ts
+++ b/workflow-recipes/tests/unit/workflow/workflowReconciler.test.ts
@@ -34,6 +34,7 @@ import {
type WorkflowRecipeSpec,
WorkflowReconciler,
type WorkflowReconcilerDeps,
+ buildNetworkPolicyOwnershipConditions,
} from '../../../src/workflow/workflowReconciler'
import { asApiserverNetworkPolicy } from './asApiserverNetworkPolicy'
@@ -3913,6 +3914,117 @@ describe('WorkflowReconciler — reconcile loop', () => {
logs.restore()
}
})
+
+ // The decision is taken again on the object the re-read returns, not
+ // reused from the first read: a writer that wins the replace may also
+ // take the policy over or start deleting it.
+ function concurrentWriterOnFirstReplace(
+ rewrite: (current: k8s.V1NetworkPolicy) => k8s.V1NetworkPolicy
+ ) {
+ let concurrentWrites = 0
+ return (
+ arg: { name: string; namespace: string },
+ live: Map<string, k8s.V1NetworkPolicy>
+ ): Promise<never> | undefined => {
+ if (arg.name !== 'test-wf-coord-to-wrc' || concurrentWrites > 0) return undefined
+ concurrentWrites += 1
+ const liveKey = `${arg.namespace}/${arg.name}`
+ const current = live.get(liveKey)
+ expect(current).toBeDefined()
+ const rewritten = rewrite(current!)
+ live.set(liveKey, {
+ ...rewritten,
+ metadata: { ...rewritten.metadata, resourceVersion: 'concurrent-1' },
+ })
+ return Promise.reject({ code: 409 })
+ }
+ }
+
+ it('reports a conflict, without a second replace, when the re-read after a replace conflict finds a foreign owner', async () => {
+ const logs = captureRunLaneNetworkPolicyLogs()
+ try {
+ const { second, reads, replaces } = await reconcileWithFailingReplace(
+ concurrentWriterOnFirstReplace(current => ({
+ ...current,
+ metadata: {
+ ...current.metadata,
+ ownerReferences: [
+ {
+ apiVersion: 'apps/v1',
+ kind: 'Deployment',
+ name: 'another-controller',
+ uid: 'foreign-owner-uid',
+ controller: true,
+ },
+ ],
+ },
+ }))
+ )
+
+ expect(reads).toHaveLength(2)
+ expect(replaces).toHaveLength(1)
+ expect(second.phase).not.toBe('failed')
+ expect(second.workflowPhase).not.toBe('failed')
+ expect(second.networkPolicyOwnershipConditions).toEqual([
+ expect.objectContaining({
+ type: 'WorkflowNetworkPolicyOwnership',
+ status: 'False',
+ reason: 'OwnershipConflict',
+ message:
+ 'NetworkPolicy ownership conflict: test-wf-coord-to-wrc (owner-reference-mismatch)',
+ }),
+ ])
+ // A conflict waits for an operator, not a timer.
+ expect(second.networkPolicyRetryPending).toBeFalsy()
+ expect(
+ logs.entries.filter(
+ entry => entry.level === 'warn' && String(entry.msg).includes('test-wf-coord-to-wrc')
+ )
+ ).toEqual([
+ expect.objectContaining({
+ reason: 'owner-reference-mismatch',
+ msg: 'NetworkPolicy "test-wf-coord-to-wrc" is not owned by this workflow; leaving it',
+ }),
+ ])
+ } finally {
+ logs.restore()
+ }
+ })
+
+ it('flags a retry, without a second replace, when the re-read after a replace conflict finds the policy terminating', async () => {
+ const logs = captureRunLaneNetworkPolicyLogs()
+ try {
+ const { second, reads, replaces } = await reconcileWithFailingReplace(
+ concurrentWriterOnFirstReplace(current => ({
+ ...current,
+ metadata: {
+ ...current.metadata,
+ deletionTimestamp: new Date('2026-09-23T10:00:00.000Z'),
+ },
+ }))
+ )
+
+ expect(reads).toHaveLength(2)
+ expect(replaces).toHaveLength(1)
+ expect(second.phase).not.toBe('failed')
+ expect(second.workflowPhase).not.toBe('failed')
+ expect(second.networkPolicyRetryPending).toBe(true)
+ // Being deleted is not a conflict: the owned set is empty, not absent.
+ expect(second.networkPolicyOwnershipConditions).toEqual([])
+ expect(
+ logs.entries.filter(
+ entry => entry.level === 'warn' && String(entry.msg).includes('test-wf-coord-to-wrc')
+ )
+ ).toEqual([
+ expect.objectContaining({
+ reason: 'terminating',
+ msg: 'NetworkPolicy "test-wf-coord-to-wrc" cannot be written yet; retrying later',
+ }),
+ ])
+ } finally {
+ logs.restore()
+ }
+ })
})
describe('create conflicts, read errors and stale runtime state', () => {
@@ -7359,3 +7471,29 @@ describe('WorkflowReconciler — reconcile loop', () => {
expect(validPhases).toContain(result.workflowPhase)
})
})
+
+describe('buildNetworkPolicyOwnershipConditions', () => {
+ it('names the conflicting policies in sorted order, whatever order the apply produced them in', () => {
+ const conditions = buildNetworkPolicyOwnershipConditions(
+ {
+ conflicts: [
+ { policy: 'test-wf-wrc-to-artifact-reader', reason: 'identity-label-mismatch' },
+ { policy: 'test-wf-coord-to-wrc', reason: 'owner-reference-mismatch' },
+ ],
+ retryPending: false,
+ },
+ '2026-09-23T10:00:00.000Z'
+ )
+
+ expect(conditions).toEqual([
+ {
+ type: 'WorkflowNetworkPolicyOwnership',
+ status: 'False',
+ reason: 'OwnershipConflict',
+ message:
+ 'NetworkPolicy ownership conflict: test-wf-coord-to-wrc (owner-reference-mismatch), test-wf-wrc-to-artifact-reader (identity-label-mismatch)',
+ lastTransitionTime: '2026-09-23T10:00:00.000Z',
+ },
+ ])
+ })
+})