Files
ruflo/v2/tests/unit/cli/commands/task-parsing.test.js
T
rUvandClaude Opus 4.5 1b6a1971f7 feat(v3): add comprehensive v3 implementation plans and swarm architecture
- Reorganize v3/ into implementation/ subfolders:
  - planning/, architecture/, migration/, integration/
  - security/, adrs/, research/, swarm-plans/

- Add 15-agent concurrent swarm implementation plans:
  - SWARM-OVERVIEW.md: Hierarchical mesh topology, 4 phases
  - AGENT-SPECIFICATIONS.md: 15 agent configs with capabilities
  - TDD-LONDON-SCHOOL-PLAN.md: Mock-first TDD methodology
  - BENCHMARK-OPTIMIZATION.md: Performance targets (2.49x-7.47x)
  - DEPLOYMENT-PLAN.md: Release strategy, CI/CD, rollback
  - GITHUB-ISSUE-TRACKING.md: Issue workflow with agent replies

- Update .claude/settings.json with proper hooks format
- Add bash aliases for claude --dangerously-skip-permissions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-04 15:40:51 +00:00

169 lines
6.2 KiB
JavaScript

// Tests for task.js argument parsing functionality
import { describe, it, expect, jest, beforeEach, afterEach } from '@jest/globals';
describe('Task Command Argument Parsing', () => {
let consoleLogSpy;
let taskCommand;
beforeEach(async () => {
consoleLogSpy = jest.spyOn(console, 'log').mockImplementation();
// Mock utils before importing
jest.doMock('../../../../src/cli/utils.js', () => ({
printSuccess: jest.fn((msg) => console.log(`✅ ${msg}`)),
printError: jest.fn((msg) => console.log(`❌ ${msg}`)),
printWarning: jest.fn((msg) => console.log(`⚠️ ${msg}`))
}));
// Dynamic import to avoid module caching issues
const taskModule = await import('../../../../src/cli/simple-commands/task.js');
taskCommand = taskModule.taskCommand;
});
afterEach(() => {
consoleLogSpy.mockRestore();
jest.clearAllMocks();
});
describe('create command', () => {
it('should parse simple quoted description correctly', async () => {
const args = ['create', 'research', '"Market analysis"'];
await taskCommand(args, {});
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('Creating research task:'));
expect(consoleLogSpy).toHaveBeenCalledWith('📋 Description: Market analysis');
});
it('should parse description with spaces in quotes', async () => {
const args = ['create', 'code', '"Implement user authentication system"'];
await taskCommand(args, {});
expect(consoleLogSpy).toHaveBeenCalledWith('📋 Description: Implement user authentication system');
});
it('should parse single-quoted descriptions', async () => {
const args = ['create', 'analysis', "'Data processing pipeline'"];
await taskCommand(args, {});
expect(consoleLogSpy).toHaveBeenCalledWith('📋 Description: Data processing pipeline');
});
it('should handle quotes within description', async () => {
const args = ['create', 'research', '"Analyze "best practices" for API design"'];
await taskCommand(args, {});
expect(consoleLogSpy).toHaveBeenCalledWith('📋 Description: Analyze "best practices" for API design');
});
it('should parse priority flag correctly', async () => {
const args = ['create', 'code', '"Build API"', '--priority', '8'];
await taskCommand(args, {});
expect(consoleLogSpy).toHaveBeenCalledWith('⚡ Priority: 8/10');
});
it('should use default priority when not specified', async () => {
const args = ['create', 'code', '"Build API"'];
await taskCommand(args, {});
expect(consoleLogSpy).toHaveBeenCalledWith('⚡ Priority: 5/10');
});
it('should handle unquoted multi-word descriptions', async () => {
const args = ['create', 'general', 'Quick', 'task', 'description'];
await taskCommand(args, {});
expect(consoleLogSpy).toHaveBeenCalledWith('📋 Description: Quick task description');
});
it('should error when type is missing', async () => {
const args = ['create'];
await taskCommand(args, {});
expect(consoleLogSpy).toHaveBeenCalledWith('❌ Usage: task create <type> "<description>"');
});
it('should error when description is missing', async () => {
const args = ['create', 'research'];
await taskCommand(args, {});
expect(consoleLogSpy).toHaveBeenCalledWith('❌ Usage: task create <type> "<description>"');
});
it('should handle edge case of empty quotes', async () => {
const args = ['create', 'research', '""'];
await taskCommand(args, {});
expect(consoleLogSpy).toHaveBeenCalledWith('❌ Usage: task create <type> "<description>"');
});
it('should handle mismatched quotes gracefully', async () => {
const args = ['create', 'code', '"Unclosed quote'];
await taskCommand(args, {});
expect(consoleLogSpy).toHaveBeenCalledWith('📋 Description: "Unclosed quote');
});
});
describe('list command', () => {
it('should parse filter flag correctly', async () => {
const args = ['list', '--filter', 'running'];
await taskCommand(args, {});
expect(consoleLogSpy).toHaveBeenCalledWith('📊 Filtered by status: running');
});
it('should parse verbose flag', async () => {
const args = ['list', '--verbose'];
await taskCommand(args, {});
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('To create tasks:'));
});
it('should parse short verbose flag', async () => {
const args = ['list', '-v'];
await taskCommand(args, {});
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('To create tasks:'));
});
it('should handle multiple flags', async () => {
const args = ['list', '--filter', 'completed', '--verbose'];
await taskCommand(args, {});
expect(consoleLogSpy).toHaveBeenCalledWith('📊 Filtered by status: completed');
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('To create tasks:'));
});
});
describe('edge cases', () => {
it('should handle special characters in description', async () => {
const args = ['create', 'code', '"Implement feature #123 @high-priority"'];
await taskCommand(args, {});
expect(consoleLogSpy).toHaveBeenCalledWith('📋 Description: Implement feature #123 @high-priority');
});
it('should handle unicode in description', async () => {
const args = ['create', 'research', '"研究 AI 技术 🚀"'];
await taskCommand(args, {});
expect(consoleLogSpy).toHaveBeenCalledWith('📋 Description: 研究 AI 技术 🚀');
});
it('should handle very long descriptions', async () => {
const longDesc = 'A'.repeat(200);
const args = ['create', 'analysis', `"${longDesc}"`];
await taskCommand(args, {});
expect(consoleLogSpy).toHaveBeenCalledWith(`📋 Description: ${longDesc}`);
});
it('should handle command injection attempts safely', async () => {
const args = ['create', 'code', '"Test; rm -rf /"'];
await taskCommand(args, {});
expect(consoleLogSpy).toHaveBeenCalledWith('📋 Description: Test; rm -rf /');
});
});
});