Skip to content

Commit 6898e63

Browse files
committed
test(core): align test fixtures with WorkspaceContext signature and GEMINI.md rename
- ls, shell, write-file tests: pass allowExternalFileAccess=false to WorkspaceContext constructor (third arg added to signature) - pathReader test: add options.allowExternalFileAccess param to createMockConfig + fileService passthrough fallback so security tests don't need a custom FileDiscoveryService - prompts test + snapshot: rename AGENTS.md -> GEMINI.md to match snippets.legacy.ts source
1 parent 5e71f83 commit 6898e63

6 files changed

Lines changed: 42 additions & 27 deletions

File tree

packages/core/src/core/__snapshots__/prompts.test.ts.snap

Lines changed: 20 additions & 20 deletions
Large diffs are not rendered by default.

packages/core/src/core/prompts.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ describe('Core System Prompt (prompts.ts)', () => {
338338
const memory = 'This is custom user memory.\nBe extra polite.';
339339
const prompt = getCoreSystemPrompt(mockConfig, memory);
340340

341-
expect(prompt).toContain('# Contextual Instructions (AGENTS.md)');
341+
expect(prompt).toContain('# Contextual Instructions (GEMINI.md)');
342342
expect(prompt).toContain('<loaded_context>');
343343
expect(prompt).toContain(memory);
344344
expect(prompt).toContain('You are Gemini CLI, an interactive CLI agent'); // Ensure base prompt follows

packages/core/src/tools/ls.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('LSTool', () => {
4646
mockConfig = {
4747
getTargetDir: () => tempRootDir,
4848
getWorkspaceContext: () =>
49-
new WorkspaceContext(tempRootDir, [tempSecondaryDir]),
49+
new WorkspaceContext(tempRootDir, [tempSecondaryDir], false),
5050
getFileService: () => new FileDiscoveryService(tempRootDir),
5151
getFileFilteringOptions: () => ({
5252
respectGitIgnore: true,

packages/core/src/tools/shell.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ describe('ShellTool', () => {
127127
getSummarizeToolOutputConfig: vi.fn().mockReturnValue(undefined),
128128
getWorkspaceContext: vi
129129
.fn()
130-
.mockReturnValue(new WorkspaceContext(tempRootDir)),
130+
.mockReturnValue(new WorkspaceContext(tempRootDir, [], false)),
131131
storage: {
132132
getProjectTempDir: vi.fn().mockReturnValue('/tmp/project'),
133133
},

packages/core/src/tools/write-file.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const mockConfigInternal = {
8383
getBaseLlmClient: vi.fn(), // Initialize as a plain mock function
8484
getFileSystemService: () => fsService,
8585
getIdeMode: vi.fn(() => false),
86-
getWorkspaceContext: () => new WorkspaceContext(rootDir, [plansDir]),
86+
getWorkspaceContext: () => new WorkspaceContext(rootDir, [plansDir], false),
8787
getApiKey: () => 'test-key',
8888
getModel: () => 'test-model',
8989
getSandbox: () => false,
@@ -145,7 +145,7 @@ describe('WriteFileTool', () => {
145145
fs.mkdirSync(plansDir, { recursive: true });
146146
}
147147

148-
const workspaceContext = new WorkspaceContext(rootDir, [plansDir]);
148+
const workspaceContext = new WorkspaceContext(rootDir, [plansDir], false);
149149
const mockStorage = {
150150
getProjectTempDir: vi.fn().mockReturnValue('/tmp/project'),
151151
};

packages/core/src/utils/pathReader.test.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,31 @@ const createMockConfig = (
2424
respectGitIgnore?: boolean;
2525
respectGeminiIgnore?: boolean;
2626
} = {},
27+
options: {
28+
allowExternalFileAccess?: boolean;
29+
} = {},
2730
): Config => {
2831
const { respectGitIgnore = true, respectGeminiIgnore = true } = fileFiltering;
29-
const workspace = new WorkspaceContext(cwd, otherDirs);
32+
const { allowExternalFileAccess = false } = options;
33+
const workspace = new WorkspaceContext(
34+
cwd,
35+
otherDirs,
36+
allowExternalFileAccess,
37+
);
3038
const fileSystemService = new StandardFileSystemService();
39+
// Fallback passthrough so security tests can exercise pathReader without
40+
// crafting a custom FileDiscoveryService for every case.
41+
const fileService: FileDiscoveryService =
42+
mockFileService ??
43+
({
44+
filterFiles: (files: string[]) => files,
45+
} as unknown as FileDiscoveryService);
3146
return {
3247
getWorkspaceContext: () => workspace,
3348
// TargetDir is used by processSingleFileContent to generate relative paths in errors/output
3449
getTargetDir: () => cwd,
3550
getFileSystemService: () => fileSystemService,
36-
getFileService: () => mockFileService,
51+
getFileService: () => fileService,
3752
getFileFilteringRespectGitIgnore: () => respectGitIgnore,
3853
getFileFilteringRespectGeminiIgnore: () => respectGeminiIgnore,
3954
} as unknown as Config;

0 commit comments

Comments
 (0)