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

            Line data    Source code
       1              : import type { WorkspaceDeployment } from '@/platform/workspace/api/workspaceApi'
       2              : import type { DeploymentCompatibilityMark } from '@/platform/workspace/composables/useDeploymentCompatibility'
       3              : 
       4              : /** The compatibility check's mark for a deployment, or for Comfy Cloud given null; null before an answer. */
       5              : export type MarkFor = (
       6              :   deploymentId: string | null
       7              : ) => DeploymentCompatibilityMark | null
       8              : 
       9              : /** The open workflow's node types, and the ones the editor found missing, as the check names them. */
      10              : export interface CheckedWorkflow {
      11              :   nodeTypes: readonly string[]
      12              :   missingNodeTypes: readonly string[]
      13              : }
      14              : 
      15              : /** A deployment with the compatibility check's mark for the open workflow; null when the answer leaves it out. */
      16              : export interface DeploymentChoice {
      17              :   deployment: WorkspaceDeployment
      18              :   mark: DeploymentCompatibilityMark | null
      19              : }
      20              : 
      21              : type WorkflowDeploymentOffer =
      22              :   | { kind: 'switch'; choices: DeploymentChoice[] }
      23              :   | { kind: 'noneRunIt' }
      24              :   | { kind: 'unchecked' }
      25              : 
      26            0 : function nodesCloudLacks(markFor: MarkFor): readonly string[] | null {
      27            0 :   const cloud = markFor(null)
      28            0 :   if (cloud === null || cloud.kind === 'unknown') return null
      29            0 :   return cloud.kind === 'missing' ? cloud.nodeTypes : []
      30              : }
      31              : 
      32              : /** Whether the check's answer is about this workflow: every node it finds Comfy Cloud lacking is one the workflow runs, and it finds Cloud lacking every missing node the workflow runs. */
      33            0 : export function answersForWorkflow(
      34              :   markFor: MarkFor,
      35              :   workflow: CheckedWorkflow
      36              : ): boolean {
      37            0 :   const cloudLacks = nodesCloudLacks(markFor)
      38            0 :   if (cloudLacks === null) return false
      39            0 :   const runsNode = (nodeType: string) => workflow.nodeTypes.includes(nodeType)
      40            0 :   return (
      41              :     cloudLacks.every(runsNode) &&
      42              :     workflow.missingNodeTypes
      43              :       .filter(runsNode)
      44              :       .every((nodeType) => cloudLacks.includes(nodeType))
      45              :   )
      46              : }
      47              : 
      48            0 : function runs(choice: DeploymentChoice): boolean {
      49            0 :   return choice.mark?.kind === 'runs'
      50              : }
      51              : 
      52              : /** Whether Switch may pick this deployment: it runs the workflow and is ready. */
      53            0 : export function canSwitchTo(choice: DeploymentChoice): boolean {
      54            0 :   return runs(choice) && choice.deployment.status === 'ready'
      55              : }
      56              : 
      57              : /** What the dialog for a workflow Comfy Cloud lacks nodes for offers, from the compatibility check's answer; a switch lists the deployments it can pick first. */
      58            0 : export function workflowDeploymentOffer(
      59              :   deployments: readonly WorkspaceDeployment[],
      60              :   markFor: MarkFor,
      61              :   workflow: CheckedWorkflow
      62              : ): WorkflowDeploymentOffer {
      63            0 :   if (
      64              :     !answersForWorkflow(markFor, workflow) ||
      65              :     markFor(null)?.kind !== 'missing'
      66              :   ) {
      67            0 :     return { kind: 'unchecked' }
      68              :   }
      69            0 :   const choices = deployments.map((deployment) => ({
      70              :     deployment,
      71              :     mark: markFor(deployment.deployment_id)
      72              :   }))
      73            0 :   if (choices.some(canSwitchTo)) {
      74            0 :     return {
      75              :       kind: 'switch',
      76              :       choices: [
      77              :         ...choices.filter(canSwitchTo),
      78              :         ...choices.filter((choice) => runs(choice) && !canSwitchTo(choice)),
      79              :         ...choices.filter((choice) => !runs(choice))
      80              :       ]
      81              :     }
      82              :   }
      83            0 :   if (choices.some(runs)) return { kind: 'unchecked' }
      84              :   const eachLacksNodes =
      85              :     choices.length > 0 && choices.every(({ mark }) => mark?.kind === 'missing')
      86            0 :   return eachLacksNodes ? { kind: 'noneRunIt' } : { kind: 'unchecked' }
      87              : }
        

Generated by: LCOV version 2.0-1