Skip to content

Commit 9bb12c2

Browse files
authored
Advertise auth logout capability (#110)
* Advertise auth logout capability Route logout through unstable ACP auth support while keeping the legacy authentication/logout extension method as a compatibility shim. * Fix test * Add back resolves
1 parent 2b98246 commit 9bb12c2

4 files changed

Lines changed: 30 additions & 7 deletions

File tree

src/CodexAcpClient.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import type {
3535
UserInput,
3636
} from "./app-server/v2";
3737
import packageJson from "../package.json";
38-
import type {AuthenticationLogoutResponse, AuthenticationStatusResponse} from "./AcpExtensions";
38+
import type {AuthenticationStatusResponse} from "./AcpExtensions";
3939

4040
/**
4141
* API for accessing the Codex App Server using ACP requests.
@@ -176,11 +176,10 @@ export class CodexAcpClient {
176176
return settingsModelProvider.config.model_provider;
177177
}
178178

179-
async logout(): Promise<AuthenticationLogoutResponse> {
179+
async logout(): Promise<void> {
180180
const accountUpdatedPromise = this.awaitNextAccountUpdated();
181181
await this.codexClient.accountLogout();
182182
await accountUpdatedPromise;
183-
return {};
184183
}
185184

186185
async authRequired(): Promise<Boolean> {

src/CodexAcpServer.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ export class CodexAcpServer implements acp.Agent {
9696
return {
9797
protocolVersion: acp.PROTOCOL_VERSION,
9898
agentCapabilities: {
99+
auth: {
100+
logout: {},
101+
},
99102
loadSession: true,
100103
promptCapabilities: {
101104
image: true
@@ -121,8 +124,10 @@ export class CodexAcpServer implements acp.Agent {
121124
switch (methodRequest.method) {
122125
case "authentication/status":
123126
return await this.runWithProcessCheck(() => this.codexAcpClient.getAuthenticationStatus());
124-
case "authentication/logout":
125-
return await this.runWithProcessCheck(() => this.codexAcpClient.logout());
127+
case "authentication/logout": {
128+
await this.unstable_logout({});
129+
return {};
130+
}
126131
}
127132
}
128133

@@ -270,6 +275,12 @@ export class CodexAcpServer implements acp.Agent {
270275
return { };
271276
}
272277

278+
async unstable_logout(_params: acp.LogoutRequest): Promise<void> {
279+
logger.log("Logout request received");
280+
await this.runWithProcessCheck(() => this.codexAcpClient.logout());
281+
logger.log("Logout request completed");
282+
}
283+
273284
async setSessionMode(
274285
_params: acp.SetSessionModeRequest,
275286
): Promise<acp.SetSessionModeResponse> {

src/__tests__/CodexACPAgent/CodexAcpClient.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe('ACP server test', { timeout: 40_000 }, () => {
103103
const authenticatedResponse = await keyFixture.getCodexAcpAgent().extMethod("authentication/status", {});
104104
expect(authenticatedResponse).toEqual({type: "api-key"});
105105

106-
await keyFixture.getCodexAcpAgent().extMethod("authentication/logout", {});
106+
await keyFixture.getCodexAcpAgent().unstable_logout({});
107107
const logoutResponse = await keyFixture.getCodexAcpAgent().extMethod("authentication/status", {});
108108
expect(logoutResponse).toEqual({type: "unauthenticated"});
109109
});
@@ -146,6 +146,16 @@ describe('ACP server test', { timeout: 40_000 }, () => {
146146
expect(newSessionResponse.sessionId).toBeDefined()
147147
})
148148

149+
it('supports legacy authentication/logout ext method', async () => {
150+
const mockFixture = createCodexMockTestFixture();
151+
const codexAcpAgent = mockFixture.getCodexAcpAgent();
152+
153+
const logoutSpy = vi.spyOn(codexAcpAgent, "unstable_logout").mockResolvedValue();
154+
155+
await expect(codexAcpAgent.extMethod("authentication/logout", {})).resolves.toEqual({});
156+
expect(logoutSpy).toHaveBeenCalledWith({});
157+
});
158+
149159
it('prefetches session additional skill roots before thread start', async () => {
150160
const mockFixture = createCodexMockTestFixture();
151161
const codexAcpClient = mockFixture.getCodexAcpClient();
@@ -565,7 +575,7 @@ describe('ACP server test', { timeout: 40_000 }, () => {
565575

566576
const sessionState: SessionState = createTestSessionState();
567577

568-
const logoutSpy = vi.spyOn(mockFixture.getCodexAcpClient(), "logout").mockResolvedValue({});
578+
const logoutSpy = vi.spyOn(mockFixture.getCodexAcpClient(), "logout").mockResolvedValue();
569579

570580
// @ts-expect-error - exercising private helper
571581
const handled = await codexAcpAgent.availableCommands.handleCommand({ name: "logout", input: null }, sessionState);

src/__tests__/CodexACPAgent/initialize.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ describe('CodexACPAgent - initialize', () => {
3232
expect(result).toEqual({
3333
protocolVersion: acp.PROTOCOL_VERSION,
3434
agentCapabilities: {
35+
auth: {
36+
logout: {},
37+
},
3538
loadSession: true,
3639
promptCapabilities: {
3740
image: true

0 commit comments

Comments
 (0)