Skip to content

Commit 14c6935

Browse files
authored
refactor(phase8 #48 G2): settings shim → knowledge_base domain + /api/v2 hard-cut (#1678)
Phase 8 second batch G2 — per architect canonical D7-2 (msg=94f663f2 §3.2.2), ``aperag/views/settings.py`` is carved into the knowledge_base domain and the URL prefix is hard-cut from ``/api/v1/settings*`` to ``/api/v2/settings*``. Changes: - Rename ``aperag/views/settings.py`` → ``aperag/domains/knowledge_base/api/settings_routes.py`` - Inline the small ``Settings`` request schema locally so the new domain module does not import ``aperag.schema.view_models`` (G1 ban). Drop the now-orphan ``Settings`` class from ``aperag/schema/view_models.py`` — no other caller imports it (verified by grep). - Switch the ``settings_router`` mount in ``aperag/app.py`` from ``/api/v1`` to ``/api/v2``; sort the import line into the ``aperag.domains.knowledge_base.api.*`` block. - Add a new boundary test ``test_no_module_imports_legacy_views_settings`` — analogous to the existing ``test_aperag_domains_never_import_legacy_auth_view_dependencies`` added by #36. Total boundary tests now 22. - Update ``docs/modularization/cleanup-inventory.md`` §3.2 to mark the row done. FE follow-up: ``web/src/features/admin/{client,server}-api.ts`` (and related typed-client regen) will be picked up by @dongdong in a sibling PR per task thread #模块化重构:e1f4ce71. Gates: 22/22 boundary, 686 pass / 29 skip / 1 deselect / 0 fail unit suite, ruff check + format clean.
1 parent 940d5bb commit 14c6935

5 files changed

Lines changed: 55 additions & 10 deletions

File tree

aperag/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
set_quota_init_ops as _id_set_quota_init_ops,
5656
)
5757
from aperag.domains.knowledge_base.api.routes import router as knowledge_base_router
58+
from aperag.domains.knowledge_base.api.settings_routes import router as settings_router
5859
from aperag.domains.knowledge_base.service.collection_service import (
5960
set_marketplace_collection_ops as _kb_set_marketplace_collection_ops,
6061
)
@@ -87,7 +88,6 @@
8788
from aperag.service.quota_service import quota_service as _legacy_quota_service
8889
from aperag.service.search_pipeline_service import search_pipeline_service as _legacy_search_pipeline_service
8990
from aperag.views.prompts import router as prompts_router
90-
from aperag.views.settings import router as settings_router
9191

9292
# Wire the knowledge_base domain's consumer-owned Protocol DI slots
9393
# (Phase 3 Step 5b2c). All four legacy service singletons now
@@ -229,7 +229,7 @@ async def health_check():
229229
app.include_router(
230230
marketplace_router, prefix="/api/v1"
231231
) # Marketplace domain router (marketplace + marketplace_collections)
232-
app.include_router(settings_router, prefix="/api/v1")
232+
app.include_router(settings_router, prefix="/api/v2") # KB domain settings (carved from views/ in #48)
233233
app.include_router(prompts_router, prefix="/api/v1") # Add prompts router
234234
app.include_router(web_access_router, prefix="/api/v2", tags=["web_access"]) # Add web_access domain router
235235
app.include_router(retrieval_router, prefix="/api/v2", tags=["retrieval"]) # Add retrieval domain router

aperag/views/settings.py renamed to aperag/domains/knowledge_base/api/settings_routes.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,43 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
"""System settings routes for the knowledge_base domain.
16+
17+
Hosts ``/settings`` endpoints related to document parser configuration
18+
(MinerU token, parser health). Carved here from ``aperag/views/settings.py``
19+
in Phase 8 task #48 (G2) per canonical D7-2: ``/api/v1/settings*`` is
20+
hard-cut to ``/api/v2/settings*`` (see cleanup-inventory.md §3.2.2).
21+
22+
Backing service is ``aperag.domains.governance.service.setting_service``
23+
because the underlying ``Setting`` ORM lives in the governance domain;
24+
this module is a thin api layer that the knowledge_base domain owns
25+
because the settings exposed here are doc-parser configuration that
26+
the KB ingest pipeline consumes.
27+
"""
28+
1529
from typing import Optional
1630

1731
from fastapi import APIRouter, Body, Depends, Response
1832
from fastapi.responses import JSONResponse
33+
from pydantic import BaseModel, Field
1934

2035
from aperag.docparser.health import ParserHealthReport, get_parser_health_report
2136
from aperag.domains.governance.service.setting_service import setting_service
2237
from aperag.domains.identity.service.auth_dependencies import required_user
23-
from aperag.schema.view_models import Settings
38+
39+
40+
class Settings(BaseModel):
41+
"""Knowledge-base parser settings request/response schema.
42+
43+
Carved here from ``aperag.schema.view_models.Settings`` in #48 (G2)
44+
so the knowledge_base domain owns the shape directly and does not
45+
depend on the legacy aggregate ``aperag.schema.view_models``.
46+
"""
47+
48+
use_mineru: Optional[bool] = Field(None, description="Whether to use MinerU")
49+
mineru_api_token: Optional[str] = Field(None, description="API token for MinerU")
50+
use_markitdown: Optional[bool] = Field(None, description="Whether to use MarkItDown")
51+
2452

2553
router = APIRouter()
2654

aperag/schema/view_models.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,6 @@ class FailResponse(BaseModel):
7272
# keep resolving the same class objects.
7373

7474

75-
class Settings(BaseModel):
76-
use_mineru: Optional[bool] = Field(None, description="Whether to use MinerU")
77-
mineru_api_token: Optional[str] = Field(None, description="API token for MinerU")
78-
use_markitdown: Optional[bool] = Field(None, description="Whether to use MarkItDown")
79-
80-
8175
class ParserHealthItem(BaseModel):
8276
key: str
8377
label: str

docs/modularization/cleanup-inventory.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ marketplace.py / marketplace_collections.py / providers_v2.py / __init__.py →
196196
| `aperag/views/openai.py` | 83 | **迁到** `aperag/domains/conversation/api/openai_routes.py`(OpenAI-compat 归 conversation),挂 `/v1/chat/completions` 保留 |
197197
| `aperag/views/prompts.py` | 205 | **迁到** `aperag/domains/model_platform/api/prompt_routes.py`,挂 `/api/v1/user-prompts` 保留 |
198198
| `aperag/views/quota.py` | 234 | **迁到** `aperag/domains/governance/api/quota_routes.py`,挂 `/api/v1/quota` 保留 |
199-
| `aperag/views/settings.py` | 67 | **迁到** `aperag/domains/knowledge_base/api/settings_routes.py`(parser health),挂 `/api/v1/settings` 保留 |
199+
| ~~`aperag/views/settings.py`~~ | ~~67~~ | ✅ Phase 8 #48 (G2) **DONE** — carved to `aperag/domains/knowledge_base/api/settings_routes.py`, hard-cut prefix `/api/v1/settings` `/api/v2/settings` per D7-2 (msg=94f663f2 §3.2.2). Legacy file deleted. |
200200
| `aperag/views/test.py` | 60 | **dev-only****直接 rm** 或迁 `tests/fixtures/`(PM 决定) |
201201
| `aperag/views/utils.py` | 134 | `auth.py` + `config.py` 依赖;**随它们迁到 identity 域 `_utils.py`**,然后 rm |
202202
| `aperag/views/chat_documents.py` | 21 | 空 stub,app.py 未 mount;**直接 rm** |

tests/unit_test/test_modularization_boundaries.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,29 @@ def test_aperag_domains_never_import_legacy_auth_view_dependencies():
358358
)
359359

360360

361+
def test_no_module_imports_legacy_views_settings():
362+
"""Phase 8 #48 (G2): ``aperag/views/settings.py`` was carved into
363+
``aperag.domains.knowledge_base.api.settings_routes`` and the legacy
364+
file is gone. No code anywhere in ``aperag/`` may import from the
365+
deleted module — the new home is the canonical owner.
366+
"""
367+
offenders: list[str] = []
368+
aperag_root = REPO_ROOT / "aperag"
369+
for path in aperag_root.rglob("*.py"):
370+
if not path.is_file():
371+
continue
372+
modules = _imported_modules(path.read_text())
373+
if "aperag.views.settings" in modules:
374+
offenders.append(f"{path.relative_to(REPO_ROOT).as_posix()} imports aperag.views.settings")
375+
376+
assert not offenders, (
377+
"`aperag.views.settings` was deleted in Phase 8 task #48 (G2). "
378+
"Import the carved router or service from "
379+
"`aperag.domains.knowledge_base.api.settings_routes` instead. "
380+
"Offenders:\n " + "\n ".join(sorted(offenders))
381+
)
382+
383+
361384
# ---------- Retrieval <-> knowledge_graph one-way bridge ----------
362385

363386

0 commit comments

Comments
 (0)