[codex] fix runtime settings restart hydration (#392)
* fix runtime settings restart hydration * fix review followups for settings hydration * dedupe log cleanup day normalization
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { normalizeLogCleanupRetentionDays } from './logCleanupRetentionDays.js';
|
||||
|
||||
describe('normalizeLogCleanupRetentionDays', () => {
|
||||
it('truncates positive numeric values', () => {
|
||||
expect(normalizeLogCleanupRetentionDays(14.9)).toBe(14);
|
||||
});
|
||||
|
||||
it('falls back to the provided default for invalid values', () => {
|
||||
expect(normalizeLogCleanupRetentionDays('oops', 7)).toBe(7);
|
||||
expect(normalizeLogCleanupRetentionDays(-1, 7)).toBe(7);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
export function normalizeLogCleanupRetentionDays(value: unknown, fallback = 30): number {
|
||||
const parsed = Number(value);
|
||||
if (Number.isFinite(parsed) && parsed >= 1) return Math.trunc(parsed);
|
||||
|
||||
const fallbackParsed = Number(fallback);
|
||||
if (Number.isFinite(fallbackParsed) && fallbackParsed >= 1) return Math.trunc(fallbackParsed);
|
||||
|
||||
return 30;
|
||||
}
|
||||
Reference in New Issue
Block a user