fix hermes adapter upstream session routing

This commit is contained in:
Haitao Pan 2026-04-22 14:08:56 +08:00
parent 5bb9afe422
commit b4123998b7
2 changed files with 9 additions and 1 deletions

View File

@ -111,7 +111,7 @@ func NewServer(client rpcClient) *Server {
providerID: strings.TrimSpace(shared.EnvOrDefault("HERMES_ADAPTER_PROVIDER_ID", defaultProviderID)),
providerLabel: strings.TrimSpace(shared.EnvOrDefault("HERMES_ADAPTER_PROVIDER_LABEL", defaultLabel)),
allowedOrigins: parseAllowedOrigins(strings.TrimSpace(shared.EnvOrDefault("HERMES_ADAPTER_ALLOWED_ORIGINS", "https://xworkmate.svc.plus,http://localhost:*,http://127.0.0.1:*"))),
upstreamMethod: strings.TrimSpace(shared.EnvOrDefault("HERMES_ADAPTER_UPSTREAM_METHOD", "")),
upstreamMethod: strings.TrimSpace(shared.EnvOrDefault("HERMES_ADAPTER_UPSTREAM_METHOD", "session.start")),
sessionRunner: func(ctx context.Context, model, prompt, workingDirectory string) (string, error) {
return shared.RunProviderCommand(
ctx,

View File

@ -95,6 +95,7 @@ func TestHandleRPCSessionStartReturnsUpstreamResult(t *testing.T) {
func TestHandleSessionStartFallsBackToPromptRunner(t *testing.T) {
stub := &stubClient{initResult: initializeResult{ProtocolVersion: 1}}
server := NewServer(stub)
server.upstreamMethod = ""
server.sessionRunner = func(ctx context.Context, model, prompt, workingDirectory string) (string, error) {
if workingDirectory != "/tmp/demo" {
t.Fatalf("expected workingDirectory /tmp/demo, got %q", workingDirectory)
@ -119,6 +120,13 @@ func TestHandleSessionStartFallsBackToPromptRunner(t *testing.T) {
}
}
func TestNewServerDefaultsHermesToUpstreamSessionStart(t *testing.T) {
server := NewServer(&stubClient{})
if got := server.upstreamMethod; got != "session.start" {
t.Fatalf("expected default upstream method session.start, got %q", got)
}
}
func TestHandleWebSocketCapabilities(t *testing.T) {
server := NewServer(&stubClient{initResult: initializeResult{ProtocolVersion: 1}})
httpServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {