mirror of
https://github.com/langgenius/dify.git
synced 2026-04-05 16:26:25 +08:00
chore(web): ignore system vars & conversation vars in rag-pipeline and snippet
This commit is contained in:
@@ -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 partOfNodesWithInspectVars = useStore(s => s.nodesWithInspectVars)
|
||||
const configsMap = useHooksStore(s => s.configsMap)
|
||||
const isRagPipeline = configsMap?.flowType === FlowType.ragPipeline
|
||||
const { data: conversationVars } = useConversationVarValues(configsMap?.flowType, !isRagPipeline ? configsMap?.flowId : '')
|
||||
const { data: allSystemVars } = useSysVarValues(configsMap?.flowType, !isRagPipeline ? configsMap?.flowId : '')
|
||||
const shouldSkipSharedVariableQueries = configsMap?.flowType === FlowType.ragPipeline || configsMap?.flowType === FlowType.snippet
|
||||
const variableFlowId = shouldSkipSharedVariableQueries ? '' : configsMap?.flowId
|
||||
const { data: conversationVars } = useConversationVarValues(configsMap?.flowType, variableFlowId)
|
||||
const { data: allSystemVars } = useSysVarValues(configsMap?.flowType, variableFlowId)
|
||||
const { varsAppendStartNode, systemVars } = (() => {
|
||||
if (allSystemVars?.length === 0)
|
||||
return { varsAppendStartNode: [], systemVars: [] }
|
||||
|
||||
Reference in New Issue
Block a user