-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathinitialize.test.ts
More file actions
112 lines (102 loc) · 3.86 KB
/
Copy pathinitialize.test.ts
File metadata and controls
112 lines (102 loc) · 3.86 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import { CodexAcpServer } from '../../CodexAcpServer';
import * as acp from '@agentclientprotocol/sdk';
import { createMockConnections } from './test-utils';
import {getCodexAuthMethods} from "../../CodexAuthMethod";
import {CodexAcpClient} from "../../CodexAcpClient";
import {CodexAppServerClient} from "../../CodexAppServerClient";
import packageJson from "../../../package.json";
describe('CodexACPAgent - initialize', () => {
let agent: CodexAcpServer;
let mockAcpConnection: any;
let mockCodexConnection: any;
beforeEach(() => {
const mocks = createMockConnections();
mockAcpConnection = mocks.mockAcpConnection;
mockCodexConnection = mocks.mockCodexConnection;
const codexAppServerClient = new CodexAppServerClient(mockCodexConnection);
const codexAcpClient = new CodexAcpClient(codexAppServerClient);
agent = new CodexAcpServer(mockAcpConnection, codexAcpClient);
});
afterEach(() => {
vi.clearAllMocks();
});
it('should return protocol version and agent capabilities', async () => {
const params: acp.InitializeRequest = {
protocolVersion: acp.PROTOCOL_VERSION
};
const result = await agent.initialize(params);
expect(result).toEqual({
protocolVersion: acp.PROTOCOL_VERSION,
agentInfo: {
name: packageJson.name,
title: "Codex",
version: packageJson.version,
},
agentCapabilities: {
auth: {
logout: {},
},
loadSession: true,
promptCapabilities: {
embeddedContext: true,
image: true
},
sessionCapabilities: {
resume: {},
list: {},
close: {},
delete: {},
additionalDirectories: {},
},
mcpCapabilities: {
acp: false,
http: true,
sse: false,
},
},
authMethods: getCodexAuthMethods(),
});
});
it('should advertise gateway auth when the client opts into gateway auth metadata', async () => {
const params: acp.InitializeRequest = {
protocolVersion: acp.PROTOCOL_VERSION,
clientCapabilities: {
auth: {
_meta: {
gateway: true,
}
}
}
};
const result = await agent.initialize(params);
expect(result.authMethods).toEqual(expect.arrayContaining([
expect.objectContaining({
id: "gateway",
})
]));
});
it('should advertise API key auth with the legacy metadata method', () => {
expect(getCodexAuthMethods()).toEqual(expect.arrayContaining([
expect.objectContaining({
id: "api-key",
_meta: {
"api-key": {
provider: "openai",
},
},
}),
]));
expect(getCodexAuthMethods()).not.toEqual(expect.arrayContaining([
expect.objectContaining({type: "env_var"}),
expect.objectContaining({id: "codex-api-key"}),
expect.objectContaining({id: "openai-api-key"}),
]));
});
it('should not advertise ChatGPT auth when browser auth is disabled', () => {
const methodIds = getCodexAuthMethods(undefined, {NO_BROWSER: "1"} as NodeJS.ProcessEnv)
.map((method) => method.id);
expect(methodIds).not.toContain("chat-gpt");
expect(methodIds).toEqual(expect.arrayContaining(["api-key"]));
});
});