cohesion-over-testability

Collapse test-driven production code splits while preserving behavior and regression coverage.

4.8k|376|Updated Mar 16, 2023
One-click install
npx skills add https://github.com/EpicenterHQ/epicenter --skill cohesion-over-testability
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cohesion-over-testability
Source: https://github.com/EpicenterHQ/epicenter/tree/main/.agents/skills/cohesion-over-testability
Command: npx skills add https://github.com/EpicenterHQ/epicenter --skill cohesion-over-testability

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Production codebases accumulate artificial seams—helpers, wrappers, and injected dependencies—that exist only so unit tests can reach internals. This Skill identifies those test-shaped splits and collapses them back into cohesive functions without losing regression coverage.

Core Features & Use Cases

  • Smell Detection: Recognizes five common forms of testability theater, including paired getter/setter injection, optional deps parameters, pure-inner/thin-outer splits, and test-only exports.
  • Six-Step Collapse Procedure: Counts production callers, reads the outer and test, inlines the inner function, and redirects coverage to integration tests, type-level invariants, or documented deletion.
  • Systematic Audit Sweep: Provides grep-based audit commands and a triage procedure (via references/sweep-procedure.md) for sweeping an entire codebase, with commit hygiene and anti-pattern guidance.
  • Use Case: A TypeScript package has a 47-line helper with a 187-line test and a one-line production wrapper. Use this Skill to inline the helper, drop the injection seam, and enforce the invariants with types instead.

Quick Start

Audit this repository for functions that were split only to satisfy unit tests and inline the ones with a single production caller.

Frequently Asked Questions about cohesion-over-testability

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I find code that was split only for unit tests?

Grep for exported functions with optional deps or overrides parameters, paired getter/setter parameters, and test files much larger than their subject under test. Then count production callers; a single caller besides the test signals a test-driven split.

When should I inline a helper function into its caller?

Inline when the helper has exactly one production caller, the caller's body is just a call plus formatting, and the helper would not exist as a separate piece without the test. Keep the split if the helper has multiple consumers or its own product purpose.

How do I keep test coverage after deleting a unit test?

Replace the deleted unit test with an integration test through the natural boundary, a type-level invariant such as a branded return type, or a documented decision that the branch is trivially exercised on every product use.

When should I not collapse a dependency injection seam?

Keep the seam when the injected dependency is policy owned by the caller, crosses a real runtime or package boundary, or when the inner function has multiple production consumers. Also keep it when inlining would push the outer past roughly 60-80 lines.

Is dependency injection always a code smell in tests?

No. Injection is legitimate when production callers pass non-default values, when it crosses process or deploy boundaries, or when it carries policy decisions. It is a smell only when the test is the sole supplier of non-default values.