mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-24 14:11:04 +00:00
test: tighten conversation binding assertions
This commit is contained in:
@@ -22,6 +22,27 @@ function expectSessionBinding(bound: SessionBindingRecord | null): SessionBindin
|
||||
return bound;
|
||||
}
|
||||
|
||||
function expectBindingFields(
|
||||
binding: SessionBindingRecord | null | undefined,
|
||||
expected: Partial<SessionBindingRecord>,
|
||||
): SessionBindingRecord {
|
||||
const record = expectSessionBinding(binding ?? null);
|
||||
for (const [key, value] of Object.entries(expected)) {
|
||||
expect(record[key as keyof SessionBindingRecord]).toEqual(value);
|
||||
}
|
||||
return record;
|
||||
}
|
||||
|
||||
function expectBindingMetadata(
|
||||
binding: SessionBindingRecord | null | undefined,
|
||||
expected: Record<string, unknown>,
|
||||
): void {
|
||||
const metadata = expectSessionBinding(binding ?? null).metadata;
|
||||
for (const [key, value] of Object.entries(expected)) {
|
||||
expect(metadata?.[key]).toEqual(value);
|
||||
}
|
||||
}
|
||||
|
||||
function setMinimalCurrentConversationRegistry(): void {
|
||||
setActivePluginRegistry(
|
||||
createTestRegistry([
|
||||
@@ -111,26 +132,23 @@ describe("generic current-conversation bindings", () => {
|
||||
},
|
||||
});
|
||||
|
||||
expect(bound).toMatchObject({
|
||||
expectBindingFields(bound, {
|
||||
bindingId: "generic:workspace\u241fdefault\u241f\u241fuser:U123",
|
||||
targetSessionKey: "agent:codex:acp:workspace-dm",
|
||||
});
|
||||
|
||||
__testing.resetCurrentConversationBindingsForTests();
|
||||
|
||||
expect(
|
||||
resolveGenericCurrentConversationBinding({
|
||||
channel: "workspace",
|
||||
accountId: "default",
|
||||
conversationId: "user:U123",
|
||||
}),
|
||||
).toMatchObject({
|
||||
const resolved = resolveGenericCurrentConversationBinding({
|
||||
channel: "workspace",
|
||||
accountId: "default",
|
||||
conversationId: "user:U123",
|
||||
});
|
||||
expectBindingFields(resolved, {
|
||||
bindingId: "generic:workspace\u241fdefault\u241f\u241fuser:U123",
|
||||
targetSessionKey: "agent:codex:acp:workspace-dm",
|
||||
metadata: expect.objectContaining({
|
||||
label: "workspace-dm",
|
||||
}),
|
||||
});
|
||||
expectBindingMetadata(resolved, { label: "workspace-dm" });
|
||||
});
|
||||
|
||||
it("normalizes persisted target session keys on reload", async () => {
|
||||
@@ -166,21 +184,19 @@ describe("generic current-conversation bindings", () => {
|
||||
conversationId: "user:U123",
|
||||
});
|
||||
|
||||
expect(resolved).toMatchObject({
|
||||
expectBindingFields(resolved, {
|
||||
bindingId: "generic:workspace\u241fdefault\u241f\u241fuser:U123",
|
||||
targetSessionKey: "agent:codex:acp:workspace-dm",
|
||||
metadata: expect.objectContaining({
|
||||
label: "workspace-dm",
|
||||
}),
|
||||
});
|
||||
expect(listGenericCurrentConversationBindingsBySession("agent:codex:acp:workspace-dm")).toEqual(
|
||||
[
|
||||
expect.objectContaining({
|
||||
bindingId: "generic:workspace\u241fdefault\u241f\u241fuser:U123",
|
||||
targetSessionKey: "agent:codex:acp:workspace-dm",
|
||||
}),
|
||||
],
|
||||
expectBindingMetadata(resolved, { label: "workspace-dm" });
|
||||
const bindings = listGenericCurrentConversationBindingsBySession(
|
||||
"agent:codex:acp:workspace-dm",
|
||||
);
|
||||
expect(bindings).toHaveLength(1);
|
||||
expectBindingFields(bindings[0], {
|
||||
bindingId: "generic:workspace\u241fdefault\u241f\u241fuser:U123",
|
||||
targetSessionKey: "agent:codex:acp:workspace-dm",
|
||||
});
|
||||
});
|
||||
|
||||
it("drops self-parent conversation refs when storing generic current bindings", async () => {
|
||||
@@ -195,25 +211,26 @@ describe("generic current-conversation bindings", () => {
|
||||
},
|
||||
});
|
||||
|
||||
expect(bound).toMatchObject({
|
||||
const boundRecord = expectBindingFields(bound, {
|
||||
bindingId: "generic:forum\u241fdefault\u241f\u241f6098642967",
|
||||
conversation: {
|
||||
channel: "forum",
|
||||
accountId: "default",
|
||||
conversationId: "6098642967",
|
||||
},
|
||||
});
|
||||
expect(boundRecord.conversation).toEqual({
|
||||
channel: "forum",
|
||||
accountId: "default",
|
||||
conversationId: "6098642967",
|
||||
});
|
||||
expect(bound?.conversation.parentConversationId).toBeUndefined();
|
||||
expect(
|
||||
expectBindingFields(
|
||||
resolveGenericCurrentConversationBinding({
|
||||
channel: "forum",
|
||||
accountId: "default",
|
||||
conversationId: "6098642967",
|
||||
}),
|
||||
).toMatchObject({
|
||||
bindingId: "generic:forum\u241fdefault\u241f\u241f6098642967",
|
||||
targetSessionKey: "agent:codex:acp:forum-dm",
|
||||
});
|
||||
{
|
||||
bindingId: "generic:forum\u241fdefault\u241f\u241f6098642967",
|
||||
targetSessionKey: "agent:codex:acp:forum-dm",
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it("migrates persisted legacy self-parent binding ids on load", async () => {
|
||||
@@ -250,27 +267,25 @@ describe("generic current-conversation bindings", () => {
|
||||
conversationId: "6098642967",
|
||||
});
|
||||
|
||||
expect(resolved).toMatchObject({
|
||||
const resolvedRecord = expectBindingFields(resolved, {
|
||||
bindingId: "generic:forum\u241fdefault\u241f\u241f6098642967",
|
||||
targetSessionKey: "agent:codex:acp:forum-dm",
|
||||
conversation: {
|
||||
channel: "forum",
|
||||
accountId: "default",
|
||||
conversationId: "6098642967",
|
||||
},
|
||||
});
|
||||
expect(resolvedRecord.conversation).toEqual({
|
||||
channel: "forum",
|
||||
accountId: "default",
|
||||
conversationId: "6098642967",
|
||||
});
|
||||
expect(resolved?.conversation.parentConversationId).toBeUndefined();
|
||||
|
||||
await expect(
|
||||
unbindGenericCurrentConversationBindings({
|
||||
bindingId: resolved?.bindingId,
|
||||
reason: "test cleanup",
|
||||
}),
|
||||
).resolves.toEqual([
|
||||
expect.objectContaining({
|
||||
bindingId: "generic:forum\u241fdefault\u241f\u241f6098642967",
|
||||
}),
|
||||
]);
|
||||
const unbound = await unbindGenericCurrentConversationBindings({
|
||||
bindingId: resolved?.bindingId,
|
||||
reason: "test cleanup",
|
||||
});
|
||||
expect(unbound).toHaveLength(1);
|
||||
expectBindingFields(unbound[0], {
|
||||
bindingId: "generic:forum\u241fdefault\u241f\u241f6098642967",
|
||||
});
|
||||
|
||||
__testing.resetCurrentConversationBindingsForTests();
|
||||
expect(
|
||||
@@ -332,17 +347,16 @@ describe("generic current-conversation bindings", () => {
|
||||
|
||||
__testing.resetCurrentConversationBindingsForTests();
|
||||
|
||||
expect(
|
||||
expectBindingMetadata(
|
||||
resolveGenericCurrentConversationBinding({
|
||||
channel: "workspace",
|
||||
accountId: "default",
|
||||
conversationId: "user:U123",
|
||||
})?.metadata,
|
||||
).toEqual(
|
||||
expect.objectContaining({
|
||||
}),
|
||||
{
|
||||
label: "workspace-dm",
|
||||
lastActivityAt: 1_234_567_890,
|
||||
}),
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user