add-unit-test

add-unit-test is a skill for Claude Code, Codex from tmj-90/gaffer. It costs 54 tokens per session (612 once invoked), scanned A, original, Apache-2.0.

A workflow for adding focused unit tests, which check one function, module, or component in isolation. It follows the testing tools and style already used in the project.

In plain words
What is it for?
Adding tests for a specific piece of code, covering normal and boundary cases, checking errors, and raising test coverage for a named unit.
Why use it?
It helps turn a ticket's expected behaviour and edge cases into tests without introducing a different testing system. Running the tests confirms whether the new checks pass and may reveal bugs.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/tmj-90/gaffer/add-unit-test
Any agent
npx skills add tmj-90/gaffer --skill add-unit-test
Clone the repo
git clone --depth 1 https://github.com/tmj-90/gaffer

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for add-unit-test

README.md
[![agentmods](https://agentmods.dev/badge/skills/tmj-90/gaffer/add-unit-test.svg)](https://agentmods.dev/skills/tmj-90/gaffer/add-unit-test)
Your own site
<a href="https://agentmods.dev/skills/tmj-90/gaffer/add-unit-test"><img src="https://agentmods.dev/badge/skills/tmj-90/gaffer/add-unit-test.svg" alt="Measured on agentmods" height="20"></a>
Per session 54 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 612 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00054 $0.00612
Opus 5 $0.00027 $0.00306
Sonnet 5 $0.00011 $0.00122
Haiku 4.5 $0.00005 $0.00061

Measured 5d ago against content hash b2038c9ba652, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

add-unit-test scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

runner/skills/add-unit-test/SKILL.md · 50 lines

How it starts

The opening of the file, as written. The whole thing — 50 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Add a unit test

Add focused, behaviour-asserting unit tests for the unit named in the ticket — matching the repo's existing test framework and conventions, not introducing a new one.

Steps

  1. Find the unit + its existing tests. Locate the source file and any sibling test file. Read 1–2 existing tests in the repo to copy the framework, naming, and assertion style (Vitest/Jest/pytest/JUnit — use what's already there).
  2. Enumerate behaviours to cover from the ticket/AC: the happy path, each meaningful branch, boundary values, and the error/throws cases. Prefer behaviour ("returns empty array when no match") over implementation detail.
  3. Write tests in the repo's test location and naming convention, one assertion focus per test, Arrange-Act-Assert. No test without a real assertion; no over-broad mocks that assert nothing.
  4. Run the test command (use the repo's test script — see the context packet's verification commands). Iterate until green. If a test reveals a real bug, note it; fix only what the ticket scopes.
  5. Evidence: the test command + its passing summary, and the new test file paths. Then use the record-evidence skill to record test_output against the AC and submit for review.

TypeScript specifics

  • Async functions: await the call and assert on the resolved value, or use await expect(fn()).rejects.toThrow(...) for the failure path — never leave a floating promise, or the test passes before the assertion runs.
  • A meaningful assertion pins the observable outcome: the returned value, a thrown error, or a call made to a genuine collaborator with the expected arguments. Asserting that a mock you fully control was called (expect(mock).toHaveBeenCalled() with no argument or outcome check) tests the mock, not the unit — prefer a real return/throw assertion over an empty mock check.
  • Fake time and randomness (vi.useFakeTimers() / seeded RNG) so timing- or random-dependent behaviour is deterministic rather than flaky.

Read the full file on GitHub · 50 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 50 lines · 54 tokens per session scan A b2038c9ba652

Subscribe to this mod's changes

add-unit-test is a skill published in the GitHub repository tmj-90/gaffer (2 stars, last pushed 4d ago), licensed Apache-2.0. It adds 54 tokens to every session and 612 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.