fix(sessions): guard archive timestamp formatting · openclaw/openclaw@8bf7bc5
steipete
·
2026-05-30
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -136,4 +136,13 @@ describe("session artifact helpers", () => {
|
136 | 136 | expect(parseSessionArchiveTimestamp(file, "reset")).toBeNull(); |
137 | 137 | expect(parseSessionArchiveTimestamp("keep.deleted.keep.jsonl", "deleted")).toBeNull(); |
138 | 138 | }); |
| 139 | + |
| 140 | +it("falls back instead of throwing for out-of-range archive timestamps", () => { |
| 141 | +expect(formatSessionArchiveTimestamp(Number.POSITIVE_INFINITY)).toMatch( |
| 142 | +/^\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}\.\d{3}Z$/, |
| 143 | +); |
| 144 | +expect(formatSessionArchiveTimestamp(9_000_000_000_000_000)).toMatch( |
| 145 | +/^\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}\.\d{3}Z$/, |
| 146 | +); |
| 147 | +}); |
139 | 148 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import { timestampMsToIsoString } from "../../shared/number-coercion.js"; |
1 | 2 | import { escapeRegExp } from "../../shared/regexp.js"; |
2 | 3 | |
3 | 4 | export type SessionArchiveReason = "bak" | "reset" | "deleted"; |
@@ -122,7 +123,11 @@ export function parseUsageCountedSessionIdFromFileName(fileName: string): string
|
122 | 123 | } |
123 | 124 | |
124 | 125 | export function formatSessionArchiveTimestamp(nowMs = Date.now()): string { |
125 | | -return new Date(nowMs).toISOString().replaceAll(":", "-"); |
| 126 | +const iso = |
| 127 | +timestampMsToIsoString(nowMs) ?? |
| 128 | +timestampMsToIsoString(Date.now()) ?? |
| 129 | +"1970-01-01T00:00:00.000Z"; |
| 130 | +return iso.replaceAll(":", "-"); |
126 | 131 | } |
127 | 132 | |
128 | 133 | function restoreSessionArchiveTimestamp(raw: string): string { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。