no-contract-data-patching-in-tests

A testing rule for contract-based software that forbids hand-writing or modifying the raw data structures used to represent contracts.

In plain words
What is it for?
Use it when testing contracts: use fixtures produced by the real system or create them through a user-facing builder or authoring interface.
Why use it?
Hand-built test data can stop matching real contracts while tests continue to pass, making the tests unreliable.

Cursor rule for Codex

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/prisma/orm/no-contract-data-patching-in-tests
Clone the repo
git clone --depth 1 https://github.com/prisma/orm

Made for: Codex.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 822 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.00822
Opus 5 $0.00000 $0.00411
Sonnet 5 $0.00000 $0.00164
Haiku 4.5 $0.00000 $0.00082

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

Security

Grade A, and why

no-contract-data-patching-in-tests 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 2d 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.

Origin

Copies of this mod

1 near-identical copy found in the catalogue:

.agents/rules/no-contract-data-patching-in-tests.mdc · 71 lines

How it starts

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

No Contract Data Patching in Tests

Rule

Never, under any circumstances, patch or hand-author raw contract data structures in tests. This is a HARD rule — hard as obsidian — not a guideline, suggestion, or default you may trade away under time pressure. Use real emitted fixtures. If a test really has to generate a contract at runtime, it may only generate it from a high-level representation made with a user-facing authoring surface (contract builder DSL, PSL) — never by writing, or worse, patching, the raw contract data structure.

A hand-built object literal that "happens" to match the contract shape is not a contract — it is a bag of random data that incidentally coincides with a real contract today and will diverge tomorrow given the velocity of this repo. Tests built on it are vacuous.

No cast-smuggling

Constructing a contract value at runtime and forcing it through the type system with as unknown as FrameworkContract<...>, as unknown as Contract, blindCast/castAs, or any equivalent escape is strictly forbidden — that cast is the tell that you are hand-authoring raw contract data. Do not refactor unrelated as casts to blindCast/castAs to slip such a value past review. There is no acceptable variant of this workaround.

If you cannot satisfy this rule

Stop. A workaround is never acceptable — it invalidates the rest of the work and is treated as a total failure of the task, not a partial success.

  • Working unattended: stop and fix whatever prevents you from satisfying the rule (e.g. add the missing emitted fixture, or extend the authoring surface) before continuing.
  • Working interactively: stop and flag it to the operator.

Why

Patched contracts drift from anything the emitter can produce: they skip authoring-time validation, encode shapes no user can reach, and silently keep passing when the real contract format changes. Tests then assert behavior for contracts that cannot exist.

Don't

// ❌ WRONG: spreading/overriding raw contract internals
const contract = withPatchedDomainModels(getTestContract(), (models) => ({
  ...models,
  Project: {
    ...project,
    relations: {
      ...project.relations,
      related: { ...related, through: { ...related.through, targetColumns: ['tenant_id'] } },
    },
  },
}));

Read the full file on GitHub · 71 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. 2d ago First seen · 71 lines · 0 tokens per session scan A de74833197ce

Subscribe to this mod's changes

no-contract-data-patching-in-tests is a cursor rule published in the GitHub repository prisma/orm (47,587 stars, last pushed today), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 822 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.