Fix bridge lint blockers

This commit is contained in:
Haitao Pan 2026-04-24 14:57:26 +08:00
parent cce9833689
commit dfead14145
8 changed files with 35 additions and 54 deletions

View File

@ -5,14 +5,12 @@ import (
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"testing"
)
func TestResolveSingleAgentForwardEndpointFromExampleConfig(t *testing.T) {
// Set the config path to example/config.yaml relative to this test file
os.Setenv("BRIDGE_CONFIG_PATH", "../../example/config.yaml")
defer os.Unsetenv("BRIDGE_CONFIG_PATH")
t.Setenv("BRIDGE_CONFIG_PATH", "../../example/config.yaml")
_, catalog, order := newProductionProviderCatalog()
if len(order) == 0 {

View File

@ -395,7 +395,9 @@ func (c *externalACPCompat) callHTTPRPC(ctx context.Context, method string, para
if err != nil {
return nil, err
}
defer response.Body.Close()
defer func() {
_ = response.Body.Close()
}()
if response.StatusCode != http.StatusOK {
body, _ := io.ReadAll(io.LimitReader(response.Body, 2048))

View File

@ -1,7 +1,6 @@
package acp
import (
"context"
"sync"
"xworkmate-bridge/internal/gatewayruntime"
@ -15,28 +14,26 @@ type session struct {
provider string // The Provider ID
target string // The Execution Target ID
compat ProviderCompat
cancel context.CancelFunc
closed bool
mu sync.Mutex
history []string
}
type Server struct {
mu sync.RWMutex
config *BridgeConfig
sessions map[string]*session
mu sync.RWMutex
config *BridgeConfig
sessions map[string]*session
// Core Control Plane Components
routingEngine RoutingEngine
providers map[string]ProviderCompat
catalog *CapabilityCatalog
orchestrator *SessionOrchestrator
memoryService memory.Service
routingEngine RoutingEngine
providers map[string]ProviderCompat
catalog *CapabilityCatalog
orchestrator *SessionOrchestrator
memoryService memory.Service
providerOrder []string
gateway *gatewayruntime.Manager
// Legacy / Common
authService interface{} // Minimal auth dependency
allowedOrigins []string
authService interface{} // Minimal auth dependency
allowedOrigins []string
}

View File

@ -252,23 +252,3 @@ func isTimeoutError(err error) bool {
}
return strings.Contains(strings.ToLower(err.Error()), "timeout")
}
func isHermesFinalSessionUpdate(notification map[string]any) bool {
if notification == nil {
return false
}
method := strings.TrimSpace(fmt.Sprint(notification["method"]))
if method != "session.update" && method != "session/update" && method != "acp.session.update" {
return false
}
params, _ := notification["params"].(map[string]any)
if len(params) == 0 {
return false
}
update, _ := params["update"].(map[string]any)
if len(update) == 0 {
update = params
}
sessionUpdate := strings.TrimSpace(fmt.Sprint(update["sessionUpdate"]))
return sessionUpdate == "agent_message_text"
}

View File

@ -70,8 +70,7 @@ func TestHandleCapabilitiesSynthesizesProviderResponse(t *testing.T) {
func TestHandleRPCSessionStartReturnsUpstreamResult(t *testing.T) {
isolateHermesConfig(t)
var stub *stubClient
stub = &stubClient{initResult: initializeResult{ProtocolVersion: 1}}
stub := &stubClient{initResult: initializeResult{ProtocolVersion: 1}}
stub.callFn = func(method string, params map[string]any) (map[string]any, error) {
switch method {
case "session/new":
@ -138,8 +137,7 @@ func TestHandleRPCSessionStartReturnsUpstreamResult(t *testing.T) {
func TestHandleRPCSessionStartRejectsEmptyUpstreamResponse(t *testing.T) {
isolateHermesConfig(t)
var stub *stubClient
stub = &stubClient{initResult: initializeResult{ProtocolVersion: 1}}
stub := &stubClient{initResult: initializeResult{ProtocolVersion: 1}}
stub.callFn = func(method string, params map[string]any) (map[string]any, error) {
switch method {
case "session/new":
@ -200,8 +198,7 @@ func TestNewServerDefaultsHermesToSessionPrompt(t *testing.T) {
func TestHandleRPCSessionMessageReusesUpstreamSession(t *testing.T) {
isolateHermesConfig(t)
var stub *stubClient
stub = &stubClient{initResult: initializeResult{ProtocolVersion: 1}}
stub := &stubClient{initResult: initializeResult{ProtocolVersion: 1}}
promptCalls := 0
stub.callFn = func(method string, params map[string]any) (map[string]any, error) {
switch method {
@ -314,8 +311,7 @@ func TestHandleRPCSessionStartUsesConfiguredHermesModelBeforePrompt(t *testing.T
t.Setenv("HOME", home)
t.Setenv("HERMES_HOME", "")
var stub *stubClient
stub = &stubClient{initResult: initializeResult{ProtocolVersion: 1}}
stub := &stubClient{initResult: initializeResult{ProtocolVersion: 1}}
stub.callFn = func(method string, params map[string]any) (map[string]any, error) {
switch method {
case "session/new":

View File

@ -45,7 +45,9 @@ func (c *opencodeHTTPClient) Initialize() (initializeResult, error) {
if err != nil {
return initializeResult{}, err
}
defer resp.Body.Close()
defer func() {
_ = resp.Body.Close()
}()
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(io.LimitReader(resp.Body, 1024))
return initializeResult{}, fmt.Errorf("opencode health failed (%d): %s", resp.StatusCode, strings.TrimSpace(string(body)))
@ -110,7 +112,9 @@ func (c *opencodeHTTPClient) CreateSession(title string) (string, error) {
if err != nil {
return "", err
}
defer resp.Body.Close()
defer func() {
_ = resp.Body.Close()
}()
raw, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
@ -213,7 +217,9 @@ func (c *opencodeHTTPClient) postSessionMessage(sessionID, prompt string, params
if err != nil {
return nil, err
}
defer resp.Body.Close()
defer func() {
_ = resp.Body.Close()
}()
raw, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err

View File

@ -213,7 +213,6 @@ func (s *Server) handleCapabilities() map[string]any {
type opencodeSessionState struct {
upstreamSessionID string
title string
lastOutput string
}

11
main.go
View File

@ -12,9 +12,9 @@ import (
)
var (
buildCommit = ""
buildVersion = "v1.1.0"
buildDate = ""
buildCommit = ""
buildVersion = "v1.1.0"
buildDate = ""
)
func main() {
@ -37,7 +37,10 @@ func main() {
case "stdio":
acp.RunStdio(os.Stdin, os.Stdout)
case "version", "-v", "--version":
printBridgeVersionInfo()
if err := printBridgeVersionInfo(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
default:
// Backward compatibility for old subcommands (optional, but we said no backward compatibility)
// However, for the transition, we can be nice or just fail.