mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
fix(channels-intelligence): refuse an ephemeral post that names no recipient
An empty user id passed the truthiness guard, so the post went out to this turn's own recipient and reported success for a recipient the caller never identified. Comparing the requested id with the recipient directly refuses it alongside a request naming somebody else. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -96,6 +96,25 @@ describe("DeliveryAdapter ephemeral posts", () => {
|
||||
expect(effect).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("refuses a request that names no recipient at all", async () => {
|
||||
const effect = vi.fn(async () => ({}));
|
||||
const session = { effect } as unknown as ClaimedChannelDelivery;
|
||||
const managed = adapter() as PlatformAdapter;
|
||||
|
||||
// An empty user id identifies nobody, so it cannot agree with this turn's
|
||||
// recipient — sending anyway would report success for a turn the caller
|
||||
// never named.
|
||||
await expect(
|
||||
managed.postEphemeral?.(
|
||||
{ claimedDelivery: session, delivery: delivery() },
|
||||
"",
|
||||
[{ type: "text", props: { value: "Only you can see this" } }],
|
||||
{ fallbackToDM: true },
|
||||
),
|
||||
).resolves.toMatchObject({ ok: false });
|
||||
expect(effect).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("refuses a turn with no identified recipient", async () => {
|
||||
const effect = vi.fn(async () => ({}));
|
||||
const session = { effect } as unknown as ClaimedChannelDelivery;
|
||||
|
||||
@@ -334,7 +334,7 @@ export class DeliveryAdapter implements PlatformAdapter {
|
||||
if (!recipient) {
|
||||
return { ok: false, error: "This turn has no identified recipient" };
|
||||
}
|
||||
if (requested && requested !== recipient) {
|
||||
if (requested !== recipient) {
|
||||
return {
|
||||
ok: false,
|
||||
error: `A managed ephemeral message reaches only this turn's own recipient (${recipient})`,
|
||||
|
||||
Reference in New Issue
Block a user