chore(web): ignore system vars & conversation vars in rag-pipeline and snippet

This commit is contained in:
JzoNg
2026-03-29 15:56:24 +08:00
parent e6e3229d17
commit 1e76ef5ccb
2 changed files with 68 additions and 3 deletions

View File

@@ -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, '')
})
})

View File

@@ -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: [] }