fix(image-analysis): preview backend status safely

This commit is contained in:
Tam Nhu Tran committed 2026-04-01 15:32:37 -04:00
1 parent 665668579d
commit d394772f7c
10 files changed
+507 -26

No files matched your search

@@ -44,11 +44,17 @@ describe('image-analysis-backend-resolver', () => {
expect(status.resolutionSource).toBe('copilot-alias');
});
it('uses the fallback backend for an unmapped settings profile', () => {
it('uses the fallback backend for an unmapped third-party settings profile', () => {
const status = resolveImageAnalysisStatus(
{
profileName: 'glm',
profileType: 'settings',
settings: {
env: {
ANTHROPIC_BASE_URL: 'https://api.z.ai/v1',
ANTHROPIC_AUTH_TOKEN: 'glm-test-key',
},
},
},
DEFAULT_IMAGE_ANALYSIS_CONFIG
);
@@ -59,6 +65,27 @@ describe('image-analysis-backend-resolver', () => {
expect(status.model).toBe('gemini-2.5-flash');
});
it('keeps direct Anthropic settings profiles on native read unless explicitly mapped', () => {
const status = resolveImageAnalysisStatus(
{
profileName: 'claude-direct',
profileType: 'settings',
settings: {
env: {
ANTHROPIC_API_KEY: 'anthropic-test-key',
},
},
},
DEFAULT_IMAGE_ANALYSIS_CONFIG
);
expect(status.supported).toBe(false);
expect(status.backendId).toBeNull();
expect(status.status).toBe('skipped');
expect(status.shouldPersistHook).toBe(false);
expect(status.reason).toContain('native file access');
});
it('uses explicit profile_backends overrides for custom aliases', () => {
const config: ImageAnalysisConfig = {
...DEFAULT_IMAGE_ANALYSIS_CONFIG,
@@ -86,6 +113,12 @@ describe('image-analysis-backend-resolver', () => {
{
profileName: 'glm',
profileType: 'settings',
settings: {
env: {
ANTHROPIC_BASE_URL: 'https://api.z.ai/v1',
ANTHROPIC_AUTH_TOKEN: 'glm-test-key',
},
},
hookInstalled: false,
sharedHookInstalled: true,
},
@@ -113,6 +113,33 @@ describe('settings-routes image-analysis status', () => {
expect(body.imageAnalysisStatus.persistencePath).toContain('glm.settings.json');
});
it('keeps direct Anthropic settings profiles on native read diagnostics', async () => {
writeJson(path.join(tempHome, '.ccs', 'claude-direct.settings.json'), {
env: {
ANTHROPIC_API_KEY: 'anthropic-test-key',
},
});
const response = await fetch(`${baseUrl}/api/settings/claude-direct/raw`);
expect(response.status).toBe(200);
const body = (await response.json()) as {
imageAnalysisStatus: {
status: string;
backendId: string | null;
shouldPersistHook: boolean;
runtimePath: string | null;
reason: string | null;
};
};
expect(body.imageAnalysisStatus.status).toBe('skipped');
expect(body.imageAnalysisStatus.backendId).toBeNull();
expect(body.imageAnalysisStatus.shouldPersistHook).toBe(false);
expect(body.imageAnalysisStatus.runtimePath).toBeNull();
expect(body.imageAnalysisStatus.reason).toContain('native file access');
});
it('returns explicit mapped status for custom aliases', async () => {
writeJson(path.join(tempHome, '.ccs', 'config.yaml'), {
version: 11,
@@ -183,4 +210,35 @@ describe('settings-routes image-analysis status', () => {
expect(body.imageAnalysisStatus.persistencePath).toBe(customSettingsPath);
expect(body.imageAnalysisStatus.hookInstalled).toBe(true);
});
it('previews image-analysis status from unsaved editor settings', async () => {
writeProfileSettings(tempHome, 'glm', {
ANTHROPIC_BASE_URL: 'https://api.z.ai/v1',
ANTHROPIC_API_KEY: 'glm-test-key',
});
const response = await fetch(`${baseUrl}/api/settings/glm/image-analysis-status`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
settings: {
env: {
ANTHROPIC_BASE_URL: 'https://proxy.example/api/provider/ghcp',
ANTHROPIC_AUTH_TOKEN: 'preview-token',
},
},
}),
});
expect(response.status).toBe(200);
const body = (await response.json()) as {
imageAnalysisStatus: {
backendId: string | null;
resolutionSource: string;
};
};
expect(body.imageAnalysisStatus.backendId).toBe('ghcp');
expect(body.imageAnalysisStatus.resolutionSource).toBe('cliproxy-bridge');
});
});