


























@@ -101,6 +101,14 @@ async function startGatewayHarness(params: {
101101return { harness, bus, cleanup };
102102}
103103104+function mockCallArg(mock: ReturnType<typeof vi.fn>, callIndex = 0, argIndex = 0): unknown {
105+const call = mock.mock.calls.at(callIndex);
106+if (!call) {
107+throw new Error(`Expected mock call ${callIndex}`);
108+}
109+return call.at(argIndex);
110+}
111+104112describe("nostr inbound gateway path", () => {
105113afterEach(() => {
106114mocks.normalizePubkey.mockClear();
@@ -114,7 +122,7 @@ describe("nostr inbound gateway path", () => {
114122}),
115123});
116124117-const options = mocks.startNostrBus.mock.calls[0]?.[0] as {
125+const options = mockCallArg(mocks.startNostrBus) as {
118126authorizeSender: (params: {
119127senderPubkey: string;
120128reply: (text: string) => Promise<void>;
@@ -129,7 +137,7 @@ describe("nostr inbound gateway path", () => {
129137}),
130138).resolves.toBe("pairing");
131139expect(sendPairingReply).toHaveBeenCalledTimes(1);
132-expect(sendPairingReply.mock.calls[0]?.[0]).toContain("Pairing code:");
140+expect(mockCallArg(sendPairingReply)).toContain("Pairing code:");
133141134142cleanup.stop();
135143});
@@ -146,7 +154,7 @@ describe("nostr inbound gateway path", () => {
146154} as never,
147155});
148156149-const options = mocks.startNostrBus.mock.calls[0]?.[0] as {
157+const options = mockCallArg(mocks.startNostrBus) as {
150158onMessage: (
151159senderPubkey: string,
152160text: string,
@@ -163,7 +171,11 @@ describe("nostr inbound gateway path", () => {
163171164172expect(harness.recordInboundSession).toHaveBeenCalledTimes(1);
165173expect(harness.dispatchReplyWithBufferedBlockDispatcher).toHaveBeenCalledTimes(1);
166-const ctx = harness.dispatchReplyWithBufferedBlockDispatcher.mock.calls[0]?.[0]?.ctx;
174+const ctx = (
175+mockCallArg(harness.dispatchReplyWithBufferedBlockDispatcher) as {
176+ctx?: Record<string, unknown>;
177+}
178+).ctx;
167179expect(ctx?.BodyForAgent).toBe("hello from nostr");
168180expect(ctx?.SenderId).toBe("sender-pubkey");
169181expect(ctx?.MessageSid).toBe("event-123");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。