Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/__tests__/command-hash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ describe('normalizeCommand', () => {
expect(normalizeCommand('echo hello\t\tworld')).toBe('echo hello world')
})

it('lowercases the entire string', () => {
expect(normalizeCommand('ECHO HELLO')).toBe('echo hello')
})

it('handles combined: " FOO BAR " → "foo bar"', () => {
expect(normalizeCommand(' FOO BAR ')).toBe('foo bar')
it('handles combined: " FOO BAR " → "FOO BAR"', () => {
expect(normalizeCommand(' FOO BAR ')).toBe('FOO BAR')
})

it('throws on empty string', () => {
Expand Down Expand Up @@ -47,10 +43,10 @@ describe('hashCommand', () => {
})

it('round-trip: normalizeCommand then hashCommand is stable across calls', () => {
const input = ' ECHO Hello World '
const input = ' echo Hello World '
const hash1 = hashCommand(normalizeCommand(input))
const hash2 = hashCommand(normalizeCommand(input))
expect(hash1).toBe(hash2)
expect(hash1).toBe(hashCommand('echo hello world'))
expect(hash1).toBe(hashCommand('echo Hello World'))
})
})
2 changes: 1 addition & 1 deletion src/core/command-hash.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createHash } from 'node:crypto'

export function normalizeCommand(cmd: string): string {
const normalized = cmd.trim().replace(/\s+/g, ' ').toLowerCase()
const normalized = cmd.trim().replace(/\s+/g, ' ')
if (normalized.length === 0) {
throw new Error('command must not be empty')
}
Expand Down