mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 08:47:44 +00:00
updated /stats to use new slash command arch (#4146)
This commit is contained in:
@@ -54,7 +54,16 @@ vi.mock('../../utils/version.js', () => ({
|
||||
}));
|
||||
|
||||
import { act, renderHook } from '@testing-library/react';
|
||||
import { vi, describe, it, expect, beforeEach, afterEach, Mock } from 'vitest';
|
||||
import {
|
||||
vi,
|
||||
describe,
|
||||
it,
|
||||
expect,
|
||||
beforeEach,
|
||||
afterEach,
|
||||
beforeAll,
|
||||
Mock,
|
||||
} from 'vitest';
|
||||
import open from 'open';
|
||||
import { useSlashCommandProcessor } from './slashCommandProcessor.js';
|
||||
import { MessageType, SlashCommandProcessorResult } from '../types.js';
|
||||
@@ -207,76 +216,6 @@ describe('useSlashCommandProcessor', () => {
|
||||
const getProcessor = (showToolDescriptions: boolean = false) =>
|
||||
getProcessorHook(showToolDescriptions).result.current;
|
||||
|
||||
describe('/stats command', () => {
|
||||
it('should show detailed session statistics', async () => {
|
||||
// Arrange
|
||||
mockUseSessionStats.mockReturnValue({
|
||||
stats: {
|
||||
sessionStartTime: new Date('2025-01-01T00:00:00.000Z'),
|
||||
},
|
||||
});
|
||||
|
||||
const { handleSlashCommand } = getProcessor();
|
||||
const mockDate = new Date('2025-01-01T01:02:03.000Z'); // 1h 2m 3s duration
|
||||
vi.setSystemTime(mockDate);
|
||||
|
||||
// Act
|
||||
await act(async () => {
|
||||
handleSlashCommand('/stats');
|
||||
});
|
||||
|
||||
// Assert
|
||||
expect(mockAddItem).toHaveBeenNthCalledWith(
|
||||
2, // Called after the user message
|
||||
expect.objectContaining({
|
||||
type: MessageType.STATS,
|
||||
duration: '1h 2m 3s',
|
||||
}),
|
||||
expect.any(Number),
|
||||
);
|
||||
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('should show model-specific statistics when using /stats model', async () => {
|
||||
// Arrange
|
||||
const { handleSlashCommand } = getProcessor();
|
||||
|
||||
// Act
|
||||
await act(async () => {
|
||||
handleSlashCommand('/stats model');
|
||||
});
|
||||
|
||||
// Assert
|
||||
expect(mockAddItem).toHaveBeenNthCalledWith(
|
||||
2, // Called after the user message
|
||||
expect.objectContaining({
|
||||
type: MessageType.MODEL_STATS,
|
||||
}),
|
||||
expect.any(Number),
|
||||
);
|
||||
});
|
||||
|
||||
it('should show tool-specific statistics when using /stats tools', async () => {
|
||||
// Arrange
|
||||
const { handleSlashCommand } = getProcessor();
|
||||
|
||||
// Act
|
||||
await act(async () => {
|
||||
handleSlashCommand('/stats tools');
|
||||
});
|
||||
|
||||
// Assert
|
||||
expect(mockAddItem).toHaveBeenNthCalledWith(
|
||||
2, // Called after the user message
|
||||
expect.objectContaining({
|
||||
type: MessageType.TOOL_STATS,
|
||||
}),
|
||||
expect.any(Number),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Other commands', () => {
|
||||
it('/editor should open editor dialog and return handled', async () => {
|
||||
const { handleSlashCommand } = getProcessor();
|
||||
|
||||
@@ -247,36 +247,6 @@ export const useSlashCommandProcessor = (
|
||||
description: 'set external editor preference',
|
||||
action: (_mainCommand, _subCommand, _args) => openEditorDialog(),
|
||||
},
|
||||
{
|
||||
name: 'stats',
|
||||
altName: 'usage',
|
||||
description: 'check session stats. Usage: /stats [model|tools]',
|
||||
action: (_mainCommand, subCommand, _args) => {
|
||||
if (subCommand === 'model') {
|
||||
addMessage({
|
||||
type: MessageType.MODEL_STATS,
|
||||
timestamp: new Date(),
|
||||
});
|
||||
return;
|
||||
} else if (subCommand === 'tools') {
|
||||
addMessage({
|
||||
type: MessageType.TOOL_STATS,
|
||||
timestamp: new Date(),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
const { sessionStartTime } = session.stats;
|
||||
const wallDuration = now.getTime() - sessionStartTime.getTime();
|
||||
|
||||
addMessage({
|
||||
type: MessageType.STATS,
|
||||
duration: formatDuration(wallDuration),
|
||||
timestamp: new Date(),
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'mcp',
|
||||
description: 'list configured MCP servers and tools',
|
||||
|
||||
Reference in New Issue
Block a user