[eric] tests: harness pins the new context-meter contract and spends the silent-quit budget; second legacy prompt revision migrates

This commit is contained in:
ciregenz
2026-08-03 20:46:57 -07:00
parent 820cf578e5
commit 331478d9fd
2 changed files with 16 additions and 3 deletions
+11 -2
View File
@@ -21,7 +21,7 @@ logger = logging.getLogger(__name__)
SETTINGS_FILE = os.path.join(DATA_DIR, "settings.json")
# The pre-2026-08-04 default prompt, byte-exact: the default persists into settings.json, so upgrading the constant alone leaves every existing install on the old text. Verbatim match only; a user-customized prompt never equals this.
# Every shipped default prompt revision, byte-exact: the default persists into settings.json, so upgrading the constant alone leaves existing installs on old text. Verbatim match only; a user-customized prompt never equals any of these. The bee3f48b-era revision differs from the 9e0b4706 one only inside Tool Priority (ToolSearch-discovery vs MCPSearch wording), so it is derived rather than duplicated.
P_LEGACY_DEFAULT_SYSTEM_PROMPT = (
"You are a personal AI assistant running inside OpenSwarm.\n\n"
"## Core Behavior\n"
@@ -50,6 +50,15 @@ P_LEGACY_DEFAULT_SYSTEM_PROMPT = (
"If you genuinely need clarification on something ambiguous, use the "
"AskUserQuestion tool. Never ask questions inline in plain text.\n"
)
P_LEGACY_DEFAULT_SYSTEM_PROMPTS = (
P_LEGACY_DEFAULT_SYSTEM_PROMPT,
P_LEGACY_DEFAULT_SYSTEM_PROMPT.replace(
"1. Connected MCP tools; fastest and most reliable. To reach an integration you "
"don't already see, use MCPSearch then MCPActivate; never ToolSearch for it.\n",
"1. Connected MCP tools; fastest and most reliable. Use ToolSearch to discover "
"what integrations are available if you're unsure.\n",
),
)
def migrate_legacy_fields(raw: dict) -> dict:
@@ -128,7 +137,7 @@ def load_settings() -> AppSettings:
p_preserve_corrupt_settings()
return AppSettings()
settings = p_coerce_settings(migrate_legacy_fields(raw))
if settings.default_system_prompt is None or settings.default_system_prompt == P_LEGACY_DEFAULT_SYSTEM_PROMPT:
if settings.default_system_prompt is None or settings.default_system_prompt in P_LEGACY_DEFAULT_SYSTEM_PROMPTS:
settings.default_system_prompt = DEFAULT_SYSTEM_PROMPT
p_cached_settings = settings.model_copy(deep=True)
p_cached_sig = sig
+5 -1
View File
@@ -54,6 +54,8 @@ def p_drive(monkeypatch, messages, prompt="hi"):
mgr = AgentManager()
from backend.apps.agents.core.models import AgentSession
session = AgentSession(name="t", model="sonnet", dashboard_id="d")
# Several harness turns deliberately end tool-only; spend the silent-quit nudge budget so the seal (tested in test_empty_finish.py) doesn't auto-continue them here.
session.empty_finish_nudges = 1
mgr.sessions[session.id] = session
asyncio.run(mgr.run_agent_loop(session.id, prompt))
return session, events
@@ -259,7 +261,9 @@ def test_full_streaming_turn_drives_the_complete_ws_contract(monkeypatch):
assert any(m.role == "assistant" and "Hello!" in str(m.content) for m in session.messages)
assert session.status == "completed"
assert session.tokens.get("output") == 550 # ResultMessage's authoritative token count landed
assert session.tokens.get("input") == 1100
# Context input = the last STEP's request size (real context), never the result's cross-step billing sum; the sum lives in input_fresh.
assert session.tokens.get("input") == 100
assert session.tokens.get("input_fresh") == 1100
def test_loop_wires_all_four_hooks_to_a_live_hook_context(monkeypatch):