Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(hcc): pin conflict-retry write 404 as fatal (#472)
Alfredo Lopezfdaec664095a
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.jsonindex ae4172910..b8019e259 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.256",+ "version": "0.1.257","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-host-context-controller",- "version": "0.1.256",+ "version": "0.1.257","license": "SEE LICENSE IN LICENSE","dependencies": {"@clerum/image-policy": "file:../packages/image-policy",diff --git a/host-context-controller/package.json b/host-context-controller/package.jsonindex de345e343..9a4977f96 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.256",+ "version": "0.1.257","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__/replaceWithConflictRetryOrder.test.ts b/host-context-controller/src/__tests__/replaceWithConflictRetryOrder.test.tsindex 3c3a8da89..1528ce37e 100644--- a/host-context-controller/src/__tests__/replaceWithConflictRetryOrder.test.ts+++ b/host-context-controller/src/__tests__/replaceWithConflictRetryOrder.test.ts@@ -122,10 +122,41 @@ describe('replaceWithConflictRetry order and retry', () => {expect(replace).not.toHaveBeenCalled()})- it('TOCTOU-NP-3: replace 409 then second read 404 returns without a third replace', async () => {- const read = vi.fn().mockResolvedValueOnce(existing).mockRejectedValueOnce({ code: 404 })- const replace = vi.fn().mockRejectedValueOnce({ code: 409 })+ it.each([+ { form: 'code', error: { code: 404 } },+ { form: 'statusCode', error: { response: { statusCode: 404 } } },+ ])(+ 'TOCTOU-NP-3: replace 409 then second read 404 ($form) returns without a third replace',+ async ({ error }) => {+ const read = vi.fn().mockResolvedValueOnce(existing).mockRejectedValueOnce(error)+ const replace = vi.fn().mockRejectedValueOnce({ code: 409 })+ const validateExisting = vi.fn()++ await expect(+ replaceWithConflictRetry({+ description: 'Service "svc"',+ logPrefix: '[Test]',+ body: desired,+ mergeExisting: preserveServiceAssignedFields,+ isUpToDate: () => false,+ validateExisting,+ read,+ replace,+ })+ ).resolves.toBeUndefined()++ expect(read).toHaveBeenCalledTimes(2)+ expect(validateExisting).toHaveBeenCalledOnce()+ expect(replace).toHaveBeenCalledOnce()+ expect(replace.mock.calls[0][0].metadata?.resourceVersion).toBe('9')+ }+ )++ it('TOCTOU-NP-4: network Error without code is rethrown', async () => {+ const networkErr = new Error('socket hang up')+ const replace = vi.fn()const validateExisting = vi.fn()+ const read = vi.fn().mockRejectedValue(networkErr)await expect(replaceWithConflictRetry({@@ -133,24 +164,24 @@ describe('replaceWithConflictRetry order and retry', () => {logPrefix: '[Test]',body: desired,mergeExisting: preserveServiceAssignedFields,- isUpToDate: () => false,+ isUpToDate: serviceMatchesDesired,validateExisting,read,replace,})- ).resolves.toBeUndefined()+ ).rejects.toBe(networkErr)- expect(read).toHaveBeenCalledTimes(2)- expect(validateExisting).toHaveBeenCalledOnce()- expect(replace).toHaveBeenCalledOnce()- expect(replace.mock.calls[0][0].metadata?.resourceVersion).toBe('9')+ expect(read).toHaveBeenCalledOnce()+ expect(validateExisting).not.toHaveBeenCalled()+ expect(replace).not.toHaveBeenCalled()})- it('TOCTOU-NP-4: network Error without code is rethrown', async () => {- const networkErr = new Error('socket hang up')- const replace = vi.fn()- const validateExisting = vi.fn()- const read = vi.fn().mockRejectedValue(networkErr)+ it.each([+ { form: 'code', error: { code: 404 } },+ { form: 'statusCode', error: { response: { statusCode: 404 } } },+ ])('TOCTOU-NP-5: helper replace 404 ($form) still throws', async ({ error }) => {+ const read = vi.fn().mockResolvedValue(existing)+ const replace = vi.fn().mockRejectedValue(error)await expect(replaceWithConflictRetry({@@ -158,16 +189,14 @@ describe('replaceWithConflictRetry order and retry', () => {logPrefix: '[Test]',body: desired,mergeExisting: preserveServiceAssignedFields,- isUpToDate: serviceMatchesDesired,- validateExisting,+ isUpToDate: () => false,read,replace,})- ).rejects.toBe(networkErr)+ ).rejects.toBe(error)expect(read).toHaveBeenCalledOnce()- expect(validateExisting).not.toHaveBeenCalled()- expect(replace).not.toHaveBeenCalled()+ expect(replace).toHaveBeenCalledOnce()})it('RETRY-SVC-2: post-409 re-read that matches skips the second replace', async () => {