JieGou has evolved.
Since this post was published, JieGou has pivoted from an AI automation platform to an AI-powered operations company delivering managed marketing and operations services. Learn about our managed services →
Update, November 2026: the Coding Agent used in this walkthrough is not available on any plan. It will run only in an isolated sandbox, which is not yet offered. The workflow below is how it will work when it is.
Test coverage is one of those metrics everyone agrees matters and nobody wants to be responsible for improving. You know the pattern: a codebase starts at 90% coverage, then a few features ship without tests, then a refactor skips the test update because “we’ll come back to it.” Six months later you’re at 60% and climbing back up feels like a full-time job that nobody signed up for.
This post walks through a JieGou workflow designed to close that gap: on every merge to main, it finds untested functions, has the Coding Agent write tests for them, and opens a pull request for review.
The problem
Coverage tends to decline the same way:
- New features ship without tests because developers are focused on delivery deadlines
- Utility functions, data transformers and validation logic go untested because they look too simple to bother with
- CI runs tests but doesn’t enforce coverage thresholds, so the decline stays invisible until someone checks
Dedicated “test writing sprints” tend to get deprioritized the moment a customer escalation comes in. Manual test writing is slow, tedious, and competes with every other priority.
The workflow
The workflow has 4 steps and is designed to trigger automatically when code merges to main. No manual intervention is needed unless a generated test needs revision.
Step 1: Trigger — GitHub webhook on PR merge
The workflow starts with a webhook trigger that fires when a pull request is merged to main.
trigger:
type: webhook
source: github
events: ["pull_request.closed"]
filters:
- field: "action"
value: "closed"
- field: "pull_request.merged"
value: true
- field: "pull_request.base.ref"
value: "main"
The webhook payload includes the list of changed files, the merge commit SHA, and the PR metadata. All of this feeds into the next step.
Step 2: Analyze — Identify untested functions
A recipe step takes the list of changed files from the webhook and cross-references them against the most recent coverage report. The recipe prompt is straightforward:
step: analyze-coverage
type: recipe
model: claude-sonnet-4-6
input:
changed_files: "{{trigger.pull_request.changed_files}}"
coverage_report: "{{secrets.COVERAGE_REPORT_URL}}"
prompt: |
You are a test coverage analyst. Given the list of changed files
and the coverage report (lcov format), identify:
1. Which changed files have less than 80% line coverage
2. Which exported functions in those files have zero coverage
3. The function signatures and a brief description of what each does
Output a JSON array of objects with fields:
file_path, function_name, signature, description, current_coverage
This step produces a structured list of exactly which functions need tests. It filters out files that already have adequate coverage, so the coding agent doesn’t waste time on code that’s already tested.
Step 3: Generate — Coding Agent writes the tests
This is where the Coding Agent does the heavy lifting. It receives the list of untested functions, clones the repository, and writes unit tests for each one.
step: generate-tests
type: coding-agent
model: claude-sonnet-4-6
repo: "{{secrets.REPO_URL}}"
branch: "test-gen/{{trigger.pull_request.number}}"
maxTurns: 30
sandbox:
memory: "1GB"
timeout: "5m"
network: false
tools:
- read
- write
- edit
- bash
- glob
- grep
input:
untested_functions: "{{steps.analyze-coverage.output}}"
task: |
You are a senior test engineer. Your job is to write unit tests for
the following untested functions:
{{untested_functions}}
Instructions:
1. Read the source file for each function to understand its behavior
2. Read existing test files in the same directory for style conventions
3. Write tests using the project's test framework (vitest)
4. Each test file should cover: happy path, edge cases, error handling
5. Run `npm test -- --reporter=verbose <test-file>` after writing each
test file to verify all tests pass
6. If a test fails, read the error, fix the test, and re-run
7. Do NOT modify source code — only create or update test files
Match the existing test style: describe blocks, clear test names,
arrange-act-assert pattern. Use the existing fixtures and helpers
where available.
The key configuration choices here:
- Model: Claude Sonnet 4.6 — fast enough for high-volume test generation, smart enough to understand complex function signatures and edge cases.
- Sandbox: 1 GB memory, 5-minute timeout — enough headroom for
npm testruns without risking runaway processes. - Network disabled — the agent doesn’t need external access; everything is in the cloned repo.
- maxTurns: 30 — allows the agent to iterate on multiple test files and fix failures across several cycles.
The task description includes a critical instruction: read existing test files first. This ensures the generated tests match the team’s conventions — same assertion style, same describe/it structure, same fixture patterns. Without this, generated tests are technically correct but stylistically inconsistent, which creates friction during review.
Step 4: Submit — Create a PR with results
After the coding agent finishes, a final recipe step creates a pull request with the generated tests and includes the test results in the PR description.
step: submit-pr
type: recipe
model: claude-sonnet-4-6
input:
modified_files: "{{steps.generate-tests.modified_files}}"
test_output: "{{steps.generate-tests.output}}"
source_pr: "{{trigger.pull_request.number}}"
prompt: |
Create a pull request with the following:
- Title: "test: auto-generated tests for PR #{{source_pr}}"
- Body: Include a summary of tests added, functions covered,
and the full test output showing all tests passing
- Label: "auto-tests"
- Request review from the original PR author
The PR is labeled auto-tests so the team can filter and batch-review generated test PRs. Requesting review from the original PR author means the person most familiar with the code sees the tests first.
Design notes
Start with pure functions
Pure functions (utilities, validators, transformers, formatters) are the best first target: they have clear inputs, clear outputs, and no side effects, so the agent can read the function, understand the contract, and write tests against it.
Modules with database connections, external API calls and shared mutable state are harder: generated tests risk mocking too much or testing implementation details rather than behavior. The analyze step can prioritize pure functions and queue complex modules for manual review.
Provide existing test examples
The task description tells the agent to read existing test files in the same directory first. Without that instruction, generated tests can be functionally correct but use different assertion patterns, describe-block structures and naming conventions from the rest of the suite.
Run tests before the PR is created
The task tells the agent to run npm test on each test file it writes and to fix failures before finishing, so a PR does not arrive with import errors, missing fixtures or failing assertions. The loop (write test, run test, read error, fix test, re-run) is how a human would work.
Review for quality, not just coverage
Coverage is a proxy metric. A test that asserts expect(result).toBeDefined() technically covers the function but doesn’t verify behavior. A review checklist for generated test PRs:
- Does each test verify a meaningful behavior, not just that the function runs?
- Are edge cases covered (null inputs, empty arrays, boundary values)?
- Do test descriptions clearly state what behavior is being tested?
- Are assertions specific (
.toBe(42)not.toBeTruthy())?
The configuration in full
For teams that want to replicate this workflow, here is the complete step configuration:
workflow:
name: "Auto Test Generation"
description: "Generate unit tests for untested code on PR merge"
trigger:
type: webhook
source: github
events: ["pull_request.closed"]
filters:
- field: "pull_request.merged"
value: true
- field: "pull_request.base.ref"
value: "main"
steps:
- id: analyze-coverage
type: recipe
model: claude-sonnet-4-6
# ... (see Step 2 above)
- id: generate-tests
type: coding-agent
model: claude-sonnet-4-6
dependsOn: [analyze-coverage]
# ... (see Step 3 above)
- id: submit-pr
type: recipe
model: claude-sonnet-4-6
dependsOn: [generate-tests]
# ... (see Step 4 above)
Most of a run’s time would be the coding agent iterating through test files and running npm test after each one.
Possible extensions
The same pattern extends in two directions:
- Integration tests — a separate coding agent step that generates integration tests for API endpoints, using the existing test helpers and database fixtures
- Coverage enforcement — a CI check that fails the build if coverage drops below a threshold, once the baseline is high enough to enforce
The broader lesson: test coverage doesn’t have to be a manual chore. With the right workflow, you can treat it as an automated pipeline that runs alongside your existing CI/CD — no dedicated sprints, no deprioritization, no coverage debt.
The Coding Agent is not available on any plan today. It will run only in an isolated sandbox, which is not yet offered. We’ll update this post when that changes.