Skip to content

content_repo 存在 repositories→services 逆向 import(分层既有违例) #113

Closed

Description

@fxbin

现状

backend/app/repositories/content_repo.py:870 与 :912 两处函数内 from app.services.scoring_engine import CONFIG as SCORING_CONFIG——repositories 层 import services 层,属 AGENTS.md 2.2 分层表逆向依赖。

机器检查(make layering / check_layering.py)只作用于 app/api/v1/,不覆盖此文件,所以一直静默存在。PR #111 独立 Verifier 复核发现(既有现状,非 #111 引入;#111 未触碰也未恶化)。

修法建议

读 CONFIG 的两个函数(list_for_today_window 一类时间窗查询)本质是「用引擎口径过滤」的查询编排,可选:

  1. 把 risk_threshold 作为参数由 services 层调用方传入(repo 回到纯 ORM 封装);
  2. 或将这两个查询的口径过滤上移到 service。

属低优先级清理,建议下次触碰 content_repo 时顺手处理,不必单独开 PR。

Activity

  1. fxbin commented on Oct 18, 2026

    @fxbin
    OwnerAuthor

    范围更正(取证核实的全量清单)

    repositories→services 逆向 import 实际为 5 处、2 个文件,比本 issue 报告的 2 处多:

    位置 内容 处置
    content_repo.py:870/:912 读 CONFIG["risk_threshold"] 本 issue 修复:scoring_caliber 搬 app/core/
    content_repo.py:598 normalize_tag_key(纯函数,零依赖) 本 issue 修复:tag_normalization 一并搬 app/core/
    analysis_repo.py:14-15 模块级 import score_items + get_feedback_scores 真重构,独立立项 #122

    「低优先级、下次顺手处理」的前提已不成立——人工清单漏了 60% 的违例,这本身就是要上机器门禁的论据。

    修复方案(圆桌四席收敛,记录见本地):

    1. scoring_caliber.py / tag_normalization.py 都是零依赖的口径单一事实源模块,从 app/services/ 搬 app/core/(core 是各层合法底座,content_repo 已 import core 三处);
    2. check_layering.py 新增「repositories 禁止 import app.services」AST 检查;analysis_repo 两处进显式 allowlist(引用 analysis_repo 评分编排上移 services(清空 layering allowlist) #122,棘轮式收缩);
    3. analysis_repo 评分编排上移 services → analysis_repo 评分编排上移 services(清空 layering allowlist) #122。

    门禁落地后本 issue 关闭;剩余部分由 #122 跟踪。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions