fix(env): improve empty profile UX and consolidate shell validation constants

- Return {} instead of null for valid-but-empty settings profiles
- Consolidate VALID_SHELLS and validShellInputs into VALID_SHELL_INPUTS
- Fix docs test count 33 → 34
This commit is contained in:
Tam Nhu Tran
2026-02-11 11:20:25 +07:00
parent a98f4a5427
commit b96eacfc06
2 changed files with 6 additions and 7 deletions
+1 -1
View File
@@ -276,7 +276,7 @@ CCS provides:
- [x] Settings profile support (glm, kimi, custom API)
- [x] Security: single-quoted output, key sanitization, shell-specific escaping
- [x] Shell completion updated (bash, zsh, fish, PowerShell)
- [x] 33 unit tests for env command
- [x] 34 unit tests for env command
### v8.0 Release (Planned - Q1 2026)
- [ ] Multiple CLIProxyAPI instances (load balancing, failover)
+5 -6
View File
@@ -20,6 +20,7 @@ type OutputFormat = 'openai' | 'anthropic' | 'raw';
const VALID_FORMATS: OutputFormat[] = ['openai', 'anthropic', 'raw'];
const VALID_SHELLS: ShellType[] = ['bash', 'fish', 'powershell'];
const VALID_SHELL_INPUTS = ['auto', 'bash', 'zsh', 'fish', 'powershell'] as const;
const VALID_ENV_KEY = /^[A-Za-z_][A-Za-z0-9_]*$/;
/** Auto-detect shell from environment */
@@ -122,11 +123,10 @@ function resolveSettingsProfile(profileName: string): Record<string, string> | n
if (profileConfig.settings) {
const settingsPath = expandPath(profileConfig.settings);
const env = loadSettingsFromFile(settingsPath);
if (Object.keys(env).length > 0) return env;
return loadSettingsFromFile(settingsPath);
}
return null;
return {};
}
/** Show help for env command */
@@ -206,9 +206,8 @@ export async function handleEnvCommand(args: string[]): Promise<void> {
const format = formatStr as OutputFormat;
const shellStr = parseFlag(args, 'shell') || 'auto';
const validShellInputs = ['auto', 'bash', 'zsh', 'fish', 'powershell'];
if (!validShellInputs.includes(shellStr)) {
console.error(fail(`Invalid shell: ${shellStr}. Use: ${validShellInputs.join(', ')}`));
if (!VALID_SHELL_INPUTS.includes(shellStr as (typeof VALID_SHELL_INPUTS)[number])) {
console.error(fail(`Invalid shell: ${shellStr}. Use: ${VALID_SHELL_INPUTS.join(', ')}`));
process.exit(1);
}
// zsh uses the same syntax as bash