Skip to content

Let CLI flags bootstrap config without a file or env#23

Merged
glslang merged 2 commits into
mainfrom
fix-cli-config-bootstrap
May 25, 2026
Merged

Let CLI flags bootstrap config without a file or env#23
glslang merged 2 commits into
mainfrom
fix-cli-config-bootstrap

Conversation

@glslang
Copy link
Copy Markdown
Owner

@glslang glslang commented May 25, 2026

Problem

load_config errored on a missing AGENT_NOTIFY_TOKEN before main() applied the --token/--server CLI flags. So when there was no bridge.toml and no env var, passing the flags alone could not start the bridge:

$ agent-notify-bridge --server http://host:8787 --token secret
Error: set AGENT_NOTIFY_TOKEN or create bridge.toml at one of: ...

The flags were applied only after the load already failed.

Fix

Defer the requirement check until the config layers are merged:

  • load_config returns an empty token instead of erroring when AGENT_NOTIFY_TOKEN is unset, so CLI flags can still supply it.
  • BridgeConfig::token is now #[serde(default)], so a bridge.toml may set server_url and leave the token to --token/the env var.
  • New settings::validate() checks the fully-merged config (file/env + CLI overrides) and is called from main() after the overrides are applied. A token from any layer now satisfies the requirement, and the error message lists all three sources.

Precedence is unchanged: CLI flags override the file/env base.

Tests

New unit tests in settings.rs:

  • validate accepts a complete config and rejects a blank token / blank server (with the expected messages).
  • cli_token_bootstraps_base_without_token — mirrors main(): an empty-token base (as from the env path with no AGENT_NOTIFY_TOKEN) fails, then validates once a --token override is applied.
  • read_config parses a file that omits the token (defaulted) and a fully-populated file.

cargo fmt --check, workspace clippy -D warnings, and cargo test all pass.

End-to-end: with no bridge.toml and no env vars, agent-notify-bridge --server ... --token ... --mock-display now boots into the tray + worker connect loop instead of erroring on a missing token.

🤖 Generated with Claude Code

load_config errored on a missing AGENT_NOTIFY_TOKEN before main() applied the --token/--server flags, so the flags alone could not start the bridge when no bridge.toml or env var was present.

Defer the requirement: load_config now returns an empty token instead of erroring, the token field is serde(default) so a file may omit it, and the merged config (file/env + CLI overrides) is checked by a new settings::validate() called from main(). Any single layer supplying the token is now accepted.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 25, 2026

Codecov Report

❌ Patch coverage is 82.92683% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.25%. Comparing base (f1e0685) to head (5078aa8).

Files with missing lines Patch % Lines
crates/agent-notify-bridge/src/settings.rs 83.60% 20 Missing ⚠️
crates/agent-notify-bridge/src/main.rs 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #23      +/-   ##
==========================================
+ Coverage   52.10%   58.25%   +6.14%     
==========================================
  Files           8        8              
  Lines        1023     1121      +98     
==========================================
+ Hits          533      653     +120     
+ Misses        490      468      -22     
Flag Coverage Δ
rust 58.25% <82.92%> (+6.14%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
crates/agent-notify-bridge/src/main.rs 0.00% <0.00%> (ø)
crates/agent-notify-bridge/src/settings.rs 84.50% <83.60%> (+84.50%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@glslang glslang force-pushed the fix-cli-config-bootstrap branch from 6facd75 to 746c91f Compare May 25, 2026 16:47
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6facd75dfb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/agent-notify-bridge/src/settings.rs Outdated
load_config returned early on a config file, so AGENT_NOTIFY_TOKEN was only ever read in the no-file path. A bridge.toml that set server_url but omitted the token (the common setup where the secret lives in the environment) then failed validation unless --token was passed.

Build the config in layers instead: an environment-derived base is overlaid by the file's set fields (file > env > default, per field), so an omitted token falls back to AGENT_NOTIFY_TOKEN. Extracted overlay_file as a pure function and added tests for the merge, including the file-server + env-token case.

Addresses Codex review feedback on #23.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@glslang
Copy link
Copy Markdown
Owner Author

glslang commented May 25, 2026

@cursor review

@cursor
Copy link
Copy Markdown

cursor Bot commented May 25, 2026

PR Summary

Low Risk
Local bridge client configuration and startup ordering only; no server auth or network protocol changes.

Overview
Fixes agent-notify-bridge startup when credentials come only from --server / --token (or env) without a full bridge.toml. Required checks move from load_config to a new validate in main after CLI overrides, so flags are no longer ignored by an early missing-token error.

load_config now builds config as environment base + per-field file overlay (blank/omitted file fields keep env values), instead of treating a partial file as the whole config. token in TOML is optional via #[serde(default)]; read_config no longer rejects empty tokens at parse time.

Unit tests cover validate, CLI token bootstrap, overlay precedence, and parsing files with or without a token.

Reviewed by Cursor Bugbot for commit 5078aa8. Configure here.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 5078aa8. Configure here.

@glslang glslang merged commit 0964750 into main May 25, 2026
11 checks passed
@glslang glslang deleted the fix-cli-config-bootstrap branch May 25, 2026 17:35
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