refactor(test): dedupe doctor legacy migration fixtures

This commit is contained in:
Peter Steinberger
2026-02-16 22:47:26 +00:00
parent 389eb8ba10
commit af5d4ac7d3

View File

@@ -92,7 +92,11 @@ 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?: {
hasLegacySessions?: boolean;
preview?: string[];
}) {
return {
targetAgentId: "main", targetAgentId: "main",
targetMainKey: "main", targetMainKey: "main",
targetScope: undefined, targetScope: undefined,
@@ -103,7 +107,7 @@ export const detectLegacyStateMigrations = vi.fn().mockResolvedValue({
legacyStorePath: "/tmp/state/sessions/sessions.json", legacyStorePath: "/tmp/state/sessions/sessions.json",
targetDir: "/tmp/state/agents/main/sessions", targetDir: "/tmp/state/agents/main/sessions",
targetStorePath: "/tmp/state/agents/main/sessions/sessions.json", targetStorePath: "/tmp/state/agents/main/sessions/sessions.json",
hasLegacy: false, hasLegacy: params?.hasLegacySessions ?? false,
legacyKeys: [], legacyKeys: [],
}, },
agentDir: { agentDir: {
@@ -121,8 +125,13 @@ export const detectLegacyStateMigrations = vi.fn().mockResolvedValue({
targetTelegramPath: "/tmp/oauth/telegram-default-allowFrom.json", targetTelegramPath: "/tmp/oauth/telegram-default-allowFrom.json",
hasLegacyTelegram: false, hasLegacyTelegram: false,
}, },
preview: [], preview: params?.preview ?? [],
}) as unknown as MockFn; };
}
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,
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"], preview: ["- Legacy sessions detected"],
}); }),
);
runLegacyStateMigrations.mockResolvedValueOnce({ runLegacyStateMigrations.mockResolvedValueOnce({
changes: ["migrated"], changes: ["migrated"],
warnings: [], warnings: [],