Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test: cover the gaps found by the adversarial review of the GFS limits
Alfredo Lopez84b3d7e5ae62
diff --git a/gfs-controller/src/quota/quota.test.ts b/gfs-controller/src/quota/quota.test.tsindex cdef8847e..aee659f05 100644--- a/gfs-controller/src/quota/quota.test.ts+++ b/gfs-controller/src/quota/quota.test.ts@@ -115,6 +115,18 @@ describe("RateLimiter", () => {t -= 1;expect(() => rl.check("s")).toThrow(RateLimitExceededError);});++ it("M15: compaction bounds the slots a subject holds to about twice its live window", () => {+ // 100 live hits per window, for 100 windows: 10 000 hits in total. Without+ // compaction the array keeps every one of them.+ let t = 0;+ const rl = new RateLimiter({ limit: 1_000, windowMs: 1_000, now: () => t });+ for (t = 1; t <= 100_000; t += 10) rl.check("s");+ // Witness: the subject is live and its window holds 100 hits.+ expect(rl.trackedSubjectCount).toBe(1);+ expect(rl.retainedSlotCount("s")).toBeGreaterThanOrEqual(100);+ expect(rl.retainedSlotCount("s")).toBeLessThanOrEqual(2 * 100 + 1);+ });});describe("buildAgentRateLimits", () => {diff --git a/gfs-controller/src/quota/rateLimit.ts b/gfs-controller/src/quota/rateLimit.tsindex 639d2bdf3..657135068 100644--- a/gfs-controller/src/quota/rateLimit.ts+++ b/gfs-controller/src/quota/rateLimit.ts@@ -50,6 +50,14 @@ export class RateLimiter {return this.hits.size;}+ /**+ * Array slots held for `subject`, expired hits included until compaction+ * drops them. Read by tests to bound the memory one subject can hold.+ */+ retainedSlotCount(subject: string): number {+ return this.hits.get(subject)?.times.length ?? 0;+ }+/*** Record a hit for `subject`; throw RateLimitExceededError if the window is* full. Retry-after is when the oldest retained hit leaves the window, thediff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex 412f0840f..38ed97aaf 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.372",+ "version": "0.1.373","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.372",+ "version": "0.1.373","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex c6d454df5..4f4971423 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.372",+ "version": "0.1.373","description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude","main": "dist/main.js","engines": {diff --git a/mcp-host/src/internalTools/gfsClient.test.ts b/mcp-host/src/internalTools/gfsClient.test.tsindex 42b499e75..80cface73 100644--- a/mcp-host/src/internalTools/gfsClient.test.ts+++ b/mcp-host/src/internalTools/gfsClient.test.ts@@ -1,4 +1,5 @@import { afterEach, describe, expect, it, vi } from 'vitest'+import type { GfscCallOptions, GfscWriteClient } from './gfs'import {DEFAULT_GFS_ACCESS_FILE,GfscHttpError,@@ -499,6 +500,80 @@ describe('gfsc client retry: cancellation, deadline, scope and jitter', () => {expect(fetchFn).toHaveBeenCalledTimes(2)})+ // Every method, not only stat: a method that drops `call` would sleep past+ // the step's remaining time and could not be cancelled.+ const EVERY_METHOD: Array<[string, (client: GfscWriteClient, call: GfscCallOptions) => unknown]> =+ [+ ['accessible', (client, call) => client.accessible({ drive: 'main' }, call)],+ ['list', (client, call) => client.list({ drive: 'main', resourceId: 'rid' }, call)],+ ['read', (client, call) => client.read({ drive: 'main', resourceId: 'rid' }, call)],+ ['stat', (client, call) => client.stat({ drive: 'main', resourceId: 'rid' }, call)],+ ['resolve', (client, call) => client.resolve({ uri: 'gfs://main/a.txt' }, call)],+ [+ 'write',+ (client, call) =>+ client.write({ drive: 'main', resourceId: 'rid', content: 'x', ifMatch: 1 }, call),+ ],+ [+ 'createFile',+ (client, call) =>+ client.createFile(+ { drive: 'main', parentResourceId: 'pid', name: 'a.txt', content: 'x' },+ call+ ),+ ],+ [+ 'createFolder',+ (client, call) =>+ client.createFolder({ drive: 'main', parentResourceId: 'pid', name: 'dir' }, call),+ ],+ [+ 'rename',+ (client, call) =>+ client.rename({ drive: 'main', resourceId: 'rid', newName: 'b.txt', ifMatch: 1 }, call),+ ],+ [+ 'copy',+ (client, call) =>+ client.copy(+ {+ drive: 'main',+ sourceResourceId: 'rid',+ destinationParentId: 'pid',+ ifMatch: 1,+ },+ call+ ),+ ],+ ]++ it.each(EVERY_METHOD)('M1: %s passes the caller signal to fetch', async (_name, invoke) => {+ const signals: Array<AbortSignal | null | undefined> = []+ const fetchFn = vi.fn(async (_input: string, init?: RequestInit) => {+ signals.push(init?.signal)+ return jsonResponse({ ok: true })+ })+ const client = createGfscClient(tokenEnv(fetchFn), clientOptions)+ const controller = new AbortController()++ await expect(invoke(client, { signal: controller.signal })).resolves.toEqual({ ok: true })+ expect(signals).toEqual([controller.signal])+ })++ it.each(EVERY_METHOD)('M1: %s bounds the retry by the caller deadline', async (_name, invoke) => {+ vi.useFakeTimers()+ const fetchFn = vi.fn(async () => rateLimited('2', 'agent_writes'))+ const client = createGfscClient(tokenEnv(fetchFn), clientOptions)++ // Retry-After 2 s is within maxRetryWaitMs but not within the deadline.+ const error = await Promise.resolve(invoke(client, { deadlineMs: Date.now() + 1500 })).catch(+ e => e+ )+ expect(error).toMatchObject({ status: 429, retryAfterSeconds: 2 })+ expect(fetchFn).toHaveBeenCalledTimes(1)+ expect(vi.getTimerCount()).toBe(0)+ })+it('L17: the retry waits Retry-After plus the injected jitter', async () => {vi.useFakeTimers()const setTimeoutSpy = vi.spyOn(globalThis, 'setTimeout')diff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.jsonindex fa59ea564..09b8aeca9 100644--- a/workflow-recipes/package-lock.json+++ b/workflow-recipes/package-lock.json@@ -1,12 +1,12 @@{"name": "workload-recipes-controller",- "version": "0.1.373",+ "version": "0.1.374","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "workload-recipes-controller",- "version": "0.1.373",+ "version": "0.1.374","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 e989368d5..5d5a68519 100644--- a/workflow-recipes/package.json+++ b/workflow-recipes/package.json@@ -1,6 +1,6 @@{"name": "workload-recipes-controller",- "version": "0.1.373",+ "version": "0.1.374","description": "Workload Recipes Controller (WRC) - WorkloadRecipe lifecycle management and MCP server interface","main": "dist/main.js","engines": {diff --git a/workflow-recipes/src/workflow/gfsOutputPublisher.test.ts b/workflow-recipes/src/workflow/gfsOutputPublisher.test.tsindex f82f2c884..3344eeba9 100644--- a/workflow-recipes/src/workflow/gfsOutputPublisher.test.ts+++ b/workflow-recipes/src/workflow/gfsOutputPublisher.test.ts@@ -162,6 +162,21 @@ describe('publishWorkflowOutputsToGfs', () => {expect(second![1]?.headers).toEqual(first![1]?.headers)})+ it('cancels the denied response body before the retry, so its connection is released', async () => {+ const denied = agentDenied('7')+ const cancel = vi.spyOn(denied.body!, 'cancel')+ const { published, fetchFn } = await publishWith([+ denied,+ jsonResponse({ data: { resourceId: 'created-file' } }, 201),+ ])++ await expect(published).resolves.toBeUndefined()+ // Witness: the retry happened, so the path that must cancel was taken.+ expect(fetchFn).toHaveBeenCalledTimes(2)+ expect(cancel).toHaveBeenCalledTimes(1)+ expect(cancel.mock.invocationCallOrder[0]).toBeLessThan(fetchFn.mock.invocationCallOrder[1]!)+ })+it('fails with the status after a second 429, making exactly two requests', async () => {const { published, fetchFn, sleepFn } = await publishWith([agentDenied('3'),