Skip to content

fix(backend): rename BRAVE_API_KEY → SERPER_API_KEY across config and routes#185

Open
leocagli wants to merge 1 commit into
Stellar-Ecosystem:mainfrom
leocagli:fix/serper-api-key-rename
Open

fix(backend): rename BRAVE_API_KEY → SERPER_API_KEY across config and routes#185
leocagli wants to merge 1 commit into
Stellar-Ecosystem:mainfrom
leocagli:fix/serper-api-key-rename

Conversation

@leocagli

@leocagli leocagli commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Fixes #16

Problem

/demo/search calls the Serper API (https://google.serper.dev/search) but the env var was named BRAVE_API_KEY — a leftover from a previous Brave Search integration. The .env.example had BRAVE_API_KEY=your_serper_api_key which is contradictory and confusing for anyone setting up the project.

Changes

File Change
backend/.env.example BRAVE_API_KEYSERPER_API_KEY
backend/src/config.js braveApiKey: process.env.BRAVE_API_KEYserperApiKey: process.env.SERPER_API_KEY
backend/src/routes/services.js config.braveApiKeyconfig.serperApiKey

No behaviour change — only the env var name and config property key change.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Updated search service backend configuration.

Closes Stellar-Ecosystem#16

The /demo/search route calls google.serper.dev but the env var and config
key were named BRAVE_API_KEY / braveApiKey — a holdover from an earlier
implementation that confuses operators and makes the .env.example example
value misleading.

Rename across all three files:
- backend/.env.example: BRAVE_API_KEY → SERPER_API_KEY
- backend/src/config.js: braveApiKey → serperApiKey
- backend/src/routes/services.js: config.braveApiKey → config.serperApiKey

No behaviour change — only the env var name and config property key change.
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Three files are updated to rename the Serper API key identifier from BRAVE_API_KEY/braveApiKey to SERPER_API_KEY/serperApiKey: the .env.example placeholder, the frozen config object, and the X-API-KEY header in the /demo/search route.

Changes

Serper API Key Rename

Layer / File(s) Summary
SERPER_API_KEY env, config, and route header
backend/.env.example, backend/src/config.js, backend/src/routes/services.js
Renames the env placeholder from BRAVE_API_KEY to SERPER_API_KEY, updates the config field from braveApiKey to serperApiKey, and switches the outbound X-API-KEY header source to config.serperApiKey.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐇 A key by the wrong name won't open the door,
So I hopped through the config and fixed every floor.
BRAVE was a misnomer — SERPER is true,
Three lines in the warren, all tidy and new.
sniff sniff — the API smells right now! 🗝️

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The PR implements the core requirement from issue #16 to rename BRAVE_API_KEY to SERPER_API_KEY across config files and routes, improving API naming clarity. Verify that automated test coverage exists for the /demo/search route as required by issue #16 acceptance criteria, and confirm failure cases return actionable responses.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: renaming BRAVE_API_KEY to SERPER_API_KEY across backend configuration and routes to fix a naming inconsistency.
Out of Scope Changes check ✅ Passed All changes are directly related to the naming inconsistency fix described in issue #16; no unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/.env.example`:
- Line 24: The README.md contains outdated documentation that references
BRAVE_API_KEY in the setup instructions, but the actual environment variable
name used throughout the application is SERPER_API_KEY. Update the README.md
setup section to replace all references to BRAVE_API_KEY with SERPER_API_KEY to
align with what is defined in backend/.env.example and used in
backend/src/config.js, ensuring users can correctly configure their environment.

In `@backend/src/config.js`:
- Line 81: The config field has been renamed from braveApiKey to serperApiKey,
but test mock objects in the contract and agents test files still reference the
old field name. Update the mock objects in both test files by replacing all
instances of braveApiKey: '' with serperApiKey: '' to align with the updated
config property name and ensure tests pass with the new configuration structure.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9dbfe8fe-32c7-4830-b289-c6aaa5c2b873

📥 Commits

Reviewing files that changed from the base of the PR and between 6fb6da9 and f2d7a06.

📒 Files selected for processing (3)
  • backend/.env.example
  • backend/src/config.js
  • backend/src/routes/services.js

Comment thread backend/.env.example
SEARCH_PRICE=0.001
WEATHER_PRICE=0.001
BRAVE_API_KEY=your_serper_api_key
SERPER_API_KEY=your_serper_api_key

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Find all references to BRAVE_API_KEY in documentation and config files

# Search for BRAVE_API_KEY references
rg -n 'BRAVE_API_KEY' --type=md --type=txt -g '!*.example'

# Also check for braveApiKey in documentation
rg -n 'braveApiKey' --type=md --type=txt

Repository: Stellar-Ecosystem/lodestar

Length of output: 168


🏁 Script executed:

# Get the README.md content around the mentioned lines
cat -n README.md | sed -n '120,135p'

Repository: Stellar-Ecosystem/lodestar

Length of output: 466


🏁 Script executed:

# Search more broadly for all BRAVE_API_KEY references
rg -n 'BRAVE_API_KEY' -g '!*.example'

Repository: Stellar-Ecosystem/lodestar

Length of output: 168


🏁 Script executed:

# Verify that SERPER_API_KEY is the actual replacement
rg -n 'SERPER_API_KEY' -B2 -A2

Repository: Stellar-Ecosystem/lodestar

Length of output: 290


Update README.md line 130 to reference SERPER_API_KEY instead of BRAVE_API_KEY.

The setup instructions reference the outdated BRAVE_API_KEY, but the actual environment variable is SERPER_API_KEY (defined in backend/.env.example and used in backend/src/config.js). Users following the README will be unable to configure the application correctly.

🧰 Tools
🪛 dotenv-linter (4.0.0)

[warning] 24-24: [UnorderedKey] The SERPER_API_KEY key should go before the WEATHER_PRICE key

(UnorderedKey)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/.env.example` at line 24, The README.md contains outdated
documentation that references BRAVE_API_KEY in the setup instructions, but the
actual environment variable name used throughout the application is
SERPER_API_KEY. Update the README.md setup section to replace all references to
BRAVE_API_KEY with SERPER_API_KEY to align with what is defined in
backend/.env.example and used in backend/src/config.js, ensuring users can
correctly configure their environment.

Comment thread backend/src/config.js
},

braveApiKey: process.env.BRAVE_API_KEY ?? '',
serperApiKey: process.env.SERPER_API_KEY ?? '',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Find test files that reference braveApiKey and need updating

# Search for braveApiKey in test files
rg -n 'braveApiKey' --type=js --glob='*test*' --glob='*spec*'

# Also check for any other JavaScript files that may reference it
rg -n 'braveApiKey' --type=js -g '!node_modules'

Repository: Stellar-Ecosystem/lodestar

Length of output: 298


🏁 Script executed:

# Check for braveApiKey in non-test files to see if this is a complete refactoring
rg -n 'braveApiKey' --type=js --glob='!*test*' --glob='!*spec*' -g '!node_modules'

Repository: Stellar-Ecosystem/lodestar

Length of output: 52


🏁 Script executed:

# Examine the test files to see the exact context of the mocks that need updating
head -20 backend/src/lib/contract.test.js | tail -15

Repository: Stellar-Ecosystem/lodestar

Length of output: 569


🏁 Script executed:

head -40 backend/src/routes/agents.test.js | tail -10

Repository: Stellar-Ecosystem/lodestar

Length of output: 526


🏁 Script executed:

# Verify the config.js file shows the renamed field
cat -n backend/src/config.js | head -85 | tail -10

Repository: Stellar-Ecosystem/lodestar

Length of output: 489


Update test mocks to use the renamed config field.

The config field has been renamed from braveApiKey to serperApiKey, but test mocks still reference the old name. Update the following locations:

  • backend/src/lib/contract.test.js:9
  • backend/src/routes/agents.test.js:36

Change braveApiKey: '' to serperApiKey: '' in both test mock objects. Tests will fail without these updates.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/src/config.js` at line 81, The config field has been renamed from
braveApiKey to serperApiKey, but test mock objects in the contract and agents
test files still reference the old field name. Update the mock objects in both
test files by replacing all instances of braveApiKey: '' with serperApiKey: ''
to align with the updated config property name and ensure tests pass with the
new configuration structure.

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.

Fix hardcoded Brave Search API header against Serper endpoint in /demo/search

1 participant