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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

NuGet strategy consolidation #1461

wants to merge 5 commits into from

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


## 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

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?

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?

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.

2 participants