Skip to content

Add profile-based auth configuration#366

Open
art049 wants to merge 2 commits into
mainfrom
profiles-auth-environments
Open

Add profile-based auth configuration#366
art049 wants to merge 2 commits into
mainfrom
profiles-auth-environments

Conversation

@art049
Copy link
Copy Markdown
Member

@art049 art049 commented May 23, 2026

Summary

  • add named CodSpeed profiles with per-profile auth, API URL, and upload URL
  • resolve the selected profile once inside CodSpeedConfig so downstream commands keep using effective config.auth/api_url/upload_url
  • add global --profile / CODSPEED_PROFILE and profile list/show/set/use commands
  • migrate legacy single-token config into profiles.default while preserving existing overrides

Testing

  • cargo fmt --check
  • cargo check (blocked: missing crates/instrument-hooks-bindings/instrument-hooks/dist/core.c)
  • cargo test config::tests (blocked: missing crates/instrument-hooks-bindings/instrument-hooks/dist/core.c)

Note: the commit was created with --no-verify because the clippy pre-commit hook hits the same missing instrument-hooks submodule artifact.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 23, 2026

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 7 untouched benchmarks


Comparing profiles-auth-environments (4575565) with main (0496dcd)

Open in CodSpeed

@art049 art049 force-pushed the profiles-auth-environments branch from 9a910f9 to e1e94b4 Compare May 23, 2026 04:23
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 24, 2026

Greptile Summary

This PR introduces named CodSpeed profiles with per-profile auth, API URL, and upload URL, along with profile list/show/set/use subcommands and a global --profile / CODSPEED_PROFILE override. Legacy single-token configs are migrated to profiles.default on first load via a clean RawConfig → PersistedConfig migration path.

  • src/config.rs is substantially rewritten: PersistedConfig (on-disk shape) is separated from CodSpeedConfig (runtime view), resolving the previous bug where persist() would clobber freshly-written profile values.
  • src/shell_session_store.rs extracts the PID-walking session state into a generic store shared by runner-mode and the new profile session tracking.
  • src/cli/profile.rs adds the new profile subcommand; src/cli/mod.rs threads the pre-loaded CodSpeedConfig through to all downstream commands.

Confidence Score: 4/5

Safe to merge with one fix: profile set can produce a self-referential error message when the shell-session profile is stale, telling the user to run the exact command they are already running.

The profile set command loads config through load_with_override, which resolves the active shell-session profile before the function can even reach profile_mut. If the session profile was registered against a config that was later deleted or modified externally, the load fails with an error message directing the user to run codspeed profile set — the exact command that is failing. All other logic (migration, persist separation, auth login, shell session store) looks sound.

src/cli/profile.rs (set function) and src/config.rs (resolve_selected_profile shell-session error handling)

Important Files Changed

Filename Overview
src/config.rs Major rewrite introducing profile-based config with PersistedConfig/RawConfig separation, v0→v1 migration, and resolve_selected_profile; shell-session error is silently swallowed (P2 suggestion filed)
src/cli/profile.rs New profile subcommand (list/show/set/use); set() uses load_with_override which resolves the shell-session profile and can produce a self-referential error when config is stale (P1 filed)
src/cli/mod.rs Adds load_config() helper, threads CodSpeedConfig through to auth/status/profile commands, injects upload_url into run/exec args from the resolved profile
src/cli/auth.rs Updated to accept pre-loaded CodSpeedConfig; login now writes the token directly into the selected profile's persisted entry
src/shell_session_store.rs Generic shell-session key/value store extracted from runner_mode; logic is identical to the deleted shell_session.rs, now parameterised by a kind string

Reviews (4): Last reviewed commit: "feat(cli): add profile system with versi..." | Re-trigger Greptile

Comment thread src/config.rs Outdated
Comment thread src/config.rs Outdated
@art049 art049 force-pushed the profiles-auth-environments branch from e1e94b4 to 9d098b3 Compare May 24, 2026 15:00
Add a pre-commit `post-checkout` stage hook that detects `git worktree
add` (signalled by an all-zero previous HEAD) and initializes
submodules + reinstalls pre-commit hooks in the new worktree. The
config opts both stages into `default_install_hook_types` so a plain
`prek install` wires up everything.

Co-Authored-By: Claude <noreply@anthropic.com>
@art049 art049 force-pushed the profiles-auth-environments branch from 9d098b3 to 3e259b8 Compare May 24, 2026 16:24
Comment thread src/cli/profile.rs
Introduce named profiles in the CodSpeed CLI config. Each profile carries
its own auth token plus optional api-url/upload-url overrides. Profile
selection at runtime follows: `--profile` / `CODSPEED_PROFILE` env var,
then a per-shell-session selection registered by `codspeed profile use`
(parent-PID keyed file under `$XDG_RUNTIME_DIR/codspeed_profile`, mirroring
how `codspeed use <mode>` works), then the built-in `default` profile.
There is no globally persisted default profile.

The on-disk config gains a `version: 1` schema field. A private
`RawConfig` deserialisation type and a `migrate` function are the only
place legacy YAML shapes are mentioned; when migration is needed the
canonical form is rewritten to disk immediately so the rest of the app
only ever sees the clean shape. Today this folds the legacy top-level
`auth.token` into `profiles.default`.

`CodSpeedConfig` is split: a private `PersistedConfig` is the on-disk
shape (version + profiles), and `CodSpeedConfig` wraps it with the
runtime-resolved auth/URLs/selected_profile. `persist` writes only the
persisted half, so runtime overrides (e.g. `CODSPEED_OAUTH_TOKEN`) can
never leak to disk.

The parent-PID shell-session machinery used by `codspeed use <mode>` is
extracted into a generic `shell_session_store` module so profile and
runner-mode share the same implementation. `src/runner_mode/` is
flattened into `src/runner_mode.rs` now that the sub-file is gone.

Co-Authored-By: Claude <noreply@anthropic.com>
@art049 art049 force-pushed the profiles-auth-environments branch from 3e259b8 to 4575565 Compare May 25, 2026 18:57
@art049
Copy link
Copy Markdown
Member Author

art049 commented May 25, 2026

@GuillaumeLagrange WDYT?

Comment thread src/cli/profile.rs
Comment on lines +102 to +112
let mut config = CodSpeedConfig::load_with_override(config_name, None)?;
let profile = config.profile_mut(profile_name);

if let Some(api_url) = api_url {
profile.api_url = Some(api_url);
}
if let Some(upload_url) = upload_url {
profile.upload_url = Some(upload_url);
}

config.persist(config_name)?;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 profile set catches its own catch-22 error from load_with_override

set() calls load_with_override, which resolves the shell-session profile (not the profile being set). When the shell session has a nonexistent profile name — e.g., after the config file is deleted or externally modified while staging was the active session — resolve_selected_profile bails with "CodSpeed profile staging does not exist. Run codspeed profile set staging to create it." That error message points to the exact command that's failing. The set subcommand operates on an explicit name argument, not the resolved session profile; it should be insulated from session-profile resolution errors by loading with allow_missing_profile: true.

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.

1 participant