mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-18 04:31:10 +00:00
fix: migrate legacy current binding ids
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user