Skip to content

test: add unit tests for env-interpolator module#273

Closed
nikolasdehor wants to merge 1 commit intoSynkraAI:mainfrom
nikolasdehor:test/env-interpolator-coverage
Closed

test: add unit tests for env-interpolator module#273
nikolasdehor wants to merge 1 commit intoSynkraAI:mainfrom
nikolasdehor:test/env-interpolator-coverage

Conversation

@nikolasdehor
Copy link
Contributor

Summary

  • Add 39 unit tests for core/config/env-interpolator module
  • Cover ENV_VAR_PATTERN, interpolateString, interpolateEnvVars, and lintEnvPatterns
  • Test ${VAR} resolution, ${VAR:-default} fallback, missing var warnings, recursive object/array walks, and lint detection

Test Coverage

Function Tests
ENV_VAR_PATTERN 6
interpolateString 10
interpolateEnvVars 13
lintEnvPatterns 10
Total 39

Test Plan

  • All 39 tests passing
  • No mutations to original config objects
  • Warning collection verified for missing env vars
  • Nested object/array interpolation verified
  • Lint detection for committed env patterns verified

Closes #272

Copilot AI review requested due to automatic review settings February 18, 2026 20:03
@vercel
Copy link

vercel bot commented Feb 18, 2026

@nikolasdehor is attempting to deploy a commit to the Pedro Valério Lopez's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Feb 18, 2026

Warning

Rate limit exceeded

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

⌛ 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.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds Jest unit coverage for the .aios-core/core/config/env-interpolator module (Issue #272), validating env var interpolation behavior and lint detection for committed ${...} patterns.

Changes:

  • Introduces 39 unit tests covering ENV_VAR_PATTERN, interpolateString, interpolateEnvVars, and lintEnvPatterns.
  • Verifies ${VAR} resolution, ${VAR:-default} fallback behavior, missing-var warning collection, and recursive traversal across objects/arrays.
  • Adds linting assertions for detecting env patterns and generating path-qualified findings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +58 to +64
const originalEnv = process.env;

beforeEach(() => {
process.env = { ...originalEnv };
});

afterAll(() => {
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

In this suite, originalEnv is captured as a reference (const originalEnv = process.env) and restored in afterAll(). This is inconsistent with other test files (which snapshot via { ...process.env } and restore in afterEach()), and makes it easier for env mutations to leak if additional tests are added or if the suite is reordered. Consider snapshotting with { ...process.env } and restoring in afterEach() for better isolation.

Suggested change
const originalEnv = process.env;
beforeEach(() => {
process.env = { ...originalEnv };
});
afterAll(() => {
const originalEnv = { ...process.env };
beforeEach(() => {
process.env = { ...originalEnv };
});
afterEach(() => {

Copilot uses AI. Check for mistakes.
Comment on lines +129 to +136
const originalEnv = process.env;

beforeEach(() => {
process.env = { ...originalEnv };
});

afterAll(() => {
process.env = originalEnv;
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

Same process.env isolation issue as above: this block captures originalEnv by reference and restores only in afterAll(). Prefer const originalEnv = { ...process.env } and restore in afterEach() to match the repo’s existing test pattern and reduce cross-test leakage.

Suggested change
const originalEnv = process.env;
beforeEach(() => {
process.env = { ...originalEnv };
});
afterAll(() => {
process.env = originalEnv;
const originalEnv = { ...process.env };
beforeEach(() => {
process.env = { ...originalEnv };
});
afterEach(() => {
process.env = { ...originalEnv };

Copilot uses AI. Check for mistakes.
expect(findings[0]).toContain('key');
expect(findings[0]).toContain('${SECRET}');
});

Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

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

Because ENV_VAR_PATTERN is a global regex (/g), lintEnvPatterns() can give false negatives if ENV_VAR_PATTERN.lastIndex is non-zero before the call (e.g., after an external .exec()/.test()). There isn’t currently a test that pre-sets ENV_VAR_PATTERN.lastIndex to a non-zero value before calling lintEnvPatterns; adding one would prevent regressions and would surface the need for lintEnvPatterns() to reset lastIndex before testing.

Suggested change
test('handles non-zero ENV_VAR_PATTERN.lastIndex before lint', () => {
// Simulate prior use of the global regex that leaves a non-zero lastIndex
ENV_VAR_PATTERN.lastIndex = 5;
const findings = lintEnvPatterns({ key: '${SECRET}' }, 'config-with-lastindex.yaml');
expect(findings).toHaveLength(1);
expect(findings[0]).toContain('config-with-lastindex.yaml');
expect(findings[0]).toContain('key');
expect(findings[0]).toContain('${SECRET}');
});

Copilot uses AI. Check for mistakes.
@nikolasdehor nikolasdehor force-pushed the test/env-interpolator-coverage branch from f55167b to ea1cd5c Compare February 18, 2026 23:08
@nikolasdehor
Copy link
Contributor Author

Consolidated into #424

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.

Add unit tests for env-interpolator module

2 participants