fix(bot): forward actor_peer_id through openviking_connection (#4650)

* fix(bot): forward actor_peer_id through openviking_connection

The --with-bot proxy built openviking_connection without RequestContext.actor_peer_id, so vikingbot fell back to body user_id.

Fixes #4649

* fix(bot): use direct actor_peer_id access and tidy test

Address #4650 review nits: read RequestContext.actor_peer_id directly, drop vikingbot-side fallback assertion from the unit test, and ensure the test file ends with a newline.
This commit is contained in:
LI
2026-09-08 21:07:54 +08:00
committed by GitHub
parent a26d9f1699
commit 6c04e2ad42
2 changed files with 42 additions and 0 deletions
+5
View File
@@ -85,6 +85,11 @@ def _build_openviking_connection(
}
if api_key:
connection["api_key"] = api_key
# Preserve request-scoped actor peer so vikingbot does not fall back to
# body user_id / authenticated OpenViking user_id (#4649).
actor_peer_id = str(ctx.actor_peer_id or "").strip()
if actor_peer_id:
connection["actor_peer_id"] = actor_peer_id
return connection
@@ -0,0 +1,37 @@
# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd.
# SPDX-License-Identifier: AGPL-3.0
from openviking.server.identity import RequestContext, Role
from openviking.server.routers.bot import _build_openviking_connection
from openviking_cli.session.user_id import UserIdentifier
def test_build_openviking_connection_forwards_actor_peer_id():
ctx = RequestContext(
user=UserIdentifier("acct", "alice"),
role=Role.USER,
actor_peer_id="peer-a",
)
connection = _build_openviking_connection(
api_key="user-key",
ctx=ctx,
effective_auth_mode="api_key",
server_url="http://127.0.0.1:1933",
)
# Assert the OpenViking-side forward only; vikingbot owns connection > body fallback.
assert connection["actor_peer_id"] == "peer-a"
def test_build_openviking_connection_omits_blank_actor_peer_id():
ctx = RequestContext(
user=UserIdentifier("acct", "alice"),
role=Role.USER,
actor_peer_id=" ",
)
connection = _build_openviking_connection(
api_key="user-key",
ctx=ctx,
effective_auth_mode="api_key",
server_url="http://127.0.0.1:1933",
)
assert "actor_peer_id" not in connection