fix(sessions): guard transcript append timestamps · openclaw/openclaw@a17c7a5
steipete
·
2026-05-30
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -937,6 +937,39 @@ describe("appendAssistantMessageToSessionTranscript", () => {
|
937 | 937 | expect(countMessages(checkedSessionFile)).toBe(1); |
938 | 938 | }); |
939 | 939 | |
| 940 | +it("falls back instead of throwing for out-of-range append timestamps", async () => { |
| 941 | +const sessionFile = resolveSessionTranscriptPathInDir( |
| 942 | +"invalid-now-transcript-session", |
| 943 | +fixture.sessionsDir(), |
| 944 | +); |
| 945 | +const dateNowSpy = vi.spyOn(Date, "now").mockReturnValue(Date.parse("2026-05-30T12:00:00Z")); |
| 946 | + |
| 947 | +try { |
| 948 | +await appendSessionTranscriptMessage({ |
| 949 | +transcriptPath: sessionFile, |
| 950 | +message: { role: "user", content: "bad clock append" }, |
| 951 | +now: 8_640_000_000_000_001, |
| 952 | +}); |
| 953 | +} finally { |
| 954 | +dateNowSpy.mockRestore(); |
| 955 | +} |
| 956 | + |
| 957 | +const message = fs |
| 958 | +.readFileSync(sessionFile, "utf-8") |
| 959 | +.trim() |
| 960 | +.split("\n") |
| 961 | +.map( |
| 962 | +(line) => |
| 963 | +JSON.parse(line) as { |
| 964 | +type?: string; |
| 965 | +timestamp?: string; |
| 966 | +}, |
| 967 | +) |
| 968 | +.find((record) => record.type === "message"); |
| 969 | + |
| 970 | +expect(message?.timestamp).toBe("2026-05-30T12:00:00.000Z"); |
| 971 | +}); |
| 972 | + |
940 | 973 | it("redacts structured message content before transcript persistence", async () => { |
941 | 974 | const sessionFile = resolveSessionTranscriptPathInDir( |
942 | 975 | "redacted-transcript-session", |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。