Skip to content

chore: Add mock trait implementations + AGENTS.md#26

Merged
mhambre merged 2 commits into
masterfrom
chore/test-readers
Jun 12, 2026
Merged

chore: Add mock trait implementations + AGENTS.md#26
mhambre merged 2 commits into
masterfrom
chore/test-readers

Conversation

@mhambre

@mhambre mhambre commented Jun 12, 2026

Copy link
Copy Markdown
Owner

No description provided.

@mhambre mhambre marked this pull request as ready for review June 12, 2026 03:23
Copilot AI review requested due to automatic review settings June 12, 2026 03:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-memory Mock* 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 + an AGENTS.md guide.

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 thread Cargo.toml
Comment thread src/utils/rand.rs
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 thread src/traits.rs
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>;
@mhambre mhambre merged commit e64abda into master Jun 12, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants