fix(editor): 语法检查按钮接真——原为原型期假实现(sleep 600ms恒报通过,用户删中括号仍提示成功);后端POST /strategy/file/{name}/check(compile()不落盘,SyntaxError返行号+消息,与保存的py_compile门禁同源);前端调真接口,错误显示「第N行:消息」红tag+toast,编辑即清;3新后端测试(删括号必报错) [vps]
CI/CD / test (push) Failing after 11m17s
CI/CD / nas-deploy (push) Has been skipped
CI/CD / nas-verify (push) Has been skipped

This commit is contained in:
2026-08-15 21:08:36 +08:00
parent 94507f2ad7
commit 4a6fb4cd37
4 changed files with 71 additions and 4 deletions
+17
View File
@@ -53,6 +53,23 @@ def post_file(name: str, req: FileWriteRequest):
return {"ok": True}
@router.post("/strategy/file/{name}/check")
def check_file(name: str, req: FileWriteRequest):
"""语法检查(不落盘):编辑器「语法检查」按钮真接线。
原前端按钮是原型期假实现(sleep 600ms 恒报通过,2026-08-15 用户实况
删括号仍报成功)。compile() 不执行代码,只做语法编译;SyntaxError
返回行号+消息供编辑器定位。
"""
try:
compile(req.code, name, "exec")
except SyntaxError as e:
return {"ok": False, "error": str(e.msg or e), "line": e.lineno}
except ValueError as e: # null bytes 等 compile 级错误
return {"ok": False, "error": str(e), "line": None}
return {"ok": True}
@router.get("/strategy/instances")
def get_instances():
return instance_store.list_instances()