




















@@ -22,6 +22,27 @@ function expectSessionBinding(bound: SessionBindingRecord | null): SessionBindin
2222return bound;
2323}
242425+function expectBindingFields(
26+binding: SessionBindingRecord | null | undefined,
27+expected: Partial<SessionBindingRecord>,
28+): SessionBindingRecord {
29+const record = expectSessionBinding(binding ?? null);
30+for (const [key, value] of Object.entries(expected)) {
31+expect(record[key as keyof SessionBindingRecord]).toEqual(value);
32+}
33+return record;
34+}
35+36+function expectBindingMetadata(
37+binding: SessionBindingRecord | null | undefined,
38+expected: Record<string, unknown>,
39+): void {
40+const metadata = expectSessionBinding(binding ?? null).metadata;
41+for (const [key, value] of Object.entries(expected)) {
42+expect(metadata?.[key]).toEqual(value);
43+}
44+}
45+2546function setMinimalCurrentConversationRegistry(): void {
2647setActivePluginRegistry(
2748createTestRegistry([
@@ -111,26 +132,23 @@ describe("generic current-conversation bindings", () => {
111132},
112133});
113134114-expect(bound).toMatchObject({
135+expectBindingFields(bound, {
115136bindingId: "generic:workspace\u241fdefault\u241f\u241fuser:U123",
116137targetSessionKey: "agent:codex:acp:workspace-dm",
117138});
118139119140__testing.resetCurrentConversationBindingsForTests();
120141121-expect(
122-resolveGenericCurrentConversationBinding({
123-channel: "workspace",
124-accountId: "default",
125-conversationId: "user:U123",
126-}),
127-).toMatchObject({
142+const resolved = resolveGenericCurrentConversationBinding({
143+channel: "workspace",
144+accountId: "default",
145+conversationId: "user:U123",
146+});
147+expectBindingFields(resolved, {
128148bindingId: "generic:workspace\u241fdefault\u241f\u241fuser:U123",
129149targetSessionKey: "agent:codex:acp:workspace-dm",
130-metadata: expect.objectContaining({
131-label: "workspace-dm",
132-}),
133150});
151+expectBindingMetadata(resolved, { label: "workspace-dm" });
134152});
135153136154it("normalizes persisted target session keys on reload", async () => {
@@ -166,21 +184,19 @@ describe("generic current-conversation bindings", () => {
166184conversationId: "user:U123",
167185});
168186169-expect(resolved).toMatchObject({
187+expectBindingFields(resolved, {
170188bindingId: "generic:workspace\u241fdefault\u241f\u241fuser:U123",
171189targetSessionKey: "agent:codex:acp:workspace-dm",
172-metadata: expect.objectContaining({
173-label: "workspace-dm",
174-}),
175190});
176-expect(listGenericCurrentConversationBindingsBySession("agent:codex:acp:workspace-dm")).toEqual(
177-[
178-expect.objectContaining({
179-bindingId: "generic:workspace\u241fdefault\u241f\u241fuser:U123",
180-targetSessionKey: "agent:codex:acp:workspace-dm",
181-}),
182-],
191+expectBindingMetadata(resolved, { label: "workspace-dm" });
192+const bindings = listGenericCurrentConversationBindingsBySession(
193+"agent:codex:acp:workspace-dm",
183194);
195+expect(bindings).toHaveLength(1);
196+expectBindingFields(bindings[0], {
197+bindingId: "generic:workspace\u241fdefault\u241f\u241fuser:U123",
198+targetSessionKey: "agent:codex:acp:workspace-dm",
199+});
184200});
185201186202it("drops self-parent conversation refs when storing generic current bindings", async () => {
@@ -195,25 +211,26 @@ describe("generic current-conversation bindings", () => {
195211},
196212});
197213198-expect(bound).toMatchObject({
214+const boundRecord = expectBindingFields(bound, {
199215bindingId: "generic:forum\u241fdefault\u241f\u241f6098642967",
200- conversation: {
201- channel: "forum",
202- accountId: "default",
203- conversationId: "6098642967",
204-},
216+});
217+expect(boundRecord.conversation).toEqual({
218+channel: "forum",
219+accountId: "default",
220+conversationId: "6098642967",
205221});
206222expect(bound?.conversation.parentConversationId).toBeUndefined();
207-expect(
223+expectBindingFields(
208224resolveGenericCurrentConversationBinding({
209225channel: "forum",
210226accountId: "default",
211227conversationId: "6098642967",
212228}),
213-).toMatchObject({
214-bindingId: "generic:forum\u241fdefault\u241f\u241f6098642967",
215-targetSessionKey: "agent:codex:acp:forum-dm",
216-});
229+{
230+bindingId: "generic:forum\u241fdefault\u241f\u241f6098642967",
231+targetSessionKey: "agent:codex:acp:forum-dm",
232+},
233+);
217234});
218235219236it("migrates persisted legacy self-parent binding ids on load", async () => {
@@ -250,27 +267,25 @@ describe("generic current-conversation bindings", () => {
250267conversationId: "6098642967",
251268});
252269253-expect(resolved).toMatchObject({
270+const resolvedRecord = expectBindingFields(resolved, {
254271bindingId: "generic:forum\u241fdefault\u241f\u241f6098642967",
255272targetSessionKey: "agent:codex:acp:forum-dm",
256- conversation: {
257- channel: "forum",
258- accountId: "default",
259- conversationId: "6098642967",
260-},
273+});
274+expect(resolvedRecord.conversation).toEqual({
275+channel: "forum",
276+accountId: "default",
277+conversationId: "6098642967",
261278});
262279expect(resolved?.conversation.parentConversationId).toBeUndefined();
263280264-await expect(
265-unbindGenericCurrentConversationBindings({
266-bindingId: resolved?.bindingId,
267-reason: "test cleanup",
268-}),
269-).resolves.toEqual([
270-expect.objectContaining({
271-bindingId: "generic:forum\u241fdefault\u241f\u241f6098642967",
272-}),
273-]);
281+const unbound = await unbindGenericCurrentConversationBindings({
282+bindingId: resolved?.bindingId,
283+reason: "test cleanup",
284+});
285+expect(unbound).toHaveLength(1);
286+expectBindingFields(unbound[0], {
287+bindingId: "generic:forum\u241fdefault\u241f\u241f6098642967",
288+});
274289275290__testing.resetCurrentConversationBindingsForTests();
276291expect(
@@ -332,17 +347,16 @@ describe("generic current-conversation bindings", () => {
332347333348__testing.resetCurrentConversationBindingsForTests();
334349335-expect(
350+expectBindingMetadata(
336351resolveGenericCurrentConversationBinding({
337352channel: "workspace",
338353accountId: "default",
339354conversationId: "user:U123",
340-})?.metadata,
341-).toEqual(
342-expect.objectContaining({
355+}),
356+{
343357label: "workspace-dm",
344358lastActivityAt: 1_234_567_890,
345-}),
359+},
346360);
347361});
348362});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。