mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-17 06:17:09 +00:00
test(cliproxy): isolate session tracker config env
This commit is contained in:
@@ -15,7 +15,10 @@ const testHome = path.join(
|
||||
os.tmpdir(),
|
||||
`ccs-test-session-port-${Date.now()}-${Math.random().toString(36).slice(2)}`
|
||||
);
|
||||
const originalCcsHome = process.env.CCS_HOME;
|
||||
const originalCcsDir = process.env.CCS_DIR;
|
||||
process.env.CCS_HOME = testHome;
|
||||
delete process.env.CCS_DIR;
|
||||
|
||||
const {
|
||||
getExistingProxy,
|
||||
@@ -28,6 +31,7 @@ const {
|
||||
deleteSessionLockForPort,
|
||||
} = require('../../../dist/cliproxy/session-tracker');
|
||||
const { CLIPROXY_DEFAULT_PORT } = require('../../../dist/cliproxy/config-generator');
|
||||
const { setGlobalConfigDir } = require('../../../dist/utils/config-manager');
|
||||
|
||||
describe('Session Tracker Port-Specific', function () {
|
||||
const variantPort1 = 8318;
|
||||
@@ -35,6 +39,11 @@ describe('Session Tracker Port-Specific', function () {
|
||||
let cliproxyDir;
|
||||
|
||||
beforeEach(function () {
|
||||
// Reassert test isolation because other files mutate CCS_DIR/CCS_HOME in the same Bun process.
|
||||
process.env.CCS_HOME = testHome;
|
||||
delete process.env.CCS_DIR;
|
||||
setGlobalConfigDir(undefined);
|
||||
|
||||
// Create test directories
|
||||
cliproxyDir = path.join(testHome, '.ccs', 'cliproxy');
|
||||
fs.mkdirSync(cliproxyDir, { recursive: true });
|
||||
@@ -49,6 +58,8 @@ describe('Session Tracker Port-Specific', function () {
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
setGlobalConfigDir(undefined);
|
||||
|
||||
// Clean up session files
|
||||
try {
|
||||
const files = fs.readdirSync(cliproxyDir);
|
||||
@@ -69,7 +80,11 @@ describe('Session Tracker Port-Specific', function () {
|
||||
} catch {
|
||||
// Ignore cleanup errors
|
||||
}
|
||||
delete process.env.CCS_HOME;
|
||||
if (originalCcsHome !== undefined) process.env.CCS_HOME = originalCcsHome;
|
||||
else delete process.env.CCS_HOME;
|
||||
if (originalCcsDir !== undefined) process.env.CCS_DIR = originalCcsDir;
|
||||
else delete process.env.CCS_DIR;
|
||||
setGlobalConfigDir(undefined);
|
||||
});
|
||||
|
||||
describe('Session Lock Path', function () {
|
||||
|
||||
@@ -12,7 +12,10 @@ const os = require('os');
|
||||
|
||||
// Set test isolation environment before importing
|
||||
const testHome = path.join(os.tmpdir(), `ccs-test-${Date.now()}-${Math.random().toString(36).slice(2)}`);
|
||||
const originalCcsHome = process.env.CCS_HOME;
|
||||
const originalCcsDir = process.env.CCS_DIR;
|
||||
process.env.CCS_HOME = testHome;
|
||||
delete process.env.CCS_DIR;
|
||||
|
||||
const {
|
||||
getExistingProxy,
|
||||
@@ -24,6 +27,7 @@ const {
|
||||
stopProxy,
|
||||
getProxyStatus,
|
||||
} = require('../../../dist/cliproxy/session-tracker');
|
||||
const { setGlobalConfigDir } = require('../../../dist/utils/config-manager');
|
||||
|
||||
describe('Session Tracker', function () {
|
||||
const testPort = 18317;
|
||||
@@ -31,6 +35,11 @@ describe('Session Tracker', function () {
|
||||
let cliproxyDir;
|
||||
|
||||
beforeEach(function () {
|
||||
// Reassert test isolation because other files mutate CCS_DIR/CCS_HOME in the same Bun process.
|
||||
process.env.CCS_HOME = testHome;
|
||||
delete process.env.CCS_DIR;
|
||||
setGlobalConfigDir(undefined);
|
||||
|
||||
// Create test directories
|
||||
cliproxyDir = path.join(testHome, '.ccs', 'cliproxy');
|
||||
fs.mkdirSync(cliproxyDir, { recursive: true });
|
||||
@@ -51,6 +60,8 @@ describe('Session Tracker', function () {
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
setGlobalConfigDir(undefined);
|
||||
|
||||
// Clean up lock files
|
||||
try {
|
||||
const files = fs.readdirSync(cliproxyDir);
|
||||
@@ -71,7 +82,11 @@ describe('Session Tracker', function () {
|
||||
} catch {
|
||||
// Ignore cleanup errors
|
||||
}
|
||||
delete process.env.CCS_HOME;
|
||||
if (originalCcsHome !== undefined) process.env.CCS_HOME = originalCcsHome;
|
||||
else delete process.env.CCS_HOME;
|
||||
if (originalCcsDir !== undefined) process.env.CCS_DIR = originalCcsDir;
|
||||
else delete process.env.CCS_DIR;
|
||||
setGlobalConfigDir(undefined);
|
||||
});
|
||||
|
||||
describe('getExistingProxy', function () {
|
||||
|
||||
Reference in New Issue
Block a user