import { describe, expect, it } from "vitest"; import { formatBackupCreateSummary, type BackupCreateResult } from "./backup-create.js"; function makeResult(overrides: Partial = {}): BackupCreateResult { return { createdAt: "2026-01-01T00:00:00.000Z", archiveRoot: "openclaw-backup-2026-01-01", archivePath: "/tmp/openclaw-backup.tar.gz", dryRun: false, includeWorkspace: true, onlyConfig: false, verified: false, assets: [], skipped: [], ...overrides, }; } describe("formatBackupCreateSummary", () => { it("formats created archives with included and skipped paths", () => { const lines = formatBackupCreateSummary( makeResult({ verified: true, assets: [ { kind: "state", sourcePath: "/state", archivePath: "archive/state", displayPath: "~/.openclaw", }, ], skipped: [ { kind: "workspace", sourcePath: "/workspace", displayPath: "~/Projects/openclaw", reason: "covered", coveredBy: "~/.openclaw", }, ], }), ); expect(lines).toEqual([ "Backup archive: /tmp/openclaw-backup.tar.gz", "Included 1 path:", "- state: ~/.openclaw", "Skipped 1 path:", "- workspace: ~/Projects/openclaw (covered by ~/.openclaw)", "Created /tmp/openclaw-backup.tar.gz", "Archive verification: passed", ]); }); it("formats dry runs and pluralized counts", () => { const lines = formatBackupCreateSummary( makeResult({ dryRun: true, assets: [ { kind: "config", sourcePath: "/config", archivePath: "archive/config", displayPath: "~/.openclaw/config.json", }, { kind: "credentials", sourcePath: "/oauth", archivePath: "archive/oauth", displayPath: "~/.openclaw/oauth", }, ], }), ); expect(lines).toEqual([ "Backup archive: /tmp/openclaw-backup.tar.gz", "Included 2 paths:", "- config: ~/.openclaw/config.json", "- credentials: ~/.openclaw/oauth", "Dry run only; archive was not written.", ]); }); });