Skip to content

Commit c538cc7

Browse files
committed
fix: Windows 上写入文件时显式指定 UTF-8 编码
1 parent d8599f5 commit c538cc7

3 files changed

Lines changed: 17 additions & 14 deletions

File tree

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,17 @@ Add to your Cursor settings (Settings → MCP):
140140
}
141141
```
142142

143-
### Claude Desktop
143+
### OpenCode
144144

145-
Edit `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
145+
Edit `~/.config/opencode/opencode.json`:
146146

147147
```json
148148
{
149-
"mcpServers": {
150-
"autocode": {
151-
"command": "autocode-mcp"
149+
"mcp": {
150+
"servers": {
151+
"autocode": {
152+
"command": "autocode-mcp"
153+
}
152154
}
153155
}
154156
}

tests/test_compiler.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async def test_compile_cpp_success():
6565
binary_path = os.path.join(tmpdir, "test" + (".exe" if os.name == "nt" else ""))
6666

6767
# 写入源代码
68-
with open(source_path, "w") as f:
68+
with open(source_path, "w", encoding="utf-8") as f:
6969
f.write(HELLO_WORLD_CODE)
7070

7171
# 编译
@@ -84,7 +84,7 @@ async def test_compile_cpp_syntax_error():
8484
binary_path = os.path.join(tmpdir, "test" + (".exe" if os.name == "nt" else ""))
8585

8686
# 写入错误代码
87-
with open(source_path, "w") as f:
87+
with open(source_path, "w", encoding="utf-8") as f:
8888
f.write("invalid c++ code {{{")
8989

9090
# 编译
@@ -103,7 +103,7 @@ async def test_compile_cpp_timeout():
103103
binary_path = os.path.join(tmpdir, "test" + (".exe" if os.name == "nt" else ""))
104104

105105
# 写入源代码
106-
with open(source_path, "w") as f:
106+
with open(source_path, "w", encoding="utf-8") as f:
107107
f.write(HELLO_WORLD_CODE)
108108

109109
# 编译(设置极短超时)
@@ -135,7 +135,7 @@ async def test_run_binary_success():
135135
source_path = os.path.join(tmpdir, "test.cpp")
136136
binary_path = os.path.join(tmpdir, "test" + (".exe" if os.name == "nt" else ""))
137137

138-
with open(source_path, "w") as f:
138+
with open(source_path, "w", encoding="utf-8") as f:
139139
f.write(HELLO_WORLD_CODE)
140140

141141
compile_result = await compile_cpp(source_path, binary_path)
@@ -157,7 +157,7 @@ async def test_run_binary_timeout():
157157
source_path = os.path.join(tmpdir, "test.cpp")
158158
binary_path = os.path.join(tmpdir, "test" + (".exe" if os.name == "nt" else ""))
159159

160-
with open(source_path, "w") as f:
160+
with open(source_path, "w", encoding="utf-8") as f:
161161
f.write(INFINITE_LOOP_CODE)
162162

163163
compile_result = await compile_cpp(source_path, binary_path)
@@ -191,7 +191,7 @@ async def test_run_binary_with_stdin():
191191
source_path = os.path.join(tmpdir, "test.cpp")
192192
binary_path = os.path.join(tmpdir, "test" + (".exe" if os.name == "nt" else ""))
193193

194-
with open(source_path, "w") as f:
194+
with open(source_path, "w", encoding="utf-8") as f:
195195
f.write(stdin_code)
196196

197197
compile_result = await compile_cpp(source_path, binary_path)
@@ -212,7 +212,7 @@ async def test_run_binary_with_args():
212212
source_path = os.path.join(tmpdir, "test.cpp")
213213
binary_path = os.path.join(tmpdir, "test" + (".exe" if os.name == "nt" else ""))
214214

215-
with open(source_path, "w") as f:
215+
with open(source_path, "w", encoding="utf-8") as f:
216216
f.write(ARGS_CODE)
217217

218218
compile_result = await compile_cpp(source_path, binary_path)
@@ -243,7 +243,7 @@ async def test_compile_all_success():
243243
sources = []
244244
for i in range(3):
245245
source_path = os.path.join(tmpdir, f"test{i}.cpp")
246-
with open(source_path, "w") as f:
246+
with open(source_path, "w", encoding="utf-8") as f:
247247
f.write(f"""
248248
#include <iostream>
249249

tests/test_tools/test_file_ops.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
File 工具组测试。
33
"""
4+
45
import os
56
import tempfile
67

@@ -54,7 +55,7 @@ async def test_file_read():
5455
with tempfile.TemporaryDirectory() as tmpdir:
5556
# 先创建文件
5657
test_file = os.path.join(tmpdir, "read_test.txt")
57-
with open(test_file, "w") as f:
58+
with open(test_file, "w", encoding="utf-8") as f:
5859
f.write("Test content")
5960

6061
result = await tool.execute(

0 commit comments

Comments
 (0)