Context
Node bindings have dedicated, comprehensive test files for builtin commands (64 tests in builtins.spec.ts), string/quoting operations (23 tests in strings-and-quoting.spec.ts), and script patterns (20 tests in scripts.spec.ts). Python has these behaviors tested incidentally within other test files but lacks dedicated, systematic coverage.
After #1259 restructures Python tests to match the Node file layout, these new files will exist but be thin. This issue fills them with comprehensive tests matching Node's coverage.
This is part of the Python ↔ Node binding parity effort (Phase 2 — Test Structure Alignment).
What to implement
test_builtins.py — Dedicated builtin command tests
Add tests mirroring Node's builtins.spec.ts (64 tests). Each test should verify a specific builtin works correctly through the Python Bash class:
File operations:
cat reads file, cat concatenates files
head -n limits lines, tail -n limits lines
wc -l counts lines, wc -w counts words
Text processing:
grep basic match, grep -i case insensitive, grep -v inverted, grep -c count, grep no match returns non-zero
sed substitute, sed global substitute, sed delete line
awk print field, awk with separator, awk sum column
sort ascending, sort -r descending, sort -n numeric
uniq removes adjacent duplicates, sort | uniq -c counts
tr transliterate, tr delete characters
cut field extraction
Output/encoding:
printf basic, printf with number
base64 encode and decode
seq generates range, seq with step
Environment:
export and env, unset variable
Data processing:
jq extract field, jq array length, jq filter array
md5sum produces hash, sha256sum produces hash
Other:
test_strings_and_quoting.py — String and quoting tests
Add tests mirroring Node's strings-and-quoting.spec.ts (23 tests):
- Single quotes preserve literal value
- Double quotes expand variables
- Double quotes preserve spaces
- Backslash escaping in double quotes
- Nested command substitution in quotes
- Heredoc basic, heredoc with variable expansion, heredoc quoted delimiter suppresses expansion
- String concatenation, string replacement, string replacement global
- Uppercase/lowercase conversion (
${var^^}, ${var,,})
- Array declaration and access, array length, array all elements, array append, array in for loop
- Empty string variable, newlines in variable, tab character
- Semicolon separates commands
- Long string handling
test_scripts.py — Real-world script pattern tests
Add tests mirroring Node's scripts.spec.ts (20 tests):
- Count lines in file
- Find and replace in file
- Extract unique values
- JSON processing pipeline
- Create directory tree and verify
- Config file generator
- Loop with accumulator
- Data transformation pipeline
- Error handling with
||
- Conditional file creation
- Function with multiple operations (multiline)
- Nested loops (multiline)
- While read loop (multiline)
- BashTool: LLM-style single command
- BashTool: LLM-style multi-step script
- BashTool: LLM-style data analysis
- BashTool: sequential calls build state
- Many sequential commands
- Large output
- Empty stdin pipe
Acceptance criteria
Depends on
Context
Node bindings have dedicated, comprehensive test files for builtin commands (64 tests in
builtins.spec.ts), string/quoting operations (23 tests instrings-and-quoting.spec.ts), and script patterns (20 tests inscripts.spec.ts). Python has these behaviors tested incidentally within other test files but lacks dedicated, systematic coverage.After #1259 restructures Python tests to match the Node file layout, these new files will exist but be thin. This issue fills them with comprehensive tests matching Node's coverage.
This is part of the Python ↔ Node binding parity effort (Phase 2 — Test Structure Alignment).
What to implement
test_builtins.py — Dedicated builtin command tests
Add tests mirroring Node's
builtins.spec.ts(64 tests). Each test should verify a specific builtin works correctly through the PythonBashclass:File operations:
catreads file,catconcatenates fileshead -nlimits lines,tail -nlimits lineswc -lcounts lines,wc -wcounts wordsText processing:
grepbasic match,grep -icase insensitive,grep -vinverted,grep -ccount, grep no match returns non-zerosedsubstitute,sedglobal substitute,seddelete lineawkprint field,awkwith separator,awksum columnsortascending,sort -rdescending,sort -nnumericuniqremoves adjacent duplicates,sort | uniq -ccountstrtransliterate,trdelete characterscutfield extractionOutput/encoding:
printfbasic,printfwith numberbase64encode and decodeseqgenerates range,seqwith stepEnvironment:
exportandenv,unsetvariableData processing:
jqextract field,jqarray length,jqfilter arraymd5sumproduces hash,sha256sumproduces hashOther:
dateruns without errortest_strings_and_quoting.py — String and quoting tests
Add tests mirroring Node's
strings-and-quoting.spec.ts(23 tests):${var^^},${var,,})test_scripts.py — Real-world script pattern tests
Add tests mirroring Node's
scripts.spec.ts(20 tests):||Acceptance criteria
test_builtins.pyhas 30+ tests covering all builtins listed abovetest_strings_and_quoting.pyhas 20+ tests covering all string/quoting scenariostest_scripts.pyhas 15+ tests covering real-world script patternsexecute_sync()for simplicity; at least 2 per file useawait execute()for async coveragepytest crates/bashkit-python/tests/ -vruff checkpassesDepends on