mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 05:12:55 -07:00
fix: Update test expectations to match createPolicyEngineConfig signature changes from rebase
This commit is contained in:
@@ -3243,6 +3243,8 @@ describe('Policy Engine Integration in loadCliConfig', () => {
|
|||||||
policyPaths: ['/path/to/policy1.toml', '/path/to/policy2.toml'],
|
policyPaths: ['/path/to/policy1.toml', '/path/to/policy2.toml'],
|
||||||
}),
|
}),
|
||||||
expect.anything(),
|
expect.anything(),
|
||||||
|
undefined,
|
||||||
|
expect.anything(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -44,10 +44,20 @@ describe('Project-Level Policies', () => {
|
|||||||
'node:fs/promises',
|
'node:fs/promises',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const mockStat = vi.fn(async (path: string) => {
|
||||||
|
if (typeof path === 'string' && path.startsWith('/mock/')) {
|
||||||
|
return {
|
||||||
|
isDirectory: () => true,
|
||||||
|
isFile: () => false,
|
||||||
|
} as unknown as Awaited<ReturnType<typeof actualFs.stat>>;
|
||||||
|
}
|
||||||
|
return actualFs.stat(path);
|
||||||
|
});
|
||||||
|
|
||||||
// Mock readdir to return a policy file for each tier
|
// Mock readdir to return a policy file for each tier
|
||||||
const mockReaddir = vi.fn(async (path: string) => {
|
const mockReaddir = vi.fn(async (path: string) => {
|
||||||
const normalizedPath = nodePath.normalize(path);
|
const normalizedPath = nodePath.normalize(path);
|
||||||
if (normalizedPath.includes('default'))
|
if (normalizedPath.endsWith('default/policies'))
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
name: 'default.toml',
|
name: 'default.toml',
|
||||||
@@ -55,11 +65,11 @@ describe('Project-Level Policies', () => {
|
|||||||
isDirectory: () => false,
|
isDirectory: () => false,
|
||||||
},
|
},
|
||||||
] as unknown as Awaited<ReturnType<typeof actualFs.readdir>>;
|
] as unknown as Awaited<ReturnType<typeof actualFs.readdir>>;
|
||||||
if (normalizedPath.includes('user'))
|
if (normalizedPath.endsWith('user/policies'))
|
||||||
return [
|
return [
|
||||||
{ name: 'user.toml', isFile: () => true, isDirectory: () => false },
|
{ name: 'user.toml', isFile: () => true, isDirectory: () => false },
|
||||||
] as unknown as Awaited<ReturnType<typeof actualFs.readdir>>;
|
] as unknown as Awaited<ReturnType<typeof actualFs.readdir>>;
|
||||||
if (normalizedPath.includes('project'))
|
if (normalizedPath.endsWith('project/policies'))
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
name: 'project.toml',
|
name: 'project.toml',
|
||||||
@@ -67,7 +77,7 @@ describe('Project-Level Policies', () => {
|
|||||||
isDirectory: () => false,
|
isDirectory: () => false,
|
||||||
},
|
},
|
||||||
] as unknown as Awaited<ReturnType<typeof actualFs.readdir>>;
|
] as unknown as Awaited<ReturnType<typeof actualFs.readdir>>;
|
||||||
if (normalizedPath.includes('system'))
|
if (normalizedPath.endsWith('system/policies'))
|
||||||
return [
|
return [
|
||||||
{ name: 'admin.toml', isFile: () => true, isDirectory: () => false },
|
{ name: 'admin.toml', isFile: () => true, isDirectory: () => false },
|
||||||
] as unknown as Awaited<ReturnType<typeof actualFs.readdir>>;
|
] as unknown as Awaited<ReturnType<typeof actualFs.readdir>>;
|
||||||
@@ -109,9 +119,15 @@ priority = 10
|
|||||||
|
|
||||||
vi.doMock('node:fs/promises', () => ({
|
vi.doMock('node:fs/promises', () => ({
|
||||||
...actualFs,
|
...actualFs,
|
||||||
default: { ...actualFs, readdir: mockReaddir, readFile: mockReadFile },
|
default: {
|
||||||
|
...actualFs,
|
||||||
readdir: mockReaddir,
|
readdir: mockReaddir,
|
||||||
readFile: mockReadFile,
|
readFile: mockReadFile,
|
||||||
|
stat: mockStat,
|
||||||
|
},
|
||||||
|
readdir: mockReaddir,
|
||||||
|
readFile: mockReadFile,
|
||||||
|
stat: mockStat,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const { createPolicyEngineConfig } = await import('./config.js');
|
const { createPolicyEngineConfig } = await import('./config.js');
|
||||||
@@ -152,8 +168,20 @@ priority = 10
|
|||||||
await vi.importActual<typeof import('node:fs/promises')>(
|
await vi.importActual<typeof import('node:fs/promises')>(
|
||||||
'node:fs/promises',
|
'node:fs/promises',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const mockStat = vi.fn(async (path: string) => {
|
||||||
|
if (typeof path === 'string' && path.startsWith('/mock/')) {
|
||||||
|
return {
|
||||||
|
isDirectory: () => true,
|
||||||
|
isFile: () => false,
|
||||||
|
} as unknown as Awaited<ReturnType<typeof actualFs.stat>>;
|
||||||
|
}
|
||||||
|
return actualFs.stat(path);
|
||||||
|
});
|
||||||
|
|
||||||
const mockReaddir = vi.fn(async (path: string) => {
|
const mockReaddir = vi.fn(async (path: string) => {
|
||||||
if (path.includes('default'))
|
const normalizedPath = nodePath.normalize(path);
|
||||||
|
if (normalizedPath.endsWith('default/policies'))
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
name: 'default.toml',
|
name: 'default.toml',
|
||||||
@@ -172,9 +200,15 @@ priority=10`,
|
|||||||
|
|
||||||
vi.doMock('node:fs/promises', () => ({
|
vi.doMock('node:fs/promises', () => ({
|
||||||
...actualFs,
|
...actualFs,
|
||||||
default: { ...actualFs, readdir: mockReaddir, readFile: mockReadFile },
|
default: {
|
||||||
|
...actualFs,
|
||||||
readdir: mockReaddir,
|
readdir: mockReaddir,
|
||||||
readFile: mockReadFile,
|
readFile: mockReadFile,
|
||||||
|
stat: mockStat,
|
||||||
|
},
|
||||||
|
readdir: mockReaddir,
|
||||||
|
readFile: mockReadFile,
|
||||||
|
stat: mockStat,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const { createPolicyEngineConfig } = await import('./config.js');
|
const { createPolicyEngineConfig } = await import('./config.js');
|
||||||
@@ -200,8 +234,20 @@ priority=10`,
|
|||||||
await vi.importActual<typeof import('node:fs/promises')>(
|
await vi.importActual<typeof import('node:fs/promises')>(
|
||||||
'node:fs/promises',
|
'node:fs/promises',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const mockStat = vi.fn(async (path: string) => {
|
||||||
|
if (typeof path === 'string' && path.startsWith('/mock/')) {
|
||||||
|
return {
|
||||||
|
isDirectory: () => true,
|
||||||
|
isFile: () => false,
|
||||||
|
} as unknown as Awaited<ReturnType<typeof actualFs.stat>>;
|
||||||
|
}
|
||||||
|
return actualFs.stat(path);
|
||||||
|
});
|
||||||
|
|
||||||
const mockReaddir = vi.fn(async (path: string) => {
|
const mockReaddir = vi.fn(async (path: string) => {
|
||||||
if (path.includes('project'))
|
const normalizedPath = nodePath.normalize(path);
|
||||||
|
if (normalizedPath.endsWith('project/policies'))
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
name: 'project.toml',
|
name: 'project.toml',
|
||||||
@@ -220,9 +266,15 @@ priority=500`,
|
|||||||
|
|
||||||
vi.doMock('node:fs/promises', () => ({
|
vi.doMock('node:fs/promises', () => ({
|
||||||
...actualFs,
|
...actualFs,
|
||||||
default: { ...actualFs, readdir: mockReaddir, readFile: mockReadFile },
|
default: {
|
||||||
|
...actualFs,
|
||||||
readdir: mockReaddir,
|
readdir: mockReaddir,
|
||||||
readFile: mockReadFile,
|
readFile: mockReadFile,
|
||||||
|
stat: mockStat,
|
||||||
|
},
|
||||||
|
readdir: mockReaddir,
|
||||||
|
readFile: mockReadFile,
|
||||||
|
stat: mockStat,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const { createPolicyEngineConfig } = await import('./config.js');
|
const { createPolicyEngineConfig } = await import('./config.js');
|
||||||
|
|||||||
Reference in New Issue
Block a user