expecttest

Testing rules for expecttest, a method that stores the expected output of a test directly in the source code and updates it when approved.

In plain words
What is it for?
Use them when checking multiline output or output that may change, and when deciding how to handle failed expected-output tests.
Why use it?
They make changes to large or frequently changing text output easier to review while keeping the expected result under test control.

Cursor rule for Cursor

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 rules/ezyang/codemcp/expecttest
Clone the repo
git clone --depth 1 https://github.com/ezyang/codemcp

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 552 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.00000 $0.00552
Opus 5 $0.00000 $0.00276
Sonnet 5 $0.00000 $0.00110
Haiku 4.5 $0.00000 $0.00055

Measured yesterday against content hash 189e57d28eab, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

expecttest 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 yesterday.

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.

.cursor/rules/expecttest.mdc · 67 lines

What it actually says

expecttest

We use expecttest for testing. If you need to match against a multiline string or some output that is likely to change in the future (e.g., the kind of thing you would have ordinarily done an assertIn with), use an expect test. If a test is assertExpectedInline and it fails, use 'accept' command to update the output, do NOT relax the test. If the output of the test seems nondeterministic (e.g., you run accept but the test is still failing on the assertExpectedInline) you should halt and ask for help from the user.

Below is its README.


This library implements expect tests (also known as "golden" tests). Expect tests are a method of writing tests where instead of hard-coding the expected output of a test, you run the test to get the output, and the test framework automatically populates the expected output. If the output of the test changes, you can rerun the test 'accept' command to accept the output.

Somewhat unusually, this library implements inline expect tests: that is to say, the expected output isn't saved to an external file, it is saved directly in the Python file (and we modify your Python file when updating the expect test.)

The general recipe for how to use this is as follows:

  1. Write your test and use assertExpectedInline() instead of a normal assertEqual. Leave the expected argument blank with an empty string:

    self.assertExpectedInline(some_func(), """""")
    
  2. Run your test. It should fail, and you get an error message about accepting the output with EXPECTTEST_ACCEPT=1 (this means to use 'accept' command)

  3. Rerun the test with 'accept' command. Now the previously blank string literal will contain the expected value of the test.

    self.assertExpectedInline(some_func(), """my_value""")
    

A minimal working example:

# test.py
import unittest
from expecttest import TestCase

class TestStringMethods(TestCase):
    def test_split(self):
        s = 'hello world'
        self.assertExpectedInline(str(s.split()), """""")

if __name__ == '__main__':
    unittest.main()

Run accept command, and the content in triple-quoted string will be automatically updated, so you don't have to fill it out yourself.

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. yesterday First seen · 67 lines · 0 tokens per session scan A 189e57d28eab

Subscribe to this mod's changes

expecttest is a cursor rule published in the GitHub repository ezyang/codemcp (1,607 stars, last pushed 8mo ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 552 tokens. 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-30.