chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
60158935f4
commit
6519682885
15831 files changed
+3063428
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import type { DifyClientConfig } from '../src/types/common'
|
||||
import { vi } from 'vite-plus/test'
|
||||
import { HttpClient } from '../src/http/client'
|
||||
|
||||
type FetchMock = ReturnType<typeof vi.fn>
|
||||
type RequestSpy = ReturnType<typeof vi.fn>
|
||||
|
||||
type HttpClientWithFetchMock = {
|
||||
client: HttpClient
|
||||
fetchMock: FetchMock
|
||||
}
|
||||
|
||||
type HttpClientWithSpies = HttpClientWithFetchMock & {
|
||||
request: RequestSpy
|
||||
requestStream: RequestSpy
|
||||
requestBinaryStream: RequestSpy
|
||||
}
|
||||
|
||||
export const createHttpClient = (
|
||||
configOverrides: Partial<DifyClientConfig> = {},
|
||||
): HttpClientWithFetchMock => {
|
||||
const fetchMock = vi.fn()
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
const client = new HttpClient({ apiKey: 'test', ...configOverrides })
|
||||
return { client, fetchMock }
|
||||
}
|
||||
|
||||
export const createHttpClientWithSpies = (
|
||||
configOverrides: Partial<DifyClientConfig> = {},
|
||||
): HttpClientWithSpies => {
|
||||
const { client, fetchMock } = createHttpClient(configOverrides)
|
||||
const request = vi
|
||||
.spyOn(client, 'request')
|
||||
.mockResolvedValue({ data: 'ok', status: 200, headers: {} })
|
||||
const requestStream = vi
|
||||
.spyOn(client, 'requestStream')
|
||||
.mockResolvedValue({ data: null, status: 200, headers: {} } as never)
|
||||
const requestBinaryStream = vi
|
||||
.spyOn(client, 'requestBinaryStream')
|
||||
.mockResolvedValue({ data: null, status: 200, headers: {} } as never)
|
||||
return {
|
||||
client,
|
||||
fetchMock,
|
||||
request,
|
||||
requestStream,
|
||||
requestBinaryStream,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user