@@ -140,6 +140,66 @@ describe('spec-schema-access transform', () => {
140140 } ) ;
141141 } ) ;
142142
143+ describe ( 'import cleanup after transform' , ( ) => {
144+ it ( 'removes original schema import after all refs are auto-transformed' , ( ) => {
145+ const input = [
146+ `import { CallToolRequestSchema } from '@modelcontextprotocol/server';` ,
147+ `const valid = CallToolRequestSchema.safeParse(data).success;` ,
148+ ''
149+ ] . join ( '\n' ) ;
150+ const { text } = applyTransform ( input ) ;
151+ expect ( text ) . toContain ( 'isSpecType.CallToolRequest(data)' ) ;
152+ expect ( text ) . not . toMatch ( / i m p o r t \s * \{ [ ^ } ] * C a l l T o o l R e q u e s t S c h e m a [ ^ } ] * \} / ) ;
153+ } ) ;
154+
155+ it ( 'keeps original schema import when some refs are diagnostic-only' , ( ) => {
156+ const input = [
157+ `import { CallToolRequestSchema } from '@modelcontextprotocol/server';` ,
158+ `const valid = CallToolRequestSchema.safeParse(data).success;` ,
159+ `const parsed = CallToolRequestSchema.parse(data);` ,
160+ ''
161+ ] . join ( '\n' ) ;
162+ const { text } = applyTransform ( input ) ;
163+ expect ( text ) . toContain ( 'isSpecType.CallToolRequest(data)' ) ;
164+ expect ( text ) . toContain ( 'CallToolRequestSchema.parse' ) ;
165+ expect ( text ) . toMatch ( / i m p o r t \s * \{ [ ^ } ] * C a l l T o o l R e q u e s t S c h e m a [ ^ } ] * \} / ) ;
166+ } ) ;
167+
168+ it ( 'removes schema specifier from import that also has other symbols' , ( ) => {
169+ const input = [
170+ `import { CallToolRequestSchema, McpError } from '@modelcontextprotocol/server';` ,
171+ `const valid = CallToolRequestSchema.safeParse(data).success;` ,
172+ `throw new McpError(1, 'fail');` ,
173+ ''
174+ ] . join ( '\n' ) ;
175+ const { text } = applyTransform ( input ) ;
176+ expect ( text ) . not . toMatch ( / i m p o r t \s * \{ [ ^ } ] * C a l l T o o l R e q u e s t S c h e m a [ ^ } ] * \} / ) ;
177+ expect ( text ) . toContain ( 'McpError' ) ;
178+ expect ( text ) . toContain ( `@modelcontextprotocol/server` ) ;
179+ } ) ;
180+ } ) ;
181+
182+ describe ( 'parent-kind guards' , ( ) => {
183+ it ( 'emits diagnostic for re-exported schema (ExportSpecifier)' , ( ) => {
184+ const input = [
185+ `import { CallToolRequestSchema } from '@modelcontextprotocol/server';` ,
186+ `export { CallToolRequestSchema };` ,
187+ ''
188+ ] . join ( '\n' ) ;
189+ const { text, result } = applyTransform ( input ) ;
190+ expect ( text ) . toContain ( 'export { CallToolRequestSchema }' ) ;
191+ expect ( result . diagnostics . some ( d => d . message . includes ( 'Re-export' ) ) ) . toBe ( true ) ;
192+ expect ( result . changesCount ) . toBe ( 0 ) ;
193+ } ) ;
194+
195+ it ( 'expands shorthand property assignment' , ( ) => {
196+ const input = [ `import { ToolSchema } from '@modelcontextprotocol/server';` , `const schemas = { ToolSchema };` , '' ] . join ( '\n' ) ;
197+ const { text, result } = applyTransform ( input ) ;
198+ expect ( text ) . toContain ( 'ToolSchema: specTypeSchemas.Tool' ) ;
199+ expect ( result . changesCount ) . toBeGreaterThan ( 0 ) ;
200+ } ) ;
201+ } ) ;
202+
143203 describe ( 'aliased imports' , ( ) => {
144204 it ( 'handles aliased import and references original name in diagnostic' , ( ) => {
145205 const input = [
0 commit comments