Skip to content

feat(cli): --shard <i>/<n> to split the suite across CI runners #739

Description

@Chemaclass

Summary

Add --shard <index>/<total> to run a deterministic subset of tests, so a large suite can be split across parallel CI machines (e.g. matrix jobs). Different from --parallel (which parallelizes on one host).

Motivation

Big suites want horizontal scaling across CI runners. Standard pattern (Jest/Playwright): --shard 1/4, --shard 2/4, … each runner executes its slice; union == full suite, no overlap. Verified missing: grep -- --shard src/*.sh → none.

Proposed API

bashunit --shard 1/4 tests/    # runner 1 of 4
bashunit --shard 2/4 tests/    # runner 2 of 4
  • 1-indexed index, 1 <= index <= total.
  • Partition the collected test list deterministically (e.g. i-th, i+total-th, … round-robin, or contiguous chunks — pick and document). Round-robin balances better when files vary in size.
  • Invalid input (index > total, total < 1, non-numeric) → clear error, non-zero exit.
  • Composable with --parallel (shard first, then parallelize the slice).

Files

  • Flag parsing + validation: src/globals.sh.
  • Partition logic: src/runner.sh (after the full test list is collected, before execution).
  • Docs: docs/command-line.md + a CI matrix example in docs/command-line.md or docs/common-patterns.md.
  • Tests: tests/acceptance/bashunit_test.sh.

TDD steps

  1. RED: with N fixture tests, --shard 1/2 and --shard 2/2 run disjoint subsets whose union is all N (assert counts / list of executed names).
  2. RED: --shard 3/2 errors out with non-zero exit and a clear message.
  3. GREEN: minimal partition.
  4. REFACTOR: verify --shard 1/2 --parallel works.

Acceptance criteria

  • --shard i/n parsed and validated (bad input → error + non-zero exit).
  • Partition is deterministic, disjoint, and covers the full suite across all shards.
  • Composes with --parallel.
  • Docs (with CI matrix snippet) + CHANGELOG (Unreleased → Added) updated.

Constraints

  • Bash 3.0+ only. See .claude/rules/bash-style.md.
  • Must pass make sa, make lint, shfmt -w ., ./bashunit tests/, ./bashunit --parallel tests/.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions