fix(cli): repair legacy config before update channel switch (#77069)

* fix(cli): repair legacy config before update channel switch

* docs(changelog): note update channel legacy config repair

* fix(update): keep legacy config repair doctor-owned

* fix(update): keep dry runs read-only

* fix(update): avoid include-flattening legacy repair
This commit is contained in:
Vincent Koc
2026-05-05 17:54:53 -07:00
committed by GitHub
parent d12c4d832d
commit fcf0561da0
4 changed files with 265 additions and 5 deletions

View File

@@ -1686,6 +1686,23 @@ function createUpdatedChannelSnapshot(
};
}
async function maybeRepairLegacyConfigForUpdateChannel(params: {
configSnapshot: Awaited<ReturnType<typeof readConfigFileSnapshot>>;
jsonMode: boolean;
}): Promise<Awaited<ReturnType<typeof readConfigFileSnapshot>>> {
if (params.configSnapshot.valid || params.configSnapshot.legacyIssues.length === 0) {
return params.configSnapshot;
}
const { repairLegacyConfigForUpdateChannel } =
await import("../../commands/doctor/legacy-config-repair.js");
const { snapshot, repaired } = await repairLegacyConfigForUpdateChannel(params);
if (!params.jsonMode && repaired) {
defaultRuntime.log(theme.muted("Migrated legacy config before changing update channel."));
}
return snapshot;
}
async function writePostCorePluginUpdateResultFile(
filePath: string | undefined,
result: PostCorePluginUpdateResult,
@@ -1947,17 +1964,24 @@ export async function updateCommand(opts: UpdateCommandOptions): Promise<void> {
includeRegistry: false,
});
const configSnapshot = await readConfigFileSnapshot();
const storedChannel = configSnapshot.valid
? normalizeUpdateChannel(configSnapshot.config.update?.channel)
: null;
const requestedChannel = normalizeUpdateChannel(opts.channel);
if (opts.channel && !requestedChannel) {
defaultRuntime.error(`--channel must be "stable", "beta", or "dev" (got "${opts.channel}")`);
defaultRuntime.exit(1);
return;
}
let configSnapshot = await readConfigFileSnapshot();
if (opts.channel && !opts.dryRun && !configSnapshot.valid) {
configSnapshot = await maybeRepairLegacyConfigForUpdateChannel({
configSnapshot,
jsonMode: Boolean(opts.json),
});
}
const storedChannel = configSnapshot.valid
? normalizeUpdateChannel(configSnapshot.config.update?.channel)
: null;
if (opts.channel && !configSnapshot.valid) {
const issues = formatConfigIssueLines(configSnapshot.issues, "-");
defaultRuntime.error(["Config is invalid; cannot set update channel.", ...issues].join("\n"));