lightsoutAlpha

module-boundary-testing

Testing a module through what it makes public.

Agent checkAdvises by default

The rule

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

Test a module through its public file, and cover the files only it uses through that file.

  • A public file is a top-level file of a subject folder, or a module folder's main file. Each gets a test beside it.
  • A file in common/ gets a test of its own: several callers rely on it.
  • A file private to one module gets a test of its own only when its cases are too many to drive through the public file, when it is a contract that stands alone, such as a parser, or when coverage a gate demands cannot be reached through the public file.
  • A file with no logic, such as a type, a constant of fixed values or an index file, gets no test.
  • An existing direct test stays. When a new test could go either way, write it against the public file.

A branch no input reaches, through the public file or directly, is dead code: delete it instead of testing it.

A test through the public file pins behaviour, not how the module is split inside, so the insides can be reorganised without touching a test.

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

srcingestioncommonutils
src/ingestion/common/utils/normalizeRecord.ts
export const normalizeRecord = ({ raw }: { raw: string }): string => raw.trim();

Correct

srcingestioncommonutils
src/ingestion/common/utils/normalizeRecord.ts
export const normalizeRecord = ({ raw }: { raw: string }): string => raw.trim();

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": {
"module-boundary-testing": "advisory"
}
}

Packs that select it