Skip to content

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

TypeScript

test(mcp-host): cover handleProviderMessageAuthorization's real catch-block wiring

Jose Ramirez197b231395e0
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index 6447202a1..569d33be4 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.234",
+ "version": "0.1.235",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.234",
+ "version": "0.1.235",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@anthropic-ai/sdk": "^0.32.0",
diff --git a/mcp-host/package.json b/mcp-host/package.json
index 52b75c433..77575d6ee 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.234",
+ "version": "0.1.235",
"description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude",
"main": "dist/main.js",
"engines": {
diff --git a/mcp-host/src/__tests__/providerMessageAuthorization.handler.test.ts b/mcp-host/src/__tests__/providerMessageAuthorization.handler.test.ts
new file mode 100644
index 000000000..bc32340dc
--- /dev/null
+++ b/mcp-host/src/__tests__/providerMessageAuthorization.handler.test.ts
@@ -0,0 +1,48 @@
+import { beforeEach, describe, expect, it, vi } from 'vitest'
+import { WorkflowBrokerRequestError } from '../core/tools/workflowBrokerClient'
+import { handleProviderMessageAuthorization } from '../main'
+import { resolveProviderWorkflowCallerContext } from '../workflow/providerWorkflowCallerContextClient'
+
+vi.mock('../workflow/providerWorkflowCallerContextClient', () => ({
+ resolveProviderWorkflowCallerContext: vi.fn(),
+}))
+
+const providerIdentity = {
+ medium: 'slack' as const,
+ providerUserId: 'U123',
+ providerChannelId: 'C123',
+ providerChannelType: 'im',
+ providerTarget: {
+ hostRef: 'agent-a',
+ communicationChannelNamespace: 'channels',
+ communicationChannelName: 'agent-a-slack',
+ },
+}
+
+describe('handleProviderMessageAuthorization', () => {
+ beforeEach(() => {
+ vi.mocked(resolveProviderWorkflowCallerContext).mockReset()
+ })
+
+ it('classifies a thrown 404 medium_account_not_found as authorized:false, reason:unresolved', async () => {
+ vi.mocked(resolveProviderWorkflowCallerContext).mockRejectedValueOnce(
+ new WorkflowBrokerRequestError(404, 'medium_account_not_found', 'not found')
+ )
+
+ await expect(handleProviderMessageAuthorization({ providerIdentity })).resolves.toEqual({
+ authorized: false,
+ reason: 'unresolved',
+ })
+ })
+
+ it('classifies a thrown 500 as authorized:false, reason:error', async () => {
+ vi.mocked(resolveProviderWorkflowCallerContext).mockRejectedValueOnce(
+ new WorkflowBrokerRequestError(500, null, 'boom')
+ )
+
+ await expect(handleProviderMessageAuthorization({ providerIdentity })).resolves.toEqual({
+ authorized: false,
+ reason: 'error',
+ })
+ })
+})
diff --git a/mcp-host/src/main.ts b/mcp-host/src/main.ts
index f0c09ca0a..0ff552f5e 100644
--- a/mcp-host/src/main.ts
+++ b/mcp-host/src/main.ts
@@ -1809,7 +1809,7 @@ export function classifyAuthorizationFailure(error: unknown): 'unresolved' | 'er
return 'error'
}
-async function handleProviderMessageAuthorization(
+export async function handleProviderMessageAuthorization(
input: ProviderMessageAuthorization
): Promise<{ authorized: boolean; reason?: 'unresolved' | 'error' }> {
const identity = input.providerIdentity