# Document known bugs with FACET, so support stops asking “bug or intended?”

> Confirm a known bug with a test, write it down at the scenario it affects with its reason and ticket, and give support one command that lists every known bug without the record ever promising one.

Source: https://facet-framework.com/en/guides/bug-or-intended/  
Last updated: 2026-11-26T23:28:23+01:00

Support asks for the third time this month. A customer entered `WELCOME10` with a kettle in the cart, then added a mug, and the 10 % only came off the kettle. Is that a bug or is it intended? The ticket from last time says "known issue" and nothing else. A developer reads the code again, explains it again in the chat, and the explanation is gone by next month.

FACET keeps a short, checkable description of each feature, called a record, next to your code; a record lists the behaviour the feature promises as scenarios. By the end of this guide the known bug is written down once, at the exact behaviour it affects: what the code does, why that is not what anybody wants, how it was confirmed and which ticket tracks the fix. `npx facet deviations` lists every such entry for support, and the record never presents the bug as a promise.

The commands below use the example shop from [“One answer instead of three”](https://facet-framework.com/en/guides/write-down-what-a-feature-does/), which already has a record for discount codes. In your own project, take the known issue support asks about most.

## Pin down what the code really does

Before writing anything down, confirm the behaviour with a test. It describes what happens today, not what should happen. Save this as `tests/discount-added-items.test.ts`:

```ts
import assert from "node:assert/strict";
import { test } from "node:test";
import { addItem, emptyCart } from "../src/checkout/cart.ts";
import { redeemDiscountCode } from "../src/checkout/discount.ts";

test("a percent code keeps the discount computed when it was entered", () => {
  const withKettle = redeemDiscountCode(
    addItem(emptyCart(), { sku: "KETTLE", unitPriceCents: 5900, quantity: 1 }),
    "WELCOME10",
    new Date("2026-10-01T12:00:00Z"),
  );
  const withMug = addItem(withKettle, { sku: "MUG", unitPriceCents: 1290, quantity: 1 });
  assert.equal(withKettle.discountCents, 590);
  assert.equal(withMug.discountCents, 590);
});
```

Run it:

```sh
node --test tests/discount-added-items.test.ts
```

![Terminal output of node --test tests/discount-added-items.test.ts: 1 test, 1 passed, 0 failed.](https://facet-framework.com/guides/bug-or-intended/repro-light.png)

*The test passes: the discount stays at 5.90 EUR after the mug is added.*

The test passes, so the customer is right: 10 % of 59.00 EUR is 5.90 EUR, and the discount stays at 5.90 EUR after a 12.90 EUR mug joins the cart. In `src/checkout/discount.ts`, `redeemDiscountCode` computes the amount once and stores it on the cart. `addItem` in `src/checkout/cart.ts` copies that amount and never computes it again.

## Write the bug down next to the behaviour it affects

Open `docs/facets/features/checkout/discounts/redeem-code.yaml` and add a scenario at the end of `contract.scenarios`:

```yaml
contract:
  scenarios:
    # the four scenarios already in the record stay here
    - id: percent-discount-ignores-items-added-later
      statement: |
        Given a cart with a 59.00 EUR kettle and the code WELCOME10 (10 %)
        When the customer adds a 12.90 EUR mug afterwards
        Then the discount stays at 5.90 EUR and does not cover the mug
      deviation:
        reason: |
          redeemDiscountCode computes the discount once, from the subtotal at that
          moment, and stores the amount on the cart. addItem copies the cart with
          that amount and never computes it again, so a percent code only covers
          the items that were in the cart when it was entered.
        confirmed_by: test
        tracked_as: SHOP-412
```

Then name the new test under `verification.unit_tests`, below the existing entry:

```yaml
verification:
  unit_tests:
    - id: tests/discount.test.ts
      proves: [expired-code-is-refused, last-day-ends-in-utc, minimum-order-value, one-code-per-order]
    - id: tests/discount-added-items.test.ts
      proves: [percent-discount-ignores-items-added-later]
```

- **The scenario states what the code does.** Its `id` names the observed behaviour (`…-ignores-items-added-later`), never the expected one. Anyone who reads only the id in a list or a diff still gets the truth.
- **`deviation` marks it as unintended.** Without that block the same scenario would read as a promise.
- **`reason`** explains in terms of the code why it is a bug, so the next person can check the claim instead of trusting it.
- **`confirmed_by`** says how it was confirmed: `test`, `code-review` or `runtime`.
- **`tracked_as`** points at the ticket where the fix is decided. Use `null` when nothing tracks it yet.

There is no field for the behaviour the shop should have. That belongs in the ticket, or in a planned record (step 5), so nobody mistakes a wish for a promise.

## Give support the list of known bugs

```sh
npx facet deviations
```

![Terminal output of npx facet deviations: checkout/discounts/redeem-code, scenario percent-discount-ignores-items-added-later, with why, confirmed: test, tracked as: SHOP-412; 1 declared deviation across 1 feature.](https://facet-framework.com/guides/bug-or-intended/deviations-light.png)

*Each known bug with its reason, its evidence and its ticket.*

That is the answer to the support question, with the reason and the ticket. For a support tool or a dashboard, the same list comes as JSON with feature, scenario, file path, reason, `confirmed_by` and `tracked_as`:

```sh
npx facet deviations --json
```

## Check that the record still passes

```sh
npx facet lint
```

![Terminal output of npx facet lint: 1 record and 1 anchor checked, 0 errors and 1 warning about two test files no record names, invoice.test.ts and refund.test.ts.](https://facet-framework.com/guides/bug-or-intended/lint-light.png)

*A written-down bug does not fail the check: 0 errors.*

Writing a bug down never fails the check, so nobody is tempted to leave it out to get a green build. The remaining warning is about other test files no record names yet.

Commit the record and the test together:

```sh
git add docs/facets/features/checkout/discounts/redeem-code.yaml tests/discount-added-items.test.ts
git commit -m "Write down that percent codes ignore items added later (SHOP-412)"
```

## Once the fix is decided, let the check remind you to remove the entry

When the team decides that a percent code should cover the whole cart, write that decision as a planned record. Save this as `docs/facets/features/checkout/discounts/recalculate-on-change.yaml`:

```yaml
schema_version: "0.1"
id: checkout/discounts/recalculate-on-change
lifecycle: planned
intent:
  summary: A percent code always covers the whole cart, also items added after the code was entered.
contract:
  scenarios:
    - id: percent-code-covers-items-added-later
      statement: |
        Given a cart with a 59.00 EUR kettle and the code WELCOME10 (10 %)
        When the customer adds a 12.90 EUR mug afterwards
        Then the discount is 7.19 EUR, 10 % of the new subtotal
lineage:
  owner:
    team: checkout
  created_at: "2026-11-22"
```

In `redeem-code.yaml`, replace `tracked_as: SHOP-412` with the id of that record, `tracked_as: checkout/discounts/recalculate-on-change`, and list the deviations again:

```sh
npx facet deviations
```

![Terminal output of npx facet deviations: the same entry, now with tracked as: checkout/discounts/recalculate-on-change.](https://facet-framework.com/guides/bug-or-intended/deviations-tracked-light.png)

*The known bug now points at the record that will replace it.*

FACET follows a record id in `tracked_as`; a ticket number it leaves alone. When the fix ships and that record becomes `active`, `npx facet lint` warns: `declares a deviation tracked as "checkout/discounts/recalculate-on-change", which is now active`. That is the moment to delete the scenario with the `deviation`, so only the promise of the new record remains. Once the discount covers the mug, the test from step 1 fails as well; delete it in the same change.

> **What this does not do**
>
> FACET does not check whether the bug is real or whether the `reason` is true; that is what the test from step 1 and
> the review are for. It does not judge whether the scenario id names the observed behaviour. A ticket number in
> `tracked_as` is never looked up, so only a record id gives you the reminder from step 5.

## If the check says something else

- **`deviation: missing property 'reason'`:** every deviation needs a reason. Write which function does what, as in step 2.
- **`deviation/confirmed_by: value must be one of 'code-review', 'test', 'runtime'`:** use one of these three words. Who reported it (support, a customer) belongs in the ticket.
- **`contract scenario(s) with no verification proof`** for the planned record: expected until the fix has a test that the record names under `verification`.
- **`value is not allowed in this context`, with a line number:** the YAML around that line is indented wrongly, usually the `deviation:` line. Indent it exactly like `statement:` above it.

For more on what a feature should do versus what it does, read [“It’s done.” Does it do what we wanted?](https://facet-framework.com/en/solutions/product-management/)

### Sources

- [FACET Core on GitHub](https://github.com/facet-framework/core)
- [How to write a record](https://github.com/facet-framework/core/blob/main/docs/AUTHORING.md)
