[B1][CI门禁] R-P1-13+R-P1-14+S-P1-5 ruff 扩 app/ + 空库 alembic upgrade 验证 #211
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
批次:B1(同源合单,v0.7 §8.2)。依据:R 报告 §3.5 W2/W3/W4;台账 R-P1-13/R-P1-14、S-P1-5。
验收标准
不做项
关闭凭证核验 (2026-10-07)
提交:
105955e(本地 main,未 push;生产随发布)。逐条对应验收标准:ruff check app/ tests/(.gitea/workflows/test.yml:75-76)。本地复现:cd backend && ruff check app/ tests/→All checks passed!。存量清零见 commit:app/ 共 6 处——app/api/v1/llm_providers.py(isort)、app/models/llm_cloud_policy.py:21(删 unusedInteger)、app/models/llm_role_member.py(删 unusedBoolean)、app/services/llm_provider_service.py(isort×2)、app/services/llm_tiers.py(isort);另修复合并扫描才暴露的tests/test_llm_outage_event.py多余空行(单独扫 tests 时 isort 解析不到 first-partyapp会漏报)。全部为自动安全修复,无noqa/分级忽略,无需登记例外ci-pg-mig(POSTGRES_DB=csctalon_dev,test.yml:44-48)并在 pytest 前跑python -m alembic upgrade head+heads(test.yml:77-88,命令级 env 前缀,不污染 conftest 以 setdefault 从TEST_POSTGRES_*回填的 pytest 连接)。本地端到端实测:新建全新空库跑 upgrade,首次即真实抓到一个链断裂并已修复——迁移a1c2e3f4d5b6无条件DROP CONSTRAINT uq_cs_record_business,但建表迁移b4c9d1f02e5a从未创建该约束(历史上仅由 create_all 依模型带出),空库报UndefinedObject;已改为先查pg_constraint存在才 DROP。修复后重测:upgrade headexit=0、alembic_version单行=t0u1v2w3x4y5、public 120 表;alembic heads唯一(多 head 时 upgrade head 本身即非零退出).gitleaks.toml:workflows 由^\.gitea/workflows/.*\.yml$收窄为仅精确^\.gitea/workflows/test\.yml$(:27);删除^backend/tests/.*\.py$全局整目录放行,改为在hardcoded-phone-number(:101-104)、hardcoded-strong-password(:87-89) 两条夹具启发式上的规则级豁免——scrm/shanmao 业务凭证规则与 gitleaks 内置密钥规则(AKIA/generic-api-key/jwt 等)对 tests 仍全量生效。确无密钥:对 git 干净跟踪快照扫描 0 命中;收窄前的 129 个命中全部在 tests、且仅两类测试夹具(118 个构造假手机号如13700137000~8、11 个假强密码如P@ssw0rd123/unit-test-shared-secret-.../sk-...-never-leak),无一是真实凭证。负向实测(gitleaks 8.30.1):往 tests 注入密钥→generic-api-key/scrm-baiyin-credentials/shanmao-platform-credentials均被抓;往gitleaks.yml(非放行)注入→被抓,注入test.yml→仍被精确放行(边界正确)docs/standards/alembic-migration管理规范.md升 v1.2:§二 增「空库可重放自检」命令、§八 新增第 6 条(空库可重放强制门禁)与第 7 条(修复可重放性缺陷可改已提交迁移的前提+首例 a1c2),并修订第 2 条;README.md:164CI 说明与:178-181本地命令补空库自检。全程仅用既有 ruff/alembic/gitleaks,未引入新工具链ruff check app/ tests/→ All checks passed!;② 全新空库alembic upgrade headexit=0、单 head;③ 全量pytest(ENV=test,csctalon_test)exit=0,100% 用例全通过无 F/E;④ 提交钩子 gitleaks 输出no leaks found(commit105955e)不做项确认:未引入 api 层覆盖率强制指标(遵工单不做项)。
遗留(不影响本单验收,供后续):
docs/standards/alembic-migration管理规范.md§一 版本链图为 2026-08-26 时点快照(停在旧 head),本次仅把顶部 head 锚点更正为实测t0u1v2w3x4y5,未重绘整图(属 #215 文档清点范畴)。tests/test_complaint_scope.py:680含源自工单 #315 实测样本的号码13603062258(纯号码分割逻辑字符串,非凭证/账号)。PII 净化建议另单处理;本次 phone 规则对 tests 规则级豁免,CI 保持全绿。