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