mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-15 06:16:03 +00:00
test(image-analysis): cover runtime auth and fallback
This commit is contained in:
1 parent
813b2dd4d0
commit
f379a4001f
15 files changed
+1077
-52
No files matched your search
@@ -116,7 +116,7 @@ describe('image-analysis-runtime-status', () => {
|
||||
expect(status.effectiveRuntimeReason).toContain('remote.example:443');
|
||||
});
|
||||
|
||||
it('keeps hook-missing on native read even when auth and proxy are ready', async () => {
|
||||
it('keeps hook-missing as a degraded fallback state while primary runtime stays active', async () => {
|
||||
const status = await hydrateImageAnalysisRuntimeStatus(
|
||||
createStatus({
|
||||
status: 'hook-missing',
|
||||
@@ -144,7 +144,7 @@ describe('image-analysis-runtime-status', () => {
|
||||
|
||||
expect(status.authReadiness).toBe('ready');
|
||||
expect(status.proxyReadiness).toBe('ready');
|
||||
expect(status.effectiveRuntimeMode).toBe('native-read');
|
||||
expect(status.effectiveRuntimeMode).toBe('cliproxy-image-analysis');
|
||||
expect(status.effectiveRuntimeReason).toContain('Profile hook is missing');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,64 @@
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'bun:test';
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import {
|
||||
hasImageAnalyzerHook,
|
||||
installImageAnalyzerHook,
|
||||
} from '../../../../src/utils/hooks/image-analyzer-hook-installer';
|
||||
import { prepareImageAnalysisFallbackHook } from '../../../../src/utils/hooks';
|
||||
|
||||
describe('image-analyzer-hook-installer', () => {
|
||||
let tempHome = '';
|
||||
let originalCcsHome: string | undefined;
|
||||
let runtimePath = '';
|
||||
let bundledRuntimePath = '';
|
||||
|
||||
beforeEach(() => {
|
||||
tempHome = fs.mkdtempSync(path.join(os.tmpdir(), 'ccs-image-analyzer-hook-'));
|
||||
originalCcsHome = process.env.CCS_HOME;
|
||||
process.env.CCS_HOME = tempHome;
|
||||
|
||||
const ccsDir = path.join(tempHome, '.ccs');
|
||||
fs.mkdirSync(ccsDir, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(ccsDir, 'config.yaml'),
|
||||
'version: 12\nimage_analysis:\n enabled: true\n',
|
||||
'utf8'
|
||||
);
|
||||
|
||||
runtimePath = path.join(ccsDir, 'hooks', 'image-analysis-runtime.cjs');
|
||||
bundledRuntimePath = path.join(process.cwd(), 'lib', 'hooks', 'image-analysis-runtime.cjs');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
if (originalCcsHome === undefined) {
|
||||
delete process.env.CCS_HOME;
|
||||
} else {
|
||||
process.env.CCS_HOME = originalCcsHome;
|
||||
}
|
||||
|
||||
if (tempHome) {
|
||||
fs.rmSync(tempHome, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it('treats a missing runtime artifact as not ready and repairs it on prepare', () => {
|
||||
expect(installImageAnalyzerHook()).toBe(true);
|
||||
fs.unlinkSync(runtimePath);
|
||||
|
||||
expect(hasImageAnalyzerHook()).toBe(false);
|
||||
expect(prepareImageAnalysisFallbackHook()).toBe(true);
|
||||
expect(fs.existsSync(runtimePath)).toBe(true);
|
||||
expect(hasImageAnalyzerHook()).toBe(true);
|
||||
});
|
||||
|
||||
it('refreshes stale runtime content during fallback hook preparation', () => {
|
||||
expect(installImageAnalyzerHook()).toBe(true);
|
||||
fs.writeFileSync(runtimePath, 'stale runtime\n', 'utf8');
|
||||
|
||||
expect(hasImageAnalyzerHook()).toBe(false);
|
||||
expect(prepareImageAnalysisFallbackHook()).toBe(true);
|
||||
expect(fs.readFileSync(runtimePath, 'utf8')).toBe(fs.readFileSync(bundledRuntimePath, 'utf8'));
|
||||
});
|
||||
});
|
||||
@@ -67,4 +67,23 @@ describe('image-analyzer-profile-hook-injector', () => {
|
||||
expect(fs.existsSync(defaultSettingsPath)).toBe(false);
|
||||
expect(persisted.hooks?.PreToolUse?.some((hook) => hook.matcher === 'Read')).toBe(true);
|
||||
});
|
||||
|
||||
it('skips copilot hook persistence when the shared fallback hook is unavailable', () => {
|
||||
const settingsPath = path.join(tempHome, '.ccs', 'copilot.settings.json');
|
||||
writeJson(settingsPath, {});
|
||||
|
||||
const ensured = ensureProfileHooks({
|
||||
profileName: 'copilot',
|
||||
profileType: 'copilot',
|
||||
settingsPath,
|
||||
sharedHookInstalled: false,
|
||||
});
|
||||
|
||||
const persisted = JSON.parse(fs.readFileSync(settingsPath, 'utf8')) as {
|
||||
hooks?: { PreToolUse?: Array<{ matcher?: string }> };
|
||||
};
|
||||
|
||||
expect(ensured).toBe(false);
|
||||
expect(persisted.hooks).toBeUndefined();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user