Skip to content

fix: expand ${env:VAR} placeholders in settings#72

Merged
jdillon merged 1 commit into
mainfrom
fix/userid-variable-expansion
Mar 23, 2026
Merged

fix: expand ${env:VAR} placeholders in settings#72
jdillon merged 1 commit into
mainfrom
fix/userid-variable-expansion

Conversation

@jdillon

@jdillon jdillon commented Mar 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add resolveEnvVariables() utility that expands ${env:VAR} placeholders using process.env, matching VS Code's variable syntax from launch.json/tasks.json
  • Apply expansion to beads.userId and beads.pathToBd settings so users can use ${env:USER} or custom env vars
  • Missing env vars resolve to empty string (don't leave placeholder literal)
  • Add Jest test infrastructure (jest.config.js with ts-jest) and 8 tests covering all edge cases
  • Update setting descriptions in package.json to document ${env:VAR} support

Fixes #60

Test plan

  • Set beads.userId to ${env:USER} — verify "Assign to me" uses actual username
  • Set beads.userId to ${env:NONEXISTENT} — verify fallback to $USER
  • Set beads.pathToBd to ${env:HOME}/bin/bd — verify CLI resolves correctly
  • Set beads.userId to a plain string — verify no regression
  • Run bun run test — all 8 tests pass

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • beads.userId and beads.pathToBd configuration settings now support environment variable expansion using ${env:VAR} placeholder syntax. Missing environment variables are substituted with empty strings.
  • Documentation

    • Updated configuration property descriptions to document the environment variable placeholder expansion capability with usage examples.

…d settings

Settings like beads.userId were used verbatim without expanding VS Code-style
${env:VAR} placeholders. Adds a resolveEnvVariables utility that matches
VS Code's variable syntax and applies it when reading string settings.

Resolves: #60
Related: vsbeads-owi

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jdillon jdillon self-assigned this Mar 23, 2026
@coderabbitai

coderabbitai Bot commented Mar 23, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR implements environment variable placeholder expansion for beads.userId and beads.pathToBd configuration settings. A new utility function resolveEnvVariables scans strings for VS Code-style ${env:VAR} placeholders and replaces them with corresponding environment variable values. The feature is integrated into two configuration-reading locations, accompanied by comprehensive tests and documentation updates.

Changes

Cohort / File(s) Summary
Documentation & Configuration
CHANGELOG.md, package.json
Added changelog entry and updated VS Code configuration property descriptions to document support for ${env:VAR} placeholder expansion in beads.userId and beads.pathToBd.
Core Utility Implementation
src/utils/resolve-env-variables.ts
New exported utility function that processes strings to expand ${env:VAR} placeholders using process.env values, replacing undefined variables with empty strings.
Feature Integration
src/backend/BeadsProjectManager.ts, src/providers/BaseViewProvider.ts
Integrated resolveEnvVariables() to preprocess configured values before use: getBdPath() processes the BD path, and initializeView() processes the user ID setting.
Testing & Jest Setup
jest.config.js, src/utils/__tests__/resolve-env-variables.test.ts
Added Jest configuration file and comprehensive test suite validating placeholder expansion, multiple placeholders, missing variables, malformed inputs, and edge cases.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A carrot path, a name so true,
With ${env:VAR} magic through and through,
The beads now know where home resides,
Environment secrets, no longer hides! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: adding environment variable placeholder expansion to settings.
Linked Issues check ✅ Passed The PR fully addresses issue #60 by implementing ${env:VAR} expansion in beads.userId and beads.pathToBd with proper tests and documentation.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing env placeholder expansion. The Jest config and test infrastructure support the core feature implementation.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/userid-variable-expansion

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.

🧹 Nitpick comments (1)
jest.config.js (1)

1-9: Consider adding ESLint environment directive for CommonJS.

The static analysis flagged 'module' is not defined because this CommonJS config file runs in a context where ESLint expects ESM. This doesn't affect functionality but could be silenced.

🔧 Optional fix to silence ESLint
 /** `@type` {import('jest').Config} */
+/* eslint-env node */
 module.exports = {

Alternatively, you could rename to jest.config.cjs to make the CommonJS format explicit, but jest.config.js is the conventional name.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@jest.config.js` around lines 1 - 9, The ESLint warning is because the
CommonJS usage (module.exports) in jest.config.js is being linted as ESM; add an
ESLint environment directive for CommonJS at the top of the file (e.g., add a
line declaring the commonjs env) so ESLint recognizes module.exports, or
alternatively rename the file to jest.config.cjs to make the CommonJS format
explicit; ensure the change targets the module.exports export in this file.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@jest.config.js`:
- Around line 1-9: The ESLint warning is because the CommonJS usage
(module.exports) in jest.config.js is being linted as ESM; add an ESLint
environment directive for CommonJS at the top of the file (e.g., add a line
declaring the commonjs env) so ESLint recognizes module.exports, or
alternatively rename the file to jest.config.cjs to make the CommonJS format
explicit; ensure the change targets the module.exports export in this file.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 88d5cd05-ca0b-4131-80a1-c00180b1b575

📥 Commits

Reviewing files that changed from the base of the PR and between 797ef48 and e3b8659.

📒 Files selected for processing (7)
  • CHANGELOG.md
  • jest.config.js
  • package.json
  • src/backend/BeadsProjectManager.ts
  • src/providers/BaseViewProvider.ts
  • src/utils/__tests__/resolve-env-variables.test.ts
  • src/utils/resolve-env-variables.ts

@jdillon jdillon merged commit 9374e76 into main Mar 23, 2026
2 checks passed
@jdillon jdillon deleted the fix/userid-variable-expansion branch March 23, 2026 21:54
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.

beads.userId does not expand placeholders

1 participant