chore: Add mock trait implementations + AGENTS.md#26
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR replaces the existing “stub” test utilities with functional in-memory mock implementations (reader/writer/metadata), adds deterministic latency/jitter utilities to support those mocks, and introduces an AGENTS.md contributor/agent guide. It also changes the crate’s core backend traits (Reader/Writer/Metadata) to use async methods via async-trait, which is a public API change.
Changes:
- Replace
StubReader/StubWriter/StubMetadata(panic stubs) with in-memoryMock*implementations plus unit tests. - Add deterministic jitter + async latency helpers (
utils::rand) used by the mocks. - Convert the public backend traits to async (
async-trait), update impacted tests, and add dependencies + anAGENTS.mdguide.
Reviewed changes
Copilot reviewed 17 out of 18 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/writers/stub_writer.rs | Removed unimplemented stub writer. |
| src/utils/writers/mod.rs | Switch exports from StubWriter to MockWriter. |
| src/utils/writers/mock_writer.rs | New in-memory async mock writer with deterministic latency + tests. |
| src/utils/readers/stub_reader.rs | Removed unimplemented stub reader. |
| src/utils/readers/mod.rs | Switch exports from StubReader to MockReader. |
| src/utils/readers/mock_reader.rs | New in-memory async mock reader with deterministic latency + tests. |
| src/utils/rand.rs | New deterministic RNG + latency/jitter utility used by mocks. |
| src/utils/mod.rs | Expose rand module in test-only utils. |
| src/utils/metadatas/stub_metadata.rs | Removed unimplemented stub metadata store. |
| src/utils/metadatas/mod.rs | Switch exports from StubMetadata to MockMetadata. |
| src/utils/metadatas/mock_metadata.rs | New in-memory async mock metadata store with deterministic latency + tests. |
| src/traits.rs | Public API change: make backend traits async and adjust Writer::write signature. |
| src/registry.rs | Update tests to async trait usage and swap stub reader for mock reader. |
| src/builder.rs | Update unit tests to use mock implementations. |
| Cargo.toml | Add async-trait, futures-timer, and tokio (dev-dep). |
| Cargo.lock | Lockfile updates for new dependencies. |
| AGENTS.md | New contributor/agent guidance document. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+11
to
+34
| #[derive(Default)] | ||
| /// In-memory writer backed by a lock-protected byte map. | ||
| pub(crate) struct MockWriter { | ||
| values: RwLock<HashMap<String, Bytes>>, | ||
| latency: Latency, | ||
| } | ||
|
|
||
| impl MockWriter { | ||
| /// Create an empty writer using the default cache latency profile. | ||
| pub(crate) fn new() -> Self { | ||
| Self { | ||
| values: RwLock::new(HashMap::new()), | ||
| latency: Latency::intra_dc(), | ||
| } | ||
| } | ||
|
|
||
| /// Create an empty writer with an explicit latency profile. | ||
| pub(crate) fn with_latency(latency: Latency) -> Self { | ||
| Self { | ||
| values: RwLock::new(HashMap::new()), | ||
| latency, | ||
| } | ||
| } | ||
| } |
Comment on lines
+11
to
+34
| #[derive(Default)] | ||
| /// In-memory metadata store backed by a lock-protected byte map. | ||
| pub(crate) struct MockMetadata { | ||
| values: RwLock<HashMap<String, Bytes>>, | ||
| latency: Latency, | ||
| } | ||
|
|
||
| impl MockMetadata { | ||
| /// Create an empty metadata store using the default cache latency profile. | ||
| pub(crate) fn new() -> Self { | ||
| Self { | ||
| values: RwLock::new(HashMap::new()), | ||
| latency: Latency::intra_dc(), | ||
| } | ||
| } | ||
|
|
||
| /// Create an empty metadata store with an explicit latency profile. | ||
| pub(crate) fn with_latency(latency: Latency) -> Self { | ||
| Self { | ||
| values: RwLock::new(HashMap::new()), | ||
| latency, | ||
| } | ||
| } | ||
| } |
Comment on lines
8
to
+16
| /// Reads explicit byte ranges from an upstream data source. | ||
| #[async_trait] | ||
| #[allow(clippy::len_without_is_empty)] | ||
| pub trait Reader: Send + Sync { | ||
| /// Return the total number of bytes in the source object. | ||
| fn len(&self) -> io::Result<usize>; | ||
| async fn len(&self) -> io::Result<usize>; | ||
|
|
||
| /// Read `length` bytes beginning at `offset`. | ||
| fn read_at(&self, offset: usize, length: usize) -> io::Result<Bytes>; | ||
| async fn read_at(&self, offset: usize, length: usize) -> io::Result<Bytes>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.