mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-17 05:20:55 +00:00
📬 feat: Persist Channel Events and Delivery Receipts (#17595)
* 📬 feat: Persist Channel Events and Delivery Receipts
* fix: enforce channel run identity and fenced recovery
* fix: fence and erase channel state during account deletion
* refactor: share channel owner admission with private persistence
* refactor: name channel account-erasure boundary explicitly
* fix: prove channel identity and delivery authority at storage boundaries
* refactor: enforce channel delivery protocol and terminal lifecycle
* fix: enforce channel tenant and operation boundaries
* fix: initialize channel config from its composition owner
* test: verify config installs channel storage reader
* test: complete config initializer contract in model mocks
* test: include channel config reader in migration fixture
* test: await SSE subscription before advancing keepalive time
* test: Observe and Drain Concurrent Fixture Work
This commit is contained in:
parent
1458e841e4
commit
7dd4fafdf3
48 changed files with 3816 additions and 54 deletions
|
|
@ -35,6 +35,7 @@ jest.mock('@librechat/api', () => ({
|
|||
|
||||
jest.mock('~/models', () => ({
|
||||
initializeMessageBudget: jest.fn(),
|
||||
initializeChannelStorageConfig: jest.fn(),
|
||||
saveMessage: jest.fn(async (req, message) => message),
|
||||
getConvo: jest.fn(async () => null),
|
||||
getMessages: jest.fn(async () => []),
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ const mockGetCacheMultiplier = jest.fn(() => 1);
|
|||
|
||||
jest.mock('~/models', () => ({
|
||||
initializeMessageBudget: jest.fn(),
|
||||
initializeChannelStorageConfig: jest.fn(),
|
||||
getMultiplier: (...args) => mockGetMultiplier(...args),
|
||||
getCacheMultiplier: (...args) => mockGetCacheMultiplier(...args),
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ const mockSpendTokens = jest.fn().mockResolvedValue(undefined);
|
|||
|
||||
jest.mock('~/models', () => ({
|
||||
initializeMessageBudget: jest.fn(),
|
||||
initializeChannelStorageConfig: jest.fn(),
|
||||
spendTokens: mockSpendTokens,
|
||||
}));
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ jest.mock('@librechat/api', () => ({
|
|||
|
||||
jest.mock('~/models', () => ({
|
||||
initializeMessageBudget: jest.fn(),
|
||||
initializeChannelStorageConfig: jest.fn(),
|
||||
saveMessage: jest.fn(async (req, message) => message),
|
||||
getConvo: jest.fn(async () => null),
|
||||
getMessages: jest.fn(async () => []),
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ const mockRecordCollectedUsage = jest
|
|||
|
||||
jest.mock('~/models', () => ({
|
||||
initializeMessageBudget: jest.fn(),
|
||||
initializeChannelStorageConfig: jest.fn(),
|
||||
spendTokens: (...args) => mockSpendTokens(...args),
|
||||
spendStructuredTokens: (...args) => mockSpendStructuredTokens(...args),
|
||||
getMultiplier: mockGetMultiplier,
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ jest.mock('@librechat/api', () => ({
|
|||
|
||||
jest.mock('~/models', () => ({
|
||||
initializeMessageBudget: jest.fn(),
|
||||
initializeChannelStorageConfig: jest.fn(),
|
||||
saveMessage: (...args) => mockSaveMessage(...args),
|
||||
getPersistedPrivateTextId: async (...args) =>
|
||||
(await mockHasPersistedPrivateText(...args)) ? 'protected-row-id' : null,
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ jest.mock('@librechat/api', () => ({
|
|||
|
||||
jest.mock('~/models', () => ({
|
||||
initializeMessageBudget: jest.fn(),
|
||||
initializeChannelStorageConfig: jest.fn(),
|
||||
saveMessage: (...args) => mockSaveMessage(...args),
|
||||
}));
|
||||
|
||||
|
|
@ -86,6 +87,28 @@ function mockSubscribeSuccess() {
|
|||
});
|
||||
}
|
||||
|
||||
/** A real HTTP socket must reach subscribe before fake time can exercise its keepalive. */
|
||||
function openSilentStream() {
|
||||
let resolveAttached;
|
||||
const subscribed = new Promise((resolve) => {
|
||||
resolveAttached = resolve;
|
||||
});
|
||||
mockGenerationJobManager.subscribe.mockImplementation(async (_streamId, _writeEvent, onDone) => {
|
||||
resolveAttached(onDone);
|
||||
return { unsubscribe: jest.fn() };
|
||||
});
|
||||
const pending = request(app)
|
||||
.get('/agents/chat/stream/stream-123')
|
||||
.then((res) => res);
|
||||
const attached = Promise.race([
|
||||
subscribed,
|
||||
pending.then((res) => {
|
||||
throw new Error(`Stream ended before subscribing: HTTP ${res.status}`);
|
||||
}),
|
||||
]);
|
||||
return { pending, attached };
|
||||
}
|
||||
|
||||
describe('SSE stream tenant isolation', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
|
|
@ -411,19 +434,8 @@ describe('SSE stream tenant isolation', () => {
|
|||
status: 'running',
|
||||
createdAt: 1000,
|
||||
});
|
||||
let finish;
|
||||
mockGenerationJobManager.subscribe.mockImplementation(
|
||||
async (_streamId, _writeEvent, onDone) => {
|
||||
finish = onDone;
|
||||
return { unsubscribe: jest.fn() };
|
||||
},
|
||||
);
|
||||
|
||||
const pending = request(app)
|
||||
.get('/agents/chat/stream/stream-123')
|
||||
.then((res) => res);
|
||||
await jest.advanceTimersByTimeAsync(0);
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
const { pending, attached } = openSilentStream();
|
||||
const finish = await attached;
|
||||
await jest.advanceTimersByTimeAsync(60_000);
|
||||
finish({ final: true });
|
||||
const res = await pending;
|
||||
|
|
@ -470,19 +482,8 @@ describe('SSE stream tenant isolation', () => {
|
|||
status: 'running',
|
||||
createdAt: 1000,
|
||||
});
|
||||
let finish;
|
||||
mockGenerationJobManager.subscribe.mockImplementation(
|
||||
async (_streamId, _writeEvent, onDone) => {
|
||||
finish = onDone;
|
||||
return { unsubscribe: jest.fn() };
|
||||
},
|
||||
);
|
||||
|
||||
const pending = request(app)
|
||||
.get('/agents/chat/stream/stream-123')
|
||||
.then((res) => res);
|
||||
await jest.advanceTimersByTimeAsync(0);
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
const { pending, attached } = openSilentStream();
|
||||
const finish = await attached;
|
||||
await jest.advanceTimersByTimeAsync(60_000);
|
||||
finish({ final: true });
|
||||
const res = await pending;
|
||||
|
|
@ -502,19 +503,8 @@ describe('SSE stream tenant isolation', () => {
|
|||
status: 'running',
|
||||
createdAt: 1000,
|
||||
});
|
||||
let finish;
|
||||
mockGenerationJobManager.subscribe.mockImplementation(
|
||||
async (_streamId, _writeEvent, onDone) => {
|
||||
finish = onDone;
|
||||
return { unsubscribe: jest.fn() };
|
||||
},
|
||||
);
|
||||
|
||||
const pending = request(app)
|
||||
.get('/agents/chat/stream/stream-123')
|
||||
.then((res) => res);
|
||||
await jest.advanceTimersByTimeAsync(0);
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
const { pending, attached } = openSilentStream();
|
||||
const finish = await attached;
|
||||
await jest.advanceTimersByTimeAsync(60_000);
|
||||
|
||||
expect(mockGenerationJobManager.subscribe).toHaveBeenCalled();
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ jest.mock('~/server/services/start/tools', () => ({
|
|||
|
||||
jest.mock('~/models', () => ({
|
||||
initializeMessageBudget: jest.fn(),
|
||||
initializeChannelStorageConfig: jest.fn(),
|
||||
getApplicableConfigs: jest.fn().mockResolvedValue([]),
|
||||
getUserPrincipals: jest.fn().mockResolvedValue([]),
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ jest.mock('@librechat/data-schemas', () => {
|
|||
|
||||
jest.mock('~/models', () => ({
|
||||
initializeMessageBudget: jest.fn(),
|
||||
initializeChannelStorageConfig: jest.fn(),
|
||||
getApplicableConfigs: jest.fn().mockResolvedValue([]),
|
||||
getUserPrincipals: jest.fn().mockResolvedValue([]),
|
||||
}));
|
||||
|
|
@ -61,14 +62,16 @@ jest.mock('@librechat/api', () => ({
|
|||
// ── Tests ──────────────────────────────────────────────────────────────
|
||||
|
||||
const { getAppConfig, invalidateConfigCaches } = require('../app');
|
||||
const { initializeMessageBudget } = require('~/models');
|
||||
const { initializeMessageBudget, initializeChannelStorageConfig } = require('~/models');
|
||||
// Capture module-composition calls before clearMocks resets the spy history.
|
||||
const budgetInitializations = [...initializeMessageBudget.mock.calls];
|
||||
const channelInitializations = [...initializeChannelStorageConfig.mock.calls];
|
||||
const invalidationOptions = mockCreateConfigCacheInvalidation.mock.calls[0][0];
|
||||
const pubSubOptions = mockCreateRedisPubSub.mock.calls[0][0];
|
||||
|
||||
test('Config supplies its actual reader exactly once during composition', () => {
|
||||
expect(budgetInitializations).toEqual([[getAppConfig]]);
|
||||
expect(channelInitializations).toEqual([[getAppConfig]]);
|
||||
});
|
||||
|
||||
describe('invalidateConfigCaches', () => {
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ const {
|
|||
|
||||
// Config owns the reader; models never import this module to obtain it.
|
||||
db.initializeMessageBudget(getAppConfig);
|
||||
db.initializeChannelStorageConfig(getAppConfig);
|
||||
|
||||
/**
|
||||
* Admin config writes clear the per-principal override caches, the MCP config-source servers
|
||||
|
|
|
|||
|
|
@ -3,7 +3,11 @@ jest.mock('@librechat/api', () => ({
|
|||
fetchModels: jest.fn(),
|
||||
}));
|
||||
jest.mock('./app');
|
||||
jest.mock('~/models', () => ({ getUserKeyValues: jest.fn(), initializeMessageBudget: jest.fn() }));
|
||||
jest.mock('~/models', () => ({
|
||||
getUserKeyValues: jest.fn(),
|
||||
initializeMessageBudget: jest.fn(),
|
||||
initializeChannelStorageConfig: jest.fn(),
|
||||
}));
|
||||
jest.mock('@librechat/data-schemas', () => ({
|
||||
...jest.requireActual('@librechat/data-schemas'),
|
||||
logger: { debug: jest.fn(), error: jest.fn(), warn: jest.fn(), info: jest.fn() },
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ jest.mock('@librechat/data-schemas', () => ({
|
|||
jest.mock('~/models', () => ({
|
||||
getUserKeyValues: jest.fn(),
|
||||
initializeMessageBudget: jest.fn(),
|
||||
initializeChannelStorageConfig: jest.fn(),
|
||||
}));
|
||||
|
||||
const exampleConfig = {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ const { ImportBatchBuilder } = require('./importBatchBuilder');
|
|||
|
||||
jest.mock('~/models', () => ({
|
||||
initializeMessageBudget: jest.fn(),
|
||||
initializeChannelStorageConfig: jest.fn(),
|
||||
bulkIncrementTagCounts: jest.fn(),
|
||||
bulkSaveConvos: jest.fn(),
|
||||
bulkSaveMessages: jest.fn(),
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ const importConversations = require('./importConversations');
|
|||
|
||||
jest.mock('~/models', () => ({
|
||||
initializeMessageBudget: jest.fn(),
|
||||
initializeChannelStorageConfig: jest.fn(),
|
||||
bulkIncrementTagCounts: jest.fn(),
|
||||
bulkSaveConvos: jest.fn(),
|
||||
bulkSaveMessages: jest.fn(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue