From ec033a945d280ae5dd238b279d47744d4f7fbc53 Mon Sep 17 00:00:00 2001 From: ThearchyHelios Date: Mon, 12 Oct 2026 14:26:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A5=BD=E6=8A=A5=E5=91=8A=E8=AF=81?= =?UTF-8?q?=E6=8D=AE=E5=9B=9E=E5=BD=92=E6=B5=8B=E8=AF=95=E7=9A=84=E5=81=B6?= =?UTF-8?q?=E5=8F=91=E5=A4=B1=E8=B4=A5=EF=BC=9A=E5=81=87=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E6=8C=89=E5=85=B1=E7=94=A8=E5=88=97=E8=A1=A8=E7=9A=84=E6=9C=80?= =?UTF-8?q?=E5=90=8E=E4=B8=80=E9=A1=B9=EF=BC=88budgets[-1]=EF=BC=89?= =?UTF-8?q?=E8=AE=A4=E8=BF=99=E4=B8=80=E6=AC=A1=E6=8A=BD=E5=8F=96=E8=A6=81?= =?UTF-8?q?=E7=9A=84=E9=A2=9D=E5=BA=A6=EF=BC=8C=E5=87=A0=E4=B8=AA=20Agent?= =?UTF-8?q?=20=E5=B9=B6=E8=A1=8C=E6=8A=BD=E5=8F=96=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=88=AB=E7=9A=84=20Agent=20=E5=88=9A=E8=A6=81=E7=9A=84?= =?UTF-8?q?=E5=A4=A7=E9=A2=9D=E5=BA=A6=E4=BC=9A=E7=AE=97=E5=88=B0=E8=BF=99?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=A4=B4=E4=B8=8A=EF=BC=8C=E8=AF=A5=E6=88=AA?= =?UTF-8?q?=E6=96=AD=E9=87=8D=E8=AF=95=E7=9A=84=E8=BF=99=E6=AC=A1=E6=88=90?= =?UTF-8?q?=E4=BA=86=E4=B8=80=E6=AC=A1=E8=BF=87=EF=BC=9B=E6=94=B9=E6=88=90?= =?UTF-8?q?=E9=A2=9D=E5=BA=A6=E8=B7=9F=E7=9D=80=E5=8F=91=E8=B5=B7=E6=8A=BD?= =?UTF-8?q?=E5=8F=96=E7=9A=84=E9=82=A3=E4=B8=AA=E4=BB=BB=E5=8A=A1=E8=B5=B0?= =?UTF-8?q?=EF=BC=88ContextVar=EF=BC=89=E3=80=82=E5=8D=95=E7=8B=AC?= =?UTF-8?q?=E8=BF=9E=E8=B7=91=2030=20=E6=AC=A1=E5=85=A8=E8=BF=87=EF=BC=88?= =?UTF-8?q?=E4=BB=A5=E5=89=8D=E7=BA=A6=E4=BA=94=E5=88=B0=E5=8D=81=E4=BA=8C?= =?UTF-8?q?=E6=AC=A1=E6=8C=82=E4=B8=80=E6=AC=A1=EF=BC=89=EF=BC=8C=E4=BA=A7?= =?UTF-8?q?=E5=93=81=E4=BB=A3=E7=A0=81=E6=B2=A1=E6=9C=89=E7=AB=9E=E4=BA=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/tests/test_report_evidence_regression.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/backend/tests/test_report_evidence_regression.py b/backend/tests/test_report_evidence_regression.py index 0d7eb648..15627541 100644 --- a/backend/tests/test_report_evidence_regression.py +++ b/backend/tests/test_report_evidence_regression.py @@ -17,6 +17,7 @@ import asyncio import json import re import sqlite3 +from contextvars import ContextVar import pytest from langchain_core.messages import AIMessage, HumanMessage, SystemMessage, ToolMessage @@ -131,10 +132,14 @@ class World: self.first_rows = {key: db.execute(sql_of(table, cols, 1)).fetchone() for _, _, key, _, table, cols in AGENTS} db.close() real = llm_mod.get_chat_model + # 这一次抽取要的额度跟着发起它的那个任务走(ContextVar):几个 Agent 并行抽取,以前读共用列表的最后一项 + # (budgets[-1]),别的 Agent 刚要的大额度会算到这一个头上,该截断重试的这次就成了一次过,测试偶发变红 + asked: ContextVar[int | None] = ContextVar("extract_budget", default=None) async def spy(session, spec): if spec.thinking == "off": self.budgets.append(spec.max_tokens) + asked.set(spec.max_tokens) return await real(session, spec) monkeypatch.setattr(llm_mod, "get_chat_model", spy) @@ -152,8 +157,8 @@ class World: def decide(model, messages): if model.response_format: key = who(messages) - world.extract_calls[key].append(world.budgets[-1]) - outcome(key, len(world.extract_calls[key]), world.budgets[-1]) + world.extract_calls[key].append(asked.get()) + outcome(key, len(world.extract_calls[key]), asked.get()) return AIMessage(content=json.dumps(world.extracted(key), ensure_ascii=False)) if any(isinstance(m, SystemMessage) and "报告撰写人" in str(m.content) for m in messages): world.writer.append(list(messages))