Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions browser_tests/tests/agent/agentConsent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -528,20 +528,24 @@ test.describe(
{ tag: ['@cloud', '@ui'] },
() => {
test.use({
agentAutoShownReadProbe: true,
agentConsentAccepted: false,
initialSettings: { 'Comfy.TutorialCompleted': false },
initialFeatureFlags: {
onboarding_tour_enabled: true,
subscription_required: true
}
})
test.describe.configure({ timeout: 90_000 })

test('stays silent for the session once Getting Started took the screen', async ({
test('defers the offer until Getting Started releases the screen', async ({
comfyPage,
agentPanel,
agentConsentReads
agentConsentWrites
}) => {
const page = comfyPage.page
const autoShownKey =
'Comfy.AgentConsent.AutoShown.test-user-e2e.ws-personal'
const gettingStarted = page.getByRole('dialog', {
name: enMessages.gettingStarted.title
})
Expand All @@ -553,24 +557,28 @@ test.describe(
await expect(gettingStarted).toBeVisible()
})

await test.step('The automatic offer runs and stays silent', async () => {
await test.step('The automatic offer waits without spending its one-time attempt', async () => {
await expect
.poll(() => agentConsentReads.length, {
.poll(() => page.evaluate(() => window.__autoShownReads ?? 0), {
message:
'the automatic offer runs once the consent read and the boot decision are both in; the fixture already waited past the decision (the loading overlay clears after it), so the read is the last input and the silence below is a decision, not a race',
'the held-offer decision reads the unspent one-shot marker',
timeout: 15_000
})
.toBeGreaterThan(0)
await expect(consent).toHaveCount(0)
await expect(agentPanel.root).toHaveCount(0)
expect(
await page.evaluate(() =>
localStorage.getItem(
'Comfy.AgentConsent.AutoShown.test-user-e2e.ws-personal'
)
)
await page.evaluate((key) => localStorage.getItem(key), autoShownKey)
).toBeNull()
})

await test.step('Taking the blank canvas presents the deferred offer', async () => {
await page.getByTestId('getting-started-blank').click()
await expect(gettingStarted).toHaveCount(0)
await expect(consent).toBeVisible()
await expect(agentPanel.root).toHaveCount(0)
expect(agentConsentWrites).toHaveLength(0)
})
})
}
)
26 changes: 24 additions & 2 deletions browser_tests/tests/agent/agentPanelMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ async function mockAgentBoot(
agentConsentReads,
agentConsentSave,
agentConsentWrites,
agentAutoShownReadProbe,
agentFlagEnabled,
agentPanelInitiallyOpen,
agentOnboardingCompleted,
Expand All @@ -174,7 +175,23 @@ async function mockAgentBoot(
let consentAccepted = agentConsentAccepted

await page.addInitScript(
({ initiallyOpen, onboardingCompleted, debugEnabled }) => {
({
initiallyOpen,
onboardingCompleted,
debugEnabled,
autoShownReadProbe
}) => {
if (autoShownReadProbe) {
const autoShownKey =
'Comfy.AgentConsent.AutoShown.test-user-e2e.ws-personal'
const originalGetItem = Storage.prototype.getItem
window.__autoShownReads = 0
Storage.prototype.getItem = function (candidate: string) {
if (candidate === autoShownKey)
window.__autoShownReads = (window.__autoShownReads ?? 0) + 1
return originalGetItem.call(this, candidate)
}
}
if (localStorage.getItem('Comfy.AgentPanel.open') === null) {
localStorage.setItem('Comfy.AgentPanel.open', String(initiallyOpen))
}
Expand All @@ -192,7 +209,8 @@ async function mockAgentBoot(
{
initiallyOpen: agentPanelInitiallyOpen,
onboardingCompleted: agentOnboardingCompleted,
debugEnabled: crdtDebugEnabled
debugEnabled: crdtDebugEnabled,
autoShownReadProbe: agentAutoShownReadProbe
}
)

Expand Down Expand Up @@ -388,6 +406,7 @@ async function mockAgentBoot(
}

type AgentFixtures = {
agentAutoShownReadProbe: boolean
agentConsentAccepted: boolean
agentConsentReads: boolean[]
agentConsentSave: { status: number; pending?: Promise<void> }
Expand All @@ -404,6 +423,7 @@ type AgentFixtures = {
}

export const agentTest = comfyPageFixture.extend<AgentFixtures>({
agentAutoShownReadProbe: [false, { option: true }],
agentConsentAccepted: [true, { option: true }],
agentConsentReads: async ({ agentFlagEnabled: _agentFlagEnabled }, use) => {
await use([])
Expand All @@ -425,6 +445,7 @@ export const agentTest = comfyPageFixture.extend<AgentFixtures>({
objectInfo: [undefined, { option: true }],
page: async (
{
agentAutoShownReadProbe,
agentConsentAccepted,
agentConsentReads,
agentConsentSave,
Expand All @@ -444,6 +465,7 @@ export const agentTest = comfyPageFixture.extend<AgentFixtures>({
testInfo
) => {
await mockAgentBoot(page, {
agentAutoShownReadProbe,
agentConsentAccepted,
agentConsentReads,
agentConsentSave,
Expand Down
1 change: 1 addition & 0 deletions browser_tests/types/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ declare global {
__commandExecutionCounts?: Record<string, number>

// Feature flags test globals
__autoShownReads?: number
__capturedMessages?: CapturedMessages
__appReadiness?: AppReadiness

Expand Down
67 changes: 63 additions & 4 deletions src/extensions/core/agentPanel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,41 @@ let consentStore: ReturnType<typeof useAgentConsentStore>
let workspaceStore: ReturnType<typeof useTeamWorkspaceStore>

const currentUser = ref<{ id: string } | null>({ id: 'account-a' })
const firstRunTookScreen = ref(false)
const isAuthInitialized = ref(true)
type FirstRunScreenState = 'released' | 'visible' | 'handoff'
const firstRunScreenState = ref<FirstRunScreenState>('released')
const gettingStartedVisible = computed(
() => firstRunScreenState.value === 'visible'
)
const firstRunHoldsScreen = computed(
() => firstRunScreenState.value !== 'released'
)
const firstRunTookScreen = computed({
get: () => firstRunHoldsScreen.value,
set: (value: boolean) => {
firstRunScreenState.value = value ? 'visible' : 'released'
}
})
const activeTour = ref<EntryPath | null>(null)
let startupDecision: Promise<boolean> = Promise.resolve(true)

function showFirstRunScreen(): void {
firstRunScreenState.value = 'visible'
}

function releaseFirstRunScreen(): void {
firstRunScreenState.value = 'released'
}

function beginFirstRunScreenHandoff(): void {
firstRunScreenState.value = 'handoff'
}

vi.mock(import('@/composables/auth/useCurrentUser'), () => ({
useCurrentUser: () =>
fromPartial<ReturnType<typeof useCurrentUser>>({
resolvedUserInfo: currentUser,
isAuthInitialized: computed(() => true),
isAuthInitialized,
isLoggedIn: computed(() => currentUser.value !== null)
})
}))
Expand Down Expand Up @@ -84,7 +110,8 @@ vi.mock(
() => ({
useFirstRunEntry: () =>
fromPartial<ReturnType<typeof useFirstRunEntry>>({
firstRunTookScreen,
gettingStartedVisible,
firstRunHoldsScreen,
whenStartupDecided: () => startupDecision
})
})
Expand Down Expand Up @@ -183,7 +210,7 @@ describe('AgentPanel extension flag gate', () => {
agentStore.isOpen = true
agentFlagEnabled.value = false
agentFlagEnabled.value = false
firstRunTookScreen.value = false
releaseFirstRunScreen()
activeTour.value = null
startupDecision = Promise.resolve(true)
vi.spyOn(useOnboardingTourStore(), 'activeTour', 'get').mockImplementation(
Expand Down Expand Up @@ -345,6 +372,38 @@ describe('AgentPanel extension flag gate', () => {
}
)

it('offers in the same session once the Getting Started screen closes', async () => {
agentFlagEnabled.value = true
showFirstRunScreen()
Object.assign(consentStore, { accepted: false, isChecking: false })

await loadEntryAndSetup()
await flush()
expect(useAgentConsent().withConsent).not.toHaveBeenCalled()

releaseFirstRunScreen()
await vi.waitFor(() =>
expect(useAgentConsent().withConsent).toHaveBeenCalledOnce()
)
})

it('keeps waiting across the Getting Started to tour handoff', async () => {
agentFlagEnabled.value = true
showFirstRunScreen()
Object.assign(consentStore, { accepted: false, isChecking: false })

await loadEntryAndSetup()
await flush()
beginFirstRunScreenHandoff()
await flush()
expect(useAgentConsent().withConsent).not.toHaveBeenCalled()

activeTour.value = 'firstRun'
releaseFirstRunScreen()
await flush()
expect(useAgentConsent().withConsent).not.toHaveBeenCalled()
})

it('offers when neither Getting Started took the screen nor a tour is active', async () => {
agentFlagEnabled.value = true
Object.assign(consentStore, { accepted: false, isChecking: false })
Expand Down
22 changes: 18 additions & 4 deletions src/extensions/core/agentPanel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { whenever } from '@vueuse/core'
import { storeToRefs } from 'pinia'
import { watch } from 'vue'
import { computed, ref, watch } from 'vue'

import { useCurrentUser } from '@/composables/auth/useCurrentUser'
import { useFeatureFlags } from '@/composables/useFeatureFlags'
Expand Down Expand Up @@ -172,7 +173,7 @@ export function registerAgentPanelExtension(): void {
const { resolvedUserInfo, isAuthInitialized, isLoggedIn } =
useCurrentUser()
const { withConsent } = useAgentConsent()
const { firstRunTookScreen, whenStartupDecided } = useFirstRunEntry()
const { firstRunHoldsScreen, whenStartupDecided } = useFirstRunEntry()
const onboardingTourStore = useOnboardingTourStore()
registerWorkflowTabActivityTracker(enabled)

Expand All @@ -185,13 +186,15 @@ export function registerAgentPanelExtension(): void {
)

const screenHolder = (): AgentConsentNotOfferedReason | null =>
firstRunTookScreen.value
firstRunHoldsScreen.value
? 'first_run_screen'
: onboardingTourStore.activeTour !== null
? 'tour_active'
: null
const screenIsClear = computed(() => screenHolder() === null)

const reportedWithheld = new Set<string>()
const offerHeld = ref(false)
const withholdOffer = (
reason: AgentConsentNotOfferedReason,
userId = resolvedUserInfo.value?.id,
Expand Down Expand Up @@ -222,6 +225,7 @@ export function registerAgentPanelExtension(): void {
const held = screenHolder()
if (held) {
withholdOffer(held)
offerHeld.value = true
return
}

Expand All @@ -247,7 +251,10 @@ export function registerAgentPanelExtension(): void {
},
canShow: () => {
const heldAtMount = screenHolder()
if (heldAtMount) withholdOffer(heldAtMount, userId, workspaceId)
if (heldAtMount) {
withholdOffer(heldAtMount, userId, workspaceId)
offerHeld.value = true
}
return heldAtMount === null
}
}
Expand Down Expand Up @@ -290,6 +297,13 @@ export function registerAgentPanelExtension(): void {
loadConsentIfEligible,
{ immediate: true }
)
whenever(
() => offerHeld.value && screenIsClear.value,
() => {
offerHeld.value = false
loadConsentIfEligible()
}
)
watch(
() => onboardingTourStore.activeTour,
(tour) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@ import { CURATED_TEMPLATE_IDS, FALLBACK_TEMPLATE_IDS } from './tutorialCards'

const mocks = vi.hoisted(() => ({
dismiss: vi.fn(),
beginTour: vi.fn(),
dismissIntoTour: vi.fn(),
loadTemplate:
vi.fn<ReturnType<typeof useTemplateWorkflows>['loadWorkflowTemplate']>(),

loadingTemplateId: { value: null as string | null }
}))

vi.mock<unknown>(import('./firstRunEntry'), () => ({
useFirstRunEntry: () => ({ dismissGettingStarted: mocks.dismiss })
}))

vi.mock<unknown>(import('../tour/useFirstRunTourController'), () => ({
useFirstRunTourController: () => ({ beginTour: mocks.beginTour })
useFirstRunEntry: () => ({
dismissGettingStarted: mocks.dismiss,
dismissIntoFirstRunTour: mocks.dismissIntoTour
})
}))

vi.mock<unknown>(
Expand Down Expand Up @@ -95,7 +94,7 @@ describe('GettingStartedScreen', () => {
vi.mocked(
useWorkflowTemplatesStore().loadWorkflowTemplates
).mockResolvedValue(undefined)
mocks.beginTour.mockResolvedValue(true)
mocks.dismissIntoTour.mockResolvedValue(undefined)
mocks.loadingTemplateId.value = null
})

Expand All @@ -116,8 +115,8 @@ describe('GettingStartedScreen', () => {
'default'
)
)
expect(mocks.beginTour).toHaveBeenCalledWith(CURATED_TEMPLATE_IDS[0])
expect(mocks.dismiss).toHaveBeenCalled()
expect(mocks.dismissIntoTour).toHaveBeenCalledWith(CURATED_TEMPLATE_IDS[0])
expect(mocks.dismiss).not.toHaveBeenCalled()
})

it('ignores a second pick while one is still loading', async () => {
Expand All @@ -134,21 +133,8 @@ describe('GettingStartedScreen', () => {
).not.toHaveBeenCalled()
})

it('leaves the user on the loaded graph when the template has no tour', async () => {
mocks.beginTour.mockResolvedValue(false)
await renderScreen()

await pickFirstTemplate()

await waitFor(() => expect(mocks.beginTour).toHaveBeenCalled())
expect(
mocks.dismiss,
'the graph is loaded and usable, so the takeover must not strand the user on it'
).toHaveBeenCalled()
})

it('keeps the click handler from rejecting when the tour cannot start', async () => {
mocks.beginTour.mockRejectedValue(new Error('tour unavailable'))
mocks.dismissIntoTour.mockRejectedValue(new Error('tour unavailable'))
const rejections: unknown[] = []
const onRejection = (reason: unknown) => rejections.push(reason)
process.on('unhandledRejection', onRejection)
Expand All @@ -157,7 +143,7 @@ describe('GettingStartedScreen', () => {

await pickFirstTemplate()

await waitFor(() => expect(mocks.beginTour).toHaveBeenCalled())
await waitFor(() => expect(mocks.dismissIntoTour).toHaveBeenCalled())
await new Promise((resolve) => setImmediate(resolve))
process.off('unhandledRejection', onRejection)

Expand Down
Loading
Loading