fix(editor): 语法检查按钮接真——原为原型期假实现(sleep 600ms恒报通过,用户删中括号仍提示成功);后端POST /strategy/file/{name}/check(compile()不落盘,SyntaxError返行号+消息,与保存的py_compile门禁同源);前端调真接口,错误显示「第N行:消息」红tag+toast,编辑即清;3新后端测试(删括号必报错) [vps]
This commit is contained in:
@@ -67,3 +67,33 @@ def test_file_read_returns_code(monkeypatch, tmp_path):
|
||||
assert isinstance(body["code"], str) and body["code"] # 编辑器空白 bug 的回归测试
|
||||
assert body["name"] == name
|
||||
assert c.get("/api/v1/strategy/file/__no_such__.py").status_code == 404
|
||||
|
||||
|
||||
# ===== 语法检查端点(编辑器「语法检查」按钮真接线)=====
|
||||
|
||||
def test_check_syntax_ok(monkeypatch, tmp_path):
|
||||
c = _client(monkeypatch, tmp_path)
|
||||
r = c.post("/api/v1/strategy/file/foo.py/check",
|
||||
json={"code": "x = [1, 2, 3]\nprint(x)\n"})
|
||||
assert r.status_code == 200
|
||||
assert r.json() == {"ok": True}
|
||||
|
||||
|
||||
def test_check_syntax_catches_missing_bracket(monkeypatch, tmp_path):
|
||||
"""删掉一个中括号必须报错并给行号(2026-08-15 用户实况:删括号仍报通过)。"""
|
||||
c = _client(monkeypatch, tmp_path)
|
||||
r = c.post("/api/v1/strategy/file/foo.py/check",
|
||||
json={"code": "x = [1, 2, 3\nprint(x)\n"})
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["ok"] is False
|
||||
assert body["line"] is not None and body["line"] >= 1
|
||||
assert body["error"]
|
||||
|
||||
|
||||
def test_check_syntax_empty_code_ok(monkeypatch, tmp_path):
|
||||
"""空代码/纯注释可编译 → ok(编辑器允许半成品里写注释)。"""
|
||||
c = _client(monkeypatch, tmp_path)
|
||||
r = c.post("/api/v1/strategy/file/foo.py/check", json={"code": "# 只有注释\n"})
|
||||
assert r.status_code == 200
|
||||
assert r.json()["ok"] is True
|
||||
|
||||
Reference in New Issue
Block a user