Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix: five PR #354 review fixes for Teams channel setup UX

Jose Ramirez985daf97fe4d
diff --git a/channel-reader/package-lock.json b/channel-reader/package-lock.json
index 7b8443206..2a210ef10 100644
--- a/channel-reader/package-lock.json
+++ b/channel-reader/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-channel-reader",
- "version": "0.1.99",
+ "version": "0.1.100",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-channel-reader",
- "version": "0.1.99",
+ "version": "0.1.100",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@kubernetes/client-node": "^1.0.0",
diff --git a/channel-reader/package.json b/channel-reader/package.json
index 58083e932..641e0db93 100644
--- a/channel-reader/package.json
+++ b/channel-reader/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-channel-reader",
- "version": "0.1.99",
+ "version": "0.1.100",
"description": "Watches CommunicationChannel CRDs and fetches messages from Telegram, Email, and Slack",
"main": "dist/main.js",
"engines": {
diff --git a/channel-reader/src/__tests__/progressFormatter.test.ts b/channel-reader/src/__tests__/progressFormatter.test.ts
deleted file mode 100644
index b79e35e6b..000000000
--- a/channel-reader/src/__tests__/progressFormatter.test.ts
+++ /dev/null
@@ -1,89 +0,0 @@
-import { describe, expect, it } from 'vitest'
-import { formatFinalMessage, formatProgressUpdate } from '../progressFormatter'
-import type { ProgressStep } from '../types'
-
-const step = (overrides: Partial<ProgressStep> = {}): ProgressStep => ({
- toolCallId: 'c1',
- toolName: 'mongodb-server__find',
- displayName: 'Mongodb-server',
- intentSummary: 'Using Mongodb-server...',
- iteration: 0,
- stepIndex: 0,
- totalSteps: 1,
- state: 'completed',
- durationMs: 340,
- ...overrides,
-})
-
-describe('formatProgressUpdate', () => {
- it('shows running step with spinner', () => {
- const result = formatProgressUpdate([step({ state: 'running', durationMs: undefined })])
- expect(result).toContain('Processing')
- expect(result).toContain('●')
- expect(result).toContain('running...')
- })
-
- it('shows completed step with checkmark and duration', () => {
- const result = formatProgressUpdate([step()])
- expect(result).toContain('✓')
- expect(result).toContain('Mongodb-server')
- expect(result).toContain('find')
- expect(result).toContain('340ms')
- })
-
- it('shows error step with cross', () => {
- const result = formatProgressUpdate([step({ state: 'error', errorSummary: 'HTTP 404' })])
- expect(result).toContain('✗')
- expect(result).toContain('unavailable (not found).')
- expect(result).not.toContain('HTTP 404')
- })
-
- it('shows iteration divider when iteration changes', () => {
- const steps = [step({ iteration: 0 }), step({ toolCallId: 'c2', iteration: 1, stepIndex: 0 })]
- const result = formatProgressUpdate(steps)
- expect(result).toContain('Thinking further')
- })
-
- it('shows tool function name for MCP tools', () => {
- const result = formatProgressUpdate([step()])
- expect(result).toContain('find')
- })
-
- it('shows tool name for native tools with shared display name', () => {
- const result = formatProgressUpdate([step({ toolName: 'memory_read', displayName: 'Memory' })])
- expect(result).toContain('memory_read')
- })
-})
-
-describe('formatFinalMessage', () => {
- it('prefixes response with compact summary', () => {
- const steps = [
- step(),
- step({
- toolCallId: 'c2',
- toolName: 'mongodb-server__aggregate',
- stepIndex: 1,
- totalSteps: 2,
- }),
- ]
- const result = formatFinalMessage(steps, 'Here is your data.')
- expect(result).toContain('✓ 2 tools used')
- expect(result).toContain('Here is your data.')
- })
-
- it('returns just the response for zero-tool tasks', () => {
- const result = formatFinalMessage([], 'Just a text response.')
- expect(result).toBe('Just a text response.')
- })
-
- it('shows warning icon when errors occurred', () => {
- const result = formatFinalMessage([step({ state: 'error' })], 'Partial response.')
- expect(result).toContain('⚠')
- })
-
- it('truncates summary if total exceeds 4096 chars', () => {
- const longResponse = 'A'.repeat(4090)
- const result = formatFinalMessage([step()], longResponse)
- expect(result.length).toBeLessThanOrEqual(4096)
- })
-})
diff --git a/channel-reader/src/main.ts b/channel-reader/src/main.ts
index 01b04cd98..5ae35a2ac 100644
--- a/channel-reader/src/main.ts
+++ b/channel-reader/src/main.ts
@@ -115,6 +115,13 @@ const UNRESOLVED_NOTICE_COPY_TELEGRAM =
* into a flooder. Exported so tests assert against the real value.
*/
export const UNRESOLVED_NOTICE_GLOBAL_CAP = 50
+/**
+ * Limiter key prefix for a provider identity with no workspace/tenant scope.
+ * Only Telegram ever reaches this: Slack and Teams identities always carry a
+ * real workspaceId (sendUnresolvedSenderNotice returns early otherwise), so
+ * this literal can never collide with an actual workspace or tenant id.
+ */
+const UNRESOLVED_NOTICE_NO_WORKSPACE_KEY = 'no-workspace'
const SLACK_VERIFICATION_SCAN_INTERVAL_MS = 60 * 1000
const TOOL_APPROVAL_ACTION_RE = /^tool:([ald]):([A-Za-z0-9_-]{16})$/
/**
@@ -301,6 +308,13 @@ export class ChannelReader {
private processedProviderEvents: Map<string, ProcessedProviderEvent> = new Map()
/** Unresolved-sender notices already sent, keyed by workspace + user + channel. */
private unresolvedNoticesSent: Map<string, { seenAt: number }> = new Map()
+ /**
+ * Whether the global-cap warning below has already logged for the current
+ * capped episode. Reset to false once cleanupStaleApprovals' TTL sweep drains
+ * unresolvedNoticesSent back under UNRESOLVED_NOTICE_GLOBAL_CAP, so a later
+ * trip into the cap logs again instead of staying silent forever.
+ */
+ private unresolvedNoticeCapLogged = false
/** Adapter route key by provider + CommunicationChannel ref. */
private adapterKeysByCommunicationChannel: Map<string, string> = new Map()
/** Adapter route key by provider + runtime channel id. */
@@ -1590,16 +1604,22 @@ export class ChannelReader {
// does. The SEND still targets msg.channelId, which is what replyChannelId hands
// every other outbound Slack call; only the dedupe identity is provider-scoped.
const conversationId = identity?.providerChannelId?.trim() || channelId
- const key = `${workspaceId}:${userId}:${conversationId}`
+ const key = `${workspaceId ?? UNRESOLVED_NOTICE_NO_WORKSPACE_KEY}:${userId}:${conversationId}`
if (this.unresolvedNoticesSent.has(key)) return
if (this.unresolvedNoticesSent.size >= UNRESOLVED_NOTICE_GLOBAL_CAP) {
- // Not deduplicated on purpose: a repeated line is the signal that this is
- // an ongoing condition, not a one-off, while every provider goes silent
- // for unresolved senders until the TTL sweep frees a slot.
- console.warn(
- `[Main] Unresolved-sender notice cap (${UNRESOLVED_NOTICE_GLOBAL_CAP}) reached; ` +
- `suppressing notice to ${userId} in ${channelId}.`
- )
+ // Log only on the transition into the capped state, not on every blocked
+ // send: at the cap, every inbound message from every unresolved sender
+ // across every provider would otherwise emit its own warning, which is
+ // loudest in exactly the misconfiguration this cap exists to contain.
+ // unresolvedNoticeCapLogged resets once cleanupStaleApprovals' TTL sweep
+ // drains the map back under the cap, so a later trip logs again.
+ if (!this.unresolvedNoticeCapLogged) {
+ this.unresolvedNoticeCapLogged = true
+ console.warn(
+ `[Main] Unresolved-sender notice cap (${UNRESOLVED_NOTICE_GLOBAL_CAP}) reached; ` +
+ `suppressing further notices until the TTL sweep frees a slot.`
+ )
+ }
return
}
// Record on ATTEMPT, not on success: a conversation Slack keeps rejecting
@@ -2268,6 +2288,11 @@ export class ChannelReader {
this.unresolvedNoticesSent.delete(key)
}
}
+ // A later trip into the cap must warn again, so once eviction above drains
+ // the map back under it, allow the next crossing to log.
+ if (this.unresolvedNoticesSent.size < UNRESOLVED_NOTICE_GLOBAL_CAP) {
+ this.unresolvedNoticeCapLogged = false
+ }
}
/**
diff --git a/channel-reader/src/progressFormatter.ts b/channel-reader/src/progressFormatter.ts
index 3007643f9..53aeb4dbc 100644
--- a/channel-reader/src/progressFormatter.ts
+++ b/channel-reader/src/progressFormatter.ts
@@ -36,6 +36,17 @@ export function describeToolError(errorSummary: string | undefined): string {
if (/timed out|timeout|etimedout|deadline/.test(raw)) return 'unavailable (timed out).'
if (/rate limit|429|too many requests/.test(raw)) return 'unavailable (rate limited).'
if (/not found|404|no such/.test(raw)) return 'unavailable (not found).'
+ // Checked before the invalid-input category below: when a message carries
+ // both a size-limit signal and generic "invalid" wording (e.g. "invalid
+ // request, payload too large"), the size limit is the more specific and
+ // more useful diagnosis, so it must win deterministically.
+ if (/too large|\b413\b/.test(raw)) return 'unavailable (too large).'
+ // Anchored on whole words so this does not fire on "invalidated" (bare
+ // "invalid"), the same way the authentication check above must not fire on
+ // "author".
+ if (/\binvalid\b|\bmalformed\b|\bbad request\b|\b400\b/.test(raw)) {
+ return 'unavailable (invalid input).'
+ }
return 'unavailable.'
}
diff --git a/channel-reader/test/progressFormatter.test.ts b/channel-reader/test/progressFormatter.test.ts
index f50117e01..50b98b0e2 100644
--- a/channel-reader/test/progressFormatter.test.ts
+++ b/channel-reader/test/progressFormatter.test.ts
@@ -1,5 +1,10 @@
import { describe, expect, it } from 'vitest'
-import { describeToolError } from '../src/progressFormatter'
+import {
+ describeToolError,
+ formatFinalMessage,
+ formatProgressUpdate,
+} from '../src/progressFormatter'
+import type { ProgressStep } from '../src/types'
describe('describeToolError', () => {
it('classifies an authentication failure without leaking the envelope', () => {
@@ -26,6 +31,51 @@ describe('describeToolError', () => {
expect(describeToolError('request timed out after 4031ms')).toBe('unavailable (timed out).')
})
+ it('classifies a payload-too-large failure', () => {
+ expect(describeToolError('Error: request payload too large')).toBe('unavailable (too large).')
+ })
+
+ it('classifies an HTTP 413 as too large', () => {
+ expect(describeToolError('HTTP/1.1 413 Payload Too Large')).toBe('unavailable (too large).')
+ })
+
+ it('does not misclassify a duration containing 413 as too large', () => {
+ // Bare `413` matched inside "4132ms"; \b413\b must not.
+ expect(describeToolError('operation finished in 4132ms')).toBe('unavailable.')
+ })
+
+ it('does not misclassify "a large number of results" as too large', () => {
+ // The literal phrase "too large" is required; a bare "large" must not match.
+ expect(describeToolError('search returned a large number of matches')).toBe('unavailable.')
+ })
+
+ it('classifies an invalid-argument failure', () => {
+ expect(describeToolError('Invalid argument: field "id" is required')).toBe(
+ 'unavailable (invalid input).'
+ )
+ })
+
+ it('classifies a malformed-input failure', () => {
+ expect(describeToolError('malformed JSON in request body')).toBe('unavailable (invalid input).')
+ })
+
+ it('does not misclassify "invalidated" as invalid input', () => {
+ // Bare `invalid` matched inside "invalidated"; \binvalid\b must not.
+ expect(describeToolError('session invalidated, please retry')).toBe('unavailable.')
+ })
+
+ it('classifies a message matching both new categories as the more specific one, deterministically', () => {
+ // "invalid" and "too large" both appear here; too large is checked first
+ // because it is the more specific diagnosis, so it must win every time.
+ expect(describeToolError('invalid request: payload too large (413)')).toBe(
+ 'unavailable (too large).'
+ )
+ })
+
+ it('classifies a rate limit', () => {
+ expect(describeToolError('429 Too Many Requests')).toBe('unavailable (rate limited).')
+ })
+
it('falls back to generic for anything unrecognised', () => {
expect(describeToolError('kaboom {"secret":"hunter2"}')).toBe('unavailable.')
})
@@ -34,3 +84,89 @@ describe('describeToolError', () => {
expect(describeToolError(undefined)).toBe('unavailable.')
})
})
+
+const step = (overrides: Partial<ProgressStep> = {}): ProgressStep => ({
+ toolCallId: 'c1',
+ toolName: 'mongodb-server__find',
+ displayName: 'Mongodb-server',
+ intentSummary: 'Using Mongodb-server...',
+ iteration: 0,
+ stepIndex: 0,
+ totalSteps: 1,
+ state: 'completed',
+ durationMs: 340,
+ ...overrides,
+})
+
+describe('formatProgressUpdate', () => {
+ it('shows running step with spinner', () => {
+ const result = formatProgressUpdate([step({ state: 'running', durationMs: undefined })])
+ expect(result).toContain('Processing')
+ expect(result).toContain('●')
+ expect(result).toContain('running...')
+ })
+
+ it('shows completed step with checkmark and duration', () => {
+ const result = formatProgressUpdate([step()])
+ expect(result).toContain('✓')
+ expect(result).toContain('Mongodb-server')
+ expect(result).toContain('find')
+ expect(result).toContain('340ms')
+ })
+
+ it('shows error step with cross', () => {
+ const result = formatProgressUpdate([step({ state: 'error', errorSummary: 'HTTP 404' })])
+ expect(result).toContain('✗')
+ expect(result).toContain('unavailable (not found).')
+ expect(result).not.toContain('HTTP 404')
+ })
+
+ it('shows iteration divider when iteration changes', () => {
+ const steps = [step({ iteration: 0 }), step({ toolCallId: 'c2', iteration: 1, stepIndex: 0 })]
+ const result = formatProgressUpdate(steps)
+ expect(result).toContain('Thinking further')
+ })
+
+ it('shows tool function name for MCP tools', () => {
+ const result = formatProgressUpdate([step()])
+ expect(result).toContain('find')
+ })
+
+ it('shows tool name for native tools with shared display name', () => {
+ const result = formatProgressUpdate([step({ toolName: 'memory_read', displayName: 'Memory' })])
+ expect(result).toContain('memory_read')
+ })
+})
+
+describe('formatFinalMessage', () => {
+ it('prefixes response with compact summary', () => {
+ const steps = [
+ step(),
+ step({
+ toolCallId: 'c2',
+ toolName: 'mongodb-server__aggregate',
+ stepIndex: 1,
+ totalSteps: 2,
+ }),
+ ]
+ const result = formatFinalMessage(steps, 'Here is your data.')
+ expect(result).toContain('✓ 2 tools used')
+ expect(result).toContain('Here is your data.')
+ })
+
+ it('returns just the response for zero-tool tasks', () => {
+ const result = formatFinalMessage([], 'Just a text response.')
+ expect(result).toBe('Just a text response.')
+ })
+
+ it('shows warning icon when errors occurred', () => {
+ const result = formatFinalMessage([step({ state: 'error' })], 'Partial response.')
+ expect(result).toContain('⚠')
+ })
+
+ it('truncates summary if total exceeds 4096 chars', () => {
+ const longResponse = 'A'.repeat(4090)
+ const result = formatFinalMessage([step()], longResponse)
+ expect(result.length).toBeLessThanOrEqual(4096)
+ })
+})
diff --git a/channel-reader/test/unresolvedSenderNotice.test.ts b/channel-reader/test/unresolvedSenderNotice.test.ts
index 13da1b897..d103d4699 100644
--- a/channel-reader/test/unresolvedSenderNotice.test.ts
+++ b/channel-reader/test/unresolvedSenderNotice.test.ts
@@ -477,7 +477,11 @@ describe('unresolved notice global cap', () => {
expect(sendMessage).toHaveBeenCalledTimes(UNRESOLVED_NOTICE_GLOBAL_CAP)
})
- it('warns once per blocked send once the cap is reached, without deduplicating', async () => {
+ it('warns exactly once for the transition into the capped state, not once per blocked send', async () => {
+ // A prior ruling had this NOT deduplicate, on the theory that a repeated
+ // line is the signal. That was wrong: at the cap, one warning per inbound
+ // message from every unresolved sender across every provider is loudest in
+ // exactly the misconfiguration the cap exists to contain.
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined)
const { deliverBatch, buildMessage } = buildReader({ medium: 'teams' })
@@ -489,13 +493,42 @@ describe('unresolved notice global cap', () => {
const capWarnings = warnSpy.mock.calls.filter(call =>
String(call[0]).includes('Unresolved-sender notice cap')
)
- // One line per blocked send (5 excess messages), not one line total: a
- // repeated line is the signal that this is an ongoing condition.
- expect(capWarnings).toHaveLength(5)
+ expect(capWarnings).toHaveLength(1)
expect(String(capWarnings[0][0])).toContain(String(UNRESOLVED_NOTICE_GLOBAL_CAP))
warnSpy.mockRestore()
})
+
+ it('warns again on a later trip into the cap, once the TTL sweep drains records below it', async () => {
+ vi.useFakeTimers()
+ const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined)
+ const { deliverBatch, buildMessage, runSweep } = buildReader({ medium: 'teams' })
+
+ const firstBatch = Array.from({ length: UNRESOLVED_NOTICE_GLOBAL_CAP + 5 }, (_, i) =>
+ buildMessage('C1', `U${i}`, 'T1')
+ )
+ await deliverBatch(firstBatch)
+
+ // Past UNRESOLVED_NOTICE_TTL_MS (24h): the sweep evicts every record from the
+ // first batch, dropping the map back under the cap.
+ await vi.advanceTimersByTimeAsync(25 * 60 * 60 * 1000)
+ runSweep()
+
+ const secondBatch = Array.from({ length: UNRESOLVED_NOTICE_GLOBAL_CAP + 5 }, (_, i) =>
+ buildMessage('C1', `V${i}`, 'T1')
+ )
+ await deliverBatch(secondBatch)
+
+ const capWarnings = warnSpy.mock.calls.filter(call =>
+ String(call[0]).includes('Unresolved-sender notice cap')
+ )
+ // One for the first trip into the cap, one for the second: still not one
+ // per blocked send within either batch.
+ expect(capWarnings).toHaveLength(2)
+
+ warnSpy.mockRestore()
+ vi.useRealTimers()
+ })
})
describe('unresolved notice link', () => {
diff --git a/control-ui/app/communication-channels/[name]/edit/page.tsx b/control-ui/app/communication-channels/[name]/edit/page.tsx
index a48480d3f..c4825dac2 100644
--- a/control-ui/app/communication-channels/[name]/edit/page.tsx
+++ b/control-ui/app/communication-channels/[name]/edit/page.tsx
@@ -47,6 +47,7 @@ import {
buildTeamsAppCreateCommand,
canGenerateTeamsCommand,
isValidTeamsBotName,
+ toTeamsBotNameInput,
} from '@lib/teamsSetup'
type ChannelProvider = CommunicationChannelProvider
@@ -301,6 +302,16 @@ export default function EditCommunicationChannelPage() {
async function handleSave(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault()
if (!draft || saving) return
+ // buildCommunicationChannelSpec writes teamsAppName into spec.teamsSettings.appName
+ // whenever it is non-empty, regardless of which provider tab is active, so an
+ // invalid value typed on the Teams tab must block Save here rather than only
+ // gating the Teams-tab Copy button (which a user editing another tab never sees).
+ if (draft.teamsAppName.trim() && !isValidTeamsBotName(draft.teamsAppName)) {
+ setSaveError(
+ 'Teams bot name must start with a letter and use lowercase letters, numbers, and hyphens.'
+ )
+ return
+ }
await persistDraft(draft, `Communication channel ${name} updated.`)
backToChannels()
}
@@ -695,14 +706,14 @@ export default function EditCommunicationChannelPage() {
current
? {
...current,
- teamsAppName: event.target.value,
+ teamsAppName: toTeamsBotNameInput(event.target.value),
// Typed, so no longer just an inherited label.
teamsAppNameFromAnnotation: false,
}
: current
)
}
- placeholder="Your Teams Bot"
+ placeholder="evenfire-bot"
disabled={saving}
autoComplete="off"
/>
diff --git a/control-ui/app/communication-channels/new/page.tsx b/control-ui/app/communication-channels/new/page.tsx
index 54d086fd4..b1226ada7 100644
--- a/control-ui/app/communication-channels/new/page.tsx
+++ b/control-ui/app/communication-channels/new/page.tsx
@@ -40,6 +40,7 @@ import {
buildTeamsAppCreateCommand,
canGenerateTeamsCommand,
isValidTeamsBotName,
+ toTeamsBotNameInput,
} from '@lib/teamsSetup'
type HostItem = {
@@ -100,10 +101,6 @@ function credentialLabel(key: keyof CredentialDraft): string {
}
}
-function toTeamsBotNameInput(value: string): string {
- return toKebabInput(value).slice(0, 64)
-}
-
function providerSettings(provider: ChannelProvider, draft: DraftState) {
if (provider === 'telegram') {
return {
diff --git a/control-ui/components/__tests__/EditCommunicationChannelPage.test.tsx b/control-ui/components/__tests__/EditCommunicationChannelPage.test.tsx
index a7f4365b1..dbcfa84ef 100644
--- a/control-ui/components/__tests__/EditCommunicationChannelPage.test.tsx
+++ b/control-ui/components/__tests__/EditCommunicationChannelPage.test.tsx
@@ -704,3 +704,77 @@ describe('EditCommunicationChannelPage Teams setup command', () => {
expect(screen.queryByText(/no public webhook origin/)).not.toBeInTheDocument()
})
})
+
+/**
+ * The create page normalizes the Name field through toTeamsBotNameInput on
+ * every keystroke and blocks submit on isValidTeamsBotName. This page used to
+ * write event.target.value raw and never validated the field on Save, so a
+ * value Create would have rejected -- e.g. one with a space, or one that
+ * starts with a digit, which toTeamsBotNameInput's kebab-casing does not fix
+ * -- persisted straight to spec.teamsSettings.appName.
+ */
+describe('EditCommunicationChannelPage Teams name validation', () => {
+ it('normalizes the Name field into the Teams CLI shape as the operator types, and offers a valid placeholder', async () => {
+ mockChannel('teams-channel', { teamsSettings: { appName: '' } })
+ await renderLoadedPage()
+
+ const user = userEvent.setup()
+ await user.click(await screen.findByRole('radio', { name: /microsoft teams/i }))
+
+ const nameInput = screen.getByLabelText(/^name$/i) as HTMLInputElement
+ // The old placeholder, "Your Teams Bot", is itself a value the field
+ // should reject: it has spaces and capitals.
+ expect(nameInput.placeholder).toBe('evenfire-bot')
+
+ await user.type(nameInput, 'Evenfire Bot!')
+
+ expect(nameInput).toHaveValue('evenfire-bot')
+ })
+
+ it('blocks Save and does not persist a Teams bot name that is still invalid after normalization', async () => {
+ // Kebab-casing lowercases and strips disallowed characters, but it does not
+ // enforce a leading letter, so a name typed as "123 Bot" survives
+ // normalization as "123-bot" -- non-empty, but still invalid because it
+ // starts with a digit. Save must catch what normalization does not.
+ mockChannel('teams-channel', { teamsSettings: { appName: 'evenfire' } })
+ await renderLoadedPage()
+
+ const user = userEvent.setup()
+ await user.click(await screen.findByRole('radio', { name: /microsoft teams/i }))
+
+ const nameInput = screen.getByLabelText(/^name$/i) as HTMLInputElement
+ await user.clear(nameInput)
+ await user.type(nameInput, '123 Bot')
+ expect(nameInput).toHaveValue('123-bot')
+
+ fireEvent.click(screen.getByRole('button', { name: 'Save changes' }))
+
+ expect(
+ await screen.findByText(
+ 'Teams bot name must start with a letter and use lowercase letters, numbers, and hyphens.'
+ )
+ ).toBeInTheDocument()
+ expect(api.apiSend).not.toHaveBeenCalled()
+ expect(navigation.push).not.toHaveBeenCalled()
+ })
+
+ it('saves a valid Teams bot name typed over the previous value', async () => {
+ mockChannel('teams-channel', { teamsSettings: { appName: 'evenfire' } })
+ await renderLoadedPage()
+
+ const user = userEvent.setup()
+ await user.click(await screen.findByRole('radio', { name: /microsoft teams/i }))
+
+ const nameInput = screen.getByLabelText(/^name$/i) as HTMLInputElement
+ await user.clear(nameInput)
+ await user.type(nameInput, 'evenfire-bot-2')
+
+ fireEvent.click(screen.getByRole('button', { name: 'Save changes' }))
+
+ await waitFor(() => expect(api.apiSend).toHaveBeenCalled())
+ const [, , body] = vi.mocked(api.apiSend).mock.calls[0] as [string, string, { spec: unknown }]
+ expect((body.spec as { teamsSettings: { appName: string } }).teamsSettings.appName).toBe(
+ 'evenfire-bot-2'
+ )
+ })
+})
diff --git a/control-ui/lib/teamsSetup.ts b/control-ui/lib/teamsSetup.ts
index 55a4fd08d..156b9584e 100644
--- a/control-ui/lib/teamsSetup.ts
+++ b/control-ui/lib/teamsSetup.ts
@@ -1,3 +1,5 @@
+import { toKebabInput } from './string'
+
/**
* Placeholder origin shown in guidance copy, and used to build a placeholder
* command, when the deployment has no public webhook address to substitute.
@@ -18,6 +20,17 @@ export function isValidTeamsBotName(value: string): boolean {
return TEAMS_BOT_NAME_RE.test(value.trim())
}
+/**
+ * Normalizes free-typed input into the Teams CLI `--name` shape as the user
+ * types, so the field can never hold something isValidTeamsBotName rejects
+ * except through an empty or in-progress value. Shared by the create and edit
+ * pages so both normalize on the same rule instead of one drifting from the
+ * other -- which is how the edit page persisted a raw, unvalidated name.
+ */
+export function toTeamsBotNameInput(value: string): string {
+ return toKebabInput(value).slice(0, 64)
+}
+
/**
* The Teams CLI needs an absolute endpoint. A deployment with no
* NEXT_PUBLIC_WORKFLOW_APPROVAL_READER_BASE_URL and a hostname that does not
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index ab8072fa4..b44f846e7 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.419",
+ "version": "0.1.420",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.419",
+ "version": "0.1.420",
"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.json
index 99ef197e9..461ffb085 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.419",
+ "version": "0.1.420",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",