diff --git a/src/workbench/extensions/agent/AgentPanelRoot.test.ts b/src/workbench/extensions/agent/AgentPanelRoot.test.ts index f9d7e10f73c..18f0dee6d24 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.test.ts +++ b/src/workbench/extensions/agent/AgentPanelRoot.test.ts @@ -8923,6 +8923,26 @@ describe('AgentPanelRoot workflow binding', () => { expect(screen.queryByTestId('agent-coach-hold-notice')).toBeNull() }) + it('sends once when another tab finishes the tour during the hold', async () => { + const key = 'Comfy.AgentPanel.onboarded.account-a.workspace-hold' + makeTab('wf-42') + const bodies = mockMessagesEndpoint('wf-42') + renderWithSelectedTarget() + await sendHeldByCoach('build me a workflow') + expect(bodies).toHaveLength(0) + + localStorage.setItem(key, 'true') + window.dispatchEvent( + new StorageEvent('storage', { + key, + newValue: 'true', + storageArea: localStorage + }) + ) + + await waitFor(() => expect(bodies).toHaveLength(1)) + }) + it('sends once when a coach step never finds its target', async () => { vi.useFakeTimers({ shouldAdvanceTime: true }) const user = userEvent.setup({ advanceTimers: vi.advanceTimersByTime }) diff --git a/src/workbench/extensions/agent/components/agent/OnboardingCoach.test.ts b/src/workbench/extensions/agent/components/agent/OnboardingCoach.test.ts index 291ae617d01..78b3dce4513 100644 --- a/src/workbench/extensions/agent/components/agent/OnboardingCoach.test.ts +++ b/src/workbench/extensions/agent/components/agent/OnboardingCoach.test.ts @@ -449,6 +449,90 @@ describe('OnboardingCoach', () => { expect(useOnboardingOverlayStore().active).toBe(true) }) + function mountWithFinished( + storageKey: string, + onFinished: () => void, + steps = STEPS + ) { + return render( + { + components: { OnboardingCoach }, + setup: () => ({ steps, storageKey, onFinished }), + template: + '
' + }, + { global: { plugins: [i18n] } } + ) + } + + it('reports the tour finished when another tab completes it', async () => { + const onFinished = vi.fn() + mountWithFinished('coach-elsewhere', onFinished) + await screen.findByRole('dialog', { name: 'Meet the agent' }) + + localStorage.setItem('coach-elsewhere', 'true') + window.dispatchEvent( + new StorageEvent('storage', { + key: 'coach-elsewhere', + newValue: 'true', + storageArea: localStorage + }) + ) + + await waitFor(() => expect(onFinished).toHaveBeenCalled()) + await nextTick() + + expect(onFinished).toHaveBeenCalledOnce() + }) + + it('reports finished once when the user skips', async () => { + const onFinished = vi.fn() + mountWithFinished('coach-skip-once', onFinished) + await userEvent.click(await screen.findByRole('button', { name: 'Skip' })) + await nextTick() + await nextTick() + + expect(onFinished).toHaveBeenCalledOnce() + }) + + it('reports finished once when the user clicks Done', async () => { + const onFinished = vi.fn() + mountWithFinished('coach-done-once', onFinished, [STEPS[0]]) + await userEvent.click(await screen.findByRole('button', { name: 'Done' })) + await nextTick() + await nextTick() + + expect(onFinished).toHaveBeenCalledOnce() + }) + + it('reports a later completion in another tab after a replay', async () => { + const onFinished = vi.fn() + const coach = ref<{ restart: () => void } | null>(null) + render( + { + components: { OnboardingCoach }, + setup: () => ({ steps: STEPS, coach, onFinished }), + template: + '
' + }, + { global: { plugins: [i18n] } } + ) + await userEvent.click(await screen.findByRole('button', { name: 'Skip' })) + coach.value?.restart() + await screen.findByRole('dialog', { name: 'Meet the agent' }) + + localStorage.setItem('coach-replay-elsewhere', 'true') + window.dispatchEvent( + new StorageEvent('storage', { + key: 'coach-replay-elsewhere', + newValue: 'true', + storageArea: localStorage + }) + ) + + await waitFor(() => expect(onFinished).toHaveBeenCalledTimes(2)) + }) + describe('reporting a step whose target never mounts', () => { const renderMissing = (target: string) => render(OnboardingCoach, { diff --git a/src/workbench/extensions/agent/components/agent/OnboardingCoach.vue b/src/workbench/extensions/agent/components/agent/OnboardingCoach.vue index eaa69c30b77..0644946be8a 100644 --- a/src/workbench/extensions/agent/components/agent/OnboardingCoach.vue +++ b/src/workbench/extensions/agent/components/agent/OnboardingCoach.vue @@ -107,19 +107,29 @@ function reportStep(action: AgentOnboardingAction): void { useTelemetry()?.trackAgentOnboardingStep({ step: index.value + 1, action }) } +let finishedHere = false + function onNext(): void { const finished = isLast.value reportStep(isLast.value ? 'finish' : 'next') + if (finished) finishedHere = true next() if (finished) emit('finished') } function onSkip(): void { reportStep('skip') + finishedHere = true finish() emit('finished') } +const completed = computed(() => !active.value && !!step.value) +watch(completed, (isCompleted) => { + if (isCompleted && !finishedHere) emit('finished') + finishedHere = false +}) + const targetObserver = new MutationObserver(resolveTargets) targetObserver.observe(document.body, { childList: true,