mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-13 04:14:57 +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:
1 parent
4c46d6c5ae
commit
785f439e9b
1 file changed
+26
-17
@@ -137,6 +137,30 @@ function resetMockState(): void {
|
|||||||
/**
|
/**
|
||||||
* Invoke the hook with JSON input
|
* 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(
|
function invokeHook(
|
||||||
input: object,
|
input: object,
|
||||||
env: Record<string, string> = {}
|
env: Record<string, string> = {}
|
||||||
@@ -144,15 +168,7 @@ function invokeHook(
|
|||||||
const result = spawnSync('node', [HOOK_PATH], {
|
const result = spawnSync('node', [HOOK_PATH], {
|
||||||
input: JSON.stringify(input),
|
input: JSON.stringify(input),
|
||||||
encoding: 'utf8',
|
encoding: 'utf8',
|
||||||
env: {
|
env: buildHookEnv(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,
|
|
||||||
},
|
|
||||||
timeout: 10000, // 10 second timeout per test
|
timeout: 10000, // 10 second timeout per test
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -169,14 +185,7 @@ function invokeHookAsync(
|
|||||||
): Promise<{ code: number; stdout: string; stderr: string }> {
|
): Promise<{ code: number; stdout: string; stderr: string }> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const child = spawn('node', [HOOK_PATH], {
|
const child = spawn('node', [HOOK_PATH], {
|
||||||
env: {
|
env: buildHookEnv(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,
|
|
||||||
},
|
|
||||||
stdio: ['pipe', 'pipe', 'pipe'],
|
stdio: ['pipe', 'pipe', 'pipe'],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user