Skip to content

fix(bridge): mock config.env in config tests to avoid local env leaks#28

Merged
y49 merged 1 commit into
mainfrom
fix/config-test-env-leak
Apr 6, 2026
Merged

fix(bridge): mock config.env in config tests to avoid local env leaks#28
y49 merged 1 commit into
mainfrom
fix/config-test-env-leak

Conversation

@y49

@y49 y49 commented Apr 6, 2026

Copy link
Copy Markdown
Owner

Summary

loadConfig() reads ~/.tlive/config.env at runtime. When a developer has a local config with TL_PORT=7849 (or any non-default value), the "uses defaults when no env vars set" test fails because the env file value overrides the expected default of 8080.

Fix: mock readFileSync to throw ENOENT for config.env paths, so tests run with pure defaults regardless of the developer's local setup.

Test plan

  • config.test.ts 7/7 pass on machine with local ~/.tlive/config.env
  • Full suite 443/443 pass

loadConfig reads ~/.tlive/config.env which can contain TL_PORT etc.,
causing the "uses defaults" test to fail on machines with a local config.
Mock readFileSync to throw ENOENT for config.env so tests use pure
defaults regardless of the developer's local setup.

@Xiaofuziod Xiaofuziod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — verified locally.

Ran into the exact same failure on macOS with a local ~/.tlive/config.env containing TL_RUNTIME=codex. The vi.mock approach correctly intercepts readFileSync and the bare catch in loadEnvFile handles it cleanly.

Confirmed:

  • 443/443 tests pass with the fix
  • The mock scope is correct (module-level, config.env paths only, other reads pass through)

@y49 y49 merged commit 42dff8f into main Apr 6, 2026
3 checks passed
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.

2 participants