@@ -12,9 +12,9 @@ import { orchestrionTransformOptions } from '../../src/orchestrion/bundler/optio
1212
1313// The code transformer reads the instrumented package's version from its
1414// on-disk `package.json`, so each test package needs a real directory.
15- function makePackage ( root : string , name : string , version : string , type ?: 'module' | 'commonjs' ) : void {
15+ function makePackage ( root : string , name : string , version : string , type ?: 'module' | 'commonjs' , subdir = 'lib' ) : void {
1616 const dir = join ( root , 'node_modules' , name ) ;
17- mkdirSync ( join ( dir , 'lib' ) , { recursive : true } ) ;
17+ mkdirSync ( join ( dir , subdir ) , { recursive : true } ) ;
1818 writeFileSync ( join ( dir , 'package.json' ) , JSON . stringify ( { name, version, ...( type ? { type } : { } ) } ) ) ;
1919}
2020
@@ -44,6 +44,8 @@ describe('module-injected transform', () => {
4444 makePackage ( root , 'mysql' , '2.18.1' , 'commonjs' ) ;
4545 makePackage ( root , 'pg' , '8.11.0' , 'module' ) ;
4646 makePackage ( root , 'my-lib' , '1.0.0' , 'commonjs' ) ;
47+ makePackage ( root , 'ioredis' , '5.11.0' , 'commonjs' , 'built' ) ;
48+ makePackage ( root , 'ai' , '7.0.0' , 'module' , 'dist' ) ;
4749 } ) ;
4850
4951 afterAll ( ( ) => {
@@ -124,6 +126,38 @@ describe('module-injected transform', () => {
124126 expect ( calls ) . toHaveLength ( 1 ) ;
125127 } ) ;
126128
129+ it ( 'injects only the registration snippet for a CJS version with native channels' , ( ) => {
130+ const t = createCodeTransformer ( orchestrionTransformOptions ( { } ) ) ;
131+ // No anchor function present — registration must not depend on any library
132+ // internals existing (`astQuery: 'Program'` matches the file root).
133+ const code = "'use strict';\nclass Redis {}\nmodule.exports = Redis;\n" ;
134+ const result = t . transform ( code , join ( root , 'node_modules/ioredis/built/Redis.js' ) ) ;
135+
136+ expect ( result ) . not . toBeNull ( ) ;
137+ expect ( result ! . code ) . toMatch (
138+ / c o n s t \s * \{ \s * o r c h e s t r i o n M o d u l e I n j e c t e d , \s * r e d i s I n t e g r a t i o n \s * \} \s * = \s * r e q u i r e \( [ " ' ] @ s e n t r y \/ s e r v e r - u t i l s \/ o r c h e s t r i o n [ " ' ] \) / ,
139+ ) ;
140+ expect ( result ! . code ) . toContain ( 'orchestrionModuleInjected("ioredis", redisIntegration)' ) ;
141+ // The library publishes its own channels, so nothing else is injected: no
142+ // diagnostics_channel import, no channel declaration, no function wrapper.
143+ expect ( result ! . code ) . not . toContain ( 'diagnostics_channel' ) ;
144+ expect ( result ! . code ) . not . toContain ( 'tr_ch_apm' ) ;
145+ expect ( result ! . code ) . toContain ( 'class Redis' ) ;
146+ } ) ;
147+
148+ it ( 'injects only the registration snippet for an ESM version with native channels' , ( ) => {
149+ const t = createCodeTransformer ( orchestrionTransformOptions ( { } ) ) ;
150+ const result = t . transform ( 'export const embed = () => {};\n' , join ( root , 'node_modules/ai/dist/index.mjs' ) ) ;
151+
152+ expect ( result ) . not . toBeNull ( ) ;
153+ expect ( result ! . code ) . toMatch (
154+ / i m p o r t \s * \{ \s * o r c h e s t r i o n M o d u l e I n j e c t e d , \s * v e r c e l A I I n t e g r a t i o n \s * \} \s * f r o m \s * [ " ' ] @ s e n t r y \/ s e r v e r - u t i l s \/ o r c h e s t r i o n [ " ' ] / ,
155+ ) ;
156+ expect ( result ! . code ) . toContain ( 'orchestrionModuleInjected("ai", vercelAIIntegration)' ) ;
157+ expect ( result ! . code ) . not . toContain ( 'diagnostics_channel' ) ;
158+ expect ( result ! . code ) . not . toContain ( 'tr_ch_apm' ) ;
159+ } ) ;
160+
127161 it ( 'honors a custom import specifier (Turbopack passes an absolute path)' , ( ) => {
128162 const t = createCodeTransformer ( {
129163 ...orchestrionTransformOptions ( { } ) ,
0 commit comments