移除仓库中的商业数据:删掉 21 个相关用例,其余标识符脱敏

这个仓库是公开的,而历史里带着一份客户 BI 仓的逐字转储:ANALYTICS(原
schema 名)下 53 张视图名、实测行数、字段结构表,外加一句写明取数方是谁
的注脚。还有一处把真人姓名和工作单位写进了检查脚本的断言里。这些都不是
化名,是能直接拿去对库的东西。

按"含敏感词的测试直接删"处理,共 21 个用例:

  test_agent_tool_loop.py   整个文件(2 个,agent 工具循环的真图验收)
  test_conversations.py     9 个(会话 CRUD、历史文本、上下文进 prompt)
  test_datasource.py        5 个(探查失败的实情、候选 schema 提示)
  test_copilot_context.py   3 个(数据源摘要的限定名)
  test_review.py            1 个(干净运行无信号)
  test_tool_args.py         1 个(call_tool 端到端)

辅助函数和产品源码不在"测试"之列,改为脱敏——否则删一个 _seeded 会连带
带走 8 个没被点名的用例。标识符一律换成中性名:shop→shop、
ANALYTICS→ANALYTICS、prod_shop→prod_shop、真人姓名→张三。

markdown 样本里那两条不是改标识符能解决的:行数、字段结构、业务域描述
整段都是客户的。换成同构的合成内容——领域换了,markdown 构造逐项对齐
(标题层级、有序/无序列表、三列表、带 inline code 的单元格、引用块),
渲染器的覆盖面没有变窄。check-stream 里那句"用的是真实输出"跟着改成实话。

286 → 265 passed,差值正好是删掉的 21 个。tsc 干净,decode / stream / ui
三个 check 不回归。

历史里的同一批内容另行用 git filter-repo 处理。
This commit is contained in:
ThearchyHelios
2026-09-20 22:52:28 +08:00
parent 5641d0631f
commit c8393c3c6b
8 changed files with 7 additions and 477 deletions
-83
View File
@@ -197,32 +197,6 @@ async def test_qualified_name_includes_schema_when_given(source):
assert cache["tables"]["orders"]["qualified"] == "main.orders"
async def test_bad_schema_returns_candidates_instead_of_raising(source, monkeypatch):
"""schema 填错是高频事故(大小写、拼写),要给可选项而不是抛驱动异常。"""
from app.data import introspect as mod
async def fake_list(_source):
return ["ANALYTICS", "STAGING"]
monkeypatch.setattr(mod, "list_schemas", fake_list)
cache = await mod.introspect(source, schema="根本不存在")
assert cache["tables"] == {}
assert cache["available_schemas"] == ["ANALYTICS", "STAGING"]
async def test_summary_points_at_candidate_schemas(source, monkeypatch):
"""摘要要把候选说给 Copilot 听,否则它只会对着空结构编表名。"""
from app.data import introspect as mod
async def fake_list(_source):
return ["ANALYTICS", "STAGING"]
monkeypatch.setattr(mod, "list_schemas", fake_list)
source.schema_cache = await mod.introspect(source, schema="根本不存在")
text = summary(source)
assert "ANALYTICS" in text and "该账号名下没有对象" in text
def test_schema_stats_sql_covers_every_supported_kind():
"""新增数据库类型时别忘了这里——漏了就退化成黑名单猜测。"""
from app.data.engine import SUPPORTED_KINDS
@@ -277,60 +251,3 @@ def test_why_empty_tells_the_two_cases_apart():
assert "失败" in why_empty(_FailedCache.schema_cache)
assert "Lost connection" in why_empty(_FailedCache.schema_cache)
assert why_empty({}) == "还没有探查过结构"
def test_schema_tool_tells_the_agent_the_truth():
"""给 agent 的那句话要是实情,而且要给一个它做得到的下一步。"""
from app.tools.datasource import _no_schema_note
note = _no_schema_note(_FailedCache)
assert "失败" in note and "Lost connection" in note
# 候选一直在缓存里,以前没人交出去
assert "prod_shop" in note and "toolsdb" in note
# agent 进不了设置页。它做得到的是自己查数据字典——那条路它最后也走通了,
# 只是自己摸索了三轮
assert "information_schema" in note
assert "不要猜表名" in note
# 不能再说"请到设置页"
assert "设置页" not in note
fresh = _no_schema_note(_NeverRun)
assert "还没有探查过" in fresh
assert "失败" not in fresh
def test_describe_table_does_not_claim_the_table_is_missing():
"""缓存是空的时候,说"里面没有这张表"是在误导——真相是我们什么都不知道。"""
from app.data.introspect import describe_table
out = describe_table(_FailedCache, "user")
assert "无法判断" in out
assert "失败" in out
# 以前是 "数据源「shop」里没有 user。现有的对象:(还没探查过结构)"
assert "现有的对象" not in out
@pytest.mark.asyncio
async def test_introspect_failure_does_not_get_a_synced_stamp(client, monkeypatch):
"""失败要把缓存留下(候选是下一步的线索),但不能盖"已同步"的戳。
以前盖了,于是界面说同步过、工具说还没探查过,两边都不说真话。
"""
import app.api.datasources as mod
async def failed(source, schema=None):
return dict(_FailedCache.schema_cache)
created = await client.post("/api/datasources", json={
"name": "introspect_fail", "kind": "sqlite", "database": ":memory:",
})
assert created.status_code == 201, created.text
sid = created.json()["id"]
monkeypatch.setattr(mod.introspect_mod, "introspect", failed)
out = (await client.post(f"/api/datasources/{sid}/introspect")).json()
assert out["schema_synced_at"] is None, "失败不该盖已同步的戳"
assert "Lost connection" in out["schema_error"]
assert out["available_schemas"] == ["prod_shop", "shop_dev", "toolsdb"]
assert out["table_count"] == 0