codeburn/tests/bash-commands.test.ts
Rafael Calleja a5696362f2 refactor: share BASH_TOOLS from classifier, remove comments
- Export BASH_TOOLS from classifier.ts instead of duplicating in bash-utils.ts
- Remove isBashTool helper (use BASH_TOOLS.has() directly)
- Strip unnecessary comments per codebase conventions
2026-04-14 10:24:38 +02:00

67 lines
2.2 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { extractBashCommands } from '../src/bash-utils.js'
import { BASH_TOOLS } from '../src/classifier.js'
describe('extractBashCommands', () => {
it('extracts single command', () => {
expect(extractBashCommands('git status')).toEqual(['git'])
})
it('extracts chained commands with &&', () => {
expect(extractBashCommands('git add . && git commit -m "x"')).toEqual(['git', 'git'])
})
it('extracts chained commands with ;', () => {
expect(extractBashCommands('ls; pwd')).toEqual(['ls', 'pwd'])
})
it('extracts piped commands', () => {
expect(extractBashCommands('cat file | grep pattern')).toEqual(['cat', 'grep'])
})
it('filters out cd', () => {
expect(extractBashCommands('cd /path && git status')).toEqual(['git'])
})
it('returns empty for cd only', () => {
expect(extractBashCommands('cd /path')).toEqual([])
})
it('returns empty for empty string', () => {
expect(extractBashCommands('')).toEqual([])
})
it('returns empty for whitespace only', () => {
expect(extractBashCommands(' ')).toEqual([])
})
it('extracts basename from full path binary', () => {
expect(extractBashCommands('/usr/bin/git status')).toEqual(['git'])
})
it('handles mixed separators', () => {
expect(extractBashCommands('cd /x && npm install; npm run build | tee log')).toEqual(['npm', 'npm', 'tee'])
})
it('handles extra whitespace', () => {
expect(extractBashCommands(' git status ')).toEqual(['git'])
})
it('handles command with quotes containing separators', () => {
expect(extractBashCommands('echo "hello && world"')).toEqual(['echo'])
})
it('handles quoted separators followed by real separator', () => {
expect(extractBashCommands('echo "hello && world" && git status')).toEqual(['echo', 'git'])
})
it('handles single-quoted separators', () => {
expect(extractBashCommands("echo 'hello && world'")).toEqual(['echo'])
})
})
describe('BASH_TOOLS', () => {
it('recognizes Bash', () => { expect(BASH_TOOLS.has('Bash')).toBe(true) })
it('recognizes BashTool', () => { expect(BASH_TOOLS.has('BashTool')).toBe(true) })
it('rejects unknown tools', () => { expect(BASH_TOOLS.has('Read')).toBe(false) })
})