Skip to content

The agent that grows with you

test(tools,tui_gateway,cli,plugins): a parseable non-dict JSON file is skipped by the sibling scans

beardthelion72a2dae25f48
diff --git a/tests/hermes_cli/test_local_runtime.py b/tests/hermes_cli/test_local_runtime.py
index 93c5930cc6c..50fb9753f4b 100644
--- a/tests/hermes_cli/test_local_runtime.py
+++ b/tests/hermes_cli/test_local_runtime.py
@@ -870,3 +870,16 @@ def test_bootstrap_failure_never_raises(tmp_path, monkeypatch):
"hermes_cli.local_runtime.binaries.ensure_runtime_installed", boom)
result = bootstrap.ensure_local_runtime({"local_runtime": {"enabled": True}})
assert result is None # no exception escaped
+
+
+def test_manifest_verified_tolerates_non_dict_manifest(tmp_path):
+ """A parseable-but-non-object manifest used to raise AttributeError out of
+ manifest_verified (the .get ran inside a try that only caught decode/OSError),
+ breaking any() scans over install dirs."""
+ from hermes_cli.local_runtime.binaries import manifest_verified
+
+ m = tmp_path / "manifest.json"
+ m.write_text('"oops"', encoding="utf-8")
+ assert manifest_verified(m) is False
+ m.write_text(json.dumps({"verified_version": "5015 (abc)"}), encoding="utf-8")
+ assert manifest_verified(m) is True
diff --git a/tests/plugins/test_a2a_plugin.py b/tests/plugins/test_a2a_plugin.py
index 959d12caa5f..87e903e81f2 100644
--- a/tests/plugins/test_a2a_plugin.py
+++ b/tests/plugins/test_a2a_plugin.py
@@ -1746,3 +1746,15 @@ class TestMultiplexConstructionScope:
assert adapter.agent_name == "default-profile-agent"
assert adapter._agents[""]["description"] == "Default profile's own agent."
assert adapter._public_url == "https://default-profile.example.com/"
+
+
+def test_load_conversation_skips_non_dict_lines(monkeypatch, tmp_path):
+ """A scalar line in a conversation file must not break replay or pollute
+ the list[dict] contract."""
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))
+ protocol.persist_message("ctx-mixed", "user", "hello", "t1")
+ path = protocol._conv_path("ctx-mixed")
+ with open(path, "a", encoding="utf-8") as f:
+ f.write("42\n")
+ convo = protocol.load_conversation("ctx-mixed")
+ assert len(convo) == 1 and convo[0]["text"] == "hello"
diff --git a/tests/test_batch_runner_discard_resume.py b/tests/test_batch_runner_discard_resume.py
index 7f8c725e0fa..2b2dd982ec6 100644
--- a/tests/test_batch_runner_discard_resume.py
+++ b/tests/test_batch_runner_discard_resume.py
@@ -173,3 +173,32 @@ def test_entry_prompt_text_shapes():
assert _entry_prompt_text({"prompt": " padded ", "discarded": "x"}) == "padded"
assert _entry_prompt_text({}) == ""
assert _entry_prompt_text("not-a-dict") == ""
+
+
+def test_scans_skip_non_dict_lines(tmp_path):
+ """A parseable-but-non-object line used to raise AttributeError/TypeError
+ mid-scan (resume scan and dataset load); it is skipped like invalid JSON."""
+ (tmp_path / "batch_1.jsonl").write_text(
+ '"scalar row"\n'
+ + json.dumps({"prompt": "ok q", "completed": True}) + "\n",
+ encoding="utf-8",
+ )
+ runner = _scan_runner(tmp_path)
+ assert runner._scan_completed_prompts_by_content() == {"ok q"}
+ dataset = tmp_path / "dataset.jsonl"
+ dataset.write_text('"not an entry"\n' + json.dumps({"prompt": "real"}) + "\n", encoding="utf-8")
+ runner.dataset_file = dataset
+ assert runner._load_dataset() == [{"prompt": "real"}]
+
+
+def test_combine_batch_files_skips_non_dict_lines(tmp_path):
+ (tmp_path / "batch_1.jsonl").write_text(
+ '42\n'
+ + json.dumps({"conversations": [{"from": "human", "value": "kept"}]}) + "\n",
+ encoding="utf-8",
+ )
+ runner = _scan_runner(tmp_path)
+ kept, _found = runner._combine_batch_files()
+ assert kept == 1
+ out = (tmp_path / "trajectories.jsonl").read_text(encoding="utf-8")
+ assert "kept" in out and "42" not in out
diff --git a/tests/test_trajectory_compressor_async.py b/tests/test_trajectory_compressor_async.py
index 89c381b5242..1f52dce999d 100644
--- a/tests/test_trajectory_compressor_async.py
+++ b/tests/test_trajectory_compressor_async.py
@@ -199,3 +199,14 @@ async def test_generate_summary_async_public_moonshot_cn_kimi_k2_5_omits_tempera
assert result.startswith("[CONTEXT SUMMARY]:")
assert "temperature" not in async_client.chat.completions.create.call_args.kwargs
+
+
+async def test_process_entry_async_passes_non_dict_through():
+ """A scalar JSONL line used to crash on '"conversations" not in entry';
+ unknown shapes pass through byte-faithful."""
+ from trajectory_compressor import TrajectoryCompressor
+
+ compressor = TrajectoryCompressor.__new__(TrajectoryCompressor)
+ entry, metrics = await compressor.process_entry_async(42)
+ assert entry == 42
diff --git a/tests/tools/test_bot_relay.py b/tests/tools/test_bot_relay.py
index 0c584d08032..d56d6ea950c 100644
--- a/tests/tools/test_bot_relay.py
+++ b/tests/tools/test_bot_relay.py
@@ -124,6 +124,23 @@ def test_enqueue_claim_is_atomic_and_single_shot(root):
assert bot_relay.claim_pending_envelopes(root) == []
+def test_claim_skips_non_dict_envelope(root):
+ """A parseable-but-non-object outbox file must not reach the Desktop consumer or
+ crash the claim sweep; the claim stays claimed so it is not re-queued."""
+ bot_relay.write_remote_roster(root, _rows())
+ roster = bot_relay.read_remote_roster(root)
+ target = bot_relay.resolve_remote_target("researcher", roster)
+ env = bot_relay.enqueue_envelope(
+ root, target=target, message="hi", sender_profile="work", sender_handle="work"
+ )
+ base = bot_relay.relay_root(root)
+ bad = base / bot_relay.OUTBOX_DIR / f"{'9' * 32}.json"
+ bad.write_text('"not an envelope"', encoding="utf-8")
+ claimed = bot_relay.claim_pending_envelopes(root)
+ assert [e["id"] for e in claimed] == [env["id"]]
+ assert not bad.exists() and (base / bot_relay.CLAIMED_DIR / bad.name).exists()
+
+
def test_write_reply_validates_envelope_id(root):
with pytest.raises(ValueError):
bot_relay.write_reply(root, "../../etc/passwd", reply="x")
diff --git a/tests/tools/test_browser_lightpanda.py b/tests/tools/test_browser_lightpanda.py
index f5da12a6911..3b0afd51df9 100644
--- a/tests/tools/test_browser_lightpanda.py
+++ b/tests/tools/test_browser_lightpanda.py
@@ -762,3 +762,16 @@ class TestLightpandaSessionLifecycle:
patch("tools.browser_tool._socket_safe_tmpdir", return_value=str(tmp_path)):
bt_lifecycle._reap_orphaned_browser_sessions()
reap.assert_called_once()
+
+ def test_orphan_reaper_survives_non_dict_record(self, tmp_path, monkeypatch):
+ """A parseable-but-non-object state file is swept like an unreadable one —
+ never an AttributeError that wedges the reaper."""
+ from tools import browser_lightpanda
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))
+ state_dir = browser_lightpanda._state_dir()
+ bad = state_dir / "broken.json"
+ bad.write_text('"not a record"', encoding="utf-8")
+ dead_owner = state_dir / "dead.json"
+ dead_owner.write_text(json.dumps({"owner_pid": 2**22 + 7}), encoding="utf-8")
+ assert browser_lightpanda.reap_orphaned_lightpanda() == 0
+ assert not bad.exists() and not dead_owner.exists()
diff --git a/tests/tools/test_write_approval.py b/tests/tools/test_write_approval.py
index 44db6451492..b99960d6907 100644
--- a/tests/tools/test_write_approval.py
+++ b/tests/tools/test_write_approval.py
@@ -48,6 +48,18 @@ def test_invalid_subsystem_is_off(hermes_home):
assert wa.write_approval_enabled("bogus") is False
+def test_list_pending_skips_non_dict_record(hermes_home):
+ """A parseable-but-non-object pending file must be skipped, not crash the sort."""
+ from tools import write_approval as wa
+ wa.stage_write("memory", {"action": "add", "target": "user", "content": "ok"},
+ summary="ok", origin="foreground")
+ pending_dir = wa._pending_path("memory", "").parent
+ (pending_dir / "bad.json").write_text('"not a record"', encoding="utf-8")
+ records = wa.list_pending("memory")
+ assert len(records) == 1 and records[0]["payload"]["content"] == "ok"
+ assert wa.get_pending("memory", "bad") is None
+
+
def test_normalize_enabled_coerces_values():
from tools import write_approval as wa
# Real bools pass through.
diff --git a/tests/tui_gateway/test_spawn_tree_records.py b/tests/tui_gateway/test_spawn_tree_records.py
new file mode 100644
index 00000000000..11630009355
--- /dev/null
+++ b/tests/tui_gateway/test_spawn_tree_records.py
@@ -0,0 +1,35 @@
+"""Tests: spawn_tree.* JSON-RPC handlers (tui_gateway/methods_session.py).
+
+A parseable-but-non-object snapshot file must not wedge ``spawn_tree.list``
+(the legacy per-file scan called ``raw.get`` outside its suppress guard) and
+must not satisfy the ``spawn_tree.load`` result contract.
+"""
+
+import json
+
+import tui_gateway.server as srv
+
+
+def test_spawn_tree_list_survives_non_dict_snapshot(tmp_path, monkeypatch):
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))
+ d = srv._spawn_tree_session_dir("sess-x")
+ (d / "bad.json").write_text('"not a snapshot"', encoding="utf-8")
+ good = d / "good.json"
+ good.write_text(json.dumps({"session_id": "sess-x", "label": "ok"}), encoding="utf-8")
+
+ envelope = srv._methods["spawn_tree.list"](1, {"session_id": "sess-x"})
+ assert "error" not in envelope, envelope
+ entries = envelope["result"]["entries"]
+ labels = {e["label"] for e in entries}
+ assert "ok" in labels and len(entries) == 2 # bad file degrades to a fallback entry
+
+
+def test_spawn_tree_load_rejects_non_dict_snapshot(tmp_path, monkeypatch):
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))
+ d = srv._spawn_tree_session_dir("sess-y")
+ bad = d / "bad.json"
+ bad.write_text("[1, 2]", encoding="utf-8")
+
+ envelope = srv._methods["spawn_tree.load"](1, {"path": str(bad)})
+ assert "error" in envelope
+ assert "not a JSON object" in envelope["error"]["message"]