refactor: Rename initializeAppConfig to setAppConfig and update related tests

This commit is contained in:
Danny Avila 2025-08-17 18:03:14 -04:00
parent eeab69ff7f
commit 2501d11fa0
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
4 changed files with 85 additions and 108 deletions

View file

@ -17,7 +17,6 @@ jest.mock('~/config', () => ({
}, },
})); }));
jest.mock('./Config/loadCustomConfig', () => jest.fn());
jest.mock('./start/interface', () => ({ jest.mock('./start/interface', () => ({
loadDefaultInterface: jest.fn(), loadDefaultInterface: jest.fn(),
})); }));
@ -32,9 +31,11 @@ jest.mock('./start/checks', () => ({
checkWebSearchConfig: jest.fn(), checkWebSearchConfig: jest.fn(),
})); }));
jest.mock('./Config/getAppConfig', () => ({ jest.mock('./Config', () => ({
initializeAppConfig: jest.fn(), setAppConfig: jest.fn(),
getAppConfig: jest.fn(), getAppConfig: jest.fn(),
setCachedTools: jest.fn(),
loadCustomConfig: jest.fn(),
})); }));
const AppService = require('./AppService'); const AppService = require('./AppService');
@ -42,12 +43,12 @@ const { loadDefaultInterface } = require('./start/interface');
describe('AppService interface configuration', () => { describe('AppService interface configuration', () => {
let mockLoadCustomConfig; let mockLoadCustomConfig;
const { initializeAppConfig } = require('./Config/getAppConfig'); const { setAppConfig } = require('./Config');
beforeEach(() => { beforeEach(() => {
jest.resetModules(); jest.resetModules();
jest.clearAllMocks(); jest.clearAllMocks();
mockLoadCustomConfig = require('./Config/loadCustomConfig'); ({ loadCustomConfig: mockLoadCustomConfig } = require('./Config'));
}); });
it('should set prompts and bookmarks to true when loadDefaultInterface returns true for both', async () => { it('should set prompts and bookmarks to true when loadDefaultInterface returns true for both', async () => {
@ -56,7 +57,7 @@ describe('AppService interface configuration', () => {
await AppService(); await AppService();
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
interfaceConfig: expect.objectContaining({ interfaceConfig: expect.objectContaining({
prompts: true, prompts: true,
@ -73,7 +74,7 @@ describe('AppService interface configuration', () => {
await AppService(); await AppService();
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
interfaceConfig: expect.objectContaining({ interfaceConfig: expect.objectContaining({
prompts: false, prompts: false,
@ -90,14 +91,14 @@ describe('AppService interface configuration', () => {
await AppService(); await AppService();
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
interfaceConfig: expect.anything(), interfaceConfig: expect.anything(),
}), }),
); );
// Verify that prompts and bookmarks are undefined when not provided // Verify that prompts and bookmarks are undefined when not provided
const initCall = initializeAppConfig.mock.calls[0][0]; const initCall = setAppConfig.mock.calls[0][0];
expect(initCall.interfaceConfig.prompts).toBeUndefined(); expect(initCall.interfaceConfig.prompts).toBeUndefined();
expect(initCall.interfaceConfig.bookmarks).toBeUndefined(); expect(initCall.interfaceConfig.bookmarks).toBeUndefined();
expect(loadDefaultInterface).toHaveBeenCalled(); expect(loadDefaultInterface).toHaveBeenCalled();
@ -109,7 +110,7 @@ describe('AppService interface configuration', () => {
await AppService(); await AppService();
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
interfaceConfig: expect.objectContaining({ interfaceConfig: expect.objectContaining({
prompts: true, prompts: true,
@ -140,7 +141,7 @@ describe('AppService interface configuration', () => {
await AppService(); await AppService();
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
interfaceConfig: expect.objectContaining({ interfaceConfig: expect.objectContaining({
peoplePicker: expect.objectContaining({ peoplePicker: expect.objectContaining({
@ -174,7 +175,7 @@ describe('AppService interface configuration', () => {
await AppService(); await AppService();
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
interfaceConfig: expect.objectContaining({ interfaceConfig: expect.objectContaining({
peoplePicker: expect.objectContaining({ peoplePicker: expect.objectContaining({
@ -199,7 +200,7 @@ describe('AppService interface configuration', () => {
await AppService(); await AppService();
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
interfaceConfig: expect.objectContaining({ interfaceConfig: expect.objectContaining({
peoplePicker: expect.objectContaining({ peoplePicker: expect.objectContaining({

View file

@ -19,10 +19,9 @@ const {
} = require('./start/checks'); } = require('./start/checks');
const { ensureDefaultCategories, seedDefaultRoles, initializeRoles } = require('~/models'); const { ensureDefaultCategories, seedDefaultRoles, initializeRoles } = require('~/models');
const { azureAssistantsDefaults, assistantsConfigSetup } = require('./start/assistants'); const { azureAssistantsDefaults, assistantsConfigSetup } = require('./start/assistants');
const { setCachedTools, setAppConfig, loadCustomConfig } = require('./Config');
const { initializeAzureBlobService } = require('./Files/Azure/initialize'); const { initializeAzureBlobService } = require('./Files/Azure/initialize');
const { initializeFirebase } = require('./Files/Firebase/initialize'); const { initializeFirebase } = require('./Files/Firebase/initialize');
const { initializeAppConfig } = require('./Config/getAppConfig');
const loadCustomConfig = require('./Config/loadCustomConfig');
const handleRateLimits = require('./Config/handleRateLimits'); const handleRateLimits = require('./Config/handleRateLimits');
const { loadDefaultInterface } = require('./start/interface'); const { loadDefaultInterface } = require('./start/interface');
const { loadTurnstileConfig } = require('./start/turnstile'); const { loadTurnstileConfig } = require('./start/turnstile');
@ -30,7 +29,6 @@ const { azureConfigSetup } = require('./start/azureOpenAI');
const { processModelSpecs } = require('./start/modelSpecs'); const { processModelSpecs } = require('./start/modelSpecs');
const { initializeS3 } = require('./Files/S3/initialize'); const { initializeS3 } = require('./Files/S3/initialize');
const { loadAndFormatTools } = require('./ToolService'); const { loadAndFormatTools } = require('./ToolService');
const { setCachedTools } = require('./Config');
const paths = require('~/config/paths'); const paths = require('~/config/paths');
/** /**
@ -113,7 +111,7 @@ const AppService = async () => {
...defaultLocals, ...defaultLocals,
[EModelEndpoint.agents]: agentsDefaults, [EModelEndpoint.agents]: agentsDefaults,
}; };
await initializeAppConfig(appConfig); await setAppConfig(appConfig);
return; return;
} }
@ -176,7 +174,7 @@ const AppService = async () => {
...endpointLocals, ...endpointLocals,
}; };
await initializeAppConfig(appConfig); await setAppConfig(appConfig);
}; };
module.exports = AppService; module.exports = AppService;

View file

@ -12,17 +12,6 @@ const {
const AppService = require('./AppService'); const AppService = require('./AppService');
jest.mock('./Config/loadCustomConfig', () => {
return jest.fn(() =>
Promise.resolve({
registration: { socialLogins: ['testLogin'] },
fileStrategy: 'testStrategy',
balance: {
enabled: true,
},
}),
);
});
jest.mock('./Files/Firebase/initialize', () => ({ jest.mock('./Files/Firebase/initialize', () => ({
initializeFirebase: jest.fn(), initializeFirebase: jest.fn(),
})); }));
@ -36,7 +25,18 @@ jest.mock('~/models/Role', () => ({
getRoleByName: jest.fn().mockResolvedValue(null), getRoleByName: jest.fn().mockResolvedValue(null),
})); }));
jest.mock('./Config', () => ({ jest.mock('./Config', () => ({
setAppConfig: jest.fn(),
getAppConfig: jest.fn(),
setCachedTools: jest.fn(), setCachedTools: jest.fn(),
loadCustomConfig: jest.fn(() =>
Promise.resolve({
registration: { socialLogins: ['testLogin'] },
fileStrategy: 'testStrategy',
balance: {
enabled: true,
},
}),
),
getCachedTools: jest.fn().mockResolvedValue({ getCachedTools: jest.fn().mockResolvedValue({
ExampleTool: { ExampleTool: {
type: 'function', type: 'function',
@ -55,10 +55,6 @@ jest.mock('./Config', () => ({
}), }),
})); }));
jest.mock('./Config/getAppConfig', () => ({
initializeAppConfig: jest.fn(),
getAppConfig: jest.fn(),
}));
jest.mock('./ToolService', () => ({ jest.mock('./ToolService', () => ({
loadAndFormatTools: jest.fn().mockReturnValue({ loadAndFormatTools: jest.fn().mockReturnValue({
ExampleTool: { ExampleTool: {
@ -126,7 +122,7 @@ describe('AppService', () => {
siteKey: 'default-site-key', siteKey: 'default-site-key',
options: {}, options: {},
}; };
const { initializeAppConfig } = require('./Config/getAppConfig'); const { setAppConfig, loadCustomConfig } = require('./Config');
beforeEach(() => { beforeEach(() => {
process.env.CDN_PROVIDER = undefined; process.env.CDN_PROVIDER = undefined;
@ -138,7 +134,7 @@ describe('AppService', () => {
expect(process.env.CDN_PROVIDER).toEqual('testStrategy'); expect(process.env.CDN_PROVIDER).toEqual('testStrategy');
expect(initializeAppConfig).toHaveBeenCalledWith({ expect(setAppConfig).toHaveBeenCalledWith({
config: expect.objectContaining({ config: expect.objectContaining({
fileStrategy: 'testStrategy', fileStrategy: 'testStrategy',
}), }),
@ -184,7 +180,7 @@ describe('AppService', () => {
}); });
it('should log a warning if the config version is outdated', async () => { it('should log a warning if the config version is outdated', async () => {
require('./Config/loadCustomConfig').mockImplementationOnce(() => loadCustomConfig.mockImplementationOnce(() =>
Promise.resolve({ Promise.resolve({
version: '0.9.0', // An outdated version for this test version: '0.9.0', // An outdated version for this test
registration: { socialLogins: ['testLogin'] }, registration: { socialLogins: ['testLogin'] },
@ -199,7 +195,7 @@ describe('AppService', () => {
}); });
it('should change the `imageOutputType` based on config value', async () => { it('should change the `imageOutputType` based on config value', async () => {
require('./Config/loadCustomConfig').mockImplementationOnce(() => loadCustomConfig.mockImplementationOnce(() =>
Promise.resolve({ Promise.resolve({
version: '0.10.0', version: '0.10.0',
imageOutputType: EImageOutputType.WEBP, imageOutputType: EImageOutputType.WEBP,
@ -207,7 +203,7 @@ describe('AppService', () => {
); );
await AppService(); await AppService();
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
imageOutputType: EImageOutputType.WEBP, imageOutputType: EImageOutputType.WEBP,
}), }),
@ -215,14 +211,14 @@ describe('AppService', () => {
}); });
it('should default to `PNG` `imageOutputType` with no provided type', async () => { it('should default to `PNG` `imageOutputType` with no provided type', async () => {
require('./Config/loadCustomConfig').mockImplementationOnce(() => loadCustomConfig.mockImplementationOnce(() =>
Promise.resolve({ Promise.resolve({
version: '0.10.0', version: '0.10.0',
}), }),
); );
await AppService(); await AppService();
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
imageOutputType: EImageOutputType.PNG, imageOutputType: EImageOutputType.PNG,
}), }),
@ -230,10 +226,10 @@ describe('AppService', () => {
}); });
it('should default to `PNG` `imageOutputType` with no provided config', async () => { it('should default to `PNG` `imageOutputType` with no provided config', async () => {
require('./Config/loadCustomConfig').mockImplementationOnce(() => Promise.resolve(undefined)); loadCustomConfig.mockImplementationOnce(() => Promise.resolve(undefined));
await AppService(); await AppService();
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
imageOutputType: EImageOutputType.PNG, imageOutputType: EImageOutputType.PNG,
}), }),
@ -241,7 +237,7 @@ describe('AppService', () => {
}); });
it('should initialize Firebase when fileStrategy is firebase', async () => { it('should initialize Firebase when fileStrategy is firebase', async () => {
require('./Config/loadCustomConfig').mockImplementationOnce(() => loadCustomConfig.mockImplementationOnce(() =>
Promise.resolve({ Promise.resolve({
fileStrategy: FileSources.firebase, fileStrategy: FileSources.firebase,
}), }),
@ -308,7 +304,7 @@ describe('AppService', () => {
}); });
it('should correctly configure Assistants endpoint based on custom config', async () => { it('should correctly configure Assistants endpoint based on custom config', async () => {
require('./Config/loadCustomConfig').mockImplementationOnce(() => loadCustomConfig.mockImplementationOnce(() =>
Promise.resolve({ Promise.resolve({
endpoints: { endpoints: {
[EModelEndpoint.assistants]: { [EModelEndpoint.assistants]: {
@ -324,7 +320,7 @@ describe('AppService', () => {
await AppService(); await AppService();
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
[EModelEndpoint.assistants]: expect.objectContaining({ [EModelEndpoint.assistants]: expect.objectContaining({
disableBuilder: true, disableBuilder: true,
@ -338,7 +334,7 @@ describe('AppService', () => {
}); });
it('should correctly configure Agents endpoint based on custom config', async () => { it('should correctly configure Agents endpoint based on custom config', async () => {
require('./Config/loadCustomConfig').mockImplementationOnce(() => loadCustomConfig.mockImplementationOnce(() =>
Promise.resolve({ Promise.resolve({
endpoints: { endpoints: {
[EModelEndpoint.agents]: { [EModelEndpoint.agents]: {
@ -354,7 +350,7 @@ describe('AppService', () => {
await AppService(); await AppService();
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
[EModelEndpoint.agents]: expect.objectContaining({ [EModelEndpoint.agents]: expect.objectContaining({
disableBuilder: true, disableBuilder: true,
@ -371,11 +367,11 @@ describe('AppService', () => {
}); });
it('should configure Agents endpoint with defaults when no config is provided', async () => { it('should configure Agents endpoint with defaults when no config is provided', async () => {
require('./Config/loadCustomConfig').mockImplementationOnce(() => Promise.resolve({})); loadCustomConfig.mockImplementationOnce(() => Promise.resolve({}));
await AppService(); await AppService();
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
[EModelEndpoint.agents]: expect.objectContaining({ [EModelEndpoint.agents]: expect.objectContaining({
disableBuilder: false, disableBuilder: false,
@ -386,7 +382,7 @@ describe('AppService', () => {
}); });
it('should configure Agents endpoint with defaults when endpoints exist but agents is not defined', async () => { it('should configure Agents endpoint with defaults when endpoints exist but agents is not defined', async () => {
require('./Config/loadCustomConfig').mockImplementationOnce(() => loadCustomConfig.mockImplementationOnce(() =>
Promise.resolve({ Promise.resolve({
endpoints: { endpoints: {
[EModelEndpoint.openAI]: { [EModelEndpoint.openAI]: {
@ -398,7 +394,7 @@ describe('AppService', () => {
await AppService(); await AppService();
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
[EModelEndpoint.agents]: expect.objectContaining({ [EModelEndpoint.agents]: expect.objectContaining({
disableBuilder: false, disableBuilder: false,
@ -413,7 +409,7 @@ describe('AppService', () => {
it('should correctly configure minimum Azure OpenAI Assistant values', async () => { it('should correctly configure minimum Azure OpenAI Assistant values', async () => {
const assistantGroups = [azureGroups[0], { ...azureGroups[1], assistants: true }]; const assistantGroups = [azureGroups[0], { ...azureGroups[1], assistants: true }];
require('./Config/loadCustomConfig').mockImplementationOnce(() => loadCustomConfig.mockImplementationOnce(() =>
Promise.resolve({ Promise.resolve({
endpoints: { endpoints: {
[EModelEndpoint.azureOpenAI]: { [EModelEndpoint.azureOpenAI]: {
@ -428,7 +424,7 @@ describe('AppService', () => {
process.env.EASTUS_API_KEY = 'eastus-key'; process.env.EASTUS_API_KEY = 'eastus-key';
await AppService(); await AppService();
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
[EModelEndpoint.azureAssistants]: expect.objectContaining({ [EModelEndpoint.azureAssistants]: expect.objectContaining({
capabilities: expect.arrayContaining([ capabilities: expect.arrayContaining([
@ -442,7 +438,7 @@ describe('AppService', () => {
}); });
it('should correctly configure Azure OpenAI endpoint based on custom config', async () => { it('should correctly configure Azure OpenAI endpoint based on custom config', async () => {
require('./Config/loadCustomConfig').mockImplementationOnce(() => loadCustomConfig.mockImplementationOnce(() =>
Promise.resolve({ Promise.resolve({
endpoints: { endpoints: {
[EModelEndpoint.azureOpenAI]: { [EModelEndpoint.azureOpenAI]: {
@ -458,7 +454,7 @@ describe('AppService', () => {
await AppService(); await AppService();
const { modelNames, modelGroupMap, groupMap } = validateAzureGroups(azureGroups); const { modelNames, modelGroupMap, groupMap } = validateAzureGroups(azureGroups);
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
[EModelEndpoint.azureOpenAI]: expect.objectContaining({ [EModelEndpoint.azureOpenAI]: expect.objectContaining({
modelNames, modelNames,
@ -500,9 +496,7 @@ describe('AppService', () => {
}, },
}; };
require('./Config/loadCustomConfig').mockImplementationOnce(() => loadCustomConfig.mockImplementationOnce(() => Promise.resolve(rateLimitsConfig));
Promise.resolve(rateLimitsConfig),
);
await AppService(); await AppService();
@ -560,9 +554,7 @@ describe('AppService', () => {
}, },
}; };
require('./Config/loadCustomConfig').mockImplementationOnce(() => loadCustomConfig.mockImplementationOnce(() => Promise.resolve(importLimitsConfig));
Promise.resolve(importLimitsConfig),
);
await AppService(); await AppService();
@ -590,7 +582,7 @@ describe('AppService', () => {
}); });
it('should correctly configure endpoint with titlePrompt, titleMethod, and titlePromptTemplate', async () => { it('should correctly configure endpoint with titlePrompt, titleMethod, and titlePromptTemplate', async () => {
require('./Config/loadCustomConfig').mockImplementationOnce(() => loadCustomConfig.mockImplementationOnce(() =>
Promise.resolve({ Promise.resolve({
endpoints: { endpoints: {
[EModelEndpoint.openAI]: { [EModelEndpoint.openAI]: {
@ -619,7 +611,7 @@ describe('AppService', () => {
await AppService(); await AppService();
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
// Check OpenAI endpoint configuration // Check OpenAI endpoint configuration
[EModelEndpoint.openAI]: expect.objectContaining({ [EModelEndpoint.openAI]: expect.objectContaining({
@ -648,7 +640,7 @@ describe('AppService', () => {
}); });
it('should configure Agent endpoint with title generation settings', async () => { it('should configure Agent endpoint with title generation settings', async () => {
require('./Config/loadCustomConfig').mockImplementationOnce(() => loadCustomConfig.mockImplementationOnce(() =>
Promise.resolve({ Promise.resolve({
endpoints: { endpoints: {
[EModelEndpoint.agents]: { [EModelEndpoint.agents]: {
@ -667,7 +659,7 @@ describe('AppService', () => {
await AppService(); await AppService();
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
[EModelEndpoint.agents]: expect.objectContaining({ [EModelEndpoint.agents]: expect.objectContaining({
disableBuilder: false, disableBuilder: false,
@ -687,7 +679,7 @@ describe('AppService', () => {
}); });
it('should handle missing title configuration options with defaults', async () => { it('should handle missing title configuration options with defaults', async () => {
require('./Config/loadCustomConfig').mockImplementationOnce(() => loadCustomConfig.mockImplementationOnce(() =>
Promise.resolve({ Promise.resolve({
endpoints: { endpoints: {
[EModelEndpoint.openAI]: { [EModelEndpoint.openAI]: {
@ -700,7 +692,7 @@ describe('AppService', () => {
await AppService(); await AppService();
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
[EModelEndpoint.openAI]: expect.objectContaining({ [EModelEndpoint.openAI]: expect.objectContaining({
titleConvo: true, titleConvo: true,
@ -709,14 +701,14 @@ describe('AppService', () => {
); );
// Verify that optional fields are not set when not provided // Verify that optional fields are not set when not provided
const initCall = initializeAppConfig.mock.calls[0][0]; const initCall = setAppConfig.mock.calls[0][0];
expect(initCall[EModelEndpoint.openAI].titlePrompt).toBeUndefined(); expect(initCall[EModelEndpoint.openAI].titlePrompt).toBeUndefined();
expect(initCall[EModelEndpoint.openAI].titlePromptTemplate).toBeUndefined(); expect(initCall[EModelEndpoint.openAI].titlePromptTemplate).toBeUndefined();
expect(initCall[EModelEndpoint.openAI].titleMethod).toBeUndefined(); expect(initCall[EModelEndpoint.openAI].titleMethod).toBeUndefined();
}); });
it('should correctly configure titleEndpoint when specified', async () => { it('should correctly configure titleEndpoint when specified', async () => {
require('./Config/loadCustomConfig').mockImplementationOnce(() => loadCustomConfig.mockImplementationOnce(() =>
Promise.resolve({ Promise.resolve({
endpoints: { endpoints: {
[EModelEndpoint.openAI]: { [EModelEndpoint.openAI]: {
@ -735,7 +727,7 @@ describe('AppService', () => {
await AppService(); await AppService();
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
// Check OpenAI endpoint has titleEndpoint // Check OpenAI endpoint has titleEndpoint
[EModelEndpoint.openAI]: expect.objectContaining({ [EModelEndpoint.openAI]: expect.objectContaining({
@ -754,7 +746,7 @@ describe('AppService', () => {
}); });
it('should correctly configure all endpoint when specified', async () => { it('should correctly configure all endpoint when specified', async () => {
require('./Config/loadCustomConfig').mockImplementationOnce(() => loadCustomConfig.mockImplementationOnce(() =>
Promise.resolve({ Promise.resolve({
endpoints: { endpoints: {
all: { all: {
@ -776,7 +768,7 @@ describe('AppService', () => {
await AppService(); await AppService();
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
// Check that 'all' endpoint config is loaded // Check that 'all' endpoint config is loaded
all: expect.objectContaining({ all: expect.objectContaining({
@ -800,7 +792,7 @@ describe('AppService', () => {
describe('AppService updating app config and issuing warnings', () => { describe('AppService updating app config and issuing warnings', () => {
let initialEnv; let initialEnv;
const { initializeAppConfig } = require('./Config/getAppConfig'); const { setAppConfig, loadCustomConfig } = require('./Config');
beforeEach(() => { beforeEach(() => {
// Store initial environment variables to restore them after each test // Store initial environment variables to restore them after each test
@ -817,11 +809,11 @@ describe('AppService updating app config and issuing warnings', () => {
it('should initialize app config with default values if loadCustomConfig returns undefined', async () => { it('should initialize app config with default values if loadCustomConfig returns undefined', async () => {
// Mock loadCustomConfig to return undefined // Mock loadCustomConfig to return undefined
require('./Config/loadCustomConfig').mockImplementationOnce(() => Promise.resolve(undefined)); loadCustomConfig.mockImplementationOnce(() => Promise.resolve(undefined));
await AppService(); await AppService();
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
paths: expect.anything(), paths: expect.anything(),
config: {}, config: {},
@ -849,13 +841,11 @@ describe('AppService updating app config and issuing warnings', () => {
refillAmount: 5000, refillAmount: 5000,
}, },
}; };
require('./Config/loadCustomConfig').mockImplementationOnce(() => loadCustomConfig.mockImplementationOnce(() => Promise.resolve(customConfig));
Promise.resolve(customConfig),
);
await AppService(); await AppService();
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
paths: expect.anything(), paths: expect.anything(),
config: customConfig, config: customConfig,
@ -877,11 +867,11 @@ describe('AppService updating app config and issuing warnings', () => {
}, },
}, },
}; };
require('./Config/loadCustomConfig').mockImplementationOnce(() => Promise.resolve(mockConfig)); loadCustomConfig.mockImplementationOnce(() => Promise.resolve(mockConfig));
await AppService(); await AppService();
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
assistants: expect.objectContaining({ assistants: expect.objectContaining({
disableBuilder: true, disableBuilder: true,
@ -893,7 +883,7 @@ describe('AppService updating app config and issuing warnings', () => {
); );
// Verify excludedIds is undefined when not provided // Verify excludedIds is undefined when not provided
const initCall = initializeAppConfig.mock.calls[0][0]; const initCall = setAppConfig.mock.calls[0][0];
expect(initCall.assistants.excludedIds).toBeUndefined(); expect(initCall.assistants.excludedIds).toBeUndefined();
}); });
@ -909,9 +899,9 @@ describe('AppService updating app config and issuing warnings', () => {
}, },
}, },
}; };
require('./Config/loadCustomConfig').mockImplementationOnce(() => Promise.resolve(mockConfig)); loadCustomConfig.mockImplementationOnce(() => Promise.resolve(mockConfig));
await require('./AppService')(); await AppService();
const { logger } = require('~/config'); const { logger } = require('~/config');
expect(logger.warn).toHaveBeenCalledWith( expect(logger.warn).toHaveBeenCalledWith(
@ -930,9 +920,9 @@ describe('AppService updating app config and issuing warnings', () => {
}, },
}, },
}; };
require('./Config/loadCustomConfig').mockImplementationOnce(() => Promise.resolve(mockConfig)); loadCustomConfig.mockImplementationOnce(() => Promise.resolve(mockConfig));
await require('./AppService')(); await AppService();
const { logger } = require('~/config'); const { logger } = require('~/config');
expect(logger.warn).toHaveBeenCalledWith( expect(logger.warn).toHaveBeenCalledWith(
@ -943,7 +933,7 @@ describe('AppService updating app config and issuing warnings', () => {
}); });
it('should issue expected warnings when loading Azure Groups with deprecated Environment Variables', async () => { it('should issue expected warnings when loading Azure Groups with deprecated Environment Variables', async () => {
require('./Config/loadCustomConfig').mockImplementationOnce(() => loadCustomConfig.mockImplementationOnce(() =>
Promise.resolve({ Promise.resolve({
endpoints: { endpoints: {
[EModelEndpoint.azureOpenAI]: { [EModelEndpoint.azureOpenAI]: {
@ -957,7 +947,7 @@ describe('AppService updating app config and issuing warnings', () => {
process.env[varInfo.key] = 'test'; process.env[varInfo.key] = 'test';
}); });
await require('./AppService')(); await AppService();
const { logger } = require('~/config'); const { logger } = require('~/config');
deprecatedAzureVariables.forEach(({ key, description }) => { deprecatedAzureVariables.forEach(({ key, description }) => {
@ -968,7 +958,7 @@ describe('AppService updating app config and issuing warnings', () => {
}); });
it('should issue expected warnings when loading conflicting Azure Envrionment Variables', async () => { it('should issue expected warnings when loading conflicting Azure Envrionment Variables', async () => {
require('./Config/loadCustomConfig').mockImplementationOnce(() => loadCustomConfig.mockImplementationOnce(() =>
Promise.resolve({ Promise.resolve({
endpoints: { endpoints: {
[EModelEndpoint.azureOpenAI]: { [EModelEndpoint.azureOpenAI]: {
@ -982,7 +972,7 @@ describe('AppService updating app config and issuing warnings', () => {
process.env[varInfo.key] = 'test'; process.env[varInfo.key] = 'test';
}); });
await require('./AppService')(); await AppService();
const { logger } = require('~/config'); const { logger } = require('~/config');
conflictingAzureVariables.forEach(({ key }) => { conflictingAzureVariables.forEach(({ key }) => {
@ -1003,7 +993,7 @@ describe('AppService updating app config and issuing warnings', () => {
}, },
}; };
require('./Config/loadCustomConfig').mockImplementationOnce(() => Promise.resolve(mockConfig)); loadCustomConfig.mockImplementationOnce(() => Promise.resolve(mockConfig));
// Set actual environment variables with different values // Set actual environment variables with different values
process.env.OCR_API_KEY_CUSTOM_VAR_NAME = 'actual-api-key'; process.env.OCR_API_KEY_CUSTOM_VAR_NAME = 'actual-api-key';
@ -1012,7 +1002,7 @@ describe('AppService updating app config and issuing warnings', () => {
await AppService(); await AppService();
// Verify that the raw string references were preserved and not interpolated // Verify that the raw string references were preserved and not interpolated
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
ocr: expect.objectContaining({ ocr: expect.objectContaining({
apiKey: '${OCR_API_KEY_CUSTOM_VAR_NAME}', apiKey: '${OCR_API_KEY_CUSTOM_VAR_NAME}',
@ -1035,12 +1025,12 @@ describe('AppService updating app config and issuing warnings', () => {
}, },
}; };
require('./Config/loadCustomConfig').mockImplementationOnce(() => Promise.resolve(mockConfig)); loadCustomConfig.mockImplementationOnce(() => Promise.resolve(mockConfig));
await AppService(); await AppService();
// Check that interface config includes the permissions // Check that interface config includes the permissions
expect(initializeAppConfig).toHaveBeenCalledWith( expect(setAppConfig).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
interfaceConfig: expect.objectContaining({ interfaceConfig: expect.objectContaining({
peoplePicker: expect.objectContaining({ peoplePicker: expect.objectContaining({

View file

@ -70,17 +70,6 @@ async function getAppConfig(options = {}) {
return baseConfig; return baseConfig;
} }
/**
* Cache the app configuration
* @param {AppConfig} config - The configuration to cache
* @returns {Promise<void>}
*/
async function cacheAppConfig(config) {
const cache = getLogStores(CacheKeys.CONFIG_STORE);
await cache.set(CacheKeys.APP_CONFIG, config);
logger.debug('[getAppConfig] App configuration cached');
}
/** /**
* Clear the app configuration cache * Clear the app configuration cache
* @returns {Promise<boolean>} * @returns {Promise<boolean>}
@ -96,7 +85,7 @@ async function clearAppConfigCache() {
* @param {AppConfig} config - The initial configuration to store * @param {AppConfig} config - The initial configuration to store
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async function initializeAppConfig(config) { async function setAppConfig(config) {
const cache = getLogStores(CacheKeys.CONFIG_STORE); const cache = getLogStores(CacheKeys.CONFIG_STORE);
await cache.set(CacheKeys.APP_CONFIG, config); await cache.set(CacheKeys.APP_CONFIG, config);
logger.debug('[getAppConfig] App configuration initialized'); logger.debug('[getAppConfig] App configuration initialized');
@ -104,7 +93,6 @@ async function initializeAppConfig(config) {
module.exports = { module.exports = {
getAppConfig, getAppConfig,
cacheAppConfig, setAppConfig,
clearAppConfigCache, clearAppConfigCache,
initializeAppConfig,
}; };