Skip to content
This repository was archived by the owner on Jul 7, 2026. It is now read-only.

Commit 1fc4967

Browse files
lwaldronGemini Code Assist
andcommitted
feat: add improve-code-coverage skill
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>
1 parent 4388177 commit 1fc4967

2 files changed

Lines changed: 123 additions & 4 deletions

File tree

SKILLS.md

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,36 @@ Skills for analyzing, documenting, and developing R/Bioconductor packages follow
242242

243243
---
244244

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.
248+
249+
**Location**: `skills/improve-code-coverage/SKILL.md`
250+
251+
**When to use**:
252+
- Increasing an R package's test coverage
253+
- Evaluating testing rigor and identifying gaps
254+
- Proactively writing test cases categorized by normal use, edge cases, error handling, and correctness
255+
256+
**Invocation**:
257+
- "Check my code coverage and help me write missing tests."
258+
- "Run covr on the package and improve testing for uncovered lines in R/my_function.R."
259+
- "Improve code coverage, focusing on edge cases and correctness."
260+
- "Summarize current code coverage."
261+
262+
**What happens**:
263+
- Runs `covr` package coverage analysis and extracts percentages for `R/` and `src/`.
264+
- Summarizes coverage results, evaluating the types of tests present.
265+
- Identifies uncovered functions and logic branches.
266+
- Classifies missing testing needs into Normal Use, Edge Cases, Error Handling, or Correctness.
267+
- Drafts new `testthat` code blocks targeting identified gaps.
268+
269+
**Output**: A chat summary breaking down coverage by test category, and code blocks containing `testthat` cases.
270+
271+
**Related skills**: analyze-r-package, security-audit-r-package
272+
273+
---
274+
245275
### security-audit-r-package
246276

247277
**Purpose**: Perform comprehensive security audit of R/Bioconductor packages
@@ -308,7 +338,7 @@ Skills for statistical analysis patterns in microbiome and multi-omics research.
308338
| Category | Skills | Purpose |
309339
|----------|--------|---------|
310340
| **meta** | create-skill, check-waldronlab-skills, document-skill, validate-skill | Repository and workflow infrastructure |
311-
| **r-packages** | analyze-r-package, create-package-instructions, security-audit-r-package, update-package-instructions | R/Bioconductor package development |
341+
| **r-packages** | analyze-r-package, create-package-instructions, improve-code-coverage, security-audit-r-package, update-package-instructions | R/Bioconductor package development |
312342
| **metagenomics** | (Planned) | Metagenomics data workflows |
313343
| **statistical-methods** | (Planned) | Statistical analysis patterns |
314344

@@ -317,14 +347,17 @@ Skills for statistical analysis patterns in microbiome and multi-omics research.
317347
| Tag | Skills | Use Case |
318348
|-----|--------|----------|
319349
| **infrastructure** | create-skill, check-waldronlab-skills, document-skill, validate-skill | Repository and workflow tasks |
350+
| **testing** | improve-code-coverage | Software testing and coverage |
320351
| **validation** | security-audit-r-package, validate-skill | Quality control and standards compliance |
321352
| **quality-control** | security-audit-r-package, validate-skill | Ensuring skill quality |
322353
| **documentation** | create-package-instructions, document-skill, update-package-instructions | Generating and maintaining docs |
323354
| **automation** | document-skill | Automating repetitive documentation tasks |
324355
| **analysis** | analyze-r-package | Understanding code and architecture |
325356
| **security** | security-audit-r-package | Security audits and vulnerability detection |
326357
| **audit** | security-audit-r-package | Comprehensive code auditing |
327-
| **bioconductor** | analyze-r-package, create-package-instructions, security-audit-r-package, update-package-instructions | Bioconductor-specific workflows |
358+
| **bioconductor** | analyze-r-package, create-package-instructions, improve-code-coverage, security-audit-r-package, update-package-instructions | Bioconductor-specific workflows |
359+
| **code-coverage** | improve-code-coverage | Code coverage analysis |
360+
| **covr** | improve-code-coverage | Tools wrapping the covr package |
328361
| **data-access** | analyze-r-package (detects), create-package-instructions | Working with remote data |
329362

330363
---
@@ -335,8 +368,9 @@ Skills for statistical analysis patterns in microbiome and multi-omics research.
335368

336369
1. **Understand the package**`analyze-r-package`
337370
2. **Create AI instructions**`create-package-instructions`
338-
3. **Audit for security issues**`security-audit-r-package`
339-
4. **Keep instructions updated**`update-package-instructions`
371+
3. **Improve test coverage**`improve-code-coverage`
372+
4. **Audit for security issues**`security-audit-r-package`
373+
5. **Keep instructions updated**`update-package-instructions`
340374

341375
### "I want to create a new skill..."
342376

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
name: improve-code-coverage
3+
description: Analyze R package code coverage using covr, classify testing gaps, and proactively write test cases to improve coverage and result correctness.
4+
version: 1.0.0
5+
category: r-packages
6+
tags: [r, testing, code-coverage, covr, bioconductor]
7+
author: waldronlab
8+
---
9+
10+
# improve-code-coverage
11+
12+
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

Comments
 (0)