mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-03 22:24:06 +00:00
fix(memory-wiki): tolerate invalid chatgpt timestamps
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user