fitness-functions
Skill777 starsChanged 5 months agoMITView on GitHub
Write architecture fitness functions — deterministic tests that enforce a project's hard rules (module boundaries, offline guarantees, content contracts) from inside its own test target. Use when a constraint lives only in prose (CLAUDE.md, code review) and should become un-arguable.
3 other projects use a version of this.
Adopted by
Most recently taken up by
- fabiandistler/agentstheir own version, first seen Sep 30, 2026
- michaelalber/ai-toolkittheir own version, first seen Jul 30, 2026
- mmondora/claude-skillstheir own version, first seen Feb 14, 2026
Other versions3 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 3
- fabiandistler/agents★ 2same name
- michaelalber/ai-toolkit★ 2same name
- mmondora/claude-skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository183 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- app-intentsSkill
- foundation-modelsSkill
- apple-intelligenceSkill
- visual-intelligenceSkill
- ad-attributionSkill
- app-description-writerSkill
- apple-search-adsSkill
- iap-finalizerSkill
- keyword-optimizerSkill
- marketing-strategySkill
- originality-checkSkill
- ratings-mechanicsSkill
- rejection-handlerSkill
- review-response-writerSkill
- screenshot-plannerSkill
- app-storeSkill
- web-presenceSkill
- core-mlSkill
- animation-patternsSkill
- game-feelSkill
- liquid-glassSkill
- sf-symbolsSkill
- designSkill
- typographySkill
- ui-prototypingSkill
- ux-writingSkill
- attributed-stringSkill
- foundationSkill
- accessibility-generatorSkill
- account-deletionSkill
- analytics-setupSkill
- announcement-bannerSkill
- app-clipSkill
- app-extensionsSkill
- app-icon-generatorSkill
- app-store-assetsSkill
- auth-flowSkill
- background-processingSkill
- ci-cd-setupSkill
- cloudkit-syncSkill
- consent-flowSkill
- custom-product-pagesSkill
- data-exportSkill
- debug-menuSkill
- deep-linkingSkill
- error-monitoringSkill
- feature-flagsSkill
- featuring-nominationSkill
- feedback-formSkill
- force-updateSkill
- http-cacheSkill
- image-loadingSkill
- in-app-eventsSkill
- lapsed-userSkill
- live-activity-generatorSkill
- localization-setupSkill
- logging-setupSkill
- milestone-celebrationSkill
- networking-layerSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 15
Use this skill when:
- Distinctive: line 87
Read CLAUDE.md / APP.md / file-header comments for hard rules currently enforced by nothing.
- Distinctive: line 106
Run the suite — it MUST fail, with a message that names the offender.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Architecture Fitness Functions
A fitness function is an ordinary test that enforces an architectural rule instead of a behavior. It lives in the app's own test target, runs under every existing test gate forever, and turns "the agent said it's fine" into an exit code. This is the gauntlet's answer for invariants no unit test of behavior can see: a file quietly importing a framework it must not touch, a registry drifting from its documented size, user-facing copy breaking its format contract.
When This Skill Activates
Use this skill when:
- A project hard rule exists only in prose — CLAUDE.md constraints, file-header comments, review checklists ("deck games must run fully offline", "only the sync layer may import CloudKit")
- A code review keeps re-checking the same structural rule by hand
- An
/apple:reviewstructural finding is being graduated into permanent enforcement - A count, boundary, or content format was broken silently once already
Why a Test, Not a Lint Rule
A per-line regex (SwiftLint custom_rules) can flag a line. A fitness function can assert a set: "the files importing MusicKit are exactly these four", "the mode registry has exactly 21 entries", "every case's copy fits the format". Sets, counts, and cross-file facts need code, and putting that code in the test target means no new tooling, no CI wiring — it rides the test gate that already exists.
The Three Patterns
Pattern 1: Import-Boundary Allowlist Scan
Enforces "only these files may import X." The test walks the shipped source tree and compares the actual importer set against an allowlist — so a fifth importer fails a test, not a code review.
Key rules (learned in production):
- Resolve the source root from
#filePath, never a hardcoded path — the test stays correct wherever the repo is checked out. - Match exact trimmed lines (
line == "import X"), notcontains— comments documenting the contract itself must not count as hits. - Compare full sets, not counts — the failure message then names the drifted file.
- Exclude non-shipping directories deliberately (DEBUG-only spikes, generated code) and say why in a comment: the guarantee is about what ships.
- The allowlist is a fence, not a headcount. Widening it is a legitimate, documented decision: when a new file genuinely belongs inside the boundary, the test failing is the system working — record why in the allowlist comment, then add it.
- Add a companion API-surface scan for bypass routes the import check can't see. An import-only check misses a file calling the underlying API directly (every file already imports Foundation, which is enough to reach
URLSessionwithout importing the fenced framework). Scan for the raw API strings (URLSession(,URLSession.shared) outside the boundary too.
Template: templates/ImportBoundaryTests.swift
Pattern 2: Runtime Sentinel
Enforces "this code path never attempts X" — stronger than "happens to succeed without X." The canonical case is an offline guarantee: register a URLProtocol subclass that intercepts, counts, and fails every network request, drive the real production path, and assert the counter stayed at zero.
Key rules:
- Register the sentinel per-test and unregister in
defer. - The sentinel fails requests loudly (never lets them reach the network) — a regression fails in CI instead of silently succeeding against a live server.
- Assert
interceptedRequestCount == 0: the contract is zero attempts, not zero successes. - Drive the real path (real service, real composition), with only storage in-memory.
Template: templates/NetworkSentinelTests.swift
Pattern 3: Contract Pins
Pins facts that must change deliberately, never by drift.
Count pins — registry and configuration sizes:
// Phase 3.5 added 3 modes — 9 modes, 5 streaming.
// Phase 3.8 added the four reunion music games — 15 modes, 9 streaming.
// Phase 3.10 added the DJ-host quartet — 18 modes, 10 streaming.
#expect(PartyOccasion.bigParty.modes.count == 18)
#expect(PartyOccasion.bigParty.modes.filter(\.usesDJEngine).count == 10)The comment trail is mandatory: each pinned number carries its history, so updating the pin is a reviewed decision with a written reason, not a chore silenced with an edit.
Copy-contract pins — structural rules on user-facing content, iterated over CaseIterable so new cases are covered automatically:
@Test func everyModeHasExactlyThreeBeats() {
for mode in GameMode.allCases {
#expect(mode.howItPlaysBeats.count == 3, "\(mode.rawValue) has \(mode.howItPlaysBeats.count) beats, expected 3")
}
}Plus a few verbatim exemplars pinned with exact equality — a future content pass must change those deliberately, not by accident.
Template: templates/ContractPinTests.swift
Process
Phase 1: Identify the Invariant
Read CLAUDE.md / APP.md / file-header comments for hard rules currently enforced by nothing. Good candidates state a set or bound: "only", "never", "exactly", "at most", "every".
Phase 2: Pick the Pattern
| The rule is about… | Pattern |
| Which files may use a framework/API | 1 — import-boundary scan (+ API-surface companion) |
| What a code path may do at runtime | 2 — runtime sentinel |
| A size, format, or exact content | 3 — contract pins |
Phase 3: Write the Suite
Copy the matching template into the existing unit-test target and adapt. One suite per invariant; name it after the guarantee (OfflineGuaranteeTests), not the mechanism. Every failure message must tell the fixer which side to change — the code or the contract — and where the contract is documented.
Phase 4: Prove It Red (Deliberate-Break Drill)
A fitness function that has never failed is unverified. Before committing:
- Introduce the violation for real (add the forbidden import to one file; change a pinned count).
- Run the suite — it MUST fail, with a message that names the offender.
- Revert. Run again — green.
Record the red/green pair in the commit message or PR. Repeat the drill whenever the suite's scanning logic (not its data) changes.
Phase 5: Commit
The suite ships in the normal test target. No special CI wiring — every existing test gate now enforces the rule.
Output Format
## Fitness Function: [invariant]
- **Rule source**: CLAUDE.md hard rule N / [file header]
- **Pattern**: import-boundary | runtime sentinel | contract pin
- **Suite**: Tests/[Name]Tests.swift
- **Deliberate-break drill**: [what was broken] → failed with "[message]" → reverted → greenCommon Pitfalls
| Pitfall | Problem | Solution |
contains("import X") matching | Comments about the rule count as violations | Compare exact trimmed lines |
| Hardcoded source paths | Breaks on other checkouts/CI | Derive root from #filePath |
| Pinning counts without history | Updating the pin becomes a mindless chore | Comment trail explaining every number |
| Import check only | Direct API calls bypass the fence | Add the API-surface companion scan |
| Never proven red | Scan bug silently passes everything | Deliberate-break drill before commit |
| Allowlist grows without comment | Fence decays into a headcount | Each entry documents why it's inside the boundary |
References
testing/tdd-bug-fix/— prove-red discipline for behavioral bugstesting/test-contract/— runtime behavioral invariants across implementationsswift/code-size/— the complexity/size half of the deterministic gauntlettesting/coverage-ratchet/— coverage floor that only rises
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

