Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(channel-reader): read the authorization reason without changing behavior
Jose Ramirez4f04c40e9c48
diff --git a/channel-reader/package-lock.json b/channel-reader/package-lock.jsonindex ea3eb03e9..53aba63ff 100644--- a/channel-reader/package-lock.json+++ b/channel-reader/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-channel-reader",- "version": "0.1.84",+ "version": "0.1.85","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-channel-reader",- "version": "0.1.84",+ "version": "0.1.85","license": "SEE LICENSE IN LICENSE","dependencies": {"@kubernetes/client-node": "^1.0.0",diff --git a/channel-reader/package.json b/channel-reader/package.jsonindex bf097085a..58adb366f 100644--- a/channel-reader/package.json+++ b/channel-reader/package.json@@ -1,6 +1,6 @@{"name": "clerum-channel-reader",- "version": "0.1.84",+ "version": "0.1.85","description": "Watches CommunicationChannel CRDs and fetches messages from Telegram, Email, and Slack","main": "dist/main.js","engines": {diff --git a/channel-reader/src/__tests__/main.test.ts b/channel-reader/src/__tests__/main.test.tsindex bb2f52286..c69b13483 100644--- a/channel-reader/src/__tests__/main.test.ts+++ b/channel-reader/src/__tests__/main.test.ts@@ -69,7 +69,7 @@ function telegramMessage(overrides: Partial<Message> = {}): Message {describe('ChannelReader provider event idempotency', () => {it('does not forward a provider message when current access is denied', async () => {const rpc = rpcClient()- rpc.authorizeProviderMessage = vi.fn(async () => false)+ rpc.authorizeProviderMessage = vi.fn(async () => ({ authorized: false }))const reader = new ChannelReader({rpcClient: rpc,notificationDeliveryClient: null,@@ -84,7 +84,10 @@ describe('ChannelReader provider event idempotency', () => {it('records denied provider events so duplicate redelivery does not reauthorize', async () => {const rpc = rpcClient()- rpc.authorizeProviderMessage = vi.fn().mockResolvedValueOnce(false).mockResolvedValueOnce(true)+ rpc.authorizeProviderMessage = vi+ .fn()+ .mockResolvedValueOnce({ authorized: false })+ .mockResolvedValueOnce({ authorized: true })const reader = new ChannelReader({rpcClient: rpc,notificationDeliveryClient: null,diff --git a/channel-reader/src/main.ts b/channel-reader/src/main.tsindex e326297a7..4f9557ee8 100644--- a/channel-reader/src/main.ts+++ b/channel-reader/src/main.ts@@ -1379,18 +1379,17 @@ export class ChannelReader {console.warn(`[Main] Duplicate provider message ignored: ${providerEventKey}`)continue}- if (- msg.providerIdentity &&- this.rpcClient.authorizeProviderMessage &&- !(await this.rpcClient.authorizeProviderMessage(msg.providerIdentity))- ) {- if (providerEventKey) {- this.processedProviderEvents.set(providerEventKey, { seenAt: Date.now() })+ if (msg.providerIdentity && this.rpcClient.authorizeProviderMessage) {+ const authorization = await this.rpcClient.authorizeProviderMessage(msg.providerIdentity)+ if (!authorization.authorized) {+ if (providerEventKey) {+ this.processedProviderEvents.set(providerEventKey, { seenAt: Date.now() })+ }+ console.warn(+ `[Main] Ignoring unauthorized ${msg.channelType} message from ${msg.sender} in ${msg.channelId}`+ )+ continue}- console.warn(- `[Main] Ignoring unauthorized ${msg.channelType} message from ${msg.sender} in ${msg.channelId}`- )- continue}const traceContext = mintChannelTraceContext(msg)diff --git a/channel-reader/src/rpcClient.ts b/channel-reader/src/rpcClient.tsindex 783bee176..f9359fe4a 100644--- a/channel-reader/src/rpcClient.ts+++ b/channel-reader/src/rpcClient.ts@@ -236,7 +236,9 @@ export class RPCClient {}}- async authorizeProviderMessage(identity: ProviderIdentity): Promise<boolean> {+ async authorizeProviderMessage(+ identity: ProviderIdentity+ ): Promise<{ authorized: boolean; reason?: 'unresolved' | 'error' }> {try {const response = await fetch(`${this.baseUrl}/v1/runtime/provider-messages/authorize`, {method: 'POST',@@ -248,15 +250,18 @@ export class RPCClient {}),body: JSON.stringify({ providerIdentity: identity }),})- if (!response.ok) return false- const body = (await response.json()) as { authorized?: unknown }- return body.authorized === true+ if (!response.ok) return { authorized: false }+ const body = (await response.json()) as { authorized?: unknown; reason?: unknown }+ if (body.authorized === true) return { authorized: true }+ return body.reason === 'unresolved' || body.reason === 'error'+ ? { authorized: false, reason: body.reason }+ : { authorized: false }} catch (error) {console.warn('[RPC] Provider message authorization failed closed:',error instanceof Error ? error.message : error)- return false+ return { authorized: false }}}diff --git a/channel-reader/test/rpcClient.test.ts b/channel-reader/test/rpcClient.test.tsindex d0e22a09a..cf7b754c9 100644--- a/channel-reader/test/rpcClient.test.ts+++ b/channel-reader/test/rpcClient.test.ts@@ -382,7 +382,7 @@ describe('RPCClient - provider message authorization', () => {}const client = new RPCClient('http://mcp-host:8080')- await expect(client.authorizeProviderMessage(identity)).resolves.toBe(true)+ await expect(client.authorizeProviderMessage(identity)).resolves.toEqual({ authorized: true })const [url, options] = mockFetch.mock.calls[0] as [string, RequestInit]expect(url).toBe('http://mcp-host:8080/v1/runtime/provider-messages/authorize')diff --git a/channel-reader/test/unresolvedSenderNotice.test.ts b/channel-reader/test/unresolvedSenderNotice.test.tsnew file mode 100644index 000000000..a7d11bbb6--- /dev/null+++ b/channel-reader/test/unresolvedSenderNotice.test.ts@@ -0,0 +1,62 @@+import { describe, expect, it, vi } from 'vitest'+import { RPCClient } from '../src/rpcClient'++const mockCfg = vi.hoisted(() => ({+ hostRef: 'test-host',+}))++vi.mock('../src/config', () => ({+ get config() {+ return mockCfg+ },+}))++describe('authorizeProviderMessage response shape', () => {+ const identity = {+ medium: 'slack' as const,+ providerUserId: 'U1',+ providerWorkspaceId: 'T1',+ providerChannelId: 'C1',+ }++ it('returns the reason from the body when unauthorized', async () => {+ vi.stubGlobal(+ 'fetch',+ vi.fn(async () => new Response(JSON.stringify({ authorized: false, reason: 'unresolved' })))+ )+ const client = new RPCClient('http://mcp-host.test')+ expect(await client.authorizeProviderMessage(identity as never)).toEqual({+ authorized: false,+ reason: 'unresolved',+ })+ })++ it('returns no reason when the response is not ok, so callers stay silent', async () => {+ vi.stubGlobal(+ 'fetch',+ vi.fn(async () => new Response('nope', { status: 503 }))+ )+ const client = new RPCClient('http://mcp-host.test')+ expect(await client.authorizeProviderMessage(identity as never)).toEqual({ authorized: false })+ })++ it('returns no reason when the request throws', async () => {+ vi.stubGlobal(+ 'fetch',+ vi.fn(async () => {+ throw new Error('network down')+ })+ )+ const client = new RPCClient('http://mcp-host.test')+ expect(await client.authorizeProviderMessage(identity as never)).toEqual({ authorized: false })+ })++ it('omits the reason when an older mcp-host returns only authorized', async () => {+ vi.stubGlobal(+ 'fetch',+ vi.fn(async () => new Response(JSON.stringify({ authorized: false })))+ )+ const client = new RPCClient('http://mcp-host.test')+ expect(await client.authorizeProviderMessage(identity as never)).toEqual({ authorized: false })+ })+})