Skip to content

Conversation

@brabster
Copy link
Contributor

@brabster brabster commented Nov 8, 2025

Fixes #2331

I did use Copilot coding agent to help me with this but I've tweaked and sense checked the output. I hope it's acceptable, let me know if there are any problems 🙏

@google-cla
Copy link

google-cla bot commented Nov 8, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@brabster brabster changed the title Copilot/deduplicate sarif outputs deduplicate sarif outputs for GitHub Nov 8, 2025
@brabster
Copy link
Contributor Author

brabster commented Nov 8, 2025

Hmm not sure what to do about "Copilot" not having signed the CLA? I guess if this solution looks good I can go rewrite the history back to me

"github.com/google/osv-scanner/v2/pkg/models"
)

func TestCreateSARIFFingerprint(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
func TestCreateSARIFFingerprint(t *testing.T) {
func Test_createSARIFFingerprint(t *testing.T) {

Copy link
Collaborator

Choose a reason for hiding this comment

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

also I think this test could do with some rework - rather than have a table test with the same inputs, and then a second (sub?) test that tests a bunch of other packages, I think we should have a single collection of table tests, and within each test we can run the function twice to do the deterministic test

Copy link
Collaborator

@another-rex another-rex left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for the contribution!

I think the current tests are mostly fine, as the second test is covering something completely separate from the first. Though can you move the second test into a separate Test_ function?

@another-rex
Copy link
Collaborator

To make the snapshot tests pass, you need to run with UPDATE_SNAPS=true env variable when running the tests.

Copilot AI and others added 3 commits November 14, 2025 07:23
- Moved "different inputs" test to separate Test_ function
- Removed duplicate test case with same inputs
- Added diverse test cases covering different scenarios
- Each test verifies determinism by calling function twice
- All tests still pass

Co-authored-by: brabster <[email protected]>
- Uses nested loops to generate all combinations of test dimensions
- Tests 2 vulnIDs × 2 artifactPaths × 4 packages = 16 combinations
- More maintainable: easy to add new test values without manual enumeration
- Better error messages showing both inputs when fingerprints collide
- Verifies all combinations produce unique fingerprints

Co-authored-by: brabster <[email protected]>
- Extracted common test parameters (vulnIDs, artifactPaths, packages) to package-level variables
- Both tests now use the same parameter sets for consistency
- Test_createSARIFFingerprint uses matrix approach to generate all 16 combinations
- Test_createSARIFFingerprint_DifferentInputs uses same parameters to verify uniqueness
- Easy to extend by modifying common parameter arrays
- Ensures both tests cover the exact same input space

Co-authored-by: brabster <[email protected]>
@brabster
Copy link
Contributor Author

Thanks @another-rex!

  • I did refactor those tests to use more of a matrix approach - I think it's easier to see what's going on and be sure that all combinations are tested. I expect it to be less brittle for you going forward too.
  • I also changed the signature tests to depend on the invariance rather than the specific hash values - again, I hope that means it's easier to see what's being tested, that it's comprehensive, and fewer changes to make if edge cases emerge.
  • I think the snapshots are good

I'm not sure what to do about Copilot's authorship and the CLA - if I need to rewrite the history and force push or something I can do that, let me know.

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.

SARIF output does not contain partialFingerprints property, resulting in duplicate records eg. in GitHub output

3 participants