# Find business rules no test checks, with FACET

> Run your existing test command through FACET and see per feature whether a test checked it, so a rule without a test shows up as unmeasured and can fail the build.

Source: https://facet-framework.com/en/guides/find-rules-without-a-test/  
Last updated: 2026-11-26T01:08:50+01:00

The test suite is green, the coverage report says 84 %, and a customer still gets a refund that the shop should have refused. Afterwards it turns out that no test ever checked the refund window. The code was covered because other tests happened to call it, but none of them asked whether day 31 is refused.

FACET keeps a short, checkable description of each feature, called a record, next to your code; each record lists the scenarios the feature promises. By the end of this guide `facet test` runs your existing test command and reports per feature whether a test checked it: passed, failed or unmeasured. The refund rule shows up as unmeasured before anyone writes a test for it, and `--fail-unmeasured` turns that gap into a failing exit code.

The commands below use a small TypeScript shop tested with Vitest. It is not the example shop from the other guides: that one runs its tests with Node's built-in test runner and already has a test for its refund window. FACET is set up in this shop as in [One answer instead of three](https://facet-framework.com/en/guides/write-down-what-a-feature-does/). In your own project, pick a rule that customers notice when it breaks.

## Write down the rule nobody has tested

A feature only counts as tested in FACET when its record names the test. Write the refund rule down first. Create the folder:

```sh
mkdir -p docs/facets/features/orders/refunds
```

In this shop, the refund rule is `src/orders/refund.ts`:

```ts
import { ShopError } from "../errors.js";
import type { Cents, Order } from "../checkout/checkout.js";

export const REFUND_WINDOW_DAYS = 30;
const DAY_MS = 24 * 60 * 60 * 1000;

export interface Refund {
  orderId: string;
  amount: Cents;
  method: "original_payment" | "store_credit";
}

export function requestRefund(order: Order, amount: Cents, now = new Date()): Refund {
  if (now.getTime() - order.deliveredAt.getTime() > REFUND_WINDOW_DAYS * DAY_MS) throw new ShopError("E3001");
  const refunded = order.refunds.reduce((sum, r) => sum + r, 0);
  if (refunded + amount > order.total) throw new ShopError("E3002");
  order.refunds.push(amount);
  return { orderId: order.id, amount, method: order.paidWith === "gift_card" ? "store_credit" : "original_payment" };
}
```

Save this as `docs/facets/features/orders/refunds/request-refund.yaml`. The scenarios describe what that code does today:

```yaml
schema_version: "0.1"
id: orders/refunds/request-refund
lifecycle: active
intent:
  summary: A customer asks for money back on an order and gets it, in full or in part, or a reason why not.
contract:
  scenarios:
    - id: refund-within-window
      statement: |
        Given an order delivered 29 days ago
        When the customer requests a refund
        Then the refund is accepted and goes back to the original payment method
    - id: refund-after-window
      statement: |
        Given an order delivered 31 days ago
        When the customer requests a refund
        Then the shop refuses it with E3001
    - id: partial-refunds-up-to-total
      statement: |
        Given an order that was already partly refunded
        When a further refund would exceed the amount paid
        Then the shop refuses it with E3002
    - id: gift-card-as-store-credit
      statement: |
        Given an order paid with a gift card
        When the customer requests a refund
        Then the money comes back as store credit
lineage:
  owner:
    team: orders
  created_at: "2026-11-22"
```

Connect it to the code with two comment lines directly above `export function requestRefund` in `src/orders/refund.ts`:

```ts
// @facet: orders/refunds/request-refund
// @facet-role: primary
export function requestRefund(order: Order, amount: Cents, now = new Date()): Refund {
```

Run the check:

```sh
npx facet lint
```

![Terminal output of npx facet lint: a warning lists the four refund scenarios with no verification proof, a second warning lists three test files no record names; 2 records, 2 anchors, 0 errors, 2 warnings.](https://facet-framework.com/guides/find-rules-without-a-test/lint-untested-light.png)

*All four refund scenarios have no test that claims them.*

The first warning is the gap from the introduction, in writing: four promises, no test. Lint only reads files, though. The next steps run the tests.

## Tell FACET how your tests run

FACET does not guess your test framework. It runs the command you declare and reads the JUnit report that command writes. Save this as `.facetrc.yaml` in the project root:

```yaml
runners:
  vitest:
    command: node_modules/.bin/vitest run
    list: node_modules/.bin/vitest list --filesOnly --json
    list_format: json
    report: junit
    report_file: reports/junit.xml
```

- **`command`** runs the tests, exactly as written.
- **`list`** names the test files without running them. It must select the same files as `command`.
- **`report_file`** is where the runner writes its JUnit XML. FACET matches results to test files by the `file` attribute in that report.

The report must carry file names. With Vitest, that is the built-in JUnit reporter with `addFileAttribute`. This shop's `vitest.config.ts` already has it:

```ts
export default defineConfig({
  test: {
    include: ["tests/**/*.test.ts"],
    reporters: ["default", ["junit", { addFileAttribute: true }]],
    outputFile: { junit: "reports/junit.xml" },
  },
});
```

Keep `reports/` in `.gitignore`. The public FACET repository has runnable setups for Jest, Vitest and PHPUnit (see the sources at the end).

## Decide what to do with tests that belong to no record yet

List what FACET discovers, without running anything:

```sh
npx facet test --list
```

```console
$ npx facet test --list
Discovery only: test commands were not executed; no test outcomes measured.
vitest: discovery measured=true, 4 file(s)
  tests/cart.test.ts
  tests/checkout.test.ts
  tests/discount.test.ts
  tests/password-reset.test.ts
error new-unclaimed vitest tests/cart.test.ts: discovered test is unclaimed and absent from baseline; read its body before adding proves
error new-unclaimed vitest tests/checkout.test.ts: discovered test is unclaimed and absent from baseline; read its body before adding proves
error new-unclaimed vitest tests/password-reset.test.ts: discovered test is unclaimed and absent from baseline; read its body before adding proves
facet: test discovery drift check failed
```

The command exits with 1. Every test file must either be named in a record or be listed, on purpose, as not belonging to one yet. Three files test cart, checkout and password reset, features that have no record. Writing records for them is the long-term answer. Until then, list them in `docs/facets/test-baseline.yaml`:

```yaml
runners:
  vitest:
    - tests/cart.test.ts
    - tests/checkout.test.ts
    - tests/password-reset.test.ts
```

The key under `runners` is the runner name from `.facetrc.yaml`. Open each file before you list it. The baseline says "reviewed, belongs to no record yet", and FACET trusts that. Run the discovery again:

```sh
npx facet test --list
```

It lists the same four files and exits with 0. A test file someone adds later and names nowhere fails this check again, so the list cannot grow unnoticed. `npx facet test --update-baseline` removes entries that a record now claims or that the runner no longer finds; it never adds one.

## Run the suite and see the untested rule

```sh
npx facet test
```

![Terminal output of npx facet test: Vitest runs 4 test files with 19 passing tests, then FACET reports checkout/discounts/redeem-code passed and orders/refunds/request-refund unmeasured with no verification file references; 1 passed, 0 failed, 1 unmeasured.](https://facet-framework.com/guides/find-rules-without-a-test/test-unmeasured-light.png)

*19 tests pass, and the refund rule is still unmeasured.*

The first part is Vitest's own output: 19 tests, all green. The last lines are FACET's view per feature. Discount codes passed, because their record names `tests/discount.test.ts` and that file passed. Refunds are **unmeasured**: no test file claims them, so a green suite says nothing about them.

By default this exits with 0. Unmeasured is information, not a failure. To make it one, add the flag:

```sh
npx facet test --fail-unmeasured
```

The same report ends with `Features: 1 passed, 0 failed, 1 unmeasured (2 total)` and `facet: test run failed (exit 1)`. In CI, this is the command that stops a feature from staying untested without anyone noticing.

## Write the missing test and claim it in the record

Save this as `tests/refund.test.ts`. Each case checks one scenario of the record:

```ts
import { describe, expect, it } from "vitest";
import type { Order } from "../src/checkout/checkout.js";
import { requestRefund } from "../src/orders/refund.js";

const DAY_MS = 24 * 60 * 60 * 1000;
const now = new Date("2026-11-22T12:00:00Z");

function orderDelivered(daysAgo: number, paidWith: Order["paidWith"] = "card"): Order {
  return {
    id: "order-1",
    items: [],
    subtotal: 4000,
    discount: 0,
    shipping: 490,
    total: 4490,
    paidWith,
    placedAt: new Date(now.getTime() - (daysAgo + 2) * DAY_MS),
    deliveredAt: new Date(now.getTime() - daysAgo * DAY_MS),
    refunds: [],
  };
}

describe("refunds", () => {
  it("accepts a refund 29 days after delivery, to the original payment", () => {
    expect(requestRefund(orderDelivered(29), 4490, now)).toEqual({
      orderId: "order-1",
      amount: 4490,
      method: "original_payment",
    });
  });

  it("refuses a refund 31 days after delivery", () => {
    expect(() => requestRefund(orderDelivered(31), 4490, now)).toThrow("E3001");
  });

  it("refuses a further refund that would exceed the amount paid", () => {
    const order = orderDelivered(3);
    requestRefund(order, 3000, now);
    expect(() => requestRefund(order, 1500, now)).toThrow("E3002");
  });

  it("refunds a gift-card payment as store credit", () => {
    expect(requestRefund(orderDelivered(3, "gift_card"), 4490, now).method).toBe("store_credit");
  });
});
```

A new test file that no record names is refused like the three before. Claim it in the record: add this block to `request-refund.yaml`, directly above `lineage:`:

```yaml
verification:
  unit_tests:
    - id: tests/refund.test.ts
      proves: [refund-within-window, refund-after-window, partial-refunds-up-to-total, gift-card-as-store-credit]
```

List a scenario under `proves` only after reading the test body. FACET checks that the scenario ids exist, not what the test does.

## Check that the gap is closed

Run the strict check again. `--only facet` hides the runner's own output and keeps FACET's summary:

```sh
npx facet test --fail-unmeasured --only facet
```

![Terminal output of npx facet test --fail-unmeasured --only facet: runner vitest exit 0, checkout/discounts/redeem-code passed, orders/refunds/request-refund passed; 2 passed, 0 failed, 0 unmeasured.](https://facet-framework.com/guides/find-rules-without-a-test/test-gate-green-light.png)

*Both features passed, nothing unmeasured, exit code 0.*

To see that the test really guards the rule, change `REFUND_WINDOW_DAYS = 30` to `14` in `src/orders/refund.ts` and run the same command:

![Terminal output of the same command after the refund window was shortened: runner vitest exit 1, redeem-code passed, orders/refunds/request-refund failed with tests/refund.test.ts failed; 1 passed, 1 failed; facet: test run failed (exit 1).](https://facet-framework.com/guides/find-rules-without-a-test/test-rule-broken-light.png)

*A broken refund rule now fails, and the report names the feature.*

Set the value back to `30`, then commit the record, the runner setup, the baseline, the anchor and the test:

```sh
git add .facetrc.yaml docs/facets src/orders/refund.ts tests/refund.test.ts
git commit -m "Describe refunds and test the refund rule"
```

> **What this does not do**
>
> `facet test` judges whole test files. A passing file counts for every scenario its record lists under `proves`; FACET
> does not check that each test case really covers its scenario, and it never writes or suggests tests. It also does not
> install your test framework or configure its reporter. Skipped tests and a report without file names stay unmeasured.

## If the report says something else

- **`discovered test is unclaimed and absent from baseline`:** a test file is named neither in a record's `verification` nor in `docs/facets/test-baseline.yaml`. Read the file, then add it to the record it proves or to the baseline.
- **`unmeasured … no verification file references`:** the record has no `verification` block, or its `id` is not the path of a test file the runner discovered. Use the path exactly as `npx facet test --list` prints it.
- **A feature stays unmeasured although its test file passed:** the JUnit report has no `file` attribute, or it is written somewhere other than `report_file`. Check the reporter options from step 2 and open `reports/junit.xml`.
- **`facet: test run failed (exit 1)` with `runner vitest: exit 1`:** a test failed. FACET keeps the runner's exit code; the lines above it name the failed feature and file.

For more on why a green suite is not the same as a tested product, read [“All green.” And the customer still calls.](https://facet-framework.com/en/solutions/testing/).

### Sources

- [Run Jest, Vitest and PHPUnit with FACET (runnable examples)](https://github.com/facet-framework/core/tree/main/examples/test-runners)
- [Test discovery and the test baseline in FACET Core](https://github.com/facet-framework/core/blob/main/registry/test_discovery.go)
- [Vitest reporters: JUnit](https://vitest.dev/guide/reporters)
