-
Notifications
You must be signed in to change notification settings - Fork 29
Clarify /mcp test-toolset requirements and replace auto-redirect with manual manifest link
#179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
959f30b
50caab4
2fb1616
4437622
ec300bd
e559378
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@storybook/addon-mcp': patch | ||
| --- | ||
|
|
||
| Improve `/mcp` HTML response |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
| import type { Options } from 'storybook/internal/types'; | ||
| import { experimental_devServer } from './preset.ts'; | ||
| import * as runStoryTests from './tools/run-story-tests.ts'; | ||
|
|
||
| describe('experimental_devServer', () => { | ||
| let mockApp: any; | ||
|
|
@@ -67,6 +68,51 @@ | |
| expect(mockRes.end).toHaveBeenCalledWith(expect.stringContaining('<html')); | ||
| }); | ||
|
|
||
| it('should show Storybook version requirement for addon-vitest and a manual manifest link', async () => { | ||
| vi.spyOn(runStoryTests, 'getAddonVitestConstants').mockResolvedValue(undefined); | ||
| const manifestEnabledOptions = { | ||
| presets: { | ||
| apply: vi.fn((key: string) => { | ||
| if (key === 'features') { | ||
| return Promise.resolve({ experimentalComponentsManifest: true }); | ||
| } | ||
| if (key === 'experimental_manifests') { | ||
| return Promise.resolve({}); | ||
| } | ||
| return Promise.resolve(undefined); | ||
| }), | ||
| }, | ||
| } as unknown as Options; | ||
|
|
||
| let getHandler: any; | ||
| mockApp.get = vi.fn((path, handler) => { | ||
| getHandler = handler; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: This captures the last registered GET handler, which happens to be Other tests in this same file already use a more robust pattern (e.g. line 144): const handlers: Record<string, any> = {};
mockApp.get = vi.fn((path: string, handler: any) => {
handlers[path] = handler;
});
await (experimental_devServer as any)(mockApp, manifestEnabledOptions);
const mcpHandler = handlers['/mcp'];
await mcpHandler(mockReq, mockRes);
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot this comment makes sense to me, fix it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated the test to capture GET handlers by route and explicitly invoke |
||
| }); | ||
|
|
||
| await (experimental_devServer as any)(mockApp, manifestEnabledOptions); | ||
|
|
||
| const mockReq = { | ||
| headers: { | ||
| accept: 'text/html', | ||
| }, | ||
| } as any; | ||
| const mockRes = { | ||
| writeHead: vi.fn(), | ||
| end: vi.fn(), | ||
| } as any; | ||
|
|
||
| await getHandler(mockReq, mockRes); | ||
|
|
||
| expect(mockRes.end).toHaveBeenCalledWith( | ||
| expect.stringContaining('This toolset requires Storybook 10.3.0+ with'), | ||
| ); | ||
| expect(mockRes.end).toHaveBeenCalledWith( | ||
| expect.stringContaining( | ||
| 'View the <a href="/manifests/components.html">component manifest debugger</a>.', | ||
| ), | ||
| ); | ||
| }); | ||
|
JReinhold marked this conversation as resolved.
|
||
|
|
||
| it('should handle POST requests as MCP protocol', async () => { | ||
| await (experimental_devServer as any)(mockApp, mockOptions); | ||
|
|
||
|
|
@@ -227,7 +273,7 @@ | |
| await (experimental_devServer as any)(mockApp, optionsWithRefs); | ||
|
|
||
| // The preset should have called presets.apply('refs') | ||
| expect(optionsWithRefs.presets.apply).toHaveBeenCalledWith('refs', {}); | ||
| }); | ||
|
|
||
| it('should handle refs config returning non-object gracefully', async () => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.