-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathruntime-host.test.ts
More file actions
84 lines (76 loc) · 2.87 KB
/
Copy pathruntime-host.test.ts
File metadata and controls
84 lines (76 loc) · 2.87 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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 = {
agentDisplayName: "OpenTag",
agentUrl: "http://agent.internal",
agentAuthHeader: "Bearer agent-secret",
intelligenceApiKey: "cpk-1_test-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,
__channelEngine: async (_config, declaredChannel) => {
await declaredChannel.ɵruntime.start();
return {
metadata: {},
stop: () => declaredChannel.ɵruntime.stop(),
};
},
});
expect(runtime.mode).toBe("intelligence");
expect(runtime.channels).toEqual(channels);
expect(runtime.learning).toBeUndefined();
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",
},
detail: {
"open-tag": {
provider: "unknown",
status: "online",
transport: "online",
},
},
});
expect(slackAdapter.started).toBe(true);
expect(teamsAdapter.started).toBe(true);
await listener.channels?.stop();
expect(stopSlack).toHaveBeenCalledOnce();
expect(stopTeams).toHaveBeenCalledOnce();
});
it("passes the configured Learning Container to Intelligence Runtime", () => {
const { runtime } = createOpenTagRuntime({
environment: {
...environment,
learningContainerId: "support-quality",
},
channels: [],
});
expect(runtime.learning).toEqual({ containerId: "support-quality" });
});
});