Skip to content

🛡️ Sentry: [test coverage improvement]#1099

Closed
madmax983 wants to merge 1 commit into
trunkfrom
sentry/artifact-test-coverage-2431047419031674089
Closed

🛡️ Sentry: [test coverage improvement]#1099
madmax983 wants to merge 1 commit into
trunkfrom
sentry/artifact-test-coverage-2431047419031674089

Conversation

@madmax983

Copy link
Copy Markdown
Owner

🎯 Target: src/artifact.rs missing test coverage and src/env/docker.rs test lints.

💣 Risk: artifact.rs contains critical data types (ArtifactSchemaVersion, ArtifactKind, ArtifactHeader, ArtifactCompatibility, ArtifactSchemaError) and functions (classify_json_value, to_string_pretty, to_writer_pretty) for serialization/deserialization and checking artifacts. A failure here could corrupt metrics, prevent loading results, or panic during artifact reads.

🧪 Strategy: Added a comprehensive tests module directly inside src/artifact.rs (using #![allow(clippy::unwrap_used)]) to test schema version logic, artifact kinds and headers, classification/deserialization logic (including errors like version mismatches and unsupported futures), and serialization to string/writer. Also fixed an existing unwrap_used lint violation inside src/env/docker.rs's test module.

🔬 Verification: cargo test artifact and cargo test env::docker --features docker passing. cargo clippy --all-targets --all-features -- -D warnings passing cleanly.


PR created automatically by Jules for task 2431047419031674089 started by @madmax983

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request adds comprehensive unit tests to src/artifact.rs covering schema versioning, artifact classification, compatibility classes, and serialization, as well as adding a clippy allow attribute to src/env/docker.rs. The review feedback suggests improving the idiomatic quality of the tests by replacing verbose match statements with assert!(matches!(...)) macros and recommends adding test coverage for MalformedHeader error cases.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/artifact.rs
Comment on lines +449 to +457
ArtifactSchemaError::KindMismatch {
expected, found, ..
} => {
assert_eq!(expected, ArtifactKind::SweepResults);
assert_eq!(found, ArtifactKind::Trajectory);
}
_ => panic!("Expected KindMismatch"),
}
}

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.

medium

Using a verbose match statement with a manual panic! is less idiomatic in Rust. We can simplify this assertion using assert!(matches!(...)) to improve readability and maintainability.

        assert!(matches!(
            err,
            ArtifactSchemaError::KindMismatch {
                expected: ArtifactKind::SweepResults,
                found: ArtifactKind::Trajectory,
                ..
            }
        ));

Comment thread src/artifact.rs
Comment on lines +467 to +477
ArtifactSchemaError::UnsupportedFuture {
version,
supported_major,
..
} => {
assert_eq!(version.major, 99);
assert_eq!(supported_major, 1);
}
_ => panic!("Expected UnsupportedFuture"),
}
}

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.

medium

Similarly, we can simplify this assertion using assert!(matches!(...)) instead of a verbose match block with a manual panic!.

        assert!(matches!(
            err,
            ArtifactSchemaError::UnsupportedFuture {
                version: ArtifactSchemaVersion { major: 99, .. },
                supported_major: 1,
                ..
            }
        ));

Comment thread src/artifact.rs
assert_eq!(res.warnings.len(), 1);
assert!(res.warnings[0].contains("newer additive minor"));
}

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.

medium

The PR aims to improve test coverage for src/artifact.rs, but it currently lacks test coverage for the MalformedHeader error cases in classify_json_value. Adding a test case to cover these scenarios ensures that malformed headers are handled correctly and prevents regressions.

    }

    #[test]
    fn classify_malformed_header() {
        // Case 1: Only one of artifact_kind or schema_version is present
        let val1 = json!({
            "artifact_kind": "trajectory"
        });
        let err1 = classify_json_value(&val1, ArtifactKind::Trajectory, "path").unwrap_err();
        assert!(matches!(err1, ArtifactSchemaError::MalformedHeader { .. }));

        // Case 2: Invalid artifact_kind
        let val2 = json!({
            "artifact_kind": "invalid_kind",
            "schema_version": {"major": 1, "minor": 13}
        });
        let err2 = classify_json_value(&val2, ArtifactKind::Trajectory, "path").unwrap_err();
        assert!(matches!(err2, ArtifactSchemaError::MalformedHeader { .. }));

        // Case 3: Invalid schema_version
        let val3 = json!({
            "artifact_kind": "trajectory",
            "schema_version": "invalid_version"
        });
        let err3 = classify_json_value(&val3, ArtifactKind::Trajectory, "path").unwrap_err();
        assert!(matches!(err3, ArtifactSchemaError::MalformedHeader { .. }));
    }

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.21429% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.66%. Comparing base (33594d5) to head (ad0e77b).

Files with missing lines Patch % Lines
src/artifact.rs 98.21% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk    #1099      +/-   ##
==========================================
+ Coverage   86.63%   86.66%   +0.02%     
==========================================
  Files         139      139              
  Lines       86826    86938     +112     
==========================================
+ Hits        75220    75341     +121     
+ Misses      11606    11597       -9     

☔ View full report in Codecov by Harness.
📢 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.

@madmax983 madmax983 closed this Jul 17, 2026
@madmax983
madmax983 deleted the sentry/artifact-test-coverage-2431047419031674089 branch July 17, 2026 00:14
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.

1 participant