mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-17 04:17:11 +00:00
test(image-analysis): 隔离 hook e2e 环境变量
避免本机会话的 CCS_IMAGE_ANALYSIS_* 配置污染 e2e 子进程,确保 mock CLIProxy 场景稳定验证。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
4c46d6c5ae
commit
785f439e9b
@@ -137,6 +137,30 @@ function resetMockState(): void {
|
||||
/**
|
||||
* Invoke the hook with JSON input
|
||||
*/
|
||||
function buildHookEnv(env: Record<string, string> = {}): NodeJS.ProcessEnv {
|
||||
const baseEnv: NodeJS.ProcessEnv = { ...process.env };
|
||||
for (const key of Object.keys(baseEnv)) {
|
||||
if (
|
||||
key.startsWith('CCS_IMAGE_ANALYSIS_') ||
|
||||
key === 'CCS_CURRENT_PROVIDER' ||
|
||||
key === 'CCS_PROFILE_TYPE' ||
|
||||
key === 'CCS_CLIPROXY_API_KEY' ||
|
||||
key === 'CCS_CLIPROXY_PORT'
|
||||
) {
|
||||
delete baseEnv[key];
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...baseEnv,
|
||||
CCS_CLIPROXY_API_KEY: CLIPROXY_API_KEY,
|
||||
CCS_CLIPROXY_PORT: String(MOCK_PORT),
|
||||
CCS_IMAGE_ANALYSIS_PROVIDER_MODELS: DEFAULT_PROVIDER_MODELS,
|
||||
CCS_CURRENT_PROVIDER: DEFAULT_PROVIDER,
|
||||
...env,
|
||||
};
|
||||
}
|
||||
|
||||
function invokeHook(
|
||||
input: object,
|
||||
env: Record<string, string> = {}
|
||||
@@ -144,15 +168,7 @@ function invokeHook(
|
||||
const result = spawnSync('node', [HOOK_PATH], {
|
||||
input: JSON.stringify(input),
|
||||
encoding: 'utf8',
|
||||
env: {
|
||||
...process.env,
|
||||
CCS_CLIPROXY_API_KEY: CLIPROXY_API_KEY,
|
||||
CCS_CLIPROXY_PORT: String(MOCK_PORT),
|
||||
// Default provider config for tests (can be overridden)
|
||||
CCS_IMAGE_ANALYSIS_PROVIDER_MODELS: DEFAULT_PROVIDER_MODELS,
|
||||
CCS_CURRENT_PROVIDER: DEFAULT_PROVIDER,
|
||||
...env,
|
||||
},
|
||||
env: buildHookEnv(env),
|
||||
timeout: 10000, // 10 second timeout per test
|
||||
});
|
||||
|
||||
@@ -169,14 +185,7 @@ function invokeHookAsync(
|
||||
): Promise<{ code: number; stdout: string; stderr: string }> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const child = spawn('node', [HOOK_PATH], {
|
||||
env: {
|
||||
...process.env,
|
||||
CCS_CLIPROXY_API_KEY: CLIPROXY_API_KEY,
|
||||
CCS_CLIPROXY_PORT: String(MOCK_PORT),
|
||||
CCS_IMAGE_ANALYSIS_PROVIDER_MODELS: DEFAULT_PROVIDER_MODELS,
|
||||
CCS_CURRENT_PROVIDER: DEFAULT_PROVIDER,
|
||||
...env,
|
||||
},
|
||||
env: buildHookEnv(env),
|
||||
stdio: ['pipe', 'pipe', 'pipe'],
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user