Test Coded Tests
Overview
Use scripts/run_tests_json.py from the repository root. It detects Rails/RSpec first, then Node package tests, runs the best available command, captures noisy runner output, and prints one JSON object to stdout. In Croft-style Rails repos that provide bin/run-specs, the script must use RAILS_ENV=test bin/rails run specs so specs run through the repo's parallel runner against test databases; when an ignored .env.test contains a DATABASE_URL with TEST_ENV_NUMBER, the script temporarily hides that file during the command so parallel_tests can assign per-worker database names, then restores it. When the parallel run fails, it reruns only the failed spec files it can extract from the output and reports that rerun in the JSON.
Workflow
Run:
python3 /home/will/.codex/skills/test-coded-tests/scripts/run_tests_json.pyIf the user supplied specific test paths or runner args, pass them after
--:python3 /home/will/.codex/skills/test-coded-tests/scripts/run_tests_json.py -- spec/models/user_spec.rbReturn the JSON output directly when the user asks for machine-readable output. Otherwise summarize the
summary.failedcount and thefailures[].fileentries.
Detection
- Croft Rails/RSpec:
Gemfileplusbin/run-specsrunsRAILS_ENV=test bin/rails run specs, which usesparallel_rspec, and reruns extracted failed spec files withRAILS_ENV=test bin/rails run specs FAILED_SPEC_FILES. - Generic Rails/RSpec:
Gemfileplus Rails/RSpec signals runsbundle exec rspec --format json. - Node:
package.jsonrunsnpm test; Jest and Vitest projects get JSON reporter flags when detectable. - Unsupported repos return JSON with
status: "not_found"instead of prose.
Output Contract
The script always writes clean JSON to stdout. Key fields:
status:passed,failed,error,timeout,dry_run, ornot_foundenvironment.type: detected runner such ascroft_parallel_rspec,rails_rspec,npm_jest,npm_vitest, ornpmrerun: present when the Croft parallel runner failed and the script reran the extracted failed spec filessummary.failed: failed example/test countfailures: grouped by filename, with example names, line numbers when available, and short messages