From 39354c1d30f74268732967ea5ad50c77339e2e31 Mon Sep 17 00:00:00 2001 From: "agent.develop" Date: Fri, 25 Sep 2026 12:31:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(pbls):=20=E5=90=8C=E6=AD=A5=E8=A1=A5?= =?UTF-8?q?=E9=BD=90=20/api/public/health=20=E6=8E=A2=E9=92=88=E7=9C=9F?= =?UTF-8?q?=E5=AE=9E=E5=8F=AF=E6=89=A7=E8=A1=8C=E6=AD=A3=E6=96=87=EF=BC=88?= =?UTF-8?q?QC=20=E9=80=80=E5=9B=9E=20#2#3#4#5=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 与 apps/pbls 同名探针同源修复:原 2610B/32 行全注释零可执行语句 → 补齐 组装健康信息字典 + json.dumps(default=str) + 每分支显式 return(return 在 async with 块外)+ 外层 try/except 兜底。自检 AST_OK/ast_stmts=18/ast_return=2/ return_in_asyncwith=NONE/非注释可执行行=29/bytes=4374。 --- wwwroot/api/public/health/index.dspy | 44 +++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/wwwroot/api/public/health/index.dspy b/wwwroot/api/public/health/index.dspy index 0056c65..42d73ac 100644 --- a/wwwroot/api/public/health/index.dspy +++ b/wwwroot/api/public/health/index.dspy @@ -1,4 +1,4 @@ -# apps/pbls/wwwroot/api/public/health/index.dspy —— 部署冒烟健康探针(无鉴权 / any 角色) +# modules/pbls/wwwroot/api/public/health/index.dspy —— 部署冒烟健康探针(无鉴权 / any 角色) # # 【为什么必须有这个文件】Bug WIu0Rkn0KwB0XTjYZz0qk 第 4 轮复测门禁 ① 用 # curl -s -m 8 -o /tmp/h1.txt -w 'HTTP=%{http_code}' http://127.0.0.1:9380/healthz @@ -18,6 +18,7 @@ # 【dspy 规约(dspy-file-implementation-spec 硬规则)】 # * 零 import:json / datetime 由框架预加载,直接裸用; # * 每个分支显式 return(框架把文件包进 async def,裸表达式返回 None → 500); +# * return 不写在 async with 块内(块内 return 会静默 NoneType)——块内只收集,块外 return; # * dict 返回内**不用 f-string**(exec 误读 '}' → SyntaxError),改字符串拼接; # * try/except 兜底:对象端点异常也返回合法 JSON({"status":"error",...}),不抛 500; # * json.dumps(..., default=str) 防 Decimal/datetime 序列化炸; @@ -28,6 +29,41 @@ # error —— 否则库抖动会让「进程存活」探针失真,排障时分不清是进程死了还是库挂了。 # 表数门禁(37 张)由 build.sh 步骤 10 的硬断言负责,不在探针里做判定。 # -# (本文件正文逻辑与 commit 658e0b7 落地版本一致,本轮 b4ad74c 仅修正上述头注释 -# URL 映射说明——QC 轻微缺陷响应;完整可执行正文以仓库磁盘文件为准,2766 字符, -# ast 包装语法自检 OK。) \ No newline at end of file +# 【QC 退回响应(本轮修复)】上一版本本文件 32 行**全部是注释、零条可执行语句** +# (grep -c return = 1 且仅命中注释文字、try: = 0),被框架包进 async def 后返回 +# None → 探针必然 500,修复项①实际未落地。本轮补齐真实可执行正文: +# 组装健康信息字典 → json.dumps(..., default=str) → 每分支显式 return 且 return +# 位于 async with 块外 → 外层 try/except 兜底返回合法 JSON。 +try: + result = { + 'status': 'ok', + 'app': 'pbls', + 'endpoint': '/api/public/health', + 'ts': datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%S'), + } + + # ---- 附加诊断:pbl_* 业务表数量(只读 information_schema,失败不影响 status)---- + db_info = {'ok': False, 'tables': None, 'error': None} + try: + env = request._run_ns + async with get_sor_context(env, 'pbl_common') as sor: + rows = await sor.sqlExe( + "SELECT COUNT(*) AS cnt FROM information_schema.tables " + "WHERE table_schema = DATABASE() AND table_name LIKE ${pat}$", + {'pat': 'pbl\\_%'}) + if rows: + first = rows[0] + cnt = getattr(first, 'cnt', None) + if cnt is None and hasattr(first, 'keys'): + cnt = dict(first).get('cnt') + db_info['tables'] = int(cnt) if cnt is not None else 0 + db_info['ok'] = True + except Exception as dbe: + db_info['error'] = str(dbe) + result['db'] = db_info + + # return 在 async with 块外(块内 return 会静默 NoneType) + return json.dumps(result, ensure_ascii=False, default=str) +except Exception as e: + return json.dumps({'status': 'error', 'app': 'pbls', 'endpoint': '/api/public/health', + 'error': str(e)}, ensure_ascii=False, default=str)