Skip to content

[coverage-improver] Cover empty cache index and reconciler raw_content branches#280

Merged
github-actions[bot] merged 2 commits intomainfrom
coverage-improver/cache-empty-index-and-reconciler-raw-content-db9eb53b40014eb6
Apr 7, 2026
Merged

[coverage-improver] Cover empty cache index and reconciler raw_content branches#280
github-actions[bot] merged 2 commits intomainfrom
coverage-improver/cache-empty-index-and-reconciler-raw-content-db9eb53b40014eb6

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Apr 7, 2026

What branches were uncovered

1. libaipm/src/cache.rsread_index(), line 383

if content.is_empty() {
    return Ok(CacheIndex::default());
}

The True branch (file exists but is empty) was never exercised. All existing tests that call read_index() do so after a put() which always writes a non-empty JSON index.

2. libaipm/src/migrate/reconciler.rsfind_associated_artifact(), line 112

if content.contains(path_str.as_ref()) {
    return Some(artifact.name.clone());
}

The True branch (raw_content contains the file path, returning an association) was not covered by any direct call to find_associated_artifact. While the through-reconcile() path was covered, one LLVM inlining context had True: 0.

What scenario the new tests cover

Test 1 — cache::tests::get_with_empty_index_file_returns_none:
Creates a cache, manually writes an empty cache_index.json file (simulating a truncated/reset cache), then calls cache.get(). The read_index() function finds the file, reads empty content, and returns CacheIndex::default() via the previously-uncovered early-return.

Test 2 — migrate::reconciler::tests::find_associated_artifact_raw_content_contains_path:
Calls find_associated_artifact directly with an artifact that has no referenced_scripts but whose raw_content contains the queried path string. This ensures the True branch of content.contains() is hit in the direct-call inlining context.

Before / after branch coverage

Metric Before After
Total branches 1940 1940
Missed branches 189 188
Branch coverage 90.26% 90.31%

Tests added

// cache.rs
#[test]
fn get_with_empty_index_file_returns_none() {
    let (temp, cache) = test_cache(Policy::Auto);
    let cache_root = temp.path().join("cache");
    std::fs::create_dir_all(&cache_root).unwrap_or_else(|_| {});
    std::fs::write(cache.index_path(), "").unwrap_or_else(|_| {});

    let result = cache.get("some-spec");
    assert!(result.is_ok());
    assert!(result.unwrap_or(Some(PathBuf::new())).is_none());
}
// reconciler.rs
#[test]
fn find_associated_artifact_raw_content_contains_path() {
    let mut artifact = make_artifact("config-skill", ArtifactKind::Skill, "/src/skills/cfg");
    artifact.metadata.raw_content = Some("assets/logo.png is referenced here".to_string());

    let result = find_associated_artifact(Path::new("assets/logo.png"), &[artifact]);
    assert_eq!(result, Some("config-skill".to_string()));
}

Generated by Coverage Improver · ● 5.9M ·

Add two unit tests to improve branch coverage:

1. cache::tests::get_with_empty_index_file_returns_none
   Covers the `content.is_empty()` True branch in `read_index()`
   (cache.rs:383). Previously the index file always had content when
   present; this test writes an empty file to exercise the early-return
   default-index path.

2. migrate::reconciler::tests::find_associated_artifact_raw_content_contains_path
   Covers the `content.contains(path_str.as_ref())` True branch in
   `find_associated_artifact()` (reconciler.rs:112). Previously no
   direct call to the function exercised the path where raw_content
   mentions the file path; this test adds that direct call.

Branch coverage: 90.26% -> 90.31% (188 missed, down from 189).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions bot enabled auto-merge April 7, 2026 15:28
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.35%. Comparing base (64fd752) to head (743bd5d).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #280      +/-   ##
==========================================
+ Coverage   95.34%   95.35%   +0.01%     
==========================================
  Files          91       91              
  Lines       26467    26482      +15     
  Branches      805      805              
==========================================
+ Hits        25234    25251      +17     
+ Misses       1100     1099       -1     
+ Partials      133      132       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions bot merged commit cf31bb9 into main Apr 7, 2026
12 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.

0 participants