Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(wrc): isolate renewalDue in the no-record test, and bound two JSDoc claims (#299)
Alfredo Lopez23d5c76e40c4
diff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.jsonindex 69deabfa3..386b77e65 100644--- a/workflow-recipes/package-lock.json+++ b/workflow-recipes/package-lock.json@@ -1,12 +1,12 @@{"name": "workload-recipes-controller",- "version": "0.1.321",+ "version": "0.1.322","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "workload-recipes-controller",- "version": "0.1.321",+ "version": "0.1.322","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 cc5d1ca53..a8b8f3a4a 100644--- a/workflow-recipes/package.json+++ b/workflow-recipes/package.json@@ -1,6 +1,6 @@{"name": "workload-recipes-controller",- "version": "0.1.321",+ "version": "0.1.322","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 1e83b9914..1018b40a9 100644--- a/workflow-recipes/src/reconciler/reconciler.test.ts+++ b/workflow-recipes/src/reconciler/reconciler.test.ts@@ -4204,54 +4204,78 @@ describe('WorkflowRecipeReconciler', () => {}})- it('does NOT record a renewal write, which writes without the set changing', async () => {+ it('does NOT record a RENEWAL write, which writes with the set unchanged', async () => {// The gate is `changed`, not "did we write". A renewal (audit M1) re-persists// an aging window with an identical set: the policy IS rewritten and no- // record is due, because nothing about the resolved set changed. This is the- // direction the record does NOT run — every entry implies a write, not the- // converse — and it is the only path that still reaches the emitter with- // changed === false, since the no-op gate returns earlier.+ // record is due, because nothing about the resolved set changed. That is the+ // direction the record does NOT run — an entry implies a write, not the+ // converse.+ //+ // ISOLATING renewalDue. The live policy fed back here is the reconciler's OWN+ // first render, with only the state annotation's `expiresAt` rewound. That+ // matters: it makes the rendered spec.egress byte-identical, so+ // `egressWriteNeeded` is FALSE and `changed` is FALSE, leaving renewalDue as+ // the only term of the H4 gate that can still authorise a write. A fixture+ // carrying just `metadata` would leave egressWriteNeeded true and the test+ // would pass without renewalDue ever being the cause.+ const kc = new k8s.KubeConfig()+ const rec = new WorkflowRecipeReconciler(kc, undefined, {+ // The SAME address both rounds, so the (fqdn,ip,port,protocol) set is unchanged.+ fqdnLookup: async () => ({+ kind: 'ok',+ ipv4: ['93.184.216.10'],+ ipv6: [],+ ttlSeconds: 300,+ }),+ })+ const recipe = uiRecipeWithExternals([{ fqdn: 'api.stripe.com', port: 443 }])++ await rec.reconcile(recipe)+ const rendered = createdPolicy('ui-egress-test-recipe')+ expect(rendered).toBeDefined()++ // Rewind ONLY the persisted expiry, keeping every (fqdn,ip,port,protocol)+ // tuple. renewalDue fires when a surviving entry's persisted expiry is within+ // overlap/2 of now and this round would advance it.+ const persisted = JSON.parse(+ rendered!.metadata!.annotations!['clerum.io/egress-fqdn-state']+ ) as Array<Record<string, unknown>>+ const aging = persisted.map(e => ({ ...e, expiresAt: Date.now() + 30_000 }))+ mockNetworkingApi.readNamespacedNetworkPolicy.mockResolvedValue({+ ...rendered,+ metadata: {+ ...rendered!.metadata,+ resourceVersion: '1',+ annotations: {+ ...rendered!.metadata!.annotations,+ 'clerum.io/egress-fqdn-state': JSON.stringify(aging),+ },+ },+ })+const cap = captureEgressRecords()+ const noOpSpy = vi.spyOn(console, 'log').mockImplementation(() => {})try {- const now = Date.now()- // expiresAt within overlap/2 of now makes this round's fresh expiry an- // advance, which is exactly what renewalDue keys on.- const aging = [- {- ip: '93.184.216.10',- port: 443,- protocol: 'TCP',- fqdn: 'api.stripe.com',- expiresAt: now + 30_000,- lastObservedAt: now,- },- ]- mockNetworkingApi.readNamespacedNetworkPolicy.mockResolvedValue({- metadata: {- name: 'ui-egress-test-recipe',- resourceVersion: '1',- annotations: { 'clerum.io/egress-fqdn-state': JSON.stringify(aging) },- },- })+ mockNetworkingApi.createNamespacedNetworkPolicy.mockClear()+ mockNetworkingApi.replaceNamespacedNetworkPolicy.mockClear()- const kc = new k8s.KubeConfig()- const rec = new WorkflowRecipeReconciler(kc, undefined, {- // The SAME address, so the (fqdn,ip,port,protocol) set is unchanged.- fqdnLookup: async () => ({- kind: 'ok',- ipv4: ['93.184.216.10'],- ipv6: [],- ttlSeconds: 300,- }),- })+ await rec.reconcile(recipe)- await rec.reconcile(uiRecipeWithExternals([{ fqdn: 'api.stripe.com', port: 443 }]))+ // POSITIVE CONTROL: a write really happened. With the spec identical and the+ // set unchanged, renewalDue is the only term left that could have caused it,+ // so this also proves the no-op gate did NOT short-circuit.+ const wrote =+ mockNetworkingApi.createNamespacedNetworkPolicy.mock.calls.length ++ mockNetworkingApi.replaceNamespacedNetworkPolicy.mock.calls.length+ expect(wrote).toBeGreaterThan(0)+ expect(noOpSpy).not.toHaveBeenCalledWith(+ expect.stringContaining('ui-egress-test-recipe" in sandbox-ui egress set unchanged — no-op')+ )- // POSITIVE CONTROL: the write really happened, so the emitter was reached- // and stayed silent by the gate — not skipped by an early return.- expect(createdPolicy('ui-egress-test-recipe')).toBeDefined()+ // ...and no record, because the resolved set did not change.expect(cap.payloads()).toHaveLength(0)} finally {+ noOpSpy.mockRestore()cap.restore()}})diff --git a/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts b/workflow-recipes/src/reconciler/workflowRecipeReconciler.tsindex 40f2ec3a3..790bee8f8 100644--- a/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts+++ b/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts@@ -172,6 +172,13 @@ function declaresInheritedParentResources(recipe: WorkflowRecipeCRD): boolean {* a record meant to be read. The accumulator already emits its entries in a* stable key order, so this is about the record's OWN readable contract rather* than about rescuing an unordered input.+ *+ * INVARIANT IT RELIES ON: input is always a valid IPv4 `a.b.c.d/32`. That holds+ * upstream — `resolveExternalEgress` emits `/32` only from `result.ipv4`+ * (AAAA is resolved and dropped), and `parseState` admits an entry only if+ * `isValidIpv4`. A non-numeric octet would yield NaN and an unstable order —+ * never a throw — so if IPv6 egress is ever added, order silently degrades+ * here and this comparator is the place to fix.*/function compareCidrByAddress(a: string, b: string): number {const octets = (cidr: string) => cidr.split('/')[0].split('.').map(Number)@@ -4838,6 +4845,12 @@ export class WorkflowRecipeReconciler {* A DECLARED FQDN THAT RESOLVED TO NOTHING STILL EMITS, with `cidrs: []`. A* set collapsing to empty is the most consequential event in the series and* must not be indistinguishable from "nothing happened".+ *+ * WHAT THE RECORD DOES NOT CARRY. `cidrs` and `ports` are two independent+ * deduped projections, not pairs: a host on `(A,443)` and `(B,8443)` renders+ * `cidrs:[A,B] ports:[443,8443]`, which reads the same as both addresses on+ * both ports. The record is an ADDRESS history — that is what it is for — so+ * it matches the enforced policy on each projection, not on their pairing.*/private logResolvedEgressSet(recipeName: string,