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

feat(query): package changes reason #9240

Merged
merged 16 commits into from
Oct 10, 2024

Conversation

NicholasLYang
Copy link
Contributor

@NicholasLYang NicholasLYang commented Oct 9, 2024

Description

Plumbing through reason for why a package changed for query. Adds a reason field which is a union of the different reasons a package could be added.

This can be reviewed commit by commit, although there is a little bit of churn around types and some behavior.

Testing Instructions

Added some tests to affected.t

Copy link

vercel bot commented Oct 9, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
examples-nonmonorepo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 10, 2024 8:37pm
8 Skipped Deployments
Name Status Preview Comments Updated (UTC)
examples-basic-web ⬜️ Ignored (Inspect) Visit Preview Oct 10, 2024 8:37pm
examples-designsystem-docs ⬜️ Ignored (Inspect) Visit Preview Oct 10, 2024 8:37pm
examples-gatsby-web ⬜️ Ignored (Inspect) Visit Preview Oct 10, 2024 8:37pm
examples-kitchensink-blog ⬜️ Ignored (Inspect) Visit Preview Oct 10, 2024 8:37pm
examples-native-web ⬜️ Ignored (Inspect) Visit Preview Oct 10, 2024 8:37pm
examples-svelte-web ⬜️ Ignored (Inspect) Visit Preview Oct 10, 2024 8:37pm
examples-tailwind-web ⬜️ Ignored (Inspect) Visit Preview Oct 10, 2024 8:37pm
examples-vite-web ⬜️ Ignored (Inspect) Visit Preview Oct 10, 2024 8:37pm

$ echo "hello world" > packages/util/new.js

Validate that both `my-app` and `util` are affected
$ ${TURBO} query "query { affectedPackages { items { name reason { __typename } } } }"
Copy link
Contributor

Choose a reason for hiding this comment

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

What's with the __typename thing? Is that going to stay? Can it just be reason (and the response also not have the value nested?)

Copy link
Member

@chris-olszewski chris-olszewski left a comment

Choose a reason for hiding this comment

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

Approving so we can get people testing this sooner vs later, but I think we'll want to change the reasons in a few ways:

  • Return all of the reasons why a package is in scope
  • Include all matching criteria for some reasons e.g. global file changes should mention all global files that changed and not just the first one
  • Lockfile changes would be a lot more useful if they returned what packages changed instead of lockfile contents.

@@ -23,19 +23,52 @@ pub enum LockfileChange {
WithContent(Vec<u8>),
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
pub enum PackageChangeReason {
Copy link
Member

Choose a reason for hiding this comment

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

Most of these variants seem more focused on why a package is included in a filter rather than "what has changed". Is PackagePresenceReason maybe a more accurate name for this enum?

/// Root task was run
RootTask { task: String },
/// The lockfile changed and caused this package to be invalidated
LockfileChanged { previous_lockfile: String },
Copy link
Member

Choose a reason for hiding this comment

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

What are we expecting consumers to do with the previous lockfile content?

file: AnchoredSystemPathBuf,
},
LockfileChangeDetectionFailed {
previous_lockfile: String,
Copy link
Member

Choose a reason for hiding this comment

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

Same question as above: What are we expecting consumers to do with the previous lockfile content?

DefaultGlobalFileChanged,
LockfileChangeDetectionFailed,
DefaultGlobalFileChanged {
file: AnchoredSystemPathBuf,
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be useful to return all changed global files instead of just the first one.

Comment on lines 148 to 149
previous_lockfile: String::from_utf8_lossy(&content)
.to_string(),
Copy link
Member

Choose a reason for hiding this comment

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

I think the far more useful bit of information here would be returning the diff between the transitive closure that gets calculated in get_changed_packages_from_lockfile

error: impl std::error::Error,
from_ref: Option<String>,
to_ref: Option<String>,
) -> Result<ChangedFilesResult, Error> {
warn!(
"unable to detect git range, assuming all files have changed: {}",
error
);
Copy link
Member

Choose a reason for hiding this comment

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

Should this warning go up a level since we're no longer making this decision in this crate?

.map(|(name, _)| name.to_owned())
.map(|(name, _)| PackageChange {
name: name.to_owned(),
reason: PackageChangeReason::IncludedByFilter {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe NoFilter is a more accurate variant for end users to understand why a package was in the run scope?

@@ -97,7 +97,7 @@ impl<'a> GitChangeDetector for ScopeChangeDetector<'a> {
include_uncommitted: bool,
allow_unknown_objects: bool,
merge_base: bool,
) -> Result<HashSet<PackageChange>, ResolutionError> {
) -> Result<HashMap<PackageName, PackageChangeReason>, ResolutionError> {
Copy link
Member

Choose a reason for hiding this comment

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

Should we be returning HashMap<PackageName, HashSet<PackageChangeReason>> so we correctly communicate to users if there are multiple reasons why a package is in scope?

}
}
}

let mut all_packages = HashSet::new();
let mut all_packages = HashMap::new();
Copy link
Member

Choose a reason for hiding this comment

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

Especially here I feel like it would be useful to indicate if there are multiple reasons a package was in scope and currently the reason is dependent on the ordering of the extend calls.

Comment on lines 102 to 111
fn merge_changed_packages(
changed_packages: &mut HashMap<PackageName, PackageChangeReason>,
new_changes: impl IntoIterator<Item = (PackageName, PackageChangeReason)>,
) {
for (package, reason) in new_changes {
if !changed_packages.contains_key(&package) {
changed_packages.insert(package, reason);
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

fn merge_changed_packages(
    changed_packages: &mut HashMap<PackageName, HashSet<PackageChangeReason>>,
    new_changes: impl IntoIterator<Item = (PackageName, PackageChangeReason)>,
) {
    for (package, reason) in new_changes {
        let mut reasons = changed_packages.entry(package).or_default();
        reasons.insert(reason);
    }
}

@NicholasLYang NicholasLYang merged commit 5c93793 into main Oct 10, 2024
43 checks passed
@NicholasLYang NicholasLYang deleted the nicholasyang/package-change-reason branch October 10, 2024 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants