mirror of
https://github.com/RuoJi6/ARTEX.git
synced 2026-10-27 17:03:49 +08:00
on_tool_call 等事件触发在 merge 时,每条事件都重复整段任务描述+目标; 当任务目标很长(如续跑继承事实)且短时间多次触发时,合并消息体积爆炸 (实测 39 条 submit_flag 连击 → 十几万字)。 - triggeredRun 拆出 taskDesc/taskGoal 任务级字段,message 只留事件正文 - by_task 合并:同任务头只写一次 - all 合并:按任务分组(首次出现排序、任务内保序),每任务头只写一次, 交错触发也不重复 - 单条触发由 finalTriggerMessage 补一次任务头 - 任务描述截 200 字、目标截 500 字,单份也有界 - 新增 trigger_merge_test.go 覆盖去重/交错/截断/定时无头
99 lines
4.0 KiB
Go
99 lines
4.0 KiB
Go
package server
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// A long task goal repeated per event was the dominant bloat. These tests pin the
|
|
// fix: the task-context header (description + goal) is rendered ONCE per task, no
|
|
// matter how many same-task fires are merged.
|
|
|
|
const longGoal = "拿到题目 f2-05 的受保护 flag 并通过 submit_flag 提交;本题密文已高度收敛,flag 只能由二进制内嵌数据派生……" // 代表那段几千字的继承事实
|
|
|
|
func sameTaskFires(n int) []triggeredRun {
|
|
items := make([]triggeredRun, n)
|
|
for i := range items {
|
|
items[i] = triggeredRun{
|
|
agentKey: "tec_benchmark", taskID: 72, taskDesc: "f2-05 逆向", taskGoal: longGoal,
|
|
message: "【本次由工具调用触发】\n工具: submit_flag\n入参: {...}\n返回: {correct:false}", mergeable: true,
|
|
}
|
|
}
|
|
return items
|
|
}
|
|
|
|
func TestMergeAllRunsWritesTaskGoalOnce(t *testing.T) {
|
|
out := mergeAllRuns(sameTaskFires(39))
|
|
if got := strings.Count(out.message, longGoal); got != 1 {
|
|
t.Fatalf("same-task goal should appear exactly once in a merged-all run, got %d", got)
|
|
}
|
|
if strings.Count(out.message, "── 触发 ") < 1 || !strings.Contains(out.message, "触发 39") {
|
|
t.Fatalf("all 39 event bodies should be present: %q", out.message)
|
|
}
|
|
// A merged run embeds its header inline, so finalTriggerMessage must not re-add it.
|
|
if out.taskDesc != "" || out.taskGoal != "" {
|
|
t.Fatalf("merged run must clear taskDesc/taskGoal to avoid a duplicate header")
|
|
}
|
|
if finalTriggerMessage(out) != out.message {
|
|
t.Fatalf("finalTriggerMessage must not prepend another header for a merged run")
|
|
}
|
|
}
|
|
|
|
func TestMergeAllRunsGroupsInterleavedTasks(t *testing.T) {
|
|
// Fires from two tasks arriving interleaved (A,B,A,B) must still carry each
|
|
// task's context exactly once — grouping, not per-event repetition.
|
|
mk := func(id int64, goal string) triggeredRun {
|
|
return triggeredRun{agentKey: "a", taskID: id, taskDesc: "d", taskGoal: goal, message: "body", mergeable: true}
|
|
}
|
|
out := mergeAllRuns([]triggeredRun{mk(1, "GOAL_A"), mk(2, "GOAL_B"), mk(1, "GOAL_A"), mk(2, "GOAL_B")})
|
|
if got := strings.Count(out.message, "GOAL_A"); got != 1 {
|
|
t.Fatalf("task #1 goal should appear once despite interleaving, got %d", got)
|
|
}
|
|
if got := strings.Count(out.message, "GOAL_B"); got != 1 {
|
|
t.Fatalf("task #2 goal should appear once despite interleaving, got %d", got)
|
|
}
|
|
if !strings.Contains(out.message, "共 2 个任务") {
|
|
t.Fatalf("header should report 2 tasks: %q", out.message)
|
|
}
|
|
if got := strings.Count(out.message, "── 触发 "); got != 4 {
|
|
t.Fatalf("all 4 event bodies should be present, got %d", got)
|
|
}
|
|
}
|
|
|
|
func TestMergeTriggeredRunsWritesTaskGoalOnce(t *testing.T) {
|
|
out := mergeTriggeredRuns(sameTaskFires(5))
|
|
if got := strings.Count(out.message, longGoal); got != 1 {
|
|
t.Fatalf("same-task goal should appear exactly once in a by-task merge, got %d", got)
|
|
}
|
|
}
|
|
|
|
func TestFinalTriggerMessageSingleFirePrependsHeaderOnce(t *testing.T) {
|
|
item := sameTaskFires(1)[0]
|
|
msg := finalTriggerMessage(item)
|
|
if got := strings.Count(msg, longGoal); got != 1 {
|
|
t.Fatalf("single fire should carry the task goal exactly once, got %d", got)
|
|
}
|
|
if !strings.HasPrefix(msg, "【任务 #72") {
|
|
t.Fatalf("single fire should be prefixed with the task-context header: %q", msg)
|
|
}
|
|
}
|
|
|
|
func TestTaskContextHeaderEmptyForIntervalFire(t *testing.T) {
|
|
if h := taskContextHeader(0, "", ""); h != "" {
|
|
t.Fatalf("interval/none trigger (no task) must produce no header, got %q", h)
|
|
}
|
|
// An interval fire's message must pass through untouched.
|
|
item := triggeredRun{message: "定时触发正文"}
|
|
if finalTriggerMessage(item) != "定时触发正文" {
|
|
t.Fatalf("interval fire message must pass through unchanged")
|
|
}
|
|
}
|
|
|
|
func TestTaskContextHeaderTruncatesLongGoal(t *testing.T) {
|
|
huge := strings.Repeat("很", 5000)
|
|
h := taskContextHeader(72, "d", huge)
|
|
if len([]rune(h)) > 800 { // 200 desc + 500 goal + 截断标记/装饰,远小于 5000
|
|
t.Fatalf("header should be bounded even for a huge goal, got %d runes", len([]rune(h)))
|
|
}
|
|
}
|