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,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: [],