返回 DeepSeek-Reasonix
quality_floor_effect_test.go
根目录 / internal / boot / quality_floor_effect_test.go
1 package boot
2
3 // Effect tests for the session quality floor: the floor must reach the
4 // controller without touching the provider-visible prefix.
5
6 import (
7 "context"
8 "fmt"
9 "reflect"
10 "strings"
11 "testing"
12
13 "reasonix/internal/ablation"
14 "reasonix/internal/control"
15 "reasonix/internal/event"
16 "reasonix/internal/provider"
17 )
18
19 // TestEffectQualityFloorDoesNotTouchProviderPrefix pins the cache contract:
20 // standard and delivery send identical system prompts and tool schemas. The
21 // workspace line embeds the run's temp dir, so both sides normalize it.
22 func TestEffectQualityFloorDoesNotTouchProviderPrefix(t *testing.T) {
23 standard := effectRun(t, "boot-effect-floor-standard", "", ablation.Set{})
24 delivery := effectRun(t, "boot-effect-floor-delivery", "delivery", ablation.Set{})
25
26 stdReq, delReq := standard[0], delivery[0]
27 stdPrompt := stripWorkspaceLine(systemMessage(stdReq.Messages))
28 delPrompt := stripWorkspaceLine(systemMessage(delReq.Messages))
29 if stdPrompt != delPrompt {
30 t.Fatalf("delivery floor changed the provider-visible system prompt\n%s", firstPromptDiff(stdPrompt, delPrompt))
31 }
32 if !reflect.DeepEqual(toolSchemaNames(stdReq.Tools), toolSchemaNames(delReq.Tools)) {
33 t.Fatalf("delivery floor changed tool schemas\nstandard=%v\ndelivery=%v",
34 toolSchemaNames(stdReq.Tools), toolSchemaNames(delReq.Tools))
35 }
36 }
37
38 // firstPromptDiff names the first differing line so a failure is diagnosable
39 // instead of reporting only that the two prefixes are unequal.
40 func firstPromptDiff(want, got string) string {
41 a, b := strings.Split(want, "\n"), strings.Split(got, "\n")
42 for i := 0; i < len(a) || i < len(b); i++ {
43 var x, y string
44 if i < len(a) {
45 x = a[i]
46 }
47 if i < len(b) {
48 y = b[i]
49 }
50 if x != y {
51 return fmt.Sprintf("line %d:\n standard: %q\n delivery: %q", i+1, x, y)
52 }
53 }
54 return "no line differs (length mismatch only)"
55 }
56
57 func stripWorkspaceLine(s string) string {
58 lines := strings.Split(s, "\n")
59 for i, l := range lines {
60 if strings.HasPrefix(l, "Current workspace:") {
61 lines[i] = "Current workspace: <ROOT>"
62 }
63 }
64 return strings.Join(lines, "\n")
65 }
66
67 // TestEffectDeliveryFloorFoldsToStandard asserts legacy role input remains
68 // readable without changing the controller's runtime posture.
69 func TestEffectDeliveryFloorFoldsToStandard(t *testing.T) {
70 if got := effectFloorController(t, "delivery").QualityFloor(); got != "standard" {
71 t.Fatalf("QualityFloor = %q, want standard", got)
72 }
73 if got := effectFloorController(t, "light").QualityFloor(); got != "standard" {
74 t.Fatalf("light must fold to standard, got %q", got)
75 }
76 if got := effectFloorController(t, "").QualityFloor(); got != "standard" {
77 t.Fatalf("default floor = %q, want standard", got)
78 }
79 }
80
81 // effectFloorController builds the real stack with a role input and returns
82 // the controller; no turn runs.
83 func effectFloorController(t *testing.T, tokenMode string) *control.Controller {
84 t.Helper()
85 isolateConfigHome(t)
86 dir := robustTempDir(t)
87 t.Chdir(dir)
88 kind := "boot-effect-floor-ctl"
89 if tokenMode != "" {
90 kind += "-" + tokenMode
91 }
92 provider.Register(kind, func(provider.Config) (provider.Provider, error) {
93 return &effectRecordingProvider{}, nil
94 })
95 writeFile(t, dir, "reasonix.toml", `
96 default_model = "floor-model"
97
98 [[providers]]
99 name = "floor-model"
100 kind = "`+kind+`"
101 model = "x"
102 `)
103 ctrl, err := Build(context.Background(), Options{Sink: event.Discard, TokenMode: tokenMode})
104 if err != nil {
105 t.Fatalf("Build(%q): %v", tokenMode, err)
106 }
107 t.Cleanup(func() { ctrl.Close() })
108 return ctrl
109 }
110
110 lines GO