Add MCP scope subdirectory regression tests

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-04-03 17:14:40 +09:00
parent f269d2fcc5
commit 6b8d9df316
2 changed files with 62 additions and 2 deletions
@@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, mock } from "bun:test"
import { mkdirSync, rmSync, writeFileSync } from "fs"
import { tmpdir } from "os"
import { join } from "path"
import { shouldLoadMcpServer } from "./scope-filter"
const TEST_DIR = join(tmpdir(), `mcp-scope-filtering-test-${Date.now()}`)
const TEST_HOME = join(TEST_DIR, "home")
@@ -27,6 +28,56 @@ describe("loadMcpConfigs", () => {
rmSync(TEST_DIR, { recursive: true, force: true })
})
describe("#given local MCP scope checks", () => {
it("#when cwd exactly matches project path #then the server is loaded", () => {
const result = shouldLoadMcpServer(
{
scope: "local",
projectPath: "/tmp/repo",
},
"/tmp/repo"
)
expect(result).toBe(true)
})
it("#when cwd is a subdirectory of project path #then the server is loaded", () => {
const result = shouldLoadMcpServer(
{
scope: "local",
projectPath: "/tmp/repo",
},
"/tmp/repo/packages/app"
)
expect(result).toBe(true)
})
it("#when cwd does not overlap project path #then the server is not loaded", () => {
const result = shouldLoadMcpServer(
{
scope: "local",
projectPath: "/tmp/repo",
},
"/tmp/other"
)
expect(result).toBe(false)
})
it("#when cwd is the parent of project path #then the server is not loaded", () => {
const result = shouldLoadMcpServer(
{
scope: "local",
projectPath: "/tmp/repo",
},
"/tmp"
)
expect(result).toBe(false)
})
})
describe("#given user-scoped MCP entries with local scope metadata", () => {
it("#when loading configs #then only servers matching the current project path are loaded", async () => {
writeFileSync(