migrate restore command (#4388)

This commit is contained in:
Abhi
2025-07-17 19:23:17 -04:00
committed by GitHub
parent f0dc9690b7
commit 5df6c9fb66
7 changed files with 424 additions and 123 deletions

View File

@@ -26,6 +26,7 @@ import { mcpCommand } from '../ui/commands/mcpCommand.js';
import { editorCommand } from '../ui/commands/editorCommand.js';
import { bugCommand } from '../ui/commands/bugCommand.js';
import { quitCommand } from '../ui/commands/quitCommand.js';
import { restoreCommand } from '../ui/commands/restoreCommand.js';
// Mock the command modules to isolate the service from the command implementations.
vi.mock('../ui/commands/memoryCommand.js', () => ({
@@ -79,6 +80,9 @@ vi.mock('../ui/commands/bugCommand.js', () => ({
vi.mock('../ui/commands/quitCommand.js', () => ({
quitCommand: { name: 'quit', description: 'Mock Quit' },
}));
vi.mock('../ui/commands/restoreCommand.js', () => ({
restoreCommand: vi.fn(),
}));
describe('CommandService', () => {
const subCommandLen = 17;
@@ -87,8 +91,10 @@ describe('CommandService', () => {
beforeEach(() => {
mockConfig = {
getIdeMode: vi.fn(),
getCheckpointingEnabled: vi.fn(),
} as unknown as Mocked<Config>;
vi.mocked(ideCommand).mockReturnValue(null);
vi.mocked(restoreCommand).mockReturnValue(null);
});
describe('when using default production loader', () => {
@@ -151,6 +157,20 @@ describe('CommandService', () => {
expect(commandNames).toContain('quit');
});
it('should include restore command when checkpointing is on', async () => {
mockConfig.getCheckpointingEnabled.mockReturnValue(true);
vi.mocked(restoreCommand).mockReturnValue({
name: 'restore',
description: 'Mock Restore',
});
await commandService.loadCommands();
const tree = commandService.getCommands();
expect(tree.length).toBe(subCommandLen + 1);
const commandNames = tree.map((cmd) => cmd.name);
expect(commandNames).toContain('restore');
});
it('should overwrite any existing commands when called again', async () => {
// Load once
await commandService.loadCommands();