From 223a4d1d62b35dc8774be0d09da42662ceb97adb Mon Sep 17 00:00:00 2001 From: sunlei Date: Sat, 4 Jul 2026 10:33:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DJenkins=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E8=A7=82=E6=B5=8B=E7=8A=B6=E6=80=81=E5=9B=9E=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/selfTest.ts | 30 +++++++++++++++++++++++++++++- src/tools/deployObservation.ts | 12 +++++++++--- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 172519c..cdb671e 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ - 生成改动文档同步计划:按变更文件自动提示需要同步的 README、API、AGENTS、docs、Obsidian、skill 和 ktWorkflow 入口;MCP 不可用时用 `pnpm run change-doc-sync -- --project ` 作为 CLI fallback。 - 生成多仓库提交/推送计划:按仓库分组、建议提交信息、列出提交和推送前检查。 - 生成远程只读健康检查和数据库同步安全向导:覆盖飞牛 NAS 服务探测、GTID、`.kt-workspace/db-sync` 转储、备份库和行数校验。 -- 生成或执行部署观测:把 Jenkins build、`build.xml` SCM revision、日志尾部、K8s Deployment、Pod、`/health/runtime` 和任务 smoke 汇总成 `.kt-workspace/test-artifacts/deploy-observation` 下的运行态证据;Jenkins 状态以日志尾部最终 `Finished:` 为准,日志存在但缺少最终态时不认定发布完成。 +- 生成或执行部署观测:把 Jenkins build、`build.xml` SCM revision/result、日志尾部、K8s Deployment、Pod、`/health/runtime` 和任务 smoke 汇总成 `.kt-workspace/test-artifacts/deploy-observation` 下的运行态证据;Jenkins 状态优先取日志尾部最终 `Finished:`,没有最终行时回退到 `build.xml` 的最终 result,result 为空才视为未完成。 - 生成专项组件工作流:KtTable、BlogArgon、AdminAuth、QQBot、FF14Plugin、NapCatLogin、SystemLog、Knife4jSwagger、FnosK8s 的防踩坑清单和验证点。 - 生成验证进程清理计划:按项目路径和端口给出 PowerShell 检查命令,不直接杀进程。 - 清理历史产物:统一治理 `.kt-workspace` 下的测试/验证产物,按目录最近修改时间只保留最近 3 轮,模板目录永久保留;CLI 默认 dry-run,真实清理必须显式传 `--execute`。 diff --git a/src/selfTest.ts b/src/selfTest.ts index a5156f4..a97f322 100644 --- a/src/selfTest.ts +++ b/src/selfTest.ts @@ -1604,10 +1604,18 @@ export async function runSelfTest(): Promise { throw new Error("deploy observation CLI parser self-check failed"); } + /** + * Builds deploy-observation fixture sections with small overrides for the + * parser branches that need deterministic regression coverage. + * + * @param overrides - Optional section mutations for Jenkins, Kubernetes, runtime health, and task smoke evidence. + * @returns Parsed section map matching the SSH collector output format. + */ const buildDeployObservationTestSections = (overrides: { desiredReplicas?: number; healthStatus?: string; jenkinsBuildXml?: string; + jenkinsResult?: string; logFinishedStatus?: string; logCommit?: string; omitFinishedStatus?: boolean; @@ -1621,7 +1629,7 @@ export async function runSelfTest(): Promise { buildDeployObservationSectionMap([ "__KT_SECTION:jenkins_meta__", "buildNumber=132", - "result=SUCCESS", + `result=${overrides.jenkinsResult ?? "SUCCESS"}`, "__KT_SECTION:jenkins_log_tail__", overrides.logCommit === "" ? `Finished: ${overrides.logFinishedStatus ?? "SUCCESS"}` @@ -1772,6 +1780,25 @@ export async function runSelfTest(): Promise { throw new Error("deploy observation build.xml commit self-check failed"); } + const deployObservationBuildXmlResultWithoutLogFinishedEvidence = + normalizeDeployObservationEvidence({ + checkedAt: new Date("2026-06-14T00:00:02.000Z"), + input: deployObservationInput, + sectionMap: buildDeployObservationTestSections({ + omitFinishedStatus: true, + }), + }); + if ( + deployObservationBuildXmlResultWithoutLogFinishedEvidence.status !== + "passed" || + deployObservationBuildXmlResultWithoutLogFinishedEvidence.details.jenkins + .finishedStatus !== "SUCCESS" + ) { + throw new Error( + "deploy observation build.xml result fallback self-check failed", + ); + } + const deployObservationLogFailureBeatsXmlEvidence = normalizeDeployObservationEvidence({ checkedAt: new Date("2026-06-14T00:00:02.000Z"), @@ -1793,6 +1820,7 @@ export async function runSelfTest(): Promise { checkedAt: new Date("2026-06-14T00:00:02.000Z"), input: deployObservationInput, sectionMap: buildDeployObservationTestSections({ + jenkinsResult: "", omitFinishedStatus: true, }), }); diff --git a/src/tools/deployObservation.ts b/src/tools/deployObservation.ts index f5febc4..374f5f4 100644 --- a/src/tools/deployObservation.ts +++ b/src/tools/deployObservation.ts @@ -396,6 +396,13 @@ export function buildDeployObservationSectionMap( return sections; } +/** + * Normalizes Jenkins build evidence collected from the NAS filesystem. + * + * @param input - Normalized deploy observation request, including the expected job and commit. + * @param sectionMap - SSH output sections containing Jenkins metadata, build.xml snippets, and log tail. + * @returns Jenkins build identity, completion status, and commit-match evidence for closeout assertions. + */ function normalizeJenkinsEvidence( input: NormalizedInput, sectionMap: Map, @@ -407,11 +414,10 @@ function normalizeJenkinsEvidence( const logFinishedStatuses = [...logTail.matchAll(/Finished:\s*([A-Z_]+)/gi)]; const logFinishedStatus = logFinishedStatuses.at(-1)?.[1]?.toUpperCase() || null; - const logTailAvailable = - logTail.trim().length > 0 && !/jenkins log not found:/i.test(logTail); const finishedStatus = logFinishedStatus || - (logTailAvailable ? null : meta.result?.toUpperCase() || null); + meta.result?.toUpperCase() || + null; const expectedCommit = input.expectedCommit || null; return {