From 5805ea801d691bb2de4451c05e3acc3e284690f6 Mon Sep 17 00:00:00 2001 From: philipp Date: Wed, 13 May 2026 13:22:31 +0200 Subject: [PATCH] Fix inventory refresh error logging Proof: npm test; node --check src/apps/inventory-sync.mjs; node --test test/inventory-sync-static.test.mjs test/trading-config.test.mjs. Assumptions: Inventory refresh failures should be logged with the active pair when available, but error logging must not throw if trading config loading or refresh work fails. Still fake: No BTC/USDC external reference price route or liquidity model exists; non-nBTC/EURe pairs still fail closed on missing price route until that path is built. --- src/apps/inventory-sync.mjs | 4 +++- test/inventory-sync-static.test.mjs | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 test/inventory-sync-static.test.mjs diff --git a/src/apps/inventory-sync.mjs b/src/apps/inventory-sync.mjs index c5f987d..ef54b58 100644 --- a/src/apps/inventory-sync.mjs +++ b/src/apps/inventory-sync.mjs @@ -136,8 +136,10 @@ await consumer.run({ async function refresh() { if (state.paused) return; + let activePair = null; try { const tradingConfig = await tradingConfigStore.getConfig(); + activePair = tradingConfig.activePair; if (!tradingConfig.ok) throw new Error(`trading config unavailable: ${tradingConfig.blockReason}`); const chains = uniqueChainsForAssets(tradingConfig.trackedAssets); const fallbackAssetByChain = new Map( @@ -201,7 +203,7 @@ async function refresh() { state.last_error = serializeError(error); logger.error('inventory_refresh_failed', { topic: config.kafkaTopicStateIntentInventory, - pair: tradingConfig.activePair, + pair: activePair, details: { error: serializeError(error), }, diff --git a/test/inventory-sync-static.test.mjs b/test/inventory-sync-static.test.mjs new file mode 100644 index 0000000..65e077a --- /dev/null +++ b/test/inventory-sync-static.test.mjs @@ -0,0 +1,12 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { readFileSync } from 'node:fs'; + +const source = readFileSync(new URL('../src/apps/inventory-sync.mjs', import.meta.url), 'utf8'); + +test('inventory refresh error logging cannot reference block-scoped trading config', () => { + assert.match(source, /let activePair = null;/); + assert.match(source, /activePair = tradingConfig\.activePair;/); + assert.match(source, /pair: activePair/); + assert.doesNotMatch(source, /pair: tradingConfig\.activePair/); +});