Skip to content

Commit

Permalink
yarn classic: Drop offline mirror collision exception raise
Browse files Browse the repository at this point in the history
Currently, we check for possible collision in the offline mirror cache
when two different tarballs have the identical name. In that case, the
second tarball will override the first one, which might lead to
unexpected behavior.

Note: This is only relevant for registry, url and git packages

The functionality works as expected until the user uses duplicate
identical dependency, one for npm and one for yarn, that happend to be
present in the yarn.lock file.

This patch replaces the exception raise for log warning to unblock
users. Further investigation should how to deal with this use case
should be done later.

Signed-off-by: Michal Šoltis <[email protected]>
  • Loading branch information
slimreaper35 committed Jan 17, 2025
1 parent 03b433f commit 7e3fd69
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
7 changes: 6 additions & 1 deletion cachi2/core/package_managers/yarn_classic/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,12 @@ def _verify_no_offline_mirror_collisions(packages: Iterable[YarnClassicPackage])
c = Counter(tarballs)
duplicate_tarballs = [f"{name} ({count}x)" for name, count in c.most_common() if count > 1]
if len(duplicate_tarballs) > 0:
raise PackageManagerError(f"Duplicate tarballs detected: {', '.join(duplicate_tarballs)}")
log.warning(
"Duplicate tarballs detected in the offline mirror: %s. "
"This may lead to unexpected behavior or conflicts during package installation. "
"Ensure that each package has a unique tarball name.",
", ".join(duplicate_tarballs),
)


# References
Expand Down
28 changes: 19 additions & 9 deletions tests/unit/package_managers/yarn_classic/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ def test_verify_corepack_yarn_version_invalid_version(
_verify_corepack_yarn_version(RootedPath(tmp_path), env={"foo": "bar"})


def test_verify_offline_mirror_collisions_registry_packages() -> None:
def test_verify_offline_mirror_collisions_registry_packages(
caplog: pytest.LogCaptureFixture,
) -> None:
packages: Iterable[YarnClassicPackage] = [
RegistryPackage(
name="foo",
Expand All @@ -261,11 +263,13 @@ def test_verify_offline_mirror_collisions_registry_packages() -> None:
),
]

with pytest.raises(PackageManagerError):
_verify_no_offline_mirror_collisions(packages)
_verify_no_offline_mirror_collisions(packages)
assert "Duplicate tarballs detected in the offline mirror: same-1.0.0.tgz (2x)" in caplog.text


def test_verify_offline_mirror_collisions_scoped_registry_packages() -> None:
def test_verify_offline_mirror_collisions_scoped_registry_packages(
caplog: pytest.LogCaptureFixture,
) -> None:
packages: Iterable[YarnClassicPackage] = [
RegistryPackage(
name="foo",
Expand All @@ -279,15 +283,21 @@ def test_verify_offline_mirror_collisions_scoped_registry_packages() -> None:
),
]

with pytest.raises(PackageManagerError):
_verify_no_offline_mirror_collisions(packages)
_verify_no_offline_mirror_collisions(packages)
assert (
"Duplicate tarballs detected in the offline mirror: @colors-colors-1.6.0.tgz (2x)"
in caplog.text
)


def test_verify_offline_mirror_collisions_git_packages() -> None:
def test_verify_offline_mirror_collisions_git_packages(caplog: pytest.LogCaptureFixture) -> None:
packages: Iterable[YarnClassicPackage] = [
GitPackage(name="foo", version="1.0.0", url="https://github.com/user/repo.git#commit-hash"),
GitPackage(name="bar", version="1.0.0", url="https://github.com/user/repo.git#commit-hash"),
]

with pytest.raises(PackageManagerError):
_verify_no_offline_mirror_collisions(packages)
_verify_no_offline_mirror_collisions(packages)
assert (
"Duplicate tarballs detected in the offline mirror: repo.git-commit-hash (2x)"
in caplog.text
)

0 comments on commit 7e3fd69

Please sign in to comment.