Skip to content

Conversation

@pyramation
Copy link
Contributor

refactor(env): add env parameter injection for testability

Summary

Adds an optional env parameter to environment parsing functions in @pgpmjs/env and @constructive-io/graphql-env, enabling dependency injection for testing. This eliminates the need for fixture files and the complex snapshot/restore pattern that was previously used to isolate tests from the host environment.

Changes:

  • getEnvVars(env?) and getEnvOptions(overrides?, cwd?, env?) in @pgpmjs/env
  • getGraphQLEnvVars(env?) and getEnvOptions(overrides?, cwd?, env?) in @constructive-io/graphql-env
  • Tests now pass env objects directly instead of mutating process.env
  • Deleted __fixtures__/ directories and test-utils.ts (no longer needed)

The API is backwards compatible - all new parameters have defaults (process.env).

Review & Testing Checklist for Human

  • Snapshot change: The graphql/env snapshot now includes "provider": "minio" - this is because tests now use a clean env object, so defaults are applied. Verify this is expected behavior.
  • Downstream repos: Check if constructive-db or pgpm-modules import these functions and need updates (they shouldn't since the API is backwards compatible, but worth verifying)
  • Test data accuracy: Verify the inline test env objects match the deleted fixture file contents

Test plan: Run pnpm test in pgpm/env and graphql/env directories to verify tests pass.

Notes

  • Build passes, tests pass locally
  • The old approach required maintaining env.keys.json in sync with actual env vars read by the code - this was a maintenance burden that's now eliminated

Link to Devin run: https://app.devin.ai/sessions/dfe526b099de4d71b5f57dbbaa1e064c
Requested by: Dan Lynch (@pyramation)

- Add optional env parameter to getEnvVars() and getEnvOptions() in @pgpmjs/env
- Add optional env parameter to getGraphQLEnvVars() and getEnvOptions() in @constructive-io/graphql-env
- Refactor tests to use env injection instead of fixture-based approach
- Delete __fixtures__ directories and test-utils.ts (no longer needed)

This enables deterministic testing without mutating process.env and
eliminates the maintenance burden of keeping env.keys.json in sync
with the actual env vars read by the code.
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@pyramation pyramation merged commit 6d6364a into main Dec 31, 2025
35 checks passed
@pyramation pyramation deleted the devin/1767222821-env-injection-refactor branch December 31, 2025 23:36
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