Skip to content

Inject channels+mirrors coming from mambajs env-lockfiles#4126

Draft
Klaim wants to merge 64 commits intomamba-org:mainfrom
Klaim:env-lockfile-channels
Draft

Inject channels+mirrors coming from mambajs env-lockfiles#4126
Klaim wants to merge 64 commits intomamba-org:mainfrom
Klaim:env-lockfile-channels

Conversation

@Klaim
Copy link
Copy Markdown
Member

@Klaim Klaim commented Dec 19, 2025

Description

So far the handling of environment lockfile read package specifications from them and used that to get the packages but the channels urls specified in the lockfile were read but then ignored.

This change makes libmamba use the urls specified by lockfiles, only for mambajs for now, and put them at the top of the priority of urls to use for each channel name (could be easily changed later if necessary).

The core of the feature is located in MTransaction create_explicit_transaction_from_lockfile() (transaction.cpp), reviewers should start reading fromo

As part of that implementation:

  • inject env-lockfile channels urls in Context and ContextChannel after reading the lockfile -- this unfortunately happens after the channels has been created with other sources of information so it is a bit contrieved by the execution flow;
  • added contains standard algorithm implementation that will be replaced by the standard once available;
  • replaced the channel selection resolution by a simpler shortcut based on the channel cache in ChannelContext (see the change in trancation.cpp in MTransaction::execute. This change has the potential to be breaking although we didn't find so far an explicit issue.
  • changed the position of the publishing of json output in MTransaction::execute so that it relies on the deduced information instead of approximations pre-execution.
  • ChannelContext::make_channel now allows adding new unique mirror urls to existing channels.
  • Improved error information when failing to find package cache info.

Type of Change

  • Bugfix
  • Feature / enhancement
  • CI / Documentation
  • Maintenance

Checklist

  • My code follows the general style and conventions of the codebase, ensuring consistency
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have run pre-commit run --all locally in the source folder and confirmed that there are no linter errors.
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes

@github-actions github-actions bot added the release::enhancements For enhancements PRs or implementing features label Dec 19, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented Dec 19, 2025

Codecov Report

❌ Patch coverage is 37.19008% with 76 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.32%. Comparing base (622f328) to head (1645ec8).

Files with missing lines Patch % Lines
libmamba/src/core/transaction.cpp 10.71% 25 Missing ⚠️
libmamba/src/core/package_cache.cpp 0.00% 18 Missing ⚠️
libmamba/src/specs/channel.cpp 41.93% 18 Missing ⚠️
libmamba/include/mamba/specs/conda_url.hpp 0.00% 6 Missing ⚠️
libmamba/include/mamba/util/url.hpp 0.00% 4 Missing ⚠️
libmamba/src/api/install.cpp 0.00% 2 Missing ⚠️
libmamba/src/core/channel_context.cpp 83.33% 2 Missing ⚠️
libmamba/src/download/mirror_map.cpp 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4126      +/-   ##
==========================================
+ Coverage   52.89%   53.32%   +0.43%     
==========================================
  Files         239      240       +1     
  Lines       29172    29270      +98     
  Branches     3092     3095       +3     
==========================================
+ Hits        15430    15609     +179     
+ Misses      13739    13658      -81     
  Partials        3        3              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Klaim Klaim force-pushed the env-lockfile-channels branch from 8209f96 to 61dd997 Compare January 5, 2026 14:25
@Klaim Klaim requested review from AntoinePrv and JohanMabille and removed request for JohanMabille February 11, 2026 17:04
@Klaim Klaim marked this pull request as ready for review February 11, 2026 17:05
Comment on lines +83 to +89
// Adds mirror urls if not already recorded, by default added at the end of the mirrors
// list.
void add_mirror_urls(
const std::vector<CondaURL>& additional_mirrors,
UrlPriority priority = UrlPriority::low
);

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.

I don't have the full context here, but if possible it would be best if these could be part of ChannelParams/resolve workflow.

The general idea of specs::Channel is that with resolve you always obtain what you want, (pure functional no mutable changes). This is because currently with libsolv hacks etc, specs::Channel are rather short-lived, converted back and forth to strings. I believe functions like set_platforms are use for only local reasoning.

Comment on lines +284 to +292
// inject additional mirrors if not already existing in current channels
for (auto& channel : it->second)
{
// TODO C++23: replace all this by std::vector(from_range_t, ...)
auto urls_view = specs::as_conda_urls(mirrors);
std::vector<specs::CondaURL> urls(urls_view.begin(), urls_view.end());

channel.add_mirror_urls(urls, new_mirrors_priority);
}
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.

If this logic could be made part of ChannelParams/Channel::resolve that would avoid adding extra complexity to the channel creation logic.

@Klaim Klaim marked this pull request as draft March 16, 2026 15:48
@Klaim
Copy link
Copy Markdown
Member Author

Klaim commented Mar 16, 2026

I keep seeing issues with the tests locally but I suspect it's actually an unrelated problem, I might have to spam the ci a bit, sorry for the noise!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release::enhancements For enhancements PRs or implementing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants