Refactor AI daily report pipeline

This commit is contained in:
Mimikko-zeus
2026-06-04 15:21:56 +08:00
parent 94e18ce22d
commit 5a98696255
64 changed files with 4778 additions and 1316 deletions

39
tests/test_env_loading.py Normal file
View File

@@ -0,0 +1,39 @@
import importlib.util
import os
import unittest
from pathlib import Path
from unittest.mock import patch
ROOT = Path(__file__).resolve().parents[1]
SCRIPT = ROOT / "script" / "ai_daily_blog_pipeline.py"
def load_pipeline_module():
spec = importlib.util.spec_from_file_location("ai_daily_blog_pipeline", SCRIPT)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
class EnvLoadingTests(unittest.TestCase):
def test_project_env_is_loaded_and_process_env_wins(self):
module = load_pipeline_module()
env_text = "LLM_MODEL=file-model\nLLM_BASE_URL=https://file.example/v1\n"
with patch.object(module.Path, "home", return_value=ROOT / "missing-home"):
with patch.dict(os.environ, {"LLM_MODEL": "process-model"}, clear=False):
with patch.object(module, "PROJECT_ENV_PATH", ROOT / ".env.test"):
(ROOT / ".env.test").write_text(env_text, encoding="utf-8")
try:
env = module.load_env()
finally:
(ROOT / ".env.test").unlink(missing_ok=True)
self.assertEqual(env["LLM_BASE_URL"], "https://file.example/v1")
self.assertEqual(env["LLM_MODEL"], "process-model")
if __name__ == "__main__":
unittest.main()