fix: restore ledger storage test execution

This commit is contained in:
AL
2026-09-12 04:21:33 +01:00
parent cebbd75ac0
commit 01f8ed8153
3 changed files with 30 additions and 5 deletions
+8
View File
@@ -186,12 +186,20 @@ export function createCircuitBreaker(
reset();
}
}, cfg.resetTimeoutMs);
// A tripped standalone breaker should not keep a CLI or test process alive.
// Gateway processes remain alive through their servers and monitoring loop.
autoResetTimer.unref?.();
}
/**
* Reset the circuit breaker
*/
function reset(): void {
if (autoResetTimer) {
clearTimeout(autoResetTimer);
autoResetTimer = null;
}
logger.info({ previousReason: tripReason }, 'Circuit breaker RESET');
isTripped = false;
+14 -5
View File
@@ -255,11 +255,20 @@ export function createMockDb(): LedgerDb & {
);
}
// Handle ORDER BY and LIMIT
const limitMatch = sql.match(/LIMIT (\d+)/i);
if (limitMatch) {
const limit = parseInt(limitMatch[1], 10);
result = result.slice(0, limit);
// Handle ORDER BY, LIMIT, and OFFSET in both literal and bound-parameter
// forms. Production queries bind these values, so the mock must preserve
// the same pagination semantics.
const literalLimit = sql.match(/LIMIT\s+(\d+)/i);
const boundLimit = /LIMIT\s+\?/i.test(sql);
const boundOffset = /OFFSET\s+\?/i.test(sql);
const limit = literalLimit
? parseInt(literalLimit[1], 10)
: boundLimit
? Number(params[params.length - (boundOffset ? 2 : 1)])
: undefined;
const offset = boundOffset ? Number(params[params.length - 1]) : 0;
if (limit !== undefined && Number.isFinite(limit)) {
result = result.slice(offset, offset + limit);
}
return result as T[];
+8
View File
@@ -351,6 +351,14 @@ describe('LedgerStorage.list', () => {
assert.strictEqual(results.length, 2);
});
it('should respect offset option', () => {
const firstPage = storage.list(MOCK_USER_ID, { limit: 2 });
const secondPage = storage.list(MOCK_USER_ID, { limit: 2, offset: 2 });
assert.strictEqual(secondPage.length, 2);
assert.notStrictEqual(secondPage[0].id, firstPage[0].id);
});
it('should filter by category', () => {
const results = storage.list(MOCK_USER_ID, { category: 'trade' });