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 FACET recordA FACET record is a short, checkable description of one feature, kept as a YAML file next to the code. It states why the feature exists, the behaviour it promises as scenarios, and the tests that check it.In the glossary, next to your code; each record lists the ScenarioA scenario is one behaviour a feature promises, written in a record as Given/When/Then steps. Each scenario has an id that tests and other records can refer to.Read more here 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. In your own project, pick a rule that customers notice when it breaks.
Step 1Write 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:
mkdir -p docs/facets/features/orders/refunds
In this shop, the refund rule is src/orders/refund.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:
schema_version: "0.1"id: orders/refunds/request-refundlifecycle: activeintent: 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 creditlineage: 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:
// @facet: orders/refunds/request-refund// @facet-role: primaryexport function requestRefund(order: Order, amount: Cents, now = new Date()): Refund {
Run the check:
npx facet lint


The first warning is the gap from the introduction, in writing: four promises, no test. LintLint is FACET's check that records and code still point at each other: every record matches its schema, every anchor names an existing record, and every active record has an anchor. It runs locally and in CI on every pull request.In the glossary only reads files, though. The next steps run the tests.
Step 2Tell 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:
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
commandruns the tests, exactly as written.listnames the test files without running them. It must select the same files ascommand.report_fileis where the runner writes its JUnit XML. FACET matches results to test files by thefileattribute 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:
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).
Step 3Decide what to do with tests that belong to no record yet
List what FACET discovers, without running anything:
npx facet test --list
npx facet test --listDiscovery only: test commands were not executed; no test outcomes measured.vitest: discovery measured=true, 4 file(s)tests/cart.test.tstests/checkout.test.tstests/discount.test.tstests/password-reset.test.tserror new-unclaimed vitest tests/cart.test.ts: discovered test is unclaimed and absent from baseline; read its body before adding proveserror new-unclaimed vitest tests/checkout.test.ts: discovered test is unclaimed and absent from baseline; read its body before adding proveserror new-unclaimed vitest tests/password-reset.test.ts: discovered test is unclaimed and absent from baseline; read its body before adding provesfacet: 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:
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:
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.
Step 4Run the suite and see the untested rule
npx facet test


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:
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.
Step 5Write the missing test and claim it in the record
Save this as tests/refund.test.ts. Each case checks one scenario of the record:
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::
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.
Step 6Check that the gap is closed
Run the strict check again. --only facet hides the runner's own output and keeps FACET's summary:
npx facet test --fail-unmeasured --only facet


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:


Set the value back to 30, then commit the record, the runner setup, the baseline, the AnchorAn anchor is a comment in the source code, starting with @facet:, that names the record the code belongs to. FACET reads these comments to know where each feature is implemented.In the glossary and the test:
git add .facetrc.yaml docs/facets src/orders/refund.ts tests/refund.test.tsgit commit -m "Describe refunds and test the refund rule"
Step 7If the report says something else
discovered test is unclaimed and absent from baseline: a test file is named neither in a record'sverificationnor indocs/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 noverificationblock, or itsidis not the path of a test file the runner discovered. Use the path exactly asnpx facet test --listprints it.- A feature stays unmeasured although its test file passed: the JUnit report has no
fileattribute, or it is written somewhere other thanreport_file. Check the reporter options from step 2 and openreports/junit.xml. facet: test run failed (exit 1)withrunner 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..