Invalidate lockfile when empty dependency groups are added or removed (#12010)

## Summary

Since https://github.com/astral-sh/uv/pull/8598, we (correctly) include
empty groups in the lockfile, so we can validate them properly in the
satisfaction check.

Closes https://github.com/astral-sh/uv/issues/12007.
This commit is contained in:
Charlie Marsh 2025-03-06 09:44:20 -08:00 committed by GitHub
parent 40dce4e009
commit 626fff1be7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 248 additions and 2 deletions

View file

@ -587,6 +587,13 @@ impl Lock {
(self.version(), self.revision()) >= (1, 1)
}
/// Returns `true` if this [`Lock`] includes entries for empty `dependency-group` metadata.
pub fn includes_empty_groups(&self) -> bool {
// Empty dependency groups are included as of https://github.com/astral-sh/uv/pull/8598,
// but Version 1 Revision 1 is the first revision published after that change.
(self.version(), self.revision()) >= (1, 1)
}
/// Returns the lockfile version.
pub fn version(&self) -> u32 {
self.version
@ -1099,7 +1106,7 @@ impl Lock {
// Validate the `dependency-groups` metadata.
let expected: BTreeMap<GroupName, BTreeSet<Requirement>> = dependency_groups
.into_iter()
.filter(|(_, requirements)| !requirements.is_empty())
.filter(|(_, requirements)| self.includes_empty_groups() || !requirements.is_empty())
.map(|(group, requirements)| {
Ok::<_, LockError>((
group,
@ -1114,7 +1121,7 @@ impl Lock {
.metadata
.dependency_groups
.iter()
.filter(|(_, requirements)| !requirements.is_empty())
.filter(|(_, requirements)| self.includes_empty_groups() || !requirements.is_empty())
.map(|(group, requirements)| {
Ok::<_, LockError>((
group.clone(),