Files
ccs/src/types/utils.ts
T
kaitranntt 92a79aa78b test(auth): add comprehensive tests for GLM auth persistence fix
Add 26 new unit tests covering:
- isFirstTimeInstall() legacy config detection (8 tests)
- loadSettingsFromFile() path expansion (5 tests)
- ProfileDetector detectProfileType() (4 tests)
- expandPath() cross-platform handling (10 tests)

Test coverage for issue #195:
- Legacy config.json/profiles.json detection
- Tilde expansion to home directory
- Environment variable expansion (${VAR}, $VAR, %VAR%)
- Mixed path separator normalization
- Corrupted config graceful handling

Files:
- tests/unit/commands/setup-command.test.ts
- tests/unit/auth/profile-detector.test.ts
- tests/unit/utils/expand-path.test.ts
2025-12-24 18:33:52 -05:00

136 lines
2.8 KiB
TypeScript

/**
* Utility Types
*/
// Re-export from error-codes for consistency
export { ERROR_CODES, getErrorDocUrl, getErrorCategory } from '../utils/error-codes';
export type { ErrorCode } from '../utils/error-codes';
/**
* Log levels
*/
export enum LogLevel {
DEBUG = 'debug',
INFO = 'info',
WARN = 'warn',
ERROR = 'error',
}
/**
* Color codes (TTY-aware)
*/
export type ColorName =
| 'red'
| 'green'
| 'yellow'
| 'blue'
| 'cyan'
| 'bold'
| 'cyanBold'
| 'reset';
/**
* Terminal capabilities
*/
export interface TerminalInfo {
isTTY: boolean;
supportsColor: boolean;
noColorEnv: boolean; // NO_COLOR env var set
}
/**
* Helper result types
*/
export type Result<T, E = Error> = { ok: true; value: T } | { ok: false; error: E };
/**
* Generic operation result for success/failure patterns
* Use this instead of defining new *Result interfaces
*/
export interface OperationResult<T = void> {
success: boolean;
message?: string;
error?: string;
data?: T;
}
/**
* Generic component/tool status
* Used for CLI tools, services, etc.
*/
export interface ComponentStatus {
installed: boolean;
path?: string;
version?: string;
}
/**
* Generic validation result
* Standardized on 'valid' property name
*/
export interface ValidationResult {
valid: boolean;
errors?: string[];
}
// =============================================================================
// UI TYPES (Phase 1: CLI UI/UX Enhancement)
// =============================================================================
/**
* Semantic color names for UI elements
*/
export type SemanticColor =
| 'success' // green - [OK] messages
| 'error' // red - [X] messages
| 'warning' // yellow - [!] messages
| 'info' // cyan - [i] messages
| 'dim' // gray - secondary text
| 'primary' // #00ECFA - headers, emphasis
| 'secondary' // #0099FF - links, accents
| 'command' // yellow italic - command examples
| 'path'; // cyan underline - file paths
/**
* Box style options for boxen wrapper
*/
export interface BoxOptions {
title?: string;
titleAlignment?: 'left' | 'center' | 'right';
padding?: number;
margin?: number;
borderColor?: string;
borderStyle?: 'single' | 'double' | 'round' | 'bold' | 'classic';
}
/**
* Table style options for cli-table3 wrapper
*/
export interface TableOptions {
head?: string[];
colWidths?: number[];
wordWrap?: boolean;
style?: 'unicode' | 'ascii';
}
/**
* Spinner options for ora wrapper
*/
export interface SpinnerOptions {
text: string;
color?: string;
prefixText?: string;
}
/**
* Spinner control interface
*/
export interface SpinnerController {
succeed: (msg?: string) => void;
fail: (msg?: string) => void;
warn: (msg?: string) => void;
info: (msg?: string) => void;
update: (text: string) => void;
stop: () => void;
}