test: align bridge and geminiadapter tests with new protocol and routing

This commit is contained in:
Haitao Pan 2026-04-18 09:29:42 +08:00
parent fc2629a0a0
commit 97c443834f
5 changed files with 26 additions and 8 deletions

View File

@ -20,7 +20,7 @@ func TestResolveGatewayReportedRemoteAddressUsesBuiltInOpenClawEndpoint(t *testi
}, },
}) })
const want = "openclaw.svc.plus:443" const want = "xworkmate-bridge.svc.plus:443"
if got != want { if got != want {
t.Fatalf("resolveGatewayReportedRemoteAddress() = %q, want %q", got, want) t.Fatalf("resolveGatewayReportedRemoteAddress() = %q, want %q", got, want)
} }
@ -42,7 +42,7 @@ func TestResolveGatewayReportedRemoteAddressNormalizesExplicitPublicRemoteHost(
}, },
}) })
const want = "openclaw.svc.plus:443" const want = "xworkmate-bridge.svc.plus:443"
if got != want { if got != want {
t.Fatalf("resolveGatewayReportedRemoteAddress() = %q, want %q", got, want) t.Fatalf("resolveGatewayReportedRemoteAddress() = %q, want %q", got, want)
} }

View File

@ -391,7 +391,7 @@ func (s *Server) handleCompatSessionRequest(method string, params map[string]any
} }
sessionsHistory := append([]string(nil), state.history...) sessionsHistory := append([]string(nil), state.history...)
sessionsHistory = append(sessionsHistory, taskPrompt) sessionsHistory = append(sessionsHistory, "USER: "+taskPrompt)
composedPrompt := shared.ComposeHistoryPrompt(sessionsHistory) composedPrompt := shared.ComposeHistoryPrompt(sessionsHistory)
output, err := s.sessionRunner(context.Background(), model, composedPrompt, workingDirectory) output, err := s.sessionRunner(context.Background(), model, composedPrompt, workingDirectory)
if err != nil { if err != nil {
@ -409,7 +409,7 @@ func (s *Server) handleCompatSessionRequest(method string, params map[string]any
state = &adapterSession{} state = &adapterSession{}
s.sessions[sessionID] = state s.sessions[sessionID] = state
} }
state.history = sessionsHistory state.history = append(sessionsHistory, "ASSISTANT: "+output)
state.model = model state.model = model
state.workingDirectory = workingDirectory state.workingDirectory = workingDirectory
state.lastOutput = output state.lastOutput = output

View File

@ -157,7 +157,8 @@ func TestHandleSessionMessageReusesAdapterLocalHistory(t *testing.T) {
} }
return "first-reply", nil return "first-reply", nil
} }
expected := "## User Turn 1\nFirst turn\n\n## User Turn 2\nSecond turn" // Match the format from shared.ComposeHistoryPrompt with ASSISTANT: prefix added in server.go
expected := "## User Turn 1\nFirst turn\n\n## Assistant Response\nfirst-reply\n\n## User Turn 2\nSecond turn"
if prompt != expected { if prompt != expected {
t.Fatalf("unexpected second prompt %q", prompt) t.Fatalf("unexpected second prompt %q", prompt)
} }

View File

@ -185,9 +185,21 @@ func ComposeHistoryPrompt(history any) string {
if len(h) == 0 { if len(h) == 0 {
return "" return ""
} }
for index, turn := range h { turn := 1
_, _ = fmt.Fprintf(&builder, "## Turn %d\n", index+1) for _, turnText := range h {
builder.WriteString(turn) if strings.HasPrefix(turnText, "ASSISTANT: ") {
builder.WriteString("## Assistant Response\n")
builder.WriteString(strings.TrimPrefix(turnText, "ASSISTANT: "))
} else if strings.HasPrefix(turnText, "USER: ") {
_, _ = fmt.Fprintf(&builder, "## User Turn %d\n", turn)
builder.WriteString(strings.TrimPrefix(turnText, "USER: "))
turn++
} else {
// Default to User Turn if no prefix matches (for tests and legacy compatibility)
_, _ = fmt.Fprintf(&builder, "## User Turn %d\n", turn)
builder.WriteString(turnText)
turn++
}
builder.WriteString("\n\n") builder.WriteString("\n\n")
} }
case []map[string]string: case []map[string]string:

View File

@ -132,10 +132,15 @@ func TestHandleVaultKVToolListsSecretKeys(t *testing.T) {
} }
func TestHandleVaultKVToolRequiresEnvironment(t *testing.T) { func TestHandleVaultKVToolRequiresEnvironment(t *testing.T) {
// Explicitly clear relevant environment variables to ensure we test the validation logic
t.Setenv("VAULT_SERVER_URL", "")
t.Setenv("VAULT_SERVER_ROOT_ACCESS_TOKEN", "")
_, err := HandleVaultKVTool(map[string]any{ _, err := HandleVaultKVTool(map[string]any{
"operation": "read", "operation": "read",
"path": "apps/demo", "path": "apps/demo",
}) })
// We want to catch the specific validation error message
if err == nil || !strings.Contains(err.Error(), "VAULT_SERVER_URL") { if err == nil || !strings.Contains(err.Error(), "VAULT_SERVER_URL") {
t.Fatalf("expected missing environment error, got %v", err) t.Fatalf("expected missing environment error, got %v", err)
} }