Ghost Writer is an end-to-end automated testing pipeline powered by Grok 3 (via GitHub Models). It monitors your active feature branches, automatically writes your test suites for you, and securely auto-merges your code to master after validating it in an isolated Docker environment.
The pipeline operates in two distinct phases:
- Push Code: A developer pushes new source code (e.g.,
.js,.py) to their working branch. - CI Trigger: GitHub Actions identifies the newly changed files.
- AI Generation: The "Ghost" script sends the new code to Grok 3 to generate the corresponding unit tests.
- Pull Request: A temporary branch (
ghost/tests-...) is created, and a PR is opened targeting the original working branch. - Clean Up: Once the developer reviews and merges the generated tests into their working branch, the temporary ghost branch is automatically deleted.
- Target Master: The developer opens a PR from their feature branch (now containing the code + generated tests) into the
masterbranch. - Docker Build: The
PR Test Validatorworkflow triggers, building a fresh Docker image (pr-tests) to ensure an isolated testing environment. - Automated Execution: The tests are executed inside the Docker container.
- Outcome Action: ✅ Success: The bot comments "All tests passed. Auto-merging." and automatically merges the PR into
master. ❌ Failure: The bot comments with the exact terminal error output and instantly closes the PR, preventing broken code from reaching production.
src/ghost_writer.py- The AI logic (GitHub Models integration).src/run_ghost.sh- The Git orchestrator (Diffing, Branching, PR creation)..github/workflows/ghost.yml- The AI test generation trigger for feature branches..github/workflows/valid.yml- The Docker validation and auto-merge trigger for the master branch.Dockerfile- The container configuration for running the test suite.
Ensure the following secrets are added to your GitHub Repository (Settings > Secrets and variables > Actions):
GH_MODELS_TOKEN: A Personal Access Token (PAT) withmodels:readpermissions.GITHUB_TOKEN: Automatically handled by GitHub Actions (used by the GitHub CLIghto create, comment, and merge PRs).
Go to Settings > Actions > General and set Workflow permissions to:
Read and write permissions- Check
Allow GitHub Actions to create and approve pull requests.
To ensure smooth operation of the workflows:
- Go to Settings > General.
- Scroll down to the Pull Requests section.
- Check Allow auto-merge (Required for the bot to run
gh pr merge). - Check Automatically delete head branches (Keeps the repo clean after Ghost branches and feature branches are merged).
To see the full pipeline in action:
# 1. Create a feature branch and push code
git checkout -b feature/new-logic
git add src/logic.js
git commit -m "feat: add business logic"
git push origin feature/new-logic
# -> Ghost Writer opens a PR with logic.test.js. Merge it into your feature branch.
# 2. Open a PR from your feature branch to master
gh pr create --base master --head feature/new-logic --title "Merge new logic to master" --body "Testing auto-merge pipeline."
# -> PR Test Validator builds Docker, runs the tests, and auto-merges if successful!