Skip to content

refactor!: back pixi's Config by rattler_config's ConfigBase<PixiConfig>#6531

Draft
wolfv wants to merge 3 commits into
mainfrom
claude/rattler-shared-config-design-m8d2gb
Draft

refactor!: back pixi's Config by rattler_config's ConfigBase<PixiConfig>#6531
wolfv wants to merge 3 commits into
mainfrom
claude/rattler-shared-config-design-m8d2gb

Conversation

@wolfv

@wolfv wolfv commented Jul 6, 2026

Copy link
Copy Markdown
Member

Description

Follow-up to #6528 (which merged the leaf-type migration from #6144). This PR contains the two commits that were pushed to the branch just after #6528 was merged and therefore never showed up there: the final form of the shared-config design, plus a compatibility test catalog.

Commit 1 — the final form (requires unreleased rattler_config 0.6, see below). pixi_config::Config is no longer a parallel struct — it is a #[serde(transparent)] wrapper around rattler_config::ConfigBase<PixiConfig> (net −630 lines):

  • PixiConfig is the tool extension the design was made for: pinning-strategy, pypi-config, detached-environments, shell, experimental, tool-platform, cache, and the deprecated change-ps1/force-activate — all with their original serde attributes, so the on-disk format is unchanged. All shared keys come from upstream CommonConfig (reached via Deref, so config.mirrors etc. keep working).
  • tls_root_certs and the allow-*-links trio are promoted upstream (the follow-ups flagged in refactor: switch to rattler_config #6144). Legacy "native"/"all" spellings keep parsing (upstream aliases) and keep their deprecation warnings.
  • Extensibility proof points, all verified live:
    • Unknown-key warnings survive the extension mechanism (the thing #[serde(flatten)] used to break): pixi config list warns Ignoring 'pinning-strateggy, shell.chnge-ps1' in …/config.toml — typos in extension keys and keys nested in known tables are both caught.
    • pixi config set delegates to the upstream generic editor: pixi config set pinning-strategy semver (an extension key) works with zero per-key code; the old ~400-line set match is deleted, keeping only 3 pixi-specific special cases (deprecated-key hard errors with identical error text, detached-environments bool/path parsing, cache.* expand+validate side effects).
    • test_config_merge_multiple now passes with HTTPS_PROXY set — the upstream fix for ProxyConfig::default() leaking the environment into saved configs, proven from pixi's own test suite.

Commit 2 — compatibility test catalog (mirrors the one added to rattler_config in conda/rattler#2557), so future changes can't silently break existing user configs:

  • 5 fixtures: canonical kitchen sink (every shared + extension key), snake_case aliases, a realistic legacy pre-0.40 config (change-ps1, force-activate, tls-root-certs = "native", boolean detached-environments, removed disable-jlap — must parse with warnings, never hard errors), typos (top-level and nested), and a merge override layer.
  • Round-trip losslessness + idempotence, a 42-entry edit matrix through the public Config::set (all shared families plus every pixi extension key, incl. all three detached-environments forms and all 9 cache.* keys) with set+unset restoring defaults, and snapshotted merge semantics (the tool-platform lower-layer-wins quirk is pinned deliberately with a comment).
  • The catalog independently re-caught the repodata merge-direction bug that the rattler-side catalog found (none of the 55 pre-existing unit tests had ever noticed it); the git pin is bumped to the fixed rattler commit.

⚠️ Merge dependency — draft until rattler_config 0.6 is released

This PR carries a [patch.crates-io] section pointing the rattler crates at the branch of conda/rattler#2557 (marked TODO: remove once rattler_config 0.6 is released). Once that releases, the patch section is dropped and versions bumped, and this becomes mergeable.

Intentional small behavior changes (all documented in the commit messages): mirrors is an IndexMap (order-preserving); empty default-channels = [] normalizes to unset; s3-options.<bucket>.<field> on a nonexistent bucket now errors instead of silently no-oping; a latent bug where set("concurrency", …) wrote pypi_config is fixed by the generic path; re-saving a config with legacy "native"/"all" writes canonical "system".

How Has This Been Tested?

  • cargo check --workspace --all-targets passes; clippy clean on all touched crates; cargo fmt --check clean.
  • pixi_config: 55 unit + 9 compat tests pass both with and without proxy env vars set (re-verified after rebasing onto the merged refactor: use shared config types from rattler_config #6528); pixi_utils: 72 passed (TLS enum promotion).
  • Live CLI verification of the proof points above (pixi config list warnings, pixi config set on extension keys and typos).
  • cargo tree -i rattler_conda_types confirms a single (git) copy of every rattler crate under the patch.

AI Disclosure

  • This PR contains AI-generated content.
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR.

Tools: Claude Code

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added sufficient tests to cover my changes.
  • I have verified that changes that would impact the JSON schema have been made in schema/model.py (no schema impact — serialized config format unchanged)

Generated by Claude Code

claude added 2 commits July 6, 2026 08:41
pixi's `Config` is no longer a parallel struct that duplicates the shared
rattler configuration keys: it is now a thin `#[serde(transparent)]`
wrapper around `rattler_config::config::ConfigBase<PixiConfig>` from the
redesigned (unreleased) rattler_config, where `PixiConfig` is pixi's
tool-specific extension. This proves out the shared-config extension
mechanism end to end.

What moved where:

- Shared keys (default-channels, authentication-override-file,
  tls-no-verify, tls-root-certs, mirrors, build, channel-config,
  repodata-config, concurrency, proxy-config, s3-options, index-config,
  run-post-link-scripts, allow-symbolic/hard/ref-links, loaded_from) now
  live in the upstream `CommonConfig` / `ConfigBase` and are reached
  through `Deref` (`config.mirrors`, `config.concurrency`, ...).
- Pixi-specific keys (pinning-strategy, pypi-config,
  detached-environments, shell, experimental, tool-platform, cache, and
  the deprecated change-ps1/force-activate) moved into the new
  `PixiConfig` extension (`config.extensions.*`), with all serde
  attributes (kebab-case, snake_case aliases, skip_serializing_if
  guards) carried over so the on-disk TOML format is unchanged. New
  accessors `shell()`, `experimental()`, `cache()`, `pinning_strategy()`
  keep call sites terse; existing accessors keep their signatures.
- `tls_root_certs` is promoted to the upstream
  `rattler_config::config::tls::TlsRootCerts` (Webpki/System). The
  legacy "native"/"all" spellings deserialize as aliases of System, and
  pixi keeps its load-time deprecation warnings by inspecting the raw
  TOML document (`Config::from_toml`) and via a clap value parser for
  `--tls-root-certs` / `PIXI_TLS_ROOT_CERTS`. pixi_utils' feature-aware
  fallback logic (native-tls vs rustls) is unchanged; the
  LegacyNative/All match arms collapse into System.
- allow-symbolic-links/allow-hard-links/allow-ref-links use the
  upstream CommonConfig fields (same flat key names, same format).

Extensibility proof points (each covered by tests):

- `Config::from_toml` uses `ConfigBase::<PixiConfig>::from_toml_str`,
  whose two-pass serde_ignored deserialization reports keys unknown to
  BOTH the common config and the extension, so the "Ignoring '...' in
  file" warnings keep working — including for typos of extension keys
  (`pinning-strateggy`) and unknown keys nested in known tables
  (`shell.chnge-ps1`, `pypi-config.index-urll`). New test:
  test_from_toml_reports_unknown_extension_keys.
- `Config::set` now special-cases only the deprecated
  change-ps1/force-activate hard errors, detached-environments
  bool/path parsing (~-expansion), and the cache.* re-validation; the
  former ~400-line match is deleted and everything else — including
  extension keys like `pinning-strategy` — delegates to the upstream
  generic `ConfigBase::set` (TOML round-trip editor). Unknown keys
  produce an error listing all supported keys (shared + extension) from
  the `Config` trait's `keys()`. New test:
  test_generic_set_handles_extension_keys; also verified against the
  built CLI: `pixi config set pinning-strategy semver` writes
  `pinning-strategy = "semver"`.
- `ProxyConfig::default()` no longer reads proxy env vars upstream, so
  pixi_config's tests are hermetic: the whole suite (including
  test_config_merge_multiple) now passes with and without
  HTTPS_PROXY/HTTP_PROXY set.

Dependency patching: a `[patch.crates-io]` block redirects every rattler
crate pixi consumes to the `claude/rattler-shared-config-design-m8d2gb`
branch of conda/rattler (single copy of each crate, verified with
`cargo tree -i rattler_conda_types`). TODO: remove once rattler_config
0.6 is released (see conda/rattler#2557) — this PR must not merge until
then.

Behavior changes (intentional, small):

- `default_channels` is `Option<Vec<NamedChannelOrUrl>>` upstream;
  `Config::default_channels()` keeps returning the configured list or
  the consts::DEFAULT_CHANNELS fallback, and from_toml normalizes an
  explicitly empty list to None to preserve the old merge semantics.
- `mirrors` is an `IndexMap` (was HashMap): deterministic ordering;
  `mirror_map()` signature updated.
- `loaded_from` now lists files in load order (lowest precedence
  first); it previously listed them in reverse.
- Editing a subkey of a non-existent s3-options bucket used to be a
  silent no-op; the generic editor rejects it (S3Options requires all
  three fields). Setting the whole bucket first works as before.
- `pixi config set concurrency '<json>'` used to (buggily) write
  pypi-config; the generic editor handles it correctly.
- PyPIConfig::is_default now also checks allow-insecure-host, so a
  pypi-config containing only allow-insecure-host is no longer dropped
  on save.
- A file containing `tls-root-certs = "native"`/`"all"` still loads
  (with the same deprecation warning), but re-saving it writes the
  canonical `"system"`.

Snapshot diff (config_merge_multiple): Debug output is now nested as
ConfigBase { common, extensions, loaded_from }; default_channels prints
as Some([...]); the (empty, serde-skipped) upstream index_config section
appears; loaded_from order flipped as described above. All values are
identical to the old snapshot.

Tests: cargo test -p pixi_config (55 passed, with and without proxy
env), cargo test -p pixi_utils (72 passed), cargo check --workspace
--all-targets, cargo clippy -p pixi_config/pixi_utils/pixi_cli/
pixi_core/pixi_api/pixi_uv_context --all-targets clean, cargo fmt.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EzYs4p6XJDj9QBcNB4ipR7
… schema

The pixi-side mirror of rattler_config's tests/compat.rs: that catalog
pins the contract of the shared keys; this one pins the whole pixi
schema (shared CommonConfig keys plus the PixiConfig extension) so
upgrading the shared config crate can never silently break a user's
existing config.toml.

New: crates/pixi_config/tests/compat.rs + test-data/compat/ fixtures
(kitchen-sink, snake-case-aliases, legacy-config, typos,
override-layer) + insta snapshots.

Coverage:

1. Parsing permutations — every fixture parses; (unused keys, parsed
   Config) snapshotted per fixture (channel_config.root_dir normalized
   so snapshots are machine-independent). snake_case aliases parse
   equal to canonical with zero warnings; a realistic old pixi config
   (change-ps1, force-activate, tls-root-certs = "native",
   detached-environments = true, repodata-config.disable-jlap) loads
   with warnings only, and the deprecated values still take effect
   through the modern accessors (change_ps1()/force_activate() see the
   folded shell.* values, "native" resolves to the system store);
   typos of shared AND extension keys, top-level and nested, are all
   reported as unused while valid neighbors survive.
2. Round-trip stability — load -> to_toml -> load is lossless and
   idempotent for all five fixtures (including the legacy one: the
   deprecated keys re-serialize and re-fold identically), and
   serialization never invents unknown keys.
3. Editing matrix — 42 entries through the public Config::set (the
   `pixi config set` code path): every shared key family plus
   pinning-strategy, detached-environments (true/false/path),
   tool-platform, pypi-config.*, shell.*,
   experimental.use-environment-activation-cache and all cache.* keys
   (absolute paths, since set re-validates). Each entry: set succeeds
   on a fully populated config, the result round-trips, and set+unset
   on a pristine config restores the default. Deprecated
   change-ps1/force-activate stay hard errors pointing at shell.*, and
   unknown keys (shared and extension typos) are rejected in both set
   and unset direction.
4. Merge semantics — kitchen-sink + override layer through
   Config::merge_config: scalars replace, mirrors/s3-options extend,
   repodata merges field-wise (default and per-channel), pypi
   index-url replaces while extra-index-urls/allow-insecure-host
   extend, shell/experimental/cache merge field-wise, and the
   long-standing tool-platform LOWER-layer-wins quirk is pinned with a
   comment so changing it becomes a conscious decision. Merged output
   snapshotted.

The catalog immediately caught a real bug: the pinned rattler commit
(33a4909) still had the repodata merge direction inverted (the lower
layer's disable-bzip2 survived an override). conda/rattler already
fixed this on the same branch in 5ded1a9 ("fix repodata merge
direction") — this commit bumps Cargo.lock to that rev, which makes
the merge test pass. None of the pre-existing pixi tests noticed the
inverted direction, which is exactly the gap this catalog closes.

Tests: cargo test -p pixi_config (55 unit + 9 compat) passes both with
proxy env scrubbed and with HTTPS_PROXY/HTTP_PROXY set; cargo check
--workspace --all-targets; clippy clean on pixi_config; cargo fmt.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EzYs4p6XJDj9QBcNB4ipR7
@wolfv wolfv changed the title refactor!: back pixi's Config by rattler_config's ConfigBase&lt;PixiConfig&gt; refactor!: back pixi's Config by rattler_config's ConfigBase<PixiConfig> Jul 6, 2026
The parse snapshots embedded the concurrency.solves default, which is
the local CPU count, so fixtures that don't set [concurrency] (e.g.
snake-case-aliases.toml) produced snapshots that only passed on the
machine that generated them. Normalize solves unconditionally in the
snapshot helper — a conditional "only when equal to the default" would
flip whenever an explicitly configured value happens to match the CPU
count — and assert the explicitly configured values in code instead,
where they are deterministic. Verified by running the suite pinned to a
different CPU count (taskset). Same fix applied to the rattler_config
catalog upstream (conda/rattler#2557).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EzYs4p6XJDj9QBcNB4ipR7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants