Skip to content

Fix env overrides for optional scalar config values#5796

Open
preko-p wants to merge 1 commit into
DSpace:mainfrom
preko-p:aios/dspace-5279-env-overrides
Open

Fix env overrides for optional scalar config values#5796
preko-p wants to merge 1 commit into
DSpace:mainfrom
preko-p:aios/dspace-5279-env-overrides

Conversation

@preko-p
Copy link
Copy Markdown

@preko-p preko-p commented Jun 4, 2026

References

Description

Environment variable overrides only walked config keys that were already present and non-empty in the merged config object. Valid optional scalar config settings with empty or absent defaults, such as matomo.trackerUrl and rest.ssrBaseUrl, could therefore ignore their corresponding DSPACE_* environment variables unless a placeholder default was added.

This PR extracts the environment override logic into a focused helper and adds a bounded supplemental map for optional scalar config leaves that cannot be discovered by the runtime object walk.

Instructions for Reviewers

List of changes in this PR:

  • Preserves the existing recursive environment override behavior for populated scalar config leaves.
  • Adds supplemental scalar environment overrides for:
    • matomo.trackerUrl via DSPACE_MATOMO_TRACKERURL
    • rest.baseUrl via DSPACE_REST_BASEURL
    • rest.ssrBaseUrl via DSPACE_REST_SSRBASEURL
  • Keeps the existing non-convention DSPACE_REST_SSRBASEURL handling in config.server.ts for compatibility.
  • Avoids adding placeholder defaults to DefaultAppConfig.
  • Avoids reverse-parsing environment variable names.
  • Does not add array/object environment parsing.
  • Documents that future absent/empty optional scalar config leaves require an explicit supplemental-map entry.
  • Adds focused tests for:
    • derived DSPACE_* names;
    • absent and empty optional scalar overrides;
    • existing number/boolean/string conversion behavior;
    • empty environment values remaining non-overrides;
    • server-only values being stripped from client config output;
    • non-object parents not being clobbered by future supplemental entries.

Scope note: this is intentionally a scalar-only fix for optional config leaves that cannot be discovered from the runtime object shape. It does not attempt to infer TypeScript interfaces at runtime or parse arrays/objects from environment variables.

Verification performed locally with Node v22.17.1 and npm@10.9.4:

npx -y npm@10.9.4 clean-install
npx -y npm@10.9.4 run test:headless -- --include src/config/env-config-overrides.spec.ts
npx -y npm@10.9.4 run lint -- --quiet
npx -y npm@10.9.4 run check-circ-deps
git diff --check

Results:

  • Focused config override spec: 7 SUCCESS
  • Lint: 0 errors with existing repo-wide warnings
  • Circular dependency check: no circular dependencies found
  • git diff --check: no whitespace errors

Checklist

  • My PR is created against the main branch of code (unless it is a backport or is fixing an issue specific to an older branch).
  • My PR is small in size (e.g. less than 1,000 lines of code, not including comments & specs/tests), or I have provided reasons as to why that's not possible.
  • My PR passes ESLint validation using npm run lint
  • My PR doesn't introduce circular dependencies (verified via npm run check-circ-deps)
  • My PR includes TypeDoc comments for all new (or modified) public methods and classes. It also includes TypeDoc for large or complex private methods.
  • My PR includes new/updated focused specs for the changed behavior. Local verification ran the focused config spec, lint, and circular dependency check; the full suite is deferred to CI.
  • My PR aligns with Accessibility guidelines if it makes changes to the user interface.
  • My PR uses i18n (internationalization) keys instead of hardcoded English text, to allow for translations.
  • My PR includes details on how to test it. I've provided clear instructions to reviewers on how to successfully test this fix or feature.
  • If my PR includes new libraries/dependencies (in package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.
  • If my PR includes new features or configurations, I've provided basic technical documentation in the PR itself.
  • If my PR fixes an issue ticket, I've linked them together.

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.

Environment variable overrides are ignored if default setting is empty

2 participants