Skip to content

[Package Data Model] Adding package models and reusable capabilities - #6370

Merged
jebriede merged 32 commits into
devfrom
dev-feature-PackageDomainModel
Apr 18, 2025
Merged

jebriede merged 32 commits into
devfrom
dev-feature-PackageDomainModel

Conversation

@jebriede

@jebriede jebriede commented Apr 2, 2025 •

Copy link
Copy Markdown
Contributor

Bug

Fixes: https://github.com/NuGet/Client.Engineering/issues/3214

Description

Package Model:

Introduced a new abstract package model to serve as the domain model for packages and implementations for package types.

  • Added various package types, including remote packages, local packages, recommended packages, referenced packages, and transitively referenced packages.
  • Implemented a factory to encapsulate the creation of the appropriate package type, including its capabilities describing package behaviors such as vulnerabilities and deprecation data, based on the construction parameters.

Capabilities and Implementations:

Introduced flexible, reusable, and testable capabilities for composing packages and their behaviors.

  • Created reusable components for capabilities, allowing different types of capabilities based on desired behavior, such as vulnerability data from package metadata or a vulnerability service.
  • Encapsulated functionality within the model to avoid replicating logic across view models and views.

View Model and Control Changes:

The PackageItemViewModel is now made to leverage the new package domain model, an improvement over having the ViewModel maintain properties to determine the package state.

  • Updated the PackageItemLoader to use the factory to build the appropriate package model type given a PackageSearchMetadataContextInfo and selected tab.
  • Refactored the PackageItemViewModel to use the new domain model as its backing model, reducing functionality within the view model itself.
  • Updated the package item view model method UpdateTransitivePackageStatus to avoid passing in the version, reducing potential errors.
  • Fixed binding for the tooltip in the package item control to account for changes in property notifications.

Package Metadata Retrieval Adapter:

  • Introduced a package metadata retrieval adapter to fetch package metadata and deprecation data separately, maintaining state and handling concurrency.

Tests:

  • Added tests for all newly introduced classes, including: the abstract package model, package model types, capability implementations, and the PackageMetadataRetrievalAdapter.

PackageDeprecationReasonEnum

  • Added an Enum to represent the different reasons for package deprecation. Also, moved constant values from the DetailControlModel related to deprecation reasons to this new class.

Refactoring to reduce Code Duplication:

  • In PackageItemViewModel combined ReloadTopLevelPackageMetadataAsync and ReloadTransitivePackageMetadataAsync into a single method ReloadPackageMetadataAsync to encapsulate the package type into the ViewModel and simplify the caller's responsibilities.
  • Extracted common try-catch logic into RunOperationAsync to reduce code duplication.

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

It's worth mentioning that we had a manual test pass of the NuGet Package Manager from the source branch that helped us discovered one bug with the deprecation label in the package list. We fixed that already and the fix is included in this PR. All other tests from that validation passed!

Copilot AI 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.

Pull Request Overview

This PR introduces a new abstract package model along with several concrete package model types and reusable capabilities for handling package vulnerabilities and deprecation. Key changes include refactoring the PackageItemLoader to leverage a PackageModelFactory for creating package models, adding new package model classes (e.g., RemotePackageModel, TransitivelyReferencedPackageModel, RecommendedPackageModel), and implementing various capability classes for vulnerability and deprecation data retrieval.

Reviewed Changes

Copilot reviewed 49 out of 50 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
PackageItemLoader.cs Refactored view model creation logic to use the new PackageModelFactory and updated transitive package handling.
VulnerablePackageMetadataCapability.cs Introduced a capability to retrieve vulnerability data from package metadata.
VulnerableDatabaseCapability.cs Added a capability to obtain vulnerability data via a package vulnerability service.
VulnerableCapabilityBase.cs Created a base class for vulnerability capabilities with built-in sorting of vulnerability data.
TransitivelyReferencedPackageModel.cs, RemotePackageModel.cs, ReferencedPackageModel.cs, RecommededPackageModel.cs New package model implementations encapsulating domain package information and capabilities.
PackageModelFactory.cs Factory class to encapsulate the creation of various package model types based on metadata.
Other files (PackageModel.cs, PackageMetadataRetrievalAdapter.cs, LocalPackageModel.cs, etc.) Support classes and interfaces for handling embedded resources and package metadata retrieval.
Files not reviewed (1)
  • src/NuGet.Clients/NuGet.PackageManagement.UI/Design/PackageItemListViewSampleData.xaml: Language not supported
Comments suppressed due to low confidence (1)

src/NuGet.Clients/NuGet.PackageManagement.UI/Models/Package/PackageModelFactory.cs:24

  • The use of 'nameof(_searchService)' in the constructor argument null check should reference the parameter 'searchService' instead (e.g., nameof(searchService)).
_searchService = searchService ?? throw new ArgumentNullException(nameof(_searchService));

@jebriede
jebriede marked this pull request as ready for review April 2, 2025 23:22
@jebriede
jebriede requested a review from a team as a code owner April 2, 2025 23:22

@nkolev92 nkolev92 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

image

This what was generated when you create a CD in VS from the NuGet.PackageManagement.UI.Models.Package folder.

From my feedback, a bunch are suggestions, the only thing that I think needs to be address is the NuGet.Protocol project feedback.

jgonz120 and others added 18 commits April 16, 2025 13:26
* Add local embedded resouce

* Added remote resource

* Added tests

* Pr comments

* Switched to value task

* remove local

* Added ReadmeUri back as a property

* typo

* rename tests

* Update test

* combine test

* rename tests
* Add new fields

* added summary

* only use ownerlist
* Add known owners capability

* Add access modifier
…#6313)

* Updated model

* Updated to include readme

* Add class modifiers

* rename

* remove newline
* Added known owners to RemotePackageModel

* Update known owners capability to be private var
* Add self hydration to deprecation

* update deprecation

* add private

* add mock to constructor
* Added some vulnerability capabilities

* Update to have refresh action

* Added tests and use interface

* PR comments

* Pr comments

* Remove unused variable

* Remove extra parameters

* update tests

* update words

* combine throw

* add readonly

* simplify

* fix words

* update
* Added capabilities to different models

* moved vulnerabiity off of base package

* update access modifiers to internal

* rename

* Update test/NuGet.Clients.Tests/NuGet.PackageManagement.UI.Test/Models/Package/LocalPackageModelTests.cs
@jebriede
jebriede force-pushed the dev-feature-PackageDomainModel branch from 152d2dd to 0b41801 Compare April 16, 2025 23:16
nkolev92
nkolev92 previously approved these changes Apr 17, 2025

@nkolev92 nkolev92 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is looking great!
Thanks for addressing all the feedback.

I have a few comments that can be resolved in this or a future PR.
During the walkthrough we discussed init properties for the models, was the decision in the end to not use them?

@Nigusu-Allehu Nigusu-Allehu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@jebriede
jebriede enabled auto-merge (squash) April 18, 2025 18:02
@jebriede
jebriede merged commit 9c479c5 into dev Apr 18, 2025
@jebriede
jebriede deleted the dev-feature-PackageDomainModel branch April 18, 2025 18:13
@zivkan zivkan added the Learning Opportunity Triggers an in-depth conversation in the weekly PR review meeting so that reviewers can learn more label Jul 29, 2025
@jeffkl jeffkl added Learning Done Used to mark when Learning Opportunity has been addressed and removed Learning Opportunity Triggers an in-depth conversation in the weekly PR review meeting so that reviewers can learn more labels Aug 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Learning Done Used to mark when Learning Opportunity has been addressed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants