Skip to content

feat: resolve ${env('...')} variables in cloud build yaml before parsing#155

Open
mozhou52 wants to merge 1 commit into
masterfrom
build-runit
Open

feat: resolve ${env('...')} variables in cloud build yaml before parsing#155
mozhou52 wants to merge 1 commit into
masterfrom
build-runit

Conversation

@mozhou52
Copy link
Copy Markdown
Collaborator

@mozhou52 mozhou52 commented May 21, 2026

Summary by CodeRabbit

  • New Features
    • Build configuration files now support environment variable substitution using ${env('VAR')} syntax. Variables are automatically resolved during the build process, with error handling for missing variables.

Review Change Stack

@mozhou52 mozhou52 requested a review from rsonghuster May 21, 2026 07:09
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

Warning

Rate limit exceeded

@mozhou52 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 58 minutes and 7 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b4974af2-736f-441b-853b-c479bb720e41

📥 Commits

Reviewing files that changed from the base of the PR and between 417a801 and 1639d2d.

📒 Files selected for processing (2)
  • __tests__/ut/commands/build_test.ts
  • src/subCommands/build/index.ts
📝 Walkthrough

Walkthrough

The PR adds environment variable substitution to the build YAML loading process. A new resolveEnvVariables function replaces ${env('VAR')} patterns with process.env values and is applied before YAML parsing. Comprehensive tests validate single and multiple substitutions, missing variable error handling, and idempotent behavior when no variables are present.

Changes

Environment Variable Resolution

Layer / File(s) Summary
resolveEnvVariables implementation and integration
src/subCommands/build/index.ts
New resolveEnvVariables function scans YAML text for ${env('...')} patterns and substitutes them with process.env values, throwing when a referenced variable is undefined. Integrated into BuilderFactory.runit() to resolve variables before YAML parsing.
resolveEnvVariables test coverage
__tests__/ut/commands/build_test.ts
Import and test suite for resolveEnvVariables covering single and double-quoted syntax, multiple substitutions, missing variable error handling, and no-op behavior.

Sequence Diagram

sequenceDiagram
  participant BuilderFactory
  participant resolveEnvVariables
  participant yaml
  participant process.env
  BuilderFactory->>BuilderFactory: read fc3-cloud-build.yaml content
  BuilderFactory->>resolveEnvVariables: pass content
  resolveEnvVariables->>process.env: lookup env variables
  resolveEnvVariables-->>BuilderFactory: return resolved content
  BuilderFactory->>yaml: parse resolved content
  yaml-->>BuilderFactory: return parsed config
Loading

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A dash of ${env} in the YAML brew,
Where rabbits now substitute what's true—
Build configs dance with process winds,
No more hardcoded secrets pinned.
Tests confirm each pattern's flight! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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: adding environment variable resolution for ${env('...')} syntax in the cloud build YAML file before parsing.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch build-runit

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
__tests__/ut/commands/build_test.ts (1)

306-341: ⚡ Quick win

Isolate process.env mutations per test to avoid leakage.

Line 308 onward mutates global env and cleans up inline; if a test fails before cleanup, later tests can become flaky. Snapshot/restore env in hooks for deterministic isolation.

Suggested patch
 describe('BuilderFactory', () => {
   let mockInputs: IInputs;
+  let originalEnv: NodeJS.ProcessEnv;

   beforeEach(() => {
+    originalEnv = { ...process.env };
     mockInputs = {
       cwd: '/test',
@@
   afterEach(() => {
+    process.env = originalEnv;
     jest.clearAllMocks();
   });
@@
   describe('resolveEnvVariables', () => {
     it('should replace env variables with single quotes', () => {
       process.env.MY_VAR = 'hello';
       const result = resolveEnvVariables('value: ${env(\'MY_VAR\')}');
       expect(result).toBe('value: hello');
-      delete process.env.MY_VAR;
     });
@@
     it('should replace env variables with double quotes', () => {
       process.env.MY_VAR = 'world';
       const result = resolveEnvVariables('value: ${env("MY_VAR")}');
       expect(result).toBe('value: world');
-      delete process.env.MY_VAR;
     });
@@
     it('should replace multiple env variables', () => {
       process.env.USERNAME = 'admin';
       process.env.PASSWORD = 'secret';
       const result = resolveEnvVariables('username: ${env(\'USERNAME\')}\npassword: ${env(\'PASSWORD\')}');
       expect(result).toBe('username: admin\npassword: secret');
-      delete process.env.USERNAME;
-      delete process.env.PASSWORD;
     });
🤖 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 `@__tests__/ut/commands/build_test.ts` around lines 306 - 341, The tests in the
resolveEnvVariables suite mutate process.env directly which can leak between
tests; wrap the describe('resolveEnvVariables') block with a beforeEach that
saves a shallow copy of process.env (e.g., const ORIGINAL_ENV = { ...process.env
}) and an afterEach that restores it (process.env = ORIGINAL_ENV) so each test
runs with an isolated env; update the tests that currently set/delete env vars
to rely on this snapshot/restore and remove inline cleanup to avoid flaky
failures if a test throws.
🤖 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.

Nitpick comments:
In `@__tests__/ut/commands/build_test.ts`:
- Around line 306-341: The tests in the resolveEnvVariables suite mutate
process.env directly which can leak between tests; wrap the
describe('resolveEnvVariables') block with a beforeEach that saves a shallow
copy of process.env (e.g., const ORIGINAL_ENV = { ...process.env }) and an
afterEach that restores it (process.env = ORIGINAL_ENV) so each test runs with
an isolated env; update the tests that currently set/delete env vars to rely on
this snapshot/restore and remove inline cleanup to avoid flaky failures if a
test throws.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8069c1c1-dc96-41a1-9345-b790e3ae3eff

📥 Commits

Reviewing files that changed from the base of the PR and between 6e5c531 and 417a801.

📒 Files selected for processing (2)
  • __tests__/ut/commands/build_test.ts
  • src/subCommands/build/index.ts

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