mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-14 03:50:49 -07:00
feat(core): Land ContextCompressionService (#24483)
This commit is contained in:
@@ -7,21 +7,23 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { discoverJitContext, appendJitContext } from './jit-context.js';
|
||||
import type { Config } from '../config/config.js';
|
||||
import type { ContextManager } from '../context/contextManager.js';
|
||||
import type { MemoryContextManager } from '../context/memoryContextManager.js';
|
||||
|
||||
describe('jit-context', () => {
|
||||
describe('discoverJitContext', () => {
|
||||
let mockConfig: Config;
|
||||
let mockContextManager: ContextManager;
|
||||
let mockMemoryContextManager: MemoryContextManager;
|
||||
|
||||
beforeEach(() => {
|
||||
mockContextManager = {
|
||||
mockMemoryContextManager = {
|
||||
discoverContext: vi.fn().mockResolvedValue(''),
|
||||
} as unknown as ContextManager;
|
||||
} as unknown as MemoryContextManager;
|
||||
|
||||
mockConfig = {
|
||||
isJitContextEnabled: vi.fn().mockReturnValue(false),
|
||||
getContextManager: vi.fn().mockReturnValue(mockContextManager),
|
||||
getMemoryContextManager: vi
|
||||
.fn()
|
||||
.mockReturnValue(mockMemoryContextManager),
|
||||
getWorkspaceContext: vi.fn().mockReturnValue({
|
||||
getDirectories: vi.fn().mockReturnValue(['/app']),
|
||||
}),
|
||||
@@ -34,27 +36,27 @@ describe('jit-context', () => {
|
||||
const result = await discoverJitContext(mockConfig, '/app/src/file.ts');
|
||||
|
||||
expect(result).toBe('');
|
||||
expect(mockContextManager.discoverContext).not.toHaveBeenCalled();
|
||||
expect(mockMemoryContextManager.discoverContext).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should return empty string when contextManager is undefined', async () => {
|
||||
it('should return empty string when memoryContextManager is undefined', async () => {
|
||||
vi.mocked(mockConfig.isJitContextEnabled).mockReturnValue(true);
|
||||
vi.mocked(mockConfig.getContextManager).mockReturnValue(undefined);
|
||||
vi.mocked(mockConfig.getMemoryContextManager).mockReturnValue(undefined);
|
||||
|
||||
const result = await discoverJitContext(mockConfig, '/app/src/file.ts');
|
||||
|
||||
expect(result).toBe('');
|
||||
});
|
||||
|
||||
it('should call contextManager.discoverContext with correct args when JIT is enabled', async () => {
|
||||
it('should call memoryContextManager.discoverContext with correct args when JIT is enabled', async () => {
|
||||
vi.mocked(mockConfig.isJitContextEnabled).mockReturnValue(true);
|
||||
vi.mocked(mockContextManager.discoverContext).mockResolvedValue(
|
||||
vi.mocked(mockMemoryContextManager.discoverContext).mockResolvedValue(
|
||||
'Subdirectory context content',
|
||||
);
|
||||
|
||||
const result = await discoverJitContext(mockConfig, '/app/src/file.ts');
|
||||
|
||||
expect(mockContextManager.discoverContext).toHaveBeenCalledWith(
|
||||
expect(mockMemoryContextManager.discoverContext).toHaveBeenCalledWith(
|
||||
'/app/src/file.ts',
|
||||
['/app'],
|
||||
);
|
||||
@@ -66,11 +68,11 @@ describe('jit-context', () => {
|
||||
vi.mocked(mockConfig.getWorkspaceContext).mockReturnValue({
|
||||
getDirectories: vi.fn().mockReturnValue(['/app', '/lib']),
|
||||
} as unknown as ReturnType<Config['getWorkspaceContext']>);
|
||||
vi.mocked(mockContextManager.discoverContext).mockResolvedValue('');
|
||||
vi.mocked(mockMemoryContextManager.discoverContext).mockResolvedValue('');
|
||||
|
||||
await discoverJitContext(mockConfig, '/app/src/file.ts');
|
||||
|
||||
expect(mockContextManager.discoverContext).toHaveBeenCalledWith(
|
||||
expect(mockMemoryContextManager.discoverContext).toHaveBeenCalledWith(
|
||||
'/app/src/file.ts',
|
||||
['/app', '/lib'],
|
||||
);
|
||||
@@ -78,7 +80,7 @@ describe('jit-context', () => {
|
||||
|
||||
it('should return empty string when no new context is found', async () => {
|
||||
vi.mocked(mockConfig.isJitContextEnabled).mockReturnValue(true);
|
||||
vi.mocked(mockContextManager.discoverContext).mockResolvedValue('');
|
||||
vi.mocked(mockMemoryContextManager.discoverContext).mockResolvedValue('');
|
||||
|
||||
const result = await discoverJitContext(mockConfig, '/app/src/file.ts');
|
||||
|
||||
@@ -87,7 +89,7 @@ describe('jit-context', () => {
|
||||
|
||||
it('should return empty string when discoverContext throws', async () => {
|
||||
vi.mocked(mockConfig.isJitContextEnabled).mockReturnValue(true);
|
||||
vi.mocked(mockContextManager.discoverContext).mockRejectedValue(
|
||||
vi.mocked(mockMemoryContextManager.discoverContext).mockRejectedValue(
|
||||
new Error('Permission denied'),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user