Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(mcp-host): falsify the shell/GFS decoupling at TaskExecutor level

Alfredo Lopez17bd28bc844a
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index 2e0a546d6..642e04a30 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.504",
+ "version": "0.1.505",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.504",
+ "version": "0.1.505",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@anthropic-ai/sdk": "^0.32.0",
diff --git a/mcp-host/package.json b/mcp-host/package.json
index 3881d4e89..2ba1fba6a 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.504",
+ "version": "0.1.505",
"description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude",
"main": "dist/main.js",
"engines": {
diff --git a/mcp-host/src/agent/__tests__/taskExecutor.gfsExecutionSafety.test.ts b/mcp-host/src/agent/__tests__/taskExecutor.gfsExecutionSafety.test.ts
index 93c0132d2..93a4063db 100644
--- a/mcp-host/src/agent/__tests__/taskExecutor.gfsExecutionSafety.test.ts
+++ b/mcp-host/src/agent/__tests__/taskExecutor.gfsExecutionSafety.test.ts
@@ -1,4 +1,4 @@
-import { afterEach, beforeEach, expect, it, vi } from 'vitest'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { spawn } from 'child_process'
import * as fs from 'node:fs/promises'
import { tmpdir } from 'node:os'
@@ -6,6 +6,7 @@ import { join } from 'node:path'
import { config as appConfig } from '../../config'
import { ConversationManager } from '../../core/conversation/conversation'
import { SimpleEventEmitter } from '../../core/orchestration/eventEmitter'
+import { ShellTool } from '../../core/tools/shell'
import { type ChatMessage, FinishReason, type ToolCall } from '../../core/types'
import { GfsDownloadStore } from '../../internalTools/gfsDownloadStore'
import { TaskLifecycle } from '../../lifecycle/taskLifecycle'
@@ -57,8 +58,11 @@ const savedConfig = {
dynamicToolsEnabled: appConfig.dynamicToolsEnabled,
promptCacheEnabled: appConfig.promptCacheEnabled,
}
+const savedNativeTool = { ...appConfig.nativeTool }
const roots: string[] = []
const stores: GfsDownloadStore[] = []
+/** Spies installed with vi.spyOn by a test; restored before the stores close. */
+const installedSpies: Array<{ mockRestore: () => void }> = []
beforeEach(() => {
Object.assign(appConfig, {
@@ -85,9 +89,11 @@ beforeEach(() => {
})
afterEach(async () => {
+ for (const spy of installedSpies.splice(0)) spy.mockRestore()
for (const store of stores.splice(0)) await store.close().catch(() => undefined)
for (const root of roots.splice(0)) await fs.rm(root, { recursive: true, force: true })
Object.assign(appConfig, savedConfig)
+ Object.assign(appConfig.nativeTool, savedNativeTool)
})
async function unavailableStore() {
@@ -366,3 +372,139 @@ it.each(['cron', 'internal'] as const)(
expect(spawn).not.toHaveBeenCalled()
}
)
+
+// ---------------------------------------------------------------------------
+// Vacuity falsifiers (#1019 / #1021). Before #1019, TaskExecutor built a
+// processing-lease provider from the store and handed it to the shell, so a
+// registry-level test cannot reproduce the pre-#1019 behaviour on its own.
+// These four tests drive TaskExecutor.run() and must go red when every #1019
+// production file is reverted.
+// ---------------------------------------------------------------------------
+
+/**
+ * Spy on every GfsDownloadStore method, enumerated at runtime so a method that
+ * exists only in another revision (the pre-#1019 acquireProcessingLease, for
+ * example) is still covered.
+ */
+function storeSpyNet(store: GfsDownloadStore) {
+ const names = Object.getOwnPropertyNames(GfsDownloadStore.prototype).filter(
+ name =>
+ name !== 'constructor' &&
+ typeof Object.getOwnPropertyDescriptor(GfsDownloadStore.prototype, name)?.value === 'function'
+ )
+ const spies = new Map(
+ names.map(name => {
+ const spy = vi.spyOn(
+ store as unknown as Record<string, (...args: unknown[]) => unknown>,
+ name
+ )
+ installedSpies.push(spy)
+ return [name, spy] as const
+ })
+ )
+ const counts = () => new Map([...spies].map(([name, spy]) => [name, spy.mock.calls.length]))
+ return { names, spies, counts }
+}
+
+/**
+ * Record, for every ShellTool.execute call, the timeout the executor passed and
+ * the store methods called between entering and leaving execute.
+ */
+function shellExecuteWindows(net: ReturnType<typeof storeSpyNet>) {
+ const windows: Array<{ timeoutMs: number | undefined; storeCalls: string[] }> = []
+ const original = ShellTool.prototype.execute
+ const spy = vi.spyOn(ShellTool.prototype, 'execute').mockImplementation(async function (
+ this: ShellTool,
+ params,
+ context
+ ) {
+ const before = net.counts()
+ try {
+ return await original.call(this, params, context)
+ } finally {
+ const after = net.counts()
+ windows.push({
+ timeoutMs: context?.timeoutMs,
+ storeCalls: [...after]
+ .filter(([name, calls]) => calls > (before.get(name) ?? 0))
+ .map(([name]) => name),
+ })
+ }
+ })
+ installedSpies.push(spy)
+ return windows
+}
+
+it('X1-shell: an inherited legacy lease does not stop an approved shell (#1019)', async () => {
+ const scenario = await shellScenario({
+ source: 'channel',
+ legacyLease: true,
+ channelCaller: true,
+ })
+ await scenario.executor.run()
+ // Witness: the executor reached the live approval gate for shell_exec.
+ expect(scenario.onApprovalNeeded).toHaveBeenCalledTimes(1)
+
+ await scenario.executor.resumeAfterApproval(false)
+
+ // Claim: the approved command spawned in the caller root and its stdout returned.
+ expect(spawn).toHaveBeenCalledOnce()
+ expect(vi.mocked(spawn).mock.calls[0]![2]).toMatchObject({ cwd: scenario.callerWorkspace })
+ expect(JSON.stringify(scenario.providerCalls.at(-1))).toContain(scenario.callerWorkspace)
+ expect(scenario.onFail).not.toHaveBeenCalled()
+})
+
+it('X1-delivery: an inherited legacy lease is discarded and GFS delivery stays advertised (#1019)', async () => {
+ const scenario = await shellScenario({
+ source: 'channel',
+ legacyLease: true,
+ channelCaller: true,
+ })
+ await scenario.executor.run()
+ // Witness: the provider received a tool list built by the executor's registry.
+ expect(scenario.advertisedTools.length).toBeGreaterThan(0)
+ expect(scenario.advertisedTools[0]).toContain('shell_exec')
+ // Claim: delivery is advertised because the store came up available.
+ expect(scenario.advertisedTools[0]).toContain('clerum__gfs_download')
+ expect(scenario.store.isAvailable()).toBe(true)
+})
+
+describe('U5-TE: TaskExecutor runs a managed shell with a timeout above the former lease ceiling (#1021)', () => {
+ it.each([
+ ['exactly one hour', 3_600_000],
+ ['one millisecond over one hour', 3_600_001],
+ ])('%s', async (_label, timeoutMs) => {
+ Object.assign(appConfig.nativeTool, { shellTimeout: timeoutMs, toolTimeout: timeoutMs })
+ const scenario = await shellScenario({ source: 'cron', healthy: true })
+ const windows = shellExecuteWindows(storeSpyNet(scenario.store))
+
+ await scenario.executor.run()
+
+ // Witness: the effective timeout reached ShellTool.execute unchanged.
+ expect(windows).toHaveLength(1)
+ expect(windows[0]!.timeoutMs).toBe(timeoutMs)
+ // Claim: the command spawned and its stdout reached the model.
+ expect(spawn).toHaveBeenCalledOnce()
+ expect(JSON.stringify(scenario.providerCalls.at(-1))).toContain(scenario.callerWorkspace)
+ expect(scenario.onFail).not.toHaveBeenCalled()
+ })
+})
+
+it('X3-TE: a shell run inside TaskExecutor makes zero GFS download store calls (#1019)', async () => {
+ const scenario = await shellScenario({ source: 'cron', healthy: true })
+ const net = storeSpyNet(scenario.store)
+ const windows = shellExecuteWindows(net)
+
+ await scenario.executor.run()
+
+ // Witnesses: the net is attached to the store instance the executor wired
+ // (isAvailable is read while the registry is built), the shell window opened
+ // once, and the command's stdout reached the model.
+ expect(net.names).toContain('isAvailable')
+ expect(net.spies.get('isAvailable')!.mock.calls.length).toBeGreaterThan(0)
+ expect(windows).toHaveLength(1)
+ expect(spawn).toHaveBeenCalledOnce()
+ expect(JSON.stringify(scenario.providerCalls.at(-1))).toContain(scenario.callerWorkspace)
+ // Claim: no store method ran while the shell executed.
+ expect(windows[0]!.storeCalls).toEqual([])
+})
diff --git a/mcp-host/src/core/tools/__tests__/nativeToolRegistry.shellStoreDecoupling.test.ts b/mcp-host/src/core/tools/__tests__/nativeToolRegistry.shellStoreDecoupling.test.ts
index 1c69bdf7a..eda0f04b3 100644
--- a/mcp-host/src/core/tools/__tests__/nativeToolRegistry.shellStoreDecoupling.test.ts
+++ b/mcp-host/src/core/tools/__tests__/nativeToolRegistry.shellStoreDecoupling.test.ts
@@ -11,6 +11,13 @@ import { NativeToolRegistry } from '../nativeToolRegistry'
// GFS download store. These tests run shell_exec through the real registry with
// a real initialized store, and through the same timeout boundary the tool loop
// uses (toolUseLoopSingleTool -> executeWithTimeout).
+//
+// They are unit coverage of the decoupled registry contract only. The registry
+// is given no processing-lease provider here, so they stay green when #1019 is
+// reverted: before #1019 TaskExecutor built that provider. The vacuity
+// falsifiers that do go red under that revert are the TaskExecutor-level
+// X1-shell, X1-delivery, U5-TE and X3-TE in
+// src/agent/__tests__/taskExecutor.gfsExecutionSafety.test.ts.
const hosts: string[] = []
const stores: GfsDownloadStore[] = []
@@ -81,7 +88,7 @@ function storeMethodNames(): string[] {
)
}
-describe('managed shell_exec without the GFS download store (#1019)', () => {
+describe('managed shell_exec without the GFS download store (#1019), registry-level unit coverage', () => {
it.each([
['just under one hour', 3_594_000, 3_594_000],
['exactly one hour', 3_600_000, 3_600_000],
diff --git a/mcp-host/src/core/tools/__tests__/shell.test.ts b/mcp-host/src/core/tools/__tests__/shell.test.ts
index e912efaa9..ee7372975 100644
--- a/mcp-host/src/core/tools/__tests__/shell.test.ts
+++ b/mcp-host/src/core/tools/__tests__/shell.test.ts
@@ -587,10 +587,25 @@ describe('ShellTool without the GFS download store (#1019)', () => {
const pidFile = join(workspacePath, 'cancel.pid')
const controller = new AbortController()
const tool = new ShellTool(workspacePath, 30_000, ['PATH'])
+ // The pid file is written before `printf started`, so aborting as soon as
+ // it exists can race the stdout read. Abort only after the tool has
+ // streamed "started", which it retains before calling onOutput.
+ let streamed = ''
+ let markStarted!: () => void
+ const started = new Promise<void>(resolve => {
+ markStarted = resolve
+ })
const execution = tool.execute(
{ command: `${background(pidFile)} wait` },
- { signal: controller.signal, onOutput: () => {} }
+ {
+ signal: controller.signal,
+ onOutput: chunk => {
+ streamed += chunk
+ if (streamed.includes('started')) markStarted()
+ },
+ }
)
+ await started
const grandchild = Number(await waitForFile(pidFile))
controller.abort(new Error('user cancelled'))
const result = await execution
diff --git a/mcp-host/src/internalTools/gfsDownloadStoreRecovery.test.ts b/mcp-host/src/internalTools/gfsDownloadStoreRecovery.test.ts
index f75f3b1b1..3cb2a8ed1 100644
--- a/mcp-host/src/internalTools/gfsDownloadStoreRecovery.test.ts
+++ b/mcp-host/src/internalTools/gfsDownloadStoreRecovery.test.ts
@@ -205,13 +205,14 @@ describe('legacy processing leases after #1019', () => {
const before = await counterValue(DISCARDED_COUNTER)
const reopened = freshStore()
await reopened.initialize()
+ // The persisted discard is the claim; the counter and the log follow it.
+ const onDisk = JSON.parse(await fs.readFile(ledgerFile(), 'utf8'))
+ expect(onDisk.records).toEqual({})
+ expect(onDisk).not.toHaveProperty('processingLeases')
expect((await counterValue(DISCARDED_COUNTER)) - before).toBe(1)
expect(discardWarnings(warn.mock.calls)).toEqual([
[{ discarded: 1 }, 'GFS download store discarded 1 legacy processing lease(s) at initialize'],
])
- const onDisk = JSON.parse(await fs.readFile(ledgerFile(), 'utf8'))
- expect(onDisk.records).toEqual({})
- expect(onDisk).not.toHaveProperty('processingLeases')
expect(reopened.isAvailable()).toBe(true)
const receipt = await fixture(reopened)
expect(reopened.debugRecord(receipt.id)?.state).toBe('completed')
@@ -234,6 +235,9 @@ describe('legacy processing leases after #1019', () => {
const before = await counterValue(DISCARDED_COUNTER)
const reopened = freshStore()
await reopened.initialize()
+ const onDisk = JSON.parse(await fs.readFile(ledgerFile(), 'utf8'))
+ expect(onDisk).not.toHaveProperty('processingLeases')
+ expect(Object.keys(onDisk.records).sort()).toEqual([intact.id, altered.id].sort())
expect((await counterValue(DISCARDED_COUNTER)) - before).toBe(1)
expect(reopened.isAvailable()).toBe(true)
expect(await reopened.reusableReceipt('caller-a', source, 7)).toMatchObject({
@@ -276,6 +280,9 @@ describe('legacy processing leases after #1019', () => {
await reopened.initialize()
expect(reopened.isAvailable()).toBe(true)
expect(reopened.debugUsage()).toMatchObject({ bytes: 7, files: 1 })
+ const onDisk = JSON.parse(await fs.readFile(ledgerFile(), 'utf8'))
+ expect(onDisk).not.toHaveProperty('processingLeases')
+ expect(Object.keys(onDisk.records)).toHaveLength(1)
expect((await counterValue(DISCARDED_COUNTER)) - before).toBe(0)
expect(discardWarnings(warn.mock.calls)).toEqual([])
})
@@ -338,11 +345,11 @@ describe('legacy processing leases after #1019', () => {
const retried = freshStore()
await retried.initialize()
expect(retried.isAvailable()).toBe(true)
- expect((await counterValue(DISCARDED_COUNTER)) - before).toBe(1)
- expect(discardWarnings(warn.mock.calls)).toHaveLength(1)
expect(JSON.parse(await fs.readFile(ledgerFile(), 'utf8'))).not.toHaveProperty(
'processingLeases'
)
+ expect((await counterValue(DISCARDED_COUNTER)) - before).toBe(1)
+ expect(discardWarnings(warn.mock.calls)).toHaveLength(1)
})
it('S9: counts and logs records an earlier boot quarantined', async () => {