一次收口 2026-11-06 的九项能力(CHANGELOG 1.5.4 → 1.8.0): - 自检探针(readiness.go):check_readiness / check_answerable 两个只读探针,把 「本体里没有」「我没权限看」「模型没抽全」三种空结果原因拆开 - 读路径语义钉死(scope.go):标记与分级的可见范围统一由 Scope 产出,实例分级 为空时继承类型默认级(fail-closed),列表与详情口径一致 - 行级可改性轴(object_owner.go):归属只收窄不宽于 grants,所有对象写路径统一 走 canWriteObject,归属查询失败即拒绝 - 公理第 6 类 certification:认证位保护人工策展内容,AI 重摄取不再覆盖已认证条目 - 跨版本结构 diff(schema_diff.go):schema_snapshots 全量快照 + diff 端点,机器 事实与人工策展分组呈现 - 分区维度 zone:分区绑类型、命中任一即可见,读路径一律带 zone 条件 - 统一分页信封(pagination.go):列表回包统一 count/total/limit/offset/has_more/ truncated,total 与 items 同源 - MCP 长任务进度(mcp_progress.go):客户端带 progressToken 才走 SSE 进度帧 - 本体 schema 导入(ontology_import.go):Turtle 导入 + 四道 fail-fast 闸门 + 整事务 + (source, external_id) 幂等 + IRI 往返不变式 MCP 工具清单并入单一注册表(mcp_registry.go),对外声明与实际可调不再各说各话; 工具数 42 → 54(只读 27 / 写入 27),注册表与分发 case 的双向漂移由 AST 单测拦截。 CHANGELOG 编号整理:新「认证位 + 行级归属」条目由 1.6.0 改为 1.5.6(1.6.x 留给 分区与结构 diff),2026-09-20 的 GB/T 规划稿改标「规划稿·未发布」——该能力已并入 v1.5.1,避免与正式发布的版本号重复。 Co-Authored-By: Claude Code <[email protected]>
84 lines
3.0 KiB
Go
84 lines
3.0 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
// TestBuildClarificationItems 澄清项的结构化组装(纯函数):
|
|
//
|
|
// 未覆盖片段 + 近似候选 → 一条条 {term, candidates, suggested_question}。
|
|
// 没有候选时也要给一句可执行的建议问法(不能只丢一个空壳)。
|
|
func TestBuildClarificationItems(t *testing.T) {
|
|
uncovered := []string{"火星基地", "氧气含量"}
|
|
cands := []answerableMatch{
|
|
{Term: "火星基地", Label: "火星基地一期", Kind: "instance", PK: "m1"},
|
|
{Term: "火星基地", Label: "火星基地二期", Kind: "instance", PK: "m2"},
|
|
{Term: "氧气含量", Label: "", Kind: "instance", PK: "m3"}, // 无显示名 → 不进候选
|
|
}
|
|
items := buildClarificationItems(uncovered, cands)
|
|
if len(items) != 2 {
|
|
t.Fatalf("澄清项数量不符:实到 %d", len(items))
|
|
}
|
|
if items[0].Term != "火星基地" {
|
|
t.Errorf("第一项的 term 应为「火星基地」,实到 %q", items[0].Term)
|
|
}
|
|
if len(items[0].Candidates) != 2 {
|
|
t.Errorf("候选应按 term 归组,实到 %v", items[0].Candidates)
|
|
}
|
|
if items[0].SuggestedQuestion == "" {
|
|
t.Error("有候选时应给出建议问法")
|
|
}
|
|
if len(items[1].Candidates) != 0 {
|
|
t.Errorf("无候选时 candidates 应为空数组,实到 %v", items[1].Candidates)
|
|
}
|
|
if items[1].Candidates == nil {
|
|
t.Error("candidates 应是空数组而不是 null(避免消费方判 nil)")
|
|
}
|
|
if items[1].SuggestedQuestion == "" {
|
|
t.Error("无候选时也应给出建议问法")
|
|
}
|
|
}
|
|
|
|
// TestBuildClarificationItemsEmpty 没有未覆盖片段 → 没有澄清项(不是空壳)。
|
|
func TestBuildClarificationItemsEmpty(t *testing.T) {
|
|
items := buildClarificationItems(nil, nil)
|
|
if len(items) != 0 {
|
|
t.Errorf("无未覆盖片段时不应有澄清项,实到 %v", items)
|
|
}
|
|
}
|
|
|
|
// TestEmptyReasonNoMatch 检索空结果的保守说明:跨类型无法归因,只给下一步。
|
|
func TestEmptyReasonNoMatch(t *testing.T) {
|
|
r := emptyReasonNoMatch("火星基地")
|
|
if r.Code != emptyCodeNoMatch {
|
|
t.Errorf("code 应为 %s,实到 %s", emptyCodeNoMatch, r.Code)
|
|
}
|
|
if r.Detail == "" || r.Remedy == "" {
|
|
t.Errorf("检索空结果应同时有说明与下一步,实到 %+v", r)
|
|
}
|
|
}
|
|
|
|
// TestSnapshotOf 没有快照头 → 空串(不能返回一个假的快照标识)。
|
|
func TestSnapshotOf(t *testing.T) {
|
|
if got := snapshotOf(nil); got != "" {
|
|
t.Errorf("nil context 应返回空串,实到 %q", got)
|
|
}
|
|
if got := snapshotOf(context.Background()); got != "" {
|
|
t.Errorf("普通 context 应返回空串,实到 %q", got)
|
|
}
|
|
}
|
|
|
|
// TestAuthzPrincipal 取主体名:nil → public,空串 → public。
|
|
func TestAuthzPrincipal(t *testing.T) {
|
|
if got := authzPrincipal(nil); got != "public" {
|
|
t.Errorf("nil authz 应返回 public,实到 %q", got)
|
|
}
|
|
if got := authzPrincipal(&Authz{}); got != "public" {
|
|
t.Errorf("空主体应返回 public,实到 %q", got)
|
|
}
|
|
if got := authzPrincipal(&Authz{Principal: "connector"}); got != "connector" {
|
|
t.Errorf("应返回主体名,实到 %q", got)
|
|
}
|
|
}
|