Repository navigation
refactor: 收敛多处平行维护为单一事实来源,并修复审计发现的 P3/P4 问题 - #7
Merged
Merged
Conversation
把「同一逻辑事实在多处各写一份、靠人工保持一致」的冗余收敛到单一来源,并加一致性 测试守卫防漂移: - 设置:全部字段只在 config.Settings 定义;RuntimeSettings 改为其别名、删除手写 类型集合;保存表单按 model_fields 动态收集;密钥清单抽 SECRET_FIELDS; jev_backend 校验内聚为 field_validator;.env.example 补 SECOND_EYE_IMAGE 并注明 DATABASE_URL 在 Docker 下被 compose 覆盖;新增一致性守卫测试(字段覆盖/未知变量/ 默认模型名)。 - 通知:新增 notify/registry.py 收敛渠道名/开关字段/构造,main 与 routes 均改用它; 新增 registry 守卫测试。 - Jev 提示词:抽取 REQUIREMENT_CRITERION/VALUE_CRITERION/REQUIREMENT_SYSTEM_PREFIX, adapter 与 typesafe 两后端共用用户模板,锁措辞测试。 - 任务:TASK_FIELDS + task_to_dict 统一创建/更新/API 序列化,补回 fetch_detail。 - 列表:抽 _apply_listing_filters + PAGE_SIZE,列表页/加载更多/API 三处统一。 - 常量:新增 constants.py(评分刻度/风险等级)、parse_utils.clamp_score;UA 与 goofish 域名抽到 crawler/constants.py;__version__ 改从包元数据读取。 - DB:删除重复的 _LISTINGS_COLUMNS(改由 _COLUMN_DDL 派生),加「DDL 列 == ORM 列」 守卫;详情页 drop_pct 改用服务端函数、展示阈值抽常量。 验证:ruff 全绿;pytest 232 passed。
- crawler: 搜索结果卡片的 seller-text-- 实为地区文本,原先 SELLER 与 LOCATION 同选择器导致 seller 与 location 恒等、地区错位;现 location 采地区、seller 置空 (卖家昵称仅从详情页取)。同步修正测试,BASE_URL 改引用 crawler.constants。 - notify: serverchan / wecom_robot 的 httpx.Client 改用 with 关闭,修复连接泄漏。 - crawler.parser: _parse_seller_block 去掉从未使用的第 4 个返回值并补类型标注。 - models: ORM 的 JSON 列补 Mapped 元素类型(list[str]/dict[str, Any])。 - json_extract: 修正“可选依赖 json-repair”的过时措辞(它已是核心依赖)。 - settings.html: “本地/Codex”预设不再硬编码内网 IP 与私有模型名,改通用占位。 - 工程:.dockerignore 补齐 .venv/缓存/构建产物;compose 固定 gotify 3.1.1。 - 测试:新增 _safe_test_url(SSRF)单测;去重复导入;测试名去轮次绑定。 验证:ruff 全绿;pytest 240 passed。
- LLMClient 暴露公开 payload()/complete(),judge 与测试端点不再访问私有方法。 - routes: 抽 _optional_int 容错 task_id 查询参数;_progress_context 复用已算出的 running/queued;测试通知失败改 logger.exception;测试端点请求体解析失败记 debug。 - crawl_service: 抽 _evaluate_and_queue 消除新品/重评的重复评估分支; build_judger 的不可用原因按 backend 判断。 - xianyu: 抽 _open_page 统一浏览器/上下文/Cookie 装配;超时与等待抽为常量。 - satisfaction/task_service: 评分刻度改用 SCORE_MAX,不再硬编码 10。 - jev_typesafe: 修正返回标注(RequirementVerdict)与索引空间注释。 - main: 用 PYTEST_CURRENT_TEST 替代 sys.modules 探测测试环境。 - 删除无引用的死模板 tasks_edit.html;测试命名与 pytest.raises 整理。 验证:ruff 全绿;pytest 240 passed。
端口原先在 compose 端口映射、登录页模板、README 与启动脚本各写一份。现由
Settings.novnc_port 定义、.env.example 记录,compose 映射与登录页链接(经
_login_context 传入 novnc_port)共用,启动脚本读 ${NOVNC_PORT:-16080}。
验证:ruff 全绿;pytest 240 passed。
Owner
|
感谢这次范围很完整的维护改进!我检查时注意到一个小问题:scripts/start-docker.sh 原先只读取 shell 环境变量 NOVNC_PORT,未读取 Compose 同样会使用的 .env 值,所以自定义端口时提示 URL 可能不匹配。我已在你的 PR 分支上补了一个小修复,解析 .env(不 source 配置文件),并验证了 .env 自定义端口和 shell 环境变量覆盖两种情况。感谢你开放 maintainer 修改权限,也感谢这次高质量贡献。等更新后的 CI 检查完成后我会合并。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
代码里存在大量「同一逻辑事实在多处各写一份、靠人工保持一致」的冗余,以及只读审计发现的若干缺陷与可维护性问题。本 PR 统一收敛为单一事实来源(SSOT)并加一致性守卫,同时修掉这些缺陷。
改动
config.Settings定义;RuntimeSettings改为其别名、删手写类型集合;保存表单按model_fields动态收集;密钥清单抽SECRET_FIELDS;jev_backend校验内聚为field_validator;.env.example补SECOND_EYE_IMAGE。notify/registry.py,main与routes共用。TASK_FIELDS+task_to_dict统一创建/更新/序列化。_apply_listing_filters+PAGE_SIZE。constants.py;UA/域名抽crawler/constants.py;DB 列改由_COLUMN_DDL派生。seller/location选择器错位导致地区字段失真;serverchan/wecom_robot的httpx.Client连接泄漏;死模板/死返回值/不可达分支清理;设置页硬编码内网 IP 与私有模型名改为占位;.dockerignore补齐;gotify 固定版本。LLMClient暴露公开payload()/complete();routes抽_optional_int、progress 去重、异常记日志;crawl_service抽_evaluate_and_queue;xianyu抽_open_page;main用PYTEST_CURRENT_TEST。验证
ruff check .全绿;pytest -q240 passed(含新增守卫与 SSRF 单测)。备注
16080在 compose 与模板各写一份,留待后续引入配置项统一下发。