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