|
1 | 1 | // Whatsapp tests cover setup entry plugin behavior. |
| 2 | +import fs from "node:fs"; |
| 3 | +import os from "node:os"; |
| 4 | +import path from "node:path"; |
2 | 5 | import { describe, expect, it, vi } from "vitest"; |
3 | 6 | import * as legacySessionSurfaceApi from "./legacy-session-surface-api.js"; |
4 | 7 | import * as legacyStateMigrationsApi from "./legacy-state-migrations-api.js"; |
@@ -68,6 +71,57 @@ describe("whatsapp setup entry", () => { |
68 | 71 | expect(legacySessionSurface.isLegacyGroupSessionKey).toBeTypeOf("function"); |
69 | 72 | }); |
70 | 73 |
|
| 74 | + it("plans migration for every Baileys auth category while preserving other shared-root files", async () => { |
| 75 | + const oauthDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-wa-legacy-migration-")); |
| 76 | + const authFiles = [ |
| 77 | + "creds.json", |
| 78 | + "creds.json.bak", |
| 79 | + "pre-key-1.json", |
| 80 | + "session-contact.json", |
| 81 | + "sender-key-group.json", |
| 82 | + "sender-key-memory-group.json", |
| 83 | + "app-state-sync-key-contact.json", |
| 84 | + "app-state-sync-version-contact.json", |
| 85 | + "lid-mapping-15551234567.json", |
| 86 | + "device-list-15551234567.json", |
| 87 | + "tctoken-15551234567.json", |
| 88 | + "identity-key-15551234567.json", |
| 89 | + ]; |
| 90 | + |
| 91 | + try { |
| 92 | + for (const file of [...authFiles, "oauth.json", "google-oauth.json", "notes.txt"]) { |
| 93 | + fs.writeFileSync(path.join(oauthDir, file), "{}", "utf-8"); |
| 94 | + } |
| 95 | + fs.mkdirSync(path.join(oauthDir, "nested")); |
| 96 | + fs.writeFileSync(path.join(oauthDir, "nested", "session-keep.json"), "{}", "utf-8"); |
| 97 | + fs.symlinkSync(path.join(oauthDir, "notes.txt"), path.join(oauthDir, "session-linked.json")); |
| 98 | + |
| 99 | + const detectLegacyStateMigrations = |
| 100 | + setupEntry.loadLegacyStateMigrationDetector?.(setupEntryLoadOptions); |
| 101 | + if (!detectLegacyStateMigrations) { |
| 102 | + throw new Error("expected WhatsApp legacy state migration detector"); |
| 103 | + } |
| 104 | + const migrations = |
| 105 | + (await detectLegacyStateMigrations({ |
| 106 | + cfg: {}, |
| 107 | + env: {}, |
| 108 | + oauthDir, |
| 109 | + stateDir: oauthDir, |
| 110 | + })) ?? []; |
| 111 | + |
| 112 | + expect(migrations.map((migration) => path.basename(migration.sourcePath)).toSorted()).toEqual( |
| 113 | + authFiles.toSorted(), |
| 114 | + ); |
| 115 | + for (const migration of migrations) { |
| 116 | + expect(migration.targetPath).toBe( |
| 117 | + path.join(oauthDir, "whatsapp", "default", path.basename(migration.sourcePath)), |
| 118 | + ); |
| 119 | + } |
| 120 | + } finally { |
| 121 | + fs.rmSync(oauthDir, { recursive: true, force: true }); |
| 122 | + } |
| 123 | + }); |
| 124 | + |
71 | 125 | it("loads the delegated setup wizard without importing runtime dependencies", async () => { |
72 | 126 | const { whatsappSetupWizard } = await import("./src/setup-surface.js"); |
73 | 127 |
|
|
0 commit comments