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 benchmark/runtime/planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def task_plan_packet(env: dict[str, str], cli: list[str]) -> dict:
cwd=env["LOOPX_PROJECT"],
env=env,
text=True,
encoding="utf-8",
capture_output=True,
check=True,
timeout=120,
Expand Down
1 change: 1 addition & 0 deletions loopx/control_plane/goals/planning_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ def _call(self, *args: str) -> dict[str, object]:
cwd=self.cwd,
env=self.env,
text=True,
encoding="utf-8",
capture_output=True,
timeout=120,
)
Expand Down
34 changes: 34 additions & 0 deletions tests/control_plane/test_benchmark_planning_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,40 @@ def test_planning_batch_non_bmp_utf16_boundaries_match_real_cli(tmp_path, monkey
assert outcome["sources"][0]["summary"] == emoji * 256


@pytest.mark.parametrize("provider", ["file", "sqlite"])
def test_planning_batch_packet_survives_gbk_parent_locale(tmp_path, monkeypatch, provider):
import subprocess
from benchmark.runtime.planning_batch import apply_initial_plan

env, _, _, _, _ = _environment(tmp_path, monkeypatch, provider, replan="empty")
env["LOOPX_TASK_STAGE"] = "plan"
objective = "中文目标:统计并交付结果。"
Path(env["LOOPX_TASK_DOC"]).write_text(objective + "\n", encoding="utf-8")
# A cp936 host decodes an unpinned text-mode child read as gbk, while the
# wrapped CLI always emits UTF-8 JSON (ensure_ascii=False).
monkeypatch.setattr(subprocess, "_text_encoding", lambda: "gbk")

packet = task_plan_packet(env, loopx_command(env))
todo_text = "[P0] 统计中文结果。"
proposal = {
"input_digest": packet["input_digest"],
"expected_provider_revision": packet["goal_acceptance"]["provider_revision"],
"outcome": {
"objective": objective,
"requirements": [{"id": "deliver", "description": "交付并验证中文结果。"}],
"source": {"ref": "checkpoint:utf8", "summary": "中文规划回执。"},
},
"todos": [{"text": todo_text, "action_kind": "implement"}],
}
ready = apply_initial_plan(env, proposal)
assert ready["status"] == "ready"
after = task_plan_packet(env, loopx_command(env))
stored = {item["todo_id"]: item for item in after["existing_todos"]}
assert stored[ready["todo_ids"][0]]["text"] == todo_text
outcome = after["goal_acceptance"]["goal_acceptance_contract"]["outcome_requirements"]["outcomes"][0]
assert outcome["objective"] == objective


@pytest.mark.parametrize("provider", ["file", "sqlite"])
def test_planning_batch_target_key_boundary_real_cli_state(tmp_path, monkeypatch, provider):
import os
Expand Down
25 changes: 25 additions & 0 deletions tests/test_runtime_subprocess_utf8.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,28 @@ def test_change_quality_scope_git_helper_pins_codec_only_in_text_mode(
assert raw.returncode == 0
assert isinstance(raw.stdout, bytes)
assert "中文笔记.txt".encode("utf-8") in raw.stdout


def test_planning_batch_cli_backend_survives_gbk_host_locale(monkeypatch) -> None:
"""The batch-planning CLI receipt decodes UTF-8 JSON on a cp936 host."""

from loopx.control_plane.goals.planning_batch import CliPlanningBatchBackend

monkeypatch.setattr(subprocess, "_text_encoding", lambda: "gbk")
payload = '{"ok": true, "title": "中文目标"}'
script = (
"import sys; sys.stdout.buffer.write("
+ repr(payload.encode("utf-8"))
+ ")"
)
backend = CliPlanningBatchBackend(
cli=[sys.executable, "-c", script],
cwd=".",
env={},
packet_reader=lambda: {},
project=".",
)

receipt = backend._call("status", "read")

assert receipt["title"] == "中文目标"
Loading