| name | parity-guard-test-pattern |
| description | When checking that all callers of a contract implement it correctly, you get false positives from wrapper delegators: |
| lastReviewed | 2026-04-30T00:00:00.000Z |
Parity Guard Test Pattern
The Problem
When checking that all callers of a contract implement it correctly, you get false positives from wrapper delegators:
execFileSync('node', [script]);
runMuscle(script);
Testing both the same way creates noise.
The Solution
Split tests into DIRECT callers and DELEGATION callers.
const directCallers = findFiles((content) =>
content.includes("child_process") &&
/exec(File)?Sync|spawn/.test(content)
);
const wrapperCallers = findFiles((content) =>
/runMuscle|muscleAndPrompt|executeScript/.test(content)
);
describe('Contract: exit code handling', () => {
describe('Direct callers (must implement)', () => {
directCallers.forEach(file => {
it(`${file} handles exit code 2`, () => {
const content = fs.readFileSync(file, 'utf8');
expect(content).toMatch(/exitCode|status|code.*===?\s*2/);
});
});
});
describe('Delegators (exempt — wrapper handles)', () => {
wrapperCallers.forEach(file => {
it(`${file} uses contract-compliant wrapper`, () => {
const content = fs.readFileSync(file, 'utf8');
expect(content).not.toMatch(/execFileSync|execSync/);
});
});
});
});
Classification Rules
| Pattern | Category | Contract Obligation |
|---|
require('child_process') + exec* | Direct | Must implement |
import { spawn } + spawn() | Direct | Must implement |
runMuscle() | Delegator | Exempt |
shellExecute() (if contract-compliant) | Delegator | Exempt |
Verification
- Direct callers all implement the contract
- Delegators use compliant wrappers
- No false positives from wrapper usage
- New callers are automatically classified
When to Apply
- Any "all X must do Y" contract
- Error handling requirements
- Logging requirements
- Security patterns (sanitization, auth checks)
Tags
quality testing contracts parity