mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-09-16 09:33:56 +00:00
🧳 fix: Carry Stateful Environments Through Runtime Config (#15374)
This commit is contained in:
parent
29b3e2ef3e
commit
9dcef360e2
1 changed files with 46 additions and 16 deletions
|
|
@ -266,24 +266,54 @@ describe('initializeAgent — execution context', () => {
|
|||
|
||||
it('initializes without Express request or response objects', async () => {
|
||||
const { agent, loadTools, db } = createMocks();
|
||||
|
||||
await expect(
|
||||
initializeAgent(
|
||||
{
|
||||
runtime: {
|
||||
user: { id: 'user-1' } as never,
|
||||
appConfig: {} as never,
|
||||
requestBody: { timezone: 'America/New_York' },
|
||||
const previousReqDescriptor = Object.getOwnPropertyDescriptor(globalThis, 'req');
|
||||
Object.defineProperty(globalThis, 'req', {
|
||||
configurable: true,
|
||||
writable: true,
|
||||
value: undefined,
|
||||
});
|
||||
const appConfig = {
|
||||
endpoints: {
|
||||
[EModelEndpoint.agents]: {
|
||||
statefulCodeSessions: {
|
||||
environments: [
|
||||
{
|
||||
id: 'request-free-stateful',
|
||||
name: 'Request-free stateful',
|
||||
type: 'attached',
|
||||
baseURL: 'https://stateful.example.com/v1',
|
||||
},
|
||||
],
|
||||
},
|
||||
agent,
|
||||
loadTools,
|
||||
endpointOption: { endpoint: EModelEndpoint.agents },
|
||||
allowedProviders: new Set([Providers.OPENAI]),
|
||||
isInitialAgent: true,
|
||||
},
|
||||
db,
|
||||
),
|
||||
).resolves.toBeDefined();
|
||||
},
|
||||
};
|
||||
|
||||
try {
|
||||
await expect(
|
||||
initializeAgent(
|
||||
{
|
||||
runtime: {
|
||||
user: { id: 'user-1' } as never,
|
||||
appConfig: appConfig as never,
|
||||
requestBody: { timezone: 'America/New_York' },
|
||||
},
|
||||
agent,
|
||||
loadTools,
|
||||
endpointOption: { endpoint: EModelEndpoint.agents },
|
||||
allowedProviders: new Set([Providers.OPENAI]),
|
||||
isInitialAgent: true,
|
||||
},
|
||||
db,
|
||||
),
|
||||
).resolves.toBeDefined();
|
||||
} finally {
|
||||
if (previousReqDescriptor == null) {
|
||||
delete (globalThis as typeof globalThis & { req?: unknown }).req;
|
||||
} else {
|
||||
Object.defineProperty(globalThis, 'req', previousReqDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
expect(loadTools).toHaveBeenCalledWith(expect.not.objectContaining({ req: expect.anything() }));
|
||||
expect(loadTools).toHaveBeenCalledWith(expect.not.objectContaining({ res: expect.anything() }));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue