-
Notifications
You must be signed in to change notification settings - Fork 9.5k
chore: add scripts/dev/test.sh — chunked FIFO local test wrapper (~1.75x faster) #2719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LahkLeKey
wants to merge
3
commits into
github:main
Choose a base branch
from
LahkLeKey:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+110
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| #!/usr/bin/env bash | ||
| # Spec Kit local test wrapper — chunked FIFO dispatch over pytest-xdist. | ||
| # | ||
| # Design (matches the chunked-task / bounded-memory pattern): | ||
| # * Collect node ids once: `pytest --collect-only -q`. | ||
| # * Split the collection into fixed-size chunks (default 200 nodes). | ||
| # * Dispatch chunks sequentially as a FIFO queue; inside each chunk, | ||
| # pytest-xdist's `--dist=load` hands tests out one at a time to | ||
| # workers as they finish — natural FIFO progression with bounded | ||
| # in-flight memory. | ||
| # * Persist the cursor (next chunk index) to | ||
| # `.pytest_cache/fast-test-cursor` after every successful chunk so | ||
| # `--resume` continues exactly where a crash left off. | ||
| # * `--reset` clears the cursor; `--bench` reports wall-time only. | ||
| # | ||
| # Usage: | ||
| # scripts/dev/test.sh # full suite, chunked | ||
| # scripts/dev/test.sh --chunk-size 100 | ||
| # scripts/dev/test.sh --resume # continue from cursor | ||
| # scripts/dev/test.sh --reset # clear cursor | ||
| # scripts/dev/test.sh --bench # time only, no -v | ||
| # scripts/dev/test.sh -- tests/test_merge.py # pass-through to pytest | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" | ||
| CURSOR_FILE="$REPO_ROOT/.pytest_cache/fast-test-cursor" | ||
|
|
||
| CHUNK_SIZE=200 | ||
| RESUME=0 | ||
| RESET=0 | ||
| BENCH=0 | ||
| PASSTHROUGH=() | ||
|
|
||
| while (( $# )); do | ||
| case "$1" in | ||
| --chunk-size) CHUNK_SIZE="$2"; shift 2 ;; | ||
| --resume) RESUME=1; shift ;; | ||
| --reset) RESET=1; shift ;; | ||
| --bench) BENCH=1; shift ;; | ||
| --) shift; PASSTHROUGH+=("$@"); break ;; | ||
| -h|--help) sed -n '2,22p' "$0"; exit 0 ;; | ||
| *) PASSTHROUGH+=("$1"); shift ;; | ||
| esac | ||
| done | ||
|
|
||
| if (( RESET )); then | ||
| rm -f "$CURSOR_FILE" | ||
| echo "[fast-test] cursor cleared" | ||
| exit 0 | ||
| fi | ||
|
|
||
| cd "$REPO_ROOT" | ||
| mkdir -p "$(dirname "$CURSOR_FILE")" | ||
|
|
||
| # 1. Collect node ids. | ||
| echo "[fast-test] collecting tests ..." | ||
| COLLECT_ERR="$(mktemp)" | ||
| COLLECT_OUT="$(mktemp)" | ||
| if ! uv run pytest --collect-only -qq "${PASSTHROUGH[@]}" >"$COLLECT_OUT" 2>"$COLLECT_ERR"; then | ||
| echo "[fast-test] test collection failed" >&2 | ||
| [[ -s "$COLLECT_ERR" ]] && { echo "--- collection stderr ---"; cat "$COLLECT_ERR"; } >&2 | ||
| rm -f "$COLLECT_ERR" "$COLLECT_OUT" | ||
| exit 1 | ||
| fi | ||
| mapfile -t NODES < <(grep -E '::' "$COLLECT_OUT" || true) | ||
| rm -f "$COLLECT_ERR" "$COLLECT_OUT" | ||
| TOTAL="${#NODES[@]}" | ||
| if (( TOTAL == 0 )); then | ||
| echo "[fast-test] no tests collected" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # 2. Determine starting cursor. | ||
| START=0 | ||
| if (( RESUME )) && [[ -f "$CURSOR_FILE" ]]; then | ||
| START="$(cat "$CURSOR_FILE")" | ||
| echo "[fast-test] resuming from next test index: $START" | ||
| fi | ||
|
|
||
| CHUNKS=$(( (TOTAL - START + CHUNK_SIZE - 1) / CHUNK_SIZE )) | ||
| echo "[fast-test] $TOTAL tests · chunk=$CHUNK_SIZE · $CHUNKS chunk(s) queued · workers=auto" | ||
|
|
||
| # 3. FIFO dispatch. | ||
| T_START=$(date +%s) | ||
| i="$START" | ||
|
LahkLeKey marked this conversation as resolved.
|
||
| chunk_idx=0 | ||
| while (( i < TOTAL )); do | ||
| end=$(( i + CHUNK_SIZE )) | ||
| (( end > TOTAL )) && end="$TOTAL" | ||
| chunk_idx=$(( chunk_idx + 1 )) | ||
| echo "[fast-test] chunk $chunk_idx/$CHUNKS tests $((i+1))..$end" | ||
|
|
||
| PYTEST_FLAGS=(-n auto --dist=load) | ||
| (( BENCH )) && PYTEST_FLAGS+=(-q) || PYTEST_FLAGS+=(--no-header -q) | ||
|
|
||
| if ! uv run pytest "${PYTEST_FLAGS[@]}" "${NODES[@]:i:CHUNK_SIZE}"; then | ||
| echo "[fast-test] chunk failed — cursor preserved at next test index $i (use --resume to retry)" | ||
| echo "$i" > "$CURSOR_FILE" | ||
| exit 1 | ||
| fi | ||
|
|
||
| i="$end" | ||
| echo "$i" > "$CURSOR_FILE" | ||
| done | ||
|
|
||
| T_END=$(date +%s) | ||
| rm -f "$CURSOR_FILE" | ||
| echo "[fast-test] all $TOTAL tests passed in $((T_END - T_START))s" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.