fix: count skipped stages in parsing progress

main
ttommybot 2026-08-03 13:52:18 +08:00 committed by lyingbug
parent 60028cbe0e
commit d3055ae068
2 changed files with 36 additions and 4 deletions

View File

@ -0,0 +1,28 @@
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { dirname, join } from 'node:path'
import test from 'node:test'
import { fileURLToPath } from 'node:url'
const here = dirname(fileURLToPath(import.meta.url))
const source = readFileSync(join(here, 'knowledge-processing-timeline.vue'), 'utf8')
test('counts skipped stages when determining the current stage', () => {
const currentStageIndex = source.slice(
source.indexOf('const currentStageIndex'),
source.indexOf('function formatDuration'),
)
assert.match(currentStageIndex, /status === 'done' \|\| s\.status === 'skipped'/)
assert.match(currentStageIndex, /Math\.min\(traversed \+ 1, stages\.value\.length\)/)
})
test('counts skipped stages in the completed stage total', () => {
const stagesStatDisplay = source.slice(
source.indexOf('const stagesStatDisplay'),
source.indexOf('const postprocessTaskStats'),
)
assert.match(stagesStatDisplay, /status === 'done' \|\| s\.status === 'skipped'/)
assert.match(stagesStatDisplay, /value: `\$\{completedCount\}\/\$\{total\}`/)
})

View File

@ -167,8 +167,10 @@ const currentStageLabel = computed(() => {
const currentStageIndex = computed(() => {
const idx = stages.value.findIndex((s) => s.status === 'running' || s.status === 'failed')
if (idx >= 0) return idx + 1
const done = stages.value.filter((s) => s.status === 'done').length
return Math.min(done + 1, stages.value.length)
const traversed = stages.value.filter(
(s) => s.status === 'done' || s.status === 'skipped',
).length
return Math.min(traversed + 1, stages.value.length)
})
function formatDuration(ms?: number): string {
@ -1182,7 +1184,9 @@ const showLastError = computed(() =>
const stagesStatDisplay = computed(() => {
const total = stages.value.length
const doneCount = stages.value.filter((s) => s.status === 'done').length
const completedCount = stages.value.filter(
(s) => s.status === 'done' || s.status === 'skipped',
).length
const inProgress = stages.value.some(
(s) => s.status === 'running' || s.status === 'failed' || s.status === 'pending',
)
@ -1194,7 +1198,7 @@ const stagesStatDisplay = computed(() => {
}
return {
label: t('knowledgeStages.head.stagesDone'),
value: `${doneCount}/${total}`,
value: `${completedCount}/${total}`,
}
})