mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
updated /quit to use new slash command arch (#4259)
Co-authored-by: Abhi <abhipatel@google.com>
This commit is contained in:
@@ -54,16 +54,7 @@ vi.mock('../../utils/version.js', () => ({
|
||||
}));
|
||||
|
||||
import { act, renderHook } from '@testing-library/react';
|
||||
import {
|
||||
vi,
|
||||
describe,
|
||||
it,
|
||||
expect,
|
||||
beforeEach,
|
||||
afterEach,
|
||||
beforeAll,
|
||||
Mock,
|
||||
} from 'vitest';
|
||||
import { vi, describe, it, expect, beforeEach, beforeAll, Mock } from 'vitest';
|
||||
import open from 'open';
|
||||
import { useSlashCommandProcessor } from './slashCommandProcessor.js';
|
||||
import { SlashCommandProcessorResult } from '../types.js';
|
||||
@@ -203,8 +194,6 @@ describe('useSlashCommandProcessor', () => {
|
||||
);
|
||||
};
|
||||
|
||||
const getProcessor = () => getProcessorHook().result.current;
|
||||
|
||||
describe('New command registry', () => {
|
||||
let ActualCommandService: typeof CommandService;
|
||||
|
||||
@@ -451,47 +440,4 @@ describe('useSlashCommandProcessor', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('/quit and /exit commands', () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it.each([['/quit'], ['/exit']])(
|
||||
'should handle %s, set quitting messages, and exit the process',
|
||||
async (command) => {
|
||||
const { handleSlashCommand } = getProcessor();
|
||||
const mockDate = new Date('2025-01-01T01:02:03.000Z');
|
||||
vi.setSystemTime(mockDate);
|
||||
|
||||
await act(async () => {
|
||||
handleSlashCommand(command);
|
||||
});
|
||||
|
||||
expect(mockAddItem).not.toHaveBeenCalled();
|
||||
expect(mockSetQuittingMessages).toHaveBeenCalledWith([
|
||||
{
|
||||
type: 'user',
|
||||
text: command,
|
||||
id: expect.any(Number),
|
||||
},
|
||||
{
|
||||
type: 'quit',
|
||||
duration: '1h 2m 3s',
|
||||
id: expect.any(Number),
|
||||
},
|
||||
]);
|
||||
|
||||
// Fast-forward timers to trigger process.exit
|
||||
await act(async () => {
|
||||
vi.advanceTimersByTime(100);
|
||||
});
|
||||
expect(mockProcessExit).toHaveBeenCalledWith(0);
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -20,7 +20,6 @@ import {
|
||||
} from '../types.js';
|
||||
import { promises as fs } from 'fs';
|
||||
import path from 'path';
|
||||
import { formatDuration } from '../utils/formatters.js';
|
||||
import { LoadedSettings } from '../../config/settings.js';
|
||||
import {
|
||||
type CommandContext,
|
||||
@@ -202,33 +201,6 @@ export const useSlashCommandProcessor = (
|
||||
toggleCorgiMode();
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'quit',
|
||||
altName: 'exit',
|
||||
description: 'exit the cli',
|
||||
action: async (mainCommand, _subCommand, _args) => {
|
||||
const now = new Date();
|
||||
const { sessionStartTime } = session.stats;
|
||||
const wallDuration = now.getTime() - sessionStartTime.getTime();
|
||||
|
||||
setQuittingMessages([
|
||||
{
|
||||
type: 'user',
|
||||
text: `/${mainCommand}`,
|
||||
id: now.getTime() - 1,
|
||||
},
|
||||
{
|
||||
type: 'quit',
|
||||
duration: formatDuration(wallDuration),
|
||||
id: now.getTime(),
|
||||
},
|
||||
]);
|
||||
|
||||
setTimeout(() => {
|
||||
process.exit(0);
|
||||
}, 100);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
if (config?.getCheckpointingEnabled()) {
|
||||
@@ -352,15 +324,7 @@ export const useSlashCommandProcessor = (
|
||||
});
|
||||
}
|
||||
return commands;
|
||||
}, [
|
||||
addMessage,
|
||||
toggleCorgiMode,
|
||||
config,
|
||||
session,
|
||||
gitService,
|
||||
loadHistory,
|
||||
setQuittingMessages,
|
||||
]);
|
||||
}, [addMessage, toggleCorgiMode, config, gitService, loadHistory]);
|
||||
|
||||
const handleSlashCommand = useCallback(
|
||||
async (
|
||||
@@ -470,6 +434,12 @@ export const useSlashCommandProcessor = (
|
||||
});
|
||||
return { type: 'handled' };
|
||||
}
|
||||
case 'quit':
|
||||
setQuittingMessages(result.messages);
|
||||
setTimeout(() => {
|
||||
process.exit(0);
|
||||
}, 100);
|
||||
return { type: 'handled' };
|
||||
default: {
|
||||
const unhandled: never = result;
|
||||
throw new Error(`Unhandled slash command result: ${unhandled}`);
|
||||
@@ -549,6 +519,7 @@ export const useSlashCommandProcessor = (
|
||||
openThemeDialog,
|
||||
openPrivacyNotice,
|
||||
openEditorDialog,
|
||||
setQuittingMessages,
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user