LibreChat/packages/api/src/stream/persistence.spec.ts
Dustin Healy cdc3339a78
🪬 fix: Fence Agent Checkpoint Ownership and Cleanup Recovery (#15680)
* 🔒 fix: Isolate Checkpoint Cleanup by Generation Ownership

* 🔒 fix: Harden Checkpoint Cleanup Ownership

* 🔒 fix: Retain Checkpoint Cleanup Evidence

* 🔒 fix: Persist checkpoint cleanup receipts

* 🔒 fix: Bound checkpoint cleanup receipt lifecycle

* fix: Bind checkpoint cleanup to durable ownership and deletion intent

* fix: Bind event actor checkpoint storage to authenticated owners

* fix: Resolve exact actor checkpoint ownership before lifecycle cleanup

* fix: Preserve actor storage compatibility with durable ownership and prune work

* fix: Defer checkpoint erasure until conversation deletion commits

* fix: Reclaim orphan actor ownership and batch deletion lookups

* fix: bind actor checkpoint ownership to payload rows

* fix: isolate actor readers and await account persistence

* fix: gate owned suspensions and drain complete account state

* fix: unify checkpoint deletion lifecycle and storage authority

* fix: Replay checkpoint deletion from durable owner state

* fix: retain checkpoint cleanup identity before topology loss

* fix: complete checkpoint catalog capture and retirement lifecycle
2026-09-07 22:04:59 -04:00

42 lines
1.7 KiB
TypeScript

import { waitForGenerationPersistence } from './persistence';
test('waits for the captured terminal epoch to finish persistence', async () => {
const read = jest
.fn()
.mockResolvedValueOnce({ createdAt: 1, metadata: { terminalPersistencePending: true } })
.mockResolvedValueOnce({ createdAt: 1, metadata: { terminalPersistencePending: false } });
await waitForGenerationPersistence('run', 1, read, { pollMs: 1 });
expect(read).toHaveBeenCalledTimes(2);
});
test('fails closed on a replacement epoch', async () => {
const read = jest
.fn()
.mockResolvedValue({ createdAt: 2, metadata: { terminalPersistencePending: true } });
await expect(waitForGenerationPersistence('run', 1, read)).rejects.toThrow('Generation replaced');
expect(read).toHaveBeenCalledTimes(1);
});
test.each(['terminalPersistencePending', 'terminalHostActionPending'])(
'fails closed on %s and lookup errors',
async (marker) => {
const read = jest.fn().mockResolvedValue({ createdAt: 1, metadata: { [marker]: true } });
await expect(waitForGenerationPersistence('run', 1, read, { timeoutMs: 0 })).rejects.toThrow(
'Timed out',
);
read.mockRejectedValue(new Error('unavailable'));
await expect(waitForGenerationPersistence('run', 1, read)).rejects.toThrow('unavailable');
},
);
test('waits for terminal host actions after provider persistence has cleared', async () => {
const read = jest
.fn()
.mockResolvedValueOnce({
createdAt: 1,
metadata: { terminalHostActionPending: true, terminalPersistencePending: false },
})
.mockResolvedValueOnce({ createdAt: 1, metadata: { terminalHostActionPending: false } });
await waitForGenerationPersistence('run', 1, read, { pollMs: 1 });
expect(read).toHaveBeenCalledTimes(2);
});