| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "path/filepath" |
| 5 | "testing" |
| 6 | |
| 7 | "reasonix/internal/agent" |
| 8 | "reasonix/internal/boot" |
| 9 | "reasonix/internal/control" |
| 10 | ) |
| 11 | |
| 12 | func TestSaveTabSessionMetaFoldsDeliveryFloorToStandard(t *testing.T) { |
| 13 | path := filepath.Join(t.TempDir(), "session.jsonl") |
| 14 | meta, err := agent.EnsureBranchMeta(path) |
| 15 | if err != nil { |
| 16 | t.Fatal(err) |
| 17 | } |
| 18 | meta.AgentPreset = boot.AgentPresetStandard |
| 19 | meta.TokenMode = boot.TokenModeFull |
| 20 | if err := agent.SaveBranchMetaPreserveUpdated(path, meta); err != nil { |
| 21 | t.Fatal(err) |
| 22 | } |
| 23 | |
| 24 | if err := saveTabSessionMetaSnapshot(tabSessionMetaSnapshot{path: legacySessionPath(path), qualityFloor: control.QualityFloorDelivery}); err != nil { |
| 25 | t.Fatal(err) |
| 26 | } |
| 27 | got, ok, err := agent.LoadBranchMeta(path) |
| 28 | if err != nil || !ok { |
| 29 | t.Fatalf("LoadBranchMeta = %+v, %v, %v", got, ok, err) |
| 30 | } |
| 31 | if got.QualityFloor != control.QualityFloorStandard { |
| 32 | t.Fatalf("persisted floor = %q, want standard", got.QualityFloor) |
| 33 | } |
| 34 | if got.AgentPreset != boot.AgentPresetStandard { |
| 35 | t.Fatalf("dual-write preset = %q, want standard", got.AgentPreset) |
| 36 | } |
| 37 | if got.TokenMode != boot.TokenModeFull { |
| 38 | t.Fatalf("dual-write tokenMode = %q, want full", got.TokenMode) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | func TestSaveTabSessionMetaStandardWritesCompatibilityValue(t *testing.T) { |
| 43 | path := filepath.Join(t.TempDir(), "standard.jsonl") |
| 44 | if _, err := agent.EnsureBranchMeta(path); err != nil { |
| 45 | t.Fatal(err) |
| 46 | } |
| 47 | if err := saveTabSessionMetaSnapshot(tabSessionMetaSnapshot{path: legacySessionPath(path), qualityFloor: control.QualityFloorStandard}); err != nil { |
| 48 | t.Fatal(err) |
| 49 | } |
| 50 | got, ok, err := agent.LoadBranchMeta(path) |
| 51 | if err != nil || !ok { |
| 52 | t.Fatalf("LoadBranchMeta = %+v, %v, %v", got, ok, err) |
| 53 | } |
| 54 | if got.QualityFloor != control.QualityFloorStandard { |
| 55 | t.Fatalf("standard compatibility floor = %q", got.QualityFloor) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | func TestTabSessionProfileFromMetaFoldsLegacyDelivery(t *testing.T) { |
| 60 | path := filepath.Join(t.TempDir(), "legacy.jsonl") |
| 61 | meta, err := agent.EnsureBranchMeta(path) |
| 62 | if err != nil { |
| 63 | t.Fatal(err) |
| 64 | } |
| 65 | meta.AgentPreset = boot.AgentPresetDelivery |
| 66 | meta.TokenMode = boot.TokenModeDelivery |
| 67 | profile := tabSessionProfileFromMeta(path, meta) |
| 68 | if profile.qualityFloor != control.QualityFloorStandard { |
| 69 | t.Fatalf("legacy decode floor = %q, want standard", profile.qualityFloor) |
| 70 | } |
| 71 | tab := &WorkspaceTab{} |
| 72 | applyTabSessionProfile(tab, profile) |
| 73 | if got := tab.qualityFloor; got != control.QualityFloorStandard { |
| 74 | t.Fatalf("legacy delivery must fold at the tab boundary: got %q", got) |
| 75 | } |
| 76 | if got := currentTabTokenMode(tab); got != boot.TokenModeFull { |
| 77 | t.Fatalf("derived tokenMode = %q, want full", got) |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | func TestTabSessionProfileFromMetaFoldsLegacyLight(t *testing.T) { |
| 82 | path := filepath.Join(t.TempDir(), "light.jsonl") |
| 83 | meta, err := agent.EnsureBranchMeta(path) |
| 84 | if err != nil { |
| 85 | t.Fatal(err) |
| 86 | } |
| 87 | meta.AgentPreset = "light" |
| 88 | meta.TokenMode = "economy" |
| 89 | profile := tabSessionProfileFromMeta(path, meta) |
| 90 | if profile.qualityFloor != control.QualityFloorStandard { |
| 91 | t.Fatalf("legacy light must fold to standard, got %q", profile.qualityFloor) |
| 92 | } |
| 93 | } |
| 94 |