mirror of
https://github.com/volcengine/OpenViking.git
synced 2026-09-29 16:58:31 +08:00
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:
@@ -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
|
||||
Reference in New Issue
Block a user