11// noinspection ES6RedundantAwait
22
3- import { describe , expect , it , vi , beforeEach } from 'vitest' ;
3+ import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest' ;
44import { createTestFixture , type TestFixture } from "../acp-test-utils" ;
55import type { McpServerStdio } from "@agentclientprotocol/sdk" ;
6+ import path from "node:path" ;
7+ import fs from "node:fs" ;
8+ import os from "node:os" ;
69
710describe ( 'MCP session configuration' , { timeout : 40_000 } , ( ) => {
811
912 let fixture : TestFixture ;
13+ let testHomeDir : string ;
14+ let previousHome : string | undefined ;
15+ let previousCodexHome : string | undefined ;
16+
1017 beforeEach ( ( ) => {
18+ previousHome = process . env [ "HOME" ] ;
19+ previousCodexHome = process . env [ "CODEX_HOME" ] ;
20+ testHomeDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "codex-acp-mcp-home-" ) ) ;
21+ process . env [ "HOME" ] = testHomeDir ;
22+ process . env [ "CODEX_HOME" ] = path . join ( testHomeDir , ".codex" ) ;
23+ fs . mkdirSync ( process . env [ "CODEX_HOME" ] , { recursive : true } ) ;
1124 fixture = createTestFixture ( ) ;
1225 vi . clearAllMocks ( ) ;
1326 } ) ;
1427
28+ afterEach ( ( ) => {
29+ if ( previousHome === undefined ) {
30+ delete process . env [ "HOME" ] ;
31+ } else {
32+ process . env [ "HOME" ] = previousHome ;
33+ }
34+ if ( previousCodexHome === undefined ) {
35+ delete process . env [ "CODEX_HOME" ] ;
36+ } else {
37+ process . env [ "CODEX_HOME" ] = previousCodexHome ;
38+ }
39+ try {
40+ fs . rmSync ( testHomeDir , { recursive : true , force : true } ) ;
41+ } catch {
42+ // Best-effort cleanup; Codex background writes can keep files transiently busy.
43+ }
44+ } ) ;
45+
1546
1647 it ( 'should return configured mcp' , async ( ) => {
1748 const codexAcpAgent = fixture . getCodexAcpAgent ( ) ;
@@ -22,7 +53,10 @@ describe('MCP session configuration', { timeout: 40_000 }, () => {
2253 name : "test-mcp" , command : "./node_modules/.bin/mcp-hello-world" , args : [ "example" ] , env : [ { name :"example" , value : "example" } ]
2354 } ;
2455
25- const newSessionResponse = await codexAcpAgent . newSession ( { cwd : "" , mcpServers : [ mcpServer ] } ) ;
56+ const newSessionResponse = await codexAcpAgent . newSession ( {
57+ cwd : path . resolve ( process . cwd ( ) ) ,
58+ mcpServers : [ mcpServer ]
59+ } ) ;
2660 fixture . clearAcpConnectionDump ( ) ;
2761 await codexAcpAgent . prompt ( { sessionId : newSessionResponse . sessionId , prompt : [ { type : "text" , text : "/mcp" } ] } ) ;
2862 const transportDump = fixture . getAcpConnectionDump ( [ ] ) ;
0 commit comments