chore: 规范标点

This commit is contained in:
pluv committed 2026-10-03 14:56:56 +08:00
1 parent 15e79887fa
commit 3dd2231c70
81 files changed
+1751 -1751

No files matched your search

+15 -15
View File
@@ -77,7 +77,7 @@ static char *dump_history(const Agent *a)
return json_dump(a->messages);
}
/* 配对不变量:任何 assistant(tool_calls) 后面必须**紧跟**同 id 的 tool 消息.
/* 配对不变量: 任何 assistant(tool_calls) 后面必须**紧跟**同 id 的 tool 消息.
* 服务端就是这么要求的, 违反了下一轮直接 400 —— 所以每次动过历史之后都要查. */
static void check_pairing(Agent *a)
{
@@ -100,7 +100,7 @@ static void check_pairing(Agent *a)
/* 一轮一轮摘下去 (/back 走的就是这条路), 历史在每一步都必须仍然自洽.
*
* 这里原来测的是"上下文超限自动裁剪" (agent_drop_oldest_round)—— 那套机制
* 已经**整个删掉**:它的判据只是错误文案里的关键词, 却会不可逆地删掉最老的
* 已经**整个删掉**: 它的判据只是错误文案里的关键词, 却会不可逆地删掉最老的
* 几轮对话. 现在超限就是如实报错、历史一个字节都不动, 怎么处理由用户决定
* (/back 摘一轮、/reset 重来). 但"摘掉一整轮之后 tool 配对不能散"这条
* 不变量与由谁触发无关, 所以留着继续测. */
@@ -160,7 +160,7 @@ static void test_take_last_round(void)
free(h);
json_free(r);
/* 关键:工具调用与结果必须整组一起走 */
/* 关键: 工具调用与结果必须整组一起走 */
r = agent_take_last_round(&a);
CHECK(r && json_array_size(r) == 4, "第一轮应 4 条, 实际 %zu",
r ? json_array_size(r) : 0);
@@ -188,7 +188,7 @@ static void test_take_last_round(void)
}
/* ------------------------------------------------------------------ */
/* 结构体检:assistant(tool_calls) 与 tool 消息的配对 */
/* 结构体检: assistant(tool_calls) 与 tool 消息的配对 */
/* ------------------------------------------------------------------ */
/* 造一条 assistant, 带 count 个工具调用 (id 依次是 c0, c1, ...) */
@@ -262,7 +262,7 @@ static void test_repair_pairing(void)
{
int fixed = 0;
puts("结构体检:本来没问题就不该动它");
puts("结构体检: 本来没问题就不该动它");
JsonValue *ok = json_new_array();
json_array_push(ok, mk_plain("user", "跑一下"));
json_array_push(ok, mk_assistant(2));
@@ -275,8 +275,8 @@ static void test_repair_pairing(void)
CHECK(fixed == 0, "合法历史的修复处数应为 0");
json_free(ok);
puts("缺 tool 消息:补齐, 且补在原位");
/* 复现真实报错:assistant 带两个调用, 中间夹了一条 user (图省事直接
puts("缺 tool 消息: 补齐, 且补在原位");
/* 复现真实报错: assistant 带两个调用, 中间夹了一条 user (图省事直接
* 模仿当年那个 bug 的形状), 第二个调用没人回应 */
JsonValue *bad = json_new_array();
json_array_push(bad, mk_plain("user", "看看图"));
@@ -289,9 +289,9 @@ static void test_repair_pairing(void)
CHECK(r != NULL, "对不上时应该返回重建好的数组");
if (r) {
CHECK(pairing_ok(r), "修完之后配对必须成立");
/* 两处:给 c1 补一条占位 (它没被回应), 再把错位的那条 c1 结果丢掉
/* 两处: 给 c1 补一条占位 (它没被回应), 再把错位的那条 c1 结果丢掉
* (它被 user 消息隔开, 已经不在 tool 段里了 —— 留着就是孤儿).
* 丢掉真实结果听着可惜, 但结构坏了只能二选一:要么丢它, 要么留一段
* 丢掉真实结果听着可惜, 但结构坏了只能二选一: 要么丢它, 要么留一段
* 服务端必然拒绝的历史. 模型会从占位消息里知道该重跑. */
CHECK(fixed == 2, "应补 1 处、丢 1 处孤儿, 实际 %d", fixed);
CHECK(json_array_size(r) == 5,
@@ -307,7 +307,7 @@ static void test_repair_pairing(void)
}
json_free(bad);
puts("末尾悬空:assistant 之后再没有消息");
puts("末尾悬空: assistant 之后再没有消息");
JsonValue *tail = json_new_array();
json_array_push(tail, mk_plain("user", "跑一下"));
json_array_push(tail, mk_assistant(1));
@@ -317,7 +317,7 @@ static void test_repair_pairing(void)
json_free(r);
json_free(tail);
puts("孤儿 tool 消息:没有对应的 tool_calls, 要丢掉");
puts("孤儿 tool 消息: 没有对应的 tool_calls, 要丢掉");
JsonValue *orphan = json_new_array();
json_array_push(orphan, mk_plain("user", "你好"));
json_array_push(orphan, mk_tool("谁也不是"));
@@ -343,19 +343,19 @@ static void test_repair_pairing(void)
}
/* ------------------------------------------------------------------ */
/* 面向用户的历史口径:不含 system */
/* 面向用户的历史口径: 不含 system */
/* ------------------------------------------------------------------ */
static void test_conversation_len(void)
{
puts("历史条数:system 是配置, 不该算进对话");
puts("历史条数: system 是配置, 不该算进对话");
Agent a;
agent_init(&a);
CHECK(agent_history_len(&a) == 0, "空 agent 的数组长度是 0");
CHECK(agent_conversation_len(&a) == 0, "空 agent 的对话长度也是 0");
/* 只有 system:数组里 1 条, 但对话是空的 */
/* 只有 system: 数组里 1 条, 但对话是空的 */
agent_add_system(&a, "你是助手");
CHECK(agent_history_len(&a) == 1, "只有 system 时数组长度 1");
CHECK(agent_conversation_len(&a) == 0,
@@ -395,7 +395,7 @@ int main(void)
agent_add_user(&a, "U1");
CHECK(agent_history_len(&a) == 2, "应 2 条");
/* 关键不变量:重复设置 system 应替换而不是追加 */
/* 关键不变量: 重复设置 system 应替换而不是追加 */
agent_add_system(&a, "S2");
CHECK(count_role(&a, "system") == 1, "重复设置 system 不应叠加, 实际 %zu 条",
count_role(&a, "system"));