no-contract-data-patching-in-tests

A testing rule for contract-based data: tests must use real emitted fixtures or create data through the same authoring interface users have.

In plain words
What is it for?
It guides tests for contracts, including runtime-generated test data, and forbids bypassing type checks with forced casts.
Why use it?
It prevents tests from passing against hand-written data that only happens to match today’s format and may stop matching the real contract later.

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

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 100% copy Near-identical to another mod 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

This is a copy

100% identical to no-contract-data-patching-in-tests — 0 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

.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/prisma-next (420 stars, last pushed 7d ago), 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. It is 100% identical to no-contract-data-patching-in-tests, differing in 0 lines, and is treated as a copy.