feat: allow custom filename for context files (#654)

Co-authored-by: N. Taylor Mullen <ntaylormullen@google.com>
This commit is contained in:
Allen Hutchison
2025-05-31 12:49:28 -07:00
committed by GitHub
parent cbc1614b84
commit 53bf778497
15 changed files with 1710 additions and 888 deletions

View File

@@ -4,10 +4,10 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { describe, it, expect, vi, beforeEach /*, afterEach */ } from 'vitest'; // afterEach removed as it was unused
import { Config, createServerConfig, ConfigParameters } from './config.js'; // Adjust import path
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { Config, createServerConfig, ConfigParameters } from './config.js';
import * as path from 'path';
// import { ToolRegistry } from '../tools/tool-registry'; // ToolRegistry removed as it was unused
import { setGeminiMdFilename as mockSetGeminiMdFilename } from '../tools/memoryTool.js';
// Mock dependencies that might be called during Config construction or createServerConfig
vi.mock('../tools/tool-registry', () => {
@@ -30,6 +30,12 @@ vi.mock('../tools/shell');
vi.mock('../tools/write-file');
vi.mock('../tools/web-fetch');
vi.mock('../tools/read-many-files');
vi.mock('../tools/memoryTool', () => ({
MemoryTool: vi.fn(),
setGeminiMdFilename: vi.fn(),
getCurrentGeminiMdFilename: vi.fn(() => 'GEMINI.md'), // Mock the original filename
DEFAULT_CONTEXT_FILENAME: 'GEMINI.md',
}));
describe('Server Config (config.ts)', () => {
const API_KEY = 'server-api-key';
@@ -106,4 +112,34 @@ describe('Server Config (config.ts)', () => {
const config = createServerConfig(paramsWithRelativeDir);
expect(config.getTargetDir()).toBe(expectedResolvedDir);
});
it('createServerConfig should call setGeminiMdFilename with contextFileName if provided', () => {
const contextFileName = 'CUSTOM_AGENTS.md';
const paramsWithContextFile: ConfigParameters = {
...baseParams,
contextFileName,
};
createServerConfig(paramsWithContextFile);
expect(mockSetGeminiMdFilename).toHaveBeenCalledWith(contextFileName);
});
it('createServerConfig should not call setGeminiMdFilename if contextFileName is not provided', () => {
createServerConfig(baseParams); // baseParams does not have contextFileName
expect(mockSetGeminiMdFilename).not.toHaveBeenCalled();
});
it('Config constructor should call setGeminiMdFilename with contextFileName if provided', () => {
const contextFileName = 'CUSTOM_AGENTS.md';
const paramsWithContextFile: ConfigParameters = {
...baseParams,
contextFileName,
};
new Config(paramsWithContextFile);
expect(mockSetGeminiMdFilename).toHaveBeenCalledWith(contextFileName);
});
it('Config constructor should not call setGeminiMdFilename if contextFileName is not provided', () => {
new Config(baseParams); // baseParams does not have contextFileName
expect(mockSetGeminiMdFilename).not.toHaveBeenCalled();
});
});

View File

@@ -19,7 +19,7 @@ import { ShellTool } from '../tools/shell.js';
import { WriteFileTool } from '../tools/write-file.js';
import { WebFetchTool } from '../tools/web-fetch.js';
import { ReadManyFilesTool } from '../tools/read-many-files.js';
import { MemoryTool } from '../tools/memoryTool.js';
import { MemoryTool, setGeminiMdFilename } from '../tools/memoryTool.js';
import { WebSearchTool } from '../tools/web-search.js';
export class MCPServerConfig {
@@ -56,6 +56,7 @@ export interface ConfigParameters {
alwaysSkipModificationConfirmation?: boolean;
vertexai?: boolean;
showMemoryUsage?: boolean;
contextFileName?: string;
}
export class Config {
@@ -100,6 +101,10 @@ export class Config {
this.vertexai = params.vertexai;
this.showMemoryUsage = params.showMemoryUsage ?? false;
if (params.contextFileName) {
setGeminiMdFilename(params.contextFileName);
}
this.toolRegistry = createToolRegistry(this);
}