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
121 changes: 114 additions & 7 deletions browser_tests/tests/agent/agentConsent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,10 @@ test.describe('Manual agent consent gate', { tag: ['@cloud', '@ui'] }, () => {
})

test.describe('Automatic agent consent', { tag: ['@cloud', '@ui'] }, () => {
test.use({ agentConsentAccepted: false })
test.use({
agentConsentAccepted: false,
agentPanelInitiallyOpen: true
})

test('offers once on first load and remains available manually after Skip', async ({
comfyPage,
Expand Down Expand Up @@ -541,19 +544,22 @@ test.describe(
).toBeNull()
})

await test.step('Taking the blank canvas presents the deferred offer', async () => {
await test.step('Taking the blank canvas leaves the activated panel available for a message', async () => {
await page.getByTestId('getting-started-blank').click()
await expect(gettingStarted).toHaveCount(0)
await expect(consent).toBeVisible()
await expect(consent).toHaveCount(0)
await expect(agentPanel.root).toBeVisible()
expect(agentConsentWrites).toHaveLength(0)
expect(
await page.evaluate((key) => localStorage.getItem(key), autoShownKey)
).toBeNull()
})
})
}
)

test.describe(
'Automatic agent consent behind a desktop sign-in approval',
'Agent activation behind a desktop sign-in approval',
{ tag: ['@cloud', '@ui'] },
() => {
test.use({ agentConsentAccepted: false })
Expand All @@ -569,7 +575,7 @@ test.describe(
)
})

test('waits for the approval before offering Agent', async ({
test('waits for the approval before leaving Agent available', async ({
comfyPage,
agentPanel,
agentConsentReads
Expand All @@ -589,7 +595,8 @@ test.describe(
'Comfy.AgentConsent.AutoShown.test-user-e2e.ws-personal'

await test.step('Boot again on a desktop sign-in link with the offer unspent', async () => {
await expect(consent).toBeVisible()
await expect(consent).toHaveCount(0)
await expect(agentPanel.root).toBeVisible()
await page.evaluate((key) => localStorage.removeItem(key), autoShownKey)
const readsBeforeLink = agentConsentReads.length
await comfyPage.goto({
Expand All @@ -614,11 +621,111 @@ test.describe(
).toBeNull()
})

await test.step('Approving clears the screen and the offer follows', async () => {
await test.step('Approving clears the screen without covering the activated panel', async () => {
await approve.click()
await expect(approval).toHaveCount(0)
await expect(consent).toHaveCount(0)
await expect(agentPanel.root).toBeVisible()
})
})
}
)

test.describe(
'Fresh signed-in Agent consent and tour sequencing',
{ tag: ['@cloud', '@ui'] },
() => {
test.use({ agentConsentAccepted: false })

for (const tourAction of ['finish', 'skip'] as const) {
test(`resumes one held send after the user ${tourAction === 'finish' ? 'finishes' : 'skips'} the tour`, async ({
agentPanel,
comfyPage,
postedMessages
}) => {
const page = comfyPage.page
const consent = page.getByRole('dialog', {
name: enMessages.agent.consent.title
})

await expect(agentPanel.root).toBeVisible()
await expect(consent).toHaveCount(0)
await agentPanel.selectWorkflow()
await agentPanel.composer.fill('Build a product photo workflow')
await agentPanel.sendButton.click()

await expect(consent).toBeVisible()
expect(postedMessages).toHaveLength(0)
await consent
.getByRole('button', { name: enMessages.agent.consent.accept })
.click()

const coachTitles = [
enMessages.agent.coachTitle,
enMessages.agent.coachWorkflowTitle,
enMessages.agent.coachGraphTitle,
enMessages.agent.coachHistoryTitle
]
await expect(
page.getByRole('dialog', { name: coachTitles[0] })
).toBeVisible()
expect(postedMessages).toHaveLength(0)

if (tourAction === 'skip') {
await page
.getByRole('dialog', { name: coachTitles[0] })
.getByRole('button', { name: enMessages.agent.skip })
.click()
} else {
for (const [index, title] of coachTitles.entries()) {
await page
.getByRole('dialog', { name: title })
.getByRole('button', {
name:
index === coachTitles.length - 1
? enMessages.onboardingCoachmarks.done
: enMessages.g.next
})
.click()
}
}

await expect.poll(() => postedMessages).toHaveLength(1)
await agentPanel.openButton.click()
await expect(agentPanel.root).toHaveCount(0)
await agentPanel.openButton.click()
await expect(agentPanel.root).toBeVisible()
await expect(consent).toHaveCount(0)
await expect.poll(() => postedMessages).toHaveLength(1)
})
}

test('resumes the held send when App Mode defers the active tour', async ({
agentPanel,
comfyPage,
postedMessages
}) => {
const page = comfyPage.page
const consent = page.getByRole('dialog', {
name: enMessages.agent.consent.title
})
const coach = page.getByRole('dialog', {
name: enMessages.agent.coachTitle
})

await agentPanel.selectWorkflow()
await agentPanel.composer.fill('Build a product photo workflow')
await agentPanel.sendButton.click()
await consent
.getByRole('button', { name: enMessages.agent.consent.accept })
.click()

await expect(coach).toBeVisible()
expect(postedMessages).toHaveLength(0)
await comfyPage.command.executeCommand('Comfy.ToggleLinear')

await expect(coach).toHaveCount(0)
await expect.poll(() => postedMessages).toHaveLength(1)
})
}
)
32 changes: 32 additions & 0 deletions src/extensions/core/agentPanel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ describe('AgentPanel extension flag gate', () => {
)
mocks.registerTracker.mockClear()
localStorage.clear()
sessionStorage.clear()
canvasStore.updateSelectedItems.mockClear()
mocks.getNodeByLocatorId.mockReset()
nodeSelectionStore.beginWorkflowLoad.mockClear()
Expand Down Expand Up @@ -270,6 +271,37 @@ describe('AgentPanel extension flag gate', () => {
})
})

it('preserves activation ownership across an app remount', async () => {
agentFlagEnabled.value = true
Object.assign(consentStore, { accepted: false, isChecking: false })
const trackAgentConsentOfferExited = vi.fn()
const { useTelemetry: useCurrentTelemetry } =
await import('@/platform/telemetry')
vi.mocked(useCurrentTelemetry).mockReturnValue(
fromPartial<NonNullable<ReturnType<typeof useTelemetry>>>({
trackAgentConsentOfferExited,
trackAgentPanelOpened: vi.fn()
})
)
sessionStorage.setItem(
'Comfy.AgentPanel.ActivationOpened.account-a.workspace-a',
'true'
)

await loadEntryAndSetup()
await flush()

expect(agentStore.isOpen).toBe(true)
expect(useAgentConsent().withConsent).not.toHaveBeenCalled()
await vi.waitFor(() =>
expect(trackAgentConsentOfferExited).toHaveBeenCalledExactlyOnceWith({
exit: 'activation_opened_panel',
stage: 'offer',
retry_armed: false
})
)
})

it('keeps the panel closed if the feature is disabled before acceptance', async () => {
agentFlagEnabled.value = true
Object.assign(consentStore, { accepted: false, isChecking: false })
Expand Down
98 changes: 94 additions & 4 deletions src/extensions/core/agentPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,68 @@ import {
export const GATE_SETTLE_TIMEOUT_MS = 5_000

const CONSENT_AUTO_SHOWN_PREFIX = 'Comfy.AgentConsent.AutoShown'
const ACTIVATION_OPENED_PANEL_PREFIX = 'Comfy.AgentPanel.ActivationOpened'

function activationOpenedPanelKey(
userId: string | undefined,
workspaceId: string | null
): string | null {
return userId && workspaceId
? `${ACTIVATION_OPENED_PANEL_PREFIX}.${userId}.${workspaceId}`
: null
}

function persistActivationOpenedPanel(
userId: string | undefined,
workspaceId: string | null
): void {
const key = activationOpenedPanelKey(userId, workspaceId)
if (!key) return
try {
sessionStorage.setItem(key, 'true')
} catch {
// The in-memory marker still preserves ownership until the next remount.
}
}

function wasActivationOpenedPanel(
userId: string | undefined,
workspaceId: string | null
): boolean {
const key = activationOpenedPanelKey(userId, workspaceId)
if (!key) return false
try {
return sessionStorage.getItem(key) === 'true'
} catch {
return false
}
}

function automaticConsentOfferScope(
{
activationOpenedPanel,
panelOpen,
userId,
workspaceId,
workspaceSwitching
}: {
activationOpenedPanel: boolean
panelOpen: boolean
userId: string | undefined
workspaceId: string | null
workspaceSwitching: boolean
},
onActivatedPanel: () => void
): [userId: string, workspaceId: string] | null {
if (!userId || !workspaceId || workspaceSwitching) {
return null
}
if (activationOpenedPanel && panelOpen) {
onActivatedPanel()
return null
}
return [userId, workspaceId]
}

function writeAutoShown(key: string, shown: boolean): boolean {
try {
Expand Down Expand Up @@ -235,6 +297,7 @@ export function registerAgentPanelExtension(): void {
return userId && workspaceId ? `${userId}.${workspaceId}` : null
}
const consentCardSeenIn = new Set<string>()
let activationOpenedPanel = false
whenever(
() => dialogStore.isDialogOpen(CONSENT_DIALOG_KEY),
() => {
Expand Down Expand Up @@ -262,9 +325,29 @@ export function registerAgentPanelExtension(): void {
return
}

const userId = resolvedUserInfo.value?.id
const workspaceId = workspaceStore.activeWorkspaceId
if (!userId || !workspaceId || workspaceStore.isSwitching) return
const candidateUserId = resolvedUserInfo.value?.id
const candidateWorkspaceId = workspaceStore.activeWorkspaceId
const offerScope = automaticConsentOfferScope(
{
activationOpenedPanel:
activationOpenedPanel ||
wasActivationOpenedPanel(candidateUserId, candidateWorkspaceId),
panelOpen: agentPanelStore.isOpen,
userId: candidateUserId,
workspaceId: candidateWorkspaceId,
workspaceSwitching: workspaceStore.isSwitching
},
() => {
useTelemetry()?.trackAgentConsentOfferExited({
exit: 'activation_opened_panel',
stage: 'offer',
retry_armed: false
})
offerHeld.value = false
}
)
if (!offerScope) return
const [userId, workspaceId] = offerScope
const key = `${CONSENT_AUTO_SHOWN_PREFIX}.${userId}.${workspaceId}`
const autoShow = prepareAutoShow(key)
if (autoShow === 'storage_unavailable') withholdOffer(autoShow)
Expand Down Expand Up @@ -320,7 +403,14 @@ export function registerAgentPanelExtension(): void {
.then((decided) => {
if (decided && agentPanelStore.enabled) {
activationOffered = true
if (!agentPanelStore.isOpen) agentPanelStore.open('activation')
if (!agentPanelStore.isOpen) {
agentPanelStore.open('activation')
activationOpenedPanel = true
persistActivationOpenedPanel(
resolvedUserInfo.value?.id,
workspaceStore.activeWorkspaceId
)
}
}
})
.catch((error: unknown) => {
Expand Down
2 changes: 2 additions & 0 deletions src/platform/telemetry/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,8 @@ export type AgentConsentOfferExit =
| 'offer_in_flight'
/** The card has already been on screen for this scope this page load. */
| 'card_already_seen'
/** Panel activation owns consent timing, so the automatic offer is dropped. */
| 'activation_opened_panel'
/** The one-shot auto-show key for this scope is already burned. */
| 'already_offered'
/** The first-run startup probe rejected. */
Expand Down
Loading
Loading