Skip to content

Add profile-based auth configuration#366

Merged
art049 merged 2 commits into
mainfrom
profiles-auth-environments
May 26, 2026
Merged

Add profile-based auth configuration#366
art049 merged 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 (32a8425) with main (4693eed)

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 token, API URL, and upload URL, replacing the previous flat single-token config. It adds profile list/show/set/use subcommands, a global --profile/CODSPEED_PROFILE flag, a v0→v1 config migration path, and a new-worktree initialization hook.

  • src/config.rs is rewritten around PersistedConfig + CodSpeedConfig::resolve_selected_profile; persist() now writes only the persisted map with no implicit sync from runtime fields, fixing the previous stale-override risks.
  • Profile commands (list, set, use) correctly load with allow_missing_profile: true so they no longer deadlock when the shell-session profile is stale.
  • src/runner_mode.rs consolidates the former runner_mode/mod.rs and runner_mode/shell_session.rs into a single flat file with no logic changes.

Confidence Score: 5/5

Safe to merge; the config rewrite is well-structured and the previously identified catch-22 and stale-override issues have been addressed in this version of the code.

The core config path cleanly separates persisted state from runtime-resolved state, and persist() writes only the persisted map. Profile subcommands correctly use allow_missing_profile=true to avoid the deadlock when the shell-session active profile no longer exists. The only finding is a documentation typo in CONTRIBUTING.md that does not affect runtime behaviour.

CONTRIBUTING.md has a typo ('prek install' → 'pre-commit install') that would block new contributors from completing setup. No source files require special attention.

Important Files Changed

Filename Overview
src/config.rs Core profile-based config: adds named profiles with per-profile auth/api_url/upload_url, migration from v0 legacy token, schema version guard, and clean persist() without sync side-effects.
src/cli/profile.rs Adds profile list/show/set/use subcommands; list() calls load_shell_session_profile() a second time instead of using config.selected_profile_name(), so the active-profile marker is never shown for the implicit default.
src/cli/auth.rs login() correctly writes token into the selected profile via profile_mut() and calls persist() which only writes persisted state; no stale-override risk.
src/cli/mod.rs Adds global --profile/CODSPEED_PROFILE flag, load_config() helper, and deprecated --config-name bridging; auth/profile commands correctly use allow_missing_profile=true.
CONTRIBUTING.md Adds Initial Setup section, but the setup command contains a typo: 'prek install' should be 'pre-commit install'.
scripts/init-worktree.sh New post-checkout hook that initialises submodules and re-installs pre-commit only when a new git worktree is being created (detected via all-zero PRE_COMMIT_FROM_REF).
.pre-commit-config.yaml Adds default_install_hook_types for post-checkout and registers the init-worktree.sh local hook.
src/runner_mode.rs Consolidates runner_mode/mod.rs and runner_mode/shell_session.rs into a single flat file; no logic changes.
src/shell_session_store.rs Adds Profile SessionKind variant and directory name; load() propagates errors via ? rather than swallowing them.

Reviews (8): 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
@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 Outdated
Copy link
Copy Markdown
Contributor

@GuillaumeLagrange GuillaumeLagrange left a comment

Choose a reason for hiding this comment

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

Olgtm, once merged I'll add/update internal instructions on how to populate the codspeed config with the various environments!

Comment thread src/cli/mod.rs Outdated
Comment thread src/config.rs
Comment thread src/shell_session_store.rs Outdated
Comment thread src/config.rs
@art049 art049 force-pushed the profiles-auth-environments branch from 4575565 to d2cd479 Compare May 26, 2026 21:04
Comment thread src/config.rs
@art049 art049 force-pushed the profiles-auth-environments branch from d2cd479 to b3a9cf7 Compare May 26, 2026 21:19
Comment thread src/cli/profile.rs
@art049 art049 force-pushed the profiles-auth-environments branch from b3a9cf7 to 0d58867 Compare May 26, 2026 21:52
Comment thread src/config.rs Outdated
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 0d58867 to 32a8425 Compare May 26, 2026 22:02
@art049 art049 merged commit ecf3c2e into main May 26, 2026
31 of 33 checks passed
@art049 art049 deleted the profiles-auth-environments branch May 26, 2026 22:13
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