Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions loopx/capabilities/context_providers/openviking.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ def _run(
return self.runner(
command,
text=True,
encoding="utf-8",
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
timeout=max(1.0, timeout_seconds),
Expand Down
1 change: 1 addition & 0 deletions loopx/capabilities/manager_context/ssh_evidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ def unavailable(code: str, reason: str) -> dict[str, Any]:
[*ssh, host, command],
capture_output=True,
text=True,
encoding="utf-8",
timeout=timeout_seconds,
)
if result.returncode:
Expand Down
2 changes: 2 additions & 0 deletions loopx/extensions/lark/cli_resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ def _version(
check=False,
env=env,
text=True,
encoding="utf-8",
errors="replace",
timeout=5,
)
except (OSError, subprocess.SubprocessError):
Expand Down
16 changes: 16 additions & 0 deletions tests/capabilities/test_reward_memory_provider_retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,19 @@ def runner(command, **kwargs):
assert result.status == "unavailable"
assert result.reason_code == "provider_server_version_incompatible"
assert "server 0.4.17" in str(result.provider_version)


def test_openviking_rejects_malformed_utf8_stdout():
def runner(command, **kwargs):
raise UnicodeDecodeError("utf-8", b"\xff", 0, 1, "invalid start byte")

with pytest.raises(UnicodeDecodeError):
OpenVikingContextProvider(runner=runner).retrieve(
namespace="reward_memory",
scope_ref="viking://user/default/resources",
query="test",
query_summary="test",
max_results=5,
timeout_seconds=5,
observed_at="2026-01-01T00:00:00Z",
)
57 changes: 57 additions & 0 deletions tests/test_manager_ssh_evidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,3 +828,60 @@ def test_remote_agent_search_keeps_source_and_audience_scope(remote):
assert argv[argv.index("--goal-id") + 1] == "remote-goal"
assert argv[argv.index("--offset") + 1] == "12"
assert records[-1]["source_id"] == "ssh:research-host"


def test_remote_read_rejects_malformed_utf8_stdout(tmp_path):
config, channel = _evidence_root(tmp_path)

def runner(argv, **kwargs):
raise UnicodeDecodeError("utf-8", b"\xff", 0, 1, "invalid start byte")

packet = remote_evidence(
tmp_path,
channel,
False,
window_days=7,
scope_valid=lambda: True,
config_path=config,
runner=runner,
)

assert packet["read_status"] == "unavailable"
assert packet["sources"][0]["status"] == "unavailable"
assert packet["sources"][0]["reason_code"] == "remote_protocol_unavailable"


def test_remote_read_accepts_valid_utf8_chinese_stdout(tmp_path):
config, channel = _evidence_root(tmp_path)

def runner(argv, **kwargs):
return subprocess.CompletedProcess(
argv,
0,
stdout=json.dumps(
{
"schema_version": "manager_evidence_page_v1",
"ok": True,
"rows": [{"goal_id": "remote-goal", "title": "远程测试任务"}],
"source": {"coverage": {"discovered": 1}},
"next_offset": None,
},
ensure_ascii=False,
),
stderr="",
)

packet = remote_evidence(
tmp_path,
channel,
False,
window_days=7,
scope_valid=lambda: True,
config_path=config,
runner=runner,
)

assert packet["read_status"] == "read"
assert packet["sources"][0]["status"] == "read"
assert packet["sources"][0]["fresh"] is True
assert packet["sources"][0]["rows_included"] == 1
Loading