Skip to content

Commit eb17954

Browse files
ochafikclaude
andcommitted
Add tests for notification handler fixes
- Test that null _meta is converted to undefined in OpenAI transport - Test that default no-op handlers accept tool notifications without error 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 915c085 commit eb17954

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/app-bridge.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,21 @@ describe("App <-> AppBridge integration", () => {
215215
expect(receivedCancellations[0]).toEqual({});
216216
});
217217

218+
it("tool notifications work with default no-op handlers", async () => {
219+
// Don't set any custom handlers - use defaults
220+
await app.connect(appTransport);
221+
222+
// These should not throw (default handlers silently accept them)
223+
// Just verify they complete without error
224+
await bridge.sendToolInput({ arguments: {} });
225+
await bridge.sendToolInputPartial({ arguments: {} });
226+
await bridge.sendToolResult({ content: [{ type: "text", text: "ok" }] });
227+
await bridge.sendToolCancelled({});
228+
229+
// If we got here without throwing, the test passes
230+
expect(true).toBe(true);
231+
});
232+
218233
it("setHostContext triggers app.onhostcontextchanged", async () => {
219234
const receivedContexts: unknown[] = [];
220235
app.onhostcontextchanged = (params) => {

src/openai/transport.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,29 @@ describe("OpenAITransport", () => {
429429
});
430430
});
431431

432+
test("converts null _meta to undefined in tool result", async () => {
433+
// Simulate null being set (e.g., from JSON parsing where null is valid)
434+
(mockOpenAI as unknown as { toolResponseMetadata: null }).toolResponseMetadata = null;
435+
436+
const transport = new OpenAITransport();
437+
const messages: unknown[] = [];
438+
transport.onmessage = (msg) => {
439+
messages.push(msg);
440+
};
441+
442+
transport.deliverInitialState();
443+
444+
await new Promise((resolve) => setTimeout(resolve, 0));
445+
446+
const toolResultNotification = messages.find(
447+
(m: unknown) =>
448+
(m as { method?: string }).method === "ui/notifications/tool-result",
449+
) as { params?: { _meta?: unknown } } | undefined;
450+
expect(toolResultNotification).toBeDefined();
451+
// _meta should be undefined, not null (SDK rejects null)
452+
expect(toolResultNotification?.params?._meta).toBeUndefined();
453+
});
454+
432455
test("does not deliver notifications when data is missing", async () => {
433456
delete mockOpenAI.toolInput;
434457
delete mockOpenAI.toolOutput;

0 commit comments

Comments
 (0)