docs(gateway): gateway 剩余文件注释改中文(逐行 1:1,代码零字节改动)
CI / Backend (build / vet / test / cross-compile) (push) Has been cancelled
CI / Frontend (tsc + vite build) (push) Has been cancelled

主人 2026-10-03 拍板「注释一律中文」;gateway 至此整包注释中文化完成(本会话共 3 批:
已推库 16 个文件 + 本批剩余文件)。
校验:机械校验(非注释改动行)= 空;剥注释后代码文本逐行比对全等(不一致文件数 0);
全树 go test ./... 58 包 ok / 0 FAIL;交叉编译绿。
This commit is contained in:
AskaEth committed 2026-10-03 22:28:25 +08:00
1 parent 91e8d7a029
commit 074ffc4ebf
73 files changed
+2529 -2529

No files matched your search

@@ -13,13 +13,13 @@ import (
"git.yeij.top/AskaEth/Cyrene_v2/internal/runtime/model"
)
// This file covers the end-to-end half of design/22 §7-5: a session that switched
// roles must keep the conversation it had, and the model must be able to tell
// which utterances came from the earlier role. The chain asserted here is:
// chat_messages (per-message persona_id) → the orchestrator's seeded turn context
// → the loop's speaker attribution → the model.Request the adapter receives.
// 本文件覆盖 design/22 §7-5 的端到端一半:切换过角色的
// 会话必须保留它曾有过的对话,且模型必须能分辨
// 哪些话语来自更早的角色。这里断言的链条是:
// chat_messages(每消息 persona_id)→ 编排器播种的回合上下文
// → loop 的说话者归属 → 适配器收到的 model.Request。
// requestTexts returns the text of every message of req, in order.
// requestTexts 按顺序返回 req 每条消息的文本。
func requestTexts(req model.Request) []string {
out := make([]string, 0, len(req.Messages))
for _, m := range req.Messages {
@@ -28,7 +28,7 @@ func requestTexts(req model.Request) []string {
return out
}
// messageTextOf concatenates the text parts of m.
// messageTextOf 拼接 m 的文本部分。
func messageTextOf(m model.Message) string {
var b strings.Builder
for _, c := range m.Content {
@@ -39,11 +39,11 @@ func messageTextOf(m model.Message) string {
return b.String()
}
// TestChatTurnCarriesSpeakerAttributionFromTranscript is design/22 §7-5 accepted
// from the process boundary: the session already holds turns spoken by role X, it
// is now bound to role Y, and one more chat turn arrives. The request must carry
// X's earlier utterance with its speaker attributed to X (not to Y), keep every
// stored body verbatim, and still open with Y's own instructions.
// TestChatTurnCarriesSpeakerAttributionFromTranscript 是从进程边界验收的
// design/22 §7-5:该会话已持有角色 X 说过的话,它现在
// 绑定到角色 Y,且又来了一个聊天回合。请求必须携带
// X 更早的话语且其说话者归属到 X(不是 Y),原样保留每个
// 已存消息体,并仍以 Y 自己的指令开头。
func TestChatTurnCarriesSpeakerAttributionFromTranscript(t *testing.T) {
t.Parallel()
ctx := context.Background()
@@ -53,8 +53,8 @@ func TestChatTurnCarriesSpeakerAttributionFromTranscript(t *testing.T) {
if err != nil {
t.Fatalf("NewSubSessionFor: %v", err)
}
// The conversation as it stood while the session spoke as X, with per-message
// persona ids exactly as the orchestrator persists them (design/22 §7-5).
// 该会话以 X 说话时的对话原貌,每消息
// persona id 与编排器持久化的完全一致(design/22 §7-5)。
for _, m := range []history.Message{
{SessionID: sub, Role: history.RoleUser, Content: "你还记得吗", PersonaID: "xilian", CreatedAt: 1000},
{SessionID: sub, Role: history.RoleAssistant, Content: "我记住了,你喜欢冰美式", PersonaID: "xilian", CreatedAt: 1001},
@@ -86,13 +86,13 @@ func TestChatTurnCarriesSpeakerAttributionFromTranscript(t *testing.T) {
}
req := ad.reqs[len(ad.reqs)-1]
// The answering role still owns the head of the prompt.
// 应答角色仍然占据提示词的开头。
if got := firstSystemText(req); got != "你是由纪。" {
t.Fatalf("first system = %q, want role Y's prompt", got)
}
// X's earlier utterance reached the model, verbatim (the turn is not amnesiac
// across the role switch).
// X 更早的话语原样抵达了模型(该回合没有
// 在角色切换处失忆)。
texts := requestTexts(req)
xIdx := -1
for i, txt := range texts {
@@ -111,7 +111,7 @@ func TestChatTurnCarriesSpeakerAttributionFromTranscript(t *testing.T) {
t.Fatalf("speaker label = %q, want xilian (the role that actually spoke it)", req.Messages[xIdx].SenderName)
}
// The speaker boundary names X and marks the stretch as not Y's own words.
// 说话者边界点明 X,并把那一段标记为不是 Y 自己的话。
note := ""
for _, m := range req.Messages {
if m.Role == model.RoleSystem && strings.Contains(messageTextOf(m), "「昔涟」(xilian)") {
@@ -123,8 +123,8 @@ func TestChatTurnCarriesSpeakerAttributionFromTranscript(t *testing.T) {
t.Fatalf("no speaker boundary for X found: %q", texts)
}
// No stored body was rewritten, and the newly sent user text carries no system
// metadata (the user lane stays free text, design/11 §10).
// 没有任何已存消息体被改写,且新发送的用户文本不携带 system
// 元数据(用户通道保持自由文本,design/11 §10)。
for _, m := range req.Messages {
if m.Role != model.RoleUser {
continue