Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions CODING_STANDARDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ A state the compiler refuses needs no test and cannot return unnoticed.
body.
- Why: it costs no test run, fails when the state becomes constructable again,
and passes for that reason only.
- **SF-IMP-5** Never write or propose an integration, end-to-end, or microVM
test for an invariant a type can enforce; enforce it in types (`SF-IMP-1`).
Test at runtime only behaviour the compiler cannot prove (decoding external
data, peer responses, timing, or database and runtime behaviour). Run tests at
the lightest tier reaching that boundary and name the covered behaviour in any
test proposal.
- **SF-IMP-5** Never write or propose an integration or end-to-end test for an
invariant a type can enforce; enforce it in types (`SF-IMP-1`). Test at
runtime only behaviour the compiler cannot prove (decoding external data, peer
responses, timing, or database and runtime behaviour). Run tests at the
lightest isolation reaching that boundary and name the covered behaviour in
any test proposal.
- Why: slow tests tie up shared hosts while proving less than a compile error.

## Tests
Expand Down Expand Up @@ -80,10 +80,14 @@ A state the compiler refuses needs no test and cannot return unnoticed.
good test hides defects.
- **SF-TST-6** Keep unit tests deterministic and isolated: no child processes,
real clocks, network calls, host ports, host file system, or shared state
across tests. Put I/O tests in adapter suites and run them where repo testing
rules specify.
- Why: tests that spawn processes or sleep stall the host and fail on timing
rather than code defects.
across tests. Put I/O tests in adapter suites, each exercising one adapter
through its port against its backing resource or a compatible engine, in the
isolation the adapter needs (an in-process engine, a container, or a virtual
machine), never the subject's own logic driven through real I/O, and run them
where repo testing rules specify.
- Why: I/O in unit tests fails on timing rather than code defects, and driving
the subject's logic through real I/O hides whether the logic or the adapter
broke.
- **SF-TST-7** Treat a property-test timeout as a design failure. Fix its input
schema, or delete the test if it encodes one specific scenario. Never raise
its timeout, lower its run count, or narrow its generator.
Expand Down
4 changes: 2 additions & 2 deletions WORKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ narrow these rules, never loosen them.
- **SF-WRK-1** Deliver the whole task. Stop only when merged, in the merge
queue, or blocked by something only the owner holds, and state which applies.
- **SF-WRK-2** Do reversible work without asking.
- **SF-WRK-4** Never run full test suites, end-to-end tests, or microVM runs on
shared hosts; leave them to CI.
- **SF-WRK-4** Never run full test suites, end-to-end tests, or tests that boot
a container or virtual machine on shared hosts; leave them to CI.
- **SF-WRK-5** Before any destructive or broad action, restate the instruction's
verb and object in one line and act strictly on that, not on a nearby
interpretation.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
title: An I/O test isolates one adapter, and its runtime is a choice, not a tier
date: 2026-12-03
category: architecture-patterns
module: coding standards
problem_type: architecture_pattern
component: testing
severity: medium
applies_when:
- A standard or pack rule names one runtime (virtual machine, container, embedded engine) as the place every test's I/O must run
- An integration test drives a runtime, workflow or use case through a real database or service and asserts what that logic decided
- Choosing where an adapter test's backing resource runs
tags: [
testing,
integration,
adapter,
isolation,
microvm,
container,
sqlite,
pglite,
coupling,
]
---

# An I/O test isolates one adapter, and its runtime is a choice, not a tier

## Context

`SF-IMP-5` listed "integration, end-to-end, or microVM" tests, and `SF-WRK-4`
banned "microVM runs" on shared hosts. Naming the microVM beside the test kinds
made it read as a test tier of its own. Repositories then wrote rules that
required a virtual machine for every integration resource and banned every
container runtime. A plain database adapter test paid a guest boot (about 5.7 s
to boot Postgres, 11 s to its first query) where an in-memory SQLite or PGlite
engine would have answered at once. Guest-specific failures followed: a tap
device the kernel refused, a guest boot that outlasted a firewall test's wait,
and a fake clock that hung during boot.

That rule also aimed at the wrong failure. Where the I/O runs was never the
harm. The harm is a test that drives the subject's own logic through real I/O
and asserts what that logic decided. Such a test fails on I/O setup as well as
on logic defects, runs slowly, and cannot say which side broke.

## Guidance

- Test the subject's logic behind its ports, with fakes and no I/O (`SF-TST-6`,
unit tests).
- Test each adapter on its own: call its port and assert what its backing
resource stored or returned, or the error it mapped.
- Choose the adapter's isolation by what it needs. For a database, that is an
in-memory engine first (SQLite on `:memory:`, PGlite), then a container or a
virtual machine only for what those cannot do.
- Test the whole system on real services in the end-to-end suite.
- Keep the shared-host limit on what is heavy, not on one runtime by name:
`SF-WRK-4` covers any test that boots a container or virtual machine.

## Why This Matters

A rule that names one runtime gets cargo-culted. Agents apply it to every test,
and it never stops the coupled test it was written against. A rule that names
the coupling catches it whatever runtime the test uses.