Skip to content

Commit b3a285b

Browse files
committed
Update agent-evals to be a commonjs library
1 parent 3a8e14a commit b3a285b

File tree

15 files changed

+2311
-582
lines changed

15 files changed

+2311
-582
lines changed

scripts/agent-evals/.mocharc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import:
2-
- ./lib/helpers/mocha-bootstrap.js
2+
- ./lib/scripts/agent-evals/src/helpers/mocha-bootstrap.js
33
timeout: 120000
44
recursive: true
55
node-options:

scripts/agent-evals/package-lock.json

Lines changed: 2073 additions & 399 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/agent-evals/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@
22
"name": "agent-evals",
33
"version": "1.0.0",
44
"description": "",
5-
"type": "module",
65
"scripts": {
76
"build": "tsc",
8-
"test": "npm run build && mocha 'lib/**/*.spec.js' --reporter spec",
7+
"test": "npm run build && mocha 'lib/**/*.spec.js' --reporter spec --require lib/scripts/agent-evals/src/helpers/mocha-bootstrap.js",
98
"test:dev": "SKIP_REBUILD=true COPY_FIREBASE_CLI_CONFIG=true npm run test"
109
},
1110
"keywords": [],
1211
"author": "",
1312
"license": "ISC",
1413
"devDependencies": {
1514
"@types/mocha": "^9.0.0",
16-
"@types/node": "^24.9.0"
15+
"@types/node": "18.19.1",
16+
"@typescript-eslint/eslint-plugin": "^5.9.0",
17+
"@typescript-eslint/parser": "^5.9.0",
18+
"typescript": "^4.5.4"
1719
},
1820
"dependencies": {
1921
"mocha": "^11.7.1",
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
import { setupEnvironment } from "../runner/index.js";
1+
import { setupEnvironment } from "../runner/index";
22

3-
await setupEnvironment();
3+
export async function mochaGlobalSetup() {
4+
await setupEnvironment();
5+
}

scripts/agent-evals/src/mock/mock-tools-main.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { Module } from "module";
2-
import path from "path";
3-
import fs from "fs";
4-
import os from "os";
2+
import * as path from "path";
3+
import * as fs from "fs";
4+
import * as os from "os";
55
import { getFirebaseCliRoot } from "../runner/paths.js";
6-
import { getToolMocks } from "./tool-mocks.js";
76

87
//
98
// This file is run as a node --import parameter before the Firebase CLI to
@@ -13,18 +12,31 @@ import { getToolMocks } from "./tool-mocks.js";
1312
// Path to the built MCP Tools implementation in the Firebase CLI, relative to
1413
// the repo's root
1514
const MCP_TOOLS_INDEX_PATH = "lib/mcp/tools/index.js";
15+
const CONFIGSTORE_INDEX_PATH = "lib/mcp/configstore.js";
1616
const LOG_FILE_PATH = path.join(os.homedir(), "Desktop", "agent_evals_mock_logs.txt");
1717
// Enable this to turn on file logging. This can be helpful for debugging
1818
// because console logs get swallowed
1919
const ENABLE_FILE_LOGGING = false;
2020

21-
const mocks = getToolMocks();
22-
2321
const originalRequire = Module.prototype.require;
24-
Module.prototype.require = function (id: string) {
22+
(Module.prototype as any).require = function (id: string) {
2523
const requiredModule = originalRequire.apply(this, [id]);
2624
const absolutePath = Module.createRequire(this.filename).resolve(id);
2725
const pathRelativeToCliRoot = path.relative(getFirebaseCliRoot(), absolutePath);
26+
console.log(`[DEBUG] Requiring: ${pathRelativeToCliRoot} (Absolute: ${absolutePath})`);
27+
28+
// Mock configstore to avoid "Cannot find module ../package.json" error and side effects
29+
if (pathRelativeToCliRoot.endsWith(CONFIGSTORE_INDEX_PATH)) {
30+
logToFile(`Mocking configstore for: ${pathRelativeToCliRoot}`);
31+
return {
32+
configstore: {
33+
get: () => undefined,
34+
set: () => { },
35+
delete: () => { },
36+
},
37+
};
38+
}
39+
2840
if (!pathRelativeToCliRoot.endsWith(MCP_TOOLS_INDEX_PATH)) {
2941
return requiredModule;
3042
}
@@ -67,6 +79,10 @@ Module.prototype.require = function (id: string) {
6779
});
6880
};
6981

82+
import { getToolMocks } from "./tool-mocks.js";
83+
84+
const mocks = getToolMocks();
85+
7086
function logToFile(message: string) {
7187
if (!ENABLE_FILE_LOGGING) {
7288
return;

scripts/agent-evals/src/mock/mocks/get-environment-mock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DEFAULT_FIREBASE_PROJECT, DEFAULT_FIREBASE_USER } from "../../data/index.js";
2-
import { renderTemplate } from "../../../../../src/mcp/tools/core/get_environment.js";
2+
import { renderTemplate } from "../../../../../src/mcp/tools/core/get_environment";
33
import { toMockContent } from "../tool-mock-utils.js";
44

55
const PROJECT_DIR = "/Users/fakeuser/develop/fake-project";

scripts/agent-evals/src/mock/mocks/next-js-with-project-mock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
DEFAULT_FIREBASE_WEB_APP_NAME,
88
DEFAULT_FIREBASE_WEB_APP_API_KEY,
99
} from "../../data/index.js";
10-
import { renderTemplate } from "../../../../../src/mcp/tools/core/get_environment.js";
10+
import { renderTemplate } from "../../../../../src/mcp/tools/core/get_environment";
1111
import { toMockContent } from "../tool-mock-utils.js";
1212

1313
const PROJECT_DIR = "/Users/fakeuser/develop/fake-project";

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
2-
import { nextJsWithProjectMock } from "./mocks/next-js-with-project-mock.js";
3-
import {
1+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types";
2+
const { nextJsWithProjectMock } = require("./mocks/next-js-with-project-mock");
3+
const {
44
getEnvironmentWithIosApp,
55
getEnvironmentWithAndroidApp,
6-
getEnvironmentWithFlutterApp
7-
} from "./mocks/get-environment-mock.js";
6+
getEnvironmentWithFlutterApp,
7+
} = require("./mocks/get-environment-mock");
88

99
export type ToolMock = CallToolResult;
1010

@@ -36,3 +36,5 @@ export function getToolMocks(): Record<string, ToolMock> {
3636
}
3737
return mocks;
3838
}
39+
40+
module.exports = { getToolMocks };

scripts/agent-evals/src/runner/agent-test-runner.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import { ToolDef } from "./tool-matcher.js";
22

3-
export interface AgentTestRunner {
4-
/**
5-
* Simulates typing a string and waits for the turn to complete. It types one
6-
* character at a time to avoid paste detection that the Gemini CLI has
7-
*/
8-
type(text: string): Promise<void>;
9-
3+
export interface AgentTestMatchers {
104
/**
115
* Looks for a specific string or regex to in the agent's output since the
126
* last time the user typed and pressed enter.
@@ -26,3 +20,16 @@ export interface AgentTestRunner {
2620
*/
2721
expectMemory(text: string | RegExp): Promise<void>;
2822
}
23+
24+
export interface AgentTestRunner extends AgentTestMatchers {
25+
/**
26+
* Simulates typing a string and waits for the turn to complete. It types one
27+
* character at a time to avoid paste detection that the Gemini CLI has
28+
*/
29+
type(text: string): Promise<void>;
30+
31+
/**
32+
* Negated assertions
33+
*/
34+
dont: AgentTestMatchers;
35+
}

0 commit comments

Comments
 (0)