Skip to content

chore: run all tests in ci and coverage#2302

Merged
tac0turtle merged 6 commits intomainfrom
marko/ci_cover
May 22, 2025
Merged

chore: run all tests in ci and coverage#2302
tac0turtle merged 6 commits intomainfrom
marko/ci_cover

Conversation

@tac0turtle
Copy link
Copy Markdown
Contributor

@tac0turtle tac0turtle commented May 21, 2025

Overview

this pr creates a test-cover.go file allowing it to run in ci and produce a large coverage reports

ref #2256

Summary by CodeRabbit

  • New Features
    • Added a streamlined command to run unit tests with coverage across multiple modules.
  • Chores
    • Updated test workflow to use the new coverage command.
    • Excluded specific mock directories from code coverage metrics.
    • Removed redundant test jobs from the workflow for improved efficiency.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2025

Warning

Rate limit exceeded

@tac0turtle has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 0 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 8bb6616 and c2c6a48.

📒 Files selected for processing (2)
  • scripts/test.mk (1 hunks)
  • scripts/test_cover.go (1 hunks)

Walkthrough

The changes introduce a new approach for running Go unit tests and collecting coverage across multiple modules. A new Go script and Makefile target automate test execution and coverage merging. The CI workflow is updated to use this new process, while redundant jobs are removed. The code coverage configuration now ignores mock directories.

Changes

File(s) Change Summary
.github/workflows/test.yml Updated unit_test job to use make test-cover; removed test_single_sequencer and test_da jobs.
scripts/test.mk Added new test-cover Makefile target to run the new coverage script.
scripts/test_cover.go Added new Go script to recursively run tests and merge coverage reports across Go modules.
codecov.yml Configured code coverage tool to ignore da/internal/mocks directory.

Sequence Diagram(s)

sequenceDiagram
    participant Workflow
    participant Makefile
    participant CoverageScript
    participant GoModules

    Workflow->>Makefile: make test-cover
    Makefile->>CoverageScript: go run scripts/test_cover.go
    loop For each Go module
        CoverageScript->>GoModules: go test -coverprofile=cover.out
        GoModules-->>CoverageScript: cover.out (if successful)
    end
    CoverageScript->>CoverageScript: Merge all cover.out files into coverage.txt
    CoverageScript->>CoverageScript: Cleanup individual cover.out files
    CoverageScript-->>Makefile: Exit status
    Makefile-->>Workflow: Test results and coverage.txt
Loading

Poem

In the warren of code, tests now run anew,
With a script that hops through modules, coverage in view.
Old jobs retired, the workflow’s more sleek,
Mocks are ignored, no more hide-and-seek!
Hooray for the Makefile, for coverage combined—
A rabbit’s delight, in results well-aligned!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2025

The latest Buf updates on your PR. Results from workflow CI and Release / buf-check (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed⏩ skipped✅ passed✅ passedMay 21, 2025, 4:47 PM

@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 50.95%. Comparing base (9eb9e59) to head (c2c6a48).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2302      +/-   ##
==========================================
- Coverage   55.79%   50.95%   -4.84%     
==========================================
  Files          53       81      +28     
  Lines        5008     7093    +2085     
==========================================
+ Hits         2794     3614     +820     
- Misses       1929     3102    +1173     
- Partials      285      377      +92     

☔ 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.

@tac0turtle tac0turtle marked this pull request as ready for review May 21, 2025 16:27
@tac0turtle tac0turtle requested review from alpe, Copilot and pthmas May 21, 2025 16:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 introduces a new Go script to run tests with coverage reporting and consolidates test execution in CI.

  • Added scripts/test_cover.go to detect modules, run tests with coverage, merge cover profiles, and clean up.
  • Updated scripts/test.mk and CI workflows in .github/workflows/test.yml to use the new test-cover target.
  • Adjusted codecov.yml to ignore additional directories.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
scripts/test_cover.go New script to run tests with coverage, merge outputs, and clean up
scripts/test.mk Added target to invoke the coverage script with go run
codecov.yml Updated ignore list for coverage analysis
.github/workflows/test.yml Modified test job to run the new target and removed extra test jobs
Comments suppressed due to low confidence (1)

.github/workflows/test.yml:42

  • [nitpick] Ensure the updated CI workflow using 'make test-cover' is reflected in the project documentation so team members understand the new testing and coverage process.
run: make test-cover

Comment thread scripts/test_cover.go
"strings"
)

func main() {
Copy link

Copilot AI May 21, 2025

Choose a reason for hiding this comment

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

[nitpick] The main function encompasses multiple phases (running tests, merging coverage files, and cleaning up). Consider refactoring into smaller helper functions to improve readability and maintainability.

Copilot uses AI. Check for mistakes.
Comment thread scripts/test_cover.go Outdated
Comment thread scripts/test.mk Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (3)
scripts/test.mk (1)

26-26: Fix comment to match target name and correct grammar

The comment should read "## test-cover: generate code coverage report." to match the target name and have correct grammar.

-## cover: generate to code coverage report.
+## test-cover: generate code coverage report.
scripts/test_cover.go (2)

16-125: 🛠️ Refactor suggestion

Refactor main function into smaller helper functions

The main function is very long (over 100 lines) and handles multiple responsibilities: finding modules, running tests, merging coverage files, and cleaning up. This makes it harder to maintain and test.

Consider refactoring into smaller functions like:

  • findModules(rootDir string) ([]string, error)
  • runTestsWithCoverage(moduleDir string) (string, error)
  • mergeCoverageFiles(coverFiles []string, outputFile string) error
  • cleanup(files []string) error

This would improve readability and make the code more maintainable.


41-41: 🛠️ Refactor suggestion

Add race detection and timeout to test command

The test command is missing the -race flag that was present in the original CI workflow. Without this flag, race conditions in concurrent code might go undetected.

Also, consider adding a timeout to prevent tests from hanging indefinitely:

-cmd := exec.Command("go", "test", "./...", "-coverprofile="+relativeCoverProfileArg, "-covermode=atomic")
+cmd := exec.Command("go", "test", "./...", "-race", "-timeout=10m", "-coverprofile="+relativeCoverProfileArg, "-covermode=atomic")
🧹 Nitpick comments (3)
scripts/test_cover.go (3)

16-18: Add command-line flags for better configurability

The script would benefit from command-line flags to make it more flexible and reusable. Currently, parameters like the root directory and test flags are hardcoded.

Consider using the flag package to add options like:

func main() {
    rootDir := flag.String("dir", ".", "Root directory to scan for Go modules")
    testFlags := flag.String("test-flags", "-race -timeout=10m", "Additional flags to pass to 'go test'")
    outputFile := flag.String("output", "coverage.txt", "Output file for merged coverage")
    verbose := flag.Bool("verbose", false, "Enable verbose output")
    flag.Parse()
    
    // Use the flags in your code
    // ...
}

This would allow users to customize the script's behavior without modifying the code.


73-77: Improve error handling and add context to errors

The error handling could be more robust, especially for file operations. Consider using fmt.Errorf to add context to errors and implementing proper cleanup on failure.

For example:

-out, err := os.Create(mergedCoverageFile)
-if err != nil {
-    log.Fatalf("Failed to create merged coverage file %s: %v\n", mergedCoverageFile, err)
-}
-defer out.Close()
+out, err := os.Create(mergedCoverageFile)
+if err != nil {
+    return fmt.Errorf("failed to create merged coverage file %s: %w", mergedCoverageFile, err)
+}
+defer func() {
+    if cerr := out.Close(); cerr != nil && err == nil {
+        err = fmt.Errorf("failed to close merged coverage file: %w", cerr)
+    }
+}()

Also consider adding signal handling to clean up temporary files when the process is interrupted.


28-31: Consider more robust directory filtering

The current directory filtering approach may miss some directories that should be excluded from testing, such as .github, node_modules, or other common non-Go directories.

Consider using a more comprehensive approach:

-if d.IsDir() && (d.Name() == "vendor" || d.Name() == ".git" || strings.Contains(path, "testdata")) {
+// Define a list of common directories to skip
+skipDirs := []string{"vendor", ".git", ".github", "node_modules", "build", "dist"}
+// Check if directory should be skipped
+if d.IsDir() {
+    if strings.Contains(path, "testdata") {
+        return filepath.SkipDir
+    }
+    for _, skipDir := range skipDirs {
+        if d.Name() == skipDir {
+            return filepath.SkipDir
+        }
+    }
+}

This would make the directory filtering more robust and easier to maintain.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 9eb9e59 and 8bb6616.

📒 Files selected for processing (4)
  • .github/workflows/test.yml (1 hunks)
  • codecov.yml (1 hunks)
  • scripts/test.mk (1 hunks)
  • scripts/test_cover.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (3)
codecov.yml (1)

14-14: Good addition to coverage exclusions

Adding mock directories to the ignore list is appropriate since they shouldn't be considered in coverage metrics.

scripts/test.mk (1)

27-30: LGTM: Well-structured make target

The implementation of the test-cover target follows the Makefile conventions used throughout the file.

.github/workflows/test.yml (1)

42-42: Good workflow simplification

Using the new make test-cover target centralizes test execution and coverage collection, making the CI workflow more maintainable.

tac0turtle and others added 2 commits May 21, 2025 18:46
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Comment thread scripts/test_cover.go
func main() {
rootDir := "."
var coverFiles []string
var testFailures bool
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The variable testFailures would be more descriptive with a name that follows boolean naming conventions. Consider renaming to hasTestFailures or testsFailed to make its purpose immediately clear to readers.

Suggested change
var testFailures bool
var testsFailed bool

Spotted by Diamond (based on custom rules)

Is this helpful? React 👍 or 👎 to let us know.

Copy link
Copy Markdown
Contributor

@alpe alpe left a comment

Choose a reason for hiding this comment

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

🥇 Good work

@tac0turtle tac0turtle added this pull request to the merge queue May 22, 2025
Merged via the queue into main with commit 15f9baa May 22, 2025
25 checks passed
@tac0turtle tac0turtle deleted the marko/ci_cover branch May 22, 2025 07:40
@github-project-automation github-project-automation Bot moved this to Done in Evolve May 22, 2025
@tac0turtle tac0turtle removed this from Evolve Aug 25, 2025
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.

4 participants