-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice_contract_post_refactor_structural_test.go
More file actions
209 lines (185 loc) · 6.42 KB
/
service_contract_post_refactor_structural_test.go
File metadata and controls
209 lines (185 loc) · 6.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package fizeau
import (
"context"
"os"
"path/filepath"
"testing"
"time"
"github.com/easel/fizeau/internal/harnesses"
"github.com/easel/fizeau/internal/serviceimpl"
"github.com/easel/fizeau/internal/test/structuraldiff"
)
type structuralFixtureHarness struct {
name string
quota harnesses.QuotaStatus
account harnesses.AccountSnapshot
}
func (h *structuralFixtureHarness) Info() harnesses.HarnessInfo {
return harnesses.HarnessInfo{Name: h.name, Type: "subprocess"}
}
func (h *structuralFixtureHarness) HealthCheck(context.Context) error { return nil }
func (h *structuralFixtureHarness) Execute(context.Context, harnesses.ExecuteRequest) (<-chan harnesses.Event, error) {
panic("structuralFixtureHarness.Execute should not be called")
}
func (h *structuralFixtureHarness) QuotaStatus(context.Context, time.Time) (harnesses.QuotaStatus, error) {
return h.quota, nil
}
func (h *structuralFixtureHarness) RefreshQuota(context.Context) (harnesses.QuotaStatus, error) {
return h.quota, nil
}
func (h *structuralFixtureHarness) QuotaFreshness() time.Duration {
return 15 * time.Minute
}
func (h *structuralFixtureHarness) SupportedLimitIDs() []string {
ids := make([]string, 0, len(h.quota.Windows))
for _, window := range h.quota.Windows {
if window.LimitID != "" {
ids = append(ids, window.LimitID)
}
}
return ids
}
func (h *structuralFixtureHarness) AccountStatus(context.Context, time.Time) (harnesses.AccountSnapshot, error) {
return h.account, nil
}
func (h *structuralFixtureHarness) RefreshAccount(context.Context) (harnesses.AccountSnapshot, error) {
return h.account, nil
}
func (h *structuralFixtureHarness) AccountFreshness() time.Duration {
return 15 * time.Minute
}
func newStructuralFixtureService() *service {
capturedAt := preRefactorCapturedAt()
claudeAccount := harnesses.AccountSnapshot{
Authenticated: true,
Email: "user@example.com",
PlanType: "claude_max",
OrgName: "Example Org",
Source: "~/.claude/.credentials.json",
CapturedAt: capturedAt,
Fresh: true,
Detail: "anthropic subscription",
}
codexAccount := harnesses.AccountSnapshot{
Authenticated: true,
Email: "user@example.com",
PlanType: "chatgpt_pro",
Source: "~/.codex/auth.json",
CapturedAt: capturedAt,
Fresh: true,
}
geminiAccount := harnesses.AccountSnapshot{
Authenticated: true,
Email: "user@example.com",
PlanType: "gemini_pro",
Source: "~/.gemini/oauth_creds.json",
CapturedAt: capturedAt,
Fresh: true,
Detail: "auth evidence cached for 7d",
}
return &service{
harnessInstances: map[string]harnesses.Harness{
"claude": &structuralFixtureHarness{
name: "claude",
quota: harnesses.QuotaStatus{
Source: "internal/harnesses/claude/quota_cache.go",
CapturedAt: capturedAt,
Fresh: true,
State: harnesses.QuotaOK,
Windows: preRefactorQuotaWindowsClaude(),
Account: &claudeAccount,
RoutingPreference: harnesses.RoutingPreferenceAvailable,
},
account: claudeAccount,
},
"codex": &structuralFixtureHarness{
name: "codex",
quota: harnesses.QuotaStatus{
Source: "internal/harnesses/codex/quota_cache.go",
CapturedAt: capturedAt,
Fresh: true,
State: harnesses.QuotaOK,
Windows: preRefactorQuotaWindowsCodex(),
Account: &codexAccount,
RoutingPreference: harnesses.RoutingPreferenceAvailable,
},
account: codexAccount,
},
"gemini": &structuralFixtureHarness{
name: "gemini",
quota: harnesses.QuotaStatus{
Source: "internal/harnesses/gemini/quota_cache.go",
CapturedAt: capturedAt,
Fresh: true,
State: harnesses.QuotaOK,
Windows: preRefactorQuotaWindowsGemini(),
Account: &geminiAccount,
RoutingPreference: harnesses.RoutingPreferenceAvailable,
Reason: "Pro tier blocked",
},
account: geminiAccount,
},
},
runtime: serviceimpl.NewRuntime(serviceimpl.RuntimeDeps{
Now: func() time.Time { return capturedAt },
}),
}
}
func postRefactorFixtures(t *testing.T) []preRefactorFixture {
t.Helper()
svc := newStructuralFixtureService()
ctx := context.Background()
claudeQuota := svc.claudeQuotaState(ctx)
codexQuota := svc.codexQuotaState(ctx)
geminiQuota := svc.geminiQuotaState(ctx)
claudeAccount := svc.claudeAccountStatus(ctx)
codexAccount := svc.codexAccountStatus(ctx)
geminiAccount := svc.geminiAccountStatus(ctx)
if claudeQuota == nil || codexQuota == nil || geminiQuota == nil {
t.Fatal("fixture service returned nil quota projection")
}
if claudeAccount == nil || codexAccount == nil || geminiAccount == nil {
t.Fatal("fixture service returned nil account projection")
}
harnessClaude := preRefactorHarnessClaude()
harnessClaude.Quota = claudeQuota
harnessClaude.Account = claudeAccount
harnessCodex := preRefactorHarnessCodex()
harnessCodex.Quota = codexQuota
harnessCodex.Account = codexAccount
harnessGemini := preRefactorHarnessGemini()
harnessGemini.Quota = geminiQuota
harnessGemini.Account = geminiAccount
providerClaude := preRefactorProviderClaudeSubscription()
providerClaude.Auth = *claudeAccount
providerClaude.Quota = claudeQuota
return []preRefactorFixture{
{"harness-claude.json", harnessClaude},
{"harness-codex.json", harnessCodex},
{"harness-gemini.json", harnessGemini},
{"harness-opencode.json", preRefactorHarnessOpenCode()},
{"harness-pi.json", preRefactorHarnessPi()},
{"provider-claude-subscription.json", providerClaude},
{"quota-claude.json", claudeQuota},
{"quota-codex.json", codexQuota},
{"quota-gemini.json", geminiQuota},
{"account-claude.json", claudeAccount},
{"account-codex.json", codexAccount},
{"account-gemini.json", geminiAccount},
}
}
func TestPostRefactorContract003FixturesStructuralDiff(t *testing.T) {
for _, fx := range postRefactorFixtures(t) {
fx := fx
t.Run(fx.relPath, func(t *testing.T) {
want, err := os.ReadFile(filepath.Join(preRefactorFixtureDir, fx.relPath))
if err != nil {
t.Fatalf("ReadFile(%q): %v", fx.relPath, err)
}
got := marshalIndentJSON(t, fx.value)
if err := structuraldiff.CompareJSON(want, got, structuraldiff.Config{}); err != nil {
t.Fatalf("structural diff failed for %s: %v\nwant:\n%s\n\ngot:\n%s", fx.relPath, err, want, got)
}
})
}
}