Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

1.3 KB
Raw Blame
import { ORPCError } from '@orpc/client'
import { consoleQuery } from '@/service/console'

const detailOptions = () =>
  consoleQuery.datasets.byDatasetId.get.queryOptions({
    input: { params: { dataset_id: 'dataset-1' } },
  })

// Shared defaults are merged into the generated options at runtime.
const retryDetail = (failureCount: number, error: Error) => {
  const options = detailOptions()
  const retry = 'retry' in options ? options.retry : undefined
  if (typeof retry !== 'function') throw new Error('expected a retry policy')
  return retry(failureCount, error)
}

describe('dataset query policies', () => {
  it.each([403, 404])('does not retry a dataset detail answered with %i', (status) => {
    expect(retryDetail(0, new ORPCError('ERROR', { status }))).toBe(false)
  })

  it('retries other dataset detail failures up to three times', () => {
    const error = new ORPCError('INTERNAL_SERVER_ERROR', { status: 500 })

    expect(retryDetail(2, error)).toBe(true)
    expect(retryDetail(3, error)).toBe(false)
  })

  it('does not refetch process rules on window focus', () => {
    const options = consoleQuery.datasets.processRule.get.queryOptions({ input: { query: {} } })
    expect('refetchOnWindowFocus' in options ? options.refetchOnWindowFocus : undefined).toBe(false)
  })
})