chore: 规范标点
This commit is contained in:
1 parent
e54390a9f8
commit
15e79887fa
84 files changed
+5439
-5398
No files matched your search
+19
-19
@@ -70,7 +70,7 @@ static JsonValue *sample(void)
|
||||
json_array_push(a, msg("tool", "file1\nfile2"));
|
||||
json_array_push(a, msg("assistant", "写好了"));
|
||||
json_array_push(a, msg("user", "改用 C"));
|
||||
json_array_push(a, msg("assistant", "好的,改成 C"));
|
||||
json_array_push(a, msg("assistant", "好的, 改成 C"));
|
||||
json_array_push(a, msg("user", "加个注释"));
|
||||
json_array_push(a, msg("assistant", "加好了"));
|
||||
return a;
|
||||
@@ -82,11 +82,11 @@ static void test_rounds(void)
|
||||
JsonValue *m = sample();
|
||||
MetaRounds r;
|
||||
CHECK(meta_rounds_build(m, &r) == 1, "应该能切出轮次");
|
||||
CHECK(r.head == 1, "system 之后的 #1 才是第一条可编辑消息,实际 %zu", r.head);
|
||||
CHECK(r.count == 3, "应切出 3 轮,实际 %zu", r.count);
|
||||
CHECK(r.starts[0] == 1, "轮 1 从 #1 开始,实际 %zu", r.starts[0]);
|
||||
CHECK(r.starts[1] == 5, "轮 2 从 #5 开始,实际 %zu", r.starts[1]);
|
||||
CHECK(r.starts[2] == 7, "轮 3 从 #7 开始,实际 %zu", r.starts[2]);
|
||||
CHECK(r.head == 1, "system 之后的 #1 才是第一条可编辑消息, 实际 %zu", r.head);
|
||||
CHECK(r.count == 3, "应切出 3 轮, 实际 %zu", r.count);
|
||||
CHECK(r.starts[0] == 1, "轮 1 从 #1 开始, 实际 %zu", r.starts[0]);
|
||||
CHECK(r.starts[1] == 5, "轮 2 从 #5 开始, 实际 %zu", r.starts[1]);
|
||||
CHECK(r.starts[2] == 7, "轮 3 从 #7 开始, 实际 %zu", r.starts[2]);
|
||||
meta_rounds_free(&r);
|
||||
|
||||
/* 没有 system 也要能切 */
|
||||
@@ -94,7 +94,7 @@ static void test_rounds(void)
|
||||
json_array_push(n, msg("user", "x"));
|
||||
json_array_push(n, msg("assistant", "y"));
|
||||
CHECK(meta_rounds_build(n, &r) == 1, "没有 system 也能切");
|
||||
CHECK(r.head == 0 && r.count == 1, "1 轮,从头开始");
|
||||
CHECK(r.head == 0 && r.count == 1, "1 轮, 从头开始");
|
||||
meta_rounds_free(&r);
|
||||
json_free(n);
|
||||
|
||||
@@ -106,13 +106,13 @@ static void test_rounds(void)
|
||||
json_free(only);
|
||||
|
||||
/* read_image 补的那条"只有图片附件、没有文字"的 user 消息**不算新的一轮** ——
|
||||
* 判据必须与主循环(agent_opens_round)一致,否则 /meta 报的轮号会和主循环的
|
||||
* 口径对不上,模型照轮号删下去,删掉的不是它以为的那一轮。
|
||||
* 判据必须与主循环 (agent_opens_round)一致, 否则 /meta 报的轮号会和主循环的
|
||||
* 口径对不上, 模型照轮号删下去, 删掉的不是它以为的那一轮.
|
||||
* 结构:system / user(text) / assistant(tool_calls) / tool / user(只有图) / assistant */
|
||||
JsonValue *withimg = json_new_array();
|
||||
json_array_push(withimg, msg("system", "s"));
|
||||
json_array_push(withimg, msg("user", "看图"));
|
||||
json_array_push(withimg, msg("assistant", "ok")); /* 占位,模拟带 tool_calls 的轮内消息 */
|
||||
json_array_push(withimg, msg("assistant", "ok")); /* 占位, 模拟带 tool_calls 的轮内消息 */
|
||||
json_array_push(withimg, msg("tool", "结果"));
|
||||
{
|
||||
JsonValue *att = json_new_object();
|
||||
@@ -126,7 +126,7 @@ static void test_rounds(void)
|
||||
}
|
||||
json_array_push(withimg, msg("assistant", "看到图了"));
|
||||
CHECK(meta_rounds_build(withimg, &r) == 1, "带附件的历史也应该能切");
|
||||
CHECK(r.count == 1, "只有附件的那条 user 不该算新的一轮,实际 %zu 轮", r.count);
|
||||
CHECK(r.count == 1, "只有附件的那条 user 不该算新的一轮, 实际 %zu 轮", r.count);
|
||||
meta_rounds_free(&r);
|
||||
json_free(withimg);
|
||||
|
||||
@@ -159,7 +159,7 @@ static char *call(Agent *a, const char *name, const char *json)
|
||||
return r;
|
||||
}
|
||||
|
||||
/* 把一段历史挂上,跑 body,再摘下来 */
|
||||
/* 把一段历史挂上, 跑 body, 再摘下来 */
|
||||
#define WITH_TOOLS(a) \
|
||||
do { \
|
||||
CHECK(meta_tools_attach(a) == 0, "attach 应成功"); \
|
||||
@@ -223,13 +223,13 @@ static void test_delete_safety(void)
|
||||
CHECK(json_array_size(a.messages) == before, "仍不该改动");
|
||||
free(r);
|
||||
|
||||
/* 一条合法一条非法:整批都不该动(先校验后执行) */
|
||||
/* 一条合法一条非法:整批都不该动 (先校验后执行) */
|
||||
r = call(&a, "delete_messages", "{\"indices\":[1,2]}");
|
||||
CHECK(r && strstr(r, "不可拆") != NULL, "混了非法项应整体拒绝");
|
||||
CHECK(json_array_size(a.messages) == before, "整体拒绝时不该改一半");
|
||||
free(r);
|
||||
|
||||
/* 合法删除:删掉第 1 轮里那句 user,并给上下文提示 */
|
||||
/* 合法删除:删掉第 1 轮里那句 user, 并给上下文提示 */
|
||||
r = call(&a, "delete_messages", "{\"indices\":[1]}");
|
||||
CHECK(r && strstr(r, "已删除 1 条") != NULL, "合法删除应成功:%s", r ? r : "");
|
||||
CHECK(strstr(r, "没有对应的提问") != NULL, "删掉提问后应提示后续回答失去上下文");
|
||||
@@ -298,7 +298,7 @@ static void test_insert_and_undo(void)
|
||||
free(r);
|
||||
|
||||
/* 撤销应回到插入前 */
|
||||
CHECK(meta_tools_ops() == 1, "应有 1 次改动,实际 %zu", meta_tools_ops());
|
||||
CHECK(meta_tools_ops() == 1, "应有 1 次改动, 实际 %zu", meta_tools_ops());
|
||||
r = call(&a, "undo_last_edit", "{}");
|
||||
CHECK(r && strstr(r, "已撤销") != NULL, "撤销应成功");
|
||||
CHECK(json_array_size(a.messages) == before, "撤销后条数应还原");
|
||||
@@ -315,7 +315,7 @@ static void test_insert_and_undo(void)
|
||||
|
||||
static void test_read_tools(void)
|
||||
{
|
||||
puts("list_rounds / read_messages(只读)");
|
||||
puts("list_rounds / read_messages (只读)");
|
||||
Agent a; agent_init(&a);
|
||||
json_free(a.messages); a.messages = sample();
|
||||
meta_tools_attach(&a);
|
||||
@@ -333,7 +333,7 @@ static void test_read_tools(void)
|
||||
r = call(&a, "read_messages", "{\"from\":2,\"to\":3}");
|
||||
CHECK(r && strstr(r, "run_command") != NULL, "应能看到工具调用");
|
||||
CHECK(r && strstr(r, "file1") != NULL, "应能看到工具结果");
|
||||
CHECK(r && strstr(r, "结构消息,不可单删") != NULL, "结构消息应有标注");
|
||||
CHECK(r && strstr(r, "结构消息, 不可单删") != NULL, "结构消息应有标注");
|
||||
free(r);
|
||||
|
||||
CHECK(meta_tools_mutating("list_rounds") == 0, "list_rounds 不是写操作");
|
||||
@@ -359,7 +359,7 @@ static void test_reroot_flag(void)
|
||||
CHECK(meta_reroot_pending() == 0, "初始不该有标记");
|
||||
|
||||
meta_tools_attach(&a);
|
||||
char *r = call(&a, "list_rounds", "{}"); /* 只读,不该打标记 */
|
||||
char *r = call(&a, "list_rounds", "{}"); /* 只读, 不该打标记 */
|
||||
free(r);
|
||||
CHECK(meta_reroot_pending() == 0, "只读操作不该打标记");
|
||||
|
||||
@@ -382,6 +382,6 @@ int main(void)
|
||||
test_delete_rounds();
|
||||
test_insert_and_undo();
|
||||
test_reroot_flag();
|
||||
printf("\n%d 项检查,%d 项失败\n", checks, failures);
|
||||
printf("\n%d 项检查, %d 项失败\n", checks, failures);
|
||||
return failures ? 1 : 0;
|
||||
}
|
||||
Reference in new issue
Block a user