Skip to content

The agent that grows with you

test(agent): stop truncation-warning ContextVar leaking between test files

Aniruddha Adakf168d857c37e
diff --git a/tests/agent/test_prompt_builder.py b/tests/agent/test_prompt_builder.py
index 4d94272023e..a92c2255bc1 100644
--- a/tests/agent/test_prompt_builder.py
+++ b/tests/agent/test_prompt_builder.py
@@ -38,6 +38,18 @@ from agent.prompt_builder import (
from hermes_cli.nous_subscription import NousFeatureState, NousSubscriptionFeatures
[email protected](autouse=True)
+def _drain_truncation_warnings():
+ """Leave no truncation warnings in the shared thread context.
+
+ Truncation warnings ride a ContextVar; under plain ``pytest`` (no
+ per-file subprocess isolation) anything this file records leaks into
+ later files' contexts and breaks their assertions/ordering.
+ """
+ yield
+ drain_truncation_warnings()
+
+
# =========================================================================
# Guidance constants
# =========================================================================
diff --git a/tests/agent/test_system_prompt.py b/tests/agent/test_system_prompt.py
index 56dc09f1a13..28d0e6d3bf7 100644
--- a/tests/agent/test_system_prompt.py
+++ b/tests/agent/test_system_prompt.py
@@ -24,6 +24,11 @@ def _make_agent(**overrides):
platform="",
pass_session_id=False,
session_id="",
+ # build_system_prompt drains pending truncation warnings and
+ # forwards each to this; a warning left in the ContextVar by an
+ # earlier test file (they share one thread's context under plain
+ # pytest) must not make this stub AttributeError.
+ _emit_status=lambda *_args, **_kwargs: None,
)
base.update(overrides)
return SimpleNamespace(**base)