# 3. Make a reviewed rule a gate

Source: https://usecns.dev/tutorial-soma-gate/

[Learning path](https://usecns.dev/get-started/) · [1. Axon](https://usecns.dev/tutorial-axon/) → [2. Soma](https://usecns.dev/tutorial-soma/) → **3. Activate a rule**

**Goal:** distinguish a review signal from a correctness test and see when a concern starts gating. Continue with the clean example repository and the shadow concern from lesson 2.

## 1. Supply one known-good history example

Before activating a concern, give Soma a **tolerance set**: commits where this rule should remain silent. For this small demonstration, make an unrelated README-only commit and verify that the application still passes:

```
printf '%s\n' '# Invoice retry example' > README.md
node --test
git add README.md
git commit -m 'Explain the example without changing invoice behavior'
KNOWN_GOOD=$(git rev-parse HEAD)

cat > docs/soma/concerns/tolerance.yaml <<EOF
schemaVersion: 1
entries:
  - commit: '$KNOWN_GOOD'
    expect_silent: [invoice-idempotency]
    note: 'README-only edit; invoice source and its passing test are unchanged'
EOF

soma concerns tolerance --only invoice-idempotency
```

**Expected:** a passing tolerance check with an applicable entry naming `invoice-idempotency`. The full commit hash is written into the dataset; do not substitute a movable branch name. A missing or unnamed dataset is **not evaluated**, not a pass.

One trivial good example teaches the mechanics; it is not enough evidence for a production rule. In a real project, select representative known-good changes and separately test historical regressions the rule should catch. Soma replays the concern, not your application test: that is why `node --test` is an explicit step.

## 2. Promote, verify and commit the activation

```
soma concerns promote invoice-idempotency
soma concerns index
soma docs reconfirm --all
soma verify
git add docs/soma
git commit -m 'Activate the reviewed invoice concern'
```

**Expected:** promotion reports `state: active`. The activation is now part of the local `main` history used as the next comparison's base. Your real project must review and land this activation on its review base; the promoting change cannot activate a new gate against itself.

## 3. See a review signal on harmless code

```
printf '\n// Retry behavior remains unchanged.\n' >> src/invoices.js
node --test
axon index --full --json
soma concerns check --base main --check --axon axon
```

**Expected:** the test passes, but Soma exits **1** because an active warning concern applies to the changed file. In scripts with `set -e`, run this expected failure separately or explicitly capture its status; do not hide real failures with `|| true`.

This is not a false claim that the comment broke the application. It is the contract of a broad path trigger: **an edit here requires a review**. Answer the concern's question and follow your team's approval process. Start with narrow, useful rules rather than a global rule that blocks every edit.

Restore this lesson's harmless edit before the next comparison:

```
git restore -- src/invoices.js
```

## 4. Contrast it with an actual regression

Change only the retry function so it submits a different idempotency key:

```
python3 - <<'PY'
from pathlib import Path
path = Path('src/invoices.js')
text = path.read_text().replace(
    'return processInvoice(invoice, submit);',
    "return submit({ invoiceId: invoice.id, idempotencyKey: invoice.id + '-retry' });"
)
path.write_text(text)
PY
node --test
```

**Expected:** the application test fails because it sees `invoice-42-retry` instead of the original `invoice-42` on retry. This test checks behavior directly; it is independent of Soma.

Now run the structural review separately:

```
axon index --full --json
soma concerns check --base main --check --axon axon
```

**Expected:** Soma again exits 1 for the applicable active concern. Its structural match is the same kind of signal as the harmless edit. A human or an additional authorized evaluator still has to answer the question; the project test is what demonstrates this specific regression.

## 5. Repair and check again

This is a disposable exercise, so restore the known-good source and rerun both kinds of check:

```
git restore -- src/invoices.js
node --test
axon index --full --json
soma verify
soma concerns check --base main --check --axon axon
```

**Expected:** the application test passes and no invoice edit remains to trigger the concern. Do not restore other people's edits in a real repository. A valid change to a guarded file needs review; it should not be discarded merely to make a report green.

## Use the workflow in your project

Choose one rule with a concrete consequence, a focused trigger and a question a reviewer can answer. Introduce it in shadow mode, collect realistic tolerance/recall examples, and promote only after the signal is useful. Preserve the project's existing test commands.

You now have the local **Axon → Soma → application tests** loop. Consult [the daily lifecycle](https://usecns.dev/lifecycle/) for the larger picture, or look up `soma concerns promote` in [Soma's command index](https://usecns.dev/commands-soma/) when you need the exact contract.