返回 DeepSeek-Reasonix
work_practice_test.go
根目录 / internal / boot / work_practice_test.go
1 package boot
2
3 import (
4 "context"
5 "strings"
6 "testing"
7
8 "reasonix/internal/agent/testutil"
9 "reasonix/internal/config"
10 )
11
12 func TestBuildAppendsWorkPracticePolicyToCustomSystemPrompt(t *testing.T) {
13 dir := robustTempDir(t)
14 t.Chdir(dir)
15 writeFile(t, dir, "reasonix.toml", `
16 default_model = "test-model"
17
18 [agent]
19 system_prompt = "BASE"
20
21 [[providers]]
22 name = "test-model"
23 kind = "openai"
24 base_url = "https://example.invalid"
25 model = "x"
26 api_key_env = "REASONIX_TEST_KEY_UNSET"
27 `)
28 approveWorkspace(t, dir)
29
30 ctrl, err := Build(context.Background(), Options{})
31 if err != nil {
32 t.Fatalf("Build: %v", err)
33 }
34 defer ctrl.Close()
35
36 sys := systemMessage(ctrl.History())
37 for _, want := range []string{"Work practices:", "implement exactly that", "review the final diff"} {
38 if !strings.Contains(sys, want) {
39 t.Fatalf("work practice policy missing %q from custom system prompt:\n%s", want, sys)
40 }
41 }
42 if strings.Index(sys, config.UserDecisionPolicy) >= strings.Index(sys, config.WorkPracticePolicy) ||
43 strings.Index(sys, config.WorkPracticePolicy) >= strings.Index(sys, config.LanguagePolicy) {
44 t.Fatal("policy order must be user-decision < work-practice < language")
45 }
46 }
47
48 func TestWorkPracticePolicyCarriesNoEnvironmentSpecificClaims(t *testing.T) {
49 for _, unwanted := range []string{"offline", "proxy", "stop retrying", "avoid repeated full-suite runs", "pre-exist"} {
50 if strings.Contains(strings.ToLower(config.WorkPracticePolicy), unwanted) {
51 t.Errorf("work practice policy must not assert %q", unwanted)
52 }
53 }
54 }
55
56 func TestBuildInjectsOfflineNoteOnlyWhenEnvironmentDeclaresIt(t *testing.T) {
57 build := func(t *testing.T, environmentSection string) (string, string) {
58 t.Helper()
59 dir := robustTempDir(t)
60 t.Chdir(dir)
61 registerBootTokenProfileTestProvider()
62 prov := testutil.NewMock("offline-context", testutil.Turn{Text: "done"})
63 setBootTokenProfileTestProvider(t, prov)
64 writeFile(t, dir, "reasonix.toml", `
65 default_model = "test-model"
66
67 [agent]
68 system_prompt = "BASE"
69
70 [[providers]]
71 name = "test-model"
72 kind = "boot-token-profile-test"
73 model = "x"
74 `+environmentSection)
75 approveWorkspace(t, dir)
76
77 ctrl, err := Build(context.Background(), Options{})
78 if err != nil {
79 t.Fatalf("Build: %v", err)
80 }
81 defer ctrl.Close()
82 _ = ctrl.Run(context.Background(), "capture request prefix")
83 if prov.LastRequest() == nil {
84 t.Fatal("provider received no request")
85 }
86 return systemMessage(ctrl.History()), sessionContextMessage(ctrl.History())
87 }
88
89 if sys, session := build(t, ""); strings.Contains(sys, config.OfflineEnvironmentNote) || strings.Contains(session, config.OfflineEnvironmentNote) {
90 t.Fatalf("undeclared environment includes offline note:\nsystem=%s\ncontext=%s", sys, session)
91 }
92 if sys, session := build(t, "\n[environment]\noffline = true\n"); strings.Contains(sys, config.OfflineEnvironmentNote) || !strings.Contains(session, config.OfflineEnvironmentNote) {
93 t.Fatalf("declared offline note must live only in session context:\nsystem=%s\ncontext=%s", sys, session)
94 }
95 sys, session := build(t, "\n[environment]\nenabled = false\noffline = true\n")
96 if !strings.Contains(session, config.OfflineEnvironmentNote) {
97 t.Fatal("offline declaration must survive disabled probing")
98 }
99 if strings.Contains(sys, config.OfflineEnvironmentNote) || strings.Contains(session, "- OS:") {
100 t.Fatal("disabled probing must suppress probed environment details and keep offline note out of system")
101 }
102 }
103
103 lines GO