LCOV - code coverage report
Current view: top level - src/platform/telemetry/utils - getExecutionContext.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 0.0 % 35 0
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : import { TOOLKIT_NODES } from '@/constants/essentialsNodes'
       2              : import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
       3              : import { useWorkflowTemplatesStore } from '@/platform/workflow/templates/repositories/workflowTemplatesStore'
       4              : import { useApp } from '@/scripts/appInstance'
       5              : import { useNodeDefStore } from '@/stores/nodeDefStore'
       6              : import { NodeSourceType } from '@/types/nodeSource'
       7              : import { reduceAllNodes } from '@/utils/graphTraversalUtil'
       8              : 
       9              : import type { ExecutionContext } from '@comfyorg/telemetry/types'
      10              : 
      11              : type NodeMetrics = {
      12              :   custom_node_count: number
      13              :   api_node_count: number
      14              :   toolkit_node_count: number
      15              :   subgraph_count: number
      16              :   total_node_count: number
      17              :   has_api_nodes: boolean
      18              :   api_node_names: string[]
      19              :   has_toolkit_nodes: boolean
      20              :   toolkit_node_names: string[]
      21              : }
      22              : 
      23            0 : export function getExecutionContext(): ExecutionContext {
      24            0 :   const workflowStore = useWorkflowStore()
      25            0 :   const templatesStore = useWorkflowTemplatesStore()
      26            0 :   const nodeDefStore = useNodeDefStore()
      27            0 :   const activeWorkflow = workflowStore.activeWorkflow
      28              : 
      29            0 :   const nodeCounts = reduceAllNodes<NodeMetrics>(
      30              :     useApp().rootGraph,
      31              :     (metrics, node) => {
      32            0 :       const nodeDef = nodeDefStore.fromLGraphNode(node)
      33            0 :       const isCustomNode =
      34              :         nodeDef?.nodeSource.type === NodeSourceType.CustomNodes
      35            0 :       const isApiNode = nodeDef?.api_node
      36            0 :       const isSubgraph =
      37              :         typeof node.isSubgraphNode === 'function' && node.isSubgraphNode()
      38              : 
      39            0 :       if (isApiNode) {
      40            0 :         metrics.has_api_nodes = true
      41            0 :         const canonicalName = nodeDef.name
      42            0 :         if (canonicalName && !metrics.api_node_names.includes(canonicalName)) {
      43            0 :           metrics.api_node_names.push(canonicalName)
      44              :         }
      45              :       }
      46              : 
      47            0 :       const isToolkitNode = TOOLKIT_NODES.has(node.type)
      48            0 :       if (isToolkitNode) {
      49            0 :         metrics.has_toolkit_nodes = true
      50            0 :         const trackingName = nodeDef?.name ?? node.type
      51            0 :         if (!metrics.toolkit_node_names.includes(trackingName)) {
      52            0 :           metrics.toolkit_node_names.push(trackingName)
      53              :         }
      54              :       }
      55              : 
      56            0 :       metrics.custom_node_count += isCustomNode ? 1 : 0
      57            0 :       metrics.api_node_count += isApiNode ? 1 : 0
      58            0 :       metrics.toolkit_node_count += isToolkitNode ? 1 : 0
      59            0 :       metrics.subgraph_count += isSubgraph ? 1 : 0
      60            0 :       metrics.total_node_count += 1
      61              : 
      62            0 :       return metrics
      63              :     },
      64              :     {
      65              :       custom_node_count: 0,
      66              :       api_node_count: 0,
      67              :       toolkit_node_count: 0,
      68              :       subgraph_count: 0,
      69              :       total_node_count: 0,
      70              :       has_api_nodes: false,
      71              :       api_node_names: [],
      72              :       has_toolkit_nodes: false,
      73              :       toolkit_node_names: []
      74              :     }
      75              :   )
      76              : 
      77            0 :   if (activeWorkflow?.filename) {
      78              :     // Use fullFilename minus .json to reconstruct the template name, which
      79              :     // preserves compound suffixes like ".app" (e.g. "foo.app.json" → "foo.app").
      80              :     // Using just `filename` strips ".app.json" entirely (e.g. "foo"), which
      81              :     // won't match knownTemplateNames entries like "foo.app".
      82            0 :     const templateName = activeWorkflow.fullFilename.replace(/\.json$/i, '')
      83              :     const isTemplate = templatesStore.knownTemplateNames.has(templateName)
      84              : 
      85            0 :     if (isTemplate) {
      86            0 :       const template = templatesStore.getTemplateByName(templateName)
      87              : 
      88            0 :       const englishMetadata = templatesStore.getEnglishMetadata(templateName)
      89              : 
      90            0 :       return {
      91              :         is_template: true,
      92              :         workflow_name: templateName,
      93              :         template_source: template?.sourceModule,
      94              :         template_category: englishMetadata?.category ?? template?.category,
      95              :         template_tags: englishMetadata?.tags ?? template?.tags,
      96              :         template_models: englishMetadata?.models ?? template?.models,
      97              :         template_use_case: englishMetadata?.useCase ?? template?.useCase,
      98              :         template_license: englishMetadata?.license ?? template?.license,
      99              :         ...nodeCounts
     100              :       }
     101              :     }
     102              : 
     103            0 :     return {
     104              :       is_template: false,
     105              :       workflow_name: activeWorkflow.filename,
     106              :       ...nodeCounts
     107              :     }
     108              :   }
     109              : 
     110            0 :   return {
     111              :     is_template: false,
     112              :     workflow_name: undefined,
     113              :     ...nodeCounts
     114              :   }
     115              : }
        

Generated by: LCOV version 2.0-1