refactor(core): consolidate env-override reading to the binary boundary#101
Merged
Conversation
Consolidate env-override reading to a single boundary (the binary). openvtc-core's mediator_did()/org_did() previously read OPENVTC_MEDIATOR_DID / OPENVTC_ORG_DID directly, duplicating the binary's apply_env_overrides boundary. These resolvers had no production callers (only their own unit tests) yet still touched process env, the exact split R21 targets. Parameterize both resolvers to take Option<&str> override values so core never reads process env; the binary remains the single place that reads OPENVTC_* and threads values in (apply_env_overrides in main.rs, unchanged). Tests rewritten to pass the override as a parameter, dropping the unsafe env mutation, ENV_LOCK mutex, and the module-level allow(unsafe_code). Signed-off-by: Glenn Gore <glenn.g@affinidi.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Task R21 (remediation plan, Phase R3 — structural).
Problem
Env-var overrides were read in two layers that could disagree:
openvtc-corereadOPENVTC_MEDIATOR_DID/OPENVTC_ORG_DIDdirectly insidemediator_did()/org_did(), while the binary appliedapply_env_overridespost-load.Finding & fix
The core resolvers had zero production callers (only their own unit tests) — the live override path is entirely the binary's
apply_env_overrides. So core was reading process env for override knobs in dead-but-present code (exactly the "two layers disagree" smell). Fix: both resolvers now takeoverride_did: Option<&str>(validation stays in core); the binary is the single env-reading boundary.OPENVTC_MEDIATOR_DID's live override (apply_env_overrides→set_active_mediator_did) is untouched — same name, same precedence, same startup point.OPENVTC_CONFIG_PATH(config-dir resolution, runs before anyConfigexists) stays in core — it's path bootstrap, not a loaded-config override.Bonus: removed the now-unneeded
unsafeenv mutation +ENV_LOCKmutex from the rewritten resolver tests. Gate:fmt/clippy -D warnings/test --workspacegreen (core 142).