lightsoutAlpha

assertions-pin-contracts

What a test asserts against.

Agent checkAdvises by default

The rule

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

  • Assert against literals. Never import a constant from the module under test into its own assertions: comparing a value to itself passes even when the value is wrong. The literal is the contract's independent second statement, not duplication. Constants from other modules, such as shared enums, are fine as inputs.
  • Pin machine-facing values exactly: error codes, event names, API fields. Pin human-facing text, such as UI copy and log messages, loosely, with stringContaining or a regex, or not at all, so a wording change fails no contract test.
  • Assert what the unit does: its output, or a side effect at its boundary, such as an injected repository called with the right arguments. Never assert that an input comes back unchanged, unless exposing it is the unit's job: for a class whose job is to resolve and expose state, its public fields are its output. Never reach into what a consumer never touches, such as private helpers or caches.

Examples

The agent flags code like the incorrect example and accepts code like the correct one.

Incorrect

src/errors/getErrorCode.unit.test.ts
import { expect, describe, test } from '@jest/globals';
import { getErrorCode } from './getErrorCode';
import { errorCodes } from './errorCodes';
describe('getErrorCode', () => {
test('names the connection failure by its wire code', () => {
const code = getErrorCode({ kind: 'connection' });
// comparing the module's own constant to itself — true even when the value is wrong
expect(code).toBe(errorCodes.connection);
});
});

Correct

src/errors/getErrorCode.unit.test.ts
import { expect, describe, test } from '@jest/globals';
import { getErrorCode } from './getErrorCode';
describe('getErrorCode', () => {
test('names the connection failure by its wire code', () => {
const code = getErrorCode({ kind: 'connection' });
expect(code).toBe('ERR_CONNECTION');
});
});

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": {
"assertions-pin-contracts": "advisory"
}
}

Packs that select it