Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions scripts/agent-evals/src/mock/mock-tools-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,31 @@

const originalRequire = Module.prototype.require;
Module.prototype.require = function (id: string) {
const requiredModule = originalRequire.apply(this, [id]);

Check warning on line 25 in scripts/agent-evals/src/mock/mock-tools-main.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
const absolutePath = Module.createRequire(this.filename).resolve(id);
const pathRelativeToCliRoot = path.relative(getFirebaseCliRoot(), absolutePath);
if (!pathRelativeToCliRoot.endsWith(MCP_TOOLS_INDEX_PATH)) {
return requiredModule;

Check warning on line 29 in scripts/agent-evals/src/mock/mock-tools-main.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe return of an `any` typed value
}

logToFile(
`Creating proxy implementation for file: ${pathRelativeToCliRoot} with tool mocks: ${JSON.stringify(Object.keys(mocks))}`,
);

return new Proxy(requiredModule, {

Check warning on line 36 in scripts/agent-evals/src/mock/mock-tools-main.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe return of an `any` typed value
get(target, prop, receiver) {
if (prop !== "availableTools") {
return Reflect.get(target, prop, receiver);

Check warning on line 39 in scripts/agent-evals/src/mock/mock-tools-main.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe return of an `any` typed value
}

logToFile(`Intercepting access to 'availableTools'`);

const originalAvailableTools = Reflect.get(target, prop, receiver);

Check warning on line 44 in scripts/agent-evals/src/mock/mock-tools-main.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
return async (ctx: any, features?: string[]): Promise<any[]> => {

Check warning on line 45 in scripts/agent-evals/src/mock/mock-tools-main.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

Check warning on line 45 in scripts/agent-evals/src/mock/mock-tools-main.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
const realTools = await originalAvailableTools(ctx, features);

Check warning on line 46 in scripts/agent-evals/src/mock/mock-tools-main.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe call of an `any` typed value

Check warning on line 46 in scripts/agent-evals/src/mock/mock-tools-main.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
if (!Array.isArray(realTools)) {
logToFile(`Error: Real tools is not an array: ${JSON.stringify(realTools)}`);
return realTools;

Check warning on line 49 in scripts/agent-evals/src/mock/mock-tools-main.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe return of an `any` typed value
}

const finalTools = realTools.map((tool) => {
Expand All @@ -57,6 +57,15 @@
logToFile(`Applying mock for tool: ${toolName}`);
return {
...tool,
mcp: {
...tool.mcp,
_meta: {
optionalProjectDir: false,
requiresProject: false,
requiresAuth: false,
requiresGemini: false,
},
Comment on lines +62 to +67
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

By completely overwriting the _meta object, you risk losing other important properties that might be defined there, such as feature. The feature property is used for grouping tools and might be necessary for filtering. To ensure that you only override the necessary flags for mocking while preserving other metadata, you should spread the existing _meta object before setting your values.

              _meta: {
                ...tool.mcp?._meta,
                optionalProjectDir: false,
                requiresProject: false,
                requiresAuth: false,
                requiresGemini: false,
              },

},
fn: async () => mocks[toolName],
};
});
Expand Down
Loading