fix: stabilize channel migration

This commit is contained in:
Peter Steinberger
2026-01-13 06:27:55 +00:00
parent 90342a4f3a
commit 993c1de361
6 changed files with 39 additions and 24 deletions

View File

@@ -2003,11 +2003,14 @@ describe("config preservation on validation failure", () => {
const { readConfigFileSnapshot } = await import("./config.js");
const snap = await readConfigFileSnapshot();
expect(snap.valid).toBe(false);
expect(snap.legacyIssues.length).toBeGreaterThan(0);
expect(snap.valid).toBe(true);
expect(snap.legacyIssues).toHaveLength(0);
expect((snap.config as Record<string, unknown>).customData).toEqual({
preserved: true,
});
expect(snap.config.channels?.whatsapp?.allowFrom).toEqual([
"+15555550123",
]);
});
});
});

View File

@@ -352,11 +352,15 @@ export function createConfigIO(overrides: ConfigIoDeps = {}) {
}
const migrated = applyLegacyMigrations(resolved);
const resolvedConfig = migrated.next ?? resolved;
const legacyIssues = findLegacyConfigIssues(resolvedConfig);
const resolvedConfigRaw = migrated.next ?? resolved;
const legacyIssues = findLegacyConfigIssues(resolvedConfigRaw);
const validated = validateConfigObject(resolvedConfig);
const validated = validateConfigObject(resolvedConfigRaw);
if (!validated.ok) {
const resolvedConfig =
typeof resolvedConfigRaw === "object" && resolvedConfigRaw !== null
? (resolvedConfigRaw as ClawdbotConfig)
: {};
return {
path: configPath,
exists: true,