Skip to content

[coverage-improver] Cover MockFs stub trait methods in discovery.rs #1646

Description

@TheLarkInn

What branch was uncovered

crates/libaipm/src/make/discovery.rs — the MockFs test helper's Fs
trait-implementation stubs (create_dir_all, write_file, read_to_string,
read_dir, lines 82–96) were never exercised by any existing test. These
methods exist only to satisfy the Fs trait bound for MockFs, but
find_marketplace/has_any_engine_marketplace only ever call exists, so
the other four methods' bodies (and their branch outcomes, e.g. the Err
path in read_to_string) were unreachable through the existing test suite,
dragging the file's branch coverage down to 64.71%.

What scenario the new test covers

Added mock_fs_stub_methods_return_expected_defaults, which directly calls
create_dir_all, write_file, read_to_string, and read_dir on a fresh
MockFs instance and asserts their documented stub behavior: the first two
return Ok(()), read_to_string returns an Err (since it always reports
"not used"), and read_dir returns an empty Vec.

Before/after branch coverage

  • discovery.rs branch coverage: 64.71% → 88.89%
  • Workspace TOTAL branch coverage: 90.64% → 90.72%

Test code added

/// Covers the unused-by-`find_marketplace` `Fs` trait methods on
/// `MockFs`. These stubs exist only to satisfy the `Fs` trait bound and
/// are never reached through `find_marketplace`/`has_any_engine_marketplace`,
/// so exercise them directly.
#[test]
fn mock_fs_stub_methods_return_expected_defaults() {
    let fs = MockFs::new();
    let path = Path::new("/project/.ai");

    assert!(fs.create_dir_all(path).is_ok());
    assert!(fs.write_file(path, b"content").is_ok());
    assert!(fs.read_to_string(path).is_err());
    assert_eq!(fs.read_dir(path).unwrap_or_default().len(), 0);
}

Verification

  • cargo build --workspace
  • cargo test --workspace ✅ (all 6 discovery tests pass)
  • cargo fmt --check
  • cargo clippy --workspace -- -D warnings — pre-existing failures unrelated
    to this change (2 manual_is_variant_and lints in resolver/mod.rs and
    security.rs from the Rust 1.98.0 toolchain bump, already being addressed
    in PR fix(clippy): use Result::is_ok_and for Rust 1.98.0 manual_is_variant_and lint #1631); no clippy issues in the modified file.

Generated by Coverage Improver · auto · 109.2 AIC · ⌖ 8.3 AIC · ⊞ 13.1K ·


Note

This was originally intended as a pull request, but PR creation failed. The changes have been pushed to the branch coverage-improver/discovery-mockfs-stub-methods-c1bd38748bdcd928.

Original error: ERR_API: [2026-08-21T12:57:49.430Z] create pull request in TheLarkInn/aipm failed (attempt 1)

Original error: Resource not accessible by personal access token - https://docs.github.com/rest/pulls/pulls#create-a-pull-request
Retryable: false
Suggestion: This error cannot be resolved by retrying. Please check the error details and fix the underlying issue.

To create the pull request manually:

gh pr create --title "[coverage-improver] Cover MockFs stub trait methods in discovery.rs" --base main --head coverage-improver/discovery-mockfs-stub-methods-c1bd38748bdcd928 --repo TheLarkInn/aipm
Show patch (39 lines)
From a3859308bcacc456a1e4276928fe51bc6c071e70 Mon Sep 17 00:00:00 2001
X-GH-AW-Base-Commit: 6d3368da0e97be67cb075dba37b9b384df816358
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Fri, 21 Aug 2026 12:53:46 +0000
Subject: [PATCH] test(discovery): cover MockFs stub trait method branches

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
 crates/libaipm/src/make/discovery.rs | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/crates/libaipm/src/make/discovery.rs b/crates/libaipm/src/make/discovery.rs
index 9245688..6c977e8 100644
--- a/crates/libaipm/src/make/discovery.rs
+++ b/crates/libaipm/src/make/discovery.rs
@@ -149,4 +149,19 @@ mod tests {
         let result = find_marketplace(Path::new("/"), &fs);
         assert!(result.is_err());
     }
+
+    /// Covers the unused-by-`find_marketplace` `Fs` trait methods on
+    /// `MockFs`. These stubs exist only to satisfy the `Fs` trait bound and
+    /// are never reached through `find_marketplace`/`has_any_engine_marketplace`,
+    /// so exercise them directly.
+    #[test]
+    fn mock_fs_stub_methods_return_expected_defaults() {
+        let fs = MockFs::new();
+        let path = Path::new("/project/.ai");
+
+        assert!(fs.create_dir_all(path).is_ok());
+        assert!(fs.write_file(path, b"content").is_ok());
+        assert!(fs.read_to_string(path).is_err());
+        assert_eq!(fs.read_dir(path).unwrap_or_default().len(), 0);
+    }
 }
-- 
2.54.0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions