Skip to content

Use Claude Code, Codex, VSCode, Pi, and OpenCode (and 6 other harnesses) for free (1.3B+ free tokens) from your terminal, app, IDE, or phone, and now from the browser with native browser sessions (multi-harness + multi-model) like OpenClaw (voice supported + ToS friendly)

Python

Repair stale Admin defaults without masking locked config (#1413)

Ali Khokhar9b525126cac8
diff --git a/pyproject.toml b/pyproject.toml
index 55f38730..d0ff28ef 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project]
name = "free-claude-code"
-version = "4.30.1"
+version = "4.30.2"
description = "Local proxy connecting coding agents to OpenAI-compatible AI providers"
readme = "README.md"
requires-python = ">=3.14.0"
diff --git a/src/free_claude_code/config/admin/persistence.py b/src/free_claude_code/config/admin/persistence.py
index 0e1320d3..042f71b7 100644
--- a/src/free_claude_code/config/admin/persistence.py
+++ b/src/free_claude_code/config/admin/persistence.py
@@ -56,7 +56,7 @@ class PreparedAdminUpdate:
def target_values_with_updates(updates: Mapping[str, Any]) -> dict[str, str]:
- """Return managed env values after applying admin updates."""
+ """Return a managed target after repairing stored state and applying updates."""
state = load_value_state()
values = template_values()
@@ -73,6 +73,13 @@ def target_values_with_updates(updates: Mapping[str, Any]) -> dict[str, str]:
if entry["source"] in {"repo_env", "template", "default"}:
values[key] = str(entry["value"])
+ # Repair stale editable state before applying the explicit request. Empty
+ # select updates then remain intact for normal Settings validation to reject.
+ for field in FIELDS:
+ values.setdefault(field.key, field.default)
+ if field.field_type == "select" and values[field.key] == "" and field.default:
+ values[field.key] = field.default
+
for key, value in updates.items():
field = FIELD_BY_KEY.get(key)
if field is None:
@@ -83,8 +90,6 @@ def target_values_with_updates(updates: Mapping[str, Any]) -> dict[str, str]:
continue
values[key] = normalize_for_env(value)
- for field in FIELDS:
- values.setdefault(field.key, field.default)
return values
diff --git a/tests/api/test_admin.py b/tests/api/test_admin.py
index 6eb6f38b..4d062043 100644
--- a/tests/api/test_admin.py
+++ b/tests/api/test_admin.py
@@ -1195,6 +1195,105 @@ def test_admin_first_apply_migrates_repo_env(monkeypatch, tmp_path):
assert "DEEPSEEK_API_KEY=deepseek-secret" in managed_text
+def test_admin_first_apply_repairs_empty_select_repo_values(monkeypatch, tmp_path):
+ _set_home(monkeypatch, tmp_path)
+ _clear_process_config(monkeypatch)
+ app = create_test_app()
+ (tmp_path / ".env").write_text(
+ "MESSAGING_PLATFORM=\nWHISPER_DEVICE=\n",
+ encoding="utf-8",
+ )
+
+ response = _local_client(app).post(
+ "/admin/api/config/apply",
+ json={"values": {"NVIDIA_NIM_API_KEY": "nim-secret"}},
+ )
+
+ assert response.status_code == 200
+ assert response.json()["applied"] is True
+ managed_text = (tmp_path / ".fcc" / ".env").read_text("utf-8")
+ assert "NVIDIA_NIM_API_KEY=nim-secret" in managed_text
+ assert "MESSAGING_PLATFORM=discord" in managed_text
+ assert "WHISPER_DEVICE=nvidia_nim" in managed_text
+
+
+def test_admin_apply_preserves_empty_managed_auth_token(monkeypatch, tmp_path):
+ _set_home(monkeypatch, tmp_path)
+ _clear_process_config(monkeypatch)
+ env_file = tmp_path / ".fcc" / ".env"
+ env_file.parent.mkdir(parents=True)
+ env_file.write_text(
+ "ANTHROPIC_AUTH_TOKEN=\nPROVIDER_RATE_LIMIT=1\n",
+ encoding="utf-8",
+ )
+ app = create_test_app()
+
+ response = _local_client(app).post(
+ "/admin/api/config/apply",
+ json={"values": {"PROVIDER_RATE_LIMIT": "2"}},
+ )
+
+ assert response.status_code == 200
+ assert response.json()["applied"] is True
+ managed_lines = env_file.read_text("utf-8").splitlines()
+ assert "ANTHROPIC_AUTH_TOKEN=" in managed_lines
+ assert "PROVIDER_RATE_LIMIT=2" in managed_lines
+
+
+def test_admin_apply_rejects_explicit_empty_select_update(monkeypatch, tmp_path):
+ _set_home(monkeypatch, tmp_path)
+ _clear_process_config(monkeypatch)
+ env_file = tmp_path / ".fcc" / ".env"
+ env_file.parent.mkdir(parents=True)
+ original = "ANTHROPIC_AUTH_TOKEN=\nMESSAGING_PLATFORM=none\n"
+ env_file.write_text(original, encoding="utf-8")
+ app = create_test_app()
+
+ response = _local_client(app).post(
+ "/admin/api/config/apply",
+ json={"values": {"MESSAGING_PLATFORM": ""}},
+ )
+
+ assert response.status_code == 200
+ body = response.json()
+ assert body["applied"] is False
+ assert body["valid"] is False
+ assert any(
+ "messaging_platform" in error and "got ''" in error for error in body["errors"]
+ )
+ assert env_file.read_text("utf-8") == original
+
+
[email protected]("source", ("process", "explicit_env_file"))
+def test_admin_apply_rejects_empty_locked_select_value(
+ monkeypatch,
+ tmp_path,
+ source,
+):
+ _set_home(monkeypatch, tmp_path)
+ _clear_process_config(monkeypatch)
+ app = create_test_app()
+ if source == "process":
+ monkeypatch.setenv("MESSAGING_PLATFORM", "")
+ else:
+ env_file = tmp_path / "locked.env"
+ env_file.write_text("MESSAGING_PLATFORM=\n", encoding="utf-8")
+ monkeypatch.setenv("FCC_ENV_FILE", str(env_file))
+
+ response = _local_client(app).post(
+ "/admin/api/config/apply",
+ json={"values": {"NVIDIA_NIM_API_KEY": "nim-secret"}},
+ )
+
+ assert response.status_code == 200
+ body = response.json()
+ assert body["applied"] is False
+ assert any(
+ "messaging_platform" in error and "got ''" in error for error in body["errors"]
+ )
+ assert not (tmp_path / ".fcc" / ".env").exists()
+
+
def test_admin_local_provider_status_reports_reachable(monkeypatch, tmp_path):
_set_home(monkeypatch, tmp_path)
_clear_process_config(monkeypatch)
diff --git a/tests/scripts/test_installers.py b/tests/scripts/test_installers.py
index 62dd9f29..0da193ff 100644
--- a/tests/scripts/test_installers.py
+++ b/tests/scripts/test_installers.py
@@ -1144,8 +1144,12 @@ def _create_windows_shortcut(
)
-def _windows_shortcut_icon(powershell: str, shortcut_path: Path) -> str:
- env = os.environ | {"FCC_TEST_SHORTCUT": str(shortcut_path)}
+def _windows_shortcut_icon(
+ powershell: str,
+ shortcut_path: Path,
+ env: dict[str, str],
+) -> str:
+ process_env = env | {"FCC_TEST_SHORTCUT": str(shortcut_path)}
completed = subprocess.run(
[
powershell,
@@ -1160,7 +1164,7 @@ def _windows_shortcut_icon(powershell: str, shortcut_path: Path) -> str:
check=True,
capture_output=True,
text=True,
- env=env,
+ env=process_env,
)
return completed.stdout
@@ -1521,6 +1525,7 @@ def test_install_ps1_fresh_install_is_verified(
_windows_shortcut_icon(
powershell_harness.powershell,
desktop_shortcut,
+ powershell_harness.env,
)
== f"{icon},0"
)
diff --git a/uv.lock b/uv.lock
index 2edce06b..d27b1f40 100644
--- a/uv.lock
+++ b/uv.lock
@@ -620,7 +620,7 @@ wheels = [
[[package]]
name = "free-claude-code"
-version = "4.30.1"
+version = "4.30.2"
source = { editable = "." }
dependencies = [
{ name = "aiohttp" },