You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Introduces a new waldronlab skill `improve-code-coverage` for analyzing R package code coverage using the `covr` package. This skill actively identifies coverage gaps in `R/` and `src/` directories and proactively suggests and writes test cases. Crucially, it categorizes testing needs into:
- Normal Use
- Edge Cases
- Error Handling
- Correctness of Results (Bioconductor standard)
Includes the fully validated `SKILL.md` and corresponding updates to the `SKILLS.md` registry.
Co-authored-by: Gemini Code Assist <gemini@google.com>
Copy file name to clipboardExpand all lines: SKILLS.md
+38-4Lines changed: 38 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -242,6 +242,36 @@ Skills for analyzing, documenting, and developing R/Bioconductor packages follow
242
242
243
243
---
244
244
245
+
### improve-code-coverage
246
+
247
+
**Purpose**: Analyze R package code coverage using covr, classify testing gaps, and proactively write test cases to improve coverage and result correctness.
description: Analyze R package code coverage using covr, classify testing gaps, and proactively write test cases to improve coverage and result correctness.
Analyzes an R package's code coverage using the `covr` package, identifies uncovered lines (specifically in `R/` and `src/`), and actively suggests and writes new test cases. It emphasizes a Bioconductor-standard approach to testing by classifying coverage and new tests into: a) normal use, b) edge cases, c) error handling, and d) correctness of results.
13
+
14
+
## Usage
15
+
16
+
Invoke this skill when you want to increase your package's test coverage or evaluate testing rigor:
17
+
- "Check my code coverage and help me write missing tests."
18
+
- "Run covr on the package and improve testing for uncovered lines in `R/my_function.R`."
19
+
- "Improve code coverage, focusing on edge cases and correctness."
20
+
- "Summarize current code coverage."
21
+
22
+
## Prerequisites
23
+
24
+
- An R package structure with an `R/` directory and typically a `tests/` directory (e.g., using `testthat`).
25
+
- R packages `covr` and `testthat` installed.
26
+
- (Optional but recommended) `src/` directory if the package uses compiled code.
27
+
28
+
## Process
29
+
30
+
### 1. Run Coverage Analysis
31
+
- Execute `covr::package_coverage()` (or `covr::file_coverage()` if focused on specific files).
32
+
- Generate a local HTML report using `covr::report()` for the user to view visually, if applicable.
33
+
- Extract and calculate the current coverage percentages for files in the `R/` and `src/` directories.
34
+
35
+
### 2. Summarize and Identify Gaps
36
+
- Present a high-level summary of the coverage results in the chat. Crucially, when summarizing, evaluate not only the raw percentage but also the type of testing present (normal use, edge cases, error handling, correctness).
37
+
- Identify specific functions, branches, or lines in `R/` and `src/` that lack test coverage.
38
+
39
+
### 3. Classify Testing Needs
40
+
For the uncovered lines, analyze the function's logic and classify the missing test requirements into four categories:
41
+
-**Normal Use**: Standard expected inputs and typical workflows.
42
+
-**Edge Cases**: NA handling, empty inputs, and extreme but valid values.
43
+
-**Error Handling**: Verifying that invalid inputs or unsupported types gracefully throw informative errors (e.g., using `expect_error()`).
44
+
-**Correctness of Results**: Validating that the statistical or computational outputs are mathematically and scientifically correct (crucial for Bioconductor packages).
45
+
46
+
### 4. Propose and Write Tests
47
+
- Draft new `testthat` code blocks targeting the identified gaps.
48
+
- Explicitly label which of the four categories (Normal Use, Edge Cases, Error Handling, Correctness) each new test addresses.
49
+
- Focus on assertions that verify *correctness* (e.g., `expect_equal()`, `expect_identical()`) rather than just checking if the code runs without error (`expect_no_error()`), alongside proper `expect_error()` checks for invalid states.
50
+
51
+
### 5. Review and Iterate
52
+
- Present the suggested tests to the user.
53
+
- If requested, append or insert the new tests into the appropriate files in `tests/testthat/`.
54
+
- Suggest re-running the coverage analysis to verify the improvement.
55
+
56
+
## Output Format
57
+
58
+
- A chat summary that explicitly breaks down coverage by test category (Normal Use, Edge Cases, Error Handling, Correctness).
59
+
- Code blocks containing `testthat` test cases, categorized by their testing purpose.
60
+
- Instructions or scripts to generate the `covr` HTML report.
61
+
62
+
## Examples
63
+
64
+
### Example 1: Full Package Coverage Check
65
+
66
+
**User**: "Check my code coverage and help me write missing tests."
67
+
68
+
**Agent**:
69
+
1. Runs `covr::package_coverage()`.
70
+
2. Summarizes the results, noting for example that `R/normalize.R` is missing edge case tests for `NA` inputs.
71
+
3. Drafts new `test_that` blocks addressing those gaps, labeled clearly by their category.
72
+
73
+
### Example 2: Focusing on a Single File
74
+
75
+
**User**: "Run covr on the package and improve testing for uncovered lines in R/stats.R."
76
+
77
+
**Agent**:
78
+
1. Identifies gaps specifically within `R/stats.R`.
79
+
2. Drafts Correctness of Results tests comparing the output of the functions to known expected statistical outputs.
80
+
3. Suggests inserting these tests into `tests/testthat/test-stats.R`.
81
+
82
+
## Notes
83
+
84
+
- For Bioconductor packages, establishing ground truth for "correctness of results" is often the hardest part of testing. When writing correctness tests, explain the logic used to determine the expected output.
85
+
- Coverage of `src/` (C/C++) requires proper compiler flags; the skill should note this if compiled code coverage is unexpectedly zero.
0 commit comments