From e05eb7d7bfccb0a2d9b7b68e614062d98d3e6c06 Mon Sep 17 00:00:00 2001 From: yyh <92089059+lyzno1@users.noreply.github.com> Date: Wed, 15 Jul 2026 12:15:16 +0800 Subject: [PATCH] fix(e2e): probe shellctl health in preflight (#38971) --- .../support/preflight/agent-backend.ts | 12 ++++--- e2e/tests/agent-backend-preflight.test.ts | 33 +++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 e2e/tests/agent-backend-preflight.test.ts diff --git a/e2e/features/agent-v2/support/preflight/agent-backend.ts b/e2e/features/agent-v2/support/preflight/agent-backend.ts index 03f31a47254..c6934811570 100644 --- a/e2e/features/agent-v2/support/preflight/agent-backend.ts +++ b/e2e/features/agent-v2/support/preflight/agent-backend.ts @@ -36,18 +36,20 @@ const getAgentBackendURL = () => { return undefined } -const checkRuntimeOpenApi = async ({ +const checkRuntimeEndpoint = async ({ + path, remediation, title, url, world, }: { + path: string remediation: string title: string url: string world: DifyWorld }) => { - const healthURL = `${url}/openapi.json` + const healthURL = `${url}${path}` try { const response = await fetch(healthURL) if (response.ok) return undefined @@ -85,7 +87,8 @@ export async function skipMissingAgentBackendRuntime(world: DifyWorld) { ) } - const agentBackendBlock = await checkRuntimeOpenApi({ + const agentBackendBlock = await checkRuntimeEndpoint({ + path: '/openapi.json', remediation: 'Start a healthy dify-agent server and make sure AGENT_BACKEND_BASE_URL points to it before running Agent v2 runtime scenarios.', title: 'Agent v2 runtime backend', @@ -96,7 +99,8 @@ export async function skipMissingAgentBackendRuntime(world: DifyWorld) { const shellctlURL = getShellctlURL() if (shellctlURL) { - const shellctlBlock = await checkRuntimeOpenApi({ + const shellctlBlock = await checkRuntimeEndpoint({ + path: '/healthz', remediation: 'Start the shellctl local sandbox, or run with E2E_START_AGENT_BACKEND=1 so E2E starts it together with dify-agent.', title: 'Agent v2 shellctl sandbox', diff --git a/e2e/tests/agent-backend-preflight.test.ts b/e2e/tests/agent-backend-preflight.test.ts new file mode 100644 index 00000000000..c099ece3da7 --- /dev/null +++ b/e2e/tests/agent-backend-preflight.test.ts @@ -0,0 +1,33 @@ +import type { DifyWorld } from '../features/support/world' +import { afterEach, describe, expect, it, vi } from 'vitest' +import { skipMissingAgentBackendRuntime } from '../features/agent-v2/support/preflight/agent-backend' + +describe('skipMissingAgentBackendRuntime', () => { + afterEach(() => { + vi.unstubAllEnvs() + vi.unstubAllGlobals() + }) + + it('keeps runtime scenarios runnable when the Go shellctl health endpoint is available', async () => { + vi.stubEnv('E2E_AGENT_BACKEND_URL', 'http://agent-backend.test/') + vi.stubEnv('E2E_SHELLCTL_URL', 'http://shellctl.test/') + const fetchMock = vi.fn(async (input) => { + const url = input.toString() + if ( + url === 'http://agent-backend.test/openapi.json' || + url === 'http://shellctl.test/healthz' + ) { + return new Response() + } + + return new Response(null, { status: 404, statusText: 'Not Found' }) + }) + vi.stubGlobal('fetch', fetchMock) + const attach = vi.fn() + const world = { attach } as unknown as DifyWorld + + await expect(skipMissingAgentBackendRuntime(world)).resolves.toBe('http://agent-backend.test') + expect(fetchMock).toHaveBeenCalledTimes(2) + expect(attach).not.toHaveBeenCalled() + }) +})