@lobu/gateway 3.0.9 → 3.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/dist/api/platform.d.ts.map +1 -1
  2. package/dist/api/platform.js +7 -26
  3. package/dist/api/platform.js.map +1 -1
  4. package/dist/auth/mcp/proxy.d.ts +14 -0
  5. package/dist/auth/mcp/proxy.d.ts.map +1 -1
  6. package/dist/auth/mcp/proxy.js +149 -13
  7. package/dist/auth/mcp/proxy.js.map +1 -1
  8. package/dist/cli/gateway.d.ts.map +1 -1
  9. package/dist/cli/gateway.js +29 -0
  10. package/dist/cli/gateway.js.map +1 -1
  11. package/dist/connections/chat-instance-manager.d.ts.map +1 -1
  12. package/dist/connections/chat-instance-manager.js +2 -1
  13. package/dist/connections/chat-instance-manager.js.map +1 -1
  14. package/dist/connections/interaction-bridge.d.ts +9 -2
  15. package/dist/connections/interaction-bridge.d.ts.map +1 -1
  16. package/dist/connections/interaction-bridge.js +121 -261
  17. package/dist/connections/interaction-bridge.js.map +1 -1
  18. package/dist/interactions.d.ts +9 -43
  19. package/dist/interactions.d.ts.map +1 -1
  20. package/dist/interactions.js +10 -52
  21. package/dist/interactions.js.map +1 -1
  22. package/dist/routes/public/agent.d.ts +4 -0
  23. package/dist/routes/public/agent.d.ts.map +1 -1
  24. package/dist/routes/public/agent.js +21 -0
  25. package/dist/routes/public/agent.js.map +1 -1
  26. package/dist/services/core-services.d.ts.map +1 -1
  27. package/dist/services/core-services.js +4 -0
  28. package/dist/services/core-services.js.map +1 -1
  29. package/package.json +9 -9
  30. package/src/__tests__/agent-config-routes.test.ts +0 -254
  31. package/src/__tests__/agent-history-routes.test.ts +0 -72
  32. package/src/__tests__/agent-routes.test.ts +0 -68
  33. package/src/__tests__/agent-schedules-routes.test.ts +0 -59
  34. package/src/__tests__/agent-settings-store.test.ts +0 -323
  35. package/src/__tests__/bedrock-model-catalog.test.ts +0 -40
  36. package/src/__tests__/bedrock-openai-service.test.ts +0 -157
  37. package/src/__tests__/bedrock-provider-module.test.ts +0 -56
  38. package/src/__tests__/chat-instance-manager-slack.test.ts +0 -204
  39. package/src/__tests__/chat-response-bridge.test.ts +0 -131
  40. package/src/__tests__/config-memory-plugins.test.ts +0 -92
  41. package/src/__tests__/config-request-store.test.ts +0 -127
  42. package/src/__tests__/connection-routes.test.ts +0 -144
  43. package/src/__tests__/core-services-store-selection.test.ts +0 -92
  44. package/src/__tests__/docker-deployment.test.ts +0 -1211
  45. package/src/__tests__/embedded-deployment.test.ts +0 -342
  46. package/src/__tests__/grant-store.test.ts +0 -148
  47. package/src/__tests__/http-proxy.test.ts +0 -281
  48. package/src/__tests__/instruction-service.test.ts +0 -37
  49. package/src/__tests__/link-buttons.test.ts +0 -112
  50. package/src/__tests__/lobu.test.ts +0 -32
  51. package/src/__tests__/mcp-config-service.test.ts +0 -347
  52. package/src/__tests__/mcp-proxy.test.ts +0 -694
  53. package/src/__tests__/message-handler-bridge.test.ts +0 -17
  54. package/src/__tests__/model-selection.test.ts +0 -172
  55. package/src/__tests__/oauth-templates.test.ts +0 -39
  56. package/src/__tests__/platform-adapter-slack-send.test.ts +0 -114
  57. package/src/__tests__/platform-helpers-model-resolution.test.ts +0 -253
  58. package/src/__tests__/provider-inheritance.test.ts +0 -212
  59. package/src/__tests__/routes/cli-auth.test.ts +0 -337
  60. package/src/__tests__/routes/interactions.test.ts +0 -121
  61. package/src/__tests__/secret-proxy.test.ts +0 -85
  62. package/src/__tests__/session-manager.test.ts +0 -572
  63. package/src/__tests__/setup.ts +0 -133
  64. package/src/__tests__/skill-and-mcp-registry.test.ts +0 -203
  65. package/src/__tests__/slack-routes.test.ts +0 -161
  66. package/src/__tests__/system-config-resolver.test.ts +0 -75
  67. package/src/__tests__/system-message-limiter.test.ts +0 -89
  68. package/src/__tests__/system-skills-service.test.ts +0 -362
  69. package/src/__tests__/transcription-service.test.ts +0 -222
  70. package/src/__tests__/utils/rate-limiter.test.ts +0 -102
  71. package/src/__tests__/worker-connection-manager.test.ts +0 -497
  72. package/src/__tests__/worker-job-router.test.ts +0 -722
  73. package/src/api/index.ts +0 -1
  74. package/src/api/platform.ts +0 -292
  75. package/src/api/response-renderer.ts +0 -157
  76. package/src/auth/agent-metadata-store.ts +0 -168
  77. package/src/auth/api-auth-middleware.ts +0 -69
  78. package/src/auth/api-key-provider-module.ts +0 -213
  79. package/src/auth/base-provider-module.ts +0 -201
  80. package/src/auth/bedrock/provider-module.ts +0 -110
  81. package/src/auth/chatgpt/chatgpt-oauth-module.ts +0 -185
  82. package/src/auth/chatgpt/device-code-client.ts +0 -218
  83. package/src/auth/chatgpt/index.ts +0 -1
  84. package/src/auth/claude/oauth-module.ts +0 -280
  85. package/src/auth/cli/token-service.ts +0 -249
  86. package/src/auth/external/client.ts +0 -560
  87. package/src/auth/external/device-code-client.ts +0 -235
  88. package/src/auth/mcp/config-service.ts +0 -420
  89. package/src/auth/mcp/proxy.ts +0 -1086
  90. package/src/auth/mcp/string-substitution.ts +0 -17
  91. package/src/auth/mcp/tool-cache.ts +0 -90
  92. package/src/auth/oauth/base-client.ts +0 -267
  93. package/src/auth/oauth/client.ts +0 -153
  94. package/src/auth/oauth/credentials.ts +0 -7
  95. package/src/auth/oauth/providers.ts +0 -69
  96. package/src/auth/oauth/state-store.ts +0 -150
  97. package/src/auth/oauth-templates.ts +0 -179
  98. package/src/auth/provider-catalog.ts +0 -220
  99. package/src/auth/provider-model-options.ts +0 -41
  100. package/src/auth/settings/agent-settings-store.ts +0 -565
  101. package/src/auth/settings/auth-profiles-manager.ts +0 -216
  102. package/src/auth/settings/index.ts +0 -12
  103. package/src/auth/settings/model-preference-store.ts +0 -52
  104. package/src/auth/settings/model-selection.ts +0 -135
  105. package/src/auth/settings/resolved-settings-view.ts +0 -298
  106. package/src/auth/settings/template-utils.ts +0 -44
  107. package/src/auth/settings/token-service.ts +0 -88
  108. package/src/auth/system-env-store.ts +0 -98
  109. package/src/auth/user-agents-store.ts +0 -68
  110. package/src/channels/binding-service.ts +0 -214
  111. package/src/channels/index.ts +0 -4
  112. package/src/cli/gateway.ts +0 -1312
  113. package/src/cli/index.ts +0 -74
  114. package/src/commands/built-in-commands.ts +0 -80
  115. package/src/commands/command-dispatcher.ts +0 -94
  116. package/src/commands/command-reply-adapters.ts +0 -27
  117. package/src/config/file-loader.ts +0 -618
  118. package/src/config/index.ts +0 -588
  119. package/src/config/network-allowlist.ts +0 -71
  120. package/src/connections/chat-instance-manager.ts +0 -1284
  121. package/src/connections/chat-response-bridge.ts +0 -618
  122. package/src/connections/index.ts +0 -7
  123. package/src/connections/interaction-bridge.ts +0 -831
  124. package/src/connections/message-handler-bridge.ts +0 -440
  125. package/src/connections/platform-auth-methods.ts +0 -15
  126. package/src/connections/types.ts +0 -84
  127. package/src/gateway/connection-manager.ts +0 -291
  128. package/src/gateway/index.ts +0 -698
  129. package/src/gateway/job-router.ts +0 -201
  130. package/src/gateway-main.ts +0 -200
  131. package/src/index.ts +0 -41
  132. package/src/infrastructure/queue/index.ts +0 -12
  133. package/src/infrastructure/queue/queue-producer.ts +0 -148
  134. package/src/infrastructure/queue/redis-queue.ts +0 -361
  135. package/src/infrastructure/queue/types.ts +0 -133
  136. package/src/infrastructure/redis/system-message-limiter.ts +0 -94
  137. package/src/interactions/config-request-store.ts +0 -198
  138. package/src/interactions.ts +0 -363
  139. package/src/lobu.ts +0 -311
  140. package/src/metrics/prometheus.ts +0 -159
  141. package/src/modules/module-system.ts +0 -179
  142. package/src/orchestration/base-deployment-manager.ts +0 -900
  143. package/src/orchestration/deployment-utils.ts +0 -98
  144. package/src/orchestration/impl/docker-deployment.ts +0 -620
  145. package/src/orchestration/impl/embedded-deployment.ts +0 -268
  146. package/src/orchestration/impl/index.ts +0 -8
  147. package/src/orchestration/impl/k8s/deployment.ts +0 -1061
  148. package/src/orchestration/impl/k8s/helpers.ts +0 -610
  149. package/src/orchestration/impl/k8s/index.ts +0 -1
  150. package/src/orchestration/index.ts +0 -333
  151. package/src/orchestration/message-consumer.ts +0 -584
  152. package/src/orchestration/scheduled-wakeup.ts +0 -704
  153. package/src/permissions/approval-policy.ts +0 -36
  154. package/src/permissions/grant-store.ts +0 -219
  155. package/src/platform/file-handler.ts +0 -66
  156. package/src/platform/link-buttons.ts +0 -57
  157. package/src/platform/renderer-utils.ts +0 -44
  158. package/src/platform/response-renderer.ts +0 -84
  159. package/src/platform/unified-thread-consumer.ts +0 -194
  160. package/src/platform.ts +0 -318
  161. package/src/proxy/http-proxy.ts +0 -752
  162. package/src/proxy/proxy-manager.ts +0 -81
  163. package/src/proxy/secret-proxy.ts +0 -402
  164. package/src/proxy/token-refresh-job.ts +0 -143
  165. package/src/routes/internal/audio.ts +0 -141
  166. package/src/routes/internal/device-auth.ts +0 -652
  167. package/src/routes/internal/files.ts +0 -226
  168. package/src/routes/internal/history.ts +0 -69
  169. package/src/routes/internal/images.ts +0 -127
  170. package/src/routes/internal/interactions.ts +0 -84
  171. package/src/routes/internal/middleware.ts +0 -23
  172. package/src/routes/internal/schedule.ts +0 -226
  173. package/src/routes/internal/types.ts +0 -22
  174. package/src/routes/openapi-auto.ts +0 -239
  175. package/src/routes/public/agent-access.ts +0 -23
  176. package/src/routes/public/agent-config.ts +0 -675
  177. package/src/routes/public/agent-history.ts +0 -422
  178. package/src/routes/public/agent-schedules.ts +0 -296
  179. package/src/routes/public/agent.ts +0 -1086
  180. package/src/routes/public/agents.ts +0 -373
  181. package/src/routes/public/channels.ts +0 -191
  182. package/src/routes/public/cli-auth.ts +0 -896
  183. package/src/routes/public/connections.ts +0 -574
  184. package/src/routes/public/landing.ts +0 -16
  185. package/src/routes/public/oauth.ts +0 -147
  186. package/src/routes/public/settings-auth.ts +0 -104
  187. package/src/routes/public/slack.ts +0 -173
  188. package/src/routes/shared/agent-ownership.ts +0 -101
  189. package/src/routes/shared/token-verifier.ts +0 -34
  190. package/src/services/bedrock-model-catalog.ts +0 -217
  191. package/src/services/bedrock-openai-service.ts +0 -658
  192. package/src/services/core-services.ts +0 -1072
  193. package/src/services/image-generation-service.ts +0 -257
  194. package/src/services/instruction-service.ts +0 -318
  195. package/src/services/mcp-registry.ts +0 -94
  196. package/src/services/platform-helpers.ts +0 -287
  197. package/src/services/session-manager.ts +0 -262
  198. package/src/services/settings-resolver.ts +0 -74
  199. package/src/services/system-config-resolver.ts +0 -89
  200. package/src/services/system-skills-service.ts +0 -229
  201. package/src/services/transcription-service.ts +0 -684
  202. package/src/session.ts +0 -110
  203. package/src/spaces/index.ts +0 -1
  204. package/src/spaces/space-resolver.ts +0 -17
  205. package/src/stores/in-memory-agent-store.ts +0 -403
  206. package/src/stores/redis-agent-store.ts +0 -279
  207. package/src/utils/public-url.ts +0 -44
  208. package/src/utils/rate-limiter.ts +0 -94
  209. package/tsconfig.json +0 -33
  210. package/tsconfig.tsbuildinfo +0 -1
@@ -1,133 +0,0 @@
1
- /**
2
- * Test setup and utilities for Gateway tests.
3
- *
4
- * Shared mocks (Redis, Queue, fetch, factories) live in @lobu/core fixtures.
5
- * This file re-exports them and adds gateway-specific helpers.
6
- */
7
-
8
- import { createMockJob as _createMockJob } from "@lobu/core/testing";
9
-
10
- export {
11
- createInstructionContext,
12
- createMockJob,
13
- createWorkerConfig,
14
- MockMessageQueue,
15
- MockRedisClient,
16
- mockFetch,
17
- } from "@lobu/core/testing";
18
-
19
- /**
20
- * Mock Express Response for SSE testing (gateway-specific)
21
- */
22
- export class MockResponse {
23
- private _ended = false;
24
- private _written: string[] = [];
25
- private _closeCallbacks: (() => void)[] = [];
26
-
27
- write(chunk: string): boolean {
28
- if (this._ended) {
29
- throw new Error("Cannot write to ended response");
30
- }
31
- this._written.push(chunk);
32
- return true;
33
- }
34
-
35
- end(): void {
36
- this._ended = true;
37
- }
38
-
39
- onClose(callback: () => void): void {
40
- this._closeCallbacks.push(callback);
41
- }
42
-
43
- simulateClose(): void {
44
- for (const cb of this._closeCallbacks) cb();
45
- }
46
-
47
- isEnded(): boolean {
48
- return this._ended;
49
- }
50
-
51
- getWritten(): string[] {
52
- return this._written;
53
- }
54
-
55
- getLastWrite(): string | undefined {
56
- return this._written[this._written.length - 1];
57
- }
58
-
59
- getAllWrites(): string {
60
- return this._written.join("");
61
- }
62
-
63
- clearWrites(): void {
64
- this._written = [];
65
- }
66
- }
67
-
68
- /**
69
- * Test utilities
70
- */
71
- export class TestHelpers {
72
- static createMockJob(overrides: any = {}): any {
73
- return _createMockJob(overrides);
74
- }
75
-
76
- static async delay(ms: number): Promise<void> {
77
- return new Promise((resolve) => setTimeout(resolve, ms));
78
- }
79
-
80
- static parseSSE(sse: string): { event: string; data: any }[] {
81
- const events: { event: string; data: any }[] = [];
82
- const lines = sse.split("\n");
83
-
84
- let currentEvent = "";
85
- let currentData = "";
86
-
87
- for (const line of lines) {
88
- if (line.startsWith("event:")) {
89
- currentEvent = line.substring(6).trim();
90
- } else if (line.startsWith("data:")) {
91
- currentData = line.substring(5).trim();
92
- } else if (line === "") {
93
- if (currentEvent && currentData) {
94
- try {
95
- events.push({
96
- event: currentEvent,
97
- data: JSON.parse(currentData),
98
- });
99
- } catch {
100
- events.push({
101
- event: currentEvent,
102
- data: currentData,
103
- });
104
- }
105
- currentEvent = "";
106
- currentData = "";
107
- }
108
- }
109
- }
110
-
111
- return events;
112
- }
113
- }
114
-
115
- /**
116
- * Mock environment variables
117
- */
118
- const mockEnvVars = {
119
- WORKER_STALE_TIMEOUT_MINUTES: "10",
120
- PUBLIC_GATEWAY_URL: "https://test-gateway.example.com",
121
- };
122
-
123
- export function setupTestEnv(): void {
124
- for (const [key, value] of Object.entries(mockEnvVars)) {
125
- process.env[key] = value;
126
- }
127
- }
128
-
129
- export function cleanupTestEnv(): void {
130
- for (const key of Object.keys(mockEnvVars)) {
131
- delete process.env[key];
132
- }
133
- }
@@ -1,203 +0,0 @@
1
- import { describe, expect, test } from "bun:test";
2
- import { McpRegistryService } from "../services/mcp-registry";
3
- import type { SystemConfigResolver } from "../services/system-config-resolver";
4
-
5
- // --- McpRegistryService ---
6
-
7
- function createMockResolver(
8
- entries: Array<{
9
- id: string;
10
- name: string;
11
- description: string;
12
- type: "oauth" | "stdio" | "sse" | "api-key";
13
- config: Record<string, unknown>;
14
- }>
15
- ) {
16
- return {
17
- getMcpRegistryServers: async () => entries,
18
- } as unknown as SystemConfigResolver;
19
- }
20
-
21
- const mcpEntries = [
22
- {
23
- id: "github",
24
- name: "GitHub",
25
- description: "GitHub integration",
26
- type: "stdio" as const,
27
- config: { type: "stdio" },
28
- },
29
- {
30
- id: "sentry",
31
- name: "Sentry",
32
- description: "Error tracking",
33
- type: "sse" as const,
34
- config: { type: "sse" },
35
- },
36
- {
37
- id: "playwright",
38
- name: "Playwright",
39
- description: "Browser automation",
40
- type: "stdio" as const,
41
- config: {},
42
- },
43
- {
44
- id: "notion",
45
- name: "Notion",
46
- description: "Notion workspace",
47
- type: "oauth" as const,
48
- config: {},
49
- },
50
- {
51
- id: "linear",
52
- name: "Linear",
53
- description: "Issue tracker",
54
- type: "api-key" as const,
55
- config: {},
56
- },
57
- {
58
- id: "slack",
59
- name: "Slack",
60
- description: "Slack messaging",
61
- type: "oauth" as const,
62
- config: {},
63
- },
64
- {
65
- id: "jira",
66
- name: "Jira",
67
- description: "Project management",
68
- type: "api-key" as const,
69
- config: {},
70
- },
71
- ];
72
-
73
- describe("McpRegistryService", () => {
74
- test("getCurated returns entries matching curated IDs", async () => {
75
- const service = new McpRegistryService(createMockResolver(mcpEntries));
76
- const curated = await service.getCurated();
77
-
78
- const ids = curated.map((e) => e.id);
79
- for (const curatedId of McpRegistryService.CURATED_MCP_IDS) {
80
- expect(ids).toContain(curatedId);
81
- }
82
- expect(curated).toHaveLength(5);
83
- });
84
-
85
- test("getCurated falls back to first 5 when no curated IDs match", async () => {
86
- const noCuratedEntries = [
87
- {
88
- id: "custom1",
89
- name: "Custom 1",
90
- description: "Desc",
91
- type: "sse" as const,
92
- config: {},
93
- },
94
- {
95
- id: "custom2",
96
- name: "Custom 2",
97
- description: "Desc",
98
- type: "sse" as const,
99
- config: {},
100
- },
101
- {
102
- id: "custom3",
103
- name: "Custom 3",
104
- description: "Desc",
105
- type: "sse" as const,
106
- config: {},
107
- },
108
- {
109
- id: "custom4",
110
- name: "Custom 4",
111
- description: "Desc",
112
- type: "sse" as const,
113
- config: {},
114
- },
115
- {
116
- id: "custom5",
117
- name: "Custom 5",
118
- description: "Desc",
119
- type: "sse" as const,
120
- config: {},
121
- },
122
- {
123
- id: "custom6",
124
- name: "Custom 6",
125
- description: "Desc",
126
- type: "sse" as const,
127
- config: {},
128
- },
129
- ];
130
- const service = new McpRegistryService(
131
- createMockResolver(noCuratedEntries)
132
- );
133
- const curated = await service.getCurated();
134
-
135
- expect(curated).toHaveLength(5);
136
- expect(curated.map((e) => e.id)).toEqual([
137
- "custom1",
138
- "custom2",
139
- "custom3",
140
- "custom4",
141
- "custom5",
142
- ]);
143
- });
144
-
145
- test("search matches by name, description, and id", async () => {
146
- const service = new McpRegistryService(createMockResolver(mcpEntries));
147
-
148
- const byName = await service.search("GitHub");
149
- expect(byName.some((e) => e.id === "github")).toBe(true);
150
-
151
- const byDesc = await service.search("Browser automation");
152
- expect(byDesc.some((e) => e.id === "playwright")).toBe(true);
153
-
154
- const byId = await service.search("linear");
155
- expect(byId.some((e) => e.id === "linear")).toBe(true);
156
- });
157
-
158
- test("search respects limit", async () => {
159
- const service = new McpRegistryService(createMockResolver(mcpEntries));
160
- // "a" appears in many names/descriptions
161
- const results = await service.search("a", 2);
162
- expect(results.length).toBeLessThanOrEqual(2);
163
- });
164
-
165
- test("search with empty query returns all up to limit", async () => {
166
- const service = new McpRegistryService(createMockResolver(mcpEntries));
167
-
168
- const results = await service.search("", 3);
169
- expect(results).toHaveLength(3);
170
-
171
- const allResults = await service.search("");
172
- expect(allResults).toHaveLength(mcpEntries.length);
173
- });
174
-
175
- test("getAll returns complete list", async () => {
176
- const service = new McpRegistryService(createMockResolver(mcpEntries));
177
- const all = await service.getAll();
178
- expect(all).toHaveLength(mcpEntries.length);
179
- });
180
-
181
- test("getById returns specific entry", async () => {
182
- const service = new McpRegistryService(createMockResolver(mcpEntries));
183
-
184
- const entry = await service.getById("sentry");
185
- expect(entry).not.toBeNull();
186
- expect(entry!.name).toBe("Sentry");
187
- });
188
-
189
- test("getById returns null for unknown id", async () => {
190
- const service = new McpRegistryService(createMockResolver(mcpEntries));
191
- const entry = await service.getById("nonexistent");
192
- expect(entry).toBeNull();
193
- });
194
-
195
- test("no resolver returns empty results", async () => {
196
- const service = new McpRegistryService();
197
-
198
- expect(await service.getCurated()).toEqual([]);
199
- expect(await service.search("github")).toEqual([]);
200
- expect(await service.getAll()).toEqual([]);
201
- expect(await service.getById("github")).toBeNull();
202
- });
203
- });
@@ -1,161 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
2
- import { createSlackRoutes } from "../routes/public/slack";
3
-
4
- class RouteRedisMock {
5
- private store = new Map<string, string>();
6
-
7
- async setex(key: string, _ttlSeconds: number, value: string): Promise<void> {
8
- this.store.set(key, value);
9
- }
10
-
11
- async get(key: string): Promise<string | null> {
12
- return this.store.get(key) ?? null;
13
- }
14
-
15
- async getdel(key: string): Promise<string | null> {
16
- const value = this.store.get(key) ?? null;
17
- this.store.delete(key);
18
- return value;
19
- }
20
-
21
- async del(...keys: string[]): Promise<number> {
22
- let removed = 0;
23
- for (const key of keys) {
24
- if (this.store.delete(key)) {
25
- removed++;
26
- }
27
- }
28
- return removed;
29
- }
30
- }
31
-
32
- describe("slack routes", () => {
33
- const originalClientId = process.env.SLACK_CLIENT_ID;
34
- const originalScopes = process.env.SLACK_OAUTH_SCOPES;
35
-
36
- let redis: RouteRedisMock;
37
- let completeSlackOAuthInstall: ReturnType<typeof mock>;
38
- let handleSlackAppWebhook: ReturnType<typeof mock>;
39
- let router: ReturnType<typeof createSlackRoutes>;
40
-
41
- beforeEach(() => {
42
- process.env.SLACK_CLIENT_ID = "client-123";
43
- process.env.SLACK_OAUTH_SCOPES = "chat:write,commands";
44
-
45
- redis = new RouteRedisMock();
46
- completeSlackOAuthInstall = mock(async () => ({
47
- teamId: "T123",
48
- teamName: "Acme",
49
- connectionId: "conn-1",
50
- }));
51
- handleSlackAppWebhook = mock(async (request: Request) => {
52
- const body = await request.text();
53
- return new Response(`handled:${body}`);
54
- });
55
-
56
- router = createSlackRoutes({
57
- getServices: () => ({
58
- getQueue: () => ({
59
- getRedisClient: () => redis,
60
- }),
61
- getPublicGatewayUrl: () => "https://gateway.example.com",
62
- }),
63
- completeSlackOAuthInstall,
64
- handleSlackAppWebhook,
65
- } as any);
66
- });
67
-
68
- afterEach(() => {
69
- if (originalClientId === undefined) {
70
- delete process.env.SLACK_CLIENT_ID;
71
- } else {
72
- process.env.SLACK_CLIENT_ID = originalClientId;
73
- }
74
-
75
- if (originalScopes === undefined) {
76
- delete process.env.SLACK_OAUTH_SCOPES;
77
- } else {
78
- process.env.SLACK_OAUTH_SCOPES = originalScopes;
79
- }
80
- });
81
-
82
- test("GET /slack/install redirects to Slack OAuth and stores state", async () => {
83
- const response = await router.request("/slack/install");
84
-
85
- expect(response.status).toBe(302);
86
-
87
- const location = response.headers.get("location");
88
- expect(location).toBeTruthy();
89
-
90
- const redirectUrl = new URL(location!);
91
- expect(redirectUrl.origin).toBe("https://slack.com");
92
- expect(redirectUrl.pathname).toBe("/oauth/v2/authorize");
93
- expect(redirectUrl.searchParams.get("client_id")).toBe("client-123");
94
- expect(redirectUrl.searchParams.get("scope")).toBe("chat:write,commands");
95
- expect(redirectUrl.searchParams.get("redirect_uri")).toBe(
96
- "https://gateway.example.com/slack/oauth_callback"
97
- );
98
-
99
- const state = redirectUrl.searchParams.get("state");
100
- expect(state).toBeTruthy();
101
-
102
- const rawState = await redis.get(`slack:oauth:state:${state}`);
103
- expect(rawState).toBeTruthy();
104
- expect(JSON.parse(rawState!)).toEqual({
105
- createdAt: expect.any(Number),
106
- redirectUri: "https://gateway.example.com/slack/oauth_callback",
107
- });
108
- });
109
-
110
- test("GET /slack/oauth_callback rejects invalid state", async () => {
111
- const response = await router.request(
112
- "/slack/oauth_callback?code=test-code&state=missing"
113
- );
114
- const body = await response.text();
115
-
116
- expect(response.status).toBe(400);
117
- expect(body).toContain("Authentication Failed");
118
- expect(body).toContain("invalid or has expired");
119
- expect(completeSlackOAuthInstall).not.toHaveBeenCalled();
120
- });
121
-
122
- test("GET /slack/oauth_callback completes install and clears state", async () => {
123
- await redis.setex(
124
- "slack:oauth:state:test-state",
125
- 600,
126
- JSON.stringify({
127
- createdAt: Date.now(),
128
- redirectUri: "https://gateway.example.com/slack/oauth_callback",
129
- })
130
- );
131
-
132
- const response = await router.request(
133
- "/slack/oauth_callback?code=test-code&state=test-state"
134
- );
135
- const body = await response.text();
136
-
137
- expect(response.status).toBe(200);
138
- expect(body).toContain("Slack installed");
139
- expect(body).toContain("Workspace connected to Lobu:");
140
- expect(body).toContain("Connection ID: conn-1");
141
- expect(completeSlackOAuthInstall).toHaveBeenCalledTimes(1);
142
- expect(completeSlackOAuthInstall.mock.calls[0]?.[1]).toBe(
143
- "https://gateway.example.com/slack/oauth_callback"
144
- );
145
- expect(await redis.get("slack:oauth:state:test-state")).toBeNull();
146
- });
147
-
148
- test("POST /slack/events forwards requests to the chat manager", async () => {
149
- const response = await router.request("/slack/events", {
150
- method: "POST",
151
- headers: {
152
- "content-type": "application/json",
153
- },
154
- body: JSON.stringify({ team_id: "T123", type: "event_callback" }),
155
- });
156
-
157
- expect(response.status).toBe(200);
158
- expect(await response.text()).toContain("handled:");
159
- expect(handleSlackAppWebhook).toHaveBeenCalledTimes(1);
160
- });
161
- });
@@ -1,75 +0,0 @@
1
- import { describe, expect, test } from "bun:test";
2
- import type { ProviderConfigEntry, SkillConfig } from "@lobu/core";
3
- import { SystemConfigResolver } from "../services/system-config-resolver";
4
-
5
- class MockSystemSkillsService {
6
- constructor(
7
- private readonly providers: Record<string, ProviderConfigEntry>,
8
- private readonly skills: SkillConfig[]
9
- ) {}
10
-
11
- async getProviderConfigs(): Promise<Record<string, ProviderConfigEntry>> {
12
- return this.providers;
13
- }
14
-
15
- async getSystemSkills(): Promise<SkillConfig[]> {
16
- return this.skills;
17
- }
18
- }
19
-
20
- describe("SystemConfigResolver MCP and provider resolution", () => {
21
- test("builds global MCP server map and registry entries from system skills", async () => {
22
- const resolver = new SystemConfigResolver(
23
- new MockSystemSkillsService(
24
- {
25
- groq: {
26
- displayName: "Groq",
27
- iconUrl: "https://example.com/groq.png",
28
- envVarName: "GROQ_API_KEY",
29
- upstreamBaseUrl: "https://api.groq.com/openai",
30
- apiKeyInstructions: "Get key",
31
- apiKeyPlaceholder: "gsk_...",
32
- },
33
- },
34
- [
35
- {
36
- repo: "system/owletto",
37
- name: "Owletto",
38
- enabled: true,
39
- description: "Memory MCP",
40
- mcpServers: [
41
- {
42
- id: "owletto",
43
- name: "Owletto",
44
- url: "https://owletto.com/mcp",
45
- },
46
- { id: "local-tool", command: "mcp-local", args: ["--stdio"] },
47
- ],
48
- } as SkillConfig,
49
- ]
50
- ) as any
51
- );
52
-
53
- const globalMcp = await resolver.getGlobalMcpServers();
54
- const registryEntries = await resolver.getMcpRegistryServers();
55
- const providers = await resolver.getProviderConfigs();
56
-
57
- expect(globalMcp.owletto).toEqual({
58
- type: "sse",
59
- url: "https://owletto.com/mcp",
60
- });
61
- expect(globalMcp["local-tool"]).toEqual({
62
- type: "stdio",
63
- command: "mcp-local",
64
- args: ["--stdio"],
65
- });
66
-
67
- expect(registryEntries.map((entry) => entry.id)).toEqual([
68
- "owletto",
69
- "local-tool",
70
- ]);
71
- expect(registryEntries[1]?.type).toBe("stdio");
72
-
73
- expect(Object.keys(providers)).toEqual(["groq"]);
74
- });
75
- });
@@ -1,89 +0,0 @@
1
- import { describe, expect, test } from "bun:test";
2
- import { MockRedisClient } from "@lobu/core/testing";
3
- import { SystemMessageLimiter } from "../infrastructure/redis/system-message-limiter";
4
-
5
- describe("SystemMessageLimiter", () => {
6
- test("sends once and suppresses subsequent sends within TTL", async () => {
7
- const redis = new MockRedisClient() as any;
8
- const limiter = new SystemMessageLimiter(redis, "test");
9
-
10
- let sentCount = 0;
11
- const sendFn = async () => {
12
- sentCount += 1;
13
- };
14
-
15
- const first = await limiter.sendOnce("k", sendFn, {
16
- sentTtlSeconds: 60,
17
- lockTtlSeconds: 30,
18
- });
19
- const second = await limiter.sendOnce("k", sendFn, {
20
- sentTtlSeconds: 60,
21
- lockTtlSeconds: 30,
22
- });
23
-
24
- expect(first).toBe(true);
25
- expect(second).toBe(false);
26
- expect(sentCount).toBe(1);
27
- });
28
-
29
- test("suppresses concurrent sends using lock even before sent marker is written", async () => {
30
- const redis = new MockRedisClient() as any;
31
- const limiter = new SystemMessageLimiter(redis, "test");
32
-
33
- let release!: () => void;
34
- const gate = new Promise<void>((resolve) => {
35
- release = resolve;
36
- });
37
-
38
- let started = 0;
39
- const sendFn = async () => {
40
- started += 1;
41
- await gate;
42
- };
43
-
44
- const p1 = limiter.sendOnce("k2", sendFn, {
45
- sentTtlSeconds: 60,
46
- lockTtlSeconds: 30,
47
- });
48
- const p2 = limiter.sendOnce("k2", sendFn, {
49
- sentTtlSeconds: 60,
50
- lockTtlSeconds: 30,
51
- });
52
-
53
- // Ensure both have attempted to run; only one should have entered sendFn.
54
- await new Promise((r) => setTimeout(r, 0));
55
- expect(started).toBe(1);
56
-
57
- release();
58
- const [r1, r2] = await Promise.all([p1, p2]);
59
- expect([r1, r2].filter(Boolean).length).toBe(1);
60
- });
61
-
62
- test("does not set sent marker on failure (allows retry)", async () => {
63
- const redis = new MockRedisClient() as any;
64
- const limiter = new SystemMessageLimiter(redis, "test");
65
-
66
- let attempts = 0;
67
- const sendFn = async () => {
68
- attempts += 1;
69
- throw new Error("fail");
70
- };
71
-
72
- await expect(
73
- limiter.sendOnce("k3", sendFn, {
74
- sentTtlSeconds: 60,
75
- lockTtlSeconds: 30,
76
- })
77
- ).rejects.toThrow("fail");
78
-
79
- // Next call should try again (not suppressed).
80
- await expect(
81
- limiter.sendOnce("k3", sendFn, {
82
- sentTtlSeconds: 60,
83
- lockTtlSeconds: 30,
84
- })
85
- ).rejects.toThrow("fail");
86
-
87
- expect(attempts).toBe(2);
88
- });
89
- });