mirror of
https://github.com/langgenius/dify.git
synced 2026-11-10 13:26:58 +08:00
fix: preserve agent publication status when renaming (#45949)
This commit is contained in:
2 files changed
+69
-2
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import type { AgentAppPagination } from '@dify/contracts/api/console/agent/types.gen'
|
||||
import type { ApiBasedExtensionResponse } from '@dify/contracts/api/console/api-based-extension/types.gen'
|
||||
import type { AppSiteResponse } from '@dify/contracts/api/console/apps/types.gen'
|
||||
import type { TagResponse as Tag } from '@dify/contracts/api/console/tags/types.gen'
|
||||
@@ -1475,6 +1476,72 @@ describe('consoleQuery agent mutation defaults', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it.each([true, false])(
|
||||
'preserves roster publication and reference data when renaming an agent with published state %s',
|
||||
async (isPublished) => {
|
||||
const consoleQuery = await loadConsoleQuery()
|
||||
const queryClient = createQueryClient()
|
||||
const agent = {
|
||||
...createAgent(),
|
||||
active_config_is_published: isPublished,
|
||||
hidden_app_backed: false,
|
||||
is_starred: false,
|
||||
published_reference_count: 1,
|
||||
published_references: [{ app_id: 'workflow-1', app_name: 'Research Workflow' }],
|
||||
}
|
||||
const otherAgent = {
|
||||
...createAgent({ id: 'agent-2', name: 'Other Agent' }),
|
||||
active_config_is_published: false,
|
||||
hidden_app_backed: false,
|
||||
is_starred: false,
|
||||
published_reference_count: 0,
|
||||
}
|
||||
const rosterPage = {
|
||||
data: [agent, otherAgent],
|
||||
has_more: false,
|
||||
limit: 30,
|
||||
page: 1,
|
||||
publication_counts: { drafts: isPublished ? 1 : 2, published: isPublished ? 1 : 0 },
|
||||
total: 2,
|
||||
} satisfies AgentAppPagination
|
||||
const listQueryKey = consoleQuery.agent.get.queryKey({
|
||||
input: { query: { page: 1, limit: 30 } },
|
||||
})
|
||||
const infiniteQueryKey = consoleQuery.agent.get.infiniteOptions({
|
||||
input: (pageParam) => ({ query: { page: Number(pageParam), limit: 30 } }),
|
||||
initialPageParam: 1,
|
||||
getNextPageParam: (lastPage) => (lastPage.has_more ? lastPage.page + 1 : undefined),
|
||||
}).queryKey
|
||||
queryClient.setQueryData(listQueryKey, rosterPage)
|
||||
queryClient.setQueryData(infiniteQueryKey, { pages: [rosterPage], pageParams: [1] })
|
||||
const updatedAgent = createAgent({ name: 'Updated Agent' })
|
||||
|
||||
await consoleQuery.agent.byAgentId.put.mutationOptions().onSuccess!(
|
||||
updatedAgent,
|
||||
{ params: { agent_id: agent.id }, body: { name: updatedAgent.name } },
|
||||
undefined,
|
||||
createMutationContext(queryClient),
|
||||
)
|
||||
|
||||
const expectedPage = {
|
||||
...rosterPage,
|
||||
data: [{ ...agent, name: updatedAgent.name }, otherAgent],
|
||||
}
|
||||
expect(queryClient.getQueryData(listQueryKey)).toEqual(expectedPage)
|
||||
expect(queryClient.getQueryData(infiniteQueryKey)).toEqual({
|
||||
pages: [expectedPage],
|
||||
pageParams: [1],
|
||||
})
|
||||
expect(
|
||||
queryClient.getQueryData(
|
||||
consoleQuery.agent.byAgentId.get.queryKey({
|
||||
input: { params: { agent_id: agent.id } },
|
||||
}),
|
||||
),
|
||||
).toEqual(updatedAgent)
|
||||
},
|
||||
)
|
||||
|
||||
it('should invalidate invite option lists after updating an agent', async () => {
|
||||
const consoleQuery = await loadConsoleQuery()
|
||||
const queryClient = createQueryClient()
|
||||
|
||||
@@ -2380,7 +2380,7 @@ export function createConsoleQuery(consoleClient: ConsoleClient) {
|
||||
return {
|
||||
...oldList,
|
||||
data: oldList.data.map((item) =>
|
||||
item.id === updatedAgent.id ? updatedAgent : item,
|
||||
item.id === updatedAgent.id ? { ...item, ...updatedAgent } : item,
|
||||
),
|
||||
}
|
||||
},
|
||||
@@ -2402,7 +2402,7 @@ export function createConsoleQuery(consoleClient: ConsoleClient) {
|
||||
pages: oldList.pages.map((page) => ({
|
||||
...page,
|
||||
data: page.data.map((item) =>
|
||||
item.id === updatedAgent.id ? updatedAgent : item,
|
||||
item.id === updatedAgent.id ? { ...item, ...updatedAgent } : item,
|
||||
),
|
||||
})),
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user