agentleFS
requierequie/endostack/skills/principle-test-behavior-not-implementation/SKILL.md

principle-test-behavior-not-implementation

Skill4 starsChanged 14 days agoMITView on GitHub

Use when writing or changing a test, or deciding whether one should stay. Check what callers can see through the interface they call, so the test breaks when behavior breaks and survives changes to internals alone.

37 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use poteto-help, ketchup-video and 3 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • ianclearySkill

    poteto-help

    Guides users through pstack setup, /poteto-mode, and picking the skill, playbook, or principle for a task. Type /poteto-help with a question.

    Also in 14 projects that use this

  • tristanphvnSkill

    ketchup-video

    Catch the user up like /keel:ketchup, with a short silent video of slides for what happened and the waiting calls as text under it. Use for /keel:ketchup-video.

    Also in 11 projects that use this

  • bnemaSkill

    setup-pstack

    Configure which Pi models pstack uses per role. Detects available provider/model specs and writes pstack's user configuration. Use for /setup-pstack, "configure pstack models", or changing pstack model choices.

    Also in 19 projects that use this

  • JoshueOsunaSkill

    Poteto Mode

    poteto's agent style for concise, detailed responses, deliberate subagents, unslopped prose, simple code, and verified work. Use for poteto, /poteto-mode, or requests to work in this style.

    Also in 3 projects that use this

  • instructureSkill

    ketchup

    Rebuild context after /clear by analyzing uncommitted changes across Canvas LMS and all plugin repositories

    Also in 18 projects that use this

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • 0

    Common

    Most of the 35 edited versions we read keep these.

  • 3

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Run two thought experiments on each test.

    line 23
  2. Distinctive:

    Keep a test only if it catches the first change and tolerates the second.

    line 26
  3. Distinctive:

    If the promise is that a request without a valid token never reaches the database, asserting the database client received no query is …

    line 29

“Common” is measured: kept by at least 6 in 10 of the 35 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Test behavior, not implementation

A test should check results visible to the code's users via the interface they call. It should fail once that visible behavior breaks and stay green when nothing but the internals move.

When it applies

Writing a test, changing one, or deciding whether to keep one.

Terms

  • Users: callers, end users, and other services.
  • Behavior: whatever users can observe. That covers return values, thrown errors, state they can read back afterwards, and effects on external systems (an outgoing request, a database row, a published message).
  • Implementation: everything they cannot see, meaning private helpers, the order of internal calls, intermediate data, and which internal component performed the work.

What to do

  1. Run two thought experiments on each test.
    • Break the behavior. Return a wrong value, drop an effect, or duplicate one. If the test stays green, it shows nothing. Usual reasons: the assertion is weaker than the contract, the expected value came from the code being tested, the test restates a constant or prompt string without running the code that uses it, or it asserts on data the test built itself.
    • Restructure the internals while keeping every observable result. If the test fails, it is pinned to implementation. It will need rewriting on every refactor and catches no bugs.
  2. Keep a test only if it catches the first change and tolerates the second. Rewrite or remove the others.
  3. To write a good test, exercise the code through the interface its users call, using a concrete input. Work out the expected result by reading the requirement, never by running the code, and assert precisely what the contract guarantees.
  4. Let the contract, not assertion style, decide what counts:
    • If the promise is that a request without a valid token never reaches the database, asserting the database client received no query is behavior. Pair it with a positive case where a valid token does produce a query, so the test demonstrably can observe calls.
    • The payload sent to a mocked external service is behavior, because that service receives it. Calling an internal helper is an implementation detail.
    • An empty list is a precise expected value when nothing should match. It is a hollow assertion when the test only needed some result.
    • Callers do not read the exact wording of an error message. They branch on the error type, so the type is the contract. For an auth failure, assert the Unauthorized type and the 401 status, not the sentence.
  5. A test can pin an invariant rather than a call: for instance, a key required in both of two tables, or a type assertion checked at compile time. Here the invariant is the behavior.

Security tests are where hollow assertions do the most damage. A test named test_rejects_path_traversal that sends ../etc/passwd and asserts "an exception was raised" passes when the code crashes for an unrelated reason. Assert the specific rejection and add a positive case that reads a legitimate file through the same path.

The failure it prevents

Tests that never catch bugs, tests that break on every refactor, and expected values that confirm themselves.

Done when

Each kept test passes both thought experiments.

Related: principle-migrate-callers-then-delete-legacy-apis, principle-foundational-thinking, tdd.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.