|
| 1 | +# Operational policy specs |
| 2 | + |
| 3 | +Human-readable specifications for eviction policies used as the **source of truth** for test-side oracles. |
| 4 | + |
| 5 | +## Directory layout |
| 6 | + |
| 7 | +```text |
| 8 | +docs/testing/specs/ |
| 9 | +├── README.md, matrix.md, template.md, tla-guide.md # hub docs |
| 10 | +├── _includes/ # shared fragments (Op mapping, maturity levels) |
| 11 | +├── policies/ # human operational specs by tier |
| 12 | +│ ├── exact/ # FIFO, LRU, LFU, … |
| 13 | +│ ├── mirror/ # Clock, 2Q, … |
| 14 | +│ ├── bounded/ # ARC, S3-FIFO, … |
| 15 | +│ └── composed/ # TTL |
| 16 | +└── formal/ # TLA+ modules + TLC runbooks |
| 17 | + ├── fifo/ |
| 18 | + └── lru/ |
| 19 | +``` |
| 20 | + |
| 21 | +**Canonical index:** [matrix.md](matrix.md) (maturity, harness mode, model paths per policy). |
| 22 | + |
| 23 | +## Pipeline (all tiers) |
| 24 | + |
| 25 | +```text |
| 26 | +policies/<tier>/<policy>.md |
| 27 | + → reference/ PolicyModel (optional — independent formulation) |
| 28 | + → exact/ PolicyModel (deque / DS-shaped oracle) |
| 29 | + → policy_semantics dual-run vs implementation |
| 30 | +``` |
| 31 | + |
| 32 | +| Tier | Harness mode | Oracle | |
| 33 | +|------|--------------|--------| |
| 34 | +| Exact / mirror | DualRun | `exact/` `PolicyModel` vs impl | |
| 35 | +| Exact (policies with `reference/` rows) | CrossModel | `reference/` vs `exact/` | |
| 36 | +| Bounded | InvariantOnly | structural invariants on impl | |
| 37 | +| Composed (TTL) | DualRun + deadlines | `LruOccupancyModel` + TTL layer | |
| 38 | + |
| 39 | +Cross-model tests prove `reference/` agrees with `exact/` on the same traces. Impl dual-run proves `exact/` agrees with real caches. |
| 40 | + |
| 41 | +## Required sections (every policy spec) |
| 42 | + |
| 43 | +Use [template.md](template.md) as the skeleton: |
| 44 | + |
| 45 | +1. **Maturity banner** — `stub`, `reference`, and/or `tla` |
| 46 | +2. **State variables** — abstract state at rest between operations |
| 47 | +3. **Init** — empty cache at capacity `C` |
| 48 | +4. **Per-`Op` transitions** — match the harness [`Op<K>`](../../../tests/abstract_models/mod.rs) alphabet |
| 49 | +5. **Tie-breaks** — deterministic victim and rank when multiple keys qualify |
| 50 | +6. **Observables** — `resident`, `peek_victim`, `recency_rank` (if applicable), `hit` classification |
| 51 | +7. **API mapping** — how each `Op` maps to cache traits (`peek` must not promote on LRU, etc.) |
| 52 | + |
| 53 | +Shared harness `Op` table: [_includes/harness-op-mapping.md](_includes/harness-op-mapping.md). Trait semantics: [trait hierarchy](../../design/trait-hierarchy.md). |
| 54 | + |
| 55 | +## Spec-change checklist |
| 56 | + |
| 57 | +When a spec changes, update in order: |
| 58 | + |
| 59 | +1. Spec doc under `policies/<tier>/` |
| 60 | +2. `tests/abstract_models/reference/<policy>.rs` (if reference model exists) |
| 61 | +3. Cross-model test expectations (if behavior changed) |
| 62 | +4. `tests/abstract_models/exact/<policy>.rs` if the exact model was wrong |
| 63 | +5. `formal/<policy>/` TLA+ module and `tlc.md` alignment notes (if applicable) |
| 64 | +6. Row in [matrix.md](matrix.md) |
| 65 | + |
| 66 | +## TLA+ (optional manual check) |
| 67 | + |
| 68 | +FIFO and LRU include TLA+ pilots under [formal/](formal/README.md). **Read first:** [tla-guide.md](tla-guide.md). TLC is **not** run in CI. |
| 69 | + |
| 70 | +```bash |
| 71 | +./scripts/run-tlc.sh fifo # or ./scripts/run-fifo-tlc.sh |
| 72 | +./scripts/run-tlc.sh lru # or ./scripts/run-lru-tlc.sh |
| 73 | +``` |
| 74 | + |
| 75 | +Success: no `SemanticOK` violation on the bundled config. Runbooks: [formal/fifo/tlc.md](formal/fifo/tlc.md), [formal/lru/tlc.md](formal/lru/tlc.md). |
| 76 | + |
| 77 | +**TLC vs Rust:** TLC proves `SemanticOK` on reachable states for a finite instance; proptest runs long sequential traces on `u8` keys. They are complementary. |
| 78 | + |
| 79 | +## Related documentation |
| 80 | + |
| 81 | +- [Policy matrix](matrix.md) — canonical index |
| 82 | +- [Policy specs by tier](policies/README.md) |
| 83 | +- [Spec template](template.md) — new policy skeleton |
| 84 | +- [TLA+ guide](tla-guide.md) — contributor guide |
| 85 | +- [Abstract models README](../../../tests/abstract_models/README.md) |
| 86 | +- [Policy semantic testing](../static-analysis.md) |
| 87 | +- [Testing strategy](../testing.md) |
0 commit comments