mirror of
https://github.com/Alishahryar1/free-claude-code.git
synced 2026-07-03 14:05:26 +02:00
Ignore removed thinking env keys
This commit is contained in:
@@ -48,11 +48,6 @@ def _configured_env_files(model_config: Mapping[str, Any]) -> tuple[Path, ...]:
|
||||
return tuple(Path(item) for item in configured)
|
||||
|
||||
|
||||
def _env_file_contains_key(path: Path, key: str) -> bool:
|
||||
"""Check whether a dotenv-style file defines the given key."""
|
||||
return _env_file_value(path, key) is not None
|
||||
|
||||
|
||||
def _env_file_value(path: Path, key: str) -> str | None:
|
||||
"""Return a dotenv value when the file explicitly defines the key."""
|
||||
if not path.is_file():
|
||||
@@ -79,31 +74,6 @@ def _env_file_override(model_config: Mapping[str, Any], key: str) -> str | None:
|
||||
return configured_value
|
||||
|
||||
|
||||
def _removed_env_var_message(model_config: Mapping[str, Any]) -> str | None:
|
||||
"""Return a migration error for removed env vars, if present."""
|
||||
removed_keys = ("NIM_ENABLE_THINKING", "ENABLE_THINKING")
|
||||
replacement = (
|
||||
"ENABLE_MODEL_THINKING, ENABLE_OPUS_THINKING, "
|
||||
"ENABLE_SONNET_THINKING, or ENABLE_HAIKU_THINKING"
|
||||
)
|
||||
|
||||
for removed_key in removed_keys:
|
||||
if removed_key in os.environ:
|
||||
return (
|
||||
f"{removed_key} has been removed in this release. "
|
||||
f"Rename it to {replacement}."
|
||||
)
|
||||
|
||||
for env_file in _configured_env_files(model_config):
|
||||
if _env_file_contains_key(env_file, removed_key):
|
||||
return (
|
||||
f"{removed_key} has been removed in this release. "
|
||||
f"Rename it to {replacement}. Found in {env_file}."
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
"""Application settings loaded from environment variables."""
|
||||
|
||||
@@ -333,14 +303,6 @@ class Settings(BaseSettings):
|
||||
default="", validation_alias="ANTHROPIC_AUTH_TOKEN"
|
||||
)
|
||||
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def reject_removed_env_vars(cls, data: Any) -> Any:
|
||||
"""Fail fast when removed environment variables are still configured."""
|
||||
if message := _removed_env_var_message(cls.model_config):
|
||||
raise ValueError(message)
|
||||
return data
|
||||
|
||||
# Handle empty strings for optional string fields
|
||||
@field_validator(
|
||||
"telegram_bot_token",
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "free-claude-code"
|
||||
version = "1.2.38"
|
||||
version = "1.2.39"
|
||||
description = "Middleware between Claude Code CLI (Anthropic API) and NVIDIA NIM"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.14.0"
|
||||
|
||||
+23
-10
@@ -350,21 +350,34 @@ class TestSettings:
|
||||
assert settings.anthropic_auth_token == "server-token"
|
||||
assert settings.uses_process_anthropic_auth_token() is False
|
||||
|
||||
def test_removed_nim_enable_thinking_raises(self, monkeypatch):
|
||||
"""NIM_ENABLE_THINKING now fails fast with a migration message."""
|
||||
@pytest.mark.parametrize("removed_key", ["NIM_ENABLE_THINKING", "ENABLE_THINKING"])
|
||||
def test_removed_thinking_env_keys_are_ignored(self, monkeypatch, removed_key):
|
||||
"""Stale thinking env keys do not block startup or affect settings."""
|
||||
from config.settings import Settings
|
||||
|
||||
monkeypatch.setenv("NIM_ENABLE_THINKING", "false")
|
||||
with pytest.raises(ValidationError, match="ENABLE_MODEL_THINKING"):
|
||||
Settings()
|
||||
monkeypatch.setenv(removed_key, "false")
|
||||
monkeypatch.setitem(Settings.model_config, "env_file", ())
|
||||
|
||||
def test_removed_enable_thinking_raises(self, monkeypatch):
|
||||
"""ENABLE_THINKING now fails fast with a migration message."""
|
||||
settings = Settings()
|
||||
|
||||
assert settings.enable_model_thinking is True
|
||||
|
||||
@pytest.mark.parametrize("removed_key", ["NIM_ENABLE_THINKING", "ENABLE_THINKING"])
|
||||
@pytest.mark.parametrize("value", ["false", ""])
|
||||
def test_removed_thinking_dotenv_keys_are_ignored(
|
||||
self, monkeypatch, tmp_path, removed_key, value
|
||||
):
|
||||
"""Stale thinking dotenv keys do not block startup or affect settings."""
|
||||
from config.settings import Settings
|
||||
|
||||
monkeypatch.setenv("ENABLE_THINKING", "false")
|
||||
with pytest.raises(ValidationError, match="ENABLE_MODEL_THINKING"):
|
||||
Settings()
|
||||
env_file = tmp_path / ".env"
|
||||
env_file.write_text(f"{removed_key}={value}\n", encoding="utf-8")
|
||||
monkeypatch.delenv(removed_key, raising=False)
|
||||
monkeypatch.setitem(Settings.model_config, "env_file", (env_file,))
|
||||
|
||||
settings = Settings()
|
||||
|
||||
assert settings.enable_model_thinking is True
|
||||
|
||||
|
||||
# --- NimSettings Validation Tests ---
|
||||
|
||||
Reference in New Issue
Block a user