This project includes a pre-commit workflow that uses Codex to generate or update tests for the current git changes, then runs only those managed tests before allowing a commit.
- Builds or refreshes
test-memory.jsonfrompackage.jsonto capture framework, versions, and test setup. - Sends the current git diff and
test-memory.jsonto Codex for test generation or updates. - Tracks all test files written by the hook in
test-memory.jsonand runs only those files. - Stages generated tests and
test-memory.jsonautomatically. - Blocks the commit if Codex fails or managed tests fail.
- Read
package.jsonto detect framework, language, and test setup. - Load or create
test-memory.json. - Build the git diff (staged + unstaged).
- Run
codex execwith the diff and memory. - Register any changed tests in
test-memory.json. - Run
npm test -- --watchAll=false --runTestsByPath <managed_files>. - Allow the commit only if tests pass.
The workflow generates and maintains internal metadata and logs as part of the pre-commit process.
chmod +x scripts/ai_test_gen_precommit.py
cat > .git/hooks/pre-commit <<'SH'
#!/bin/sh
python3 scripts/ai_test_gen_precommit.py
SH
chmod +x .git/hooks/pre-commitCODEX_CMDto override the Codex CLI (default:codex exec --color=never).CODEX_TIMEOUTto limit Codex runtime in seconds (default: 300).
