1. The problem
In one sentence
The server follows the shape of the spec but breaks a rule of the business, and no single response shows it.
A story
A shop has 5 items of an article in stock. A customer orders 8, and the server accepts the order: 201 Created, a valid body. The stock is now -3. A shipped order can be cancelled. Two customers can register with the same email. A withdrawal can take more money than the account holds. A second page of a list starts with the last item of the first page. An expired token is still accepted. In every case the answer is well-formed and matches the spec.
Why it hurts
The rules of the business are the reason the API exists. They are rarely written in the spec, because a schema cannot hold them. They live in people’s heads and in tests, and when neither is there, the server can break them without any alarm.
- For developers: each rule needs a test that creates the situation and checks the outcome. The spec cannot do that for you.
- For managers: broken rules are the expensive kind of bug: negative stock, overdrawn accounts, duplicate customers, orders that cannot be undone. They damage data and trust, and they are found by users.
- For DevOps: run a scenario for the critical rules in the pipeline after each deploy, on a test server that can be reset.
Example
Six rules, each broken in the sandbox server:
an order above the stock -> must be refused with 422 (the server accepts it, 201)
the stock -> must stay at zero or more (it is -3)
cancel a shipped order -> must be refused with 409 (the server answers 200)
a duplicate customer email -> must be refused with 409 (the server answers 201)
withdraw more than the balance -> must be refused with 422 (the server answers 200)
page 2 of a list -> must not repeat the last item of page 1
an expired token -> must be refused with 401 (the server answers 200)
How to detect it without clrsig
- Write the rule down as a sentence, then try to break it by hand with
curl: order too many, cancel a shipped order, register twice. - Ask the product owner for the five rules that must never be broken, and test those first.
How to fix it
There are two usual causes:
- The code is wrong (almost always). The rule is missing, or enforced in the client only. Enforce it on the server, in the same place as the write.
- The spec is silent. The rule is not written down. Document it in the description of the operation and declare the status that signals a refusal (
409,422).
To tell which: ask who owns the rule. A rule that matters must be enforced by the server and checked by a test.
Related problems
AC-043 A stale update overwrites a newer one, AC-038 Valid shape, wrong meaning, AC-027 The next call needs a value the previous response did not give.
Words used on this page are explained once in the glossary.
2. How clrsig helps
Check
No built-in check, and the state is not caught: every response matches the spec. A scenario with assertions that state the correct rule finds each case, and a step fails exactly where the server is wrong.
Command
The scenario resets the sandbox, sends requests that write data (POST), and asserts the correct outcome of each rule:
Safety. Run this against a test server, never production.
clrsig conformsendsPOST,PUTandDELETErequests built from the spec: start with--read-only, and take secrets from the environment (${NAME}), never from files in the repository.
clrsig run clrsig/scenarios/conform-fail-business-rules.yaml \
--env clrsig/environments/conform-fail.yaml \
--spec specs/conform-fail.yaml
Exit code: 0 all steps pass, 1 a step failed, 2 the scenario or the setup is broken. Here it is 1.
What you see
Output from clrsig v0.21.0, recorded on 2026-11-30:
Scenario: conform-fail - business rules the server breaks
The rules of the ok API (stock, order states, unique values, insufficient funds, pagination, expiry), broken here in ways the spec does not describe. Each step asserts the CORRECT rule, so a step fails exactly where the server is wrong; the contract checks alone cannot see any of it (the responses match the spec). The expected outcome of every step is in expectations/conform-fail.yaml. The stale If-Match rule is the PUT /lost-update case of conform-fail-write-bugs.yaml. Run with --spec specs/conform-fail.yaml. The first step resets the family.
PASS reset 204 14ms
✓ status eq 204
FAIL an order above the stock is refused 201 1ms
✗ status eq 422: expected "422"; got "201"
FAIL the stock stays at zero or more 200 1ms
✗ jsonpath $.stock gt -1: expected value > "-1"; got "-3"
PASS create an order within the stock 201 1ms
✓ status eq 201
→ shippedOrderId = "o-3"
PASS ship it 200 1ms
✓ status eq 200
✓ jsonpath $.status eq shipped
FAIL a shipped order cannot be cancelled 200 1ms
✗ status eq 409: expected "409"; got "200"
PASS first customer 201 1ms
✓ status eq 201
FAIL a duplicate email is refused 201 2ms
✗ status eq 409: expected "409"; got "201"
FAIL withdrawing more than the balance is a 422 200 0ms
✗ status eq 422: expected "422"; got "200"
✗ schema: Error at "/id": property "id" is missing
→ [CS-RESP-005] "id" is missing from the response. Why: The spec marks "id" as required, but the server's response did not include it. Where: response body, field id. Fix: Return "id" from the server, or make it optional in the spec if it is not always present.
PASS page 1 200 2ms
✓ status eq 200
→ lastOnPage1 = "i-3"
FAIL page 2 does not repeat the last item of page 1 200 2ms
✗ jsonpath $.items[0].id ne i-3: expected value != "i-3"; got "i-3"
PASS a valid token is accepted 200 2ms
✓ status eq 200
FAIL an expired token is refused 200 1ms
✗ status eq 401: expected "401"; got "200"
Spec: 1 of 13 responses were not compared with the spec (no matching operation in the spec: 1)
FAILED 6 passed, 7 failed, 0 skipped (7/15 assertions passed) 49ms
How to read it: each FAIL line names the rule and the value the server gave. The steps that pass (create, ship, first customer) are the setup the rules depend on. The Spec: line says that the reset call is not in the spec, which is expected here.
Where to look
- Desktop app: open the scenario and run it; each step shows its assertions, and the result page lists the failed ones.
- Reports:
--format jsonandjunitonclrsig run. - GitHub Action: use
command: runwith thescenario,envandspecinputs;specreplaces the scenario’sspecFile. Older releases of the Action ignoredspecwithrun; if you use one, addspecFile: ../../specs/conform-fail.yamlto the scenario instead (the path is relative to the scenario file) (setup and upgrading).
How clrsig helps you fix it
It tells you which rule failed and what the server did instead. It does not know why. The scenario also documents the rules, in a form that a pipeline can run.
Limits
- You write each rule. A rule nobody wrote is not checked.
- The scenario needs a test server that can be reset, because it creates and changes data.
- A green run means nothing is wrong in what was checked.
More ways
Nothing yet.
3. Video brief for Google NotebookLM
VIDEO BRIEF — AC-040 · A business rule is broken though every response looks fine
Length: 5 to 7 minutes. Language: English. Audience: developers, with a line each for managers and DevOps.
One idea: the rules of the business are the reason an API exists; a schema cannot hold them, so you test them with a scenario.
Open with this story: A shop has a few items of an article in stock. A customer orders more than the stock, and the server accepts the order with 201 Created and a valid body. The stock is now negative. A shipped order can be cancelled. Two customers can register with the same email. A withdrawal can take more money than the account holds. In every case the answer is well-formed and matches the spec.
Say these facts, in this order:
1. The scenario asserts the correct rule at each step, so a step fails exactly where the server is wrong.
2. Rules broken in the sandbox: an order above the stock is accepted and the stock goes to minus 3; a shipped order can be cancelled; a duplicate email is accepted; a withdrawal over the balance is accepted; page 2 repeats the last item of page 1; an expired token is accepted.
3. The steps that pass are the setup the rules depend on: create an order, ship it, register the first customer.
4. Seven steps fail and six pass.
5. Two usual causes: the code is wrong (the rule is missing or enforced only in the client), or the spec is silent about the rule.
6. For managers: negative stock, overdrawn accounts, duplicate customers; found by users.
7. For DevOps: run a scenario for the critical rules after each deploy, on a test server that can be reset.
Show on screen: the list of six rules, the command (clrsig run clrsig/scenarios/conform-fail-business-rules.yaml --env clrsig/environments/conform-fail.yaml --spec specs/conform-fail.yaml), and the FAIL lines of the output block, copied exactly from the card.
Name the check: none built in; found by assertions in a scenario. Say the clrsig version: v0.21.0.
Explain these words once: business rule (a rule of the business, such as stock cannot be negative); scenario (a script of steps with your own checks, called assertions); 409 (a conflict with the current state); 422 (the request is well-formed but cannot be processed); exit code (0 clean, 1 a finding, 2 setup or spec broken).
Say what clrsig does not see here: you write each rule; a rule nobody wrote is not checked; a green run means nothing is wrong in what was checked.
Safety line (if a write is shown): Run this against a test server, never production. clrsig conform sends POST, PUT and DELETE requests built from the spec: start with --read-only, and take secrets from the environment (${NAME}), never from files in the repository.
Finish with three recap questions:
1. Why can the spec not hold these rules? (A schema describes shape, not business behaviour.)
2. Which status should a refused duplicate or a refused cancel answer? (409.)
3. Where should a rule be enforced? (On the server, in the same place as the write.)
Tease the next video: AC-041 · A write returns success but is not saved.
Do not: say "contract testing" alone; say clrsig "catches everything"; invent flags, IDs or numbers; read tables aloud; use any fact that is not in the card.