fix: detect legacy dreaming corpus directories

This commit is contained in:
Peter Steinberger
2026-05-08 20:16:04 +01:00
parent 5e5b6f8158
commit 45a16c1c68
2 changed files with 51 additions and 1 deletions

View File

@@ -757,4 +757,49 @@ describe("maybeRepairLegacyRuntimeStateFiles", () => {
});
});
});
it("imports legacy memory-core session corpus when it is the only dreaming file", async () => {
await withTempDir("openclaw-doctor-memory-core-corpus-", async (rootDir) => {
const stateDir = path.join(rootDir, "state");
const workspaceDir = path.join(rootDir, "workspace");
const sessionCorpusDir = path.join(workspaceDir, "memory", ".dreams", "session-corpus");
const env = { ...process.env, OPENCLAW_STATE_DIR: stateDir, OPENCLAW_TEST_FAST: "1" };
const cfg = {
agents: {
defaults: {
workspace: workspaceDir,
},
},
};
await withEnvAsync(env, async () => {
await fs.mkdir(sessionCorpusDir, { recursive: true });
await fs.writeFile(
path.join(sessionCorpusDir, "2026-04-06.txt"),
"User: Store the legacy corpus in SQLite.\n",
"utf8",
);
await maybeRepairLegacyRuntimeStateFiles({
prompter: { shouldRepair: true },
env,
cfg,
});
expect(noteMock).toHaveBeenCalledWith(
expect.stringContaining("memory-core dreaming checkpoint row"),
"Doctor changes",
);
await expect(fs.stat(path.join(sessionCorpusDir, "2026-04-06.txt"))).rejects.toMatchObject({
code: "ENOENT",
});
await expect(
readDreamingSessionCorpusText({
workspaceDir,
relativePath: "memory/.dreams/session-corpus/2026-04-06.txt",
env,
}),
).resolves.toBe("User: Store the legacy corpus in SQLite.\n");
});
});
});
});

View File

@@ -151,7 +151,12 @@ export async function legacyMemoryCoreDreamingStateFilesExist(params: {
}): Promise<boolean> {
for (const workspaceDir of configuredDreamingWorkspaces(params.cfg)) {
for (const relativePath of Object.values(DREAMING_STATE_RELATIVE_PATHS)) {
if (await fileExists(path.join(workspaceDir, relativePath))) {
const absolutePath = path.join(workspaceDir, relativePath);
const exists =
relativePath === DREAMING_STATE_RELATIVE_PATHS.sessionCorpusDir
? await dirExists(absolutePath)
: await fileExists(absolutePath);
if (exists) {
return true;
}
}