返回 DeepSeek-Reasonix
goal_budget_class_test.go
根目录 / internal / agent / goal_budget_class_test.go
1 package agent
2
3 import "testing"
4
5 func TestGoalTaskNeedsWriteBudgetMatrix(t *testing.T) {
6 // User-reported Chinese bare fault statement must land on the write budget.
7 const userReported = "数据模型管理器又出现历史 BUG 了……"
8 if !GoalTaskNeedsWriteBudget(userReported) {
9 t.Fatalf("GoalTaskNeedsWriteBudget(%q) = false, want write", userReported)
10 }
11 // Ordinary Delivery must still treat the same bare fault as non-mutation
12 // (observable read / evidence, not write-required).
13 if deliveryTaskNeedsMutation(userReported) {
14 t.Fatalf("deliveryTaskNeedsMutation(%q) changed; ordinary Delivery must stay non-mutation", userReported)
15 }
16
17 writeCases := []string{
18 userReported,
19 "应用打开设置时崩溃",
20 "the auth service crashes on login",
21 "parser throws an exception on empty input",
22 "fix the crash in a.go",
23 "帮我修复wps的崩溃问题",
24 "why does it fail and fix it",
25 "为什么失败然后修复它",
26 "解释失败原因并修复",
27 }
28 for _, input := range writeCases {
29 if !GoalTaskNeedsWriteBudget(input) {
30 t.Errorf("Goal write budget missing for %q", input)
31 }
32 }
33
34 simpleCases := []string{
35 "为什么会出现这个 BUG?",
36 "只分析原因,不要修改代码。",
37 "诊断数据库连接失败原因。",
38 "复现并定位问题,但不要修复。",
39 "why does this bug happen?",
40 "explain the crash without changing code",
41 "reproduce the crash and identify the root cause",
42 "review only and do not fix anything",
43 "hello",
44 }
45 for _, input := range simpleCases {
46 if GoalTaskNeedsWriteBudget(input) {
47 t.Errorf("Goal simple budget expected for %q", input)
48 }
49 }
50 }
51
52 func TestGoalBareFaultDoesNotChangeDeliveryClassification(t *testing.T) {
53 // Pin ordinary Delivery consultation/diagnosis so Goal write inference
54 // cannot drift the shared delivery gates.
55 readonly := []string{
56 "为什么会出现这个 BUG?",
57 "诊断数据库连接失败原因。",
58 "reproduce the crash and identify the root cause",
59 "应用打开设置时崩溃",
60 "数据模型管理器又出现历史 BUG 了……",
61 }
62 for _, input := range readonly {
63 if deliveryTaskNeedsMutation(input) {
64 t.Errorf("delivery mutation incorrectly true for %q", input)
65 }
66 }
67 mutation := []string{
68 "fix the crash in a.go",
69 "为什么失败然后修复它",
70 }
71 for _, input := range mutation {
72 if !deliveryTaskNeedsMutation(input) {
73 t.Errorf("delivery mutation incorrectly false for %q", input)
74 }
75 }
76 }
77
78 func TestTaskFaultSignalsSharedWithGoalClassification(t *testing.T) {
79 // Shared fault list must keep task recognition and Goal classification
80 // aligned for bare problem statements.
81 for _, phrase := range []string{"bug", "crash", "崩溃", "异常", "报错", "失败"} {
82 input := "something " + phrase + " happened"
83 if !taskInputHasFaultSignal(input) {
84 t.Errorf("taskInputHasFaultSignal missing %q", phrase)
85 }
86 if !heuristicInputIsTask(input) && !stringsContainsCJK(phrase) {
87 // English bare fault remains a task signal.
88 if !heuristicInputIsTask("the service has a " + phrase) {
89 t.Errorf("heuristic task signal missing for fault %q", phrase)
90 }
91 }
92 }
93 }
94
95 func stringsContainsCJK(s string) bool {
96 for _, r := range s {
97 if r > 127 {
98 return true
99 }
100 }
101 return false
102 }
103
103 lines GO