import json import subprocess from scripts import execute def test_invoke_codex_uses_utf8_for_unicode_prompt(tmp_path, monkeypatch): phase_dir = tmp_path / "phases" / "unicode-phase" phase_dir.mkdir(parents=True) (phase_dir / "index.json").write_text( json.dumps( { "project": "FESA Structural Solver", "phase": "unicode-phase", "steps": [{"step": 0, "name": "unicode", "status": "pending"}], } ), encoding="utf-8", ) (phase_dir / "step0.md").write_text("Euler–Bernoulli 보", encoding="utf-8") invocation = {} def capture_run(command, **kwargs): invocation["command"] = command invocation["kwargs"] = kwargs return subprocess.CompletedProcess(command, 0, stdout="", stderr="") monkeypatch.setattr(execute, "ROOT", tmp_path) monkeypatch.setattr(execute.subprocess, "run", capture_run) executor = execute.StepExecutor("unicode-phase") executor._invoke_codex({"step": 0, "name": "unicode"}, "승인된 설계 – ") assert "Euler–Bernoulli 보" in invocation["kwargs"]["input"] assert invocation["kwargs"]["encoding"] == "utf-8" if execute.os.name == "nt": config_index = invocation["command"].index("-c") assert invocation["command"][config_index + 1] == 'windows.sandbox="unelevated"' def test_run_git_decodes_output_as_utf8(tmp_path, monkeypatch): invocation = {} def capture_run(command, **kwargs): invocation["command"] = command invocation["kwargs"] = kwargs return subprocess.CompletedProcess(command, 0, stdout="", stderr="") monkeypatch.setattr(execute.subprocess, "run", capture_run) executor = object.__new__(execute.StepExecutor) executor._root = str(tmp_path) executor._run_git("status", "--short") assert invocation["kwargs"]["encoding"] == "utf-8" def test_feature_commit_message_is_windows_console_safe(): message = execute.StepExecutor.FEAT_MSG.format( phase="linear-static-3d-euler-beam", num=0, name="requirements-baseline" ) message.encode("cp949") def test_configure_utf8_stdio_reconfigures_both_streams(monkeypatch): class ReconfigurableStream: def __init__(self): self.encodings = [] def reconfigure(self, *, encoding): self.encodings.append(encoding) stdout = ReconfigurableStream() stderr = ReconfigurableStream() monkeypatch.setattr(execute.sys, "stdout", stdout) monkeypatch.setattr(execute.sys, "stderr", stderr) execute._configure_utf8_stdio() assert stdout.encodings == ["utf-8"] assert stderr.encodings == ["utf-8"]