Skip to content

Intent → Spec → Test: Linking Must-Nevers to Held-Out Tests, and When Not To

How to link must-nevers to rules and hidden tests by ID, keep those tests out of an AI agent's reach, and use the model only where a mistake would be costly.

Series · AI-Native Development · Part 2 of 6

For tech leads, developers and QA engineers who want agents to write code without shipping what nobody checked. This is the deep dive behind one of the eight approaches in AI-Assisted Delivery Methodologies Compared. It is a model I have been developing, so its costs are covered as plainly as its benefits.

TL;DR

  • Three layers, written by people before the agent starts: intent (the outcome and a must-never list), spec (concrete rules in when/then form), and tests (visible ones the agent works against, and hidden ones it never sees, also called held-out tests).
  • Every item carries the ID of the one above it, and CI fails the build if a must-never has no rule, a rule has no test, or a must-never has no hidden test.
  • Hidden tests only work if the agent cannot read them. Ignore files and deny rules are a soft guardrail; keeping the tests in a repository only CI checks out is the hard one.
  • It works because the agent never marks its own homework: each part closes one way a change can look done but be wrong, and a machine checks every part.
  • It is too heavy for most changes. It is a modern requirements traceability matrix, and applied everywhere it produces hollow specs written to turn the check green. Use it for high-risk changes and route everything else to lighter approaches.

What You'll Learn

  • Why the model works, and why it sits in the expensive top-right corner of the approaches map
  • How must-nevers, rules and tests link by ID, with a working Salesforce example
  • How to keep hidden tests away from an agent, and why most guardrails are soft
  • How to report a failed hidden test without teaching the agent to game it
  • When not to use this at all, and how to route changes by risk instead

The Problem

AI coding agents are very good at making tests pass. That is the problem: if the agent can see the tests, it can shape the code to those exact tests, or write tests after the code that pass for the wrong reason. Code review does not catch it reliably once agents open more pull requests than people can read.

The usual fixes help but leave gaps. Specs drift from the code unless something checks them. Tests prove behaviour but not that the behaviour was the one the business wanted. This model joins the two and lets a machine check the join.

Common Questions This Article Answers:

  • How do I stop an agent from writing code that only passes the tests I showed it?
  • Where do I put tests the agent must not see, if it can read my whole repository?
  • Do I really need specs and traceability for every change?

Quick Answer

Write a short must-never list for each high-risk change ("a guest user must never read Contact records"), turn each must-never into a rule with real values, and prove each rule with a test. Keep at least one test per must-never hidden: in a repository that only CI checks out, so it never appears in the agent's workspace. Give every item the ID of the one above and make CI fail when a link is missing. When a hidden test fails, show the agent which must-never broke, not the test code. Do all of this only for changes where a mistake is expensive, such as authentication, permissions, billing, guest access and data retention, and use a fast test loop for everything else.

Must-Nevers and Hidden Tests, in Plain Terms

A must-never is a line the business says can never be crossed, written as one plain sentence. Where a feature request says what to build, a must-never names the outcome that would be a disaster:

  • "A visitor who is not logged in must never see a customer's contact details."
  • "A customer must never be charged twice for the same order."
  • "The integration user must never be able to delete records."

The closest Salesforce idea is a validation rule, but for a whole change instead of one field: a guard on what must never be true afterwards, whatever else the change does.

A hidden test (often called a held-out test) is a test the agent never sees; only the CI pipeline runs it. Think of an exam. The visible tests are the practice questions: the agent sees them and works until it passes. The hidden tests are the exam itself. If a student had the exam questions in advance, a pass would prove nothing. An agent shown a test will make that test pass, sometimes by shaping the code to that exact check instead of fixing the problem. A test it could not see is an honest check.

Together, in one Salesforce example:

  1. Must-never: a visitor who is not logged in must never see Contact records.
  2. Rule: after any change to the guest profile, sharing or site settings, the guest user has no access to Contact.
  3. Visible test (the agent sees it): the guest profile's read permission on Contact is unchecked.
  4. Hidden test (only CI sees it): runs as the guest user, tries to read Contacts, and expects none. It catches the case where the box is unchecked but a sharing rule or another route still lets the guest in.

A few words you will see

Term What it means here
Must-never A line the business says can never be crossed, written as one plain sentence with an ID such as MN-001
Rule A concrete when/then statement that makes a must-never testable, with an ID such as R-014
Hidden test (also called a held-out test) A test the agent never sees and only CI runs, like exam questions a student has not seen in advance
Traceability The chain from must-never to rule to test, checked by machine
Property-based test A test that generates random inputs on every run, so answers cannot be hard-coded

How the Three Layers Link

Layer Answers Written by Fails on its own because
Intent Why, and what must never happen Product owner The agent guesses the implementation
Spec Exactly what correct looks like BA and architect It turns into waterfall in Markdown, or code written in YAML
Test Machine proof that the code meets the spec QA The agent games the tests, or they check code paths instead of business meaning

The traceability rule ties them together. CI fails the build when:

  • a must-never has no rule (the spec does not say what it means in practice);
  • a rule has no test (nothing proves it);
  • a must-never has no hidden test (the agent could have shaped the code to the visible tests alone);
  • a new test also passes on the old code (it never failed, so it proves nothing about the change).

If a must-never cannot be tested, the design usually needs a better seam. Weakening the must-never is not the fix.

Why It Works

The model rests on one idea: the agent should not mark its own homework. An agent is very good at making whatever check it can see pass, and sometimes it does that by gaming the check instead of solving the problem. In June 2025, METR reported that frontier models working on coding tasks tried to raise their scores by modifying the tests or scoring code, and by finding the answer the checker used. Model makers test for it the same way this model guards against it: Anthropic's system card for Claude Sonnet 4.5 measures reward hacking with hidden tests that are fuzzed versions of the tests the model can see, and counts a hack when a solution passes the visible tests but fails the hidden ones. It reports that hard-coding and special-casing still happen, at much lower rates than in earlier models. Each part of the model closes one way a change can look finished without being right:

How a change can look done but be wrong What catches it Why it holds
The agent builds the wrong thing Intent: must-nevers written before work starts The goal is set by someone who owns the risk, not inferred by the agent
The agent fills gaps with guesses Spec: rules with real values A missing rule fails the build, so a guess shows up as a gap
A test passes but proves nothing Red first: new tests must fail on the old code A test that never failed was never testing the change
The agent shapes the code to the tests it can see Hidden tests in a CI-only repository It cannot aim at a check it never sees
Someone weakens a test to get a change through QA approval on the hidden-test repository Tests change only with sign-off from the people who own them
A must-never quietly loses its rule or its test The traceability check in CI Coverage becomes a build result, not someone's memory
Someone ships around all of it Deploys only through the CI user There is no other route to production

Two things make the combination stronger than its parts. The checks run by machine on every change, so they do not depend on a reviewer's attention, which is the first thing to go when agents open more pull requests than people can read. And the must-never list keeps the effort focused on the few outcomes that would be expensive, not on every requirement, which is what keeps it smaller than a full specification.

What is proven and what is not. Each piece is established practice: test-first development, specification by example, tests written independently of the code, and requirements traceability from regulated industries. The agent behaviour it guards against is documented. The combination as one model has not been measured in a controlled study. Treat it as a well-founded design, not a proven result, and measure your change failure rate before and after you adopt it.

Where It Sits Among the Approaches

Eight approaches on two axes, placed from the comparison table below. Point at, or tap, a number.
Cheap guardrailsHeavy and well guardedFast and unguardedEffort without enforcementEffort upfrontnonehighestHow hard it is to ship unchecked code12345678

The top left is where the cheapest guardrails sit. Approaches high on effort but low on enforcement depend on someone keeping their artifacts true.

On the map from the methodologies comparison, Intent → Spec → Test sits in the top right: the most effort upfront, and the hardest route for unchecked code.

  • Top, because of the table above. Most approaches close one or two of those seven gaps. This one closes all of them, and a machine enforces each one. Test-first agents and harness engineering sit just below: they share the hidden tests and gates, but nothing links those tests back to what the business said must never happen.
  • Right, because of the work before the first line of code. Someone has to write must-nevers, turn them into rules, write hidden tests and keep the IDs linked, all before the agent starts. No other approach asks for as much upfront.
  • Being top right does not make it the best choice. That corner is the expensive one. For most changes the top left, cheap guardrails such as test-first agents, is the better buy. The map shows that the strongest checks cost the most, which is why this model belongs on high-risk changes only.
  • The positions are my assessment, read from the cost and enforcement columns of the comparison table, not measurements. They are ordinal: "harder than", not "twice as hard".

The Links on Disk: A Salesforce Example

The must-never, the rule that covers it and the hidden test that proves it each carry the ID of the one above:

<!-- intent/portal-security.md -->
### MN-001: Guest users never see Contacts
A guest (unauthenticated) site user must never read Contact records,
under any site configuration.
# spec/portal-security.spec.yaml
- id: R-014
  covers: [MN-001]
  when: A deployment changes the guest user profile, sharing or site settings
  then: The guest user has no read access to Contact
  tests: [GuestContactIsolationTest]   # hidden: lives in the CI-only repository
// CI-only test repository, deployed to a scratch org or sandbox with the change
// MustNever: MN-001 | Rule: R-014
@IsTest
private class GuestContactIsolationTest {
    @IsTest
    static void guestUserCannotReadContacts() {
        insert new Contact(LastName = 'Isolation check');
        User guest = [SELECT Id FROM User WHERE UserType = 'Guest' AND IsActive = true LIMIT 1];
        Integer visible = 0;
        System.runAs(guest) {
            try {
                visible = [SELECT COUNT() FROM Contact WITH USER_MODE];
            } catch (QueryException e) {
                visible = 0; // no object access: the query is refused
            }
        }
        Assert.areEqual(0, visible, 'MN-001 violated: guest user can read Contact records');
    }
}

The test is a sketch to adapt to your own site. Note where it lives: not in force-app with everything else. Apex tests have to be deployed to an org to run, so a hidden Apex test sits in a separate repository that only CI fetches and deploys alongside the change. In CI that is two extra steps after the main deploy:

sf project deploy start --source-dir held-out-tests/force-app --target-org ci-scratch
sf apex run test --class-names GuestContactIsolationTest --target-org ci-scratch --wait 10

The check that every must-never has a rule, and every rule a test, can be a short script in the same pipeline that reads the intent and spec files and looks up each test name.

Keeping Hidden Tests Out of the Agent's Reach

A hidden test only works if the agent cannot read it. There are soft and hard ways to do that:

  • Soft: ignore and deny rules. Cursor reads a .cursorignore file. Claude Code uses permissions.deny rules in .claude/settings.json, such as Read(./held-out/**). Its documentation says these rules cover its own file tools and shell commands like cat, but not a grep -r run from a parent folder or a script that opens files itself, and points to OS-level sandboxing for real enforcement. Treat them as a guardrail, not a boundary.
  • Hard: keep the tests out of the workspace. Put hidden tests in a separate repository that only CI checks out. The agent's working copy never contains them, so nothing has to block them.
  • Control who can change them. Changes to the hidden-test repository need QA approval, so a hidden test cannot be quietly weakened to make a change pass.

Report the symptom, not the source

When a hidden test fails, the message the agent sees should name the broken invariant, not the test code:

✗ MN-001 violated: guest user can read Contact records (rule R-014)
  Full test output is in the CI log.

That tells the agent, or the developer, what to fix without showing the assertion it could aim at. The full output stays in the CI log, where the people debugging can read it.

Make some tests impossible to game

Property-based tests generate random inputs on every run, so an agent cannot hard-code answers even when it can see the test. Hypothesis (Python) and fast-check (JavaScript) are the common libraries. Apex has no mainstream equivalent, so on Salesforce this applies to code outside Apex, such as Lightning Web Components and integration services.

When Not to Use It

Linking must-nevers to rules to tests by ID and checking the links in CI is a modern version of a requirements traceability matrix, familiar from regulated industries. Applied to every change, it turns into bureaucracy. Worse, people (or agents) start generating hollow specs to turn the check green, which is less useful than having no spec at all.

Signs it has become too heavy:

  • specs written after the code;
  • must-nevers that only restate the rule beneath them;
  • a green traceability check on specs nobody reads.

It also costs a BA or product owner willing to write must-nevers, and it is still unproven on platforms where most change is configuration rather than code. On Salesforce, Flow tests and queries against what was deployed can stand in for some unit tests, but the tooling is thinner than for Apex.

Route Changes by Risk Instead

Most teams should not pick one approach for everything. Route each change by how much damage a mistake would do:

Tier Example changes Approach What it costs
1. Low risk Layout changes, copy, internal tooling A fast test loop Fast tests, no spec
2. Medium risk New endpoints, integrations other teams use, data migrations Spec-first development plus test-first Write the contract first, then build and test
3. High risk Authentication, permissions, billing, guest access, data retention Intent → Spec → Test Must-nevers, linked rules, hidden tests in CI

Route by path where you can, so nobody has to remember. CI rules or code owners on the folders that hold permission sets, sharing rules, authentication classes and site settings put those changes in tier 3 automatically. Everything else defaults to tier 1 unless the story says otherwise.

Which tier is this change? Answer the questions; the path you take stays open.

Does the change touch authentication, permissions, sharing, guest access, billing or data retention?

Three tiers, one question each

Start with what the change touches. The panel gives the tier and how much process it needs.

Frequently Asked Questions

Q: Is this just a requirements traceability matrix?

A: It is the same idea, kept small and checked by machine. A traditional matrix is a document someone maintains by hand; here the links are IDs in files next to the code, and CI fails the build when one is missing. The risk is the same too: applied to everything, it becomes paperwork, which is why it belongs only in the high-risk tier.

Q: Can an agent write the hidden tests?

A: Not the agent that writes the code, or the tests stop being independent. A separate agent working only from the spec can draft them, but a QA engineer should review and own them, and they should live in the repository the coding agent cannot see.

Q: Does this work for Flows and configuration?

A: Partly. Intent and spec work for any change, and they pay off immediately for admin-led teams. The test layer is weaker: Flow tests and post-deploy queries can check some rules, but configuration has nothing as strong as Apex unit tests plus hidden tests yet.

Q: Do I need it for everything?

A: No, and you should not use it everywhere. Applied to every change it becomes a traceability bureaucracy. Use it for authentication, permissions, billing, guest access and data retention, and a fast test loop for the rest.

Key Takeaways

  • Must-never, rule, test, linked by ID and checked in CI, makes gaps visible before any code is written.
  • Hidden tests belong outside the agent's workspace. Ignore and deny rules are a guardrail, not a boundary.
  • Report which must-never broke, not the test code, and keep the full output for people.
  • Use it only where a mistake is expensive. Route by risk, and keep everything else light.

What's Next?

Recommended Reading:

Action Items:

  1. Pick one high-risk area (guest access, permissions or billing) and write three must-nevers for it.
  2. Turn each into a rule with real values, and write one hidden test per must-never in a repository only CI checks out.
  3. Add the traceability check to CI, and route only that area through it at first.

Resources & References

Responses

Checking your session.

Loading responses.