test: fix web test

Signed-off-by: -LAN- <laipz8200@outlook.com>
This commit is contained in:
-LAN- 2025-08-29 23:20:28 +08:00
parent 5415d0c6d1
commit 11d32ca87d
No known key found for this signature in database
GPG Key ID: 6BA0D108DED011FF

View File

@ -9,10 +9,16 @@ const remove = (node: AgentLogItemWithChildren, removeId: string) => {
if (!children || children.length === 0) if (!children || children.length === 0)
return return
const hasCircle = !!children.find(c => c.message_id === removeId) const hasCircle = !!children.find((c) => {
const childId = c.message_id || (c as any).id
return childId === removeId
})
if (hasCircle) { if (hasCircle) {
node.hasCircle = true node.hasCircle = true
node.children = node.children.filter(c => c.message_id !== removeId) node.children = node.children.filter((c) => {
const childId = c.message_id || (c as any).id
return childId !== removeId
})
children = node.children children = node.children
} }
@ -28,9 +34,10 @@ const removeRepeatedSiblings = (list: AgentLogItemWithChildren[]) => {
const result: AgentLogItemWithChildren[] = [] const result: AgentLogItemWithChildren[] = []
const addedItemIds: string[] = [] const addedItemIds: string[] = []
list.forEach((item) => { list.forEach((item) => {
if (!addedItemIds.includes(item.message_id)) { const itemId = item.message_id || (item as any).id
if (itemId && !addedItemIds.includes(itemId)) {
result.push(item) result.push(item)
addedItemIds.push(item.message_id) addedItemIds.push(itemId)
} }
}) })
return result return result
@ -38,16 +45,26 @@ const removeRepeatedSiblings = (list: AgentLogItemWithChildren[]) => {
const removeCircleLogItem = (log: AgentLogItemWithChildren) => { const removeCircleLogItem = (log: AgentLogItemWithChildren) => {
const newLog = cloneDeep(log) const newLog = cloneDeep(log)
// If no children, return as is
if (!newLog.children || newLog.children.length === 0)
return newLog
newLog.children = removeRepeatedSiblings(newLog.children) newLog.children = removeRepeatedSiblings(newLog.children)
let { message_id: id, children } = newLog const id = newLog.message_id || (newLog as any).id
if (!children || children.length === 0) let { children } = newLog
return log
// check one step circle // check one step circle
const hasOneStepCircle = !!children.find(c => c.message_id === id) const hasOneStepCircle = !!children.find((c) => {
const childId = c.message_id || (c as any).id
return childId === id
})
if (hasOneStepCircle) { if (hasOneStepCircle) {
newLog.hasCircle = true newLog.hasCircle = true
newLog.children = newLog.children.filter(c => c.message_id !== id) newLog.children = newLog.children.filter((c) => {
const childId = c.message_id || (c as any).id
return childId !== id
})
children = newLog.children children = newLog.children
} }
@ -62,21 +79,54 @@ const listToTree = (logs: AgentLogItem[]) => {
if (!logs || logs.length === 0) if (!logs || logs.length === 0)
return [] return []
const tree: AgentLogItemWithChildren[] = [] // First pass: identify all unique items and track parent-child relationships
logs.forEach((log) => { const itemsById = new Map<string, any>()
const hasParent = !!log.parent_id const childrenById = new Map<string, any[]>()
if (hasParent) {
const parent = logs.find(item => item.message_id === log.parent_id) as AgentLogItemWithChildren logs.forEach((item) => {
if (parent) { const itemId = item.message_id || (item as any).id
if (!parent.children)
parent.children = [] // Only add to itemsById if not already there (keep first occurrence)
parent.children.push(log as AgentLogItemWithChildren) if (itemId && !itemsById.has(itemId))
} itemsById.set(itemId, item)
}
else { // Initialize children array for this ID if needed
tree.push(log as AgentLogItemWithChildren) if (itemId && !childrenById.has(itemId))
childrenById.set(itemId, [])
// If this item has a parent, add it to parent's children list
if (item.parent_id) {
if (!childrenById.has(item.parent_id))
childrenById.set(item.parent_id, [])
childrenById.get(item.parent_id)!.push(item)
} }
}) })
// Second pass: build tree structure
const tree: AgentLogItemWithChildren[] = []
// Find root nodes (items without parents)
itemsById.forEach((item) => {
const hasParent = !!item.parent_id
if (!hasParent) {
const itemId = item.message_id || (item as any).id
const children = childrenById.get(itemId)
if (children && children.length > 0)
item.children = children
tree.push(item as AgentLogItemWithChildren)
}
})
// Add children property to all items that have children
itemsById.forEach((item) => {
const itemId = item.message_id || (item as any).id
const children = childrenById.get(itemId)
if (children && children.length > 0)
item.children = children
})
return tree return tree
} }