perf(usage): bound session log retention · openclaw/openclaw@00f8b10
vincentkoc
·
2026-06-23
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -2753,4 +2753,28 @@ example
|
2753 | 2753 | loadSessionLogs({ sessionFile, limit: Number.POSITIVE_INFINITY }), |
2754 | 2754 | ).resolves.toEqual([]); |
2755 | 2755 | }); |
| 2756 | + |
| 2757 | +it("keeps the latest logs when transcript timestamps are out of order", async () => { |
| 2758 | +const root = await makeSessionCostRoot("session-logs-unsorted-limit"); |
| 2759 | +const sessionFile = path.join(root, "session.jsonl"); |
| 2760 | +const entries = [ |
| 2761 | +["2026-02-12T10:03:00.000Z", "third"], |
| 2762 | +["2026-02-12T10:01:00.000Z", "first"], |
| 2763 | +["2026-02-12T10:04:00.000Z", "fourth"], |
| 2764 | +["2026-02-12T10:02:00.000Z", "second"], |
| 2765 | +].map(([timestamp, content]) => ({ |
| 2766 | +type: "message", |
| 2767 | + timestamp, |
| 2768 | +message: { role: "user", content }, |
| 2769 | +})); |
| 2770 | +await fs.writeFile( |
| 2771 | +sessionFile, |
| 2772 | +entries.map((entry) => JSON.stringify(entry)).join("\n"), |
| 2773 | +"utf-8", |
| 2774 | +); |
| 2775 | + |
| 2776 | +const logs = await loadSessionLogs({ sessionFile, limit: 2 }); |
| 2777 | + |
| 2778 | +expect(logs?.map((log) => log.content)).toEqual(["third", "fourth"]); |
| 2779 | +}); |
2756 | 2780 | }); |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。