fix: stabilize web test shard failures

This commit is contained in:
Yanli 盐粒 2026-03-17 18:44:42 +08:00
parent 9100190a68
commit 37df3899ff
3 changed files with 44 additions and 10 deletions

View File

@ -12,6 +12,7 @@ import type {
IOnDataMoreInfo,
IOtherOptions,
} from '@/service/base'
import type { NodeTracing } from '@/types/workflow'
import { uniqBy } from 'es-toolkit/compat'
import { noop } from 'es-toolkit/function'
import { produce, setAutoFreeze } from 'immer'
@ -53,6 +54,39 @@ type SendCallback = {
isPublicAPI?: boolean
}
type ParallelTraceLike = Pick<NodeTracing, 'id' | 'node_id' | 'parallel_id' | 'execution_metadata'>
const findParallelTraceIndex = (
tracing: ParallelTraceLike[],
data: Partial<ParallelTraceLike>,
) => {
const incomingParallelId = data.execution_metadata?.parallel_id ?? data.parallel_id
if (data.id) {
const matchedByIdIndex = tracing.findIndex((item) => {
if (item.id !== data.id)
return false
const existingParallelId = item.execution_metadata?.parallel_id ?? item.parallel_id
if (!existingParallelId || !incomingParallelId)
return true
return existingParallelId === incomingParallelId
})
if (matchedByIdIndex > -1)
return matchedByIdIndex
}
return tracing.findIndex((item) => {
if (item.node_id !== data.node_id)
return false
const existingParallelId = item.execution_metadata?.parallel_id ?? item.parallel_id
return existingParallelId === incomingParallelId
})
}
export const useChat = (
config?: ChatConfig,
formSettings?: {
@ -396,7 +430,7 @@ export const useChat = (
if (!responseItem.workflowProcess?.tracing)
return
const tracing = responseItem.workflowProcess.tracing
const iterationIndex = tracing.findIndex(item => item.id === iterationFinishedData.id)!
const iterationIndex = findParallelTraceIndex(tracing, iterationFinishedData)
if (iterationIndex > -1) {
tracing[iterationIndex] = {
...tracing[iterationIndex],
@ -477,7 +511,7 @@ export const useChat = (
if (!responseItem.workflowProcess?.tracing)
return
const tracing = responseItem.workflowProcess.tracing
const loopIndex = tracing.findIndex(item => item.id === loopFinishedData.id)!
const loopIndex = findParallelTraceIndex(tracing, loopFinishedData)
if (loopIndex > -1) {
tracing[loopIndex] = {
...tracing[loopIndex],
@ -943,7 +977,7 @@ export const useChat = (
},
onIterationFinish: ({ data: iterationFinishedData }) => {
const tracing = responseItem.workflowProcess!.tracing!
const iterationIndex = tracing.findIndex(item => item.id === iterationFinishedData.id)!
const iterationIndex = findParallelTraceIndex(tracing, iterationFinishedData)
if (iterationIndex > -1) {
tracing[iterationIndex] = {
...tracing[iterationIndex],
@ -1034,7 +1068,7 @@ export const useChat = (
},
onLoopFinish: ({ data: loopFinishedData }) => {
const tracing = responseItem.workflowProcess!.tracing!
const loopIndex = tracing.findIndex(item => item.id === loopFinishedData.id)!
const loopIndex = findParallelTraceIndex(tracing, loopFinishedData)
if (loopIndex > -1) {
tracing[loopIndex] = {
...tracing[loopIndex],

View File

@ -264,7 +264,7 @@ describe('UrlInput', () => {
render(<UrlInput {...props} />)
const input = screen.getByRole('textbox')
await userEvent.type(input, longUrl)
fireEvent.change(input, { target: { value: longUrl } })
expect(input).toHaveValue(longUrl)
})
@ -275,7 +275,7 @@ describe('UrlInput', () => {
render(<UrlInput {...props} />)
const input = screen.getByRole('textbox')
await userEvent.type(input, unicodeUrl)
fireEvent.change(input, { target: { value: unicodeUrl } })
expect(input).toHaveValue(unicodeUrl)
})
@ -285,7 +285,7 @@ describe('UrlInput', () => {
render(<UrlInput {...props} />)
const input = screen.getByRole('textbox')
await userEvent.type(input, 'https://rapid.com', { delay: 1 })
fireEvent.change(input, { target: { value: 'https://rapid.com' } })
expect(input).toHaveValue('https://rapid.com')
})
@ -297,7 +297,7 @@ describe('UrlInput', () => {
render(<UrlInput {...props} />)
const input = screen.getByRole('textbox')
await userEvent.type(input, 'https://enter.com')
fireEvent.change(input, { target: { value: 'https://enter.com' } })
// Focus button and press enter
const button = screen.getByRole('button', { name: /run/i })

View File

@ -151,7 +151,7 @@ describe('useDatasetCardState', () => {
expect(result.current.modalState.showRenameModal).toBe(false)
})
it('should close confirm delete modal when closeConfirmDelete is called', () => {
it('should close confirm delete modal when closeConfirmDelete is called', async () => {
const dataset = createMockDataset()
const { result } = renderHook(() =>
useDatasetCardState({ dataset, onSuccess: vi.fn() }),
@ -162,7 +162,7 @@ describe('useDatasetCardState', () => {
result.current.detectIsUsedByApp()
})
waitFor(() => {
await waitFor(() => {
expect(result.current.modalState.showConfirmDelete).toBe(true)
})