Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

2.1 KB
Raw Blame
import type { DifyWorld } from '../../support/world.ts'
import { Then, When } from '@cucumber/cucumber'
import { zPostAgentResponse } from '@dify/contracts/api/console/agent/zod.gen'
import { expect } from '@playwright/test'
import { createE2EResourceName } from '../../../support/naming.ts'

When('I create an Agent v2 test agent from the Agent Roster', async function (this: DifyWorld) {
  const page = this.getPage()
  const agentName = createE2EResourceName('Agent', 'roster-ui')
  const agentRole = 'E2E roster-created assistant'
  const agentDescription = 'Created by Dify E2E through the Agent Roster UI.'

  await page.goto('/agents')
  await page.getByRole('button', { name: 'Create' }).click()
  await page.getByRole('menuitem', { name: 'Create from Blank' }).click()

  const dialog = page.getByRole('dialog', { name: 'Create agent' })
  await expect(dialog).toBeVisible()
  await dialog.getByRole('textbox', { name: 'Name' }).fill(agentName)
  await dialog.getByRole('textbox', { name: /Role.*optional/ }).fill(agentRole)
  await dialog.getByRole('textbox', { name: /Description.*optional/ }).fill(agentDescription)

  const createResponsePromise = page.waitForResponse(
    (response) =>
      response.request().method() === 'POST' &&
      new URL(response.url()).pathname.endsWith('/console/api/agent'),
  )

  await dialog.getByRole('button', { name: 'Create' }).click()
  const createResponse = await createResponsePromise
  expect(createResponse.ok()).toBe(true)

  const createdAgent = zPostAgentResponse.parse(await createResponse.json())
  this.createdAgentIds.push(createdAgent.id)
  this.lastCreatedAgentName = createdAgent.name
  this.lastCreatedAgentRole = createdAgent.role ?? undefined
})

Then('the created Agent v2 should open in Configure', async function (this: DifyWorld) {
  const agentId = this.createdAgentIds.at(-1)
  if (!agentId) throw new Error('No Agent v2 ID found. Create an Agent v2 test agent first.')

  await expect(this.getPage()).toHaveURL(new RegExp(`/agents/${agentId}/configure(?:\\?.*)?$`), {
    timeout: 30_000,
  })
  await expect(this.getPage().getByRole('heading', { name: 'Configure' })).toBeVisible({
    timeout: 30_000,
  })
})