mirror of
https://github.com/Alishahryar1/free-claude-code.git
synced 2026-07-09 16:00:45 +00:00
## Problem
Admin config was a single responsibility hub with manually duplicated
provider metadata. Provider labels, fields, template loading,
validation, persistence, and status lived in one place.
## Changes
| Before | After |
| --- | --- |
| Admin config lived in one large `api/admin_config.py` module. | Admin
config lives in package modules for manifest, sources, values,
validation, persistence, and status. |
| Provider admin fields and UI labels were manually duplicated. |
Provider admin fields and display names derive from `PROVIDER_CATALOG`
with admin-only help overrides. |
| `fcc-init` and Admin UI loaded `.env.example` separately. | `fcc-init`
and Admin UI use shared `config.env_template` loading. |
| Architecture docs pointed to the old admin config module. |
Architecture docs describe the package owners and catalog-driven
provider manifest. |
<!-- greptile_comment -->
<details open><summary><h3>Greptile Summary</h3></summary>
This PR refactors admin configuration into a catalog-driven package. The
main changes are:
- Split the former monolithic `api/admin_config.py` into manifest,
source loading, value presentation, validation, persistence, and
provider status modules.
- Generate provider admin fields and display names from
`PROVIDER_CATALOG` with admin-specific help overrides.
- Share `.env.example` loading between `fcc-init` and Admin UI defaults
through `config.env_template`.
- Update admin routes, Admin UI provider labels, architecture docs,
version metadata, and contract/API tests for the new module layout.
</details>
<h3>Confidence Score: 5/5</h3>
The refactor appears merge-safe with no code issues identified in the
reviewed changes.
The package split, catalog-driven provider metadata, shared environment
template loading, route updates, and tests/docs changes are cohesive and
covered by corresponding contract/API/CLI test updates.
<details><summary><h3><a href="https://www.greptile.com/trex"><img
alt="T-Rex"
src="https://greptile-static-assets.s3.amazonaws.com/trex/trex_green.svg"
height="20" align="absmiddle"></a> T-Rex Logs</h3></summary>
**What T-Rex did**
- T-Rex ran manifest validation for catalog provider before and after
routes, capturing base and head responses and catalog-alignment checks,
and confirmed the validation completed successfully.
- T-Rex evaluated the shared-env-template scenarios, observing the
before run with no config.env\_template module and the after run with
the module present, with patched loader values and all consistency
checks passing, and the run exited with code 0.
- T-Rex executed the package-admin-workflow validation, verifying the
base and after import paths, the load/validate/write workflow produced
matching outputs, and the run completed with exit code 0.
<a
href="https://app.greptile.com/trex/runs/12529845/artifacts"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewAllArtifactsDark.svg?v=1"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewAllArtifacts.svg?v=1"><img
alt="View all artifacts"
src="https://greptile-static-assets.s3.amazonaws.com/badges/ViewAllArtifacts.svg?v=1"
height="32"></picture></a>
<sub><a href="https://www.greptile.com/trex"><img alt="T-Rex"
src="https://greptile-static-assets.s3.amazonaws.com/trex/trex_green.svg"
height="14" align="absmiddle"></a> Ran code and verified through
T-Rex</sub>
</details>
<sub>Reviews (1): Last reviewed commit: ["Refactor admin config into
catalog-drive..."](d6239d7953)
| [Re-trigger
Greptile](https://app.greptile.com/api/retrigger?id=40315222)</sub>
<!-- /greptile_comment -->
81 lines
2.5 KiB
Python
81 lines
2.5 KiB
Python
from __future__ import annotations
|
|
|
|
import re
|
|
import tomllib
|
|
from pathlib import Path
|
|
from urllib.parse import unquote, urlsplit
|
|
|
|
|
|
def test_architecture_document_exists() -> None:
|
|
repo_root = Path(__file__).resolve().parents[2]
|
|
|
|
assert (repo_root / "ARCHITECTURE.md").is_file()
|
|
|
|
|
|
def test_architecture_document_relative_links_resolve() -> None:
|
|
repo_root = Path(__file__).resolve().parents[2]
|
|
architecture = repo_root / "ARCHITECTURE.md"
|
|
text = architecture.read_text(encoding="utf-8")
|
|
|
|
missing: list[str] = []
|
|
for match in re.finditer(r"(?<!!)\[[^\]]+\]\(([^)]+)\)", text):
|
|
raw_target = match.group(1).strip()
|
|
target = raw_target.split("#", 1)[0]
|
|
if not target or urlsplit(target).scheme:
|
|
continue
|
|
if not (repo_root / unquote(target)).exists():
|
|
missing.append(raw_target)
|
|
|
|
assert missing == []
|
|
|
|
|
|
def test_smoke_lib_has_no_sse_shim_module() -> None:
|
|
repo_root = Path(__file__).resolve().parents[2]
|
|
assert not (repo_root / "smoke" / "lib" / "sse.py").exists()
|
|
|
|
|
|
def test_api_package_exports() -> None:
|
|
import api
|
|
|
|
assert set(api.__all__) == {
|
|
"MessagesRequest",
|
|
"MessagesResponse",
|
|
"TokenCountRequest",
|
|
"TokenCountResponse",
|
|
"create_app",
|
|
}
|
|
|
|
|
|
def test_root_env_example_is_the_single_template_source() -> None:
|
|
repo_root = Path(__file__).resolve().parents[2]
|
|
root_example = repo_root / ".env.example"
|
|
duplicate_example = repo_root / "config" / "env.example"
|
|
|
|
assert root_example.is_file()
|
|
assert not duplicate_example.exists()
|
|
|
|
|
|
def test_root_env_example_is_packaged_for_config_template_loader() -> None:
|
|
repo_root = Path(__file__).resolve().parents[2]
|
|
pyproject = tomllib.loads((repo_root / "pyproject.toml").read_text("utf-8"))
|
|
|
|
force_include = pyproject["tool"]["hatch"]["build"]["targets"]["wheel"][
|
|
"force-include"
|
|
]
|
|
|
|
assert force_include[".env.example"] == "config/env.example"
|
|
|
|
|
|
def test_pyproject_first_party_packages_match_packaged_roots() -> None:
|
|
repo_root = Path(__file__).resolve().parents[2]
|
|
pyproject = (repo_root / "pyproject.toml").read_text(encoding="utf-8")
|
|
match = re.search(r"known-first-party = \[(?P<items>[^\]]+)\]", pyproject)
|
|
|
|
assert match is not None
|
|
configured = {
|
|
item.strip().strip('"')
|
|
for item in match.group("items").split(",")
|
|
if item.strip()
|
|
}
|
|
expected = {"api", "cli", "config", "core", "messaging", "providers", "smoke"}
|
|
assert configured == expected
|