fix(memory-wiki): tolerate invalid chatgpt timestamps

This commit is contained in:
Peter Steinberger
2026-05-30 06:16:03 -04:00
parent 4d4748e807
commit 8aabf45ddb
2 changed files with 28 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ import {
replaceManagedMarkdownBlock,
withTrailingNewline,
} from "openclaw/plugin-sdk/memory-host-markdown";
import { timestampMsToIsoString } from "openclaw/plugin-sdk/number-runtime";
import { uniqueStrings } from "openclaw/plugin-sdk/string-coerce-runtime";
import { compileMemoryWikiVault } from "./compile.js";
import type { ResolvedMemoryWikiConfig } from "./config.js";
@@ -203,7 +204,7 @@ function isoFromUnix(raw: unknown): string | undefined {
if (!Number.isFinite(numeric)) {
return undefined;
}
return new Date(numeric * 1000).toISOString();
return timestampMsToIsoString(numeric * 1000);
}
function cleanMessageText(value: string): string {

View File

@@ -605,4 +605,30 @@ cli note
.then((entries) => entries.filter((entry) => entry !== "index.md")),
).resolves.toStrictEqual([]);
});
it("imports ChatGPT exports with out-of-range Unix timestamps", async () => {
const { rootDir, config } = await createCliVault({ initialize: true });
const exportDir = await createChatGptExport(rootDir);
const conversationsPath = path.join(exportDir, "conversations.json");
const conversations = JSON.parse(await fs.readFile(conversationsPath, "utf8")) as Array<
Record<string, unknown>
>;
conversations[0].update_time = 9_000_000_000_000;
await fs.writeFile(conversationsPath, `${JSON.stringify(conversations, null, 2)}\n`, "utf8");
const result = await runWikiChatGptImport({
config,
exportPath: exportDir,
json: true,
});
expect(result.createdCount).toBe(1);
const sourceFile = (await fs.readdir(path.join(rootDir, "sources"))).find(
(entry) => entry !== "index.md",
);
expect(sourceFile).toBeDefined();
const pageContent = await fs.readFile(path.join(rootDir, "sources", sourceFile ?? ""), "utf8");
expect(pageContent).toContain("- Created: 2024-04-06T00:26:40.000Z");
expect(pageContent).toContain("- Updated: 2024-04-06T00:26:40.000Z");
});
});