Skip to content

Commit 21aa297

Browse files
MonkeyLeeTjalehman
andauthored
fix(cron): auto-migrate legacy cron store (#90208)
Merged via squash. Prepared head SHA: f5aa1b6 Co-authored-by: MonkeyLeeT <6754057+MonkeyLeeT@users.noreply.github.com> Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com> Reviewed-by: @jalehman
1 parent 4752e9a commit 21aa297

3 files changed

Lines changed: 237 additions & 118 deletions

File tree

src/commands/doctor-config-preflight.state-migration.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ const autoMigrateLegacyState = vi.hoisted(() =>
1010
const autoMigrateLegacyTaskStateSidecars = vi.hoisted(() =>
1111
vi.fn(async () => ({ migrated: true, skipped: false, changes: ["task-imported"], warnings: [] })),
1212
);
13+
const repairLegacyCronStoreWithoutPrompt = vi.hoisted(() =>
14+
vi.fn(async () => ({ changes: ["cron-imported"], warnings: [] })),
15+
);
1316
const readConfigFileSnapshot = vi.hoisted(() =>
1417
vi.fn(async () => ({
1518
exists: true,
@@ -29,6 +32,10 @@ vi.mock("./doctor-state-migrations.js", () => ({
2932
autoMigrateLegacyTaskStateSidecars,
3033
}));
3134

35+
vi.mock("./doctor/cron/index.js", () => ({
36+
repairLegacyCronStoreWithoutPrompt,
37+
}));
38+
3239
vi.mock("../config/io.js", () => ({
3340
readConfigFileSnapshot,
3441
recoverConfigFromJsonRootSuffix: vi.fn(),
@@ -48,11 +55,15 @@ describe("runDoctorConfigPreflight state migration", () => {
4855

4956
expect(autoMigrateLegacyStateDir).toHaveBeenCalledOnce();
5057
expect(readConfigFileSnapshot).toHaveBeenCalledOnce();
58+
expect(repairLegacyCronStoreWithoutPrompt).toHaveBeenCalledWith({
59+
cfg: { gateway: { mode: "local", port: 19091 } },
60+
});
5161
expect(autoMigrateLegacyState).toHaveBeenCalledWith({
5262
cfg: { gateway: { mode: "local", port: 19091 } },
5363
env: process.env,
5464
recoverCorruptTargetStore: undefined,
5565
});
66+
expect(note).toHaveBeenCalledWith("- cron-imported", "Doctor changes");
5667
expect(note).toHaveBeenCalledWith("- imported", "Doctor changes");
5768
});
5869

@@ -90,6 +101,7 @@ describe("runDoctorConfigPreflight state migration", () => {
90101
});
91102

92103
expect(autoMigrateLegacyState).not.toHaveBeenCalled();
104+
expect(repairLegacyCronStoreWithoutPrompt).not.toHaveBeenCalled();
93105
expect(autoMigrateLegacyTaskStateSidecars).toHaveBeenCalledWith({ env: process.env });
94106
expect(note).toHaveBeenCalledWith("- task-imported", "Doctor changes");
95107
});

src/commands/doctor-config-preflight.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,21 @@ import { noteIncludeConfinementWarning } from "./doctor-config-analysis.js";
1616
import { findDoctorLegacyConfigIssues } from "./doctor/shared/legacy-config-issues.js";
1717

1818
type DoctorStateMigrationsModule = typeof import("./doctor-state-migrations.js");
19+
type DoctorCronModule = typeof import("./doctor/cron/index.js");
1920

2021
let doctorStateMigrationsPromise: Promise<DoctorStateMigrationsModule> | null = null;
22+
let doctorCronPromise: Promise<DoctorCronModule> | null = null;
2123

2224
function loadDoctorStateMigrations(): Promise<DoctorStateMigrationsModule> {
2325
doctorStateMigrationsPromise ??= import("./doctor-state-migrations.js");
2426
return doctorStateMigrationsPromise;
2527
}
2628

29+
function loadDoctorCron(): Promise<DoctorCronModule> {
30+
doctorCronPromise ??= import("./doctor/cron/index.js");
31+
return doctorCronPromise;
32+
}
33+
2734
async function maybeMigrateLegacyConfig(): Promise<string[]> {
2835
const changes: string[] = [];
2936
const home = resolveHomeDir();
@@ -174,6 +181,11 @@ export async function runDoctorConfigPreflight(
174181

175182
const baseConfig = snapshot.sourceConfig ?? snapshot.config ?? {};
176183
if (options.migrateState !== false) {
184+
if (snapshot.valid) {
185+
const { repairLegacyCronStoreWithoutPrompt } = await loadDoctorCron();
186+
const cronResult = await repairLegacyCronStoreWithoutPrompt({ cfg: baseConfig });
187+
noteStateMigrationResult(cronResult);
188+
}
177189
const { autoMigrateLegacyState, autoMigrateLegacyTaskStateSidecars } =
178190
await loadDoctorStateMigrations();
179191
const stateResult = snapshot.valid

0 commit comments

Comments
 (0)