Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(facts): reject calendar-invalid date-only ttl values
masashiono061150f8f1f55250
diff --git a/src/core/facts/ttl-parse.ts b/src/core/facts/ttl-parse.tsindex 57171dd982..a42fe07657 100644--- a/src/core/facts/ttl-parse.ts+++ b/src/core/facts/ttl-parse.ts@@ -54,6 +54,11 @@ export function parseTtlShorthand(raw: unknown): TtlParseResult {const ms = parseDurationShorthandMs(s);if (ms !== null) return { ok: true, validUntil: new Date(Date.now() + ms) };+ if (/^\d{4}-\d{2}-\d{2}$/.test(s) &&+ (!Number.isFinite(Date.parse(s)) || new Date(s).toISOString().slice(0, 10) !== s)) {+ return { ok: false, code: 'unparseable', input: s };+ }+const iso = Date.parse(s);if (Number.isFinite(iso)) return { ok: true, validUntil: new Date(iso) };diff --git a/test/writeback-config.test.ts b/test/writeback-config.test.tsindex 2419c49b03..45e2ad20da 100644--- a/test/writeback-config.test.ts+++ b/test/writeback-config.test.ts@@ -54,6 +54,18 @@ describe('parseTtlShorthand (pure leaf)', () => {expect(res.validUntil.toISOString()).toBe('2030-01-02T00:00:00.000Z');});+ test('date-only ISO values must be valid calendar dates', () => {+ expect(parseTtlShorthand('2026-02-30')).toEqual({+ ok: false,+ code: 'unparseable',+ input: '2026-02-30',+ });+ const leapDay = parseTtlShorthand('2024-02-29');+ if (!leapDay.ok || !leapDay.validUntil) throw new Error('expected valid leap-day date');+ expect(leapDay.validUntil.toISOString().slice(0, 10)).toBe('2024-02-29');+ expect(parseTtlShorthand('2026-02-28T10:00:00Z').ok).toBe(true);+ });+test('typed failures: not_string / iso_duration / unparseable', () => {expect(parseTtlShorthand(30)).toMatchObject({ ok: false, code: 'not_string' });expect(parseTtlShorthand('P30D')).toMatchObject({ ok: false, code: 'iso_duration' });