fix(doctor): add headless flags + auto-migrate sessions

This commit is contained in:
Peter Steinberger
2026-01-07 04:43:05 +01:00
parent 9c9ae5aa54
commit 6ffece68b0
9 changed files with 350 additions and 76 deletions

View File

@@ -6,9 +6,9 @@ import { afterEach, describe, expect, it, vi } from "vitest";
import type { ClawdbotConfig } from "../config/config.js";
import {
autoMigrateLegacyAgentDir,
autoMigrateLegacyState,
detectLegacyStateMigrations,
resetAutoMigrateLegacyAgentDirForTest,
resetAutoMigrateLegacyStateForTest,
runLegacyStateMigrations,
} from "./doctor-state-migrations.js";
@@ -23,7 +23,7 @@ async function makeTempRoot() {
}
afterEach(async () => {
resetAutoMigrateLegacyAgentDirForTest();
resetAutoMigrateLegacyStateForTest();
if (!tempRoot) return;
await fs.promises.rm(tempRoot, { recursive: true, force: true });
tempRoot = null;
@@ -111,7 +111,7 @@ describe("doctor legacy state migrations", () => {
const log = { info: vi.fn(), warn: vi.fn() };
const result = await autoMigrateLegacyAgentDir({
const result = await autoMigrateLegacyState({
cfg,
env: { CLAWDBOT_STATE_DIR: root } as NodeJS.ProcessEnv,
log,
@@ -123,6 +123,35 @@ describe("doctor legacy state migrations", () => {
expect(log.info).toHaveBeenCalled();
});
it("auto-migrates legacy sessions on startup", async () => {
const root = await makeTempRoot();
const cfg: ClawdbotConfig = {};
const legacySessionsDir = path.join(root, "sessions");
fs.mkdirSync(legacySessionsDir, { recursive: true });
writeJson5(path.join(legacySessionsDir, "sessions.json"), {
"+1555": { sessionId: "a", updatedAt: 10 },
});
fs.writeFileSync(path.join(legacySessionsDir, "a.jsonl"), "a", "utf-8");
const log = { info: vi.fn(), warn: vi.fn() };
const result = await autoMigrateLegacyState({
cfg,
env: { CLAWDBOT_STATE_DIR: root } as NodeJS.ProcessEnv,
log,
now: () => 123,
});
expect(result.migrated).toBe(true);
expect(log.info).toHaveBeenCalled();
const targetDir = path.join(root, "agents", "main", "sessions");
expect(fs.existsSync(path.join(targetDir, "a.jsonl"))).toBe(true);
expect(fs.existsSync(path.join(legacySessionsDir, "a.jsonl"))).toBe(false);
expect(fs.existsSync(path.join(targetDir, "sessions.json"))).toBe(true);
});
it("migrates legacy WhatsApp auth files without touching oauth.json", async () => {
const root = await makeTempRoot();
const cfg: ClawdbotConfig = {};