From c97d7e79959e39f370679bec04414976bbba96a5 Mon Sep 17 00:00:00 2001 From: hjhan Date: Thu, 30 Jul 2026 10:06:21 +0800 Subject: [PATCH] =?UTF-8?q?feat(diag):=20=E5=8F=AF=E4=BF=9D=E7=95=99?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E6=97=A5=E5=BF=97+=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=AF=E8=BF=BD=E6=BA=AF=E6=9C=BA=E5=88=B6=EF=BC=88=E9=98=B6?= =?UTF-8?q?=E6=AE=B50.5=E6=AD=A2=E8=A1=80=E5=A2=9E=E5=BC=BA=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 解决 EQD-6838 排查时硬编码版本号 v20260729a 散落3处、无法按需开关、 看不到实际加载缓存戳的问题。 层1 运行时开关(核心): - HtmlUtil.cs 新增 GitCommit(读 AssemblyInformationalVersion,零新依赖) - _MainLayout.cshtml 注入 window.ylotc.__diag(jsVersion+git+built) - main.js 顶部新增 otcDebug 工具(banner+log),debug 默认 false 生产零输出 - swapTradeEdit.js / fastVue.base.js 硬编码标记改为 otcDebug.banner - 开启方式:URL ?otcdebug=1(会话)或 localStorage.setItem('otcdebug','1')(持久) 层2 构建守卫: - pre-commit 新增第三块 bundle 版本一致性检查(rebuild-bundles.py --verify) - 修复 Windows python3 Store stub 不可用问题(优先用 python) - 注:bundle 头部不注入 git sha(会随 commit 变化导致 verify 永久失败), 版本可追溯完全由运行时 __diag(后端注入)覆盖 层3 单测预防: - 新增 diag.test.js(213测试之一),用 console spy 守卫开关行为 - 断言不再含硬编码 v20260729a + 防止第二套调试开关回归 验证:11 suites/213 tests 全绿,--verify 通过,C# 编译0错误 --- YLErpWeb/Common/HtmlUtil.cs | 15 +- YLErpWeb/Views/Shared/_MainLayout.cshtml | 12 ++ YLErpWeb/fe-tests/diag.test.js | 177 ++++++++++++++++++ YLErpWeb/fe-tests/hooks/pre-commit | 35 +++- .../Scripts/app/swaptrade/swapTradeEdit.js | 5 +- YLErpWeb/wwwroot/Scripts/base/main.js | 20 ++ YLErpWeb/wwwroot/Scripts/fast/fastVue.base.js | 10 +- YLErpWeb/wwwroot/Statics/bundles/bundle.js | 30 ++- YLErpWeb/wwwroot/Statics/bundles/bundleV2.js | 20 ++ 9 files changed, 316 insertions(+), 8 deletions(-) create mode 100644 YLErpWeb/fe-tests/diag.test.js diff --git a/YLErpWeb/Common/HtmlUtil.cs b/YLErpWeb/Common/HtmlUtil.cs index cc3e6247..1292f24e 100644 --- a/YLErpWeb/Common/HtmlUtil.cs +++ b/YLErpWeb/Common/HtmlUtil.cs @@ -1,5 +1,5 @@ using Microsoft.AspNetCore.Html; -using System.Collections; +using System.Reflection; using YLErp.Events; namespace YLErp @@ -17,6 +17,12 @@ namespace YLErp //bin目录文件版本 public static readonly DateTime BinFileVersion; + /// + /// Git提交哈希(取自程序集 AssemblyInformationalVersion,由.NET SDK在编译时自动生成, + /// 格式 "1.0.0+<sha>";前端诊断信息用它精确定位是哪次提交的部署)。 + /// + public static readonly string GitCommit; + static long _dataCacheUpdateTime; static HtmlUtil() @@ -27,6 +33,13 @@ namespace YLErp BinFileVersion = files.Any() ? files.Max(n => n.LastWriteTime) : DateTime.MinValue; JsVersion = BinFileVersion.ToString("yyMMddHHmmss"); + //从 AssemblyInformationalVersion 读取 git sha(SDK 编译时已嵌入,零额外依赖) + var infoVer = typeof(HtmlUtil).Assembly + .GetCustomAttribute()?.InformationalVersion; + //格式 "1.0.0+",取 + 之后部分;无则回退到完整字符串 + GitCommit = string.IsNullOrEmpty(infoVer) ? "unknown" + : (infoVer.Contains('+') ? infoVer.Substring(infoVer.LastIndexOf('+') + 1) : infoVer); + EventBus.Subscribe(t => { _dataCacheUpdateTime = DateTimeOffset.Now.ToUnixTimeSeconds(); diff --git a/YLErpWeb/Views/Shared/_MainLayout.cshtml b/YLErpWeb/Views/Shared/_MainLayout.cshtml index 07b5b054..59716859 100644 --- a/YLErpWeb/Views/Shared/_MainLayout.cshtml +++ b/YLErpWeb/Views/Shared/_MainLayout.cshtml @@ -157,6 +157,18 @@