Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(workflow-recipes): keep the token seen when the finalizer DELETE fails (R4-L1)
Alfredo Lopez6d743d1ab7ed
diff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.jsonindex 254f8a086..70cef38b7 100644--- a/workflow-recipes/package-lock.json+++ b/workflow-recipes/package-lock.json@@ -1,12 +1,12 @@{"name": "workload-recipes-controller",- "version": "0.1.433",+ "version": "0.1.434","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "workload-recipes-controller",- "version": "0.1.433",+ "version": "0.1.434","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 54067fa46..842b6cde0 100644--- a/workflow-recipes/package.json+++ b/workflow-recipes/package.json@@ -1,6 +1,6 @@{"name": "workload-recipes-controller",- "version": "0.1.433",+ "version": "0.1.434","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.tsindex 284037cca..6c445fea8 100644--- a/workflow-recipes/src/reconciler/reconciler.test.ts+++ b/workflow-recipes/src/reconciler/reconciler.test.ts@@ -15589,7 +15589,26 @@ describe('WorkflowRecipeReconciler', () => {expect(policyDeletes()).toBe(1)})- it('reconcileDelete drops the ledger: no DELETE until a new token ADDED, then even below the old watermark', async () => {+ function recreatedRecipe(): WorkflowRecipeCRD {+ return makeRecipe({+ metadata: {+ name: 'test-recipe',+ namespace: 'sandbox-recipes',+ uid: 'uid-recreated',+ generation: 1,+ },+ })+ }++ /** Fails only the token Secret DELETE; every other Secret DELETE succeeds. */+ function failTokenDelete(code: number): void {+ mockCoreApi.deleteNamespacedSecret.mockImplementation(async ({ name }: { name: string }) => {+ if (name === SECRET_NAME) throw { code }+ return {}+ })+ }++ it('R4-L1: after the finalizer deleted the token, a recreated recipe sends no DELETE until a new token ADDED, then even below the old watermark', async () => {const recipe = reapRecipe(4)tokenSeen()await reconciler.ensureOAuthBrokerTokenSecret(recipe)@@ -15597,10 +15616,28 @@ describe('WorkflowRecipeReconciler', () => {expect(secretDeletes()).toBe(1)await reconciler.reconcileDelete(recipe)+ // Witness for the premise: the finalizer sent the token DELETE, and the+ // default mock answers it 2xx.+ expect(secretDeletes()).toBe(2)mockCoreApi.deleteNamespacedSecret.mockClear()- // The finalizer deleted the token with the recipe; nothing is left to reap.- await reconciler.ensureOAuthBrokerTokenSecret(recipe)- expect(secretDeletes()).toBe(0)++ const debugSpy = captureLogger('debug')+ try {+ await reconciler.ensureOAuthBrokerTokenSecret(recreatedRecipe())+ await reconciler.ensureOAuthBrokerTokenSecret(recreatedRecipe())+ expect(secretDeletes()).toBe(0)+ // Liveness witness: both passes reached the ledger and it declined.+ expect(+ debugSpy.mock.calls.filter(+ ([message, fields]) =>+ typeof message === 'string' &&+ message.startsWith('Skipping oauth-broker-token delete') &&+ (fields as { generation?: number }).generation === 1+ )+ ).toHaveLength(2)+ } finally {+ debugSpy.mockRestore()+ }// A token ADDED for a recipe under the same name: the old watermark is// gone, so a lower generation deletes.@@ -15609,6 +15646,46 @@ describe('WorkflowRecipeReconciler', () => {expect(secretDeletes()).toBe(1)})+ it('R4-L1: a finalizer whose token DELETE failed keeps the token seen, so a recreated recipe deletes it once', async () => {+ tokenSeen()+ failTokenDelete(500)+ try {+ await reconciler.reconcileDelete(reapRecipe(4))+ // Witness: the finalizer sent the token DELETE and it failed.+ expect(secretDeletes()).toBe(1)+ } finally {+ mockCoreApi.deleteNamespacedSecret.mockResolvedValue({})+ }+ mockCoreApi.deleteNamespacedSecret.mockClear()++ // The recipe is recreated under the same name without backgroundAccess.+ await reconciler.ensureOAuthBrokerTokenSecret(recreatedRecipe())+ await reconciler.ensureOAuthBrokerTokenSecret(recreatedRecipe())+ expect(secretDeletes()).toBe(1)+ })++ it('R4-L1: a token ADDED while the finalizer DELETE is in flight keeps the token seen', async () => {+ tokenSeen()+ mockCoreApi.deleteNamespacedSecret.mockImplementation(async ({ name }: { name: string }) => {+ // The recipe was recreated and its token ADDED was handled before the+ // finalizer's DELETE of the old token returned.+ if (name === SECRET_NAME) reconciler.invalidateOAuthBrokerSecretLedger('test-recipe')+ return {}+ })+ try {+ await reconciler.reconcileDelete(reapRecipe(4))+ // Witness: the finalizer sent the token DELETE.+ expect(secretDeletes()).toBe(1)+ } finally {+ mockCoreApi.deleteNamespacedSecret.mockResolvedValue({})+ }+ mockCoreApi.deleteNamespacedSecret.mockClear()++ await reconciler.ensureOAuthBrokerTokenSecret(recreatedRecipe())+ await reconciler.ensureOAuthBrokerTokenSecret(recreatedRecipe())+ expect(secretDeletes()).toBe(1)+ })+it('G3: does not record a Secret delete after DELETE 403 or 500', async () => {const recipe = reapRecipe(4)tokenSeen()