mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 04:18:05 +00:00
fix(isolation): use getCcsDir() for test isolation
Replace os.homedir() with getCcsDir() in 11 source files to ensure tests don't touch the user's real ~/.ccs/ directory. The getCcsDir() function from config-manager.ts respects CCS_HOME env var for test isolation. Files fixed: - src/auth/profile-detector.ts - src/auth/profile-registry.ts - src/delegation/headless-executor.ts - src/delegation/session-manager.ts - src/glmt/glmt-transformer.ts - src/management/checks/config-check.ts - src/management/checks/profile-check.ts - src/management/checks/system-check.ts - src/management/instance-manager.ts - src/management/shared-manager.ts - src/utils/update-checker.ts
This commit is contained in:
@@ -11,11 +11,11 @@
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import { findSimilarStrings, expandPath } from '../utils/helpers';
|
||||
import { Config, Settings, ProfileMetadata } from '../types';
|
||||
import { UnifiedConfig, CopilotConfig } from '../config/unified-config-types';
|
||||
import { loadUnifiedConfig, isUnifiedMode } from '../config/unified-config-loader';
|
||||
import { getCcsDir } from '../utils/config-manager';
|
||||
|
||||
export type ProfileType = 'settings' | 'account' | 'cliproxy' | 'copilot' | 'default';
|
||||
|
||||
@@ -84,8 +84,9 @@ class ProfileDetector {
|
||||
private readonly profilesPath: string;
|
||||
|
||||
constructor() {
|
||||
this.configPath = path.join(os.homedir(), '.ccs', 'config.json');
|
||||
this.profilesPath = path.join(os.homedir(), '.ccs', 'profiles.json');
|
||||
const ccsDir = getCcsDir();
|
||||
this.configPath = path.join(ccsDir, 'config.json');
|
||||
this.profilesPath = path.join(ccsDir, 'profiles.json');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import { ProfileMetadata } from '../types';
|
||||
import {
|
||||
loadOrCreateUnifiedConfig,
|
||||
saveUnifiedConfig,
|
||||
isUnifiedMode,
|
||||
} from '../config/unified-config-loader';
|
||||
import { getCcsDir } from '../utils/config-manager';
|
||||
|
||||
/**
|
||||
* Profile Registry (Simplified)
|
||||
@@ -43,7 +43,7 @@ export class ProfileRegistry {
|
||||
private profilesPath: string;
|
||||
|
||||
constructor() {
|
||||
this.profilesPath = path.join(os.homedir(), '.ccs', 'profiles.json');
|
||||
this.profilesPath = path.join(getCcsDir(), 'profiles.json');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
import { spawn } from 'child_process';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import * as fs from 'fs';
|
||||
import { SessionManager } from './session-manager';
|
||||
import { SettingsParser } from './settings-parser';
|
||||
@@ -15,6 +14,7 @@ import { ui, warn, info } from '../utils/ui';
|
||||
import { type ExecutionOptions, type ExecutionResult, type StreamMessage } from './executor/types';
|
||||
import { StreamBuffer, formatToolVerbose } from './executor/stream-parser';
|
||||
import { buildExecutionResult } from './executor/result-aggregator';
|
||||
import { getCcsDir } from '../utils/config-manager';
|
||||
|
||||
// Re-export types for consumers
|
||||
export type { ExecutionOptions, ExecutionResult, StreamMessage } from './executor/types';
|
||||
@@ -63,7 +63,7 @@ export class HeadlessExecutor {
|
||||
}
|
||||
|
||||
// Get settings path for profile
|
||||
const settingsPath = path.join(os.homedir(), '.ccs', `${profile}.settings.json`);
|
||||
const settingsPath = path.join(getCcsDir(), `${profile}.settings.json`);
|
||||
|
||||
// Validate settings file exists
|
||||
if (!fs.existsSync(settingsPath)) {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import { getCcsDir } from '../utils/config-manager';
|
||||
|
||||
interface SessionData {
|
||||
sessionId: string;
|
||||
@@ -39,7 +39,7 @@ class SessionManager {
|
||||
private readonly sessionsPath: string;
|
||||
|
||||
constructor() {
|
||||
this.sessionsPath = path.join(os.homedir(), '.ccs', 'delegation-sessions.json');
|
||||
this.sessionsPath = path.join(getCcsDir(), 'delegation-sessions.json');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import { DeltaAccumulator } from './delta-accumulator';
|
||||
import { getCcsDir } from '../utils/config-manager';
|
||||
import {
|
||||
RequestTransformer,
|
||||
StreamParser,
|
||||
@@ -48,7 +48,7 @@ export class GlmtTransformer {
|
||||
|
||||
const debugEnabled = process.env.CCS_DEBUG === '1';
|
||||
this.debugLog = config.debugLog ?? debugEnabled;
|
||||
this.debugLogDir = config.debugLogDir || path.join(os.homedir(), '.ccs', 'logs');
|
||||
this.debugLogDir = config.debugLogDir || path.join(getCcsDir(), 'logs');
|
||||
|
||||
// Initialize pipeline components
|
||||
this.requestTransformer = new RequestTransformer({
|
||||
|
||||
@@ -7,6 +7,7 @@ import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import { ok, fail, warn, info } from '../../utils/ui';
|
||||
import { HealthCheck, IHealthChecker, createSpinner } from './types';
|
||||
import { getCcsDir } from '../../utils/config-manager';
|
||||
|
||||
const ora = createSpinner();
|
||||
|
||||
@@ -20,7 +21,7 @@ export class ConfigFilesChecker implements IHealthChecker {
|
||||
private readonly ccsDir: string;
|
||||
|
||||
constructor() {
|
||||
this.ccsDir = path.join(os.homedir(), '.ccs');
|
||||
this.ccsDir = getCcsDir();
|
||||
}
|
||||
|
||||
run(results: HealthCheck): void {
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import { ok, fail, warn, info } from '../../utils/ui';
|
||||
import { HealthCheck, IHealthChecker, createSpinner } from './types';
|
||||
import { getCcsDir } from '../../utils/config-manager';
|
||||
|
||||
const ora = createSpinner();
|
||||
|
||||
@@ -18,7 +18,7 @@ export class ProfilesChecker implements IHealthChecker {
|
||||
private readonly ccsDir: string;
|
||||
|
||||
constructor() {
|
||||
this.ccsDir = path.join(os.homedir(), '.ccs');
|
||||
this.ccsDir = getCcsDir();
|
||||
}
|
||||
|
||||
run(results: HealthCheck): void {
|
||||
@@ -130,7 +130,7 @@ export class InstancesChecker implements IHealthChecker {
|
||||
private readonly ccsDir: string;
|
||||
|
||||
constructor() {
|
||||
this.ccsDir = path.join(os.homedir(), '.ccs');
|
||||
this.ccsDir = getCcsDir();
|
||||
}
|
||||
|
||||
run(results: HealthCheck): void {
|
||||
@@ -169,7 +169,7 @@ export class DelegationChecker implements IHealthChecker {
|
||||
private readonly ccsDir: string;
|
||||
|
||||
constructor() {
|
||||
this.ccsDir = path.join(os.homedir(), '.ccs');
|
||||
this.ccsDir = getCcsDir();
|
||||
}
|
||||
|
||||
run(results: HealthCheck): void {
|
||||
|
||||
@@ -3,13 +3,12 @@
|
||||
*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import { spawn } from 'child_process';
|
||||
import { getClaudeCliInfo } from '../../utils/claude-detector';
|
||||
import { escapeShellArg } from '../../utils/shell-executor';
|
||||
import { ok, fail } from '../../utils/ui';
|
||||
import { HealthCheck, IHealthChecker, createSpinner } from './types';
|
||||
import { getCcsDir } from '../../utils/config-manager';
|
||||
|
||||
const ora = createSpinner();
|
||||
|
||||
@@ -99,7 +98,7 @@ export class CcsDirectoryChecker implements IHealthChecker {
|
||||
private readonly ccsDir: string;
|
||||
|
||||
constructor() {
|
||||
this.ccsDir = path.join(os.homedir(), '.ccs');
|
||||
this.ccsDir = getCcsDir();
|
||||
}
|
||||
|
||||
run(results: HealthCheck): void {
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import SharedManager from './shared-manager';
|
||||
import { getCcsDir } from '../utils/config-manager';
|
||||
|
||||
/**
|
||||
* Instance Manager Class
|
||||
@@ -19,7 +19,7 @@ class InstanceManager {
|
||||
private readonly sharedManager: SharedManager;
|
||||
|
||||
constructor() {
|
||||
this.instancesDir = path.join(os.homedir(), '.ccs', 'instances');
|
||||
this.instancesDir = path.join(getCcsDir(), 'instances');
|
||||
this.sharedManager = new SharedManager();
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import { ok, info, warn } from '../utils/ui';
|
||||
import { getCcsDir } from '../utils/config-manager';
|
||||
|
||||
interface SharedItem {
|
||||
name: string;
|
||||
@@ -28,9 +29,10 @@ class SharedManager {
|
||||
|
||||
constructor() {
|
||||
this.homeDir = os.homedir();
|
||||
this.sharedDir = path.join(this.homeDir, '.ccs', 'shared');
|
||||
const ccsDir = getCcsDir();
|
||||
this.sharedDir = path.join(ccsDir, 'shared');
|
||||
this.claudeDir = path.join(this.homeDir, '.claude');
|
||||
this.instancesDir = path.join(this.homeDir, '.ccs', 'instances');
|
||||
this.instancesDir = path.join(ccsDir, 'instances');
|
||||
this.sharedItems = [
|
||||
{ name: 'commands', type: 'directory' },
|
||||
{ name: 'skills', type: 'directory' },
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import * as https from 'https';
|
||||
import { getCcsDir } from './config-manager';
|
||||
|
||||
const CACHE_DIR = path.join(os.homedir(), '.ccs', 'cache');
|
||||
const CACHE_DIR = path.join(getCcsDir(), 'cache');
|
||||
const UPDATE_CHECK_FILE = path.join(CACHE_DIR, 'update-check.json');
|
||||
const CHECK_INTERVAL = 24 * 60 * 60 * 1000; // 24 hours
|
||||
const GITHUB_API_URL = 'https://api.github.com/repos/kaitranntt/ccs/releases/latest';
|
||||
|
||||
Reference in New Issue
Block a user