mirror of
https://github.com/langgenius/dify.git
synced 2026-09-08 10:56:13 +08:00
chore(web): ignore system vars & conversation vars in rag-pipeline and snippet
This commit is contained in:
parent
e6e3229d17
commit
1e76ef5ccb
@ -0,0 +1,64 @@
|
|||||||
|
import { FlowType } from '@/types/common'
|
||||||
|
import { renderWorkflowHook } from '../../__tests__/workflow-test-env'
|
||||||
|
import useInspectVarsCrud from '../use-inspect-vars-crud'
|
||||||
|
|
||||||
|
const mockUseConversationVarValues = vi.fn()
|
||||||
|
const mockUseSysVarValues = vi.fn()
|
||||||
|
|
||||||
|
vi.mock('@/service/use-workflow', () => ({
|
||||||
|
useConversationVarValues: (flowType?: FlowType, flowId?: string) => mockUseConversationVarValues(flowType, flowId),
|
||||||
|
useSysVarValues: (flowType?: FlowType, flowId?: string) => mockUseSysVarValues(flowType, flowId),
|
||||||
|
}))
|
||||||
|
|
||||||
|
describe('useInspectVarsCrud', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.clearAllMocks()
|
||||||
|
mockUseConversationVarValues.mockReturnValue({ data: [] })
|
||||||
|
mockUseSysVarValues.mockReturnValue({ data: [] })
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should pass flowId to conversation and system variable queries for app flows', () => {
|
||||||
|
renderWorkflowHook(() => useInspectVarsCrud(), {
|
||||||
|
hooksStoreProps: {
|
||||||
|
configsMap: {
|
||||||
|
flowId: 'app-1',
|
||||||
|
flowType: FlowType.appFlow,
|
||||||
|
fileSettings: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(mockUseConversationVarValues).toHaveBeenCalledWith(FlowType.appFlow, 'app-1')
|
||||||
|
expect(mockUseSysVarValues).toHaveBeenCalledWith(FlowType.appFlow, 'app-1')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should skip conversation and system variable queries for rag pipelines', () => {
|
||||||
|
renderWorkflowHook(() => useInspectVarsCrud(), {
|
||||||
|
hooksStoreProps: {
|
||||||
|
configsMap: {
|
||||||
|
flowId: 'pipeline-1',
|
||||||
|
flowType: FlowType.ragPipeline,
|
||||||
|
fileSettings: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(mockUseConversationVarValues).toHaveBeenCalledWith(FlowType.ragPipeline, '')
|
||||||
|
expect(mockUseSysVarValues).toHaveBeenCalledWith(FlowType.ragPipeline, '')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should skip conversation and system variable queries for snippets', () => {
|
||||||
|
renderWorkflowHook(() => useInspectVarsCrud(), {
|
||||||
|
hooksStoreProps: {
|
||||||
|
configsMap: {
|
||||||
|
flowId: 'snippet-1',
|
||||||
|
flowType: FlowType.snippet,
|
||||||
|
fileSettings: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(mockUseConversationVarValues).toHaveBeenCalledWith(FlowType.snippet, '')
|
||||||
|
expect(mockUseSysVarValues).toHaveBeenCalledWith(FlowType.snippet, '')
|
||||||
|
})
|
||||||
|
})
|
||||||
@ -12,9 +12,10 @@ const varsAppendStartNodeKeys = ['query', 'files']
|
|||||||
const useInspectVarsCrud = () => {
|
const useInspectVarsCrud = () => {
|
||||||
const partOfNodesWithInspectVars = useStore(s => s.nodesWithInspectVars)
|
const partOfNodesWithInspectVars = useStore(s => s.nodesWithInspectVars)
|
||||||
const configsMap = useHooksStore(s => s.configsMap)
|
const configsMap = useHooksStore(s => s.configsMap)
|
||||||
const isRagPipeline = configsMap?.flowType === FlowType.ragPipeline
|
const shouldSkipSharedVariableQueries = configsMap?.flowType === FlowType.ragPipeline || configsMap?.flowType === FlowType.snippet
|
||||||
const { data: conversationVars } = useConversationVarValues(configsMap?.flowType, !isRagPipeline ? configsMap?.flowId : '')
|
const variableFlowId = shouldSkipSharedVariableQueries ? '' : configsMap?.flowId
|
||||||
const { data: allSystemVars } = useSysVarValues(configsMap?.flowType, !isRagPipeline ? configsMap?.flowId : '')
|
const { data: conversationVars } = useConversationVarValues(configsMap?.flowType, variableFlowId)
|
||||||
|
const { data: allSystemVars } = useSysVarValues(configsMap?.flowType, variableFlowId)
|
||||||
const { varsAppendStartNode, systemVars } = (() => {
|
const { varsAppendStartNode, systemVars } = (() => {
|
||||||
if (allSystemVars?.length === 0)
|
if (allSystemVars?.length === 0)
|
||||||
return { varsAppendStartNode: [], systemVars: [] }
|
return { varsAppendStartNode: [], systemVars: [] }
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user