The agent that turns websites into APIs!
test(windows): make launcher verification independent of npm cache
kalil0321353a901c5d7e
diff --git a/src/reverse_api/cli.py b/src/reverse_api/cli.pyindex 6969b58..0e4a1b7 100644--- a/src/reverse_api/cli.py+++ b/src/reverse_api/cli.py@@ -3037,21 +3037,21 @@ def _run_script_machine_payload(from .runtime_commands import resolve_windows_commandsteps[0] = resolve_windows_command([executable, *steps[0][1:]])- result = None+ binary_result = Nonefor cmd in steps:emit_event("process_started", run_id=run_id, script_path=str(script))- result = subprocess.run(cmd, cwd=str(script.parent), capture_output=True)- if result.returncode != 0:+ binary_result = subprocess.run(cmd, cwd=str(script.parent), capture_output=True)+ if binary_result.returncode != 0:break- assert result is not None, "build_script_commands returned no execution steps"+ assert binary_result is not None, "build_script_commands returned no execution steps"return _build_run_payload(identifier=identifier,run_id=run_id,script_path=str(script),script_args=script_args,- returncode=result.returncode,- stdout=decode_process_output(result.stdout),- stderr=decode_process_output(result.stderr),+ returncode=binary_result.returncode,+ stdout=decode_process_output(binary_result.stdout),+ stderr=decode_process_output(binary_result.stderr),scripts=scripts,)diff --git a/src/reverse_api/runtime_commands.py b/src/reverse_api/runtime_commands.pyindex a5f7bb7..9c383f5 100644--- a/src/reverse_api/runtime_commands.py+++ b/src/reverse_api/runtime_commands.py@@ -15,10 +15,12 @@ def decode_process_output(output: bytes | str | None) -> str:return ""if isinstance(output, bytes):try:- output = output.decode("utf-8")+ text = output.decode("utf-8")except UnicodeDecodeError:- output = output.decode(locale.getencoding(), errors="replace")- return output.replace("\r\n", "\n").replace("\r", "\n")+ text = output.decode(locale.getencoding(), errors="replace")+ else:+ text = output+ return text.replace("\r\n", "\n").replace("\r", "\n")def resolve_windows_command(argv: list[str]) -> list[str]:diff --git a/tests/test_opencode_runtime.py b/tests/test_opencode_runtime.pyindex 1e76a84..3e99b7a 100644--- a/tests/test_opencode_runtime.py+++ b/tests/test_opencode_runtime.py@@ -160,7 +160,7 @@ async def test_starts_latest_package_without_global_opencode(monkeypatch: pytestwith patch.object(opencode_runtime.shutil,"which",- side_effect=lambda name: None if name == "opencode" else f"/bin/{name}",+ side_effect=lambda name: None if name == "opencode" else name if name.startswith("/bin/") else f"/bin/{name}",):with patch.object(opencode_runtime.subprocess, "Popen", return_value=process) as popen:status = await opencode_runtime.ensure_opencode_server(diff --git a/tests/test_runtime_commands.py b/tests/test_runtime_commands.pyindex 67c9d34..2653913 100644--- a/tests/test_runtime_commands.py+++ b/tests/test_runtime_commands.py@@ -68,10 +68,15 @@ def test_native_node_preserves_shell_characters(tmp_path):def test_real_npx_preserves_client_arguments(tmp_path):npx = shutil.which("npx")assert npx, "npx must be available on Windows CI"- script = tmp_path / "echo args.js"- script.write_text("console.log(JSON.stringify(process.argv.slice(2)))", encoding="utf-8")+ script = tmp_path / "echo-args.js"+ script.write_text("#!/usr/bin/env node\nconsole.log(JSON.stringify(process.argv.slice(2)))", encoding="utf-8")+ (tmp_path / "package.json").write_text(json.dumps({+ "name": "rae-argument-fixture", "version": "1.0.0",+ "bin": {"rae-echo": "echo-args.js"},+ }), encoding="utf-8")arguments = ["https://example.com/?a=1&b=2|three", "%PATH%", "!literal!", 'quoted"text', "中文"]- argv = resolve_windows_command([npx, "--offline", "--", "node", str(script), *arguments])+ # A local dependency-free fixture avoids relying on cached registry metadata.+ argv = resolve_windows_command([npx, "--offline", "--yes", "--package", str(tmp_path), "rae-echo", *arguments])assert argv[0].lower().endswith("node.exe"), "must bypass the batch shim"result = subprocess.run(argv, capture_output=True, encoding="utf-8", check=True, timeout=30)assert json.loads(result.stdout) == arguments