fix(cli): emit migrate-storage invocation event

This commit is contained in:
Dhruv Sharma 2026-05-10 17:10:08 +05:30
parent e50ce95d0e
commit 58eb015dfc
2 changed files with 34 additions and 0 deletions

View File

@ -52,6 +52,28 @@ describe("ao migrate-storage — activity events", () => {
consoleLogSpy.mockRestore();
});
it("emits cli.migration_invoked before migration work starts", async () => {
mockMigrateStorage.mockImplementation(async () => {
expect(recordedEvents()).toContainEqual(
expect.objectContaining({
kind: "cli.migration_invoked",
source: "cli",
level: "info",
data: expect.objectContaining({
rollback: false,
dryRun: true,
force: true,
}),
}),
);
return { projects: 1 };
});
await program.parseAsync(["node", "ao", "migrate-storage", "--dry-run", "--force"]);
expect(mockMigrateStorage).toHaveBeenCalledOnce();
});
it("emits cli.migration_failed when migrateStorage throws", async () => {
mockMigrateStorage.mockRejectedValue(new Error("disk full"));

View File

@ -13,6 +13,18 @@ export function registerMigrateStorage(program: Command): void {
.option("--rollback", "Reverse a previous migration (restores .migrated directories)")
.action(
async (opts: { dryRun?: boolean; force?: boolean; rollback?: boolean }) => {
recordActivityEvent({
source: "cli",
kind: "cli.migration_invoked",
level: "info",
summary: `storage ${opts.rollback ? "rollback" : "migration"} invoked`,
data: {
rollback: opts.rollback === true,
dryRun: opts.dryRun === true,
force: opts.force === true,
},
});
try {
if (opts.rollback) {
await rollbackStorage({