From 88cfc1cdd64ee2d2b39dfa0f29ae2bafd0a833d8 Mon Sep 17 00:00:00 2001 From: Michelle Tilley Date: Tue, 3 Feb 2026 14:22:44 -0800 Subject: [PATCH] Address PR feedback --- src/agents/tools/discord-actions-presence.test.ts | 6 ++++++ src/agents/tools/discord-actions-presence.ts | 8 +++++++- src/discord/monitor/gateway-registry.test.ts | 5 +++-- src/discord/monitor/gateway-registry.ts | 6 +++++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/agents/tools/discord-actions-presence.test.ts b/src/agents/tools/discord-actions-presence.test.ts index 1a5d537310..71cf967e16 100644 --- a/src/agents/tools/discord-actions-presence.test.ts +++ b/src/agents/tools/discord-actions-presence.test.ts @@ -196,6 +196,12 @@ describe("handleDiscordPresenceAction", () => { ); }); + it("requires activityType when activityName is provided", async () => { + await expect( + handleDiscordPresenceAction("setPresence", { activityName: "My Game" }, presenceEnabled), + ).rejects.toThrow(/activityType is required/); + }); + it("rejects unknown presence actions", async () => { await expect(handleDiscordPresenceAction("unknownAction", {}, presenceEnabled)).rejects.toThrow( /Unknown presence action/, diff --git a/src/agents/tools/discord-actions-presence.ts b/src/agents/tools/discord-actions-presence.ts index bdc7adf65f..90639aa64e 100644 --- a/src/agents/tools/discord-actions-presence.ts +++ b/src/agents/tools/discord-actions-presence.ts @@ -55,7 +55,13 @@ export async function handleDiscordPresenceAction( const activities: Activity[] = []; if (activityTypeRaw || activityName) { - const typeNum = activityTypeRaw ? ACTIVITY_TYPE_MAP[activityTypeRaw.toLowerCase()] : 0; + if (!activityTypeRaw) { + throw new Error( + "activityType is required when activityName is provided. " + + `Valid types: ${Object.keys(ACTIVITY_TYPE_MAP).join(", ")}`, + ); + } + const typeNum = ACTIVITY_TYPE_MAP[activityTypeRaw.toLowerCase()]; if (typeNum === undefined) { throw new Error( `Invalid activityType "${activityTypeRaw}". Must be one of: ${Object.keys(ACTIVITY_TYPE_MAP).join(", ")}`, diff --git a/src/discord/monitor/gateway-registry.test.ts b/src/discord/monitor/gateway-registry.test.ts index 876a47678d..8e0c66a87e 100644 --- a/src/discord/monitor/gateway-registry.test.ts +++ b/src/discord/monitor/gateway-registry.test.ts @@ -23,11 +23,12 @@ describe("gateway-registry", () => { expect(getGateway("account-b")).toBeUndefined(); }); - it("uses 'default' key when accountId is undefined", () => { + it("uses collision-safe key when accountId is undefined", () => { const gateway = fakeGateway(); registerGateway(undefined, gateway); expect(getGateway(undefined)).toBe(gateway); - expect(getGateway("default")).toBe(gateway); + // "default" as a literal account ID must not collide with the sentinel key + expect(getGateway("default")).toBeUndefined(); }); it("unregisters a gateway", () => { diff --git a/src/discord/monitor/gateway-registry.ts b/src/discord/monitor/gateway-registry.ts index 54dfd6281b..b0fa844ba2 100644 --- a/src/discord/monitor/gateway-registry.ts +++ b/src/discord/monitor/gateway-registry.ts @@ -8,8 +8,12 @@ import type { GatewayPlugin } from "@buape/carbon/gateway"; */ const gatewayRegistry = new Map(); +// Sentinel key for the default (unnamed) account. Uses a prefix that cannot +// collide with user-configured account IDs. +const DEFAULT_ACCOUNT_KEY = "\0__default__"; + function resolveAccountKey(accountId?: string): string { - return accountId ?? "default"; + return accountId ?? DEFAULT_ACCOUNT_KEY; } /** Register a GatewayPlugin instance for an account. */