Skip to content

refactor(core): consolidate env-override reading to the binary boundary#101

Merged
stormer78 merged 2 commits into
mainfrom
refactor/r21-consolidate-env-overrides
Jun 11, 2026
Merged

refactor(core): consolidate env-override reading to the binary boundary#101
stormer78 merged 2 commits into
mainfrom
refactor/r21-consolidate-env-overrides

Conversation

@stormer78

Copy link
Copy Markdown
Contributor

Task R21 (remediation plan, Phase R3 — structural).

Problem

Env-var overrides were read in two layers that could disagree: openvtc-core read OPENVTC_MEDIATOR_DID/OPENVTC_ORG_DID directly inside mediator_did()/org_did(), while the binary applied apply_env_overrides post-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 take override_did: Option<&str> (validation stays in core); the binary is the single env-reading boundary. OPENVTC_MEDIATOR_DID's live override (apply_env_overridesset_active_mediator_did) is untouched — same name, same precedence, same startup point.

OPENVTC_CONFIG_PATH (config-dir resolution, runs before any Config exists) stays in core — it's path bootstrap, not a loaded-config override.

Bonus: removed the now-unneeded unsafe env mutation + ENV_LOCK mutex from the rewritten resolver tests. Gate: fmt/clippy -D warnings/test --workspace green (core 142).

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>
@stormer78 stormer78 requested a review from a team as a code owner June 11, 2026 12:32
@stormer78 stormer78 merged commit 058fd23 into main Jun 11, 2026
11 of 13 checks passed
@stormer78 stormer78 deleted the refactor/r21-consolidate-env-overrides branch June 11, 2026 12:43
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.

1 participant