Files
fd2db63184 feat: KnowledgeFS and New Knowledge (#44165)
Co-authored-by: Jyong <76649700+JohnJyong@users.noreply.github.com>
Co-authored-by: hjlarry <hjlarry@163.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: zhaohao1004 <zhaohao1004@gmail.com>
Co-authored-by: yyh <yuanyouhuilyz@gmail.com>
Co-authored-by: FFXN <lizy@dify.ai>
2026-10-23 03:34:59 +00:00

72 lines
2.4 KiB
TypeScript

// @vitest-environment node
import { QueryClient } from '@tanstack/react-query'
import { consoleQuery } from '@/service/console'
const mocks = vi.hoisted(() => ({
connection: vi.fn(async () => undefined),
getQueryClient: vi.fn(),
getSystemFeatures: vi.fn(),
}))
vi.mock('server-only', () => ({}))
vi.mock('@/app/get-query-client', () => ({
getQueryClient: mocks.getQueryClient,
}))
vi.mock('@/next/server', () => ({
connection: mocks.connection,
}))
vi.mock('@/service/console', async (importOriginal) => {
const actual = await importOriginal<typeof import('@/service/console')>()
const { withConsoleResponses } = await import('@/test/console/service-responses')
return {
...actual,
consoleQuery: withConsoleResponses(actual.consoleQuery, {
'systemFeatures.get': () => mocks.getSystemFeatures(),
}),
}
})
describe('System Features server requests', () => {
beforeEach(() => {
vi.clearAllMocks()
vi.resetModules()
mocks.getQueryClient.mockReturnValue(
new QueryClient({ defaultOptions: { queries: { retry: false } } }),
)
mocks.connection.mockResolvedValue(undefined)
mocks.getSystemFeatures.mockResolvedValue({ deployment_edition: 'CLOUD' })
})
it('reuses a successful optional lookup from the request query client', async () => {
const { dehydrateSystemFeatures, getOptionalSystemFeatures } = await import('../server')
await expect(getOptionalSystemFeatures()).resolves.toEqual({ deployment_edition: 'CLOUD' })
await expect(getOptionalSystemFeatures()).resolves.toEqual({ deployment_edition: 'CLOUD' })
expect(mocks.getSystemFeatures).toHaveBeenCalledOnce()
expect(dehydrateSystemFeatures().queries).toEqual([
expect.objectContaining({
queryKey: consoleQuery.systemFeatures.get.queryKey(),
state: expect.objectContaining({
data: { deployment_edition: 'CLOUD' },
status: 'success',
}),
}),
])
})
it('keeps optional failures soft for the rest of the request', async () => {
mocks.getSystemFeatures.mockRejectedValueOnce(new Error('System Features unavailable'))
const { getOptionalSystemFeatures } = await import('../server')
await expect(getOptionalSystemFeatures()).resolves.toBeUndefined()
await expect(getOptionalSystemFeatures()).resolves.toBeUndefined()
expect(mocks.getSystemFeatures).toHaveBeenCalledOnce()
})
})