Skip to content

Commit 5e41074

Browse files
authored
fix: gateway startup fails on legacy default channel allowlists (#108453)
* fix: migrate legacy default channel allowlists * docs: explain bundled-channel default-account boundary in allowFrom migration
1 parent 84ff010 commit 5e41074

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

‎src/infra/state-migrations.channel-pairing.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,27 @@ describe("legacy channel pairing state migration", () => {
8383
);
8484
});
8585

86+
it("imports a built-in channel's explicit default account without channel config", async () => {
87+
const { env, sourceDir } = await createFixture();
88+
const filePath = path.join(sourceDir, "whatsapp-default-allowFrom.json");
89+
writeJson(filePath, {
90+
version: 1,
91+
allowFrom: ["+12025550101", "+12025550102", "+12025550103"],
92+
});
93+
94+
const detected = detectLegacyChannelPairingState({ sourceDir });
95+
const result = migrateLegacyChannelPairingState({ detected, env });
96+
97+
expect(result.warnings).toEqual([]);
98+
expect(result.changes).toEqual([
99+
"Migrated 3 whatsapp/default allowFrom entries → shared SQLite state",
100+
]);
101+
expect(fs.existsSync(filePath)).toBe(false);
102+
expect(readChannelPairingStateSnapshot("whatsapp", env).allowFrom).toEqual({
103+
default: ["+12025550101", "+12025550102", "+12025550103"],
104+
});
105+
});
106+
86107
it("merges with authoritative SQLite rows and keeps unreadable sources", async () => {
87108
const { env, sourceDir } = await createFixture();
88109
const createdAt = new Date().toISOString();
@@ -159,6 +180,27 @@ describe("legacy channel pairing state migration", () => {
159180
expect(readChannelPairingStateSnapshot("telegram", env).allowFrom).toEqual({});
160181
});
161182

183+
it("does not infer default accounts for external channels", async () => {
184+
const { env, sourceDir } = await createFixture();
185+
const filePath = path.join(sourceDir, "custom-channel-default-allowFrom.json");
186+
writeJson(filePath, { version: 1, allowFrom: ["external-user"] });
187+
188+
const detected = detectLegacyChannelPairingState({
189+
sourceDir,
190+
configuredChannelIds: ["custom-channel"],
191+
});
192+
const result = migrateLegacyChannelPairingState({ detected, env });
193+
194+
expect(result.changes).toEqual([]);
195+
expect(result.warnings).toEqual([
196+
expect.stringContaining(
197+
"Legacy channel allowFrom channel/account is unresolved; left in place",
198+
),
199+
]);
200+
expect(fs.existsSync(filePath)).toBe(true);
201+
expect(readChannelPairingStateSnapshot("custom-channel", env).allowFrom).toEqual({});
202+
});
203+
162204
it("leaves overlapping channel and account filename interpretations in place", async () => {
163205
const { env, sourceDir } = await createFixture();
164206
const filePath = path.join(sourceDir, "telegram-business-allowFrom.json");

‎src/infra/state-migrations.channel-pairing.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ function parseAllowFromFilename(
112112
targets.push({ channel: channel as PairingChannel, accountId: matchingAccountIds[0] });
113113
} else if (matchingAccountIds.length > 1) {
114114
hasAccountCollision = true;
115+
} else if (accountKey === DEFAULT_ACCOUNT_ID && CHANNEL_IDS.includes(channel)) {
116+
// "default" is canonical, so bundled `<channel>-default` files resolve without config.
117+
// Keep this on CHANNEL_IDS: knownChannelIds also includes configured and pairing-file ids.
118+
// After safeAccountKey finds no match, those other channels must remain unresolved.
119+
targets.push({ channel: channel as PairingChannel, accountId: DEFAULT_ACCOUNT_ID });
115120
}
116121
}
117122
if (hasAccountCollision || targets.length > 1) {

0 commit comments

Comments
 (0)