-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathfrontend_setup_scripts_test.go
More file actions
164 lines (144 loc) · 5.24 KB
/
frontend_setup_scripts_test.go
File metadata and controls
164 lines (144 loc) · 5.24 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
package main
import (
"net/http"
"net/http/httptest"
"path/filepath"
"strings"
"testing"
"time"
)
func TestServeCodexSetupScript_PowerShell(t *testing.T) {
h := &proxyHandler{}
req := httptest.NewRequest(http.MethodGet, "http://example.com/setup/codex/testtoken?shell=powershell", nil)
rr := httptest.NewRecorder()
h.serveCodexSetupScript(rr, req)
if rr.Code != http.StatusOK {
t.Fatalf("status = %d, want %d", rr.Code, http.StatusOK)
}
if ct := rr.Header().Get("Content-Type"); !strings.HasPrefix(ct, "text/plain") {
t.Fatalf("Content-Type = %q, want text/plain*", ct)
}
body := rr.Body.String()
if !strings.Contains(body, "Set-StrictMode -Version Latest") {
t.Fatalf("expected PowerShell script body, got:\n%s", body)
}
if !strings.Contains(body, "Join-Path $HOME '.codex'") {
t.Fatalf("expected codex paths in script body, got:\n%s", body)
}
if !strings.Contains(body, "model_catalog_json = ") {
t.Fatalf("expected model catalog config in script body, got:\n%s", body)
}
if !strings.Contains(body, "[mcp_servers.model_sync]") {
t.Fatalf("expected MCP sidecar config in script body, got:\n%s", body)
}
if !strings.Contains(body, "model_sync.ps1") {
t.Fatalf("expected MCP sidecar script install in PowerShell body, got:\n%s", body)
}
if !strings.Contains(body, "$firstLine = [Console]::In.ReadLine()") {
t.Fatalf("expected MCP JSONL transport support in PowerShell body, got:\n%s", body)
}
}
func TestServeCodexSetupScript_Bash(t *testing.T) {
h := &proxyHandler{}
req := httptest.NewRequest(http.MethodGet, "http://example.com/setup/codex/testtoken", nil)
rr := httptest.NewRecorder()
h.serveCodexSetupScript(rr, req)
if rr.Code != http.StatusOK {
t.Fatalf("status = %d, want %d", rr.Code, http.StatusOK)
}
if ct := rr.Header().Get("Content-Type"); !strings.HasPrefix(ct, "text/x-shellscript") {
t.Fatalf("Content-Type = %q, want text/x-shellscript*", ct)
}
body := rr.Body.String()
if !strings.Contains(body, "model_sync.sh") {
t.Fatalf("expected MCP sidecar script install in bash body, got:\n%s", body)
}
if !strings.Contains(body, "model_catalog_json = ") {
t.Fatalf("expected model catalog config in bash script body, got:\n%s", body)
}
if !strings.Contains(body, "[mcp_servers.model_sync]") {
t.Fatalf("expected MCP sidecar config in bash script body, got:\n%s", body)
}
if !strings.Contains(body, "MCP_TRANSPORT_MODE=\"jsonl\"") {
t.Fatalf("expected MCP JSONL transport support in bash body, got:\n%s", body)
}
}
func TestServeGeminiSetupScript_PowerShell(t *testing.T) {
secret := "test-secret-key-12345678901234567890"
t.Setenv("POOL_JWT_SECRET", secret)
tmpDir := t.TempDir()
usersPath := filepath.Join(tmpDir, "pool_users.json")
store, err := newPoolUserStore(usersPath)
if err != nil {
t.Fatalf("newPoolUserStore: %v", err)
}
user := &PoolUser{
ID: "user123",
Token: "tok123",
Email: "test@example.com",
PlanType: "pro",
CreatedAt: time.Now(),
}
if err := store.Create(user); err != nil {
t.Fatalf("create user: %v", err)
}
h := &proxyHandler{poolUsers: store}
req := httptest.NewRequest(http.MethodGet, "http://example.com/setup/gemini/tok123?shell=powershell", nil)
rr := httptest.NewRecorder()
h.serveGeminiSetupScript(rr, req)
if rr.Code != http.StatusOK {
t.Fatalf("status = %d, want %d", rr.Code, http.StatusOK)
}
if ct := rr.Header().Get("Content-Type"); !strings.HasPrefix(ct, "text/plain") {
t.Fatalf("Content-Type = %q, want text/plain*", ct)
}
body := rr.Body.String()
if !strings.Contains(body, "$env:CODE_ASSIST_ENDPOINT = $BaseUrl") {
t.Fatalf("expected PowerShell env setup in body, got:\n%s", body)
}
if strings.Contains(body, "`") {
t.Fatalf("PowerShell script should not contain backticks (Go raw string safety), got:\n%s", body)
}
}
func TestServeClaudeSetupScript_PowerShell(t *testing.T) {
secret := "test-secret-key-12345678901234567890"
t.Setenv("POOL_JWT_SECRET", secret)
// Ensure env is not contaminated by user-specific settings during test runs.
t.Setenv("PUBLIC_URL", "")
tmpDir := t.TempDir()
usersPath := filepath.Join(tmpDir, "pool_users.json")
store, err := newPoolUserStore(usersPath)
if err != nil {
t.Fatalf("newPoolUserStore: %v", err)
}
user := &PoolUser{
ID: "user456",
Token: "tok456",
Email: "test2@example.com",
PlanType: "pro",
CreatedAt: time.Now(),
}
if err := store.Create(user); err != nil {
t.Fatalf("create user: %v", err)
}
h := &proxyHandler{poolUsers: store}
req := httptest.NewRequest(http.MethodGet, "http://example.com/setup/claude/tok456?shell=powershell", nil)
rr := httptest.NewRecorder()
h.serveClaudeSetupScript(rr, req)
if rr.Code != http.StatusOK {
t.Fatalf("status = %d, want %d", rr.Code, http.StatusOK)
}
if ct := rr.Header().Get("Content-Type"); !strings.HasPrefix(ct, "text/plain") {
t.Fatalf("Content-Type = %q, want text/plain*", ct)
}
body := rr.Body.String()
if !strings.Contains(body, "$env:ANTHROPIC_BASE_URL = $BaseUrl") {
t.Fatalf("expected PowerShell env setup in body, got:\n%s", body)
}
if !strings.Contains(body, "ConvertTo-Json -Depth 10") {
t.Fatalf("expected PowerShell JSON update logic in body, got:\n%s", body)
}
if strings.Contains(body, "`") {
t.Fatalf("PowerShell script should not contain backticks (Go raw string safety), got:\n%s", body)
}
}