Skip to content
27 changes: 27 additions & 0 deletions browser_tests/fixtures/data/shortcutPackFixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export const DISABLED_SHORTCUT_EXTENSION = 'Test.DisabledShortcutPack'
export const ENABLED_SHORTCUT_EXTENSION = 'Test.EnabledShortcutPack'
export const SHORTCUT_PACK_SCRIPT = '/extensions/shortcut-pack/main.js'

/** Pack script registering two extensions with Alt+J / Alt+K; a run stamps `body[data-ran-shortcut]`. */
export const shortcutPackSource = `
import { app } from '../../scripts/app.js'

for (const [name, key] of [
['${DISABLED_SHORTCUT_EXTENSION}', 'j'],
['${ENABLED_SHORTCUT_EXTENSION}', 'k']
]) {
app.registerExtension({
name,
commands: [
{
id: name + '.Run',
label: name + ' run',
function: () => {
document.body.dataset.ranShortcut = name
}
}
],
keybindings: [{ combo: { key, alt: true }, commandId: name + '.Run' }]
})
}
`
18 changes: 18 additions & 0 deletions browser_tests/fixtures/extensionFixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { mergeTests } from '@playwright/test'
import { networkIsolationFixture as base } from '@e2e/fixtures/networkIsolationFixture'

import { comfyPageFixture } from '@e2e/fixtures/ComfyPage'
import { ExtensionHelper } from '@e2e/fixtures/helpers/ExtensionHelper'

const extensionHelperFixture = base.extend<{
extensions: ExtensionHelper
}>({
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
extensions: async ({ page }, use) => {
await use(new ExtensionHelper(page))
}
})

export const extensionTest = mergeTests(
comfyPageFixture,
extensionHelperFixture
)
18 changes: 18 additions & 0 deletions browser_tests/fixtures/helpers/ExtensionHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { Page } from '@playwright/test'

import type { ComfyExtension } from '@/types/comfy'

/** A test extension with no hooks: only data that survives `page.evaluate`. */
export type DataOnlyExtension = Pick<ComfyExtension, 'name' | 'provenance'>

export class ExtensionHelper {
constructor(private readonly page: Page) {}

/** Registers each extension through the app, in order. */
async register(...extensions: DataOnlyExtension[]): Promise<void> {
await this.page.evaluate((extensions) => {
for (const extension of extensions)
window.app!.registerExtension(extension)
}, extensions)
}
}
173 changes: 87 additions & 86 deletions browser_tests/tests/settings/agentExtensionProvenance.spec.ts
Original file line number Diff line number Diff line change
@@ -1,84 +1,90 @@
import type { GetExtensionsResponse } from '@comfyorg/ingest-types'

import {
comfyExpect as expect,
comfyPageFixture as test
} from '@e2e/fixtures/ComfyPage'
import { comfyExpect as expect } from '@e2e/fixtures/ComfyPage'
import { extensionTest as test } from '@e2e/fixtures/extensionFixture'
import { expectElementScreenshot } from '@e2e/fixtures/utils/screenshotRegion'
import type { WorkspaceStore } from '@e2e/types/globals'

test.describe(
'Agent-created extension provenance',
{ tag: '@settings' },
() => {
test('shows agent attribution and filters the extension list', async ({
comfyPage,
page
}) => {
await page.evaluate(() => {
window.app!.registerExtension({ name: 'Manual.Toolbar' })
window.app!.registerExtension({
name: 'agent.cushions.toolbar',
provenance: {
createdBy: 'comfy-agent',
summary: 'Adds cushion controls'
test(
'shows agent attribution and filters the extension list',
{
tag: '@screenshot'
},
async ({ comfyPage, extensions, page }) => {
await extensions.register(
{ name: 'Manual.Toolbar' },
{
name: 'agent.cushions.toolbar',
provenance: {
createdBy: 'comfy-agent',
summary: 'Adds cushion controls'
}
}
})
})
)

await test.step('Open Extensions and see agent attribution', async () => {
await comfyPage.settingDialog.open()
await comfyPage.settingDialog.category('Extension').click()
await expect(page.getByText('Created by agent')).toBeVisible()
await expect(
comfyPage.settingDialog.contentArea.getByText(/Adds cushion controls/)
).toBeVisible()
})
await test.step('Open Extensions and see agent attribution', async () => {
await comfyPage.settingDialog.open()
await comfyPage.settingDialog.category('Extension').click()
await expect(page.getByText('Created by agent')).toBeVisible()
await expect(
comfyPage.settingDialog.contentArea.getByText(
/Adds cushion controls/
)
).toBeVisible()
})

await test.step('Show only agent-created extensions', async () => {
await page.getByRole('button', { name: 'Agent-created' }).click()
await expect(
page.getByRole('switch', { name: 'agent.cushions.toolbar' })
).toBeVisible()
await expect(
page.getByRole('switch', { name: 'Manual.Toolbar' })
).toBeHidden()
})
await test.step('Show only agent-created extensions', async () => {
await page.getByRole('button', { name: 'Agent-created' }).click()
await expect(
page.getByRole('switch', { name: 'agent.cushions.toolbar' })
).toBeVisible()
await expect(
page.getByRole('switch', { name: 'Manual.Toolbar' })
).toBeHidden()
await expectElementScreenshot(
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
comfyPage.settingDialog.contentArea,
'agent-extensions-filtered.png'
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
)
})

await test.step('Disable every agent-created extension', async () => {
const dialog = comfyPage.settingDialog
await dialog.openExtensionActions()
await comfyPage.contextMenu
.menuItem('Disable all agent-created')
.click()
await expect(
dialog.root.getByRole('switch', { name: 'agent.cushions.toolbar' })
).not.toBeChecked()
await expect(
dialog.root.getByRole('button', { name: 'Reload to apply changes' })
).toBeVisible()
await expect
.poll(() =>
comfyPage.settings.getPersistedSetting<string[]>(
'Comfy.Extension.Disabled'
await test.step('Disable every agent-created extension', async () => {
const dialog = comfyPage.settingDialog
await dialog.openExtensionActions()
await comfyPage.contextMenu
.menuItem('Disable all agent-created')
.click()
await expect(
dialog.root.getByRole('switch', { name: 'agent.cushions.toolbar' })
).not.toBeChecked()
await expect(
dialog.root.getByRole('button', { name: 'Reload to apply changes' })
).toBeVisible()
await expect
.poll(() =>
comfyPage.settings.getPersistedSetting<string[]>(
'Comfy.Extension.Disabled'
)
)
)
.toContain('agent.cushions.toolbar')
await dialog.root.getByRole('button', { name: 'All' }).click()
await expect(
dialog.root.getByRole('switch', { name: 'Manual.Toolbar' })
).toBeChecked()
})
})
.toContain('agent.cushions.toolbar')
await dialog.root.getByRole('button', { name: 'All' }).click()
await expect(
dialog.root.getByRole('switch', { name: 'Manual.Toolbar' })
).toBeChecked()
})
}
)

test('disables the bulk action when every agent extension is read-only', async ({
comfyPage,
page
extensions
}) => {
await page.evaluate(() => {
window.app!.registerExtension({
name: 'pysssss.Locking',
provenance: { createdBy: 'comfy-agent' }
})
await extensions.register({
name: 'pysssss.Locking',
provenance: { createdBy: 'comfy-agent' }
})

await comfyPage.settingDialog.open()
Expand All @@ -91,16 +97,14 @@ test.describe(

test('announces a newly registered agent extension with both actions', async ({
comfyPage,
page
extensions
}) => {
await page.evaluate(() => {
window.app!.registerExtension({
name: 'agent.cushions.notices',
provenance: {
createdBy: 'comfy-agent',
summary: 'Adds cushion controls'
}
})
await extensions.register({
name: 'agent.cushions.notices',
provenance: {
createdBy: 'comfy-agent',
summary: 'Adds cushion controls'
}
})

const notice = comfyPage.toast.withText(
Expand Down Expand Up @@ -130,21 +134,20 @@ test.describe(

test('routes an already-open Settings dialog to the extension controls', async ({
comfyPage,
extensions,
page
}) => {
await test.step('Open Settings on another panel first', async () => {
await comfyPage.settingDialog.open()
await comfyPage.settingDialog.goToAboutPanel()
})

await page.evaluate(() => {
window.app!.registerExtension({
name: 'agent.cushions.routing',
provenance: {
createdBy: 'comfy-agent',
summary: 'Adds cushion controls'
}
})
await extensions.register({
name: 'agent.cushions.routing',
provenance: {
createdBy: 'comfy-agent',
summary: 'Adds cushion controls'
}
})

const notice = comfyPage.toast.withText(
Expand All @@ -163,11 +166,9 @@ test.describe(
await comfyPage.settingDialog.goToAboutPanel()
await expect(page.locator('.about-container')).toBeVisible()

await page.evaluate(() => {
window.app!.registerExtension({
name: 'agent.cushions.rerouting',
provenance: { createdBy: 'comfy-agent' }
})
await extensions.register({
name: 'agent.cushions.rerouting',
provenance: { createdBy: 'comfy-agent' }
})
await comfyPage.toast
.withText('Your agent added agent.cushions.rerouting')
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions browser_tests/tests/settings/disabledExtensionShortcut.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import type { GetExtensionsResponse } from '@comfyorg/ingest-types'

import {
comfyExpect as expect,
comfyPageFixture as test
} from '@e2e/fixtures/ComfyPage'
import {
DISABLED_SHORTCUT_EXTENSION,
ENABLED_SHORTCUT_EXTENSION,
SHORTCUT_PACK_SCRIPT,
shortcutPackSource
} from '@e2e/fixtures/data/shortcutPackFixture'

test.use({
initialSettings: { 'Comfy.Extension.Disabled': [DISABLED_SHORTCUT_EXTENSION] }
})

test.beforeEach(async ({ page }) => {
await page.route('**/extensions', (route) =>
route.fulfill({
json: [SHORTCUT_PACK_SCRIPT] satisfies GetExtensionsResponse
})
)
await page.route(`**${SHORTCUT_PACK_SCRIPT}*`, (route) =>
route.fulfill({ contentType: 'text/javascript', body: shortcutPackSource })
)
})

test.describe(
'Disabled third-party extension shortcuts',
{ tag: ['@settings', '@keyboard'] },
() => {
test("a disabled extension's shortcut does nothing and is not listed", async ({
comfyPage,
page
}) => {
const body = page.locator('body')

await test.step('Alt+J (disabled extension) does nothing', async () => {
await comfyPage.canvas.click({ position: { x: 400, y: 400 } })
await comfyPage.canvas.press('Alt+KeyJ')
await comfyPage.nextFrame()
await expect(body).not.toHaveAttribute('data-ran-shortcut')
})

await test.step('Alt+K (enabled extension) still runs', async () => {
await comfyPage.canvas.press('Alt+KeyK')
await expect(body).toHaveAttribute(
'data-ran-shortcut',
ENABLED_SHORTCUT_EXTENSION
)
})

await test.step('Only the enabled shortcut is in Keybindings', async () => {
const { keybindingPanel } = comfyPage.settingDialog
await comfyPage.settingDialog.open()
await comfyPage.settingDialog.category('Keybinding').click()
await keybindingPanel.search('ShortcutPack')
await expect(
keybindingPanel.commandRow(`${ENABLED_SHORTCUT_EXTENSION}.Run`)
).toBeVisible()
await expect(
keybindingPanel.commandRow(`${DISABLED_SHORTCUT_EXTENSION}.Run`)
).toHaveCount(0)
})
})
}
)
Loading