fix: honor nostr default account routing

This commit is contained in:
Tak Hoffman
2026-04-03 12:29:36 -05:00
parent f77054eaee
commit 9f049cb1d8
2 changed files with 57 additions and 4 deletions

View File

@@ -85,4 +85,58 @@ describe("nostr outbound cfg threading", () => {
cleanup.stop();
});
it("uses the configured defaultAccount when accountId is omitted", async () => {
const resolveMarkdownTableMode = vi.fn(() => "off");
const convertMarkdownTables = vi.fn((text: string) => text);
setNostrRuntime({
channel: {
text: {
resolveMarkdownTableMode,
convertMarkdownTables,
},
},
reply: {},
} as unknown as PluginRuntime);
const sendDm = vi.fn(async () => {});
const bus = {
sendDm,
close: vi.fn(),
getMetrics: vi.fn(() => ({ counters: {} })),
publishProfile: vi.fn(),
getProfileState: vi.fn(async () => null),
};
mocks.startNostrBus.mockResolvedValueOnce(bus as any);
const cleanup = (await nostrPlugin.gateway!.startAccount!(
createStartAccountContext({
account: buildResolvedNostrAccount({ accountId: "work" }),
}),
)) as { stop: () => void };
const cfg = {
channels: {
nostr: {
privateKey: TEST_RESOLVED_PRIVATE_KEY, // pragma: allowlist secret
defaultAccount: "work",
},
},
};
await nostrPlugin.outbound!.sendText!({
cfg: cfg as any,
to: "NPUB123",
text: "hello",
});
expect(resolveMarkdownTableMode).toHaveBeenCalledWith({
cfg,
channel: "nostr",
accountId: "work",
});
expect(sendDm).toHaveBeenCalledWith("normalized-npub123", "hello");
cleanup.stop();
});
});

View File

@@ -406,9 +406,8 @@ export const nostrPlugin: ChannelPlugin<ResolvedNostrAccount> = createChatChanne
return entry.trim();
}
},
notify: async ({ id, message }) => {
// Get the default account's bus and send approval message
const bus = activeBuses.get(DEFAULT_ACCOUNT_ID);
notify: async ({ cfg, id, message, accountId }) => {
const bus = activeBuses.get(accountId ?? resolveDefaultNostrAccountId(cfg));
if (bus) {
await bus.sendDm(id, message);
}
@@ -423,7 +422,7 @@ export const nostrPlugin: ChannelPlugin<ResolvedNostrAccount> = createChatChanne
textChunkLimit: 4000,
sendText: async ({ cfg, to, text, accountId }) => {
const core = getNostrRuntime();
const aid = accountId ?? DEFAULT_ACCOUNT_ID;
const aid = accountId ?? resolveDefaultNostrAccountId(cfg);
const bus = activeBuses.get(aid);
if (!bus) {
throw new Error(`Nostr bus not running for account ${aid}`);