| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func TestContextMaintenanceInfoUsesOptionalCamelCaseWailsFields(t *testing.T) { |
| 10 | b, err := json.Marshal(ContextInfo{Maintenance: &ContextMaintenanceInfo{ |
| 11 | CanonicalTokens: 800_000, ProjectedTokens: 160_000, |
| 12 | TriggerTokens: 850_000, CheckpointState: "applied", |
| 13 | LastReceipt: &ContextMaintenanceReceiptInfo{ |
| 14 | OperationID: "op", Action: "summary", SavedTokens: 4096, |
| 15 | }, |
| 16 | ContextBudget: &ContextBudgetInfo{WindowMode: "shared", Source: "official", WindowTokens: 1_048_576}, |
| 17 | }}) |
| 18 | if err != nil { |
| 19 | t.Fatal(err) |
| 20 | } |
| 21 | got := string(b) |
| 22 | for _, want := range []string{ |
| 23 | `"maintenance"`, `"projectedTokens":160000`, `"canonicalTokens":800000`, |
| 24 | `"triggerTokens":850000`, `"checkpointState":"applied"`, |
| 25 | `"lastReceipt"`, `"operationId":"op"`, `"savedTokens":4096`, `"action":"summary"`, |
| 26 | `"contextBudget"`, `"windowMode":"shared"`, `"source":"official"`, |
| 27 | } { |
| 28 | if !strings.Contains(got, want) { |
| 29 | t.Fatalf("ContextInfo JSON missing %s: %s", want, got) |
| 30 | } |
| 31 | } |
| 32 | if strings.Contains(got, "operation_id") || strings.Contains(got, "saved_tokens") { |
| 33 | t.Fatalf("ContextInfo leaked sidecar snake_case into Wails JSON: %s", got) |
| 34 | } |
| 35 | } |
| 36 |