Skip to content

Commit 8ee1f36

Browse files
authored
Fix MultipleKeysError when user condarc declares auto_activate (#500)
1 parent bce0bd8 commit 8ee1f36

4 files changed

Lines changed: 78 additions & 14 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# CHANGELOG
22

3+
## [v4.0.1] (2026-04-24)
4+
5+
### Fixes
6+
7+
- Fix `MultipleKeysError` on conda 25.11+ when a user-supplied `condarc-file`
8+
already declares `auto_activate`: now only one of `auto_activate` /
9+
`auto_activate_base` is written to `.condarc`, preferring whichever key the
10+
user's existing condarc uses.
11+
- Add `auto_activate` to the boolean coercion set so its value is serialized as
12+
a YAML boolean when it is the chosen canonical key.
13+
- Add `local_repodata_ttl` to `KNOWN_CONDARC_KEYS` to silence a spurious
14+
"Unrecognized condarc key" warning for a valid conda key.
15+
16+
[v4.0.1]: https://github.com/conda-incubator/setup-miniconda/releases/tag/v4.0.1
17+
318
## [v4.0.0] (2026-04-23)
419

520
### Breaking Changes

‎dist/setup/index.js‎

Lines changed: 14 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/__tests__/conda.test.ts‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ describe("writeCondaConfig", () => {
261261
expect(config["pkgs_dirs"]).toContain("/mock/pkgs");
262262
});
263263

264-
it("sets auto_activate_base from input", async () => {
264+
it("sets auto_activate_base from input when no alias is in existing condarc", async () => {
265265
const { writeCondaConfig } = await import("../conda");
266266
const inputs = makeInputs({ channels: "conda-forge" });
267267

@@ -271,6 +271,38 @@ describe("writeCondaConfig", () => {
271271

272272
const config = getWrittenConfig();
273273
expect(config["auto_activate_base"]).toBe(false);
274+
expect(config).not.toHaveProperty("auto_activate");
275+
});
276+
277+
it("prefers auto_activate key when user condarc already contains it (avoids MultipleKeysError on conda 25.11+)", async () => {
278+
const { writeCondaConfig } = await import("../conda");
279+
const inputs = makeInputs({ channels: "conda-forge" });
280+
281+
// Simulate a user condarc that uses the new canonical key name
282+
vi.mocked(fsMod.readFileSync).mockReturnValue(
283+
yaml.dump({ auto_activate: true }),
284+
);
285+
286+
await writeCondaConfig(inputs, makeOptions());
287+
288+
const config = getWrittenConfig();
289+
expect(config).not.toHaveProperty("auto_activate_base");
290+
expect(config["auto_activate"]).toBe(false);
291+
});
292+
293+
it("uses auto_activate_base when user condarc has auto_activate_base (avoids MultipleKeysError on conda 25.11+)", async () => {
294+
const { writeCondaConfig } = await import("../conda");
295+
const inputs = makeInputs({ channels: "conda-forge" });
296+
297+
vi.mocked(fsMod.readFileSync).mockReturnValue(
298+
yaml.dump({ auto_activate_base: false }),
299+
);
300+
301+
await writeCondaConfig(inputs, makeOptions());
302+
303+
const config = getWrittenConfig();
304+
expect(config["auto_activate_base"]).toBe(false);
305+
expect(config).not.toHaveProperty("auto_activate");
274306
});
275307

276308
it("sets notify_outdated_conda to false", async () => {

‎src/conda.ts‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ const BOOLEAN_CONDARC_KEYS = new Set([
197197
"add_anaconda_token",
198198
"add_pip_as_python_dependency",
199199
"allow_softlinks",
200+
"auto_activate",
200201
"auto_activate_base",
201202
"auto_update_conda",
202203
"show_channel_urls",
@@ -223,6 +224,7 @@ const KNOWN_CONDARC_KEYS = new Set([
223224
"override_channels_enabled",
224225
"pkgs_dirs",
225226
"proxy_servers",
227+
"local_repodata_ttl",
226228
"repodata_threads",
227229
"restore_free_channel",
228230
"safety_checks",
@@ -363,15 +365,22 @@ export async function writeCondaConfig(
363365
core.info(`pkgs_dir: '${pkgsDir}'`);
364366
}
365367

366-
// --- auto_activate_base ---
367-
// Write auto_activate_base for broad compatibility. Conda 25.5.0+ also
368-
// accepts auto_activate as the canonical name, but older versions only
369-
// recognize auto_activate_base.
370-
config["auto_activate_base"] = coerceConfigValue(
371-
"auto_activate_base",
368+
// --- auto_activate / auto_activate_base ---
369+
// conda 25.11+ raises MultipleKeysError if both aliases coexist in the same
370+
// .condarc. Prefer whichever key the user already set (via condarc-file or
371+
// an existing .condarc); fall back to auto_activate_base for compatibility
372+
// with conda versions older than 25.5.0.
373+
const autoActivateKey =
374+
"auto_activate" in config && !("auto_activate_base" in config)
375+
? "auto_activate"
376+
: "auto_activate_base";
377+
delete config["auto_activate"];
378+
delete config["auto_activate_base"];
379+
config[autoActivateKey] = coerceConfigValue(
380+
autoActivateKey,
372381
inputs.condaConfig.auto_activate,
373382
);
374-
core.info(`auto_activate_base: ${config["auto_activate_base"]}`);
383+
core.info(`${autoActivateKey}: ${config[autoActivateKey]}`);
375384

376385
// --- All other config entries ---
377386
const SKIP_KEYS = new Set([

0 commit comments

Comments
 (0)