LCOV - code coverage report
Current view: top level - src/platform/customNodes/manager/utils - conflictUtils.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 74.2 % 31 23
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : import { groupBy, uniqBy } from 'es-toolkit/compat'
       2              : 
       3              : import { normalizePackId } from '@/platform/customNodes/manager/utils/packUtils'
       4              : import type {
       5              :   RegistryAccelerator,
       6              :   RegistryOS
       7              : } from '@/platform/customNodes/manager/types/compatibility.types'
       8              : import type {
       9              :   ConflictDetail,
      10              :   ConflictDetectionResult,
      11              :   SystemEnvironment
      12              : } from '@/platform/customNodes/manager/types/conflictDetectionTypes'
      13              : import {
      14              :   checkAcceleratorCompatibility,
      15              :   checkOSCompatibility
      16              : } from '@/platform/customNodes/manager/utils/systemCompatibility'
      17              : import { checkVersionCompatibility } from '@/platform/customNodes/manager/utils/versionUtil'
      18              : 
      19              : /**
      20              :  * Checks for banned package status conflicts.
      21              :  */
      22          223 : export function createBannedConflict(
      23              :   isBanned?: boolean
      24              : ): ConflictDetail | null {
      25          223 :   if (isBanned === true) {
      26            0 :     return {
      27              :       type: 'banned',
      28              :       current_value: 'installed',
      29              :       required_value: 'not_banned'
      30              :     }
      31              :   }
      32          223 :   return null
      33              : }
      34              : 
      35              : /**
      36              :  * Checks for pending package status conflicts.
      37              :  */
      38          223 : export function createPendingConflict(
      39              :   isPending?: boolean
      40              : ): ConflictDetail | null {
      41          223 :   if (isPending === true) {
      42            0 :     return {
      43              :       type: 'pending',
      44              :       current_value: 'installed',
      45              :       required_value: 'not_pending'
      46              :     }
      47              :   }
      48          223 :   return null
      49              : }
      50              : 
      51              : /**
      52              :  * Single source of truth for mapping a Node/NodeVersion status string to
      53              :  * banned/pending booleans. NodeStatusBanned is a Node-only value; NodeVersion
      54              :  * has no pending-equivalent Node status, so isPending only checks the
      55              :  * NodeVersion enum.
      56              :  */
      57          193 : export function deriveStatusFlags(status?: string): {
      58              :   isBanned: boolean
      59              :   isPending: boolean
      60              : } {
      61          193 :   return {
      62              :     isBanned:
      63              :       status === 'NodeStatusBanned' || status === 'NodeVersionStatusBanned',
      64              :     isPending: status === 'NodeVersionStatusPending'
      65              :   }
      66              : }
      67              : 
      68              : /**
      69              :  * Normalized compatibility inputs for a single package, produced by each call
      70              :  * site from its own source shape. Banned/pending are pre-derived booleans
      71              :  * (see {@link deriveStatusFlags}) since the two callers read status from
      72              :  * different source shapes (Node vs NodeVersion).
      73              :  */
      74              : export interface CompatibilityInput {
      75              :   supported_os?: RegistryOS[]
      76              :   supported_accelerators?: RegistryAccelerator[]
      77              :   supported_comfyui_version?: string
      78              :   supported_comfyui_frontend_version?: string
      79              :   isBanned: boolean
      80              :   isPending: boolean
      81              : }
      82              : 
      83              : /**
      84              :  * Runs the six compatibility leaf checks and collects the conflicts that fire.
      85              :  *
      86              :  * Canonical order = comfyui_version → frontend_version → OS → accelerator →
      87              :  * banned → pending; every consumer filters conflicts by `.type`, so the order
      88              :  * is cosmetic only.
      89              :  */
      90          223 : export function evaluateCompatibility(
      91              :   input: CompatibilityInput,
      92              :   env: SystemEnvironment
      93              : ): ConflictDetail[] {
      94          223 :   const conflicts: ConflictDetail[] = []
      95              : 
      96          223 :   const versionConflict = checkVersionCompatibility(
      97              :     'comfyui_version',
      98              :     env.comfyui_version,
      99              :     input.supported_comfyui_version
     100              :   )
     101          223 :   if (versionConflict) conflicts.push(versionConflict)
     102              : 
     103          223 :   const frontendConflict = checkVersionCompatibility(
     104              :     'frontend_version',
     105              :     env.frontend_version,
     106              :     input.supported_comfyui_frontend_version
     107              :   )
     108          223 :   if (frontendConflict) conflicts.push(frontendConflict)
     109              : 
     110          223 :   const osConflict = checkOSCompatibility(input.supported_os, env.os)
     111          223 :   if (osConflict) conflicts.push(osConflict)
     112              : 
     113          223 :   const acceleratorConflict = checkAcceleratorCompatibility(
     114              :     input.supported_accelerators,
     115              :     env.accelerator
     116              :   )
     117          223 :   if (acceleratorConflict) conflicts.push(acceleratorConflict)
     118              : 
     119          223 :   const bannedConflict = createBannedConflict(input.isBanned)
     120          223 :   if (bannedConflict) conflicts.push(bannedConflict)
     121              : 
     122          223 :   const pendingConflict = createPendingConflict(input.isPending)
     123          223 :   if (pendingConflict) conflicts.push(pendingConflict)
     124              : 
     125          223 :   return conflicts
     126              : }
     127              : 
     128              : /**
     129              :  * Groups and deduplicates conflicts by normalized package name.
     130              :  * Consolidates multiple conflict sources (registry checks, import failures, disabled packages with version suffix)
     131              :  * into a single UI entry per package.
     132              :  *
     133              :  * Example:
     134              :  * - Input: [{name: "pack@1_0_3", conflicts: [...]}, {name: "pack", conflicts: [...]}]
     135              :  * - Output: [{name: "pack", conflicts: [...combined unique conflicts...]}]
     136              :  *
     137              :  * @param conflicts Array of conflict detection results (may have duplicate packages with version suffixes)
     138              :  * @returns Array of deduplicated conflict results grouped by normalized package name
     139              :  */
     140            0 : export function consolidateConflictsByPackage(
     141              :   conflicts: ConflictDetectionResult[]
     142              : ): ConflictDetectionResult[] {
     143              :   // Group conflicts by normalized package name using es-toolkit
     144            0 :   const grouped = groupBy(conflicts, (conflict) =>
     145              :     normalizePackId(conflict.package_name)
     146              :   )
     147              : 
     148              :   // Merge conflicts for each group
     149            0 :   return Object.entries(grouped).map(([packageName, packageConflicts]) => {
     150              :     // Flatten all conflicts from the group
     151            0 :     const allConflicts = packageConflicts.flatMap((pc) => pc.conflicts)
     152              : 
     153              :     // Remove duplicate conflicts using uniqBy
     154            0 :     const uniqueConflicts = uniqBy(
     155              :       allConflicts,
     156              :       (conflict) =>
     157              :         `${conflict.type}|${conflict.current_value}|${conflict.required_value}`
     158              :     )
     159              : 
     160              :     // Use the first item as base and update with merged data
     161              :     const baseItem = packageConflicts[0]
     162            0 :     return {
     163              :       ...baseItem,
     164              :       package_name: packageName, // Use normalized name
     165              :       conflicts: uniqueConflicts,
     166              :       has_conflict: uniqueConflicts.length > 0,
     167              :       is_compatible: uniqueConflicts.length === 0
     168              :     }
     169              :   })
     170              : }
        

Generated by: LCOV version 2.0-1