@@ -176,6 +176,36 @@ def test_hook_auto_mine_legacy_env_prefix():
176176 del os .environ ["MEMPAL_HOOKS_AUTO_MINE" ]
177177
178178
179+ @pytest .mark .parametrize ("empty" , ["" , " " , "\t " , "\n " ])
180+ def test_hook_auto_mine_empty_env_falls_back_to_config (empty ):
181+ """Empty / whitespace-only env values must fall back to config, not flip to True."""
182+ tmpdir = tempfile .mkdtemp ()
183+ with open (os .path .join (tmpdir , "config.json" ), "w" ) as f :
184+ json .dump ({"hooks" : {"auto_mine" : False }}, f )
185+ os .environ ["MEMPALACE_HOOKS_AUTO_MINE" ] = empty
186+ try :
187+ cfg = MempalaceConfig (config_dir = tmpdir )
188+ assert cfg .hook_auto_mine is False
189+ finally :
190+ del os .environ ["MEMPALACE_HOOKS_AUTO_MINE" ]
191+
192+
193+ def test_hook_auto_mine_empty_primary_does_not_leak_to_legacy ():
194+ """An empty primary env var must not silently fall through to the legacy var."""
195+ tmpdir = tempfile .mkdtemp ()
196+ with open (os .path .join (tmpdir , "config.json" ), "w" ) as f :
197+ json .dump ({"hooks" : {"auto_mine" : False }}, f )
198+ os .environ ["MEMPALACE_HOOKS_AUTO_MINE" ] = ""
199+ os .environ ["MEMPAL_HOOKS_AUTO_MINE" ] = "true"
200+ try :
201+ cfg = MempalaceConfig (config_dir = tmpdir )
202+ # Primary is set (to ""), so legacy must be ignored; empty -> fall back to config.
203+ assert cfg .hook_auto_mine is False
204+ finally :
205+ del os .environ ["MEMPALACE_HOOKS_AUTO_MINE" ]
206+ del os .environ ["MEMPAL_HOOKS_AUTO_MINE" ]
207+
208+
179209# --- sanitize_name ---
180210
181211
0 commit comments