# Workshop: does this gate hold?

> Take away one of the four questions that make a gate valid and see where the error slips through; then decide whether six gates hold.

A gate holds if you answer yes to four questions. Take one away and see where the error slips through.

## Build the gate

The change is the discount codes. Before starting, it was decided that the total never drops below €0, not even with two codes. The agent brings an error nobody has seen yet: with two codes at once, the total comes out negative. It says "done."

- The criterion was agreed before building

- It's checked without trusting what it says

- The builder can't control the criterion, the run or its evidence

- It rejects the bad case and accepts the good one

### The gate says no. The error goes back to the agent and you don't even notice.

### The gate opens and the error reaches production.

The check was written after seeing its work. It checks what it did, not what was needed: the negative total wasn't in any case.

The agent printed  3 passed  and nobody ran it. Saying it opened the gate.

The agent changed what surrounds the test: it put  "test": "exit 0"  in package.json. CI ran what was on its branch.

Nobody tried this check with both a negative total and a valid one. In this example it lets both through.

## Five gates. Do they hold?

1. The agent runs the tests in its own session and tells you they pass.
   
   - It holds
   
   - It doesn't hold
   
   **That's it.****No.** It doesn't hold: it's still its word. Have someone else run them, be it CI, an engine or you in a clean copy.
2. CI required on a protected branch. The payment tests were written by another session before starting, and you saw them reject an incorrect payment and accept a correct one. A CI step checks that neither the tests nor what surrounds them changed from what was approved.
   
   - It holds
   
   - It doesn't hold
   
   **That's it.****No.** It holds: it was decided before, someone else runs it, it's out of its reach and you've seen it distinguish the two cases.
3. A linter that has been in the repository for months and has never flagged anything.
   
   - It holds
   
   - It doesn't hold
   
   **That's it.****No.** It doesn't hold yet: a gate that never closes is not a gate. Try one example it should reject and another it should accept.
4. You see the diff and ask the same agent to write tests for what it has done.
   
   - It holds
   
   - It doesn't hold
   
   **That's it.****No.** It doesn't hold: it comes afterwards and whoever goes through writes it. It will check what it did, not what was needed.
5. Before building, you agreed what a separate reviewer would check. It works in a protected copy with clean context. It has rejected the planted fault and accepted the correct case.
   
   - It holds
   
   - It doesn't hold
   
   **That's it.****No.** It holds: it's a reviewer. It works as a check, although its approval never counts as a person's.

[Build yours: a gate by hand](https://gate-driven.dev/en/docs/start-today/index.html.md) [How a gate gets fooled](https://gate-driven.dev/en/docs/how-a-gate-gets-fooled/index.html.md)
