Skip to content

Commit 4947413

Browse files
committed
test(nostr): preserve inbound sanitizer coverage
1 parent e7cb24d commit 4947413

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

extensions/nostr/src/channel.inbound.test.ts

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ function createMockBus() {
4747
};
4848
}
4949

50-
function createRuntimeHarness(deliveredText = "|a|b|") {
50+
function createRuntimeHarness() {
5151
const recordInboundSession = vi.fn(async () => {});
5252
const dispatchReplyWithBufferedBlockDispatcher = vi.fn(async ({ dispatcherOptions }) => {
53-
await dispatcherOptions.deliver({ text: deliveredText });
53+
await dispatcherOptions.deliver({ text: "|a|b|" });
5454
});
5555
const convertMarkdownTables = vi.fn((text: string) => `converted:${text}`);
5656
const runtime = {
@@ -99,9 +99,8 @@ function createRuntimeHarness(deliveredText = "|a|b|") {
9999
async function startGatewayHarness(params: {
100100
account: ReturnType<typeof buildResolvedNostrAccount>;
101101
cfg?: Parameters<typeof createStartAccountContext>[0]["cfg"];
102-
deliveredText?: string;
103102
}) {
104-
const harness = createRuntimeHarness(params.deliveredText);
103+
const harness = createRuntimeHarness();
105104
const bus = createMockBus();
106105
setNostrRuntime(harness.runtime);
107106
mocks.startNostrBus.mockResolvedValueOnce(bus as never);
@@ -244,27 +243,45 @@ describe("nostr inbound gateway path", () => {
244243
expectedText: null,
245244
},
246245
])("$name", async ({ deliveredText, expectedText }) => {
246+
mocks.dispatchInboundDirectDm.mockImplementationOnce(
247+
async (params: Parameters<typeof DispatchInboundDirectDm>[0]) => {
248+
await params.deliver({ text: deliveredText });
249+
},
250+
);
247251
const { harness, cleanup } = await startGatewayHarness({
248252
account: buildResolvedNostrAccount({
249253
publicKey: "bot-pubkey",
250254
config: { dmPolicy: "allowlist", allowFrom: ["nostr:sender-pubkey"] },
251255
}),
252-
deliveredText,
253256
});
254257
const options = mockCallArg(mocks.startNostrBus) as {
255258
onMessage: (
256259
senderPubkey: string,
257260
text: string,
258261
reply: (text: string) => Promise<void>,
259262
meta: { eventId: string; createdAt: number },
263+
lifecycle: NostrIngressLifecycle,
260264
) => Promise<void>;
261265
};
262266
const sendReply = vi.fn(async (_text: string) => {});
267+
const lifecycle: NostrIngressLifecycle = {
268+
abortSignal: new AbortController().signal,
269+
onAdopted: vi.fn(async () => {}),
270+
onDeferred: vi.fn(),
271+
onAdoptionFinalizing: vi.fn(),
272+
onAbandoned: vi.fn(async () => {}),
273+
};
263274

264-
await options.onMessage("sender-pubkey", "hello from nostr", sendReply, {
265-
eventId: "event-123",
266-
createdAt: 1_710_000_000,
267-
});
275+
await options.onMessage(
276+
"sender-pubkey",
277+
"hello from nostr",
278+
sendReply,
279+
{
280+
eventId: "event-123",
281+
createdAt: 1_710_000_000,
282+
},
283+
lifecycle,
284+
);
268285

269286
if (expectedText === null) {
270287
expect(harness.convertMarkdownTables).not.toHaveBeenCalled();

extensions/nostr/src/gateway.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export const startNostrGatewayAccount: NostrGatewayStart = async (ctx) => {
198198
if (!outboundText.trim()) {
199199
return;
200200
}
201-
// The gateway inbound reply path bypasses the outbound adapter, so
201+
// The gateway inbound reply path bypasses the outbound adapter, so
202202
// strip internal tool-trace scaffolding here too — matching the
203203
// sanitizeText hook on nostrOutboundAdapter.
204204
const sanitizedText = sanitizeAssistantVisibleText(outboundText);

0 commit comments

Comments
 (0)