mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
feature(commands) - Refactor Slash Command + Vision For the Future (#3175)
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { describe, it, expect, vi, beforeEach, Mock } from 'vitest';
|
||||
import { Config, ConfigParameters, SandboxConfig } from './config.js';
|
||||
import * as path from 'path';
|
||||
import { setGeminiMdFilename as mockSetGeminiMdFilename } from '../tools/memoryTool.js';
|
||||
@@ -13,6 +13,8 @@ import {
|
||||
DEFAULT_OTLP_ENDPOINT,
|
||||
} from '../telemetry/index.js';
|
||||
|
||||
import { loadServerHierarchicalMemory } from '../utils/memoryDiscovery.js';
|
||||
|
||||
// Mock dependencies that might be called during Config construction or createServerConfig
|
||||
vi.mock('../tools/tool-registry', () => {
|
||||
const ToolRegistryMock = vi.fn();
|
||||
@@ -24,6 +26,10 @@ vi.mock('../tools/tool-registry', () => {
|
||||
return { ToolRegistry: ToolRegistryMock };
|
||||
});
|
||||
|
||||
vi.mock('../utils/memoryDiscovery.js', () => ({
|
||||
loadServerHierarchicalMemory: vi.fn(),
|
||||
}));
|
||||
|
||||
// Mock individual tools if their constructors are complex or have side effects
|
||||
vi.mock('../tools/ls');
|
||||
vi.mock('../tools/read-file');
|
||||
@@ -270,4 +276,38 @@ describe('Server Config (config.ts)', () => {
|
||||
expect(config.getTelemetryOtlpEndpoint()).toBe(DEFAULT_OTLP_ENDPOINT);
|
||||
});
|
||||
});
|
||||
|
||||
describe('refreshMemory', () => {
|
||||
it('should update memory and file count on successful refresh', async () => {
|
||||
const config = new Config(baseParams);
|
||||
const mockMemoryData = {
|
||||
memoryContent: 'new memory content',
|
||||
fileCount: 5,
|
||||
};
|
||||
|
||||
(loadServerHierarchicalMemory as Mock).mockResolvedValue(mockMemoryData);
|
||||
|
||||
const result = await config.refreshMemory();
|
||||
|
||||
expect(loadServerHierarchicalMemory).toHaveBeenCalledWith(
|
||||
config.getWorkingDir(),
|
||||
config.getDebugMode(),
|
||||
config.getFileService(),
|
||||
config.getExtensionContextFilePaths(),
|
||||
);
|
||||
|
||||
expect(config.getUserMemory()).toBe(mockMemoryData.memoryContent);
|
||||
expect(config.getGeminiMdFileCount()).toBe(mockMemoryData.fileCount);
|
||||
expect(result).toEqual(mockMemoryData);
|
||||
});
|
||||
|
||||
it('should propagate errors from loadServerHierarchicalMemory', async () => {
|
||||
const config = new Config(baseParams);
|
||||
const testError = new Error('Failed to load memory');
|
||||
|
||||
(loadServerHierarchicalMemory as Mock).mockRejectedValue(testError);
|
||||
|
||||
await expect(config.refreshMemory()).rejects.toThrow(testError);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user