mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-21 02:24:09 -07:00
fix(core): ensure sandbox approvals are correctly persisted and matched for proactive expansions (#24577)
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
||||
shortenPath,
|
||||
normalizePath,
|
||||
resolveToRealPath,
|
||||
makeRelative,
|
||||
} from './paths.js';
|
||||
|
||||
vi.mock('node:fs', async (importOriginal) => {
|
||||
@@ -215,7 +216,7 @@ describe('isSubpath', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('isSubpath on Windows', () => {
|
||||
describe.skipIf(process.platform !== 'win32')('isSubpath on Windows', () => {
|
||||
afterEach(() => vi.unstubAllGlobals());
|
||||
|
||||
beforeEach(() => mockPlatform('win32'));
|
||||
@@ -268,6 +269,20 @@ describe('isSubpath on Windows', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe.skipIf(process.platform !== 'darwin')('isSubpath on Darwin', () => {
|
||||
afterEach(() => vi.unstubAllGlobals());
|
||||
|
||||
beforeEach(() => mockPlatform('darwin'));
|
||||
|
||||
it('should be case-insensitive for path components on Darwin', () => {
|
||||
expect(isSubpath('/PROJECT', '/project/src')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true for a direct subpath on Darwin', () => {
|
||||
expect(isSubpath('/Users/Test', '/Users/Test/file.txt')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('shortenPath', () => {
|
||||
describe.skipIf(process.platform === 'win32')('on POSIX', () => {
|
||||
it('should not shorten a path that is shorter than maxLen', () => {
|
||||
@@ -586,6 +601,54 @@ describe('resolveToRealPath', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('makeRelative', () => {
|
||||
describe.skipIf(process.platform === 'win32')('on POSIX', () => {
|
||||
it('should return relative path if targetPath is already relative', () => {
|
||||
expect(makeRelative('foo/bar', '/root')).toBe('foo/bar');
|
||||
});
|
||||
|
||||
it('should return relative path from root to target', () => {
|
||||
const root = '/Users/test/project';
|
||||
const target = '/Users/test/project/src/file.ts';
|
||||
expect(makeRelative(target, root)).toBe('src/file.ts');
|
||||
});
|
||||
|
||||
it('should return "." if target and root are the same', () => {
|
||||
const root = '/Users/test/project';
|
||||
expect(makeRelative(root, root)).toBe('.');
|
||||
});
|
||||
|
||||
it('should handle parent directories with ..', () => {
|
||||
const root = '/Users/test/project/src';
|
||||
const target = '/Users/test/project/docs/readme.md';
|
||||
expect(makeRelative(target, root)).toBe('../docs/readme.md');
|
||||
});
|
||||
});
|
||||
|
||||
describe.skipIf(process.platform !== 'win32')('on Windows', () => {
|
||||
it('should return relative path if targetPath is already relative', () => {
|
||||
expect(makeRelative('foo/bar', 'C:\\root')).toBe('foo/bar');
|
||||
});
|
||||
|
||||
it('should return relative path from root to target', () => {
|
||||
const root = 'C:\\Users\\test\\project';
|
||||
const target = 'C:\\Users\\test\\project\\src\\file.ts';
|
||||
expect(makeRelative(target, root)).toBe('src\\file.ts');
|
||||
});
|
||||
|
||||
it('should return "." if target and root are the same', () => {
|
||||
const root = 'C:\\Users\\test\\project';
|
||||
expect(makeRelative(root, root)).toBe('.');
|
||||
});
|
||||
|
||||
it('should handle parent directories with ..', () => {
|
||||
const root = 'C:\\Users\\test\\project\\src';
|
||||
const target = 'C:\\Users\\test\\project\\docs\\readme.md';
|
||||
expect(makeRelative(target, root)).toBe('..\\docs\\readme.md');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('normalizePath', () => {
|
||||
it('should resolve a relative path to an absolute path', () => {
|
||||
const result = normalizePath('some/relative/path');
|
||||
@@ -615,7 +678,19 @@ describe('normalizePath', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe.skipIf(process.platform === 'win32')('on POSIX', () => {
|
||||
describe.skipIf(process.platform !== 'darwin')('on Darwin', () => {
|
||||
beforeEach(() => mockPlatform('darwin'));
|
||||
afterEach(() => vi.unstubAllGlobals());
|
||||
|
||||
it('should lowercase the entire path', () => {
|
||||
const result = normalizePath('/Users/TEST');
|
||||
expect(result).toBe('/users/test');
|
||||
});
|
||||
});
|
||||
|
||||
describe.skipIf(
|
||||
process.platform === 'win32' || process.platform === 'darwin',
|
||||
)('on Linux', () => {
|
||||
it('should preserve case', () => {
|
||||
const result = normalizePath('/usr/Local/Bin');
|
||||
expect(result).toContain('Local');
|
||||
|
||||
Reference in New Issue
Block a user