Skip to content

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

TypeScript

test(mcp-host): close GFS store coverage gaps from the audit

Alfredo Lopez53520aa75260
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index 994f2ae00..f9164e0e4 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.525",
+ "version": "0.1.527",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.525",
+ "version": "0.1.527",
"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 ee3e5cf46..bc2473f04 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.525",
+ "version": "0.1.527",
"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.ts
index 35c100b5c..bc33ea084 100644
--- a/mcp-host/src/__tests__/gfsRuntime.test.ts
+++ b/mcp-host/src/__tests__/gfsRuntime.test.ts
@@ -128,13 +128,37 @@ describe('GFS runtime bootstrap', () => {
vi.setSystemTime(Date.now() + 120_000)
+ // The name disappears at the rename to `.trash-<uuid>`; the removal is
+ // counted only after the rm is proven, so both are awaited together.
await vi.waitFor(
async () => {
await expect(fs.lstat(directory)).rejects.toMatchObject({ code: 'ENOENT' })
+ expect(await expiryCount('expired_removed')).toBe(removed + 1)
},
{ timeout: 5_000, interval: 10 }
)
- expect(await expiryCount('expired_removed')).toBe(removed + 1)
+ })
+
+ it('a cleanup that throws is logged and the next cycle sweeps again', async () => {
+ const runtime = await start(await root(), 25)
+ const warn = vi.spyOn(logger, 'warn')
+ const cleanup = vi
+ .spyOn(GfsDownloadStore.prototype, 'cleanupExpired')
+ .mockImplementationOnce(async () => {
+ throw Object.assign(new Error('injected EIO'), { code: 'EIO' })
+ })
+
+ // Witness: a second cycle reached cleanup after the first one threw.
+ await vi.waitFor(() => expect(cleanup.mock.calls.length).toBeGreaterThanOrEqual(2), {
+ timeout: 5_000,
+ interval: 10,
+ })
+
+ expect(warn).toHaveBeenCalledWith(
+ { component: 'gfs-runtime', code: 'EIO' },
+ 'GFS download cleanup failed; the next cycle retries it'
+ )
+ expect(runtime.store.isAvailable()).toBe(true)
})
it('stop joins the cycle in flight and closes the store', async () => {
diff --git a/mcp-host/src/agent/__tests__/callerRootBinding.test.ts b/mcp-host/src/agent/__tests__/callerRootBinding.test.ts
index fa2ce5248..8ebfed11a 100644
--- a/mcp-host/src/agent/__tests__/callerRootBinding.test.ts
+++ b/mcp-host/src/agent/__tests__/callerRootBinding.test.ts
@@ -70,10 +70,10 @@ describe('degraded GFS caller-root binding', () => {
it('keeps ordinary text running while managed file/shell roots fail closed', async () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'gfs-degraded-binding-'))
try {
- fs.mkdirSync(path.join(root, '.gfs-download-store'), { recursive: true })
- fs.writeFileSync(path.join(root, '.gfs-download-store', 'ledger-v1.json'), '{invalid')
+ // `users` as a file: the store starts, but no caller root can be bound.
fs.writeFileSync(path.join(root, 'users'), 'not-a-directory', 'utf-8')
const runtime = await bootstrapGfsRuntime(root)
+ expect(runtime.store.isAvailable()).toBe(true)
const queue = new MessageQueue()
const lifecycle = new TaskLifecycle()
const agent = new AgentStateMachine(queue, lifecycle, { autoStart: false, taskDelay: 0 })
@@ -116,10 +116,10 @@ describe('degraded GFS caller-root binding', () => {
it('keeps real incoming admission dispatching when the GFS caller root is degraded', async () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'gfs-degraded-admission-'))
try {
- fs.mkdirSync(path.join(root, '.gfs-download-store'), { recursive: true })
- fs.writeFileSync(path.join(root, '.gfs-download-store', 'ledger-v1.json'), '{invalid')
+ // `users` as a file: the store starts, but no caller root can be bound.
fs.writeFileSync(path.join(root, 'users'), 'not-a-directory', 'utf-8')
const runtime = await bootstrapGfsRuntime(root)
+ expect(runtime.store.isAvailable()).toBe(true)
const reference = buildGfsFileReference({
drive: 'main',
resourceId: 'a'.repeat(32),
@@ -135,6 +135,7 @@ describe('degraded GFS caller-root binding', () => {
}),
})
if (!reference.ok) throw new Error(reference.message)
+ const bindingRoots: unknown[] = []
const dispatch = vi.fn(() => ({
success: true,
taskId: 'task-1',
@@ -153,6 +154,7 @@ describe('degraded GFS caller-root binding', () => {
fileReferenceGfs: () => ({ status: 'unsupported' }),
gfsSurfaceRuntimeCapability: message => {
const binding = resolveCallerRootBinding(runtime.workspaceProvider, message)
+ bindingRoots.push(binding.root)
const workspaceFile = Boolean(runtime.store.isAvailable() && binding.root)
return { workspaceFile, localExecutor: workspaceFile, visual: false }
},
@@ -173,6 +175,9 @@ describe('degraded GFS caller-root binding', () => {
expect(response).toMatchObject({ success: true, taskId: 'task-1' })
expect(dispatch).toHaveBeenCalledTimes(1)
+ // Witness: admission asked for the caller root and the binding failed closed.
+ expect(bindingRoots.length).toBeGreaterThan(0)
+ expect(bindingRoots.every(bound => !bound)).toBe(true)
} finally {
fs.rmSync(root, { recursive: true, force: true })
}
diff --git a/mcp-host/src/agent/__tests__/gfsExecutionCapability.test.ts b/mcp-host/src/agent/__tests__/gfsExecutionCapability.test.ts
index 0c0b54c8d..00976c4e0 100644
--- a/mcp-host/src/agent/__tests__/gfsExecutionCapability.test.ts
+++ b/mcp-host/src/agent/__tests__/gfsExecutionCapability.test.ts
@@ -36,7 +36,7 @@ describe('gfsWorkspaceExecutionEnabled', () => {
).toBe(true)
})
- it('rejects delivery while the Host store is in recovery-required state', () => {
+ it('rejects delivery while the Host store is unavailable', () => {
expect(
gfsWorkspaceExecutionEnabled(
input({
diff --git a/mcp-host/src/agent/gfsExecutionCapability.ts b/mcp-host/src/agent/gfsExecutionCapability.ts
index 316797c7c..c7aee1f07 100644
--- a/mcp-host/src/agent/gfsExecutionCapability.ts
+++ b/mcp-host/src/agent/gfsExecutionCapability.ts
@@ -53,7 +53,7 @@ export function gfsWorkspaceExecutionEnabled(
* Associate every executable registry with the Host GFS store independently of
* download eligibility. Shell never falls back to the shared Host root while a
* store exists and fails closed without a caller root. Shell never calls the
- * store (#1019), so a recovery-required store only disables delivery.
+ * store (#1019), so an unavailable store only disables delivery.
*/
export function gfsManagedWorkspaceExecution(
input: GfsExecutionCapabilityInput
diff --git a/mcp-host/src/core/tools/nativeToolRegistry.ts b/mcp-host/src/core/tools/nativeToolRegistry.ts
index f9f8ac7d8..380783a46 100644
--- a/mcp-host/src/core/tools/nativeToolRegistry.ts
+++ b/mcp-host/src/core/tools/nativeToolRegistry.ts
@@ -205,7 +205,7 @@ export class NativeToolRegistry implements ToolRegistry {
// existing positional call sites stay valid; only taskExecutor passes it.
activeLlmProvider?: LlmProvider,
gfsDownload?: {
- /** Omitted when the durable store is recovery-required; delivery then fails closed. */
+ /** Omitted when the Host has no download store or it is unavailable; delivery then fails closed. */
store?: GfsDownloadStore
/** True only for attended, policy-eligible, healthy workspace delivery. */
deliveryAvailable: boolean
diff --git a/mcp-host/src/internalTools/gfsDownloadStore.test.ts b/mcp-host/src/internalTools/gfsDownloadStore.test.ts
index 17b32cd0e..6603312af 100644
--- a/mcp-host/src/internalTools/gfsDownloadStore.test.ts
+++ b/mcp-host/src/internalTools/gfsDownloadStore.test.ts
@@ -306,6 +306,42 @@ describe('GFS download store: publication', () => {
expect(next.receipt.sha256).toBe(digest(next.bytes))
await expect(store.readManagedFile(next.receipt.path, CALLER)).resolves.toEqual(next.bytes)
})
+
+ it('F4b: a temporary meta.json that cannot be removed after a failed publish is logged, not swallowed', async () => {
+ const { transfer, bytes } = await startTransfer(store, callerRoot, CALLER, 3, 16)
+ renameBoundary.mockImplementationOnce(async () => {
+ throw Object.assign(new Error('injected EIO'), { code: 'EIO' })
+ })
+ rmBoundary.mockImplementation(async (target: string, options: unknown) => {
+ if (path.basename(target).startsWith('meta.json.tmp-'))
+ throw Object.assign(new Error('injected EACCES'), { code: 'EACCES' })
+ return nativeFs.rm(target, options as Parameters<typeof nativeFs.rm>[1])
+ })
+ const warn = vi.spyOn(logger, 'warn')
+
+ await expect(store.publish(transfer.id, CALLER, digest(bytes))).rejects.toMatchObject({
+ code: 'storage_write_failed',
+ })
+
+ // Witness: the cleanup attempted the temporary file and failed.
+ const directory = downloadDirectory(callerRoot, transfer.id)
+ const leftover = (await nativeFs.readdir(directory)).filter(name =>
+ name.startsWith('meta.json.tmp-')
+ )
+ expect(leftover).toHaveLength(1)
+ expect(rmBoundary).toHaveBeenCalledWith(
+ expect.stringMatching(new RegExp(`/input-${transfer.id}/${leftover[0]!}$`)),
+ { force: true }
+ )
+ // The log line carries the errno code only, never the path.
+ expect(warn).toHaveBeenCalledWith(
+ { component: 'GfsDownloadStore', code: 'EACCES' },
+ expect.stringContaining('could not remove a temporary meta.json')
+ )
+ rmBoundary.mockImplementation(nativeFs.rm)
+ await store.fail(transfer.id, CALLER)
+ expect(await exists(directory)).toBe(false)
+ })
})
describe('GFS download store: reuse', () => {
@@ -339,6 +375,28 @@ describe('GFS download store: reuse', () => {
vi.setSystemTime(Date.now() + 2 * 60 * 60_000)
await expect(store.reusableReceipt(CALLER, sourceFor(8), 12)).resolves.toBeUndefined()
})
+
+ it("F7b: another caller's reuse lookup never hashes or removes a copy it does not own", async () => {
+ const { receipt } = await completedCopy(store, callerRoot, CALLER, 9, 24)
+ const directory = downloadDirectory(callerRoot, receipt.id)
+ // Same size, different content: only a hash can tell the copy is corrupt.
+ await nativeFs.writeFile(path.join(directory, 'source'), Buffer.alloc(24, 0xee))
+ const removedBefore = await expiryCount('incomplete_removed')
+ hashBoundary.mockClear()
+
+ await expect(store.reusableReceipt('caller-b', sourceFor(9), 24)).resolves.toBeUndefined()
+
+ expect(hashBoundary).not.toHaveBeenCalled()
+ expect(await exists(path.join(directory, 'source'))).toBe(true)
+ expect(await expiryCount('incomplete_removed')).toBe(removedBefore)
+
+ // Witness: the owner's identical lookup reaches the copy, hashes it and
+ // removes it, so the lookup above was answered by the caller filter.
+ await expect(store.reusableReceipt(CALLER, sourceFor(9), 24)).resolves.toBeUndefined()
+ expect(hashBoundary).toHaveBeenCalledTimes(1)
+ expect(await exists(directory)).toBe(false)
+ expect(await expiryCount('incomplete_removed')).toBe(removedBefore + 1)
+ })
})
/** The smallest limits the policy accepts with two callers' worth of Host storage. */
@@ -409,6 +467,46 @@ describe('GFS download store: quotas and eviction', () => {
expect(await quotaCount('caller', 'retained_files')).toBe(denied + 1)
})
+ it("F10b: a quota denial carries only its code, never another caller's id, path, name or usage", async () => {
+ const { limited } = await limitedStore(HOST_30_CALLER_15)
+ const otherRoot = await callerDirectory(hostRoot, 'caller-b')
+ const thirdRoot = await callerDirectory(hostRoot, 'caller-c')
+ const other = await completedCopy(limited, otherRoot, 'caller-b', 24, 10, { owner: 'task-b' })
+ const third = await completedCopy(limited, thirdRoot, 'caller-c', 25, 10, { owner: 'task-c' })
+ await completedCopy(limited, callerRoot, CALLER, 28, 5, { owner: 'task-a' })
+
+ // Within maxFileBytes (10) and caller-a's 15; the Host would reach 35 of 30
+ // and every copy is pinned, so only the Host quota decision can refuse it.
+ const error = await startTransfer(limited, callerRoot, CALLER, 26, 10).then(
+ () => undefined,
+ (rejection: unknown) => rejection
+ )
+
+ // The re-imported module registers its metrics elsewhere; the fitting
+ // admission at the end is the witness that this was the quota decision.
+ expect(error).toMatchObject({ code: 'host_quota_exceeded' })
+ const visible = error as Error & Record<string, unknown>
+ expect(Object.keys(visible).sort()).toEqual(['code', 'name'])
+ expect(visible.message).toBe('GFS download store failed (host_quota_exceeded)')
+ const serialized = JSON.stringify({ ...visible, message: visible.message })
+ for (const secret of [
+ 'caller-b',
+ 'caller-c',
+ otherRoot,
+ thirdRoot,
+ other.receipt.id,
+ third.receipt.id,
+ 'fixture-24',
+ 'fixture-25',
+ 'task-b',
+ 'task-c',
+ ])
+ expect(serialized).not.toContain(secret)
+ expect(await exists(downloadDirectory(otherRoot, other.receipt.id))).toBe(true)
+ // Neither size nor free space was the cause: 5 bytes fit the Host's 30 exactly.
+ await expect(startTransfer(limited, callerRoot, CALLER, 27, 5)).resolves.toBeDefined()
+ })
+
it('F11: pinned and active downloads are never evicted', async () => {
const { limited } = await limitedStore({
...HOST_30_CALLER_15,
@@ -523,24 +621,33 @@ describe('GFS download store: sweep', () => {
const wrongSize = await handMadeDirectory(callerRoot)
await writeMeta(wrongSize.directory, metaFor(wrongSize.id, bytes))
await nativeFs.writeFile(path.join(wrongSize.directory, 'source'), Buffer.alloc(21, 3))
+ // A crash while meta.json was being written leaves its temporary name.
+ const temporaryMeta = await handMadeDirectory(callerRoot)
+ await nativeFs.writeFile(path.join(temporaryMeta.directory, 'source.partial'), bytes)
+ await nativeFs.writeFile(
+ path.join(temporaryMeta.directory, `meta.json.tmp-${nativeCrypto.randomUUID()}`),
+ JSON.stringify(metaFor(temporaryMeta.id, bytes)),
+ { mode: 0o600 }
+ )
for (const shape of [
orphanPartial,
metaWithoutSource,
sourceWithoutMeta,
invalidMeta,
wrongSize,
+ temporaryMeta,
])
shapes.push(shape.directory)
const removed = await expiryCount('incomplete_removed')
await expect(store.cleanupExpired()).resolves.toEqual({
removedExpired: 0,
- removedIncomplete: 5,
+ removedIncomplete: 6,
removeFailed: 0,
})
for (const directory of shapes) expect(await exists(directory)).toBe(false)
- expect(await expiryCount('incomplete_removed')).toBe(removed + 5)
+ expect(await expiryCount('incomplete_removed')).toBe(removed + 6)
// Witness: the complete download stays on disk and readable through the index.
await expect(store.readManagedFile(kept.receipt.path, CALLER)).resolves.toEqual(kept.bytes)
})
@@ -633,6 +740,32 @@ describe('GFS download store: sweep', () => {
await expect(store.cleanupExpired()).resolves.toMatchObject({ removedIncomplete: 1 })
expect(await exists(path.join(downloads, leftover[0]!))).toBe(false)
})
+
+ it("F20b: a caller's unreadable download directory is counted and logged, and the store stays available", async () => {
+ const downloads = path.join(callerRoot, '.gfs-downloads')
+ await nativeFs.mkdir(downloads, { mode: 0o700 })
+ const warn = vi.spyOn(logger, 'warn')
+ const failed = await expiryCount('sweep_failed')
+ await nativeFs.chmod(downloads, 0o000)
+ try {
+ await expect(store.cleanupExpired()).resolves.toMatchObject({ removeFailed: 0 })
+
+ expect(await expiryCount('sweep_failed')).toBe(failed + 1)
+ expect(warn).toHaveBeenCalledWith(
+ { component: 'GfsDownloadStore', code: 'EACCES' },
+ expect.stringContaining('could not list a download directory')
+ )
+ expect(store.isAvailable()).toBe(true)
+ // Witness: another caller still gets a download admitted and published.
+ const otherRoot = await callerDirectory(hostRoot, 'caller-b')
+ const other = await completedCopy(store, otherRoot, 'caller-b', 112, 8)
+ await expect(store.readManagedFile(other.receipt.path, 'caller-b')).resolves.toEqual(
+ other.bytes
+ )
+ } finally {
+ await nativeFs.chmod(downloads, 0o700)
+ }
+ })
})
describe('GFS download store: managed reads', () => {
@@ -692,6 +825,49 @@ describe('GFS download store: managed reads', () => {
code: 'download_missing',
})
})
+
+ it('F23b: a kubelet fsGroup expansion is restored to the private modes after the content is re-hashed', async () => {
+ const { receipt, bytes } = await completedCopy(store, callerRoot, CALLER, 124, 20)
+ const directory = downloadDirectory(callerRoot, receipt.id)
+ const source = path.join(directory, 'source')
+ await nativeFs.chmod(source, 0o660)
+ await nativeFs.chmod(directory, 0o2770)
+ hashBoundary.mockClear()
+
+ // The prefix read hashes nothing on its own, so a hash here is the
+ // fsGroup branch verifying the content before it restores the mode.
+ await expect(store.readManagedFilePrefix(receipt.path, CALLER, 8)).resolves.toEqual(
+ bytes.subarray(0, 8)
+ )
+
+ expect(hashBoundary).toHaveBeenCalledTimes(1)
+ expect((await nativeFs.stat(source)).mode & 0o7777).toBe(0o600)
+ expect((await nativeFs.stat(directory)).mode & 0o7777).toBe(0o700)
+ await expect(store.readManagedFile(receipt.path, CALLER)).resolves.toEqual(bytes)
+ })
+
+ it('F23c: an fsGroup-expanded source whose content changed is not restored or served', async () => {
+ const { receipt } = await completedCopy(store, callerRoot, CALLER, 125, 20)
+ const directory = downloadDirectory(callerRoot, receipt.id)
+ const source = path.join(directory, 'source')
+ await nativeFs.writeFile(source, Buffer.alloc(20, 0xcd))
+ await nativeFs.chmod(source, 0o660)
+ hashBoundary.mockClear()
+
+ await expect(store.readManagedFilePrefix(receipt.path, CALLER, 8)).rejects.toMatchObject({
+ code: 'download_missing',
+ })
+
+ // Witness: the content was hashed, and the mismatch kept the group mode.
+ expect(hashBoundary).toHaveBeenCalledTimes(1)
+ expect((await nativeFs.stat(source)).mode & 0o7777).toBe(0o660)
+
+ // Reuse reaches the same check and removes the copy.
+ const removed = await expiryCount('incomplete_removed')
+ await expect(store.reusableReceipt(CALLER, sourceFor(125), 20)).resolves.toBeUndefined()
+ expect(await exists(directory)).toBe(false)
+ expect(await expiryCount('incomplete_removed')).toBe(removed + 1)
+ })
})
describe('GFS download store: pins, lifecycle and errors', () => {
diff --git a/mcp-host/src/internalTools/gfsDownloadStoreBoundaries.test.ts b/mcp-host/src/internalTools/gfsDownloadStoreBoundaries.test.ts
index 21093ab6c..6db11e0a8 100644
--- a/mcp-host/src/internalTools/gfsDownloadStoreBoundaries.test.ts
+++ b/mcp-host/src/internalTools/gfsDownloadStoreBoundaries.test.ts
@@ -367,7 +367,10 @@ describe('GFS download store boundaries: quota and capacity', () => {
startTransfer(store, callerDirectory(hostRoot, fresh), fresh, index + 1, 1)
).rejects.toMatchObject({ code: 'host_quota_exceeded' })
expect(await quotaCount('host', 'retained_files')).toBe(denied + 1)
- })
+ // 64 real publications: the bound is the Host file limit, which is a
+ // constant, so the timeout is explicit rather than the 5 s default that a
+ // loaded machine can exceed.
+ }, 60_000)
it('Q5: free space exactly at the threshold is admitted and one byte less is refused', async () => {
const observed = await nativeFs.statfs(hostRoot, { bigint: true })
@@ -510,6 +513,20 @@ describe('GFS download store boundaries: expiry', () => {
}
})
+ it('E2b: a managed prefix read succeeds until one millisecond before expiry', async () => {
+ const copy = await expiringCopy(343)
+ vi.setSystemTime(copy.expiresAtMs - 1)
+ await expect(store.readManagedFilePrefix(copy.receipt.path, A, 4)).resolves.toEqual(
+ copy.bytes.subarray(0, 4)
+ )
+ for (const instant of [copy.expiresAtMs, copy.expiresAtMs + 1]) {
+ vi.setSystemTime(instant)
+ await expect(store.readManagedFilePrefix(copy.receipt.path, A, 4)).rejects.toMatchObject({
+ code: 'download_expired',
+ })
+ }
+ })
+
it('E3: the sweep removes a copy exactly at its expiry', async () => {
const copy = await expiringCopy(342)
await expect(store.cleanupExpired(copy.expiresAtMs - 1)).resolves.toMatchObject({
@@ -566,6 +583,16 @@ describe('GFS download store boundaries: in-process concurrency', () => {
it('C4: a sweep requested during publication runs after it and keeps the copy', async () => {
const { transfer, bytes } = await startTransfer(store, rootA, A, 353, 12)
+ const source = path.join(downloadDirectory(rootA, transfer.id), 'source')
+ // The private sweep is observed, not replaced: it records whether the
+ // publication had finished when the sweep actually started.
+ const internals = store as unknown as { sweep: (now: number) => Promise<unknown> }
+ const realSweep = internals.sweep.bind(store)
+ const sourceAtSweepStart: boolean[] = []
+ vi.spyOn(internals, 'sweep').mockImplementation(async (now: number) => {
+ sourceAtSweepStart.push(exists(source))
+ return realSweep(now)
+ })
let sweep: ReturnType<GfsDownloadStore['cleanupExpired']> | undefined
renameBoundary.mockImplementation(async (from: string, to: string) => {
await nativeFs.rename(from, to)
@@ -577,21 +604,32 @@ describe('GFS download store boundaries: in-process concurrency', () => {
expect(sweep).toBeDefined()
await expect(sweep).resolves.toMatchObject({ removedIncomplete: 0, removedExpired: 0 })
+ // Witness: the requested sweep ran once, after source was in place.
+ expect(sourceAtSweepStart).toEqual([true])
await expect(store.readManagedFile(receipt.path, A)).resolves.toEqual(bytes)
})
it('C5: close requested during publication waits for it', async () => {
const { transfer, bytes } = await startTransfer(store, rootA, A, 354, 12)
let closing: Promise<void> | undefined
+ let closed = false
+ let closedAtSourceRename: boolean | undefined
renameBoundary.mockImplementation(async (from: string, to: string) => {
+ if (path.basename(to) === 'source') closedAtSourceRename = closed
await nativeFs.rename(from, to)
- if (path.basename(to) === 'meta.json') closing = store.close(5_000)
+ if (path.basename(to) === 'meta.json')
+ closing = store.close(5_000).then(() => {
+ closed = true
+ })
})
const receipt = await store.publish(transfer.id, A, digestOf(bytes))
expect(closing).toBeDefined()
await closing
+ // Witness: the last rename of the publication ran before close resolved.
+ expect(closedAtSourceRename).toBe(false)
+
expect(store.isAvailable()).toBe(false)
expect(syncFs.readFileSync(path.join(rootA, receipt.path))).toEqual(bytes)
})
@@ -852,6 +890,40 @@ describe('GFS download store boundaries: path swapped between check and use', ()
expect(syncFs.readFileSync(path.join(decoy, 'source.partial'))).toEqual(bytes)
})
+ it('K2b: a caller directory swapped between the meta.json rename and the source rename publishes nothing', async () => {
+ const { transfer, bytes } = await startTransfer(store, rootB, B, 83, 8)
+ const outside = outsideDirectory()
+ const decoy = downloadDirectory(outside, transfer.id)
+ syncFs.mkdirSync(decoy, { recursive: true, mode: 0o700 })
+ syncFs.chmodSync(path.dirname(decoy), 0o700)
+ const decoyBytes = Buffer.alloc(8, 0x6d)
+ syncFs.writeFileSync(path.join(decoy, 'source.partial'), decoyBytes, { mode: 0o600 })
+ let swapped = false
+ renameBoundary.mockImplementation(async (from: string, to: string) => {
+ await nativeFs.rename(from, to)
+ if (!swapped && path.basename(String(to)) === 'meta.json') {
+ swapped = true
+ syncFs.renameSync(rootB, `${rootB}-moved`)
+ syncFs.symlinkSync(outside, rootB)
+ }
+ })
+
+ await expect(store.publish(transfer.id, B, digestOf(bytes))).rejects.toMatchObject({
+ code: 'workspace_unavailable',
+ })
+
+ // Witness: meta.json was renamed into place, then the swap happened.
+ expect(swapped).toBe(true)
+ const targets = renameBoundary.mock.calls.map(([, to]) => path.basename(String(to)))
+ expect(targets).toContain('meta.json')
+ expect(targets).not.toContain('source')
+ // The swap target is untouched and the real directory holds no source.
+ expect(syncFs.readdirSync(decoy)).toEqual(['source.partial'])
+ expect(syncFs.readFileSync(path.join(decoy, 'source.partial'))).toEqual(decoyBytes)
+ const moved = downloadDirectory(`${rootB}-moved`, transfer.id)
+ expect(syncFs.readdirSync(moved).sort()).toEqual(['meta.json', 'source.partial'])
+ })
+
it('K3: a read whose caller directory is swapped after the check serves nothing from outside', async () => {
const { receipt, bytes } = await completedCopy(store, rootB, B, 82, 8)
// Witness: the owner's read works before the swap.
diff --git a/mcp-host/src/workspace/__tests__/gfsCallerRootBinding.test.ts b/mcp-host/src/workspace/__tests__/gfsCallerRootBinding.test.ts
index d28a6166f..490beb01e 100644
--- a/mcp-host/src/workspace/__tests__/gfsCallerRootBinding.test.ts
+++ b/mcp-host/src/workspace/__tests__/gfsCallerRootBinding.test.ts
@@ -138,12 +138,10 @@ describe('NativeRegistry GFS caller file-tool binding', () => {
expect(traversal.is_error).toBe(true)
})
- it('keeps the verified caller root when delivery is recovery-required', async () => {
- fs.mkdirSync(path.join(root, '.gfs-download-store'), { recursive: true })
- fs.writeFileSync(path.join(root, '.gfs-download-store', 'ledger-v1.json'), '{invalid')
+ it('keeps the verified caller root when the store is unavailable', async () => {
store = new GfsDownloadStore(root)
stores.push(store)
- await store.initialize().catch(() => undefined)
+ expect(store.isAvailable()).toBe(false)
const callerRoot = new ScopedWorkspaceProvider(root).forSource(source()).userRootPath
const degraded = registry(callerRoot, false)
diff --git a/scripts/ci/pinned-vitest-cases/mcp-host.json b/scripts/ci/pinned-vitest-cases/mcp-host.json
index 0c1a59946..cef64ec25 100644
--- a/scripts/ci/pinned-vitest-cases/mcp-host.json
+++ b/scripts/ci/pinned-vitest-cases/mcp-host.json
@@ -570,5 +570,41 @@
{
"suite": "protectedWorkspacePaths.test.ts",
"fullName": "protected workspace paths blocks a retired pre-#1028 store tree and leaves a lookalike name readable"
+ },
+ {
+ "suite": "gfsRuntime.test.ts",
+ "fullName": "GFS runtime bootstrap a cleanup that throws is logged and the next cycle sweeps again"
+ },
+ {
+ "suite": "gfsDownloadStore.test.ts",
+ "fullName": "GFS download store: publication F4b: a temporary meta.json that cannot be removed after a failed publish is logged, not swallowed"
+ },
+ {
+ "suite": "gfsDownloadStore.test.ts",
+ "fullName": "GFS download store: reuse F7b: another caller's reuse lookup never hashes or removes a copy it does not own"
+ },
+ {
+ "suite": "gfsDownloadStore.test.ts",
+ "fullName": "GFS download store: quotas and eviction F10b: a quota denial carries only its code, never another caller's id, path, name or usage"
+ },
+ {
+ "suite": "gfsDownloadStore.test.ts",
+ "fullName": "GFS download store: sweep F20b: a caller's unreadable download directory is counted and logged, and the store stays available"
+ },
+ {
+ "suite": "gfsDownloadStore.test.ts",
+ "fullName": "GFS download store: managed reads F23b: a kubelet fsGroup expansion is restored to the private modes after the content is re-hashed"
+ },
+ {
+ "suite": "gfsDownloadStore.test.ts",
+ "fullName": "GFS download store: managed reads F23c: an fsGroup-expanded source whose content changed is not restored or served"
+ },
+ {
+ "suite": "gfsDownloadStoreBoundaries.test.ts",
+ "fullName": "GFS download store boundaries: expiry E2b: a managed prefix read succeeds until one millisecond before expiry"
+ },
+ {
+ "suite": "gfsDownloadStoreBoundaries.test.ts",
+ "fullName": "GFS download store boundaries: path swapped between check and use K2b: a caller directory swapped between the meta.json rename and the source rename publishes nothing"
}
]