mirror of
https://github.com/langgenius/dify.git
synced 2026-03-25 00:07:56 +08:00
feat(diff-coverage): enhance coverage reporting for multi-line statements and branches (#33516)
Co-authored-by: CodingOnStar <hanxujiang@dify.com>
This commit is contained in:
@ -100,7 +100,7 @@ export function getChangedStatementCoverage(entry, changedLines) {
|
||||
continue
|
||||
}
|
||||
|
||||
uncoveredLines.push(statement.start.line)
|
||||
uncoveredLines.push(getFirstChangedLineInRange(statement, normalizedChangedLines))
|
||||
}
|
||||
|
||||
return {
|
||||
@ -111,6 +111,7 @@ export function getChangedStatementCoverage(entry, changedLines) {
|
||||
}
|
||||
|
||||
export function getChangedBranchCoverage(entry, changedLines) {
|
||||
const normalizedChangedLines = [...(changedLines ?? [])].sort((a, b) => a - b)
|
||||
if (!entry) {
|
||||
return {
|
||||
covered: 0,
|
||||
@ -141,7 +142,7 @@ export function getChangedBranchCoverage(entry, changedLines) {
|
||||
const location = locations[armIndex] ?? branch.loc ?? branch
|
||||
uncoveredBranches.push({
|
||||
armIndex,
|
||||
line: getLocationStartLine(location) ?? branch.line ?? 1,
|
||||
line: getFirstChangedLineInRange(location, normalizedChangedLines, branch.line ?? 1),
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -247,6 +248,20 @@ function rangeIntersectsChangedLines(location, changedLines) {
|
||||
return false
|
||||
}
|
||||
|
||||
function getFirstChangedLineInRange(location, changedLines, fallbackLine = 1) {
|
||||
const startLine = getLocationStartLine(location)
|
||||
const endLine = getLocationEndLine(location) ?? startLine
|
||||
if (!startLine || !endLine)
|
||||
return startLine ?? fallbackLine
|
||||
|
||||
for (const lineNumber of changedLines) {
|
||||
if (lineNumber >= startLine && lineNumber <= endLine)
|
||||
return lineNumber
|
||||
}
|
||||
|
||||
return startLine ?? fallbackLine
|
||||
}
|
||||
|
||||
function getLocationStartLine(location) {
|
||||
return location?.start?.line ?? location?.line ?? null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user