Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-ui): stop a stale Slack label from minting a Request URL
Jose Ramirez6a5ca4913c32
diff --git a/control-ui/app/communication-channels/[name]/edit/page.tsx b/control-ui/app/communication-channels/[name]/edit/page.tsxindex 0d4dbedf2..afccbf37e 100644--- a/control-ui/app/communication-channels/[name]/edit/page.tsx+++ b/control-ui/app/communication-channels/[name]/edit/page.tsx@@ -27,7 +27,7 @@ import {buildCommunicationChannelSpec,communicationChannelInitialTab,createCommunicationChannelDraft,- hasSlackConfig,+ hasSlackConfigForRequestUrl,} from '@lib/communicationChannelEdit'import {COMMUNICATION_CHANNEL_PROVIDERS,@@ -156,9 +156,11 @@ export default function EditCommunicationChannelPage() {// The URL depends only on namespace/name, both fixed at create time, and the// reader resolves that id regardless of slackSettings, so a draft-derived URL// is already server-truthful. The guard against a copyable dead end on a- // non-Slack channel is kept: no Slack config in the draft, no URL.+ // non-Slack channel is kept: no Slack config in the draft, no URL. A bot+ // handle the draft only inherited from the clerum.io/slack-bot-label+ // annotation is not Slack config, which is why this is not hasSlackConfig.const slackRequestUrl =- draft && hasSlackConfig(draft)+ draft && hasSlackConfigForRequestUrl(draft)? slackWebhookUrlForChannelName(item?.metadata?.name?.trim() || name,item?.metadata?.namespace@@ -454,7 +456,14 @@ export default function EditCommunicationChannelPage() {value={draft.slackBotHandle}onChange={event =>setDraft(current =>- current ? { ...current, slackBotHandle: event.target.value } : current+ current+ ? {+ ...current,+ slackBotHandle: event.target.value,+ // Typed, so no longer just an inherited label.+ slackBotHandleFromAnnotation: false,+ }+ : current)}placeholder="Your Slack App"diff --git a/control-ui/components/__tests__/EditCommunicationChannelPage.test.tsx b/control-ui/components/__tests__/EditCommunicationChannelPage.test.tsxindex 30cb19166..eb7196788 100644--- a/control-ui/components/__tests__/EditCommunicationChannelPage.test.tsx+++ b/control-ui/components/__tests__/EditCommunicationChannelPage.test.tsx@@ -43,7 +43,7 @@ afterEach(() => {type ChannelSpec = Record<string, unknown>-function mockChannel(name: string, spec: ChannelSpec) {+function mockChannel(name: string, spec: ChannelSpec, annotations?: Record<string, string>) {navigation.params = { name }vi.mocked(api.apiGet).mockImplementation(async path => {if (path === '/api/v1/admin/hosts') {@@ -52,7 +52,7 @@ function mockChannel(name: string, spec: ChannelSpec) {if (path === `/api/v1/admin/communication-channels/${name}`) {return {item: {- metadata: { name, namespace: 'channels' },+ metadata: { name, namespace: 'channels', ...(annotations ? { annotations } : {}) },spec: { access: { users: [], teams: [] }, hostRef: 'agent-a', ...spec },},}@@ -77,6 +77,21 @@ const SLACK_CHANNEL_SPEC: ChannelSpec = {slackSettings: { botHandle: 'Evenfire', replyOnlyWhenMentioned: true },}+/** A Telegram-only channel that still carries a leftover Slack label annotation. */+const LABELLED_TELEGRAM_CHANNEL = 'telegram-labelled'+const LABELLED_TELEGRAM_SPEC: ChannelSpec = {+ telegramSettings: { botHandle: '@ops_bot', replyOnlyWhenMentioned: false },+}+const STALE_SLACK_LABEL = { 'clerum.io/slack-bot-label': 'Evenfire' }+/**+ * The Request URL that channel would get if the gate let an annotation through:+ * base64url of {"namespace":"channels","name":"telegram-labelled"}, which is what+ * the reader decodes. Written out rather than derived so a change to either the+ * gate or the encoding has to be looked at.+ */+const LABELLED_TELEGRAM_REQUEST_URL =+ 'https://webhook.example.com/webhooks/slack/slack%3AeyJuYW1lc3BhY2UiOiJjaGFubmVscyIsIm5hbWUiOiJ0ZWxlZ3JhbS1sYWJlbGxlZCJ9'+describe('EditCommunicationChannelPage', () => {it('renders Teams setup details and confirmed conversation metadata', async () => {vi.mocked(api.apiGet).mockImplementation(async path => {@@ -226,4 +241,53 @@ describe('EditCommunicationChannelPage Slack app manifest', () => {// Nothing was persisted to get here: no PUT, and the manifest is on screen.expect(vi.mocked(api.apiSend)).not.toHaveBeenCalled()})++ it('gives a Telegram-only channel with a stale Slack label no Request URL and no manifest', async () => {+ // clerum.io/slack-bot-label is a leftover display label, not a Slack provider.+ // Seeding the draft from it made this channel render a full, copyable Request+ // URL and manifest for a Slack app that does not exist, which is the paste-the-+ // wrong-URL failure this whole page guard is for.+ vi.stubEnv('NEXT_PUBLIC_WORKFLOW_APPROVAL_READER_BASE_URL', 'https://webhook.example.com')+ mockChannel(LABELLED_TELEGRAM_CHANNEL, LABELLED_TELEGRAM_SPEC, STALE_SLACK_LABEL)+ await renderLoadedPage()+ fireEvent.click(screen.getByRole('radio', { name: 'Slack' }))++ // The annotation still fills the visible field. Only the URL and the manifest are gated.+ expect(screen.getByLabelText(/Slack App Name/)).toHaveValue('Evenfire')+ expect(screen.getByText('Available once this channel has a Slack App Name')).toBeInTheDocument()+ expect(screen.queryByText(LABELLED_TELEGRAM_REQUEST_URL)).not.toBeInTheDocument()+ expect(screen.getByRole('button', { name: 'Copy' })).toBeDisabled()+ expect(screen.queryByText('Slack App Manifest')).not.toBeInTheDocument()+ expect(screen.queryByText(/display_information:/)).not.toBeInTheDocument()+ expect(screen.queryByText(/no public webhook address/)).not.toBeInTheDocument()+ })++ it('offers the Request URL and manifest once an App Name is typed over a stale Slack label', async () => {+ // The draft gate exists so the manifest is reachable before anything is saved:+ // Slack hands out the xoxb token only after the app the manifest creates has+ // been installed. Excluding the annotation must not cost that.+ vi.stubEnv('NEXT_PUBLIC_WORKFLOW_APPROVAL_READER_BASE_URL', 'https://webhook.example.com')+ mockChannel(LABELLED_TELEGRAM_CHANNEL, LABELLED_TELEGRAM_SPEC, STALE_SLACK_LABEL)+ await renderLoadedPage()+ fireEvent.click(screen.getByRole('radio', { name: 'Slack' }))++ expect(screen.queryByText('Slack App Manifest')).not.toBeInTheDocument()++ fireEvent.change(screen.getByLabelText(/Slack App Name/), { target: { value: 'Ops Bot' } })++ expect(screen.getByText(LABELLED_TELEGRAM_REQUEST_URL)).toBeInTheDocument()+ expect(screen.getByRole('button', { name: 'Copy' })).toBeEnabled()+ expect(screen.getByText('Slack App Manifest')).toBeInTheDocument()+ const lines = (screen.getByText(/display_information:/).textContent ?? '').split('\n')+ expect(lines.filter(line => /^\s+(name|display_name):/.test(line))).toEqual([+ ' name: "Ops Bot"',+ ' display_name: "Ops Bot"',+ ])+ expect(lines.filter(line => line.trim().startsWith('request_url:'))).toEqual([+ ` request_url: ${LABELLED_TELEGRAM_REQUEST_URL}`,+ ` request_url: ${LABELLED_TELEGRAM_REQUEST_URL}`,+ ])+ // Nothing was persisted to get here: no PUT, and the manifest is on screen.+ expect(vi.mocked(api.apiSend)).not.toHaveBeenCalled()+ })})diff --git a/control-ui/lib/__tests__/communicationChannelEdit.test.ts b/control-ui/lib/__tests__/communicationChannelEdit.test.tsindex d48468272..4f434691c 100644--- a/control-ui/lib/__tests__/communicationChannelEdit.test.ts+++ b/control-ui/lib/__tests__/communicationChannelEdit.test.ts@@ -3,6 +3,7 @@ import {buildCommunicationChannelSpec,communicationChannelInitialTab,createCommunicationChannelDraft,+ hasSlackConfigForRequestUrl,} from '../communicationChannelEdit'import type { CommunicationChannelItem } from '../communicationChannels'@@ -69,6 +70,53 @@ describe('communication channel edit helpers', () => {expect(draft.telegramBotHandle).toBe('legacy_bot')})+ it('keeps the Slack label annotation out of the Request URL gate and nowhere else', () => {+ // Only the Request URL and the app manifest ignore an annotation-only bot+ // handle. The field it fills, the tab the page opens on, and the saved spec+ // all still honour it, so this pins the split rather than the exclusion alone.+ const item = channel({+ metadata: {+ name: 'label-only',+ namespace: 'channels',+ annotations: { 'clerum.io/slack-bot-label': 'Evenfire' },+ },+ spec: { hostRef: 'chatllm', access: { users: [], teams: [] } },+ })+ const draft = createCommunicationChannelDraft(item)++ expect(draft.slackBotHandle).toBe('Evenfire')+ expect(draft.slackBotHandleFromAnnotation).toBe(true)+ expect(hasSlackConfigForRequestUrl(draft)).toBe(false)+ expect(communicationChannelInitialTab(item)).toBe('slack')+ expect(buildCommunicationChannelSpec(draft)).toEqual({+ hostRef: 'chatllm',+ access: { users: [], teams: [] },+ slack: [],+ slackSettings: {+ botHandle: 'Evenfire',+ replyOnlyWhenMentioned: false,+ replyInThreads: false,+ },+ })+ })++ it('counts a Slack bot handle that came from the spec, not the annotation', () => {+ const draft = createCommunicationChannelDraft(+ channel({+ metadata: {+ name: 'slack-channel',+ namespace: 'channels',+ annotations: { 'clerum.io/slack-bot-label': 'Stale Label' },+ },+ spec: { hostRef: 'chatllm', slackSettings: { botHandle: 'Evenfire' } },+ })+ )++ expect(draft.slackBotHandle).toBe('Evenfire')+ expect(draft.slackBotHandleFromAnnotation).toBe(false)+ expect(hasSlackConfigForRequestUrl(draft)).toBe(true)+ })+it('omits inactive provider settings from the saved spec', () => {const spec = buildCommunicationChannelSpec({accessTeamIds: [],diff --git a/control-ui/lib/communicationChannelEdit.ts b/control-ui/lib/communicationChannelEdit.tsindex 743f99ca2..617f754e5 100644--- a/control-ui/lib/communicationChannelEdit.ts+++ b/control-ui/lib/communicationChannelEdit.ts@@ -8,6 +8,13 @@ export type CommunicationChannelDraftState = {hostRef: stringslack: CommunicationChannelGroup[]slackBotHandle: string+ /**+ * True when `slackBotHandle` was seeded from the `clerum.io/slack-bot-label`+ * annotation rather than from `spec.slackSettings` or from typing. Absent+ * means "not from the annotation": a hand-built draft has no annotation+ * history, and anything the operator types clears the flag.+ */+ slackBotHandleFromAnnotation?: booleanslackReplyOnlyWhenMentioned: booleanslackReplyInThreads: booleanslackWorkspaceId: string@@ -56,6 +63,37 @@ export function hasSlackConfig()}+/**+ * Gate for the Slack Request URL and app manifest, and for nothing else.+ *+ * `hasSlackConfig` counts a `slackBotHandle` seeded from the+ * `clerum.io/slack-bot-label` annotation, which is how a Telegram-only channel+ * carrying a stale label rendered a copyable Request URL and a full manifest for+ * a Slack app that does not exist. An annotation is a leftover label, not a+ * declaration that this channel has a Slack provider.+ *+ * Everything else keeps reading `hasSlackConfig`: the annotation still fills the+ * visible App Name field, still decides which tab the edit page opens on, and+ * still reaches the saved spec. Only the copyable URL and the manifest wait for+ * a real Slack provider, whether persisted or typed into the open draft.+ */+export function hasSlackConfigForRequestUrl(+ draft: Pick<+ CommunicationChannelDraftState,+ | 'slack'+ | 'slackBotHandle'+ | 'slackBotHandleFromAnnotation'+ | 'slackReplyInThreads'+ | 'slackReplyOnlyWhenMentioned'+ | 'slackWorkspaceId'+ >+): boolean {+ return hasSlackConfig({+ ...draft,+ slackBotHandle: draft.slackBotHandleFromAnnotation ? '' : draft.slackBotHandle,+ })+}+export function hasTeamsConfig(draft: Pick<CommunicationChannelDraftState,@@ -74,6 +112,8 @@ export function createCommunicationChannelDraft(item: CommunicationChannelItem): CommunicationChannelDraftState {const spec = item.spec || {}+ const slackBotHandleFromSpec = spec.slackSettings?.botHandle || ''+ const slackBotHandleFromLabel = annotationValue(item, ['clerum.io/slack-bot-label'])return {accessTeamIds: spec.access?.teams || [],accessUserIds: spec.access?.users || [],@@ -82,8 +122,8 @@ export function createCommunicationChannelDraft(: {}),hostRef: spec.hostRef || '',slack: spec.slack || [],- slackBotHandle:- spec.slackSettings?.botHandle || annotationValue(item, ['clerum.io/slack-bot-label']),+ slackBotHandle: slackBotHandleFromSpec || slackBotHandleFromLabel,+ slackBotHandleFromAnnotation: !slackBotHandleFromSpec && Boolean(slackBotHandleFromLabel),slackReplyOnlyWhenMentioned: spec.slackSettings?.replyOnlyWhenMentioned === true,slackReplyInThreads: spec.slackSettings?.replyInThreads === true,slackWorkspaceId: spec.slackSettings?.workspaceId || '',diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex 9bf210451..1e14c7564 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.400",+ "version": "0.1.401","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.400",+ "version": "0.1.401","dependencies": {"@clerum/llm-providers": "file:../packages/llm-providers","@clerum/workflow-recipe-capability-policy": "file:../packages/workflow-recipe-capability-policy",diff --git a/control-ui/package.json b/control-ui/package.jsonindex efe1a22e8..ba70147ac 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.400",+ "version": "0.1.401","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",