Skip to content

fix(cli): treat blank or whitespace-only config as unset - #218

Open
dirtybits wants to merge 1 commit into
mainfrom
fix/cli-config-blank-fallback
Open

dirtybits wants to merge 1 commit into
mainfrom
fix/cli-config-blank-fallback

Conversation

@dirtybits

Copy link
Copy Markdown
Owner

Summary

A blank or whitespace-only --base-url / --rpc-url (or the matching AGENTVOUCH_BASE_URL / AGENTVOUCH_RPC_URL / ANCHOR_PROVIDER_URL env vars) was being passed straight through as an empty string, breaking every API and RPC call in that CLI invocation.

Every CLI command routes through resolveBaseUrl / resolveRpcUrl in packages/agentvouch-cli/src/lib/config.ts. Those used an explicit || env || default chain that treats whitespace as truthy, so a value of " " short-circuited the fallback and resolved to "" instead of the protocol default.

Added a firstNonBlank helper that trims each candidate and only advances the chain when the value is empty, so blank/whitespace candidates fall through to the next candidate (env, then the protocol default). resolveBaseUrl keeps its trailing-slash normalization; resolveRpcUrl keeps its env-chain ordering.

Behavior

  • resolveBaseUrl("") / resolveBaseUrl(" ") → now https://agentvouch.xyz (was "")
  • resolveRpcUrl("") / resolveRpcUrl("\n\r\t") → now https://api.devnet.solana.com (was "")
  • Well-formed URLs with surrounding whitespace and trailing slashes are still trimmed/slash-stripped exactly as before.
  • Explicit URL still wins over env; env ordering (AGENTVOUCH_RPC_URL then ANCHOR_PROVIDER_URL) preserved.

Test plan

  • New packages/agentvouch-cli/test/config.test.ts pins fallback precedence for both resolvers (default, env, explicit, blank, whitespace-only, trailing-slash, env ordering).
  • npm run test:cli → 12 files / 67 tests all pass.
  • npm run typecheck --workspace @agentvouch/cli → clean.
  • npx prettier --check on both changed files → clean.
  • npm run build --workspace @agentvouch/cli → build success.
  • Web build intentionally out of scope (CLI-only change; no web files touched).

A blank or whitespace-only --base-url / --rpc-url (or the matching env
var) previously became an empty string, because the explicit || env ||
default chain treats whitespace as truthy. That silently broke every
subsequent API or RPC call in the invocation.

Resolve each candidate by trimming and only continue to the next one when
the value is empty, so a blank candidate falls through to the env/default
fallback. Added test/config.test.ts to pin down the fallback precedence
for both resolveBaseUrl and resolveRpcUrl.

Verified: npm run test:cli (67/67), CLI typecheck, prettier, cli build.

This branch was successfully deployed

1 active deployment
Preview — 0409fb16 Deployed Sep 29, 2026 by vercel[bot]
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