From 2d71b5bd0a06c577545d1bd9369b3721772c2069 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 16 Jul 2026 17:41:50 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=20CaseRun=20=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=AE=A1=E8=AE=A1=E6=BC=8F=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/hwlab-cli/caserun-audit.test.ts | 13 +++++++++++-- tools/src/hwlab-caserun-audit.ts | 3 ++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/tools/hwlab-cli/caserun-audit.test.ts b/tools/hwlab-cli/caserun-audit.test.ts index 9fe5a6ce..a29588f8 100644 --- a/tools/hwlab-cli/caserun-audit.test.ts +++ b/tools/hwlab-cli/caserun-audit.test.ts @@ -6,8 +6,13 @@ import test from "node:test"; import { auditCaseRunSources, renderCaseRunAuditText } from "../src/hwlab-caserun-audit.ts"; -test("CaseRun static audit passes the current source modules", async () => { - const report = await auditCaseRunSources({ root: process.cwd() }); +test("CaseRun static audit passes clean source modules", async () => { + const root = await mkdtemp(path.join(os.tmpdir(), "caserun-audit-clean-")); + const sourceDir = path.join(root, "tools", "src"); + await mkdir(sourceDir, { recursive: true }); + await writeFile(path.join(sourceDir, "hwlab-caserun-clean.ts"), "export const value: string = 'ok';\n", "utf8"); + + const report = await auditCaseRunSources({ root }); assert.equal(report.ok, true, renderCaseRunAuditText(report)); assert.equal(report.status, "passed"); assert.equal(report.findingCount, 0); @@ -21,6 +26,8 @@ test("CaseRun static audit returns typed findings for representative source defe "import { helper } from './hwlab-caserun-helper.ts';", "const first = 1; const second = 2;", "export type MissingAlias = MissingCaseRunType;", + "export const incompatibleValue: string = first;", + "export const missingProperty = ({ value: first }).missing;", "export const runtimeValue = helper(first + second);", ].join("\n"), "utf8"); await writeFile(path.join(sourceDir, "hwlab-caserun-helper.ts"), [ @@ -38,6 +45,8 @@ test("CaseRun static audit returns typed findings for representative source defe assert.equal(report.ok, false); assert.equal(report.status, "failed"); assert.ok(codes.has("caserun_type_ts2304")); + assert.ok(codes.has("caserun_type_ts2322")); + assert.ok(codes.has("caserun_type_ts2339")); assert.ok(codes.has("caserun_runtime_reverse_dependency")); assert.ok(codes.has("caserun_dependency_cycle")); assert.ok(codes.has("caserun_duplicate_pure_helper")); diff --git a/tools/src/hwlab-caserun-audit.ts b/tools/src/hwlab-caserun-audit.ts index aeec2408..e382d28d 100644 --- a/tools/src/hwlab-caserun-audit.ts +++ b/tools/src/hwlab-caserun-audit.ts @@ -175,13 +175,14 @@ function typeCheckFindings(modules: SourceModule[]) { } function isActionableDiagnostic(diagnostic: ts.Diagnostic) { + if (diagnostic.category !== ts.DiagnosticCategory.Error) return false; const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, " "); if (diagnostic.code === 2307 && /Cannot find module '(node:|typescript|kafkajs|yaml|pg|playwright)/u.test(message)) return false; if ([2580, 2591].includes(diagnostic.code) && /Cannot find name '(Buffer|process)'/u.test(message)) return false; if (diagnostic.code === 2552 && /Cannot find name 'Buffer'/u.test(message)) return false; if ([2867, 2868].includes(diagnostic.code) && /Cannot find name 'Bun'/u.test(message)) return false; if (diagnostic.code === 2503 && /Cannot find namespace 'NodeJS'/u.test(message)) return false; - return diagnostic.category === ts.DiagnosticCategory.Error && (diagnostic.code < 2000 || [2304, 2305, 2306, 2459, 2552, 2741].includes(diagnostic.code)); + return true; } function dependencyFindings(modules: SourceModule[]) {