chore: import upstream snapshot with attribution
Publish `@librechat/data-schemas` to NPM / pack (push) Failing after 8s
Publish `@librechat/client` to NPM / pack (push) Failing after 0s
GitNexus Index / index (push) Failing after 1s
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Has been skipped
Sync Helm Chart Tags / Sync chart tags (push) Failing after 2s
Publish `librechat-data-provider` to NPM / pack (push) Failing after 1s
Docker Dev Images Build / build (Dockerfile, librechat-dev, node) (push) Failing after 1s
Docker Dev Images Build / build (Dockerfile.multi, librechat-dev-api, api-build) (push) Failing after 0s
Sync Helm Chart Tags / Ignore non-main push (push) Has been skipped
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Failing after 1s
Publish `@librechat/client` to NPM / publish-npm (push) Has been cancelled
Publish `librechat-data-provider` to NPM / publish-npm (push) Has been cancelled
GitNexus Index / post-index (push) Has been cancelled
Publish `@librechat/data-schemas` to NPM / publish-npm (push) Has been cancelled
Publish `@librechat/data-schemas` to NPM / pack (push) Failing after 8s
Publish `@librechat/client` to NPM / pack (push) Failing after 0s
GitNexus Index / index (push) Failing after 1s
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Has been skipped
Sync Helm Chart Tags / Sync chart tags (push) Failing after 2s
Publish `librechat-data-provider` to NPM / pack (push) Failing after 1s
Docker Dev Images Build / build (Dockerfile, librechat-dev, node) (push) Failing after 1s
Docker Dev Images Build / build (Dockerfile.multi, librechat-dev-api, api-build) (push) Failing after 0s
Sync Helm Chart Tags / Ignore non-main push (push) Has been skipped
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Failing after 1s
Publish `@librechat/client` to NPM / publish-npm (push) Has been cancelled
Publish `librechat-data-provider` to NPM / publish-npm (push) Has been cancelled
GitNexus Index / post-index (push) Has been cancelled
Publish `@librechat/data-schemas` to NPM / publish-npm (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
const mockAccess = jest.fn();
|
||||
const mockLoadServiceKey = jest.fn();
|
||||
const mockIsUserProvided = jest.fn((value) => value === 'user_provided');
|
||||
const mockLogger = {
|
||||
debug: jest.fn(),
|
||||
error: jest.fn(),
|
||||
warn: jest.fn(),
|
||||
};
|
||||
|
||||
function mockOptionalModule(moduleName, factory) {
|
||||
try {
|
||||
require.resolve(moduleName);
|
||||
jest.doMock(moduleName, factory);
|
||||
} catch {
|
||||
jest.doMock(moduleName, factory, { virtual: true });
|
||||
}
|
||||
}
|
||||
|
||||
function mockDependencies() {
|
||||
jest.doMock('fs/promises', () => ({
|
||||
access: mockAccess,
|
||||
}));
|
||||
|
||||
mockOptionalModule('@librechat/api', () => ({
|
||||
isEnabled: (value) => value === true || value === 'true' || value === '1',
|
||||
isUserProvided: mockIsUserProvided,
|
||||
loadServiceKey: mockLoadServiceKey,
|
||||
}));
|
||||
|
||||
mockOptionalModule('@librechat/data-schemas', () => ({
|
||||
logger: mockLogger,
|
||||
}));
|
||||
|
||||
mockOptionalModule('librechat-data-provider', () => ({
|
||||
EModelEndpoint: {
|
||||
agents: 'agents',
|
||||
anthropic: 'anthropic',
|
||||
assistants: 'assistants',
|
||||
azureAssistants: 'azureAssistants',
|
||||
azureOpenAI: 'azureOpenAI',
|
||||
bedrock: 'bedrock',
|
||||
google: 'google',
|
||||
openAI: 'openAI',
|
||||
},
|
||||
}));
|
||||
|
||||
jest.doMock('~/server/utils/handleText', () => ({
|
||||
generateConfig: (key) => (key ? { userProvide: key === 'user_provided' } : false),
|
||||
}));
|
||||
}
|
||||
|
||||
describe('loadAsyncEndpoints', () => {
|
||||
const originalEnv = process.env;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
jest.resetModules();
|
||||
mockDependencies();
|
||||
process.env = { ...originalEnv };
|
||||
delete process.env.GOOGLE_KEY;
|
||||
delete process.env.GOOGLE_SERVICE_KEY_FILE;
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
process.env = originalEnv;
|
||||
});
|
||||
|
||||
function loadModule(env = {}) {
|
||||
process.env = { ...process.env, ...env };
|
||||
return require('./loadAsyncEndpoints');
|
||||
}
|
||||
|
||||
it('does not load the default Google service key when the default file is missing', async () => {
|
||||
mockAccess.mockRejectedValue(Object.assign(new Error('missing'), { code: 'ENOENT' }));
|
||||
const loadAsyncEndpoints = loadModule();
|
||||
|
||||
const result = await loadAsyncEndpoints();
|
||||
|
||||
expect(result).toEqual({ google: false });
|
||||
expect(mockLoadServiceKey).not.toHaveBeenCalled();
|
||||
expect(mockLogger.error).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('loads the default Google service key when the default file exists', async () => {
|
||||
const serviceKey = { project_id: 'test-project' };
|
||||
mockAccess.mockResolvedValue();
|
||||
mockLoadServiceKey.mockResolvedValue(serviceKey);
|
||||
const loadAsyncEndpoints = loadModule();
|
||||
|
||||
const result = await loadAsyncEndpoints();
|
||||
|
||||
expect(result).toEqual({ google: { userProvide: false } });
|
||||
expect(mockLoadServiceKey).toHaveBeenCalledWith(expect.stringContaining('api/data/auth.json'));
|
||||
});
|
||||
|
||||
it('loads an explicitly configured Google service key path without probing the default file', async () => {
|
||||
const serviceKey = { project_id: 'test-project' };
|
||||
mockLoadServiceKey.mockResolvedValue(serviceKey);
|
||||
const loadAsyncEndpoints = loadModule({
|
||||
GOOGLE_SERVICE_KEY_FILE: '/secrets/google-service-account.json',
|
||||
});
|
||||
|
||||
const result = await loadAsyncEndpoints();
|
||||
|
||||
expect(result).toEqual({ google: { userProvide: false } });
|
||||
expect(mockAccess).not.toHaveBeenCalled();
|
||||
expect(mockLoadServiceKey).toHaveBeenCalledWith('/secrets/google-service-account.json');
|
||||
});
|
||||
|
||||
it('uses GOOGLE_KEY without probing for a service key', async () => {
|
||||
const loadAsyncEndpoints = loadModule({ GOOGLE_KEY: 'user_provided' });
|
||||
|
||||
const result = await loadAsyncEndpoints();
|
||||
|
||||
expect(result).toEqual({ google: { userProvide: true } });
|
||||
expect(mockAccess).not.toHaveBeenCalled();
|
||||
expect(mockLoadServiceKey).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user