assertions-pin-contracts
an assertion that restates the module under test instead of stating its contract independently
Agent checkadvisory by defaultbasetests
The argument
Assertions Pin Contracts
- Assert with literals — never import a constant from the module under test into its own assertions. A test comparing
xtoxis a tautology that passes even when the value is wrong; the literal in the test is the independent second statement of the contract. (Duplication between a source constant and its test literal is contract-pinning, not a DRY violation.) Constants from other modules — shared enums the codebase already defines — are fine as inputs. - Pin machine-facing values strictly, human-facing copy loosely. Error codes, event names, and API fields get exact assertions; UI copy and log messages get
stringContaining/regex or no assertion at all — wording changes shouldn't fail contract tests. - Construct the subject under test directly; stub only unowned boundaries (network, filesystem, other modules' services). Don't mock what you own and could simply instantiate.
- Prefer behavior assertions over property echoes — assert what the unit does (output, side effect at its boundary), not that a value passed in reappears unchanged.
The proof
failsrc/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);
});
});
passsrc/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');
});
});
Turn it down
Both lines go in your lightsout.config.json.
"standards-checks": { "assertions-pin-contracts": "advisory" }"standards-checks": { "assertions-pin-contracts": "off" }