Skip to main content
skill CX Codex

principle-test-behavior-not-implementation — Claude Code skill

A rule for tests you write or keep: assert what callers can observe. Turns tests that break on every refactor into ones that catch real bugs.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add backnotprop/pstack --skill principle-test-behavior-not-implementation -a claude-code
Open on GitHub

What principle-test-behavior-not-implementation does

The skill applies whenever you write, change or keep a test. It treats a test as a claim about what the code does for its users: another module calling it, a person using the app, a service on the other end. Observable means return values, errors, state you can read back, and effects that leave the code, like a request sent or a row written. Private helpers and the order of internal calls are not observable, so they are not behavior.

Two imagined edits do the judging. Break the behavior: return the wrong value, skip an effect, run it twice. A test that still passes proves nothing. Then change the internals while every observable result stays the same; a test that now fails is pinned to the implementation, needs a rewrite after each refactor and still catches no bug. Keep the test that fails on the first edit and passes on the second.

Everything ships in one SKILL.md, no scripts. The frontmatter sets disable-model-invocation: true, so the agent will not pick the rule up on its own: name the skill in your prompt. The file also works through edge cases. An empty list is the right answer when nothing matches and a hollow check when the test only needs some result. A mocked external service sees its payload, so the payload counts as behavior; a call to an internal helper does not. Worth rereading your mocks against that.

What it helps with

  • rewrite a test that breaks after every refactor
  • catch a test that stays green when the return value is wrong
  • strip assertions on private helpers
  • derive the expected value from the requirement instead of a test run
  • decide whether a mocked payload counts as behavior

Example prompts for the agent

  • Rewrite the createOrder test with principle-test-behavior-not-implementation: break the return value and the test has to fail.
  • Run checkout.spec.ts through both edits from principle-test-behavior-not-implementation and tell me which assertions are pinned to internals.
  • Drop the private-method assertions in user.test.ts and keep what the caller can see, as principle-test-behavior-not-implementation says.

How to install principle-test-behavior-not-implementation

1Skills CLI (Vercel)

npx skills add backnotprop/pstack --skill principle-test-behavior-not-implementation -a claude-code

2Manually: put the files in place

~/.claude/skills/principle-test-behavior-not-implementation/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/principle-test-behavior-not-implementation/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about principle-test-behavior-not-implementation

How to install principle-test-behavior-not-implementation in Claude Code?

Run npx skills add backnotprop/pstack --skill principle-test-behavior-not-implementation -a claude-code. The skill lands at ~/.claude/skills/principle-test-behavior-not-implementation/SKILL.md.

What does principle-test-behavior-not-implementation do?

It makes a test assert only what users can observe: a result, an error, a side effect. Tests that fail on internal reshuffling get rewritten or deleted.

Why doesn't the skill trigger by itself?

The frontmatter carries disable-model-invocation: true. The agent will not invoke the rule unasked, so you reference the skill by name in your prompt.

Source text

SKILL.md · MIT
---
name: principle-test-behavior-not-implementation
description: "Apply when you write, change, or keep a test. Assert what the code's users can observe, so that the test fails when that behavior breaks and keeps passing when only the internals change."
disable-model-invocation: true
---

# Test Behavior, Not Implementation

A test is a claim about what the code does for its users: a caller, an end user, or another service. Behavior is what those users can observe through the interface they use. That includes return values, errors, state they can read back, and effects on systems outside the code, such as a request sent, a row written, or a message emitted. Implementation is what they cannot observe: private helpers, internal call order, intermediate data, and which internal collaborator did the work.

Judge each test against two imagined edits:

- **Break the behavior.** Make the code return a wrong value, skip an effect, or do the effect twice. If the test still passes, it proves nothing. The usual causes are an assertion looser than the contract, an expected value computed by the code under test, a restated constant or prompt string that never runs the code that reads it, and an assertion on data that the test built itself.
- **Change the internals.** Keep every observable result the same and restructure the code underneath. If the test now fails, it is pinned to the implementation. It will need a rewrite on every refactor and still catches no bug.

Keep a test that catches the first edit and survives the second. Rewrite or delete the rest. To write a test that does both, drive the code through its users' interface with a concrete input. Derive the expected value from the requirement, not from a run of the code. Assert what the contract promises, no less and no more.

The contract decides, not the shape of the assertion. When "an empty cart never charges" is the promise, an assertion that the payment client got no call is behavior. Pair it with a case where the charge happens, so that the test shows it can see a call. The payload that a mocked external service receives is behavior, because that service observes it. A call to an internal helper is implementation, because no user can see it. An empty list is the exact answer when no record matches, and a hollow check when the test only needs some result. An exact error message pins wording that no caller reads. The error type that callers branch on is the contract.

A test can pin an invariant instead of a call, such as a key that must exist in two tables or a compile-time type check. The invariant is the behavior.

© backnotprop · MIT · backnotprop/pstack

Similar skills

All skills for Testing and QA →

From the same set44

automate-me Turns your daily coding habits into a personal -mode skill by mining recent workspace transcripts and running structured questionnaires. CX Codex +1 5,100installs principle-outcome-oriented-execution A rule for planned rewrites and migrations: the agent converges on the target architecture instead of propping up intermediate states with compatibility code. CX Codex +1 5,100installs principle-boundary-discipline A rule-set skill for coding agents: validation and error handling stay at system boundaries, while the inside trusts its types and plain functions. CX Codex +1 5,100installs principle-sequence-verifiable-units Guides coding agents to break multi-step sweeps and migrations into verifiable units. Keeps each step verified before proceeding to the next. CX Codex +1 5,100installs principle-minimize-reader-load A skill that spots unnecessary layers of abstraction and hidden state slowing down code comprehension. Use it when reviewing complex code where the logic is hard to trace. CX Codex +1 5,200installs principle-migrate-callers-then-delete-legacy-apis Instructs the assistant to migrate internal callers and delete legacy APIs in a single wave, skipping temporary compatibility layers. CX Codex +1 5,200installs principle-model-the-domain Guides an agent to model domain rules in data structures instead of growing conditionals. Use it when stateful code or repeated shape assumptions start spreading. CX Codex +1 5,200installs principle-redesign-from-first-principles A skill that makes the agent rebuild an existing design as if the new requirement had been there from day one. Use it when a change ripples through types, docs, and examples. CX Codex +1 5,200installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor