|
9 | 9 | const BOT_PUBLIC_KEY = "a".repeat(64); |
10 | 10 | const ALICE_PUBLIC_KEY = "b".repeat(64); |
11 | 11 | const SECOND_ALICE_PUBLIC_KEY = "c".repeat(64); |
| 12 | +const BOB_PUBLIC_KEY = "d".repeat(64); |
12 | 13 |
|
13 | 14 | function members(...values: BuzzMentionMember[]): BuzzMentionMember[] { |
14 | 15 | return [{ publicKey: BOT_PUBLIC_KEY, displayName: "OpenClaw" }, ...values]; |
@@ -82,6 +83,51 @@ describe("Buzz outbound mentions", () => { |
82 | 83 | ).toEqual([ALICE_PUBLIC_KEY]); |
83 | 84 | }); |
84 | 85 |
|
| 86 | + it("requires explicit identities to resolve the named member they accompany", () => { |
| 87 | + const explicitBob = nip19.npubEncode(BOB_PUBLIC_KEY); |
| 88 | + const roomMembers = members( |
| 89 | + { publicKey: ALICE_PUBLIC_KEY, displayName: "Alice" }, |
| 90 | + { publicKey: SECOND_ALICE_PUBLIC_KEY, displayName: "Alice" }, |
| 91 | + { publicKey: BOB_PUBLIC_KEY, displayName: "Bob" }, |
| 92 | + ); |
| 93 | + |
| 94 | + expect(() => |
| 95 | + resolveBuzzMessageMentions({ |
| 96 | + text: `Hello @Missing (nostr:${explicitBob})`, |
| 97 | + members: roomMembers, |
| 98 | + senderPublicKey: BOT_PUBLIC_KEY, |
| 99 | + }), |
| 100 | + ).toThrow('Buzz mention "@missing" does not match a current room member'); |
| 101 | + |
| 102 | + expect(() => |
| 103 | + resolveBuzzMessageMentions({ |
| 104 | + text: `Hello @Alice (nostr:${explicitBob})`, |
| 105 | + members: roomMembers, |
| 106 | + senderPublicKey: BOT_PUBLIC_KEY, |
| 107 | + }), |
| 108 | + ).toThrow('Buzz mention "@alice" is ambiguous'); |
| 109 | + }); |
| 110 | + |
| 111 | + it("bounds ambiguous-member guidance", () => { |
| 112 | + const duplicateMembers = Array.from({ length: 8 }, (_, index) => ({ |
| 113 | + publicKey: (index + 1).toString(16).repeat(64), |
| 114 | + displayName: "Alice", |
| 115 | + })); |
| 116 | + |
| 117 | + expect(() => |
| 118 | + resolveBuzzMessageMentions({ |
| 119 | + text: "Hello @Alice", |
| 120 | + members: members(...duplicateMembers), |
| 121 | + senderPublicKey: BOT_PUBLIC_KEY, |
| 122 | + }), |
| 123 | + ).toThrow( |
| 124 | + `candidates: ${duplicateMembers |
| 125 | + .slice(0, 5) |
| 126 | + .map((member) => nip19.npubEncode(member.publicKey)) |
| 127 | + .join(", ")}, and 3 more.`, |
| 128 | + ); |
| 129 | + }); |
| 130 | + |
85 | 131 | it("rejects explicit identities outside the room and excludes the bot identity", () => { |
86 | 132 | const outsider = "d".repeat(64); |
87 | 133 | expect(() => |
|
0 commit comments