mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 06:16:37 +00:00
- Split types.ts (331 LOC) into 4 concern-based files under types/: platform-types, binary-types, provider-types, config-types - Preserve backward compat via barrel re-export (types.ts → types/index) - Reorganize 53 root-level files into 8 subdirectories: accounts/, ai-providers/, auth/, binary/, config/, executor/, management/, proxy/, quota/, routing/, services/, sync/ - Reduce src/cliproxy/ root from 65 to 8 files (target: ≤10) - Colocate 87 unit tests from tests/unit/cliproxy/ into src/cliproxy/*/__tests__/ (13 colocated test directories) - Update import paths across 40+ consumer files - Add TDD backward-compat test for types split Refs #1135
145 lines
4.6 KiB
TypeScript
145 lines
4.6 KiB
TypeScript
import { describe, expect, it } from 'bun:test';
|
|
import { readFileSync } from 'fs';
|
|
import { dirname } from 'path';
|
|
import type { ImageAnalysisStatus } from '../../../../src/utils/hooks/image-analysis-backend-resolver';
|
|
import type { AuthStatus } from '../../../../src/cliproxy/auth/auth-handler';
|
|
import {
|
|
ModuleKind,
|
|
ScriptTarget,
|
|
transpileModule,
|
|
type CompilerOptions,
|
|
} from 'typescript';
|
|
|
|
function createStatus(overrides: Partial<ImageAnalysisStatus> = {}): ImageAnalysisStatus {
|
|
return {
|
|
enabled: true,
|
|
supported: true,
|
|
status: 'active',
|
|
backendId: 'ghcp',
|
|
backendDisplayName: 'GitHub Copilot (OAuth)',
|
|
model: 'claude-haiku-4.5',
|
|
resolutionSource: 'profile-backend',
|
|
reason: null,
|
|
shouldPersistHook: true,
|
|
persistencePath: '/tmp/orq.settings.json',
|
|
runtimePath: '/api/provider/ghcp',
|
|
usesCurrentTarget: true,
|
|
usesCurrentAuthToken: true,
|
|
hookInstalled: true,
|
|
sharedHookInstalled: true,
|
|
authReadiness: 'unknown',
|
|
authProvider: 'ghcp',
|
|
authDisplayName: 'GitHub Copilot (OAuth)',
|
|
authReason: 'Auth readiness has not been verified yet.',
|
|
proxyReadiness: 'unknown',
|
|
proxyReason: 'CLIProxy runtime readiness has not been verified yet.',
|
|
effectiveRuntimeMode: 'native-read',
|
|
effectiveRuntimeReason: null,
|
|
profileModel: 'claude-haiku-4.5',
|
|
nativeReadPreference: false,
|
|
nativeImageCapable: true,
|
|
nativeImageReason: 'claude-haiku-4.5 can read images natively.',
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe('image-analysis-runtime-status circular dependency regression', () => {
|
|
it('reads auth deps from the CommonJS module object at call time', async () => {
|
|
const authHandlerModule: {
|
|
initializeAccounts: undefined | (() => void);
|
|
getAuthStatus: undefined | ((provider: 'ghcp') => AuthStatus);
|
|
} = {
|
|
initializeAccounts: undefined,
|
|
getAuthStatus: undefined,
|
|
};
|
|
|
|
const sourcePath = new URL(
|
|
'../../../../src/utils/hooks/image-analysis-runtime-status.ts',
|
|
import.meta.url
|
|
);
|
|
const source = readFileSync(sourcePath, 'utf8');
|
|
const compilerOptions: CompilerOptions = {
|
|
module: ModuleKind.CommonJS,
|
|
target: ScriptTarget.ES2020,
|
|
esModuleInterop: true,
|
|
};
|
|
const transpiled = transpileModule(source, { compilerOptions }).outputText;
|
|
|
|
const module = { exports: {} as Record<string, unknown> };
|
|
const requireMap: Record<string, unknown> = {
|
|
'../../cliproxy/auth/auth-handler': authHandlerModule,
|
|
'../../cliproxy/services/remote-proxy-client': {
|
|
checkRemoteProxy: async () => ({ reachable: false, error: 'not-used' }),
|
|
},
|
|
'../../cliproxy/services/remote-auth-fetcher': {
|
|
fetchRemoteAuthStatus: async () => [],
|
|
},
|
|
'../../cliproxy/proxy/proxy-target-resolver': {
|
|
getProxyTarget: () => ({
|
|
host: '127.0.0.1',
|
|
port: 8317,
|
|
protocol: 'http',
|
|
isRemote: false,
|
|
}),
|
|
},
|
|
'../../cliproxy/provider-capabilities': {
|
|
getProviderDisplayName: () => 'GitHub Copilot (OAuth)',
|
|
isCLIProxyProvider: () => true,
|
|
},
|
|
'../../cliproxy/services/stats-fetcher': {
|
|
isCliproxyRunning: async () => true,
|
|
},
|
|
'../../config/unified-config-types': {
|
|
DEFAULT_IMAGE_ANALYSIS_CONFIG: {},
|
|
},
|
|
'./image-analysis-backend-resolver': {
|
|
resolveImageAnalysisStatus: () => createStatus(),
|
|
},
|
|
};
|
|
|
|
const compiledModule = new Function(
|
|
'exports',
|
|
'require',
|
|
'module',
|
|
'__filename',
|
|
'__dirname',
|
|
transpiled
|
|
);
|
|
compiledModule(
|
|
module.exports,
|
|
(specifier: string) => {
|
|
const dependency = requireMap[specifier];
|
|
if (!dependency) {
|
|
throw new Error(`Unexpected dependency: ${specifier}`);
|
|
}
|
|
return dependency;
|
|
},
|
|
module,
|
|
sourcePath.pathname,
|
|
dirname(sourcePath.pathname)
|
|
);
|
|
|
|
authHandlerModule.initializeAccounts = () => {};
|
|
authHandlerModule.getAuthStatus = () => ({
|
|
provider: 'ghcp',
|
|
authenticated: true,
|
|
tokenDir: '/tmp/auth',
|
|
tokenFiles: ['github-copilot-test.json'],
|
|
accounts: [],
|
|
defaultAccount: undefined,
|
|
});
|
|
|
|
const { hydrateImageAnalysisRuntimeStatus } = module.exports as {
|
|
hydrateImageAnalysisRuntimeStatus: (
|
|
baseStatus: ImageAnalysisStatus,
|
|
deps?: Record<string, unknown>
|
|
) => Promise<ImageAnalysisStatus>;
|
|
};
|
|
const status = await hydrateImageAnalysisRuntimeStatus(createStatus(), {});
|
|
|
|
expect(status.authReadiness).toBe('ready');
|
|
expect(status.proxyReadiness).toBe('ready');
|
|
expect(status.effectiveRuntimeMode).toBe('cliproxy-image-analysis');
|
|
});
|
|
});
|