一、客服 Agent 智能增强(正面回应"不智能、动不动就转人工")
- 决策链由 2 个出口扩到 5 个:E1 澄清 / E2 计算型 / E3 知识直返 / E4 证据约束生成 / E5 分级回退
- 转人工从"默认动作"降为最后一档 E5c,只保留 4 类白名单:
P0 反诈 / P1 账户与个人数据 / P2 写操作与争议 / 用户明确要求人工
- 46 条金标实测(修复前 → 修复后):
转人工率 43.5% → 10.9%;出口准确率 45.7% → 100%;事实正确率 69.6% → 100%
禁忌违反 1 → 0;档位越权 / 无出处数字 / 误拒 四项零容忍全 0
- 安全不变量 INV-1~INV-5;零容忍规则未删,改的是挂载点
(输出侧字面黑名单 → 检索层档位隔离 + 判定层合规词表 + 输出守护)
二、知识库:档位单点化与物理隔离
- 新增 app/core/knowledge_tier.py 作为档位规则唯一落点(G-03),
knowledge_contracts.py 原定义块改为显式再导出(X as X,非副本)
- 档位过滤由 bool 默认值(fail-open)改为 tiers 必填集合(缺参即 TypeError)
- Milvus 侧四集合按 visibility 分区键物理隔离;双 schema 收敛为一套
- 新增 app/core/actor.py:访客三元组与匿名判定的唯一构造/判定点(G-01/G-01b)
- 新增 app/core/fund_fee_rules.py:费率计算纯函数
三、前端入参边界对齐(本轮 W11 新修,4 处"校验宽于存储")
- message 加 max_length=8000(与浮窗 widget.js 的 maxlength 一致)
- session_id 加 1—64;idempotency_key 上限 128 → 64(对齐列宽 String(64))
- feedback_type 加 max_length=32(对齐列宽 String(32))
- 8 条路径参数补 min_length=1 + max_length=64 + 字符集正则
({session_id} / {run_id} / {handover_id})
- 改前超限值会落到 MySQL 才失败(500);改后一律 422 AGENT_INPUT_INVALID + 字段级定位
- 新增 tests/unit/api/test_frontend_boundaries.py(33 例),含"端点表 ↔ OpenAPI 全量对照"
四、投顾模块整体清除(D4.4 / D4.5)
- 删除投顾相关 controller / schema / model / repository / service 及门户页面
- tools/portal_api_check.py 同步作废 AD003/AD005/AD011/A047 四条用例与 advisor_t 登录
(端点与账号均已不存在,此前稳定报 3 条假红)
五、验证(提交前实测)
- pytest -q:1856 passed / 2 skipped / 0 failed
- ruff check app tools tests:19(= 基线);mypy app:2(= 基线)
- 前端接口契约体检 portal_api_check.py:38 项,通过 34,失败 0,跳过 4
- 全链路冒烟 e2e_smoke_test.py --read-only:31/31
- HTTP 全链路探针 http_probe.py:11/11 succeeded
- 跨文档一致性 _consistency.py:GATE PASS
- 真机边界复验 12 条:12/12 符合预期
六、纪律与文档
- 可改文件白名单 A-09(docs/46)与底座会签申请单 A-10(docs/47,组 1—组 4 全部受理)
- 零 DDL:未新增/修改任何表结构,89 张业务表与基线一致
- 证据留痕:docs/evidence/**(含 46 条金标 score、快照、清除与重建记录)
- 未提交(刻意排除,见提交说明):仓库内 客服agent/ 与 开发文档/ 是 2026-09-16 前的
过期副本(Todolist 440 行 vs 权威 D2.1 1167 行),权威正本在仓库外;
_chunks_report.txt 是 tools/build_knowledge_chunks.py 生成的本地产物
96 lines
3.8 KiB
Python
96 lines
3.8 KiB
Python
"""验证迁移前状态证据采集器只读取 Git 元数据。"""
|
|
|
|
# 导入测试所需的标准库 JSON、路径和子进程结果类型。
|
|
import json
|
|
from pathlib import Path
|
|
from subprocess import CompletedProcess
|
|
|
|
# 导入 pytest 补丁类型以及待验证的预检工具接口。
|
|
from pytest import MonkeyPatch
|
|
|
|
from tools.foundation_migration_preflight import (
|
|
collect_workspace_state,
|
|
run_git,
|
|
write_preflight_report,
|
|
)
|
|
|
|
|
|
# 验证未跟踪客服文件会被记录,且采集结果不含环境变量名称或值。
|
|
def test_collect_workspace_state_records_untracked_paths_without_environment_values(
|
|
tmp_path: Path,
|
|
) -> None:
|
|
# 构造确定性的 Git 命令替身,不调用真实 Git 或环境变量。
|
|
def fake_git_runner(_worktree: Path, *args: str) -> str:
|
|
# 为分支查询返回功能分支名称。
|
|
if args == ("branch", "--show-current"):
|
|
return "feature/knowledge-rag\n"
|
|
# 为提交查询返回固定的非敏感提交标识。
|
|
if args == ("rev-parse", "HEAD"):
|
|
return "abc123\n"
|
|
# 为状态查询返回一个未跟踪文件。
|
|
if args == ("status", "--short"):
|
|
return "?? app/service/agent/implementations/advisor.py\n"
|
|
# 防止测试静默接受未定义的 Git 查询。
|
|
raise AssertionError(f"unexpected git arguments: {args}")
|
|
|
|
# 使用替身采集临时工作区的只读状态。
|
|
state = collect_workspace_state(tmp_path, runner=fake_git_runner)
|
|
|
|
# 断言采集到预期的分支名称。
|
|
assert state["branch"] == "feature/knowledge-rag"
|
|
# 断言未跟踪文件完整保留在状态清单中。
|
|
assert state["status"] == ["?? app/service/agent/implementations/advisor.py"]
|
|
# 断言序列化结果不包含任何环境变量敏感字段。
|
|
assert "MYSQL_PASSWORD" not in json.dumps(state)
|
|
|
|
|
|
# 验证报告写入器只输出传入的非敏感 Git 状态结构。
|
|
def test_write_preflight_report_persists_utf8_json(tmp_path: Path) -> None:
|
|
# 指定临时报告文件,避免写入任何真实工作目录。
|
|
report_path = tmp_path / "preflight.json"
|
|
# 构造只含安全 Git 元数据的状态条目。
|
|
states = [{"path": "D:/workspace", "branch": "develop", "head": "abc123", "status": []}]
|
|
|
|
# 写入迁移前报告。
|
|
write_preflight_report(report_path, states)
|
|
|
|
# 以 UTF-8 读取并解析报告正文。
|
|
report = json.loads(report_path.read_text(encoding="utf-8"))
|
|
# 断言报告保留原始状态条目。
|
|
assert report == states
|
|
|
|
|
|
# 验证每次 Git 查询只信任当前显式工作区,而不写入全局 Git 配置。
|
|
def test_run_git_scopes_safe_directory_to_the_requested_worktree(
|
|
tmp_path: Path,
|
|
monkeypatch: MonkeyPatch,
|
|
) -> None:
|
|
# 保存被测函数交给子进程层的命令参数。
|
|
captured_commands: list[list[str]] = []
|
|
|
|
# 构造返回固定分支名的无副作用子进程替身。
|
|
def fake_run(command: list[str], **_kwargs: object) -> CompletedProcess[str]:
|
|
# 记录命令以便后续断言安全目录范围。
|
|
captured_commands.append(command)
|
|
# 返回模拟的 Git 成功结果。
|
|
return CompletedProcess(command, 0, "develop\n", "")
|
|
|
|
# 让测试不执行真实 Git。
|
|
monkeypatch.setattr("tools.foundation_migration_preflight.subprocess.run", fake_run)
|
|
|
|
# 执行一个受限 Git 分支查询。
|
|
output = run_git(tmp_path, "branch", "--show-current")
|
|
|
|
# 断言调用仍返回 Git 输出。
|
|
assert output == "develop\n"
|
|
# 断言命令仅为该临时工作区附加安全目录。
|
|
assert captured_commands == [[
|
|
"git",
|
|
"-c",
|
|
f"safe.directory={tmp_path.resolve().as_posix()}",
|
|
"-C",
|
|
str(tmp_path.resolve()),
|
|
"branch",
|
|
"--show-current",
|
|
]]
|