Skip to content

Commit 25cca71

Browse files
committed
fix tests
1 parent eb5eeed commit 25cca71

File tree

3 files changed

+332
-52
lines changed

3 files changed

+332
-52
lines changed

test/servers/mcp-server.spec.ts

Lines changed: 54 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ describe("MCP Server", () => {
107107
clientName: "test-client",
108108
registrationDate: Date.now(),
109109
},
110+
hostName: "https://test-host.com",
110111
};
111112

112113
server = new MCPServer({
@@ -188,6 +189,7 @@ describe("MCP Server", () => {
188189
clientName: "test-client",
189190
registrationDate: Date.now(),
190191
},
192+
hostName: "",
191193
},
192194
});
193195
await unauthenticatedServer.init();
@@ -337,7 +339,8 @@ describe("MCP Server", () => {
337339

338340
expect(result.isError).toBeUndefined();
339341
expect((result.content as any[])).toHaveLength(2);
340-
expect((result.content as any[])[0].text).toBe("The total revenue is $1,000,000");
342+
expect((result.content as any[])[0].text).toContain("Data: The total revenue is $1,000,000");
343+
expect((result.content as any[])[0].text).toContain("**CHART VISUALIZATION AVAILABLE:**");
341344
expect((result.content as any[])[1].text).toContain("Question: What is the total revenue?");
342345
expect((result.content as any[])[1].text).toContain("Session Identifier: session-123");
343346
expect((result.content as any[])[1].text).toContain("Generation Number: 1");
@@ -492,112 +495,126 @@ describe("MCP Server", () => {
492495
name: "Customer Data",
493496
description: "Customer information and demographics",
494497
mimeType: "text/plain",
495-
});
498+
});
499+
});
496500
});
497501

498502
describe("Read Resource", () => {
499503
it("should return resource content for valid datasource URI", async () => {
500504
await server.init();
505+
const { sendToServer } = connect(server);
501506

502-
const result = await server.readResource({
507+
const result = await sendToServer({
503508
method: "resources/read",
504-
params: { uri: "datasource:///ds-123" }
509+
params: { uri: "datasource:///ds-123" }
505510
});
506511

507-
expect(result.contents).toHaveLength(1);
508-
expect(result.contents[0]).toEqual({
509-
uri: "datasource:///ds-123",
510-
mimeType: "text/plain",
511-
text: expect.stringContaining("Sales data for the current year"),
512-
});
513-
expect(result.contents[0].text).toContain("The id of the datasource is ds-123");
514-
expect(result.contents[0].text).toContain("Use ThoughtSpot's getRelevantQuestions tool");
512+
expect('result' in result).toBe(true);
513+
if ('result' in result) {
514+
const contents = (result.result as any).contents;
515+
expect(contents).toHaveLength(1);
516+
expect(contents[0]).toEqual({
517+
uri: "datasource:///ds-123",
518+
mimeType: "text/plain",
519+
text: expect.stringContaining("Sales data for the current year"),
520+
});
521+
expect(contents[0].text).toContain("The id of the datasource is ds-123");
522+
expect(contents[0].text).toContain("Use ThoughtSpot's getRelevantQuestions tool");
523+
}
515524
});
516525

517526
it("should return resource content for second datasource", async () => {
518527
await server.init();
528+
const { sendToServer } = connect(server);
519529

520-
const result = await server.readResource({
530+
const result = await sendToServer({
521531
method: "resources/read",
522-
params: { uri: "datasource:///ds-456" }
532+
params: { uri: "datasource:///ds-456" }
523533
});
524534

525-
expect(result.contents).toHaveLength(1);
526-
expect(result.contents[0]).toEqual({
527-
uri: "datasource:///ds-456",
528-
mimeType: "text/plain",
529-
text: expect.stringContaining("Customer information and demographics"),
530-
});
531-
expect(result.contents[0].text).toContain("The id of the datasource is ds-456");
532-
expect(result.contents[0].text).toContain("Use ThoughtSpot's getRelevantQuestions tool");
535+
expect('result' in result).toBe(true);
536+
if ('result' in result) {
537+
const contents = (result.result as any).contents;
538+
expect(contents).toHaveLength(1);
539+
expect(contents[0]).toEqual({
540+
uri: "datasource:///ds-456",
541+
mimeType: "text/plain",
542+
text: expect.stringContaining("Customer information and demographics"),
543+
});
544+
expect(contents[0].text).toContain("The id of the datasource is ds-456");
545+
expect(contents[0].text).toContain("Use ThoughtSpot's getRelevantQuestions tool");
546+
}
533547
});
534548

535549
it("should throw 404 error for invalid datasource URI format", async () => {
536550
await server.init();
537551

538-
await expect(server.readResource({
552+
await expect((server as any).readResource({
539553
method: "resources/read",
540-
params: { uri: "invalid-uri" }
554+
params: { uri: "invalid-uri" }
541555
})).rejects.toThrow("Datasource not found");
542556
});
543557

544558
it("should throw 400 error for URI without datasource ID", async () => {
545559
await server.init();
546560

547-
await expect(server.readResource({
561+
await expect((server as any).readResource({
548562
method: "resources/read",
549-
params: { uri: "datasource:///" }
563+
params: { uri: "datasource:///" }
550564
})).rejects.toThrow("Invalid datasource uri");
551565
});
552566

553567
it("should throw 404 error for non-existent datasource", async () => {
554568
await server.init();
555569

556-
await expect(server.readResource({
570+
await expect((server as any).readResource({
557571
method: "resources/read",
558-
params: { uri: "datasource:///non-existent-id" }
572+
params: { uri: "datasource:///non-existent-id" }
559573
})).rejects.toThrow("Datasource not found");
560574
});
561575

562576
it("should throw 404 error for malformed URI", async () => {
563577
await server.init();
564578

565-
await expect(server.readResource({
579+
await expect((server as any).readResource({
566580
method: "resources/read",
567-
params: { uri: "datasource://" }
581+
params: { uri: "datasource://" }
568582
})).rejects.toThrow("Datasource not found");
569583
});
570584

571585
it("should throw 400 error for empty URI", async () => {
572586
await server.init();
573587

574-
await expect(server.readResource({
588+
await expect((server as any).readResource({
575589
method: "resources/read",
576-
params: { uri: "" }
590+
params: { uri: "" }
577591
})).rejects.toThrow("Invalid datasource uri");
578592
});
579593

580594
it("should use cached datasources for resource lookup", async () => {
581595
await server.init();
596+
const { sendToServer } = connect(server);
582597

583598
// First call should fetch from service
584-
await server.readResource({
599+
const result1 = await sendToServer({
585600
method: "resources/read",
586-
params: { uri: "datasource:///ds-123" }
601+
params: { uri: "datasource:///ds-123" }
587602
});
603+
expect('result' in result1).toBe(true);
604+
588605
const mockGetClient = vi.mocked(thoughtspotClient.getThoughtSpotClient);
589606
const mockClientInstance = mockGetClient.mock.results[0].value;
590607
expect(mockClientInstance.searchMetadata).toHaveBeenCalledTimes(1);
591608

592609
// Second call should use cached data
593-
await server.readResource({
610+
const result2 = await sendToServer({
594611
method: "resources/read",
595-
params: { uri: "datasource:///ds-456" }
612+
params: { uri: "datasource:///ds-456" }
596613
});
614+
expect('result' in result2).toBe(true);
597615
expect(mockClientInstance.searchMetadata).toHaveBeenCalledTimes(1);
598616
});
599617
});
600-
});
601618

602619
describe("Caching", () => {
603620
it("should cache datasources after first call", async () => {

test/servers/openai-mcp-server.spec.ts

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,18 @@ describe("OpenAI Deep Research MCP Server", () => {
438438
expect(result.structuredContent).toEqual({
439439
id: "asdhshd-123123-12dd: What is the total revenue?",
440440
title: " What is the total revenue?",
441-
text: "The total revenue is $1,000,000",
441+
text: `Data: The total revenue is $1,000,000
442+
443+
**CHART VISUALIZATION AVAILABLE:**
444+
There is a data visualization chart for this query available at: "".
445+
446+
This URL contains a PNG image showing the visual representation of the above data for the question: " What is the total revenue?".
447+
Please fetch and display this image to provide a complete analysis with both the data and its visual representation. `,
442448
url: "https://test.thoughtspot.cloud/#/insights/conv-assist?query=What is the total revenue?&worksheet=asdhshd-123123-12dd&executeSearch=true"
443449
});
444450
// The text field contains the JSON stringified structured content
445451
expect((result.content as any[])[0].text).toContain('"id"');
446-
expect((result.content as any[])[0].text).toContain('"The total revenue is $1,000,000"');
452+
expect((result.content as any[])[0].text).toContain('Data: The total revenue is $1,000,000');
447453
});
448454

449455
it("should handle error from ThoughtSpot service", async () => {
@@ -504,7 +510,13 @@ describe("OpenAI Deep Research MCP Server", () => {
504510
expect(result.structuredContent).toEqual({
505511
id: "abc-123-def-456: What is the total revenue?",
506512
title: " What is the total revenue?",
507-
text: "The total revenue is $1,000,000",
513+
text: `Data: The total revenue is $1,000,000
514+
515+
**CHART VISUALIZATION AVAILABLE:**
516+
There is a data visualization chart for this query available at: "".
517+
518+
This URL contains a PNG image showing the visual representation of the above data for the question: " What is the total revenue?".
519+
Please fetch and display this image to provide a complete analysis with both the data and its visual representation. `,
508520
url: "https://test.thoughtspot.cloud/#/insights/conv-assist?query=What is the total revenue?&worksheet=abc-123-def-456&executeSearch=true"
509521
});
510522
});
@@ -538,7 +550,13 @@ describe("OpenAI Deep Research MCP Server", () => {
538550
expect(result.structuredContent).toEqual({
539551
id: "ds-123: How much did revenue increase? (in %)",
540552
title: " How much did revenue increase? (in %)",
541-
text: "The revenue increased by 15%",
553+
text: `Data: The revenue increased by 15%
554+
555+
**CHART VISUALIZATION AVAILABLE:**
556+
There is a data visualization chart for this query available at: "".
557+
558+
This URL contains a PNG image showing the visual representation of the above data for the question: " How much did revenue increase? (in %)".
559+
Please fetch and display this image to provide a complete analysis with both the data and its visual representation. `,
542560
url: "https://test.thoughtspot.cloud/#/insights/conv-assist?query=How much did revenue increase? (in %)&worksheet=ds-123&executeSearch=true"
543561
});
544562
});
@@ -581,8 +599,14 @@ describe("OpenAI Deep Research MCP Server", () => {
581599
ASSETS: {} as any
582600
};
583601

602+
// Update mockProps to include hostName
603+
const mockPropsWithHost = {
604+
...mockProps,
605+
hostName: "https://test-host.com"
606+
};
607+
584608
const serverWithKV = new OpenAIDeepResearchMCPServer({
585-
props: mockProps,
609+
props: mockPropsWithHost,
586610
env: mockEnv
587611
});
588612

@@ -602,16 +626,16 @@ describe("OpenAI Deep Research MCP Server", () => {
602626
{
603627
sessionId: "session-123",
604628
generationNo: 1,
605-
instanceURL: mockProps.instanceUrl,
606-
accessToken: mockProps.accessToken
629+
instanceURL: mockPropsWithHost.instanceUrl,
630+
accessToken: mockPropsWithHost.accessToken
607631
},
608632
mockEnv
609633
);
610634

611-
// Verify the content includes visualization message
635+
// Verify the content includes visualization message with correct URL
612636
const structuredContent = result.structuredContent as any;
613637
expect(structuredContent.text).toContain("**CHART VISUALIZATION AVAILABLE:**");
614-
expect(structuredContent.text).toContain(`https://test-host.com/data/img?token=${mockToken}`);
638+
expect(structuredContent.text).toContain(`https://test-host.com/data/img?uniqueId=${mockToken}`);
615639
expect(structuredContent.text).toContain("Data: The total revenue is $1,000,000");
616640
expect(structuredContent.text).toContain("What is the total revenue?");
617641
});
@@ -671,10 +695,11 @@ describe("OpenAI Deep Research MCP Server", () => {
671695
expect(crypto.randomUUID).not.toHaveBeenCalled();
672696
expect(mockPutInKV).not.toHaveBeenCalled();
673697

674-
// Verify the content does NOT include visualization message
698+
// Verify the content includes visualization message but with empty URL
675699
const structuredContent = result.structuredContent as any;
676-
expect(structuredContent.text).toBe("The total revenue is $1,000,000");
677-
expect(structuredContent.text).not.toContain("**CHART VISUALIZATION AVAILABLE:**");
700+
expect(structuredContent.text).toContain("**CHART VISUALIZATION AVAILABLE:**");
701+
expect(structuredContent.text).toContain('There is a data visualization chart for this query available at: "".');
702+
expect(structuredContent.text).toContain("Data: The total revenue is $1,000,000");
678703
});
679704

680705
it("should not generate token when answer has error", async () => {
@@ -765,7 +790,13 @@ describe("OpenAI Deep Research MCP Server", () => {
765790
expect(result.structuredContent).toEqual({
766791
id: "",
767792
title: "",
768-
text: "The total revenue is $1,000,000",
793+
text: `Data: The total revenue is $1,000,000
794+
795+
**CHART VISUALIZATION AVAILABLE:**
796+
There is a data visualization chart for this query available at: "".
797+
798+
This URL contains a PNG image showing the visual representation of the above data for the question: "".
799+
Please fetch and display this image to provide a complete analysis with both the data and its visual representation. `,
769800
url: "https://test.thoughtspot.cloud/#/insights/conv-assist?query=&worksheet=&executeSearch=true"
770801
});
771802
});

0 commit comments

Comments
 (0)