Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NuGet strategy consolidation #1461

Merged
merged 11 commits into from
Feb 14, 2025
Merged

NuGet strategy consolidation #1461

merged 11 commits into from
Feb 14, 2025

Conversation

JeffreyHuynh1
Copy link
Contributor

@JeffreyHuynh1 JeffreyHuynh1 commented Aug 21, 2024

Overview

All of the CLI’s nuget strategies run everytime fossa analyze is run. This causes duplicate information to be uploaded on almost every run. The worst part of this is that one of the strategies analyzes a lockfile with determined versions and the other analyzes a manifest with versions that may not be present in the final build.

From Nugets website

The project.json file maintains a list of packages used in a project, known as a package management format. It supersedes packages.config but is in turn superseded by PackageReference with NuGet 4.0+.

https://fossa.com/blog/managing-dependencies-net-csproj-packagesconfig/

Acceptance criteria

  • Nuget analysis strategies are not all run and utilize fallbacks to ensure that duplicate dependencies are not uploaded.

  • Implementation decisions here do not prevent https://fossa.atlassian.net/browse/ANE-702 from being implemented.

  • Consolidate analysis for project.assets.json and package reference files because they have the same entry point, .csproj files. The other strategies can remain the same and be ran independently.

Documentation is updated to display what the fallback order is.

Testing plan

  • Refactored existing test to work with the consolidation and it's working as it did previously.

Risks

[Question] - Was looking into writing an integration test to test the case where we have both .csproj files (triggers PackageReference strategy) and project.assets.json files, that way we can test out the consolidation changes in this pr. After looking at our integration tests, it looks like we test against open source repos , the issue with project.assets.json files is that they are not typically included in open source repos as they are generated automatically by the .NET SDK during the restore process. We also didn't have an existing integration test for the project.assets.json strategy either. I feel like we should still have a test for this but am unsure on the best way to go about it. Should I just clone a repo, generate a project.assets.json file and push those changes to a new repo so that we can test against for our tests?

Metrics

References

Checklist

  • I added tests for this PR's change (or explained in the PR description why tests don't make sense).
  • If this PR introduced a user-visible change, I added documentation into docs/.
  • If this PR added docs, I added links as appropriate to the user manual's ToC in docs/README.ms and gave consideration to how discoverable or not my documentation is.
  • If this change is externally visible, I updated Changelog.md. If this PR did not mark a release, I added my changes into an # Unreleased section at the top.
  • If I made changes to .fossa.yml or fossa-deps.{json.yml}, I updated docs/references/files/*.schema.json AND I have updated example files used by fossa init command. You may also need to update these if you have added/removed new dependency type (e.g. pip) or analysis target type (e.g. poetry).
  • If I made changes to a subcommand's options, I updated docs/references/subcommands/<subcommand>.md.

@JeffreyHuynh1 JeffreyHuynh1 marked this pull request as ready for review August 23, 2024 17:56
@JeffreyHuynh1 JeffreyHuynh1 requested a review from a team as a code owner August 23, 2024 17:56
@JeffreyHuynh1 JeffreyHuynh1 requested review from zlav and spatten August 23, 2024 17:56
Copy link
Contributor

@spatten spatten left a comment

Choose a reason for hiding this comment

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

I think we need some tests that test the new behaviour works and actually runs the correct strategy depending on whether a project.assets.json file or a .csproj file is found during discovery.

We should have a test plan that tests these two cases as well, so we can manually validate that this works.

- `cargo` - Rust dependencies that are typically found at [crates.io](https://crates.io/).
- `carthage` - Dependencies as specified by the [Carthage](https://github.com/Carthage/Carthage) package manager.
- `composer` - Dependencies specified by the PHP package manager [Composer](https://getcomposer.org/), which are located on [Packagist](https://packagist.org/).
- `cpan` - Dependencies located on the [CPAN package manager](https://www.cpan.org/).
<!-- markdown-link-check-disable-next-line -->
- `cran` - Dependencies located on the [CRAN](https://cran.r-project.org/) like repository.
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to re-enable these? I think they were disabled because they were flaky in the past

Copy link
Contributor

Choose a reason for hiding this comment

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

Not knowing a reason to re-enable, I've added these back


## Requirements
| Strategy | Direct Deps | Transitive Deps | Edges |
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] Can you prettify these markdown tables?

I do it through the Markdown Table Prettifier extension: https://marketplace.visualstudio.com/items?itemName=darkriszty.markdown-table-prettify

Just install that, and then "command-P prettify markdown tables" in each markdown doc

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the extension link; done and done

Comment on lines 33 to 34
import Strategy.NuGet.PackageReference qualified as PackageReference
import Strategy.NuGet.PackageReference qualified as ProjectAssetsJson
Copy link
Contributor

Choose a reason for hiding this comment

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

You're importing the same package twice but calling it different things. Shouldn't the second one of these be imported from Strategy.NuGet.ProjectAssetsJson?

Copy link
Contributor

Choose a reason for hiding this comment

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

I've picked this up and am working from the assumption that this was a typo and meant to be Strategy.NuGet.ProjectAssetsJson

analyzeProjectStaticOnly _ = getDeps

getDeps :: (Has ReadFS sig m, Has Diagnostics sig m) => NuGetProject -> m DependencyResults
getDeps project = context "NuGet" (getAssetsJsonDeps project <||> getPackageReferenceDeps project)
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels weird that we're just running getAssetsJsonDeps on the file even if it's not named project.assets.json. Should we switch on the filename, or add a new field to the Nuget type that tells us which type of analysis we should be doing?

Copy link
Contributor

Choose a reason for hiding this comment

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

I changed this to call getAssetsJsonDeps only on project.assets.json. I think that we should probably rely on the file in question living where it does to avoid some perverse edge case like "this other JSON file I found is a valid project.assets.json file but dotnet will not treat it as such. I hold this opinion lightly, will revert if desired.

@zlav zlav removed their request for review October 11, 2024 19:24
@james-fossa james-fossa force-pushed the nuget-strategy branch 2 times, most recently from ecfcc6a to cb7b6e4 Compare January 10, 2025 11:21
@james-fossa james-fossa requested a review from spatten January 16, 2025 15:29
Copy link
Contributor

@spatten spatten left a comment

Choose a reason for hiding this comment

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

This looks great! I had a few, minor and optional, nits. Nothing blocking approval

@@ -54,6 +54,7 @@ Supported dependency types:
- `pub` - Dart dependencies found at [pub.dev](https://www.pub.dev/).
- `pypi` - Python dependencies that are typically found at [Pypi.org](https://pypi.org/).
- `swift` - Swift dependencies using the [Swift Package Manager](https://www.swift.org/package-manager/).
<!-- markdown-link-check-disable-next-line -->
Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, now I'm reversing my previous comment. This comment is not on current master, and I don't think this PR should change that

@@ -0,0 +1,17 @@
# Quick reference: NuGet
Copy link
Contributor

Choose a reason for hiding this comment

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

This file is new in this PR and not referenced anywhere in the documentation. There are other <language>-qr.md files in the repo, but I think it's confusing to have both nuget.md and nuget-qr.md.

So, I know you didn't add it, but I think we should delete it

@@ -38,7 +55,20 @@ testServiceStackForPkgConfig =
it "should find targets" $ \(result, _) -> do
length result `shouldBe` 4

testDotnetCoreTwoExampleForPackageAssetsJson :: Spec
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be named testDotnetCoreTwoExampleForProjectAssetsJson?

@james-fossa james-fossa merged commit 90efbf2 into master Feb 14, 2025
18 of 19 checks passed
@james-fossa james-fossa deleted the nuget-strategy branch February 14, 2025 15:02
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