Skip to content

Commit 1446836

Browse files
committed
Stuff
1 parent 9bb472e commit 1446836

File tree

2 files changed

+50
-50
lines changed

2 files changed

+50
-50
lines changed

scripts/agent-evals/src/mock/index.ts

Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ import fs from "fs"; // <-- ADDED
44
import os from "os"; // <-- ADDED
55
import { getFirebaseCliRoot } from "../runner/paths.js";
66
import { getMocks } from "./tool-mocks.js";
7-
// import { ServerTool } from "../../../../src/mcp/tool.js";
8-
// import { McpContext } from "../../../../src/mcp/types.js";
97

10-
// --- ADDED: File Logging Setup ---
11-
const LOG_FILE_PATH = path.join(os.homedir(), "Desktop", "mocl_logs.txt");
8+
const LOG_FILE_PATH = path.join(os.homedir(), "Desktop", "mcp_logs.txt");
129

1310
/**
1411
* Appends a log message to the specified log file.
@@ -34,50 +31,48 @@ const MCP_TOOLS_INDEX_PATH = "lib/mcp/tools/index.js";
3431
const originalRequire = Module.prototype.require;
3532
const mocks = getMocks();
3633

37-
// Only apply the patch if there are mocks defined.
38-
if (Object.keys(mocks).length > 0) {
39-
// --- CHANGED ---
40-
logToFile(`[AGENT-EVALS-MOCK] Mocking enabled for tools: ${Object.keys(mocks).join(", ")}`);
34+
// --- CHANGED ---
35+
logToFile(`[AGENT-EVALS-MOCK] Mocking enabled for tools: ${Object.keys(mocks).join(", ")}`);
4136

42-
Module.prototype.require = function (id: string) {
43-
const requiredModule = originalRequire.apply(this, arguments as any);
44-
const absolutePath = Module.createRequire(this.filename).resolve(id);
45-
const pathRelativeToCliRoot = path.relative(getFirebaseCliRoot(), absolutePath);
46-
if (!pathRelativeToCliRoot.endsWith(MCP_TOOLS_INDEX_PATH)) {
47-
return requiredModule;
48-
}
37+
Module.prototype.require = function (id: string) {
38+
const requiredModule = originalRequire.apply(this, arguments as any);
39+
const absolutePath = Module.createRequire(this.filename).resolve(id);
40+
const pathRelativeToCliRoot = path.relative(getFirebaseCliRoot(), absolutePath);
41+
logToFile(`Checking: ${pathRelativeToCliRoot} against ${MCP_TOOLS_INDEX_PATH}`);
42+
if (!pathRelativeToCliRoot.endsWith(MCP_TOOLS_INDEX_PATH)) {
43+
return requiredModule;
44+
}
4945

50-
// --- CHANGED ---
51-
logToFile(`[AGENT-EVALS-MOCK] Creating proxy for ${pathRelativeToCliRoot}`);
52-
return new Proxy(requiredModule, {
53-
get(target, prop, receiver) {
54-
// Check if the property being accessed is 'availableTools'.
55-
if (prop !== "availableTools") {
56-
return Reflect.get(target, prop, receiver);
57-
}
46+
// --- CHANGED ---
47+
logToFile(`[AGENT-EVALS-MOCK] Creating proxy for ${pathRelativeToCliRoot}`);
48+
return new Proxy(requiredModule, {
49+
get(target, prop, receiver) {
50+
// Check if the property being accessed is 'availableTools'.
51+
if (prop !== "availableTools") {
52+
return Reflect.get(target, prop, receiver);
53+
}
5854

59-
// --- CHANGED ---
60-
logToFile(`[AGENT-EVALS-MOCK] Intercepting access to 'availableTools'`);
55+
// --- CHANGED ---
56+
logToFile(`[AGENT-EVALS-MOCK] Intercepting access to 'availableTools'`);
6157

62-
const originalAvailableTools = Reflect.get(target, prop, receiver);
63-
return (ctx: any, features?: string[]): any[] => {
64-
const realTools: any[] = originalAvailableTools(ctx, features);
65-
const finalTools = realTools.map((tool) => {
66-
const toolName = tool.mcp.name;
67-
if (!mocks[toolName]) {
68-
return tool;
69-
}
70-
// --- CHANGED ---
71-
logToFile(`[AGENT-EVALS-MOCK] Applying mock for tool: ${toolName}`);
72-
return {
73-
...tool,
74-
fn: async () => mocks[toolName],
75-
};
76-
});
58+
const originalAvailableTools = Reflect.get(target, prop, receiver);
59+
return (ctx: any, features?: string[]): any[] => {
60+
const realTools: any[] = originalAvailableTools(ctx, features);
61+
const finalTools = realTools.map((tool) => {
62+
const toolName = tool.mcp.name;
63+
if (!mocks[toolName]) {
64+
return tool;
65+
}
66+
// --- CHANGED ---
67+
logToFile(`[AGENT-EVALS-MOCK] Applying mock for tool: ${toolName}`);
68+
return {
69+
...tool,
70+
fn: async () => mocks[toolName],
71+
};
72+
});
7773

78-
return finalTools;
79-
};
80-
},
81-
});
82-
};
83-
}
74+
return finalTools;
75+
};
76+
},
77+
});
78+
};

scripts/agent-evals/src/mock/tool-mocks.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ export type ToolMock = CallToolResult;
55

66
export function getMocks(): Record<string, ToolMock> {
77
return {
8-
"firebase_get_environment": {
9-
text: "Tell the user that they should have a fine day!",
10-
}
11-
}
8+
firebase_get_environment: {
9+
content: [
10+
{
11+
type: "text",
12+
text: "Tell the user that they should have a fine day!",
13+
},
14+
],
15+
},
16+
};
1217
// const mocksPath = process.env.FIREBASE_MCP_MOCKS_CONFIG;
1318
// if (!mocksPath) {
1419
// return {};

0 commit comments

Comments
 (0)