diff --git a/scripts/src/hwlab-node-web-sentinel-service.ts b/scripts/src/hwlab-node-web-sentinel-service.ts index 7d99a7e1..dc185ba6 100644 --- a/scripts/src/hwlab-node-web-sentinel-service.ts +++ b/scripts/src/hwlab-node-web-sentinel-service.ts @@ -1553,14 +1553,14 @@ function visibleFindingsForRun( const artifactFindings = arrayRecords(artifactSummary.findings) .slice(0, limit) .map((item) => enrichFindingWithCheck(config, compactStoredFinding(item))); - return mergeVisibleFindings(storedFindings, artifactFindings, limit); + return mergeVisibleFindings(config, storedFindings, artifactFindings, limit); } -function mergeVisibleFindings(primary: readonly Record[], artifact: readonly Record[], limit: number): readonly Record[] { +function mergeVisibleFindings(config: WebProbeSentinelServiceConfig, primary: readonly Record[], artifact: readonly Record[], limit: number): readonly Record[] { const merged: Record[] = []; const seen = new Set(); for (const item of [...primary, ...artifact]) { - const id = canonicalFindingIdentity(item); + const id = canonicalFindingIdentity(config, item); const key = id ?? `${JSON.stringify(item).slice(0, 160)}:${stringOrNull(item.severity) ?? stringOrNull(item.level) ?? ""}`; if (seen.has(key)) continue; seen.add(key); @@ -1570,13 +1570,20 @@ function mergeVisibleFindings(primary: readonly Record[], artif return merged; } -function canonicalFindingIdentity(item: Record): string | null { +function canonicalFindingIdentity(config: WebProbeSentinelServiceConfig, item: Record): string | null { const check = record(item.check); - return stringOrNull(item.checkCode) - ?? stringOrNull(check.code) - ?? stringOrNull(item.checkId) - ?? stringOrNull(check.id) - ?? findingIdentity(item); + const explicitCheckCode = stringOrNull(item.checkCode) ?? stringOrNull(check.code); + if (explicitCheckCode !== null) return explicitCheckCode; + const catalog = checkCatalogById(config); + const explicitCheckId = stringOrNull(item.checkId) ?? stringOrNull(check.id); + if (explicitCheckId !== null) { + const entry = catalog.get(explicitCheckId); + return stringOrNull(entry?.code) ?? stringOrNull(entry?.id) ?? explicitCheckId; + } + const findingId = findingIdentity(item); + if (findingId === null) return null; + const entry = catalog.get(findingId); + return stringOrNull(entry?.code) ?? stringOrNull(entry?.id) ?? findingId; } function findingIdentity(item: Record): string | null {