From 6ba2d50eeb36afbe17c14e3dd34fcb2ef08ae6b9 Mon Sep 17 00:00:00 2001 From: Eugene Date: Mon, 18 May 2026 16:50:17 +0200 Subject: [PATCH] fix(editor): Follow-up changes for Agent permission gates (no-changelog) (#30632) --- .../__tests__/AgentBuilder.readonly.test.ts | 72 +++++++++ .../agents/__tests__/AgentChatPanel.test.ts | 31 ++++ .../__tests__/useAgentPermissions.test.ts | 140 ++++++++++++++++++ .../agents/components/AgentChatPanel.vue | 18 ++- .../agents/composables/useAgentPermissions.ts | 12 +- .../features/agents/views/AgentsListView.vue | 10 +- .../projects/components/ProjectHeader.test.ts | 8 +- .../projects/components/ProjectHeader.vue | 11 +- 8 files changed, 277 insertions(+), 25 deletions(-) create mode 100644 packages/frontend/editor-ui/src/features/agents/__tests__/useAgentPermissions.test.ts diff --git a/packages/frontend/editor-ui/src/features/agents/__tests__/AgentBuilder.readonly.test.ts b/packages/frontend/editor-ui/src/features/agents/__tests__/AgentBuilder.readonly.test.ts index 0b25afbec60..6220889b172 100644 --- a/packages/frontend/editor-ui/src/features/agents/__tests__/AgentBuilder.readonly.test.ts +++ b/packages/frontend/editor-ui/src/features/agents/__tests__/AgentBuilder.readonly.test.ts @@ -187,6 +187,78 @@ describe('AgentChatPanel — read-only build chat input', () => { expect(chatInput.props('placeholder')).toBe('agents.builder.readonly.placeholder'); }); + it('does not auto-send a seeded initialMessage when the build chat is read-only', async () => { + const sendMessage = vi.fn(); + const loadHistory = vi.fn(); + // Reset module cache so the doMock below replaces the stream mock set up + // by the earlier test in this describe block — without this, the cached + // AgentChatPanel.vue would keep using the previous mock and our + // `loadHistory` assertion would observe zero calls on the wrong fn. + vi.resetModules(); + vi.doMock('../composables/useAgentChatStream', () => ({ + useAgentChatStream: () => ({ + messages: ref([]), + isStreaming: ref(false), + messagingState: ref('idle'), + fatalError: ref(null), + loadHistory, + sendMessage, + stopGenerating: vi.fn(), + resume: vi.fn(), + dismissFatalError: vi.fn(), + }), + })); + vi.doMock('../composables/useAgentTelemetry', () => ({ + useAgentTelemetry: () => ({ trackSubmittedMessage: vi.fn() }), + })); + vi.doMock('../composables/agentTelemetry.utils', () => ({ + buildAgentConfigFingerprint: vi.fn().mockResolvedValue({}), + })); + + const beforeSend = vi.fn(); + const { default: AgentChatPanel } = await import('../components/AgentChatPanel.vue'); + + const wrapper = mount(AgentChatPanel, { + props: { + projectId: 'p1', + agentId: 'a1', + endpoint: 'build', + agentConfig: null, + agentStatus: 'draft', + connectedTriggers: [], + canEditAgent: false, + initialMessage: 'seed build prompt', + beforeSend, + }, + global: { + stubs: { + N8nButton: { template: '' }, + N8nCallout: { template: '
' }, + N8nIconButton: { template: '