From 063458d9a9114505261c68d24950c7dcf0591cd9 Mon Sep 17 00:00:00 2001 From: step35 Date: Sun, 26 Apr 2026 12:28:45 -0400 Subject: [PATCH] fix(evennia): remove hardcoded /Users/apayne path from game engines Replace WORLD_DIR hardcoded to /Users/apayne/.timmy/evennia/timmy_world with configurable path resolution via TIMMY_WORLD_DIR environment variable. Default remains Path.home() / '.timmy' / 'evennia' / 'timmy_world'. Fixes portability: works on any machine, not just Alexander's Mac. Changes: - evennia/timmy_world/game.py: add import os, use os.getenv() - evennia/timmy_world/world/game.py: same change Testing: - tests/test_evennia_local_world_game.py: add new test test_world_dir_is_overrideable_by_environment() Verifies TIMMY_WORLD_DIR env var overrides default. Acceptance criteria: - [x] Replace hardcoded WORLD_DIR with config/env/pathlib resolution - [x] Save/load behavior preserved (STATE_FILE, TIMMY_LOG still derived) - [x] Regression test added proving overrideability Closes #831 --- evennia/timmy_world/game.py | 3 ++- evennia/timmy_world/world/game.py | 3 ++- tests/test_evennia_local_world_game.py | 31 ++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/evennia/timmy_world/game.py b/evennia/timmy_world/game.py index fad9473..672fa05 100644 --- a/evennia/timmy_world/game.py +++ b/evennia/timmy_world/game.py @@ -6,9 +6,10 @@ Not simulation. Story. """ import json, time, os, random from datetime import datetime +import os from pathlib import Path -WORLD_DIR = Path('/Users/apayne/.timmy/evennia/timmy_world') +WORLD_DIR = Path(os.getenv('TIMMY_WORLD_DIR', Path.home() / '.timmy' / 'evennia' / 'timmy_world')) STATE_FILE = WORLD_DIR / 'game_state.json' TIMMY_LOG = WORLD_DIR / 'timmy_log.md' diff --git a/evennia/timmy_world/world/game.py b/evennia/timmy_world/world/game.py index 1b2aa74..1aaa75e 100644 --- a/evennia/timmy_world/world/game.py +++ b/evennia/timmy_world/world/game.py @@ -6,9 +6,10 @@ Not simulation. Story. """ import json, time, os, random from datetime import datetime +import os from pathlib import Path -WORLD_DIR = Path('/Users/apayne/.timmy/evennia/timmy_world') +WORLD_DIR = Path(os.getenv('TIMMY_WORLD_DIR', Path.home() / '.timmy' / 'evennia' / 'timmy_world')) STATE_FILE = WORLD_DIR / 'game_state.json' TIMMY_LOG = WORLD_DIR / 'timmy_log.md' diff --git a/tests/test_evennia_local_world_game.py b/tests/test_evennia_local_world_game.py index f22a5d9..daebab8 100644 --- a/tests/test_evennia_local_world_game.py +++ b/tests/test_evennia_local_world_game.py @@ -1,6 +1,8 @@ from importlib.util import module_from_spec, spec_from_file_location from pathlib import Path +import os import unittest +from unittest.mock import patch ROOT = Path(__file__).resolve().parent.parent @@ -67,5 +69,34 @@ class TestEvenniaLocalWorldGame(unittest.TestCase): self.assertIn("The servers hum steady. The green LED pulses.", result["world_events"]) + def test_world_dir_is_overrideable_by_environment(self): + """Test that TIMMY_WORLD_DIR env var overrides the hardcoded default.""" + import importlib.util + import tempfile + from pathlib import Path + + # Create a temp directory to use as WORLD_DIR + with tempfile.TemporaryDirectory() as tmp: + override_path = Path(tmp) + + # Patch the environment before loading the module + env = os.environ.copy() + env['TIMMY_WORLD_DIR'] = str(override_path) + + # Load the module fresh in a new namespace with patched env + spec = importlib.util.spec_from_file_location("evennia_local_world_game_override", GAME_PATH) + module = importlib.util.module_from_spec(spec) + assert spec.loader is not None + # Execute with patched environ + old_env = os.environ + os.environ = env + try: + spec.loader.exec_module(module) + finally: + os.environ = old_env + + # The WORLD_DIR should equal the override path + self.assertEqual(module.WORLD_DIR, override_path) + if __name__ == "__main__": unittest.main() -- 2.43.0