LCOV - code coverage report
Current view: top level - src/platform/workflowErrors/overlay - useErrorOverlayState.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 100.0 % 77 77
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : import { computed } from 'vue'
       2              : import { useI18n } from 'vue-i18n'
       3              : import { storeToRefs } from 'pinia'
       4              : 
       5              : import { isIssuesTabEnabled } from '@/platform/settings/missingWarningVisibility'
       6              : import { useExecutionErrorStore } from '@/stores/executionErrorStore'
       7              : import { useErrorGroups } from '@/platform/workflowErrors/panel/useErrorGroups'
       8              : import type {
       9              :   MissingPackGroup,
      10              :   SwapNodeGroup
      11              : } from '@/platform/workflowErrors/panel/useErrorGroups'
      12              : import {
      13              :   buildAllErrorContext,
      14              :   buildGroupErrorContext
      15              : } from '@/platform/workflowErrors/panel/buildAgentErrorContext'
      16              : import type { ErrorGroup } from '@/platform/workflowErrors/panel/types'
      17              : import type { MissingMediaGroup } from '@/platform/workflowErrors/missingMedia/types'
      18              : import type { MissingModelGroup } from '@/platform/workflowErrors/missingModel/types'
      19              : 
      20              : type OverlayCopy = { title?: string; message: string }
      21              : 
      22          427 : function resolveSingleOverlayCopy(group: ErrorGroup): OverlayCopy | undefined {
      23          427 :   if (group.type === 'execution') {
      24           23 :     const [card] = group.cards
      25           23 :     const [error] = card.errors
      26           23 :     const message = error.toastMessage ?? error.displayMessage ?? error.message
      27              : 
      28           23 :     if (!message) return undefined
      29              : 
      30           23 :     return {
      31              :       title: error.toastTitle ?? error.displayTitle ?? group.displayTitle,
      32              :       message
      33              :     }
      34              :   }
      35              : 
      36          427 :   const message =
      37              :     group.toastMessage ?? group.displayMessage ?? group.displayTitle
      38          427 :   if (!message) return undefined
      39              : 
      40          427 :   return {
      41              :     title: group.toastTitle ?? group.displayTitle,
      42              :     message
      43              :   }
      44              : }
      45              : 
      46           12 : function resolveGroupOverlayCopy(group: ErrorGroup): OverlayCopy | undefined {
      47           12 :   const message =
      48              :     group.displayMessage ?? group.toastMessage ?? group.displayTitle
      49           12 :   if (!message) return undefined
      50              : 
      51           12 :   return {
      52              :     title: group.displayTitle,
      53              :     message
      54              :   }
      55              : }
      56              : 
      57           40 : function countMissingNodeReferences(groups: MissingPackGroup[]): number {
      58           40 :   return groups.reduce((count, group) => count + group.nodeTypes.length, 0)
      59              : }
      60              : 
      61           14 : function countSwapNodeReferences(groups: SwapNodeGroup[]): number {
      62           14 :   return groups.reduce((count, group) => count + group.nodeTypes.length, 0)
      63              : }
      64              : 
      65          697 : function getMissingModelRows(groups: MissingModelGroup[]) {
      66          697 :   return groups.flatMap((group) => group.models)
      67              : }
      68              : 
      69           30 : function getMissingMediaRows(groups: MissingMediaGroup[]) {
      70           30 :   return groups.flatMap((group) => group.items)
      71              : }
      72              : 
      73          362 : function hasSingleRowWithAtMostOneReference(
      74              :   rows: Array<{ referencingNodes: readonly unknown[] }>
      75              : ): boolean {
      76          362 :   const row = rows[0]
      77          362 :   return rows.length === 1 && row.referencingNodes.length <= 1
      78              : }
      79              : 
      80              : interface OverlayGroupContext {
      81              :   missingPackGroups: MissingPackGroup[]
      82              :   missingModelGroups: MissingModelGroup[]
      83              :   missingMediaGroups: MissingMediaGroup[]
      84              :   swapNodeGroups: SwapNodeGroup[]
      85              : }
      86              : 
      87          439 : function isSingleLeafGroup(
      88              :   group: ErrorGroup,
      89              :   context: OverlayGroupContext
      90              : ): boolean {
      91          439 :   if (group.type === 'execution') {
      92           23 :     return group.cards.length === 1 && group.cards[0]?.errors.length === 1
      93              :   }
      94              : 
      95          437 :   if (group.type === 'missing_node') {
      96           40 :     return (
      97              :       context.missingPackGroups.length === 1 &&
      98              :       countMissingNodeReferences(context.missingPackGroups) === 1
      99              :     )
     100              :   }
     101              : 
     102          433 :   if (group.type === 'swap_nodes') {
     103           14 :     return (
     104              :       context.swapNodeGroups.length === 1 &&
     105              :       countSwapNodeReferences(context.swapNodeGroups) === 1
     106              :     )
     107              :   }
     108              : 
     109          362 :   if (group.type === 'missing_model') {
     110          348 :     return hasSingleRowWithAtMostOneReference(
     111              :       getMissingModelRows(context.missingModelGroups)
     112              :     )
     113              :   }
     114              : 
     115           14 :   return hasSingleRowWithAtMostOneReference(
     116              :     getMissingMediaRows(context.missingMediaGroups)
     117              :   )
     118              : }
     119              : 
     120          447 : function shouldUseAggregateCopyForSingleGroup(
     121              :   group: ErrorGroup,
     122              :   context: OverlayGroupContext
     123              : ): boolean {
     124          447 :   if (group.type === 'missing_node') {
     125           40 :     return context.missingPackGroups.length > 1
     126              :   }
     127              : 
     128          441 :   if (group.type === 'swap_nodes') {
     129           19 :     return context.swapNodeGroups.length > 1
     130              :   }
     131              : 
     132          388 :   if (group.type === 'missing_model') {
     133          349 :     return getMissingModelRows(context.missingModelGroups).length > 1
     134              :   }
     135              : 
     136           57 :   if (group.type === 'missing_media') {
     137           16 :     return getMissingMediaRows(context.missingMediaGroups).length > 1
     138              :   }
     139              : 
     140           23 :   return false
     141              : }
     142              : 
     143         2155 : export function useErrorOverlayState() {
     144         2155 :   const { t } = useI18n()
     145         2155 :   const executionErrorStore = useExecutionErrorStore()
     146         2155 :   const { isErrorOverlayOpen } = storeToRefs(executionErrorStore)
     147         2155 :   const {
     148              :     allErrorGroups,
     149              :     missingPackGroups,
     150              :     missingModelGroups,
     151              :     missingMediaGroups,
     152              :     swapNodeGroups
     153              :   } = useErrorGroups('')
     154              : 
     155         2155 :   const hasError = computed(() =>
     156              :     allErrorGroups.value.some((group) => group.severity === 'error')
     157              :   )
     158              : 
     159         2155 :   const hasMissingNodes = computed(() =>
     160              :     allErrorGroups.value.some((group) => group.type === 'missing_node')
     161              :   )
     162              : 
     163         2155 :   const downloadableMissingModelGroups = computed(() =>
     164              :     allErrorGroups.value.every((group) => group.type === 'missing_model')
     165              :       ? missingModelGroups.value
     166              :       : []
     167              :   )
     168              : 
     169         2155 :   const totalErrorCount = computed(() =>
     170              :     allErrorGroups.value.reduce((sum, group) => sum + group.count, 0)
     171              :   )
     172              : 
     173         2155 :   const multipleIssueCountLabel = computed(() =>
     174              :     t(
     175              :       'errorOverlay.multipleIssueCount',
     176              :       { count: totalErrorCount.value },
     177              :       totalErrorCount.value
     178              :     )
     179              :   )
     180              : 
     181         2155 :   const aggregateOverlayCopy = computed<OverlayCopy>(() => ({
     182              :     title: multipleIssueCountLabel.value,
     183              :     message: t('errorOverlay.multipleIssuesMessage')
     184              :   }))
     185              : 
     186         2155 :   const overlayCopy = computed<OverlayCopy | undefined>(() => {
     187          460 :     const groups = allErrorGroups.value
     188          460 :     if (groups.length === 0) return undefined
     189          460 :     if (groups.length > 1) return aggregateOverlayCopy.value
     190              : 
     191          447 :     const [group] = groups
     192          447 :     const context = {
     193              :       missingPackGroups: missingPackGroups.value,
     194              :       missingModelGroups: missingModelGroups.value,
     195              :       missingMediaGroups: missingMediaGroups.value,
     196              :       swapNodeGroups: swapNodeGroups.value
     197              :     }
     198              : 
     199          455 :     if (shouldUseAggregateCopyForSingleGroup(group, context)) {
     200            8 :       return aggregateOverlayCopy.value
     201              :     }
     202              : 
     203          439 :     if (isSingleLeafGroup(group, context)) {
     204          427 :       return resolveSingleOverlayCopy(group) ?? resolveGroupOverlayCopy(group)
     205              :     }
     206              : 
     207           12 :     return resolveGroupOverlayCopy(group)
     208              :   })
     209              : 
     210         2155 :   const overlayMessage = computed(() => overlayCopy.value?.message ?? '')
     211              : 
     212         2155 :   const overlayTitle = computed(() => overlayCopy.value?.title ?? '')
     213              : 
     214         2155 :   const overlayGroupKeys = computed(() =>
     215              :     allErrorGroups.value.map((group) => group.groupKey)
     216              :   )
     217              : 
     218         2155 :   const askAgentContext = computed(() => {
     219            2 :     const groups = allErrorGroups.value
     220            2 :     if (groups.length === 0) return undefined
     221            2 :     const context = {
     222              :       missingPackGroups: missingPackGroups.value,
     223              :       swapNodeGroups: swapNodeGroups.value,
     224              :       missingModelGroups: missingModelGroups.value,
     225              :       missingMediaGroups: missingMediaGroups.value
     226              :     }
     227            2 :     const base =
     228              :       groups.length === 1
     229              :         ? buildGroupErrorContext(groups[0], context)
     230              :         : buildAllErrorContext(groups, context, {
     231              :             label: t('agent.errorContext.allLabel')
     232              :           })
     233            2 :     return overlayTitle.value ? { ...base, label: overlayTitle.value } : base
     234              :   })
     235              : 
     236              :   const isVisible = computed(
     237              :     () =>
     238              :       isErrorOverlayOpen.value &&
     239              :       isIssuesTabEnabled() &&
     240              :       totalErrorCount.value > 0 &&
     241              :       overlayMessage.value.trim().length > 0
     242              :   )
     243              : 
     244         2155 :   return {
     245              :     hasError,
     246              :     hasMissingNodes,
     247              :     downloadableMissingModelGroups,
     248              :     isVisible,
     249              :     overlayMessage,
     250              :     overlayTitle,
     251              :     overlayGroupKeys,
     252              :     askAgentContext
     253              :   }
     254              : }
        

Generated by: LCOV version 2.0-1