fix: migrate legacy current binding ids

This commit is contained in:
Gustavo Madeira Santana
2026-04-10 12:01:50 -04:00
parent 70b57a4410
commit def7dcda96
2 changed files with 70 additions and 2 deletions

View File

@@ -156,6 +156,72 @@ describe("generic current-conversation bindings", () => {
});
});
it("migrates persisted legacy self-parent binding ids on load", async () => {
const filePath = __testing.resolveBindingsFilePath();
await fs.mkdir(path.dirname(filePath), { recursive: true });
await fs.writeFile(
filePath,
JSON.stringify({
version: 1,
bindings: [
{
bindingId: "generic:telegram\u241fdefault\u241f6098642967\u241f6098642967",
targetSessionKey: "agent:codex:acp:telegram-dm",
targetKind: "session",
conversation: {
channel: "telegram",
accountId: "default",
conversationId: "6098642967",
parentConversationId: "6098642967",
},
status: "active",
boundAt: 1234,
metadata: {
label: "telegram-dm",
},
},
],
}),
);
const resolved = resolveGenericCurrentConversationBinding({
channel: "telegram",
accountId: "default",
conversationId: "6098642967",
});
expect(resolved).toMatchObject({
bindingId: "generic:telegram\u241fdefault\u241f\u241f6098642967",
targetSessionKey: "agent:codex:acp:telegram-dm",
conversation: {
channel: "telegram",
accountId: "default",
conversationId: "6098642967",
},
});
expect(resolved?.conversation.parentConversationId).toBeUndefined();
await expect(
unbindGenericCurrentConversationBindings({
bindingId: resolved?.bindingId,
reason: "test cleanup",
}),
).resolves.toEqual([
expect.objectContaining({
bindingId: "generic:telegram\u241fdefault\u241f\u241f6098642967",
}),
]);
__testing.resetCurrentConversationBindingsForTests();
expect(
resolveGenericCurrentConversationBinding({
channel: "telegram",
accountId: "default",
conversationId: "6098642967",
}),
).toBeNull();
});
it("removes persisted bindings on unbind", async () => {
await bindGenericCurrentConversation({
targetSessionKey: "agent:codex:acp:googlechat-room",

View File

@@ -76,9 +76,11 @@ function loadBindingsIntoMemory(): void {
if (!record?.bindingId || !record?.conversation?.conversationId || isBindingExpired(record)) {
continue;
}
bindingsByConversationKey.set(buildConversationKey(record.conversation), {
const conversation = normalizeConversationRef(record.conversation);
bindingsByConversationKey.set(buildConversationKey(conversation), {
...record,
conversation: normalizeConversationRef(record.conversation),
bindingId: buildBindingId(conversation),
conversation,
});
}
}