Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(mcp-host): make GFS writer-retry test deterministic and size default-cap store timeouts
Alfredo Lopez5afbee61fd3b
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex b8d39b9eb..2e0a546d6 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.503",+ "version": "0.1.504","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.503",+ "version": "0.1.504","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex 7af022fab..3881d4e89 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.503",+ "version": "0.1.504","description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude","main": "dist/main.js","engines": {diff --git a/mcp-host/src/__tests__/gfsRuntime.test.ts b/mcp-host/src/__tests__/gfsRuntime.test.tsindex 2b7b7f65d..f63acea2e 100644--- a/mcp-host/src/__tests__/gfsRuntime.test.ts+++ b/mcp-host/src/__tests__/gfsRuntime.test.ts@@ -57,12 +57,42 @@ describe('GFS runtime bootstrap', () => {.mockImplementation(async () => {cleanupStarted.resolve()})+ // Fake timers keep each retry out of the old writer's close(). With real+ // timers a 25 ms retry can start verifying the in-process prior owner and+ // see it release mid-verification; that is classified as ambiguous+ // ownership (non-transient), the retry ends in recovery-required state and+ // cleanup never starts. Under host load this hung the test until the 5 s+ // timeout. Store I/O stays real; only the retry schedule is controlled.+ vi.useFakeTimers()+ const initialize = vi.spyOn(GfsDownloadStore.prototype, 'initialize')const runtime = await bootstrapGfsRuntime(value, { retryDelayMs: 25, maxRetryAttempts: 40 })runtimes.push(runtime)expect(runtime.store.isAvailable()).toBe(false)expect(cleanup).not.toHaveBeenCalled()+ await expect(initialize.mock.results[0]!.value).rejects.toMatchObject({+ code: 'writer_locked',+ transientWriterContention: true,+ })+ expect(vi.getTimerCount()).toBe(1)++ // A retry while the old writer still holds stays verified contention and+ // schedules the next retry instead of ending the supervision.+ await vi.advanceTimersByTimeAsync(25)+ expect(initialize).toHaveBeenCalledTimes(2)+ await expect(initialize.mock.results[1]!.value).rejects.toMatchObject({+ code: 'writer_locked',+ transientWriterContention: true,+ })+ // The settled rejection reschedules through promise callbacks only; flush+ // microtasks without advancing the fake clock.+ for (let turn = 0; turn < 20 && vi.getTimerCount() === 0; turn += 1) await Promise.resolve()+ expect(vi.getTimerCount()).toBe(1)+ expect(runtime.store.isAvailable()).toBe(false)+ expect(cleanup).not.toHaveBeenCalled()await first.close()+ await vi.advanceTimersByTimeAsync(25)+ expect(initialize).toHaveBeenCalledTimes(3)await cleanupStarted.promiseexpect(runtime.store.isAvailable()).toBe(true)expect(cleanup).toHaveBeenCalledOnce()diff --git a/mcp-host/src/internalTools/gfsDownloadStoreAdversarialQuota.test.ts b/mcp-host/src/internalTools/gfsDownloadStoreAdversarialQuota.test.tsindex 64bad0adf..b7d17039c 100644--- a/mcp-host/src/internalTools/gfsDownloadStoreAdversarialQuota.test.ts+++ b/mcp-host/src/internalTools/gfsDownloadStoreAdversarialQuota.test.ts@@ -53,6 +53,19 @@ function future(ms = 60_000): string {const CALLER = 'caller-a'+/**+ * Timeout for tests that publish the full default host retained-file cap (64+ * records). Each publication is durable on purpose: about 5.4 fsyncs and 6.3+ * writer-ownership verifications per record, constant per record (no growth+ * with ledger size). Measured on the development host for 64 one-byte+ * publications: 3.2-8.9 s at load average 27-38, worst 13.2 s at load 37;+ * fsync alone is 46-54% of it. In the full suite with 7 extra busy processes+ * (load average 37-68) these tests took 11.3 s and 13.4 s. The default 5 s+ * timeout cannot hold that work under load, and fewer records would no longer+ * reach the default cap.+ */+const DEFAULT_CAP_PUBLICATION_TIMEOUT_MS = 30_000+let hostRoot: stringlet callerRoot: stringlet store: GfsDownloadStore@@ -263,31 +276,35 @@ describe('GFS download store adversarial quota', () => {await store.releaseReceiptOwner('byte-owner', CALLER)})- it('denies the 65th pinned record at the host retained-file cap', async () => {- const callers: string[] = []- for (let callerIndex = 0; callerIndex < 8; callerIndex += 1) {- const caller = `caller-${callerIndex}`- const root = await callerDirectory(hostRoot, caller)- callers.push(caller)- for (let file = 0; file < GFS_FILE_LIMITS.callerRetainedFiles; file += 1) {- await completedCopy(store, root, caller, callerIndex * 10 + file, 1, 1, `${caller}-owner`)+ it(+ 'denies the 65th pinned record at the host retained-file cap',+ async () => {+ const callers: string[] = []+ for (let callerIndex = 0; callerIndex < 8; callerIndex += 1) {+ const caller = `caller-${callerIndex}`+ const root = await callerDirectory(hostRoot, caller)+ callers.push(caller)+ for (let file = 0; file < GFS_FILE_LIMITS.callerRetainedFiles; file += 1) {+ await completedCopy(store, root, caller, callerIndex * 10 + file, 1, 1, `${caller}-owner`)+ }}- }- expect(store.debugUsage()).toMatchObject({ files: 64 })+ expect(store.debugUsage()).toMatchObject({ files: 64 })- const freshRoot = await callerDirectory(hostRoot, 'caller-z')- await expect(- store.createTransfer({- callerIdentity: 'caller-z',- callerWorkspacePath: freshRoot,- source: sourceFor(999, 1),- sizeBytes: 1,- expiresAt: future(),- })- ).rejects.toMatchObject({ code: 'host_quota_exceeded' })- expect(store.debugUsage()).toMatchObject({ files: 64 })- for (const caller of callers) await store.releaseReceiptOwner(`${caller}-owner`, caller)- })+ const freshRoot = await callerDirectory(hostRoot, 'caller-z')+ await expect(+ store.createTransfer({+ callerIdentity: 'caller-z',+ callerWorkspacePath: freshRoot,+ source: sourceFor(999, 1),+ sizeBytes: 1,+ expiresAt: future(),+ })+ ).rejects.toMatchObject({ code: 'host_quota_exceeded' })+ expect(store.debugUsage()).toMatchObject({ files: 64 })+ for (const caller of callers) await store.releaseReceiptOwner(`${caller}-owner`, caller)+ },+ DEFAULT_CAP_PUBLICATION_TIMEOUT_MS+ )it('rolls back charge, owner pins, and active slots when mkdir fails with proven absence', async () => {await fs.chmod(callerRoot, 0o500)@@ -746,31 +763,36 @@ describe('GFS download store physical capacity and reclaim', () => {await target.releaseReceiptOwner(`${identity}-owner`, identity)})- it('keeps all default-cap small copies when current physical capacity is zero', async () => {- const { root, store: target } = await setup({- MCP_HOST_GFS_MAX_FILE_BYTES: '1024',- MCP_HOST_GFS_DOWNLOAD_STORAGE_BYTES: String(1024 * 1024),- MCP_HOST_GFS_CALLER_DOWNLOAD_STORAGE_BYTES: String(128 * 1024),- })- const receipts = []- for (let index = 0; index < 8; index++) {- const identity = `caller-${index}`- const directory = await callerDirectory(root, identity)- for (let file = 0; file < 8; file++) receipts.push(await copy(target, directory, identity, 1))- }- await capacity(root, 0)- await expect(- target.createTransfer({- callerIdentity: 'caller-new',- callerWorkspacePath: await callerDirectory(root, 'caller-new'),- source: capacitySource,- sizeBytes: 1,- expiresAt: future(),+ it(+ 'keeps all default-cap small copies when current physical capacity is zero',+ async () => {+ const { root, store: target } = await setup({+ MCP_HOST_GFS_MAX_FILE_BYTES: '1024',+ MCP_HOST_GFS_DOWNLOAD_STORAGE_BYTES: String(1024 * 1024),+ MCP_HOST_GFS_CALLER_DOWNLOAD_STORAGE_BYTES: String(128 * 1024),})- ).rejects.toMatchObject({ code: 'host_quota_exceeded' })- expect(target.debugUsage().files).toBe(64)- for (const receipt of receipts) expect(target.debugRecord(receipt.id)).toBeDefined()- })+ const receipts = []+ for (let index = 0; index < 8; index++) {+ const identity = `caller-${index}`+ const directory = await callerDirectory(root, identity)+ for (let file = 0; file < 8; file++)+ receipts.push(await copy(target, directory, identity, 1))+ }+ await capacity(root, 0)+ await expect(+ target.createTransfer({+ callerIdentity: 'caller-new',+ callerWorkspacePath: await callerDirectory(root, 'caller-new'),+ source: capacitySource,+ sizeBytes: 1,+ expiresAt: future(),+ })+ ).rejects.toMatchObject({ code: 'host_quota_exceeded' })+ expect(target.debugUsage().files).toBe(64)+ for (const receipt of receipts) expect(target.debugRecord(receipt.id)).toBeDefined()+ },+ DEFAULT_CAP_PUBLICATION_TIMEOUT_MS+ )it('respects pending active reservations before any cache-pressure effect', async () => {const { root, store: target } = await setup({ MCP_HOST_GFS_CALLER_DOWNLOAD_MAX_FILES: '1' })