Files
dify/cli/src/api/apps.test.ts
GareArc c3f56fcc9a refactor(openapi/cli): drop tag/author from app usage-face noun
The app noun is the usage face; tags and author are build/management
metadata that belong to studio-app, not here. Remove them end to end:

- backend: drop tags/created_by_name from AppListRow, tag from
  AppListQuery, the TagItem model, and the tag-name filter lookup;
  stop hardcoding the cross-tenant blanks in the permitted-external list
- cli: remove the --tag flag, TAGS/AUTHOR columns, and tag from the
  list query; single get app <id> no longer fabricates the fields
- regenerate openapi contracts (types/zod) and markdown docs

get app and get app <id> now agree (neither surfaces tags/author),
resolving the list-vs-single divergence raised in review.
2026-06-21 21:25:13 -07:00

113 lines
3.7 KiB
TypeScript

import type { StubServer } from '@test/fixtures/stub-server'
import { testHttpClient } from '@test/fixtures/http-client'
import { jsonResponder, startStubServer } from '@test/fixtures/stub-server'
import { afterEach, describe, expect, it } from 'vitest'
import { isHttpClientError } from '@/errors/base'
import { AppsClient } from './apps.js'
const LIST_BODY = { page: 1, limit: 20, total: 0, has_more: false, data: [] }
const DESCRIBE_BODY = { info: { id: 'app-1', name: 'Demo', mode: 'chat', service_api_enabled: true } }
function makeClient(host: string): AppsClient {
return new AppsClient(testHttpClient(host, 'dfoa_test'))
}
function queryOf(url: string | undefined): URLSearchParams {
return new URL(url ?? '', 'http://x').searchParams
}
describe('AppsClient.list', () => {
let stub: StubServer
afterEach(async () => {
await stub?.stop()
})
it('defaults page=1 & limit=20 and always sends workspace_id', async () => {
stub = await startStubServer(cap => jsonResponder(200, LIST_BODY, cap))
await makeClient(stub.url).list({ workspaceId: 'ws-1' })
const q = queryOf(stub.captured.url)
expect(stub.captured.method).toBe('GET')
expect(q.get('workspace_id')).toBe('ws-1')
expect(q.get('page')).toBe('1')
expect(q.get('limit')).toBe('20')
// Optional filters are omitted entirely when not supplied.
expect(q.has('mode')).toBe(false)
expect(q.has('name')).toBe(false)
})
it('forwards explicit pagination and filters', async () => {
stub = await startStubServer(cap => jsonResponder(200, LIST_BODY, cap))
await makeClient(stub.url).list({
workspaceId: 'ws-1',
page: 3,
limit: 50,
mode: 'chat',
name: 'support bot',
})
const q = queryOf(stub.captured.url)
expect(q.get('page')).toBe('3')
expect(q.get('limit')).toBe('50')
expect(q.get('mode')).toBe('chat')
expect(q.get('name')).toBe('support bot')
})
it('treats empty-string filters as absent (not blank query params)', async () => {
stub = await startStubServer(cap => jsonResponder(200, LIST_BODY, cap))
await makeClient(stub.url).list({ workspaceId: 'ws-1', mode: '', name: '' })
const q = queryOf(stub.captured.url)
expect(q.has('mode')).toBe(false)
expect(q.has('name')).toBe(false)
})
it('propagates server 403 as a classified BaseError', async () => {
stub = await startStubServer(cap => jsonResponder(403, { error: 'forbidden' }, cap))
await expect(makeClient(stub.url).list({ workspaceId: 'ws-1' })).rejects.toSatisfy(
err => isHttpClientError(err) && err.httpStatus === 403,
)
})
})
describe('AppsClient.describe', () => {
let stub: StubServer
afterEach(async () => {
await stub?.stop()
})
it('hits /apps/<id>/describe, omits workspace_id and fields when not given', async () => {
stub = await startStubServer(cap => jsonResponder(200, DESCRIBE_BODY, cap))
const res = await makeClient(stub.url).describe('app-1')
expect(stub.captured.url?.split('?')[0]).toBe('/openapi/v1/apps/app-1/describe')
const q = queryOf(stub.captured.url)
expect(q.has('workspace_id')).toBe(false)
expect(q.has('fields')).toBe(false)
expect(res.info?.id).toBe('app-1')
})
it('joins fields with commas', async () => {
stub = await startStubServer(cap => jsonResponder(200, DESCRIBE_BODY, cap))
await makeClient(stub.url).describe('app-1', ['parameters', 'input_schema'])
expect(queryOf(stub.captured.url).get('fields')).toBe('parameters,input_schema')
})
it('URL-encodes the app id', async () => {
stub = await startStubServer(cap => jsonResponder(200, DESCRIBE_BODY, cap))
await makeClient(stub.url).describe('app/with space')
expect(stub.captured.url?.split('?')[0]).toBe('/openapi/v1/apps/app%2Fwith%20space/describe')
})
})