fix(destination-buffer): return entries in chronological order (oldest-first) and adjust pagination semantics

This commit is contained in:
2026-02-20 08:57:22 +00:00
parent dbcfeba16d
commit 9a61a3a9af
4 changed files with 24 additions and 13 deletions

View File

@@ -36,11 +36,11 @@ tap.test('should store log entries via handleLog', async () => {
expect(buffer.getEntryCount()).toEqual(3);
});
tap.test('should retrieve entries newest-first', async () => {
tap.test('should retrieve entries in chronological order (oldest-first)', async () => {
const entries = buffer.getEntries();
expect(entries.length).toEqual(3);
expect(entries[0].message).toEqual('Watch out');
expect(entries[2].message).toEqual('Hello world');
expect(entries[0].message).toEqual('Hello world');
expect(entries[2].message).toEqual('Watch out');
});
tap.test('should filter entries by level', async () => {
@@ -59,10 +59,13 @@ tap.test('should filter entries by search string', async () => {
});
tap.test('should support limit and offset pagination', async () => {
// limit=2, offset=0 → last 2 entries in chronological order
const page1 = buffer.getEntries({ limit: 2, offset: 0 });
expect(page1.length).toEqual(2);
expect(page1[0].message).toEqual('Watch out');
expect(page1[0].message).toEqual('Something failed');
expect(page1[1].message).toEqual('Watch out');
// limit=2, offset=2 → skip 2 from end, return up to 2
const page2 = buffer.getEntries({ limit: 2, offset: 2 });
expect(page2.length).toEqual(1);
expect(page2[0].message).toEqual('Hello world');
@@ -94,10 +97,10 @@ tap.test('should enforce circular buffer max entries', async () => {
expect(smallBuffer.getEntryCount()).toEqual(5);
// Should have kept the latest 5 (messages 5-9)
// Should have kept the latest 5 (messages 5-9), returned chronologically
const entries = smallBuffer.getEntries({ limit: 10 });
expect(entries[0].message).toEqual('Message 9');
expect(entries[4].message).toEqual('Message 5');
expect(entries[0].message).toEqual('Message 5');
expect(entries[4].message).toEqual('Message 9');
});
tap.test('should clear all entries', async () => {