test: add comprehensive tests for useStatusLine hook and statuslineCommand

Cover config validation, command execution with exec options, stdin JSON
payload, stale generation rejection, debouncing, config removal, cleanup
on unmount, EPIPE handling, command hot-reload, all state change triggers
(token count, model, branch, vim toggle, file lines), and process management.
This commit is contained in:
wenshao 2026-04-09 15:50:41 +08:00
parent 36aadd7fa1
commit f25fc047f1
2 changed files with 662 additions and 0 deletions

View file

@ -0,0 +1,78 @@
/**
* @license
* Copyright 2025 Qwen
* SPDX-License-Identifier: Apache-2.0
*/
import { describe, it, expect, beforeEach } from 'vitest';
import { statuslineCommand } from './statuslineCommand.js';
import { type CommandContext } from './types.js';
import { createMockCommandContext } from '../../test-utils/mockCommandContext.js';
describe('statuslineCommand', () => {
let mockContext: CommandContext;
beforeEach(() => {
mockContext = createMockCommandContext();
});
it('should have the correct name and description', () => {
expect(statuslineCommand.name).toBe('statusline');
expect(statuslineCommand.description).toBeDefined();
});
it('should return submit_prompt with default prompt when no args', () => {
if (!statuslineCommand.action) {
throw new Error('statusline command must have an action');
}
const result = statuslineCommand.action(mockContext, '');
expect(result).toEqual({
type: 'submit_prompt',
content: [
{
text: expect.stringContaining('statusline-setup'),
},
],
});
// Default prompt should mention PS1
expect(result).toHaveProperty(
'content.0.text',
expect.stringContaining('PS1'),
);
});
it('should use user-provided args as the prompt', () => {
if (!statuslineCommand.action) {
throw new Error('statusline command must have an action');
}
const result = statuslineCommand.action(
mockContext,
'show model name and git branch',
);
expect(result).toEqual({
type: 'submit_prompt',
content: [
{
text: expect.stringContaining('show model name and git branch'),
},
],
});
});
it('should trim whitespace-only args and use default prompt', () => {
if (!statuslineCommand.action) {
throw new Error('statusline command must have an action');
}
const result = statuslineCommand.action(mockContext, ' ');
expect(result).toHaveProperty(
'content.0.text',
expect.stringContaining('PS1'),
);
});
});