LCOV - code coverage report
Current view: top level - src/renderer/extensions/firstRunTour/tour - firstRunTourDefinition.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 4.5 % 44 2
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : import type { RectTarget } from '@/platform/onboarding/coachmarkRegistry'
       2              : import type { Ref } from 'vue'
       3              : 
       4              : import {
       5              :   registerCoachmark,
       6              :   unregisterCoachmark
       7              : } from '@/platform/onboarding/coachmarkRegistry'
       8              : import { FIRST_RUN_COACH_IDS } from '@/platform/onboarding/onboardingTours'
       9              : import type {
      10              :   CoachId,
      11              :   CoachStep,
      12              :   TourResolution
      13              : } from '@/platform/onboarding/onboardingTours'
      14              : import { app } from '@/scripts/app'
      15              : 
      16              : import { resolveTourRoles } from '@/renderer/extensions/firstRunTour/roles/resolveTourRoles'
      17              : import type { ResolvedRoles } from '@/renderer/extensions/firstRunTour/roles/resolveTourRoles'
      18              : import { sequenceBuilder } from '@/renderer/extensions/firstRunTour/roles/tourSequence'
      19              : import type { TourStep } from '@/renderer/extensions/firstRunTour/roles/tourSequence'
      20              : import { frameNode } from './cameraFraming'
      21              : import { canvasNodeTarget } from './canvasCoachTarget'
      22              : 
      23              : /** How far the run has got, which is all the Run step's copy has to report. */
      24              : export type RunState = 'idle' | 'generating' | 'succeeded' | 'failed'
      25              : 
      26              : /**
      27              :  * What the workflow does. The Upload and Prompt steps mean something different
      28              :  * in each, so it selects their copy.
      29              :  */
      30              : type TourShape = 't2i' | 'i2v' | 'image-edit' | 'other'
      31              : 
      32         2355 : const COACH_ID: Record<TourStep['kind'], CoachId> = {
      33              :   upload: FIRST_RUN_COACH_IDS.source,
      34              :   prompt: FIRST_RUN_COACH_IDS.prompt,
      35              :   run: FIRST_RUN_COACH_IDS.runButton,
      36              :   result: FIRST_RUN_COACH_IDS.sink
      37              : }
      38              : 
      39              : /** Undoes the last registration; the tour holds one target set at a time. */
      40         2355 : let releaseRegistered = () => {}
      41              : 
      42              : /** Drops the canvas targets a finished tour registered. */
      43            0 : export function releaseFirstRunTargets() {
      44            0 :   releaseRegistered()
      45            0 :   releaseRegistered = () => {}
      46              : }
      47              : 
      48            0 : function registerCanvasTargets(sequence: TourStep[]) {
      49            0 :   const registered: [CoachId, RectTarget][] = []
      50            0 :   for (const step of sequence) {
      51            0 :     if (step.kind === 'run') continue
      52            0 :     const id = COACH_ID[step.kind]
      53            0 :     const target = canvasNodeTarget(step.nodeId)
      54            0 :     registerCoachmark(id, target)
      55            0 :     registered.push([id, target])
      56              :   }
      57            0 :   releaseRegistered = () => {
      58            0 :     for (const [id, target] of registered) {
      59            0 :       unregisterCoachmark(id, target)
      60            0 :       target.dispose?.()
      61              :     }
      62              :   }
      63              : }
      64              : 
      65            0 : function tourShape({
      66              :   source,
      67              :   promptHost,
      68              :   sink,
      69              :   mediaKind
      70              : }: ResolvedRoles): TourShape {
      71            0 :   if (!promptHost || !sink) return 'other'
      72            0 :   if (!source) return 't2i'
      73            0 :   return mediaKind === 'video' ? 'i2v' : 'image-edit'
      74              : }
      75              : 
      76              : interface StepContext {
      77              :   shape: TourShape
      78              :   runState: Readonly<Ref<RunState>>
      79              : }
      80              : 
      81              : /**
      82              :  * A step's variant is part of its name, so the engine resolves the copy from
      83              :  * `onboardingCoachmarks.firstRun.<name>` without knowing what a template is.
      84              :  */
      85            0 : function toCoachStep(
      86              :   step: TourStep,
      87              :   index: number,
      88              :   { shape, runState }: StepContext
      89              : ): CoachStep {
      90            0 :   const common = {
      91              :     kind: 'spotlight' as const,
      92              :     coachId: COACH_ID[step.kind],
      93              :     deferTarget: true,
      94              :     cursor: true,
      95              :     interactive: step.kind !== 'result'
      96              :   }
      97              : 
      98            0 :   if (step.kind === 'run')
      99            0 :     return { ...common, name: 'run', placement: 'bottom', selfAdvancing: true }
     100              : 
     101            0 :   const framed = {
     102              :     ...common,
     103              :     placement: 'auto' as const,
     104              :     onEnter: (signal: AbortSignal) =>
     105              :       frameNode(step.nodeId, signal, { glide: index > 0 })
     106              :   }
     107              : 
     108              :   // The run outlives the step that starts it, so Result is where it reports.
     109            0 :   if (step.kind === 'result')
     110            0 :     return {
     111              :       ...framed,
     112              :       get name() {
     113            0 :         if (runState.value === 'generating') return 'result.generating'
     114            0 :         if (runState.value === 'failed') return 'result.failed'
     115            0 :         return `result.${step.mediaKind}`
     116              :       }
     117              :     }
     118              : 
     119            0 :   return { ...framed, name: `${step.kind}.${shape}` }
     120              : }
     121              : 
     122              : /**
     123              :  * Builds the first-run tour for a template, or for whatever is on the canvas
     124              :  * when no template id came with it. A graph the roles cannot be read off
     125              :  * leaves nothing worth guiding anyone through — "click Run" alone is not a
     126              :  * tour — so it yields no steps and the engine reports that it did not start.
     127              :  */
     128            0 : export async function firstRunTourSteps(
     129              :   templateId: string | undefined,
     130              :   runState: Readonly<Ref<RunState>>
     131              : ): Promise<TourResolution> {
     132            0 :   releaseFirstRunTargets()
     133            0 :   const graph = app.rootGraphOrUndefined
     134            0 :   if (!graph) return { steps: [], reason: 'no_roles' }
     135            0 :   const roles = resolveTourRoles(graph, templateId)
     136            0 :   if (!roles) return { steps: [], reason: 'no_roles' }
     137              : 
     138            0 :   const sequence = sequenceBuilder(roles)
     139            0 :   if (sequence.every((step) => step.kind === 'run'))
     140            0 :     return { steps: [], reason: 'run_only' }
     141              : 
     142            0 :   registerCanvasTargets(sequence)
     143            0 :   const context: StepContext = { shape: tourShape(roles), runState }
     144            0 :   return {
     145              :     steps: sequence.map((step, index) => toCoachStep(step, index, context))
     146              :   }
     147              : }
        

Generated by: LCOV version 2.0-1