refactor: stop requiring legacy session dirs

This commit is contained in:
Peter Steinberger
2026-05-08 12:59:55 +01:00
parent 5a2f63e00b
commit 4ca98227e9
2 changed files with 18 additions and 5 deletions

View File

@@ -181,6 +181,18 @@ describe("doctor state integrity oauth dir checks", () => {
expect(text).not.toContain("CRITICAL: OAuth dir missing");
});
it("does not require the legacy sessions directory for SQLite-backed sessions", async () => {
const cfg: OpenClawConfig = {};
const confirmRuntimeRepair = await runStateIntegrity(cfg);
expect(stateIntegrityText()).not.toContain("CRITICAL: Sessions dir missing");
expect(confirmRuntimeRepair).not.toHaveBeenCalledWith(
expect.objectContaining({
message: expect.stringContaining("Create Sessions dir"),
}),
);
});
it("does not prompt for oauth dir when whatsapp is configured without persisted auth state", async () => {
const cfg: OpenClawConfig = {
channels: {
@@ -425,7 +437,7 @@ describe("doctor state integrity oauth dir checks", () => {
});
it.skipIf(process.platform === "win32")(
"does not archive referenced transcripts when the state dir path resolves through a symlink",
"treats symlinked legacy transcript files as orphan cleanup candidates",
async () => {
const cfg: OpenClawConfig = {};
const originalHome = tempHome;
@@ -459,8 +471,10 @@ describe("doctor state integrity oauth dir checks", () => {
);
await noteStateIntegrity(cfg, { confirmRuntimeRepair, note: noteMock });
expect(fs.existsSync(transcriptPath)).toBe(true);
expect(stateIntegrityText()).not.toContain("These .jsonl files are no longer referenced");
expect(fs.existsSync(transcriptPath)).toBe(false);
expect(stateIntegrityText()).toContain(
"These legacy .jsonl files are no longer referenced by SQLite session rows",
);
} finally {
fs.rmSync(symlinkHome, { force: true, recursive: true });
}

View File

@@ -775,7 +775,6 @@ export async function noteStateIntegrity(
if (stateDirExists) {
const dirCandidates = new Map<string, string>();
dirCandidates.set(sessionsDir, "Sessions dir");
if (requireOAuthDir) {
dirCandidates.set(oauthDir, "OAuth dir");
} else if (!existsDir(oauthDir)) {
@@ -869,7 +868,7 @@ export async function noteStateIntegrity(
const store = Object.fromEntries(
listSessionEntries({ agentId, env }).map(({ sessionKey, entry }) => [sessionKey, entry]),
);
const sessionPathOpts = resolveSessionFilePathOptions({ agentId, sessionsDir });
const sessionPathOpts = resolveSessionFilePathOptions({ agentId });
const entries = Object.entries(store).filter(([, entry]) => entry && typeof entry === "object");
if (entries.length > 0) {
const recent = entries