lightsoutAlpha

test-code-path-coverage

Which tests a unit needs.

Agent checkAdvises by default

The rule

Agents read this text as written when they write and review code.

Cover every code path: branches, error handling and boundary conditions. Give each path one test, and never add a test that only varies the input. Inputs that take one path to different outputs share one test.each.

To reach a branch that guards against input the types forbid, such as a default arm or an early return on an impossible discriminant, force the input with as unknown as T. That and the stub cast test-mock-untyped allows are the only casts a test writes.

Examples

The agent flags code like the incorrect example and accepts code like the correct one. Each example is a small repo, because this rule looks across files. It opens on the file that matters; the other files are the repo around it.

Incorrect

srcbilling
src/billing/getDiscount.ts
interface Params {
total: number;
}
export const getDiscount = ({ total }: Params): number => {
let discount = 0;
if (total >= 100) {
discount = total / 10;
}
return discount;
};

Correct

srcbilling
src/billing/getDiscount.ts
interface Params {
total: number;
}
export const getDiscount = ({ total }: Params): number => {
let discount = 0;
if (total >= 100) {
discount = total / 10;
}
return discount;
};

Configure

  • Block"blocking"Stops a run when a file the run changed breaks the rule.
  • Advise"advisory"Reports it and hands it to the refactor agent. Never stops a run.
    Default
  • Off"off"Not checked. Use it when your own linter already enforces the rule.

Add this to your lightsout.config.json, then change the value.

lightsout.config.json
{
"standards-rule-settings": {
"test-code-path-coverage": "advisory"
}
}

Packs that select it