fix(clients): hermetic tests ignore .env.json.local unless MOLO_LIVE_NET is set

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-24 04:46:35 +02:00
co-authored by Claude Sonnet 5.5
parent 5a54982339
commit d92baa5de5
4 changed files with 10 additions and 2 deletions
+1 -1
View File
@@ -117,7 +117,7 @@ example-test: example
b=$(EXAMPLE_BUILD)/tests/$$n; \
if $(CXX) $(EXAMPLE_CXXFLAGS) -I$(EXAMPLE_DIR) -I$(EXAMPLE_TESTDIR) -Isrc \
$$t $(EXAMPLE_BUILD)/libexample.a $(EXAMPLE_REAL_LIBS) -lwolfssl -o $$b > $$b.log 2>&1; \
then $$b >> $$b.log 2>&1; else echo "COMPILE FAILED: $$t" >> $$b.log; false; fi; \
then MOLO_ENV_FILES=off $$b >> $$b.log 2>&1; else echo "COMPILE FAILED: $$t" >> $$b.log; false; fi; \
echo $$? > $$b.rc' < $(EXAMPLE_BUILD)/tests/list.txt
pass=0; fail=0; \
for l in `ls $(EXAMPLE_BUILD)/tests/*.log | sort`; do \
+3
View File
@@ -58,6 +58,9 @@ client, credentials, errors, or caps.
APIs that refuse keys) use the same seam: `Credentials::bearer`; a
`GOOGLE_ACCESS_TOKEN` (same lookup order) takes precedence over a key.
Tokens expire after about an hour; refresh is the caller's job (gap).
- Test runs set `MOLO_ENV_FILES=off`: config files are ignored so a developer's
`.env.json.local` cannot change test outcomes. `MOLO_LIVE_NET=1` re-enables
them for the opt-in live checks.
- No key: `configured()` is false and every call throws `NotConfiguredError`
(HTTP 503, status `NOT_CONFIGURED`) before any network traffic. Loud, not
silent.
+5
View File
@@ -43,6 +43,11 @@ std::string from_json_file(const char* path, const char* name) {
// secrets), then .env.json, both in the working directory.
std::string Credentials::env(const char* name) {
if (const char* v = std::getenv(name); v && *v) return v;
// Test runs set MOLO_ENV_FILES=off so a developer's .env.json.local never
// leaks into hermetic tests; opt-in live runs (MOLO_LIVE_NET) need it.
const char* files = std::getenv("MOLO_ENV_FILES");
if (files && std::string(files) == "off" && !std::getenv("MOLO_LIVE_NET"))
return "";
std::string local = from_json_file(".env.json.local", name);
if (!local.empty()) return local;
return from_json_file(".env.json", name);
+1 -1
View File
@@ -48,7 +48,7 @@ $(GOOGLE_LIB): $(GOOGLE_OBJS)
# The clients test harness (framework.h plus main.cpp) is reused, not copied.
google-test: $(GOOGLE_TEST_BIN)
$(GOOGLE_TEST_BIN)
MOLO_ENV_FILES=off $(GOOGLE_TEST_BIN)
$(GOOGLE_TEST_BIN): $(GOOGLE_OBJS) $(GOOGLE_TEST_SRCS) $(CLIENTS_LIB) $(OPERABILITY_LIB) $(ROOT)/tests/src/clients/main.cpp
@mkdir -p $(dir $@)