docs(gateway): gateway 剩余文件注释改中文(逐行 1:1,代码零字节改动)
主人 2026-10-03 拍板「注释一律中文」;gateway 至此整包注释中文化完成(本会话共 3 批: 已推库 16 个文件 + 本批剩余文件)。 校验:机械校验(非注释改动行)= 空;剥注释后代码文本逐行比对全等(不一致文件数 0); 全树 go test ./... 58 包 ok / 0 FAIL;交叉编译绿。
This commit is contained in:
1 parent
91e8d7a029
commit
074ffc4ebf
73 files changed
+2529
-2529
No files matched your search
@@ -25,9 +25,9 @@ func gwTestLogger() *slog.Logger {
|
||||
return slog.New(slog.NewTextHandler(io.Discard, nil))
|
||||
}
|
||||
|
||||
// newMemoryStoreForGateway opens an isolated in-memory SQLite DB and builds a
|
||||
// real memory.Store over it so the owner write path (which type-asserts to
|
||||
// *memory.Store) exercises the real Add.
|
||||
// newMemoryStoreForGateway 打开隔离的内存 SQLite DB,并在其上构建
|
||||
// 真实的 memory.Store,使 owner 写路径(它类型断言到
|
||||
// *memory.Store)演练真实的 Add。
|
||||
func newMemoryStoreForGateway(t *testing.T) *memory.Store {
|
||||
t.Helper()
|
||||
ctx := context.Background()
|
||||
@@ -97,7 +97,7 @@ func TestAdminAddMemoryWritesAndLists(t *testing.T) {
|
||||
t.Fatalf("added = %+v, want persona/她喜欢喝冰美式", added)
|
||||
}
|
||||
|
||||
// The freshly added item is now listed.
|
||||
// 刚添加的条目现在已被列出。
|
||||
listResp, listBody := doReq(t, http.MethodGet, ts.URL+"/api/v1/admin/memories", nil, tok)
|
||||
if listResp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("list status = %d, want 200 (body=%s)", listResp.StatusCode, listBody)
|
||||
@@ -117,13 +117,13 @@ func TestAdminAddMemoryRejectsBadInput(t *testing.T) {
|
||||
_, ts, jwt := buildEnv(t, cfgDefault(), Deps{Memories: store})
|
||||
tok := signAny(t, jwt, "acct", auth.RoleOwner)
|
||||
|
||||
// Blank content.
|
||||
// 空白内容。
|
||||
resp, _ := doReq(t, http.MethodPost, ts.URL+"/api/v1/admin/memories",
|
||||
map[string]any{"personaId": "cyrene", "content": " "}, tok)
|
||||
if resp.StatusCode != http.StatusBadRequest {
|
||||
t.Fatalf("blank content status = %d, want 400", resp.StatusCode)
|
||||
}
|
||||
// Invalid scope.
|
||||
// 非法 scope。
|
||||
resp2, _ := doReq(t, http.MethodPost, ts.URL+"/api/v1/admin/memories",
|
||||
map[string]any{"personaId": "cyrene", "content": "x", "scope": "bogus"}, tok)
|
||||
if resp2.StatusCode != http.StatusBadRequest {
|
||||
@@ -133,7 +133,7 @@ func TestAdminAddMemoryRejectsBadInput(t *testing.T) {
|
||||
|
||||
func TestAdminAddMemoryUnwired501(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, ts, jwt := buildEnv(t, cfgDefault(), Deps{}) // no memory store
|
||||
_, ts, jwt := buildEnv(t, cfgDefault(), Deps{}) // 无记忆存储
|
||||
tok := signAny(t, jwt, "acct", auth.RoleOwner)
|
||||
resp, _ := doReq(t, http.MethodPost, ts.URL+"/api/v1/admin/memories",
|
||||
map[string]any{"content": "x"}, tok)
|
||||
@@ -155,7 +155,7 @@ func TestAdminIndexRagImportsAndLists(t *testing.T) {
|
||||
t.Fatalf("index status = %d, want 201 (body=%s)", resp.StatusCode, body)
|
||||
}
|
||||
|
||||
// The document now shows up in the list (imported + chunked).
|
||||
// 该文档现在出现在列表中(已导入 + 已切分)。
|
||||
listResp, listBody := doReq(t, http.MethodGet, ts.URL+"/api/v1/admin/rag", nil, tok)
|
||||
if listResp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("list status = %d, want 200 (body=%s)", listResp.StatusCode, listBody)
|
||||
@@ -168,7 +168,7 @@ func TestAdminIndexRagImportsAndLists(t *testing.T) {
|
||||
t.Fatalf("documents = %+v, want one 内部知识库.md with 2 chunks", res.Documents)
|
||||
}
|
||||
|
||||
// It is immediately queryable (keyword/line path).
|
||||
// 它立即可查询(关键词/行路径)。
|
||||
qResp, qBody := doReq(t, http.MethodPost, ts.URL+"/api/v1/admin/rag/query",
|
||||
map[string]any{"query": "评审流程"}, tok)
|
||||
if qResp.StatusCode != http.StatusOK {
|
||||
@@ -214,9 +214,9 @@ func TestAdminIndexRagUnwired501(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// newLlmRuntimeForGateway builds a hot-swappable RuntimeLLM pointing at a fresh
|
||||
// temp models.json, seeded by the env config. It is the real stack the admin
|
||||
// write endpoint persists to and reloads.
|
||||
// newLlmRuntimeForGateway 构建一个可热切换的 RuntimeLLM,指向全新的
|
||||
// 临时 models.json,由环境配置播种。它就是管理写端点
|
||||
// 持久化并重载的真实栈。
|
||||
func newLlmRuntimeForGateway(t *testing.T, modelsPath string, env config.LLMConfig) *model.RuntimeLLM {
|
||||
t.Helper()
|
||||
return model.NewRuntimeLLM(modelsPath, env, gwTestLogger())
|
||||
@@ -247,7 +247,7 @@ func TestAdminAddLlmProviderPersistsAndReloads(t *testing.T) {
|
||||
t.Fatalf("add res = %+v", res)
|
||||
}
|
||||
|
||||
// models.json now holds the saved group (promoted to index 0 = active).
|
||||
// models.json 现在持有已保存的分组(提升到下标 0 = 活动)。
|
||||
groups, warn := runtimeconfig.LoadModels(modelsPath, env)
|
||||
if warn != nil {
|
||||
t.Fatalf("load models warn = %v", warn)
|
||||
@@ -256,12 +256,12 @@ func TestAdminAddLlmProviderPersistsAndReloads(t *testing.T) {
|
||||
t.Fatalf("file groups = %+v, want deepseek first with sk-ds and maxTokens 1234", groups)
|
||||
}
|
||||
|
||||
// The running stack reflects the new active provider/model (hot reload).
|
||||
// 运行中的栈反映了新的活动 provider/model(热重载)。
|
||||
if runtime.Provider() != "openai" || runtime.Model() != "deepseek-flash" {
|
||||
t.Fatalf("runtime Provider=%q Model=%q, want openai/deepseek-flash", runtime.Provider(), runtime.Model())
|
||||
}
|
||||
|
||||
// GET /admin/llm reflects the saved group and never leaks any API key.
|
||||
// GET /admin/llm 反映已保存的分组,且绝不泄露任何 API key。
|
||||
gResp, gBody := doReq(t, http.MethodGet, ts.URL+"/api/v1/admin/llm", nil, tok)
|
||||
if gResp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("get status = %d, want 200", gResp.StatusCode)
|
||||
@@ -286,7 +286,7 @@ func TestAdminAddLlmProviderSwitchProvider(t *testing.T) {
|
||||
_, ts, jwt := buildEnv(t, cfgDefault(), Deps{LLM: runtime})
|
||||
tok := signAny(t, jwt, "acct", auth.RoleOwner)
|
||||
|
||||
// Saving an anthropic group makes it the active provider/model.
|
||||
// 保存 anthropic 分组会使其成为活动的 provider/model。
|
||||
resp, body := doReq(t, http.MethodPost, ts.URL+"/api/v1/admin/llm",
|
||||
map[string]any{"provider": "anthropic", "baseUrl": "https://api.anthropic.com", "apiKey": "sk-ant", "model": "claude-sonnet-4"}, tok)
|
||||
if resp.StatusCode != http.StatusCreated {
|
||||
@@ -295,7 +295,7 @@ func TestAdminAddLlmProviderSwitchProvider(t *testing.T) {
|
||||
if runtime.Provider() != "anthropic" || runtime.Model() != "claude-sonnet-4" {
|
||||
t.Fatalf("runtime Provider=%q Model=%q, want anthropic/claude-sonnet-4", runtime.Provider(), runtime.Model())
|
||||
}
|
||||
// The saved group is active (index 0) and anthropic.
|
||||
// 已保存的分组是活动的(下标 0)且为 anthropic。
|
||||
if runtime.Group().Provider != "anthropic" {
|
||||
t.Fatalf("active group = %+v, want anthropic", runtime.Group())
|
||||
}
|
||||
@@ -309,16 +309,16 @@ func TestAdminAddLlmProviderPartialEditPreservesFields(t *testing.T) {
|
||||
_, ts, jwt := buildEnv(t, cfgDefault(), Deps{LLM: runtime})
|
||||
tok := signAny(t, jwt, "acct", auth.RoleOwner)
|
||||
|
||||
// Seed a fully-specified group.
|
||||
// 播种一个完整指定的分组。
|
||||
resp, body := doReq(t, http.MethodPost, ts.URL+"/api/v1/admin/llm",
|
||||
map[string]any{"id": "deepseek", "provider": "openai", "baseUrl": "https://api.deepseek.com/v1", "apiKey": "sk-ds", "model": "deepseek-flash", "multimodal": true, "fallback": "deepseek-v4-flash", "maxTokens": 1234}, tok)
|
||||
if resp.StatusCode != http.StatusCreated {
|
||||
t.Fatalf("seed status = %d, want 201 (body=%s)", resp.StatusCode, body)
|
||||
}
|
||||
|
||||
// Partial edit: only the model is given. Every omitted field must keep its
|
||||
// stored value — in particular maxTokens (a full replace reset it to 0) and
|
||||
// apiKey (a full replace wiped it).
|
||||
// 局部编辑:只给出 model。每个省略的字段都必须保持其
|
||||
// 已存值 —— 尤其是 maxTokens(整体替换会把它重置为 0)与
|
||||
// apiKey(整体替换会抹掉它)。
|
||||
resp2, body2 := doReq(t, http.MethodPost, ts.URL+"/api/v1/admin/llm",
|
||||
map[string]any{"id": "deepseek", "model": "deepseek-v4-pro"}, tok)
|
||||
if resp2.StatusCode != http.StatusCreated {
|
||||
@@ -352,13 +352,13 @@ func TestAdminAddLlmProviderRejectsBadInput(t *testing.T) {
|
||||
_, ts, jwt := buildEnv(t, cfgDefault(), Deps{LLM: runtime})
|
||||
tok := signAny(t, jwt, "acct", auth.RoleOwner)
|
||||
|
||||
// Missing model.
|
||||
// 缺少 model。
|
||||
resp, body := doReq(t, http.MethodPost, ts.URL+"/api/v1/admin/llm",
|
||||
map[string]any{"baseUrl": "https://x"}, tok)
|
||||
if resp.StatusCode != http.StatusBadRequest {
|
||||
t.Fatalf("missing model status = %d, want 400 (body=%s)", resp.StatusCode, body)
|
||||
}
|
||||
// Invalid provider.
|
||||
// 非法 provider。
|
||||
resp2, _ := doReq(t, http.MethodPost, ts.URL+"/api/v1/admin/llm",
|
||||
map[string]any{"provider": "bogus", "baseUrl": "https://x", "model": "m"}, tok)
|
||||
if resp2.StatusCode != http.StatusBadRequest {
|
||||
@@ -368,7 +368,7 @@ func TestAdminAddLlmProviderRejectsBadInput(t *testing.T) {
|
||||
|
||||
func TestAdminAddLlmProviderUnwired501(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, ts, jwt := buildEnv(t, cfgDefault(), Deps{}) // no LLM stack wired
|
||||
_, ts, jwt := buildEnv(t, cfgDefault(), Deps{}) // 未接线 LLM 栈
|
||||
tok := signAny(t, jwt, "acct", auth.RoleOwner)
|
||||
resp, _ := doReq(t, http.MethodPost, ts.URL+"/api/v1/admin/llm",
|
||||
map[string]any{"baseUrl": "https://x", "model": "m"}, tok)
|
||||
|
||||
Reference in new issue
Block a user