bitflicker64 commented on code in PR #418:
URL: https://github.com/apache/hugegraph-ai/pull/418#discussion_r4513637397


##########
hugegraph-llm/src/tests/config/test_config.py:
##########
@@ -87,3 +86,94 @@ def test_env_path_prefers_explicit_override(self):
         custom_env = Path("/tmp/hugegraph-llm-test.env")
         with patch.dict(environ, {base_config.ENV_PATH_ENV_VAR: 
str(custom_env)}):
             self.assertEqual(Path(base_config.resolve_env_path()), custom_env)
+
+
+_ENV_SCRUB_PREFIXES = (
+    "OPENAI_",
+    "OLLAMA_",
+    "CHAT_",
+    "EXTRACT_",
+    "TEXT2GQL_",
+    "EMBEDDING_",
+    "RERANKER_",
+    "COHERE_",
+    "CO_API_",
+    "HUGEGRAPH_LLM_",
+)
+
+
+def _scrub_config_env(monkeypatch):
+    for name in list(environ):
+        if name.upper().startswith(_ENV_SCRUB_PREFIXES):
+            monkeypatch.delenv(name)
+
+
+def _config_import_env(home: Path) -> dict:
+    env = dict(environ)
+    for name in list(env):
+        if name.upper().startswith(_ENV_SCRUB_PREFIXES):
+            env.pop(name)
+    env["HUGEGRAPH_LLM_ENV_PATH"] = str(home / ".env")
+    env["HUGEGRAPH_LLM_SETTINGS_PATH"] = str(home / "settings.yaml")
+    env["HUGEGRAPH_LLM_PROMPT_CONFIG_PATH"] = str(home / "config_prompt.yaml")
+    return env
+
+
+def _run_config_import(tmp_path: Path, home: Path) -> 
subprocess.CompletedProcess:
+    return subprocess.run(
+        [sys.executable, "-c", "import hugegraph_llm.config"],
+        env=_config_import_env(home),
+        cwd=tmp_path,
+        capture_output=True,
+        text=True,
+        timeout=120,
+    )
+
+
+def test_env_export_round_trip_preserves_typed_fields(tmp_path, monkeypatch):
+    from hugegraph_llm.config.llm_config import LLMConfig
+    from hugegraph_llm.config.models import base_config
+
+    _scrub_config_env(monkeypatch)
+    monkeypatch.setattr(base_config, "env_path", str(tmp_path / ".env"))
+
+    settings = LLMConfig()
+    settings.ollama_chat_port = 12345
+    settings.openai_chat_tokens = 4096
+    settings.extract_use_chat = False
+    settings.hybrid_llm_weights = 0.0
+    settings.generate_env()
+
+    reloaded = LLMConfig()
+    assert reloaded.ollama_chat_port == 12345
+    assert isinstance(reloaded.ollama_chat_port, int)
+    assert reloaded.openai_chat_tokens == 4096
+    assert isinstance(reloaded.openai_chat_tokens, int)
+    assert reloaded.extract_use_chat is False

Review Comment:
   Important: `LLMConfig._canonical` defaults `extract_use_chat` to `False` 
whenever the dotenv holds an extract connection field, and `generate_env()` 
always writes `EXTRACT_LLM_TYPE`, so this assertion passes even when 
`EXTRACT_USE_CHAT` is never exported. Also assert that the exported `.env` 
contains `EXTRACT_USE_CHAT='False'`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to