Skip to content

po4yka/RIPDPI / .agents/skills/ripdpi-tdd

ripdpi-tdd

Verified

Red-green-refactor workflow for RIPDPI plus test-double and FaultQueue conventions. Use when the user asks for test-first work or a defect needs a reproducing test. Not for Kotlin test syntax (use kotlin-test-patterns).

FileKindSize
SKILL.mdskill md5.3 KB
references/testing-anti-patterns.mdmarkdown5.1 KB

references/testing-anti-patterns.md

View on GitHub
# Testing Anti-Patterns

Extended reference for the TDD skill. Load this when diagnosing test quality issues.

## Test Double Anti-Patterns

**No mocking libraries.** The project uses hand-written Fakes exclusively. MockK and Mockito add implicit behavior, make tests brittle to refactoring, and hide design problems.

**Fresh Fake per test.** Never share mutable Fake state across tests. Create a new instance in each test method or in a `@BeforeTest` setup.

**Test public API, not internals.** If you need to reach into private fields or use reflection to test something, the design needs to change -- not the test.

**FaultScope.ONE_SHOT vs PERSISTENT.** Default to `ONE_SHOT` -- it fires once and is consumed. Use `PERSISTENT` only when the test exercises repeated calls to the same target (e.g., polling loops). Forgetting to clear a `PERSISTENT` fault causes mysterious failures in subsequent test methods if Fake instances are accidentally shared.

**FaultOutcome selection.** Match the outcome to the real failure mode:
- `EXCEPTION` / `TIMEOUT` / `DROP` / `RESET` -- for I/O and network faults
- `MALFORMED_PAYLOAD` / `BLANK_PAYLOAD` -- for corrupt or empty native responses (non-throwing)
- `PANIC` -- for simulated native panics that cross the JNI boundary

## Coroutine Testing Anti-Patterns

**Use `runTest`, not `runBlocking`.** `runTest` from `kotlinx-coroutines-test` auto-advances virtual time and fails on uncaught exceptions. `runBlocking` blocks real threads and masks timing bugs.

**Async start + blocker pattern.** When testing code that calls `start()` on a blocking native operation, use the `startedSignal` / `startBlocker` pattern from existing Fakes:

```kotlin
val bindings = FakeRipDpiProxyBindings()
bindings.startedSignal = CompletableDeferred()
bindings.startBlocker = CompletableDeferred()

// Launch the operation under test
val job = launch { runtime.start(preferences) }

// Wait for native start to be called
bindings.startedSignal!!.await()

// Assert intermediate state here

// Unblock native start
bindings.startBlocker!!.complete(Unit)
job.join()
```

**Harness cleanup.** Always cancel coroutine scopes and clear FaultQueues in `@AfterTest`. Leaked coroutines cause flaky tests and misleading stack traces.

## Golden Contract Anti-Patterns

**Scrub volatile fields.** Timestamps, session IDs, loopback ports, temp paths, and archive filenames must be scrubbed or replaced with deterministic placeholders before comparison. See `docs/testing.md` for the full list of scrubbed vs. strict fields.

**Review before blessing.** Never run `RIPDPI_BLESS_GOLDENS=1` and commit without inspecting the diff. Golden contracts are compatibility boundaries -- accidental changes break downstream consumers.

**Correct fixture directory.** Match the test layer:
- Rust: `tests/golden/` within the crate
- JVM: `src/test/resources/golden/` within the module
- Android instrumentation: `app/src/androidTest/assets/golden/`

Putting fixtures in the wrong directory causes silent test skips or misleading passes.

## Rust Testing Anti-Patterns

**TEST_LOCK for shared state.** Rust integration tests that touch shared resources (network ports, file paths) must use a test mutex or serial test attribute. Parallel test execution causes port conflicts and flaky failures.

**Explicit runtime for fixture lifecycle.** When tests use the local-network-fixture binary, build and manage the Tokio runtime explicitly. Do not rely on `#[tokio::test]` defaults for tests that need fixture startup/teardown sequencing.

**Ephemeral ports.** See the `rust-tdd` skill for the general ephemeral-port pattern. The RIPDPI-specific exception is `scripts/ci/start-local-network-fixture.sh`: it intentionally binds fixed, well-known ports (control port `RIPDPI_FIXTURE_CONTROL_PORT`, default `46090`, plus the TCP/TLS/DNS ports the `android-device-debug` skill's port-forwarding commands hardcode) rather than an ephemeral one, because those ports are forwarded to a device with `adb reverse` and must be predictable. Do not change the fixture to bind port 0.

**Proptest regression files.** When `proptest` finds a failing case, it writes a regression file. Commit these files -- they prevent the same failure from being missed in future runs.

## Structural Anti-Patterns

**Reuse shared helpers.** Before writing a helper, look for one in the owning module's test sources (`TestDoubles.kt` in `:core:engine`). Duplicated helper logic across test classes drifts.

**No reflection.** Reflection-based tests break silently on rename refactors. Test through the public API; add a production seam only when a non-trivial behavior cannot be reached any other way, never only to test trivial wiring.

**Unit test when possible.** Integration and E2E tests are slower, flakier, and harder to debug. Only escalate when the behavior genuinely requires real Android components or network I/O. Most business logic can be tested with Fakes at the unit level.

**One assertion focus per test.** A test method should verify one behavior. Multiple unrelated assertions in a single test make failures ambiguous -- you cannot tell which behavior broke without reading the full stack trace.
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall