mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-16 13:00:55 +00:00
* 🚜 feat: Support Native PostgreSQL Tool Favorites
* fix: Guard PostgreSQL Reconciliation and Connection Leases
* fix: Scope Favorites Erasure Fences to Deletion Attempts
* fix: Preserve Account Erasure Ownership Until Cancellation Completes
* fix: Reject Unsupported PostgreSQL Command Flags Before Connecting
* fix: Keep Command Validation Compatible With the TypeScript Target
* fix: Keep Migration Previews Read-Only and Preserve Erasure Recovery Identity
* fix: Fence Erasure Recovery Across Tenant and Ownership Changes
* fix: Isolate Migration Dependencies and Keep Mongo Scans Outside Transactions
* fix: Inject PostgreSQL Backend Factories at Composition Roots
* ci: Shard Complete Mutation Work Without Relaxing the Aggregate Gate
---------
Co-authored-by: Lia <lia@librechat.ai>
137 lines
4.2 KiB
JavaScript
137 lines
4.2 KiB
JavaScript
const { readFileSync } = require('node:fs');
|
|
const { resolve, dirname } = require('node:path');
|
|
const { runInNewContext } = require('node:vm');
|
|
|
|
describe.each(['index', 'experimental'])('%s entrypoint lifecycle wiring', (entrypoint) => {
|
|
it.each([false, true])(
|
|
'retains the original startup error and cleans up (persistence failure: %s)',
|
|
async (failFavorites) => {
|
|
const file = resolve(__dirname, `${entrypoint}.js`);
|
|
const events = [];
|
|
const errors = [];
|
|
const tasks = new Map();
|
|
const bootError = new Error('boot failure');
|
|
const noop = new Proxy(
|
|
function () {
|
|
return noop;
|
|
},
|
|
{
|
|
get(_target, key) {
|
|
return key === 'then' ? undefined : noop;
|
|
},
|
|
},
|
|
);
|
|
const closeFavorites = async () => {
|
|
events.push('close');
|
|
if (failFavorites) {
|
|
throw new Error('close failure');
|
|
}
|
|
};
|
|
const api = new Proxy(
|
|
{
|
|
cacheConfig: {},
|
|
isEnabled: () => false,
|
|
waitForKeyvRedisClient: async () => {},
|
|
createMetrics: () => ({}),
|
|
registerShutdownTask: (name, fn) => tasks.set(name, fn),
|
|
},
|
|
{
|
|
get(target, key) {
|
|
return Reflect.has(target, key) ? Reflect.get(target, key) : noop;
|
|
},
|
|
},
|
|
);
|
|
const models = new Proxy(
|
|
{
|
|
seedDatabase: async () => {},
|
|
sweepOrphanedPreviews: async () => {},
|
|
initializeFavorites: async (config) => {
|
|
events.push('initialize');
|
|
expect(config.persistence.favorites).toBe('postgres');
|
|
if (failFavorites) {
|
|
throw bootError;
|
|
}
|
|
},
|
|
closeFavorites,
|
|
},
|
|
{
|
|
get(target, key) {
|
|
return Reflect.has(target, key) ? Reflect.get(target, key) : noop;
|
|
},
|
|
},
|
|
);
|
|
runInNewContext(
|
|
readFileSync(file, 'utf8'),
|
|
{
|
|
require: (id) => {
|
|
if (id === 'path') {
|
|
return { resolve, dirname };
|
|
}
|
|
if (id === 'cluster') {
|
|
return { isMaster: false };
|
|
}
|
|
if (id === 'express') {
|
|
return () => ({ locals: {}, disable() {}, set() {}, use() {} });
|
|
}
|
|
if (id === '@librechat/api') {
|
|
return api;
|
|
}
|
|
if (id === '@librechat/data-schemas') {
|
|
return {
|
|
logger: { info() {}, warn() {}, error: (...args) => errors.push(args) },
|
|
runAsSystem: async (fn) => fn(),
|
|
};
|
|
}
|
|
if (id === '~/models') {
|
|
return models;
|
|
}
|
|
if (id === '~/db') {
|
|
return { connectDb: async () => {}, indexSync: async () => {} };
|
|
}
|
|
if (id === './services/Config') {
|
|
return {
|
|
loadCustomConfig: async (print, options) => {
|
|
expect(print).toBe(false);
|
|
expect(options).toEqual({ storageSelection: true });
|
|
return { persistence: { favorites: 'postgres' } };
|
|
},
|
|
getAppConfig: async () => {
|
|
events.push('config');
|
|
throw bootError;
|
|
},
|
|
};
|
|
}
|
|
return noop;
|
|
},
|
|
__dirname: dirname(file),
|
|
module: { exports: {} },
|
|
console,
|
|
process: {
|
|
env: {},
|
|
pid: 1,
|
|
on() {},
|
|
exit: (code) => events.push(`exit:${code}`),
|
|
},
|
|
setTimeout,
|
|
clearTimeout,
|
|
setInterval,
|
|
clearInterval,
|
|
Buffer,
|
|
},
|
|
{ filename: file },
|
|
);
|
|
await new Promise((resolve) => setImmediate(resolve));
|
|
expect(events[0]).toBe('initialize');
|
|
expect(events).toContain('close');
|
|
expect(events).toContain('exit:1');
|
|
const last = errors[errors.length - 1];
|
|
expect(last[last.length - 1]).toBe(bootError);
|
|
if (failFavorites) {
|
|
expect(events).not.toContain('config');
|
|
} else {
|
|
expect(tasks.get('favorites persistence')).toBe(closeFavorites);
|
|
expect(events).toContain('config');
|
|
}
|
|
},
|
|
);
|
|
});
|