Skip to content

test(python): add missing test categories — builtins, strings, scripts #1260

@chaliy

Description

@chaliy

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:

  • date runs without error

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

  • test_builtins.py has 30+ tests covering all builtins listed above
  • test_strings_and_quoting.py has 20+ tests covering all string/quoting scenarios
  • test_scripts.py has 15+ tests covering real-world script patterns
  • Each test is self-contained (creates its own Bash instance)
  • Tests cover both positive (expected output) and negative (error) cases
  • Tests use execute_sync() for simplicity; at least 2 per file use await execute() for async coverage
  • All tests pass: pytest crates/bashkit-python/tests/ -v
  • ruff check passes
  • No test names duplicate existing tests in other files

Depends on

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions