@@ -2,10 +2,9 @@ import type * as acp from "@agentclientprotocol/sdk";
22import fs from "node:fs" ;
33import path from "node:path" ;
44import { afterEach , beforeEach , describe , expect , it } from "vitest" ;
5- import { McpApprovalOptionId , type McpApprovalOptionId as McpApprovalOptionIdValue } from "../../../McpApprovalOptionId" ;
65import { ApprovalOptionId } from "../../../ApprovalOptionId" ;
76import {
8- createAuthenticatedFixture ,
7+ createAuthenticatedFixture , createPermissionResponse ,
98 describeE2E ,
109 expectEndTurn ,
1110 type PermissionResponder ,
@@ -33,18 +32,18 @@ function isMcpPermissionRequest(request: acp.RequestPermissionRequest): boolean
3332 return request . toolCall . kind === "execute" && request . _meta ?. [ "is_mcp_tool_approval" ] === true ;
3433}
3534
36- function createMcpPermissionResponse ( optionId : McpApprovalOptionIdValue | null ) : acp . RequestPermissionResponse {
35+ function createMcpPermissionResponse ( optionId : ApprovalOptionId | null ) : acp . RequestPermissionResponse {
3736 if ( optionId === null ) {
3837 return { outcome : { outcome : "cancelled" } } ;
3938 }
4039 return { outcome : { outcome : "selected" , optionId} } ;
4140}
4241
43- function createMcpPermissionResponder ( ...optionIds : McpApprovalOptionIdValue [ ] ) : PermissionResponder {
42+ function createMcpPermissionResponder ( ...optionIds : ApprovalOptionId [ ] ) : PermissionResponder {
4443 const queue = [ ...optionIds ] ;
4544 return ( request ) => createMcpPermissionResponse (
4645 isMcpPermissionRequest ( request )
47- ? queue . shift ( ) ?? McpApprovalOptionId . Decline
46+ ? queue . shift ( ) ?? ApprovalOptionId . RejectOnce
4847 : null ,
4948 ) ;
5049}
@@ -89,7 +88,7 @@ describeE2E("E2E MCP approval tests (configured in session)", () => {
8988 }
9089
9190 it ( "executes an approved MCP tool call" , async ( ) => {
92- fixture . setPermissionResponder ( createMcpPermissionResponder ( McpApprovalOptionId . AllowOnce ) ) ;
91+ fixture . setPermissionResponder ( createMcpPermissionResponder ( ApprovalOptionId . AllowOnce ) ) ;
9392 const { sessionId, invocationMarkerPath} = await createMcpSession ( ) ;
9493
9594 await expectEchoToolReply ( fixture , sessionId , MCP_ECHO_MESSAGE ) ;
@@ -98,7 +97,7 @@ describeE2E("E2E MCP approval tests (configured in session)", () => {
9897 } ) ;
9998
10099 it ( "ends turn when MCP tool call is rejected" , async ( ) => {
101- fixture . setPermissionResponder ( createMcpPermissionResponder ( McpApprovalOptionId . Decline ) ) ;
100+ fixture . setPermissionResponder ( createMcpPermissionResponder ( ApprovalOptionId . RejectOnce ) ) ;
102101 const { sessionId, invocationMarkerPath} = await createMcpSession ( ) ;
103102
104103 expectEndTurn ( await fixture . connection . prompt ( {
@@ -113,7 +112,7 @@ describeE2E("E2E MCP approval tests (configured in session)", () => {
113112 } ) ;
114113
115114 it ( "skips subsequent approvals in the same session when allow_session is selected" , async ( ) => {
116- fixture . setPermissionResponder ( createMcpPermissionResponder ( McpApprovalOptionId . AllowSession ) ) ;
115+ fixture . setPermissionResponder ( createMcpPermissionResponder ( ApprovalOptionId . AllowForSession ) ) ;
117116 const { sessionId, invocationMarkerPath} = await createMcpSession ( ) ;
118117
119118 await expectEchoToolReply ( fixture , sessionId , "session approval first" ) ;
@@ -124,7 +123,7 @@ describeE2E("E2E MCP approval tests (configured in session)", () => {
124123 } ) ;
125124
126125 it ( "requests subsequent approvals after session restart when allow_session is selected" , async ( ) => {
127- fixture . setPermissionResponder ( createMcpPermissionResponder ( McpApprovalOptionId . AllowSession , McpApprovalOptionId . AllowOnce ) ) ;
126+ fixture . setPermissionResponder ( createMcpPermissionResponder ( ApprovalOptionId . AllowForSession , ApprovalOptionId . AllowOnce ) ) ;
128127 const { sessionId, invocationMarkerPath} = await createMcpSession ( ) ;
129128
130129 await expectEchoToolReply ( fixture , sessionId , MCP_ECHO_MESSAGE ) ;
@@ -162,9 +161,10 @@ describeE2E("E2E MCP approval tests (configured in toml)", () => {
162161 fixture = await createAuthenticatedFixture ( undefined , [ createMcpServer ( invocationMarkerPath ) ] ) ;
163162 } ) ;
164163
164+ //TODO: recheck allow_always == persist?
165165 it ( "skips subsequent approvals in the same session when allow_always is selected" , async ( ) => {
166166 fixture . setPermissionResponder (
167- createMcpPermissionResponder ( McpApprovalOptionId . AllowAlways ) ,
167+ createMcpPermissionResponder ( ApprovalOptionId . AllowPersist ) ,
168168 ) ;
169169 const sessionId = ( await fixture . createSession ( ) ) . sessionId ;
170170
@@ -177,7 +177,7 @@ describeE2E("E2E MCP approval tests (configured in toml)", () => {
177177
178178 it . skip ( "skips subsequent approvals after session restart when allow_always is selected" , async ( ) => {
179179 fixture . setPermissionResponder (
180- createMcpPermissionResponder ( McpApprovalOptionId . AllowAlways ) ,
180+ createMcpPermissionResponder ( ApprovalOptionId . AllowPersist ) ,
181181 ) ;
182182 const firstSessionId = ( await fixture . createSession ( ) ) . sessionId ;
183183
@@ -200,15 +200,14 @@ describeE2E("E2E MCP approval tests (configured in toml)", () => {
200200 describe ( "persisted approvals" , ( ) => {
201201 let beforeRestartFixture : SpawnedAgentFixture | null = null ;
202202 let afterRestartFixture : SpawnedAgentFixture | null = null ;
203+ let sessionId : string ;
203204
204205 beforeEach ( async ( ) => {
205206 // The outer beforeEach already created `fixture` without a config-backed MCP server.
206207 // Persistence tests need the server in config.toml so Codex offers "Always allow",
207208 // so dispose that fixture and replace it with a config-backed one.
208209 await fixture . dispose ( ) ;
209- beforeRestartFixture = await createAuthenticatedFixture ( {
210- configBackedMcpServers : [ createMcpServer ( ) ] ,
211- } ) ;
210+ beforeRestartFixture = await createAuthenticatedFixture ( undefined , [ createMcpServer ( invocationMarkerPath ) ] ) ;
212211 fixture = beforeRestartFixture ;
213212 sessionId = ( await fixture . createSession ( ) ) . sessionId ;
214213 } ) ;
0 commit comments