unrip/test/history-writer-refresh-config.test.mjs
philipp d24ac8ee59
Some checks failed
deploy / deploy (push) Failing after 44s
Keep history replay inside preflight freshness
Proof: npm test (143 passing); npm run operator-dashboard:build; git diff --cached --check.

Assumptions: Derived portfolio/outcome refreshes are only useful for live freshness when the source event is within the same 30s inventory window enforced by request preflight.

Still fake: No live asset migration submitted; legacy btc.omft remains tracked but not converted to nBTC by this change.
2026-05-07 16:18:41 +02:00

37 lines
1.3 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { loadConfig } from '../src/lib/config.mjs';
const ENV_KEYS = [
'HISTORY_WRITER_DERIVED_REFRESH_MAX_EVENT_AGE_MS',
'INTENT_REQUEST_INVENTORY_MAX_AGE_MS',
];
function withCleanEnv(fn) {
const previous = Object.fromEntries(ENV_KEYS.map((key) => [key, process.env[key]]));
for (const key of ENV_KEYS) delete process.env[key];
try {
return fn();
} finally {
for (const [key, value] of Object.entries(previous)) {
if (value == null) delete process.env[key];
else process.env[key] = value;
}
}
}
test('history writer derived refresh replay cutoff matches request inventory freshness', () => withCleanEnv(() => {
const config = loadConfig({ envPath: '/tmp/unrip-no-such-env-file' });
assert.equal(config.historyWriterDerivedRefreshMaxEventAgeMs, 30000);
assert.equal(config.historyWriterDerivedRefreshMaxEventAgeMs, config.intentRequestInventoryMaxAgeMs);
}));
test('kubernetes history writer replay cutoff matches request inventory freshness', () => {
const manifest = readFileSync(new URL('../deploy/k8s/base/unrip.yaml', import.meta.url), 'utf8');
assert.match(manifest, /HISTORY_WRITER_DERIVED_REFRESH_MAX_EVENT_AGE_MS: "30000"/);
assert.match(manifest, /INTENT_REQUEST_INVENTORY_MAX_AGE_MS: "30000"/);
});