mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-15 16:14:26 +00:00
fix(tests): isolate tests from user ~/.ccs directory
Problem: Test suite was directly modifying user's personal ~/.ccs/ directory, causing configuration interference during development. Solution: - Add test-environment.js fixture with CCS_HOME env var support - Update postinstall.js to respect CCS_HOME for test isolation - Update config-manager.ts with getCcsHome() helper - Update postinstall.test.js and cli.test.js to use isolated env - Remove auto-install of .claude/ symlinks from postinstall (users can run "ccs sync" to opt-in) Benefits: - Tests run in temp directories, no user config affected - Users control when .claude/ items are installed via "ccs sync" - All 39 tests passing with proper isolation
This commit is contained in:
1 parent
1c3c4aade0
commit
49150dc24f
5 files changed
+278
-84
No files matched your search
+16
-27
@@ -12,14 +12,24 @@ const os = require('os');
|
||||
* Runs when: npm install -g @kaitranntt/ccs
|
||||
* Idempotent: Safe to run multiple times (won't overwrite existing configs)
|
||||
* Cross-platform: Works on Unix, macOS, Windows
|
||||
*
|
||||
* Test isolation: Set CCS_HOME env var to redirect all operations to a test directory
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get the CCS home directory (respects CCS_HOME env var for test isolation)
|
||||
* @returns {string} Home directory path
|
||||
*/
|
||||
function getCcsHome() {
|
||||
return process.env.CCS_HOME || os.homedir();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate created configuration files
|
||||
* @returns {object} { success: boolean, errors: string[], warnings: string[] }
|
||||
*/
|
||||
function validateConfiguration() {
|
||||
const homedir = os.homedir();
|
||||
const homedir = getCcsHome();
|
||||
const errors = [];
|
||||
const warnings = [];
|
||||
|
||||
@@ -63,8 +73,8 @@ function validateConfiguration() {
|
||||
|
||||
function createConfigFiles() {
|
||||
try {
|
||||
// Get user home directory (cross-platform)
|
||||
const homedir = os.homedir();
|
||||
// Get user home directory (cross-platform, respects CCS_HOME for test isolation)
|
||||
const homedir = getCcsHome();
|
||||
const ccsDir = path.join(homedir, '.ccs');
|
||||
|
||||
// Create ~/.ccs/ directory if missing
|
||||
@@ -106,30 +116,9 @@ function createConfigFiles() {
|
||||
}
|
||||
console.log('');
|
||||
|
||||
// Copy .claude/ directory from package to ~/.ccs/.claude/ (v4.1.1)
|
||||
try {
|
||||
const ClaudeDirInstaller = require('../dist/utils/claude-dir-installer').default;
|
||||
const installer = new ClaudeDirInstaller();
|
||||
const packageDir = path.join(__dirname, '..');
|
||||
installer.install(packageDir);
|
||||
|
||||
// Clean up deprecated files (v4.3.2)
|
||||
installer.cleanupDeprecated();
|
||||
} catch (err) {
|
||||
console.warn('[!] Failed to install .claude/ directory:', err.message);
|
||||
console.warn(' CCS items may not be available');
|
||||
}
|
||||
|
||||
// Install CCS items to ~/.claude/ (v4.1.0)
|
||||
try {
|
||||
const { ClaudeSymlinkManager } = require('../dist/utils/claude-symlink-manager');
|
||||
const claudeSymlinkManager = new ClaudeSymlinkManager();
|
||||
claudeSymlinkManager.install();
|
||||
} catch (err) {
|
||||
console.warn('[!] CCS item installation warning:', err.message);
|
||||
console.warn(' Run "ccs sync" to retry');
|
||||
}
|
||||
console.log('');
|
||||
// NOTE: .claude/ directory installation moved to "ccs sync" command
|
||||
// Users can run "ccs sync" to install CCS commands/skills to ~/.claude/
|
||||
// This gives users control over when to modify their Claude configuration
|
||||
|
||||
// Create config.json if missing
|
||||
const configPath = path.join(ccsDir, 'config.json');
|
||||
|
||||
Reference in new issue
Block a user