test(server): add unit coverage for the store_budget LRU key ordering and JSON length helpers
- Dominant language
- Rust
- Stars
- 467
- Forks
- 54
- Avg merge
- 4h 25m
- Merged PRs (30d)
- 310
Description
## Summary
`src/server/store_budget.rs`, the shared helper module for the bounded in-memory server stores, has no tests, while every sibling helper module under `src/server/` carries a `_tests.rs`. Add direct unit coverage for its two pure helpers.
## Background
The module exposes `serialized_json_len_saturating` (a saturating JSON byte counter, `src/server/store_budget.rs:28`) and the `LruKey` `Ord` implementation whose tiebreak chain (last_accessed, then sequence, then id) determines eviction order. Both `responses_store.rs` and `conversation_store.rs` depend on these to stay correctly bounded, so the ordering is worth pinning. A grep for either symbol finds no test anywhere.
## Proposed Solution
Add a `store_budget_tests.rs` wired via `#[cfg(test)]` in `src/server/mod.rs`, matching the existing sibling pattern. Cover the JSON length saturation path and a sort of hand-built `LruKey` values that exercises each tiebreak level. No MLX or model dependency is involved.
## Implementation Notes
- `src/server/store_budget.rs:28` defines `serialized_json_len_saturating`, backed by the `SaturatingByteCounter` writer that returns `usize::MAX` on serialization error.
- The `LruKey` `Ord` impl (last_accessed then sequence then id) is the eviction contract used by the bounded stores.
- Follow the `src/server/*_tests.rs` convention already present for the sibling helpers.
## Acceptance Criteria
- [ ] Both helpers have direct unit coverage, including the `Ord` tiebreak chain
- [ ] Tests follow the `src/server/*_tests.rs` convention
---
## Original Suggestion
### Title: test(server): add unit tests for the store_budget helpers
`src/server/store_budget.rs` — the shared helper module for the bounded in-memory server stores — has zero tests, while every sibling helper module in `src/server/` carries a `_tests.rs`.
## Evidence
- `src/server/store_budget.rs:28-78` — `serialized_json_len_saturating` and the `LruKey` `Ord` impl (last_accessed → sequence → id tiebreak) are pure and allocation-free; a grep for either symbol finds no test anywhere
- The eviction order encoded in that `Ord` impl is exactly what keeps the response/conversation stores bounded correctly — worth pinning
## Suggested fix
Add a `store_budget_tests.rs` wired via `#[cfg(test)]` in `src/server/mod.rs`, matching the existing sibling pattern: a few asserts on the JSON length saturation and a sort of hand-built `LruKey`s covering each tiebreak level. No MLX or model dependency involved.
## Acceptance criteria
- [ ] Both helpers have direct unit coverage, including the `Ord` tiebreak chain
- [ ] Tests follow the `src/server/*_tests.rs` convention
Contributor guide
Research direction
Start with src/server/store_budget.rs and the existing src/server/*_tests.rs sibling pattern, then inspect src/server/mod.rs for test-module wiring. Add direct tests for serialized_json_len_saturating and hand-built LruKey values covering the last_accessed, sequence, and id tiebreaks. Done means both helpers have coverage and the tests follow the established convention.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend, testing
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100