fix: address review findings (#6666)
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
PR_CHECK_LOG_TAIL_BYTES,
|
||||
PR_CHECK_LOG_TAIL_EARLIER_SEPARATOR,
|
||||
sliceCheckLogTail
|
||||
} from './check-job-log-tail-slice'
|
||||
|
||||
describe('sliceCheckLogTail', () => {
|
||||
it('keeps the recent tail when no earlier error markers are present', () => {
|
||||
const logLines = Array.from({ length: 210 }, (_, index) => `line ${index}`)
|
||||
const sliced = sliceCheckLogTail(logLines.join('\n'))
|
||||
|
||||
expect(sliced).toContain('line 209')
|
||||
expect(sliced).not.toContain('line 0')
|
||||
expect(Buffer.from(sliced, 'utf8').byteLength).toBeLessThanOrEqual(PR_CHECK_LOG_TAIL_BYTES)
|
||||
})
|
||||
|
||||
it('pulls earlier error lines into the excerpt when the recent tail is noisy', () => {
|
||||
const noisyPrefix = Array.from({ length: 120 }, (_, index) => `Setting up package-${index}`)
|
||||
const failure = '##[error]Process completed with exit code 236.'
|
||||
const noisySuffix = Array.from({ length: 100 }, (_, index) => `Running trigger ${index}`)
|
||||
const sliced = sliceCheckLogTail([...noisyPrefix, failure, ...noisySuffix].join('\n'))
|
||||
|
||||
expect(sliced).toContain(failure)
|
||||
expect(sliced).toContain(PR_CHECK_LOG_TAIL_EARLIER_SEPARATOR)
|
||||
expect(sliced).toContain('Running trigger 39')
|
||||
expect(sliced).not.toContain('Setting up package-0')
|
||||
expect(Buffer.from(sliced, 'utf8').byteLength).toBeLessThanOrEqual(PR_CHECK_LOG_TAIL_BYTES)
|
||||
})
|
||||
|
||||
it('still applies the byte cap after combining earlier errors with the recent tail', () => {
|
||||
const logLines = Array.from({ length: 220 }, (_, index) => `line ${index} ${'x'.repeat(120)}`)
|
||||
const sliced = sliceCheckLogTail(logLines.join('\n'))
|
||||
|
||||
expect(sliced).toContain('line 219')
|
||||
expect(Buffer.from(sliced, 'utf8').byteLength).toBeLessThanOrEqual(PR_CHECK_LOG_TAIL_BYTES)
|
||||
})
|
||||
|
||||
it('keeps earlier error context when the recent tail is larger than the byte cap', () => {
|
||||
const noisyPrefix = Array.from({ length: 120 }, (_, index) => `Installing package ${index}`)
|
||||
const failure = 'AssertionError: expected visible failure'
|
||||
const hugeRecentTail = Array.from(
|
||||
{ length: 100 },
|
||||
(_, index) => `recent line ${index} ${'x'.repeat(300)}`
|
||||
)
|
||||
const sliced = sliceCheckLogTail([...noisyPrefix, failure, ...hugeRecentTail].join('\n'))
|
||||
|
||||
expect(sliced).toContain(failure)
|
||||
expect(sliced).toContain(PR_CHECK_LOG_TAIL_EARLIER_SEPARATOR)
|
||||
expect(sliced).toContain('recent line 99')
|
||||
expect(Buffer.from(sliced, 'utf8').byteLength).toBeLessThanOrEqual(PR_CHECK_LOG_TAIL_BYTES)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,84 @@
|
||||
export const PR_CHECK_LOG_TAIL_LINES = 200
|
||||
export const PR_CHECK_LOG_TAIL_RECENT_LINES = 100
|
||||
export const PR_CHECK_LOG_TAIL_BYTES = 16 * 1024
|
||||
export const PR_CHECK_LOG_TAIL_ERROR_CONTEXT_LINES = 2
|
||||
export const PR_CHECK_LOG_TAIL_MAX_EARLIER_LINES = 30
|
||||
export const PR_CHECK_LOG_TAIL_EARLIER_SEPARATOR = '… earlier errors …'
|
||||
|
||||
// Why: install/cache steps can flood the tail; pull a small window around earlier
|
||||
// error markers so failures remain visible without downloading the full job log.
|
||||
const ERROR_LINE_PATTERN =
|
||||
/(?:##\[error\]|::error::|::error\b|\berror:|FAILED|exit code|ENOENT|EACCES|panic:|AssertionError)/i
|
||||
|
||||
function applyLogTailByteCap(text: string): string {
|
||||
if (Buffer.byteLength(text, 'utf8') <= PR_CHECK_LOG_TAIL_BYTES) {
|
||||
return text
|
||||
}
|
||||
return sliceTrailingTextByUtf8Bytes(text, PR_CHECK_LOG_TAIL_BYTES)
|
||||
}
|
||||
|
||||
function sliceTrailingTextByUtf8Bytes(text: string, byteLimit: number): string {
|
||||
let byteLength = 0
|
||||
const characters = Array.from(text)
|
||||
for (let index = characters.length - 1; index >= 0; index -= 1) {
|
||||
const characterByteLength = Buffer.byteLength(characters[index] ?? '', 'utf8')
|
||||
if (byteLength + characterByteLength > byteLimit) {
|
||||
return characters.slice(index + 1).join('')
|
||||
}
|
||||
byteLength += characterByteLength
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
function joinLogExcerptWithByteCap(prefixLines: string[], recentLines: string[]): string {
|
||||
const prefix = prefixLines.join('\n')
|
||||
const prefixByteLength = Buffer.byteLength(prefix, 'utf8')
|
||||
if (prefixByteLength >= PR_CHECK_LOG_TAIL_BYTES) {
|
||||
return sliceTrailingTextByUtf8Bytes(prefix, PR_CHECK_LOG_TAIL_BYTES)
|
||||
}
|
||||
|
||||
const separator = prefix.length > 0 && recentLines.length > 0 ? '\n' : ''
|
||||
const recentBudget =
|
||||
PR_CHECK_LOG_TAIL_BYTES - prefixByteLength - Buffer.byteLength(separator, 'utf8')
|
||||
const recentTail = sliceTrailingTextByUtf8Bytes(recentLines.join('\n'), recentBudget)
|
||||
return `${prefix}${separator}${recentTail}`
|
||||
}
|
||||
|
||||
function collectEarlierErrorLineIndexes(lines: string[], recentStart: number): number[] {
|
||||
const indexes = new Set<number>()
|
||||
for (let index = 0; index < recentStart; index += 1) {
|
||||
if (!ERROR_LINE_PATTERN.test(lines[index] ?? '')) {
|
||||
continue
|
||||
}
|
||||
const contextStart = Math.max(0, index - PR_CHECK_LOG_TAIL_ERROR_CONTEXT_LINES)
|
||||
const contextEnd = Math.min(recentStart - 1, index + PR_CHECK_LOG_TAIL_ERROR_CONTEXT_LINES)
|
||||
for (let contextIndex = contextStart; contextIndex <= contextEnd; contextIndex += 1) {
|
||||
indexes.add(contextIndex)
|
||||
}
|
||||
}
|
||||
return [...indexes].sort((left, right) => left - right)
|
||||
}
|
||||
|
||||
export function sliceCheckLogTail(logText: string): string {
|
||||
const lines = logText.split(/\r?\n/)
|
||||
const recentStart = Math.max(0, lines.length - PR_CHECK_LOG_TAIL_RECENT_LINES)
|
||||
const recentLines = lines.slice(recentStart)
|
||||
|
||||
if (recentStart === 0) {
|
||||
return applyLogTailByteCap(lines.join('\n'))
|
||||
}
|
||||
|
||||
const earlierIndexes = collectEarlierErrorLineIndexes(lines, recentStart)
|
||||
if (earlierIndexes.length === 0) {
|
||||
return applyLogTailByteCap(lines.slice(-PR_CHECK_LOG_TAIL_LINES).join('\n'))
|
||||
}
|
||||
|
||||
const cappedEarlierIndexes = earlierIndexes.slice(-PR_CHECK_LOG_TAIL_MAX_EARLIER_LINES)
|
||||
const earlierLines = cappedEarlierIndexes.map((index) => lines[index] ?? '')
|
||||
// Why: if the recent tail alone exceeds the byte cap, keep the earlier error
|
||||
// context visible instead of truncating it back out of the combined excerpt.
|
||||
return joinLogExcerptWithByteCap(
|
||||
[...earlierLines, PR_CHECK_LOG_TAIL_EARLIER_SEPARATOR],
|
||||
recentLines
|
||||
)
|
||||
}
|
||||
@@ -37,6 +37,7 @@ import {
|
||||
import { mkdtemp, readFile, rm, writeFile } from 'fs/promises'
|
||||
import { join } from 'path'
|
||||
import { tmpdir } from 'os'
|
||||
import { sliceCheckLogTail } from './check-job-log-tail-slice'
|
||||
import { getPRConflictSummary } from './conflict-summary'
|
||||
import { getSshFilesystemProvider } from '../providers/ssh-filesystem-dispatch'
|
||||
import { joinWorktreeRelativePath } from '../runtime/runtime-relative-paths'
|
||||
@@ -98,8 +99,6 @@ type GhExecOptions = ReturnType<typeof ghRepoExecOptions>
|
||||
type HostedReviewLocalGitOptions = ReturnType<typeof getHostedReviewLocalGitOptions>
|
||||
|
||||
const ORCA_REPO = 'stablyai/orca'
|
||||
const PR_CHECK_LOG_TAIL_LINES = 200
|
||||
const PR_CHECK_LOG_TAIL_BYTES = 16 * 1024
|
||||
const PR_CHECK_LOG_TAIL_JOB_LIMIT = 5
|
||||
// Why: each entry holds up to 16KB of log text; bound the cache so a long
|
||||
// session reviewing many failing checks can't grow it without limit.
|
||||
@@ -3155,15 +3154,6 @@ function isCheckJobFailureState(state: string | null | undefined): boolean {
|
||||
)
|
||||
}
|
||||
|
||||
function sliceCheckLogTail(logText: string): string {
|
||||
const lineTail = logText.split(/\r?\n/).slice(-PR_CHECK_LOG_TAIL_LINES).join('\n')
|
||||
const bytes = Buffer.from(lineTail, 'utf8')
|
||||
if (bytes.byteLength <= PR_CHECK_LOG_TAIL_BYTES) {
|
||||
return lineTail
|
||||
}
|
||||
return bytes.subarray(bytes.byteLength - PR_CHECK_LOG_TAIL_BYTES).toString('utf8')
|
||||
}
|
||||
|
||||
function getCheckJobLogTailCacheKey(job: PRCheckRunDetails['jobs'][number]): string | null {
|
||||
if (job.id === null) {
|
||||
return null
|
||||
|
||||
@@ -137,7 +137,7 @@ function JobCard({ job, index }: { job: PRCheckJob; index: number }): React.JSX.
|
||||
</div>
|
||||
)}
|
||||
|
||||
{job.logTail && <CheckJobLogTail logTail={job.logTail} />}
|
||||
{job.logTail && <CheckJobLogTail logTail={job.logTail} expanded={jobFailed} />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,29 @@
|
||||
import React, { useCallback, useRef, useState } from 'react'
|
||||
import React, { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import { Check, Copy } from 'lucide-react'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
const LOG_EXCERPT_ERROR_LINE_PATTERN =
|
||||
/(?:##\[error\]|::error::|::error\b|\berror:|FAILED|exit code|ENOENT|EACCES|panic:|AssertionError)/i
|
||||
|
||||
function getLogExcerptScrollTop(pre: HTMLPreElement, logTail: string): number {
|
||||
const lines = logTail.split(/\r?\n/)
|
||||
let targetLineIndex = lines.length - 1
|
||||
for (let index = 0; index < lines.length; index += 1) {
|
||||
if (LOG_EXCERPT_ERROR_LINE_PATTERN.test(lines[index] ?? '')) {
|
||||
targetLineIndex = index
|
||||
}
|
||||
}
|
||||
|
||||
const lineHeight = Number.parseFloat(getComputedStyle(pre).lineHeight)
|
||||
const approximateLineHeight = Number.isFinite(lineHeight) ? lineHeight : 16
|
||||
const targetScroll = targetLineIndex * approximateLineHeight
|
||||
const maxScroll = Math.max(0, pre.scrollHeight - pre.clientHeight)
|
||||
if (targetLineIndex < lines.length - 1) {
|
||||
return Math.min(maxScroll, Math.max(0, targetScroll - pre.clientHeight / 3))
|
||||
}
|
||||
return maxScroll
|
||||
}
|
||||
|
||||
function CopyButton({
|
||||
text,
|
||||
@@ -62,25 +85,49 @@ function CopyButton({
|
||||
)
|
||||
}
|
||||
|
||||
export function CheckJobLogTail({ logTail }: { logTail: string }): React.JSX.Element {
|
||||
export function CheckJobLogTail({
|
||||
logTail,
|
||||
expanded = false
|
||||
}: {
|
||||
logTail: string
|
||||
expanded?: boolean
|
||||
}): React.JSX.Element {
|
||||
const logPreRef = useRef<HTMLPreElement | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
const logPre = logPreRef.current
|
||||
if (!logPre) {
|
||||
return
|
||||
}
|
||||
// Why: noisy install/cache output buries failures at the top of the excerpt;
|
||||
// jump to the last error marker when present, otherwise the log end.
|
||||
logPre.scrollTop = getLogExcerptScrollTop(logPre, logTail)
|
||||
}, [expanded, logTail])
|
||||
|
||||
return (
|
||||
<div className="mt-3 min-w-0">
|
||||
<div className="mb-1.5 flex min-w-0 items-center gap-2">
|
||||
<div className="min-w-0 flex-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground">
|
||||
{translate(
|
||||
'auto.components.right.sidebar.checks.panel.content.d713f500b2',
|
||||
'Log tail (last 200 lines)'
|
||||
'Log excerpt'
|
||||
)}
|
||||
</div>
|
||||
<CopyButton
|
||||
text={logTail}
|
||||
title={translate(
|
||||
'auto.components.right.sidebar.checks.panel.content.679bf2093c',
|
||||
'Copy log tail'
|
||||
'Copy log excerpt'
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<pre className="max-h-72 overflow-auto whitespace-pre-wrap rounded bg-muted/40 p-3 font-mono text-xs text-muted-foreground scrollbar-sleek">
|
||||
<pre
|
||||
ref={logPreRef}
|
||||
className={cn(
|
||||
'overflow-auto whitespace-pre-wrap rounded bg-muted/40 p-3 font-mono text-xs text-muted-foreground scrollbar-sleek',
|
||||
expanded ? 'min-h-48 max-h-[min(50vh,32rem)]' : 'max-h-72'
|
||||
)}
|
||||
>
|
||||
{logTail}
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
@@ -377,8 +377,20 @@ describe('CheckJobLogTail', () => {
|
||||
})
|
||||
)
|
||||
|
||||
expect(markup).toContain('Log tail (last 200 lines)')
|
||||
expect(markup).toContain('Log excerpt')
|
||||
expect(markup).toContain('Error: expected true to be false')
|
||||
expect(markup).toContain('Copy log tail')
|
||||
expect(markup).toContain('Copy log excerpt')
|
||||
})
|
||||
|
||||
it('uses a taller viewport when expanded for failed-job details', () => {
|
||||
const markup = renderToStaticMarkup(
|
||||
React.createElement(CheckJobLogTail, {
|
||||
logTail: 'Error: expected true to be false',
|
||||
expanded: true
|
||||
})
|
||||
)
|
||||
|
||||
expect(markup).toContain('min-h-48')
|
||||
expect(markup).toContain('max-h-[min(50vh,32rem)]')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -8996,8 +8996,8 @@
|
||||
"5e52f4ef7f": "failing",
|
||||
"02ca4f9074": "passing",
|
||||
"e15a8b77ef": "No inline details are available for this check.",
|
||||
"679bf2093c": "Copy log tail",
|
||||
"d713f500b2": "Log tail (last 200 lines)",
|
||||
"679bf2093c": "Copy log excerpt",
|
||||
"d713f500b2": "Log excerpt",
|
||||
"a916648574": "Open details",
|
||||
"07eccfa397": "No details are available for this check.",
|
||||
"49731703ea": "Jobs",
|
||||
|
||||
Reference in New Issue
Block a user