mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-13 14:15:56 +00:00
test(cliproxy): stabilize path-sensitive CI test assertions
- infer update cache paths from runtime module behavior instead of hardcoded ~/.ccs - assert GLMT default log path via getCcsDir to avoid cross-suite env leakage
This commit is contained in:
1 parent
edd2a354eb
commit
c9faf6cdc9
2 files changed
+51
-14
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const GlmtTransformer = require('../../../dist/glmt/glmt-transformer').default;
|
const GlmtTransformer = require('../../../dist/glmt/glmt-transformer').default;
|
||||||
|
const { getCcsDir } = require('../../../dist/utils/config-manager');
|
||||||
|
|
||||||
describe('GlmtTransformer', () => {
|
describe('GlmtTransformer', () => {
|
||||||
describe('Request transformation', () => {
|
describe('Request transformation', () => {
|
||||||
@@ -202,11 +203,10 @@ describe('GlmtTransformer', () => {
|
|||||||
delete process.env.CCS_DEBUG;
|
delete process.env.CCS_DEBUG;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses ~/.ccs/logs by default', () => {
|
it('uses CCS logs directory by default', () => {
|
||||||
const transformer = new GlmtTransformer();
|
const transformer = new GlmtTransformer();
|
||||||
const os = require('os');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const expectedPath = path.join(os.homedir(), '.ccs', 'logs');
|
const expectedPath = path.join(getCcsDir(), 'logs');
|
||||||
assert.strictEqual(transformer.debugLogDir, expectedPath);
|
assert.strictEqual(transformer.debugLogDir, expectedPath);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ describe('Beta Channel Implementation (Phase 3)', function () {
|
|||||||
let originalHttpsGet;
|
let originalHttpsGet;
|
||||||
let mockFileSystem = {};
|
let mockFileSystem = {};
|
||||||
let httpsRequests = [];
|
let httpsRequests = [];
|
||||||
|
let cacheFilePath;
|
||||||
|
let cacheDirPath;
|
||||||
|
|
||||||
beforeAll(async function () {
|
beforeAll(async function () {
|
||||||
// Note: Build is handled by CI before tests run (bun run build:all)
|
// Note: Build is handled by CI before tests run (bun run build:all)
|
||||||
@@ -36,6 +38,8 @@ describe('Beta Channel Implementation (Phase 3)', function () {
|
|||||||
// Reset mocks
|
// Reset mocks
|
||||||
mockFileSystem = {};
|
mockFileSystem = {};
|
||||||
httpsRequests = [];
|
httpsRequests = [];
|
||||||
|
cacheFilePath = undefined;
|
||||||
|
cacheDirPath = undefined;
|
||||||
|
|
||||||
// Store original functions
|
// Store original functions
|
||||||
originalFsExistsSync = fs.existsSync;
|
originalFsExistsSync = fs.existsSync;
|
||||||
@@ -46,26 +50,44 @@ describe('Beta Channel Implementation (Phase 3)', function () {
|
|||||||
|
|
||||||
// Mock fs.existsSync
|
// Mock fs.existsSync
|
||||||
fs.existsSync = (filePath) => {
|
fs.existsSync = (filePath) => {
|
||||||
return mockFileSystem[filePath] !== undefined;
|
const key = String(filePath);
|
||||||
|
if (key.endsWith('/update-check.json') || key.endsWith('\\update-check.json')) {
|
||||||
|
cacheFilePath = key;
|
||||||
|
cacheDirPath = path.dirname(key);
|
||||||
|
}
|
||||||
|
if (key.endsWith('/cache') || key.endsWith('\\cache')) {
|
||||||
|
cacheDirPath = key;
|
||||||
|
}
|
||||||
|
return mockFileSystem[key] !== undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mock fs.readFileSync
|
// Mock fs.readFileSync
|
||||||
fs.readFileSync = (filePath, encoding) => {
|
fs.readFileSync = (filePath, encoding) => {
|
||||||
if (mockFileSystem[filePath]) {
|
const key = String(filePath);
|
||||||
return mockFileSystem[filePath];
|
if (mockFileSystem[key]) {
|
||||||
|
return mockFileSystem[key];
|
||||||
}
|
}
|
||||||
throw new Error(`ENOENT: no such file or directory, open '${filePath}'`);
|
throw new Error(`ENOENT: no such file or directory, open '${filePath}'`);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mock fs.writeFileSync
|
// Mock fs.writeFileSync
|
||||||
fs.writeFileSync = (filePath, data, encoding) => {
|
fs.writeFileSync = (filePath, data, encoding) => {
|
||||||
mockFileSystem[filePath] = data;
|
const key = String(filePath);
|
||||||
|
if (key.endsWith('/update-check.json') || key.endsWith('\\update-check.json')) {
|
||||||
|
cacheFilePath = key;
|
||||||
|
cacheDirPath = path.dirname(key);
|
||||||
|
}
|
||||||
|
mockFileSystem[key] = data;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mock fs.mkdirSync
|
// Mock fs.mkdirSync
|
||||||
fs.mkdirSync = (dirPath, options) => {
|
fs.mkdirSync = (dirPath, options) => {
|
||||||
|
const key = String(dirPath);
|
||||||
|
if (key.endsWith('/cache') || key.endsWith('\\cache')) {
|
||||||
|
cacheDirPath = key;
|
||||||
|
}
|
||||||
// Just mark as created for testing
|
// Just mark as created for testing
|
||||||
mockFileSystem[dirPath] = 'directory';
|
mockFileSystem[key] = 'directory';
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mock https.get
|
// Mock https.get
|
||||||
@@ -110,6 +132,9 @@ describe('Beta Channel Implementation (Phase 3)', function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Force path discovery from module internals to avoid hardcoded ~/.ccs assumptions.
|
||||||
|
updateCheckerModule.readCache();
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function () {
|
afterEach(function () {
|
||||||
@@ -261,6 +286,10 @@ describe('Beta Channel Implementation (Phase 3)', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('checkForUpdates with targetTag parameter', function () {
|
describe('checkForUpdates with targetTag parameter', function () {
|
||||||
|
function getCacheFilePath() {
|
||||||
|
return cacheFilePath || path.join(os.homedir(), '.ccs', 'cache', 'update-check.json');
|
||||||
|
}
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
// Set up a fresh cache
|
// Set up a fresh cache
|
||||||
const cacheData = {
|
const cacheData = {
|
||||||
@@ -268,7 +297,7 @@ describe('Beta Channel Implementation (Phase 3)', function () {
|
|||||||
latest_version: null,
|
latest_version: null,
|
||||||
dismissed_version: null
|
dismissed_version: null
|
||||||
};
|
};
|
||||||
mockFileSystem[path.join(os.homedir(), '.ccs', 'cache', 'update-check.json')] = JSON.stringify(cacheData);
|
mockFileSystem[getCacheFilePath()] = JSON.stringify(cacheData);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should use latest tag when targetTag is "latest"', async function () {
|
it('should use latest tag when targetTag is "latest"', async function () {
|
||||||
@@ -355,7 +384,7 @@ describe('Beta Channel Implementation (Phase 3)', function () {
|
|||||||
await updateCheckerModule.checkForUpdates('5.4.0', true, 'npm', 'dev');
|
await updateCheckerModule.checkForUpdates('5.4.0', true, 'npm', 'dev');
|
||||||
|
|
||||||
// Check cache was updated with dev version
|
// Check cache was updated with dev version
|
||||||
const cachePath = path.join(os.homedir(), '.ccs', 'cache', 'update-check.json');
|
const cachePath = getCacheFilePath();
|
||||||
const cacheData = JSON.parse(mockFileSystem[cachePath]);
|
const cacheData = JSON.parse(mockFileSystem[cachePath]);
|
||||||
|
|
||||||
// Dev versions are now stored in dev_version field (not latest_version)
|
// Dev versions are now stored in dev_version field (not latest_version)
|
||||||
@@ -371,7 +400,7 @@ describe('Beta Channel Implementation (Phase 3)', function () {
|
|||||||
dev_version: '5.5.0',
|
dev_version: '5.5.0',
|
||||||
dismissed_version: null
|
dismissed_version: null
|
||||||
};
|
};
|
||||||
mockFileSystem[path.join(os.homedir(), '.ccs', 'cache', 'update-check.json')] = JSON.stringify(cacheData);
|
mockFileSystem[getCacheFilePath()] = JSON.stringify(cacheData);
|
||||||
|
|
||||||
// Call with force=false to use cache
|
// Call with force=false to use cache
|
||||||
const result = await updateCheckerModule.checkForUpdates('5.4.0', false, 'npm', 'dev');
|
const result = await updateCheckerModule.checkForUpdates('5.4.0', false, 'npm', 'dev');
|
||||||
@@ -458,9 +487,17 @@ describe('Beta Channel Implementation (Phase 3)', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Cache functionality', function () {
|
describe('Cache functionality', function () {
|
||||||
|
function getCacheFilePath() {
|
||||||
|
return cacheFilePath || path.join(os.homedir(), '.ccs', 'cache', 'update-check.json');
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCacheDirPath() {
|
||||||
|
return cacheDirPath || path.dirname(getCacheFilePath());
|
||||||
|
}
|
||||||
|
|
||||||
it('should create cache directory if not exists', async function () {
|
it('should create cache directory if not exists', async function () {
|
||||||
// Ensure no cache exists
|
// Ensure no cache exists
|
||||||
const cacheDir = path.join(os.homedir(), '.ccs', 'cache');
|
const cacheDir = getCacheDirPath();
|
||||||
delete mockFileSystem[cacheDir];
|
delete mockFileSystem[cacheDir];
|
||||||
|
|
||||||
await updateCheckerModule.checkForUpdates('5.4.0', true, 'npm', 'latest');
|
await updateCheckerModule.checkForUpdates('5.4.0', true, 'npm', 'latest');
|
||||||
@@ -477,7 +514,7 @@ describe('Beta Channel Implementation (Phase 3)', function () {
|
|||||||
dev_version: '5.5.0',
|
dev_version: '5.5.0',
|
||||||
dismissed_version: '5.5.0'
|
dismissed_version: '5.5.0'
|
||||||
};
|
};
|
||||||
mockFileSystem[path.join(os.homedir(), '.ccs', 'cache', 'update-check.json')] = JSON.stringify(cacheData);
|
mockFileSystem[getCacheFilePath()] = JSON.stringify(cacheData);
|
||||||
|
|
||||||
const result = await updateCheckerModule.checkForUpdates('5.4.1', false, 'npm', 'dev');
|
const result = await updateCheckerModule.checkForUpdates('5.4.1', false, 'npm', 'dev');
|
||||||
|
|
||||||
@@ -488,7 +525,7 @@ describe('Beta Channel Implementation (Phase 3)', function () {
|
|||||||
|
|
||||||
it('should handle corrupted cache gracefully', async function () {
|
it('should handle corrupted cache gracefully', async function () {
|
||||||
// Set up corrupted cache
|
// Set up corrupted cache
|
||||||
mockFileSystem[path.join(os.homedir(), '.ccs', 'cache', 'update-check.json')] = 'invalid json';
|
mockFileSystem[getCacheFilePath()] = 'invalid json';
|
||||||
|
|
||||||
// Should not throw error
|
// Should not throw error
|
||||||
const result = await updateCheckerModule.checkForUpdates('5.4.0', true, 'npm', 'latest');
|
const result = await updateCheckerModule.checkForUpdates('5.4.0', true, 'npm', 'latest');
|
||||||
|
|||||||
Reference in new issue
Block a user