fix(runtime): 隔离线程任务上下文 (#6420)

* fix(runtime): isolate thread task contexts

* test: use canonical message schema import
This commit is contained in:
InfinityPacer
2026-08-23 20:10:23 +08:00
committed by GitHub
parent 45b41a5caa
commit 146f8649f6
8 changed files with 154 additions and 16 deletions
+18
View File
@@ -18,6 +18,7 @@ from app.adapters.network.browser import (
launch_browser_context,
launch_browser_context_async,
)
from app.runtime.correlation import correlation_scope, get_correlation_id
class _FakeResponse:
@@ -348,6 +349,23 @@ def test_browser_session_helper_runs_same_session_on_one_worker_thread():
assert session_thread_ids[0] not in caller_thread_ids
def test_browser_session_helper_preserves_each_call_context():
"""会话固定线程必须使用每次操作的上下文,不能保留首次请求状态。"""
page = _FakePage()
context = _FakeContext([page])
helper = BrowserSessionHelper()
observed = []
with patch.object(BrowserSessionHelper, "_launch_context", return_value=context):
for correlation_id in ("request-one", "request-two"):
with correlation_scope(correlation_id):
observed.append(
helper.with_session("session-1", lambda _session: get_correlation_id())
)
assert observed == ["request-one", "request-two"]
def test_browser_session_helper_closes_session_on_worker_thread():
"""关闭会话时应在创建浏览器对象的工作线程内释放资源。"""
page = _FakePage()