fix(core): update tests to match tool changes and resolve timeouts

This commit is contained in:
Taylor Mullen
2026-02-09 01:07:16 -08:00
committed by N. Taylor Mullen
parent 93f9e89114
commit 7ef1a3f5ea
2 changed files with 7 additions and 9 deletions
@@ -11,6 +11,7 @@ import {
GREP_TOOL_NAME, GREP_TOOL_NAME,
LS_TOOL_NAME, LS_TOOL_NAME,
READ_FILE_TOOL_NAME, READ_FILE_TOOL_NAME,
WEB_FETCH_TOOL_NAME,
} from '../tools/tool-names.js'; } from '../tools/tool-names.js';
import { DEFAULT_GEMINI_MODEL } from '../config/models.js'; import { DEFAULT_GEMINI_MODEL } from '../config/models.js';
import { makeFakeConfig } from '../test-utils/config.js'; import { makeFakeConfig } from '../test-utils/config.js';
@@ -50,6 +51,7 @@ describe('CodebaseInvestigatorAgent', () => {
READ_FILE_TOOL_NAME, READ_FILE_TOOL_NAME,
GLOB_TOOL_NAME, GLOB_TOOL_NAME,
GREP_TOOL_NAME, GREP_TOOL_NAME,
WEB_FETCH_TOOL_NAME,
]); ]);
}); });
+5 -9
View File
@@ -12,6 +12,10 @@ import type { PolicySettings } from './types.js';
import { ApprovalMode, PolicyDecision, InProcessCheckerType } from './types.js'; import { ApprovalMode, PolicyDecision, InProcessCheckerType } from './types.js';
import { isDirectorySecure } from '../utils/security.js'; import { isDirectorySecure } from '../utils/security.js';
import { Storage } from '../config/storage.js';
import * as tomlLoader from './toml-loader.js';
import { createPolicyEngineConfig } from './config.js';
vi.unmock('../config/storage.js'); vi.unmock('../config/storage.js');
vi.mock('../utils/security.js', () => ({ vi.mock('../utils/security.js', () => ({
@@ -26,8 +30,6 @@ afterEach(() => {
describe('createPolicyEngineConfig', () => { describe('createPolicyEngineConfig', () => {
beforeEach(async () => { beforeEach(async () => {
vi.resetModules();
const { Storage } = await import('../config/storage.js');
// Mock Storage to avoid picking up real user/system policies from the host environment // Mock Storage to avoid picking up real user/system policies from the host environment
vi.spyOn(Storage, 'getUserPoliciesDir').mockReturnValue( vi.spyOn(Storage, 'getUserPoliciesDir').mockReturnValue(
'/non/existent/user/policies', '/non/existent/user/policies',
@@ -40,7 +42,6 @@ describe('createPolicyEngineConfig', () => {
}); });
it('should filter out insecure system policy directories', async () => { it('should filter out insecure system policy directories', async () => {
const { Storage } = await import('../config/storage.js');
const systemPolicyDir = '/insecure/system/policies'; const systemPolicyDir = '/insecure/system/policies';
vi.spyOn(Storage, 'getSystemPoliciesDir').mockReturnValue(systemPolicyDir); vi.spyOn(Storage, 'getSystemPoliciesDir').mockReturnValue(systemPolicyDir);
@@ -51,10 +52,6 @@ describe('createPolicyEngineConfig', () => {
return { secure: true }; return { secure: true };
}); });
// We need to spy on loadPoliciesFromToml to verify which directories were passed
// But it is not exported from config.js, it is imported.
// We can spy on the module it comes from.
const tomlLoader = await import('./toml-loader.js');
const loadPoliciesSpy = vi.spyOn(tomlLoader, 'loadPoliciesFromToml'); const loadPoliciesSpy = vi.spyOn(tomlLoader, 'loadPoliciesFromToml');
loadPoliciesSpy.mockResolvedValue({ loadPoliciesSpy.mockResolvedValue({
rules: [], rules: [],
@@ -62,7 +59,6 @@ describe('createPolicyEngineConfig', () => {
errors: [], errors: [],
}); });
const { createPolicyEngineConfig } = await import('./config.js');
const settings: PolicySettings = {}; const settings: PolicySettings = {};
await createPolicyEngineConfig( await createPolicyEngineConfig(
@@ -80,7 +76,7 @@ describe('createPolicyEngineConfig', () => {
// But other directories (user, default) should be there // But other directories (user, default) should be there
expect(calledDirs).toContain('/non/existent/user/policies'); expect(calledDirs).toContain('/non/existent/user/policies');
expect(calledDirs).toContain('/tmp/mock/default/policies'); expect(calledDirs).toContain('/tmp/mock/default/policies');
}); }, 30000);
it('should return ASK_USER for write tools and ALLOW for read-only tools by default', async () => { it('should return ASK_USER for write tools and ALLOW for read-only tools by default', async () => {
const actualFs = const actualFs =