mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-06 17:38:35 +00:00
test(agent): remove obsolete runtime context assertions
This commit is contained in:
parent
54b250430d
commit
d349b65713
@ -283,20 +283,6 @@ class TestBuildMessages:
|
|||||||
messages = builder.build_messages([], "hello", channel="cli", chat_id="direct")
|
messages = builder.build_messages([], "hello", channel="cli", chat_id="direct")
|
||||||
user_msg = str(messages[-1]["content"])
|
user_msg = str(messages[-1]["content"])
|
||||||
assert user_msg == "hello"
|
assert user_msg == "hello"
|
||||||
assert "Runtime Context" not in user_msg
|
|
||||||
assert "Current Time:" not in user_msg
|
|
||||||
assert "Chat ID:" not in user_msg
|
|
||||||
|
|
||||||
def test_session_metadata_does_not_inject_context_without_provider(self, tmp_path):
|
|
||||||
builder = _builder(tmp_path)
|
|
||||||
messages = builder.build_messages(
|
|
||||||
[],
|
|
||||||
"hi",
|
|
||||||
channel="cli",
|
|
||||||
chat_id="x",
|
|
||||||
session_metadata={"goal_state": {"status": "active", "objective": "hidden"}},
|
|
||||||
)
|
|
||||||
assert messages[-1]["content"] == "hi"
|
|
||||||
|
|
||||||
def test_explicit_runtime_context_blocks_are_appended(self, tmp_path):
|
def test_explicit_runtime_context_blocks_are_appended(self, tmp_path):
|
||||||
builder = _builder(tmp_path)
|
builder = _builder(tmp_path)
|
||||||
|
|||||||
@ -62,26 +62,6 @@ def test_system_prompt_reflects_current_dream_memory_contract(tmp_path) -> None:
|
|||||||
assert "write important facts here" not in prompt
|
assert "write important facts here" not in prompt
|
||||||
|
|
||||||
|
|
||||||
def test_default_user_message_has_no_runtime_context(tmp_path) -> None:
|
|
||||||
workspace = _make_workspace(tmp_path)
|
|
||||||
builder = ContextBuilder(workspace)
|
|
||||||
|
|
||||||
messages = builder.build_messages(
|
|
||||||
history=[],
|
|
||||||
current_message="Return exactly: OK",
|
|
||||||
channel="cli",
|
|
||||||
chat_id="direct",
|
|
||||||
)
|
|
||||||
|
|
||||||
assert messages[0]["role"] == "system"
|
|
||||||
assert "## Current Session" not in messages[0]["content"]
|
|
||||||
|
|
||||||
assert messages[-1]["role"] == "user"
|
|
||||||
user_content = messages[-1]["content"]
|
|
||||||
assert user_content == "Return exactly: OK"
|
|
||||||
assert "_meta" not in messages[-1]
|
|
||||||
|
|
||||||
|
|
||||||
def test_provider_context_appended_after_user_content(tmp_path) -> None:
|
def test_provider_context_appended_after_user_content(tmp_path) -> None:
|
||||||
workspace = _make_workspace(tmp_path)
|
workspace = _make_workspace(tmp_path)
|
||||||
builder = ContextBuilder(workspace)
|
builder = ContextBuilder(workspace)
|
||||||
@ -102,42 +82,6 @@ def test_provider_context_appended_after_user_content(tmp_path) -> None:
|
|||||||
assert user_pos < context_pos, "user content must precede provider context"
|
assert user_pos < context_pos, "user content must precede provider context"
|
||||||
|
|
||||||
|
|
||||||
def test_sender_id_is_not_injected_without_provider(tmp_path) -> None:
|
|
||||||
workspace = _make_workspace(tmp_path)
|
|
||||||
builder = ContextBuilder(workspace)
|
|
||||||
|
|
||||||
messages = builder.build_messages(
|
|
||||||
history=[],
|
|
||||||
current_message="Return exactly: OK",
|
|
||||||
channel="cli",
|
|
||||||
chat_id="direct",
|
|
||||||
sender_id="user-12345",
|
|
||||||
)
|
|
||||||
|
|
||||||
user_content = messages[-1]["content"]
|
|
||||||
assert isinstance(user_content, str)
|
|
||||||
assert user_content == "Return exactly: OK"
|
|
||||||
assert "Sender ID:" not in user_content
|
|
||||||
|
|
||||||
|
|
||||||
def test_runtime_context_excludes_sender_id_when_not_provided(tmp_path) -> None:
|
|
||||||
"""Sender ID should not be present in runtime context when not provided."""
|
|
||||||
workspace = _make_workspace(tmp_path)
|
|
||||||
builder = ContextBuilder(workspace)
|
|
||||||
|
|
||||||
messages = builder.build_messages(
|
|
||||||
history=[],
|
|
||||||
current_message="Return exactly: OK",
|
|
||||||
channel="cli",
|
|
||||||
chat_id="direct",
|
|
||||||
sender_id=None,
|
|
||||||
)
|
|
||||||
|
|
||||||
user_content = messages[-1]["content"]
|
|
||||||
assert isinstance(user_content, str)
|
|
||||||
assert "Sender ID:" not in user_content
|
|
||||||
|
|
||||||
|
|
||||||
def test_unprocessed_history_injected_into_system_prompt(tmp_path) -> None:
|
def test_unprocessed_history_injected_into_system_prompt(tmp_path) -> None:
|
||||||
"""Entries in history.jsonl not yet consumed by Dream appear with timestamps."""
|
"""Entries in history.jsonl not yet consumed by Dream appear with timestamps."""
|
||||||
workspace = _make_workspace(tmp_path)
|
workspace = _make_workspace(tmp_path)
|
||||||
|
|||||||
@ -181,8 +181,6 @@ async def test_runtime_context_is_persisted_as_next_turn_prompt_prefix(tmp_path)
|
|||||||
assert second_wire[2]["role"] == "assistant"
|
assert second_wire[2]["role"] == "assistant"
|
||||||
assert second_wire[2]["content"] == "first answer"
|
assert second_wire[2]["content"] == "first answer"
|
||||||
assert second_wire[3]["content"].startswith("second turn")
|
assert second_wire[3]["content"].startswith("second turn")
|
||||||
assert "Current Time:" not in str(second_wire)
|
|
||||||
assert "Chat ID:" not in str(second_wire)
|
|
||||||
assert len(provider_calls) == 2
|
assert len(provider_calls) == 2
|
||||||
|
|
||||||
persisted_first_user = session.messages[0]
|
persisted_first_user = session.messages[0]
|
||||||
|
|||||||
@ -1401,7 +1401,6 @@ async def test_system_subagent_followup_is_persisted_before_prompt_assembly(tmp_
|
|||||||
assert "[Message Time:" not in non_system[0]["content"]
|
assert "[Message Time:" not in non_system[0]["content"]
|
||||||
assert "[Message Time:" not in non_system[1]["content"]
|
assert "[Message Time:" not in non_system[1]["content"]
|
||||||
assert non_system[2]["content"].count("subagent result") == 1
|
assert non_system[2]["content"].count("subagent result") == 1
|
||||||
assert "Current Time:" not in non_system[2]["content"]
|
|
||||||
assert non_system[2]["content"] == "subagent result"
|
assert non_system[2]["content"] == "subagent result"
|
||||||
|
|
||||||
loop.sessions.invalidate("cli:test")
|
loop.sessions.invalidate("cli:test")
|
||||||
|
|||||||
@ -460,27 +460,12 @@ def test_get_history_does_not_duplicate_persisted_cli_app_runtime_context():
|
|||||||
assert public_history == [{"role": "user", "content": "please use @drawio"}]
|
assert public_history == [{"role": "user", "content": "please use @drawio"}]
|
||||||
|
|
||||||
|
|
||||||
def test_get_history_does_not_synthesize_mcp_preset_attachment():
|
def test_public_history_omits_cli_app_breadcrumb():
|
||||||
session = Session(key="test:mcp-preset")
|
|
||||||
session.messages.append({
|
|
||||||
"role": "user",
|
|
||||||
"content": "please use @linear",
|
|
||||||
"mcp_presets": [{"name": "linear", "transport": "stdio"}],
|
|
||||||
})
|
|
||||||
|
|
||||||
assert session.get_history(max_messages=500) == [{
|
|
||||||
"role": "user",
|
|
||||||
"content": "please use @linear",
|
|
||||||
}]
|
|
||||||
|
|
||||||
|
|
||||||
def test_public_history_does_not_synthesize_legacy_capability_context():
|
|
||||||
session = Session(key="test:legacy-capabilities")
|
session = Session(key="test:legacy-capabilities")
|
||||||
session.messages.append({
|
session.messages.append({
|
||||||
"role": "user",
|
"role": "user",
|
||||||
"content": "please use the attachments",
|
"content": "please use the attachments",
|
||||||
"cli_apps": [{"name": "drawio", "entry_point": "cli-anything-drawio"}],
|
"cli_apps": [{"name": "drawio", "entry_point": "cli-anything-drawio"}],
|
||||||
"mcp_presets": [{"name": "linear", "transport": "stdio"}],
|
|
||||||
})
|
})
|
||||||
|
|
||||||
public_history = session.get_history(
|
public_history = session.get_history(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user