[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:
Cita
2026-04-02 17:27:25 +08:00
committed by GitHub
parent 1407f754b1
commit 082891a217
8 changed files with 365 additions and 279 deletions
@@ -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;
}