From 481bd37dabcb1f50e45bbdd0d997ab82c609e5a9 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 10 May 2026 22:27:10 +0100 Subject: [PATCH] test: tighten conversation binding assertions --- .../current-conversation-bindings.test.ts | 122 ++++++++++-------- 1 file changed, 68 insertions(+), 54 deletions(-) diff --git a/src/infra/outbound/current-conversation-bindings.test.ts b/src/infra/outbound/current-conversation-bindings.test.ts index 50c396b5859..743a613aa1c 100644 --- a/src/infra/outbound/current-conversation-bindings.test.ts +++ b/src/infra/outbound/current-conversation-bindings.test.ts @@ -22,6 +22,27 @@ function expectSessionBinding(bound: SessionBindingRecord | null): SessionBindin return bound; } +function expectBindingFields( + binding: SessionBindingRecord | null | undefined, + expected: Partial, +): 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, +): 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, - }), + }, ); }); });