-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathruntime-host.test.ts
More file actions
61 lines (55 loc) · 2.11 KB
/
Copy pathruntime-host.test.ts
File metadata and controls
61 lines (55 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { describe, expect, it, vi } from "vitest";
import { FakeAdapter, FakeAgent } from "@copilotkit/channels";
import { createOpenTagChannel } from "./channel.js";
import type { AppEnvironment } from "./env.js";
import {
OPENTAG_SERVICE_USER,
createOpenTagRuntime,
} from "./runtime-host.js";
const environment: AppEnvironment = {
agentUrl: "http://agent.internal",
agentAuthHeader: "Bearer agent-secret",
intelligenceApiKey: "intelligence-secret",
intelligenceApiUrl: "https://intelligence.example.test",
intelligenceGatewayWsUrl: "wss://gateway.example.test",
channelName: "open-tag",
port: 3000,
};
describe("createOpenTagRuntime", () => {
it("registers the Channel in an Intelligence runtime and Node listener", async () => {
const slackAdapter = new FakeAdapter({ platform: "slack" });
const teamsAdapter = new FakeAdapter({ platform: "teams" });
const stopSlack = vi.spyOn(slackAdapter, "stop");
const stopTeams = vi.spyOn(teamsAdapter, "stop");
const channel = createOpenTagChannel("open-tag", new FakeAgent());
channel.ɵruntime.addAdapter(slackAdapter);
channel.ɵruntime.addAdapter(teamsAdapter);
const channels = [channel];
const { intelligence, listener, runtime } = createOpenTagRuntime({
environment,
channels,
});
expect(runtime.mode).toBe("intelligence");
expect(runtime.channels).toEqual(channels);
expect(intelligence.ɵgetApiUrl()).toBe(environment.intelligenceApiUrl);
expect(intelligence.ɵgetClientWsUrl()).toContain(
"gateway.example.test",
);
expect(
await runtime.identifyUser?.(new Request("http://localhost")),
).toEqual(OPENTAG_SERVICE_USER);
expect(listener.channels).toBeDefined();
await listener.channels?.ready({ timeoutMs: 500 });
expect(listener.channels?.status()).toEqual({
overall: "online",
channels: {
"open-tag": "online",
},
});
expect(slackAdapter.started).toBe(true);
expect(teamsAdapter.started).toBe(true);
await listener.channels?.stop();
expect(stopSlack).toHaveBeenCalledOnce();
expect(stopTeams).toHaveBeenCalledOnce();
});
});