This playbook uses Antigravity CLI as its primary interface. It is for developers who can already run a project’s tests and want to delegate test writing to an agent. You will produce a diff containing only one new test file, a mutation-check record that goes from green to red and back to green, and a review and recovery checklist. You can apply the same boundary in Antigravity App or an IDE extension: use plans and the Review pane in the App, or accept and reject individual changes in the IDE extension. See Create a project in the Antigravity app and review artifacts and IDE extensions: Review agent changes in your editor for how those interfaces present the work.
This is an independent, unofficial guidebook with no affiliation with Google. The function, repository, and command output on this page are synthetic. The commands were not run while preparing this page. Execution modes, permissions, and review interfaces can change; if the product you see differs from this page, follow the official page.
In plain English: A test-writing agent can also change the code under test
Section titled “In plain English: A test-writing agent can also change the code under test”A chat response gives you test code and leaves you to decide where to save it. An agent can read the repository, create files, and run commands. If the prompt says only “make the tests pass,” the agent may change both the tests and the implementation, leaving a green suite that proves nothing about whether the original function is protected.
This playbook therefore separates two scopes: the agent’s persistent changes may add only one test file; the source under test remains read-only. First build a behavior inventory and derive assertions from current behavior by following Add tests for an existing function. This page adds execution modes, permissions, review, and recovery for an agent-run task.
You will also perform one mutation check. A person temporarily breaks one behavior in the source, verifies that the new tests fail for the right reason, and immediately restores the source. That temporary mutation does not authorize the agent to change the implementation. The final diff must still contain only the new test file. If the suite remains green after the mutation, the tests do not protect the target behavior.
Minimal example
Section titled “Minimal example”Weak prompt:
Write a complete test suite for lateFeeCents. If the implementation is wrong, fix it too, and finish with passing tests.This mixes test design, implementation changes, and the goal of manufacturing a green result. Rewrite it as follows:
First, analyze the current behavior of lateFeeCents without writing anything. Produce a test table and wait for my approval.
Persistent change scope: you may only add test/late-fee.test.js.Do not change src/, package.json, lockfiles, existing tests, configuration, or dependencies.Do not delete, skip, or weaken assertions. If current behavior looks defective, record it as an open question; do not fix it.
Run the existing tests first and preserve the baseline. After adding the test file, run the same command and report the command,exit status, and output. Then stop. I will perform a one-line mutation manually; you may only analyze whether the failurematches the target behavior. Finally, report git status --short, git diff for tracked files, andgit diff --no-index -- /dev/null test/late-fee.test.js for the new file. The last command exits with 1 when it finds the expected difference.The /dev/null form used below is for POSIX. In Windows CMD, use NUL: git diff --no-index -- NUL test/late-fee.test.js.
The boundary names not only “do not change source,” but also the one allowed path, explicit exclusions, pause points, and the final diff criterion. That makes an out-of-scope edit an observable failure rather than an argument over whether a “helpful fix” counts as completion.
Complete example: Add tests for a late-fee function
Section titled “Complete example: Add tests for a late-fee function”Starting materials
Section titled “Starting materials”The synthetic demo-fees repository uses Node.js 24, ECMAScript modules, and the built-in test runner. test/smoke.test.js is an unrelated existing smoke test. The target function has no tests yet.
demo-fees/|-- package.json|-- src/| `-- late-fee.js`-- test/ `-- smoke.test.js{ "type": "module", "scripts": { "test": "node --test" }}export function lateFeeCents(daysLate) { if (!Number.isInteger(daysLate) || daysLate <= 0) return 0; return Math.min(daysLate * 25, 500);}The current behavior can be derived from the source: non-integers, zero, and negative numbers return 0; positive integers cost 25 cents per day; the fee reaches its 500-cent cap on day 20 and does not increase afterward. This describes current behavior, not a confirmed product requirement. For how to select cases and separate an existing behavior from a defect, see Add tests for an existing function.
Set the scope and permissions first
Section titled “Set the scope and permissions first”The agent’s only persistent write target is test/late-fee.test.js. CLI permission rules use action(target), and conflicting rules follow Deny > Ask > Allow. This example denies known out-of-scope files and leaves the target test file behind default diff review. Unmatched workspace paths are not an automatic deny, so these rules do not replace line-by-line review. See Permissions and sandbox: what presets, rules, and the sandbox each control for the rule syntax and scopes.
The following task-level rules are an unrun illustration. Check paths and the active rule scope in your own synthetic repository instead of overwriting an existing configuration mechanically:
{ "permissions": { "allow": [ "command(node --test)", "command(git status --short)", "command(git diff)", "command(git diff --no-index -- /dev/null test/late-fee.test.js)" ], "deny": [ "write_file(src/)", "write_file(test/smoke.test.js)", "write_file(package.json)", "write_file(package-lock.json)", "command(git commit)", "command(git push)" ] }}The rules are a second boundary; keep the scope in the prompt as well. Do not replace these narrow rules with command(*) or a global permission-bypass switch. See Before enabling auto or Turbo: risks, acceptable cases, and reversal for which review gates broader settings remove.
Mode, inspection, and output at each step
Section titled “Mode, inspection, and output at each step”| Step | Execution mode and permissions | What you inspect | Expected artifact |
|---|---|---|---|
| 1. Establish a baseline | plan; read source, configuration, and existing tests without writing |
File inventory, test command, and source evidence for every behavior | Behavior table and test plan |
| 2. Add tests | Switch to default; permit only the target test file and review every command |
The edit prompt names only test/late-fee.test.js |
A one-file addition diff |
| 3. Run and review | default; approve only node --test, git status --short, git diff for tracked files, and git diff --no-index for the new file |
Command, exit status, output, and changed-file list | Green post-change record |
| 4. Mutation check | Keep default mode and the write_file(src/) deny rule in place; stop agent writes while a person changes source temporarily |
The cap case fails, rather than an import or environment error | Expected red record |
| 5. Restore and finish | Restore source, then run the same test under default |
The source diff disappears and every test is green again | Final test-only diff |
CLI plan mode investigates with read-only search and inspection tools before returning a structured plan. In default, file edits pause for diff review and commands follow the active permission policy. Do not guess the current or default mode: check the status bar first. See Your first agent task: Use execution modes and permissions as guardrails for the verified mode behavior.
Step one: Read-only plan and baseline
Section titled “Step one: Read-only plan and baseline”Send this in plan mode:
Goal: add current-behavior tests for lateFeeCents in src/late-fee.js.
This turn is read-only. Do not modify files or run commands. Please:1. List the files you actually read.2. Derive inputs, outputs, and boundaries from the source.3. Propose the smallest test set and explain which incorrect implementation each case would distinguish.4. Name test/late-fee.test.js as the only path that may be added.5. State that you will not change src/, existing tests, dependencies, configuration, or lockfiles.6. List the existing test command to run later, but do not claim that it ran.Reject two kinds of plans: one that turns “should non-integers be charged?” into an unconfirmed requirement, and one that says “fix src/late-fee.js if tests fail.” An acceptable plan describes current behavior, the target test file, the baseline command, and the pause points.
Before approving the plan, run these commands yourself in an independent terminal:
git status --shortnode --testIf git status --short is nonempty, isolate or record the existing work and do not continue until you can distinguish pre-existing changes from this task’s changes. Preserve the initial status and test baseline. The following is synthetic expected output, not a result run by this guidebook:
command: node --testresult: tests 1, pass 1, fail 0exit status: 0If the baseline is not green, stop this task. Record and resolve the old failure separately; do not let the agent hide it inside a test-writing task by changing implementation or existing tests.
Step two: Add only the test file
Section titled “Step two: Add only the test file”Switch to default, then send the complete execution prompt:
I ran the baseline: git status --short produced no output; node --test reported tests 1, pass 1, fail 0; exit status 0.
Now add only test/late-fee.test.js. Do not modify any other file, especiallysrc/late-fee.js, test/smoke.test.js, package.json, lockfiles, or configuration.
Requirements:- Use node:test and node:assert/strict.- Cover non-positive or non-integer input, below the cap, exactly at the cap, and above the cap.- Name tests after observable current behavior.- Add no dependency, skip no test, and do not change test discovery.- Show the diff before saving; after saving, request permission to run node --test.- If any test fails, stop and report the actual value. Do not change implementation to satisfy the assertion.- Finally report git status --short, git diff for tracked files, and git diff --no-index -- /dev/null test/late-fee.test.js for the new file. The last command exits with 1 when it finds a difference. Do not commit or push.Expected new file:
import test from 'node:test';import assert from 'node:assert/strict';import { lateFeeCents } from '../src/late-fee.js';
test('returns zero for non-positive or non-integer days', () => { assert.equal(lateFeeCents(0), 0); assert.equal(lateFeeCents(-2), 0); assert.equal(lateFeeCents(1.5), 0);});
test('charges 25 cents per late day below the cap', () => { assert.equal(lateFeeCents(1), 25); assert.equal(lateFeeCents(19), 475);});
test('reaches the 500-cent cap on day 20', () => { assert.equal(lateFeeCents(20), 500);});
test('does not exceed the cap after day 20', () => { assert.equal(lateFeeCents(21), 500); assert.equal(lateFeeCents(100), 500);});In the edit confirmation, inspect the path before the assertions. Reject any path other than test/late-fee.test.js. Reject source, existing-test, or configuration changes as well. Do not use bulk acceptance merely because the diff is short.
Step three: Run and review independently
Section titled “Step three: Run and review independently”After accepting the new file, and only then, approve node --test. The following remains synthetic expected output:
command: node --testresult: tests 5, pass 5, fail 0exit status: 0Inspect the actual changes instead of relying on the agent’s “all tests passed” summary. In the CLI, /diff exposes All Changes and Per Turn views. In the App, inspect Agent Edits in the Review pane. In an IDE extension, accept or reject individual changes. See Review agent changes before you accept them for the verified workflow across the three interfaces.
Run and preserve at least these checks independently. The third command below is for POSIX; in Windows CMD, use git diff --no-index -- NUL test/late-fee.test.js:
git status --shortgit diffgit diff --no-index -- /dev/null test/late-fee.test.jsnode --testBecause the initial status was empty, the expected final status contains only the untracked test/late-fee.test.js. Plain git diff confirms that tracked files are unchanged; git diff --no-index lets you inspect the new file. An exit status of 1 from the latter means that it found the expected difference; it is not a test failure. If src/late-fee.js changed, treat the turn as failed even if the suite is green. Preserve the status and diffs, reject or restore the out-of-scope edit, and rerun the baseline.
Step four: Perform one temporary mutation by hand
Section titled “Step four: Perform one temporary mutation by hand”Stop agent writes and do not relax write_file(src/). A person temporarily introduces this one-line defect:
return Math.min(daysLate * 25, 500);return daysLate * 25;Run the same node --test command. This is an expected failure. Its synthetic expected summary is:
command: node --testresult: tests 5, pass 4, fail 1failing test: does not exceed the cap after day 20first mismatch: actual 525, expected 500exit status: 1This red result shows that the new test detects removal of the cap. A syntax, import, or missing-file failure does not prove the target behavior. If the suite stays green, check that test discovery includes the new file, that the input exceeds 20 days, and that the assertion calls the same export. See Add tests for an existing function for the general mutation-check and restoration method.
Immediately restore Math.min(daysLate * 25, 500), then run node --test again. The synthetic expected summary returns to tests 5, pass 5, fail 0 with exit status 0. Finally, run git diff -- src/late-fee.js; it should be empty. The final diff may contain only the new test file.
Counterexamples and rewrites
Section titled “Counterexamples and rewrites”Counterexample one: Use auto and finish in one pass
Section titled “Counterexample one: Use auto and finish in one pass”Use auto. Analyze the function, add tests, and fix everything until the suite is green without interrupting me.auto automatically accepts workspace edits, removing the gate where you verify the test-file and source boundary. It does not mean “edit tests only.” See Before enabling auto or Turbo: risks, acceptable cases, and reversal for those risks and recovery paths. Rewrite: inspect a read-only plan under plan, review the single test file under default, and have a person perform the mutation.
Counterexample two: Delegate the meaning of a failure
Section titled “Counterexample two: Delegate the meaning of a failure”If a new test fails, decide whether the test or the implementation is wrong and handle it directly.This permits the agent to weaken assertions or change implementation. Rewrite: on failure, stop and report the input, actual value, expected value, command, and exit status verbatim. A person decides whether the cause is an unsupported assertion, an existing defect, or an environment problem, and implementation work becomes a separate task.
Counterexample three: Read only the completion summary
Section titled “Counterexample three: Read only the completion summary”The agent says it added four tests and all of them pass, so the change is ready to commit.A summary proves neither file scope nor the ability of the assertions to fail. Rewrite: compare the file list and diff, rerun the tests yourself, perform a temporary mutation that turns the target test red, restore it, and confirm that the source diff is empty. Follow Review agent changes before you accept them for the review method.
Verification checklist
Section titled “Verification checklist”- A person preserved the initial
git status --short, baseline command, output summary, and exit status; pre-existing work is distinguishable from this task, and the baseline was green. - The
planphase was read-only and did not propose fixing implementation, changing configuration, or installing dependencies. - The scope says verbatim that only
test/late-fee.test.jsmay be added. - Permissions or interface review kept
src/, existing tests, configuration, lockfiles, commits, and pushes out of scope. - Every assertion traces to source or a confirmed contract rather than an idealized behavior.
- The same command was green after adding tests, and its actual output and exit status were recorded.
- The temporary mutation made the target test red because of the expected value difference, not an environment error.
- The mutation was restored, and the same command returned to green.
-
git status,git difffor tracked files,git diff --no-indexfor the new file, and the interface’s review surface together show that only the test file was added. - No real secret, customer data, production log, or private conversation entered the materials.
- No synthetic output from this page was presented as evidence from the real repository.
Recovery and safety boundaries
Section titled “Recovery and safety boundaries”- The agent changed source: Stop later commands and preserve
git statusand the diff. Restore only the out-of-scope file without overwriting pre-existing uncommitted work. On the next attempt, add awrite_file(src/)deny rule and keep the exact “add only the test file” sentence. - The baseline already fails: Record the failure and leave this playbook. Investigate the environment or existing defect first; do not let the agent modify implementation under the label of writing tests.
- The new test is red on its first run: Check the import path, test discovery, input, actual value, and behavior inventory. Do not change implementation or weaken an assertion without evidence.
- The mutation leaves the suite green: Confirm that you ran the same repository and command, the runner discovered the test file, and the mutation changes output for the target input. Add a case that distinguishes the original and mutated behavior if needed.
- You forgot to restore the mutation: Inspect
git diff -- src/late-fee.js, restore only that line, and rerun the full suite. Do not use a cleanup command that could overwrite unrelated uncommitted work. - You accepted the wrong file: Use
/diffin the CLI, Agent Edits in the App, or the pending-file list in the IDE extension to locate the turn’s changes. Use Git for file-level recovery; do not treat conversation rewind as disk rollback. See Your first agent task: Use execution modes and permissions as guardrails for that boundary. - The interface differs from this page: Do not guess button names or defaults. Follow the official page and the interface you see, then use Git diff and actual test results as independent evidence.
Next: Return to Add tests for an existing function for test design and mutation technique. If the tests expose a real defect, open a separate task and read Locate and fix a bug. Before accepting any agent change, follow Review agent changes before you accept them.