Skip to content

Commit fd4408c

Browse files
authored
T-021: Add multi-execution support to exec command (#125)
* T-021: Add multi-execution support to exec command - Add --all, --indexes, --until-success, --summary flags to exec command - Implement JSONL streaming output with run records and summary - Add comprehensive command selection logic with precedence handling - Support index ranges (e.g., '0,2-3') and validation - Maintain backward compatibility with single command execution - Add 19 comprehensive unit tests covering all new functionality - Update README.md with detailed multi-execution documentation - Implement proper error handling and validation for all new features Resolves #111 * Fix CI issues: mypy command, JSON output, and exit codes - Fix mypy command in CI workflow to specify autorepro tests paths - Fix JSON output parsing in exec CLI tests for multi-execution format - Fix exit code mismatch: return 2 for out-of-range index errors - Update unit tests to expect correct exit codes - Prevent duplicate JSONL records in multi-execution mode - Add noqa comment for PLR0912 complexity warning Resolves CI test failures for T-021
1 parent 13c4266 commit fd4408c

6 files changed

Lines changed: 933 additions & 24 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
run: python -m ruff check .
5353

5454
- name: Mypy (type check)
55-
run: mypy || true
55+
run: mypy autorepro tests || true
5656

5757
- name: Export PYTHON_BIN
5858
run: echo "PYTHON_BIN=$(which python)" >> $GITHUB_ENV

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,69 @@ $ autorepro scan --json --show 3
291291
- **Python**: `pyproject.toml`, `setup.py`, `requirements.txt`, `*.py`
292292
- **Rust**: `Cargo.toml`, `Cargo.lock`, `*.rs`
293293

294+
### Exec Command (Multi-execution Support)
295+
296+
Executes commands from a reproduction plan with support for single or multiple command execution, early stopping, and structured logging.
297+
298+
```bash
299+
# Execute single command (default behavior)
300+
$ autorepro exec --desc "pytest failing"
301+
# Executes the top-ranked command
302+
303+
# Execute all candidate commands in order
304+
$ autorepro exec --desc "pytest failing" --all
305+
# Runs all suggested commands sequentially
306+
307+
# Execute specific commands by index
308+
$ autorepro exec --desc "test issues" --indexes "0,2-4"
309+
# Runs commands at indices 0, 2, 3, and 4
310+
311+
# Stop at first successful command
312+
$ autorepro exec --desc "build problems" --until-success
313+
# Stops execution after first command with exit code 0
314+
315+
# Multi-execution with JSONL logging
316+
$ autorepro exec --desc "CI tests" --all --jsonl runs.jsonl --summary summary.json
317+
318+
# Dry-run to preview selected commands
319+
$ autorepro exec --desc "npm test" --indexes "1,3" --dry-run
320+
[1] npm test --verbose
321+
[3] npm run test:unit
322+
```
323+
324+
**Multi-execution Features:**
325+
326+
- **`--all`**: Execute all candidate commands in their original order
327+
- **`--indexes "N,M-P"`**: Execute specific commands by indices/ranges (comma-separated)
328+
- **`--until-success`**: Stop after the first command that exits with code 0
329+
- **`--summary FILE.json`**: Write final execution summary to JSON file
330+
- **Command precedence**: `--indexes` takes precedence over `--all`, both override single `--index`
331+
332+
**JSONL Output Format:**
333+
334+
When using `--jsonl`, each execution produces a run record followed by a final summary:
335+
336+
```jsonl
337+
{"type": "run", "index": 0, "cmd": "pytest", "start_ts": "2025-09-13T12:00:00Z", "end_ts": "2025-09-13T12:00:05Z", "exit_code": 1, "duration_ms": 5000}
338+
{"type": "run", "index": 1, "cmd": "pytest -v", "start_ts": "2025-09-13T12:00:05Z", "end_ts": "2025-09-13T12:00:08Z", "exit_code": 0, "duration_ms": 3000}
339+
{"type": "summary", "schema_version": 1, "tool": "autorepro", "runs": 2, "successes": 1, "first_success_index": 1}
340+
```
341+
342+
**Execution Options:**
343+
344+
- `--timeout N`: Command timeout in seconds (default: 120)
345+
- `--env KEY=VAL`: Set environment variable (repeatable)
346+
- `--env-file PATH`: Load environment variables from file
347+
- `--tee PATH`: Append full stdout/stderr to log file
348+
- `--jsonl PATH`: Stream JSONL records for each run and summary
349+
- `--dry-run`: Print selected commands without executing
350+
351+
**Exit Behavior:**
352+
353+
- **Single execution**: Returns the command's exit code
354+
- **Multi-execution**: Returns 0 if any command succeeded, otherwise the last exit code
355+
- **`--until-success`**: Returns 0 when a command succeeds, otherwise the last failure code
356+
294357
### Init Command
295358

296359
Creates a devcontainer.json file with default configuration (Python 3.11, Node 20, Go 1.22). The command is idempotent and provides atomic file writes.

0 commit comments

Comments
 (0)