mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 11:57:39 +00:00
refactor(test): dedupe doctor legacy migration fixtures
This commit is contained in:
@@ -92,37 +92,46 @@ export const autoMigrateLegacyStateDir = vi.fn().mockResolvedValue({
|
|||||||
warnings: [],
|
warnings: [],
|
||||||
}) as unknown as MockFn;
|
}) as unknown as MockFn;
|
||||||
|
|
||||||
export const detectLegacyStateMigrations = vi.fn().mockResolvedValue({
|
function createLegacyStateMigrationDetectionResult(params?: {
|
||||||
targetAgentId: "main",
|
hasLegacySessions?: boolean;
|
||||||
targetMainKey: "main",
|
preview?: string[];
|
||||||
targetScope: undefined,
|
}) {
|
||||||
stateDir: "/tmp/state",
|
return {
|
||||||
oauthDir: "/tmp/oauth",
|
targetAgentId: "main",
|
||||||
sessions: {
|
targetMainKey: "main",
|
||||||
legacyDir: "/tmp/state/sessions",
|
targetScope: undefined,
|
||||||
legacyStorePath: "/tmp/state/sessions/sessions.json",
|
stateDir: "/tmp/state",
|
||||||
targetDir: "/tmp/state/agents/main/sessions",
|
oauthDir: "/tmp/oauth",
|
||||||
targetStorePath: "/tmp/state/agents/main/sessions/sessions.json",
|
sessions: {
|
||||||
hasLegacy: false,
|
legacyDir: "/tmp/state/sessions",
|
||||||
legacyKeys: [],
|
legacyStorePath: "/tmp/state/sessions/sessions.json",
|
||||||
},
|
targetDir: "/tmp/state/agents/main/sessions",
|
||||||
agentDir: {
|
targetStorePath: "/tmp/state/agents/main/sessions/sessions.json",
|
||||||
legacyDir: "/tmp/state/agent",
|
hasLegacy: params?.hasLegacySessions ?? false,
|
||||||
targetDir: "/tmp/state/agents/main/agent",
|
legacyKeys: [],
|
||||||
hasLegacy: false,
|
},
|
||||||
},
|
agentDir: {
|
||||||
whatsappAuth: {
|
legacyDir: "/tmp/state/agent",
|
||||||
legacyDir: "/tmp/oauth",
|
targetDir: "/tmp/state/agents/main/agent",
|
||||||
targetDir: "/tmp/oauth/whatsapp/default",
|
hasLegacy: false,
|
||||||
hasLegacy: false,
|
},
|
||||||
},
|
whatsappAuth: {
|
||||||
pairingAllowFrom: {
|
legacyDir: "/tmp/oauth",
|
||||||
legacyTelegramPath: "/tmp/oauth/telegram-allowFrom.json",
|
targetDir: "/tmp/oauth/whatsapp/default",
|
||||||
targetTelegramPath: "/tmp/oauth/telegram-default-allowFrom.json",
|
hasLegacy: false,
|
||||||
hasLegacyTelegram: false,
|
},
|
||||||
},
|
pairingAllowFrom: {
|
||||||
preview: [],
|
legacyTelegramPath: "/tmp/oauth/telegram-allowFrom.json",
|
||||||
}) as unknown as MockFn;
|
targetTelegramPath: "/tmp/oauth/telegram-default-allowFrom.json",
|
||||||
|
hasLegacyTelegram: false,
|
||||||
|
},
|
||||||
|
preview: params?.preview ?? [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const detectLegacyStateMigrations = vi
|
||||||
|
.fn()
|
||||||
|
.mockResolvedValue(createLegacyStateMigrationDetectionResult()) as unknown as MockFn;
|
||||||
|
|
||||||
export const runLegacyStateMigrations = vi.fn().mockResolvedValue({
|
export const runLegacyStateMigrations = vi.fn().mockResolvedValue({
|
||||||
changes: [],
|
changes: [],
|
||||||
@@ -312,37 +321,12 @@ export async function arrangeLegacyStateMigrationTest(): Promise<{
|
|||||||
|
|
||||||
detectLegacyStateMigrations.mockClear();
|
detectLegacyStateMigrations.mockClear();
|
||||||
runLegacyStateMigrations.mockClear();
|
runLegacyStateMigrations.mockClear();
|
||||||
detectLegacyStateMigrations.mockResolvedValueOnce({
|
detectLegacyStateMigrations.mockResolvedValueOnce(
|
||||||
targetAgentId: "main",
|
createLegacyStateMigrationDetectionResult({
|
||||||
targetMainKey: "main",
|
hasLegacySessions: true,
|
||||||
targetScope: undefined,
|
preview: ["- Legacy sessions detected"],
|
||||||
stateDir: "/tmp/state",
|
}),
|
||||||
oauthDir: "/tmp/oauth",
|
);
|
||||||
sessions: {
|
|
||||||
legacyDir: "/tmp/state/sessions",
|
|
||||||
legacyStorePath: "/tmp/state/sessions/sessions.json",
|
|
||||||
targetDir: "/tmp/state/agents/main/sessions",
|
|
||||||
targetStorePath: "/tmp/state/agents/main/sessions/sessions.json",
|
|
||||||
hasLegacy: true,
|
|
||||||
legacyKeys: [],
|
|
||||||
},
|
|
||||||
agentDir: {
|
|
||||||
legacyDir: "/tmp/state/agent",
|
|
||||||
targetDir: "/tmp/state/agents/main/agent",
|
|
||||||
hasLegacy: false,
|
|
||||||
},
|
|
||||||
whatsappAuth: {
|
|
||||||
legacyDir: "/tmp/oauth",
|
|
||||||
targetDir: "/tmp/oauth/whatsapp/default",
|
|
||||||
hasLegacy: false,
|
|
||||||
},
|
|
||||||
pairingAllowFrom: {
|
|
||||||
legacyTelegramPath: "/tmp/oauth/telegram-allowFrom.json",
|
|
||||||
targetTelegramPath: "/tmp/oauth/telegram-default-allowFrom.json",
|
|
||||||
hasLegacyTelegram: false,
|
|
||||||
},
|
|
||||||
preview: ["- Legacy sessions detected"],
|
|
||||||
});
|
|
||||||
runLegacyStateMigrations.mockResolvedValueOnce({
|
runLegacyStateMigrations.mockResolvedValueOnce({
|
||||||
changes: ["migrated"],
|
changes: ["migrated"],
|
||||||
warnings: [],
|
warnings: [],
|
||||||
|
|||||||
Reference in New Issue
Block a user