@@ -86,12 +86,12 @@ describe("ComponentDetection.processComponentsToManifests", () => {
8686 } ,
8787 isDevelopmentDependency : false ,
8888 topLevelReferrers : [ ] , // Empty = direct dependency
89- locationsFoundAt : [ "/ package.json" ]
89+ locationsFoundAt : [ "package.json" ]
9090 }
9191 ] ;
9292
9393 const dependencyGraphs : DependencyGraphs = {
94- "/ package.json" : {
94+ "package.json" : {
9595 graph : { "test-package" : null } ,
9696 explicitlyReferencedComponentIds : [ "test-package 1.0.0 - npm" ] ,
9797 developmentDependencies : [ ] ,
@@ -102,7 +102,7 @@ describe("ComponentDetection.processComponentsToManifests", () => {
102102 const manifests = ComponentDetection . processComponentsToManifests ( componentsFound , dependencyGraphs ) ;
103103
104104 expect ( manifests ) . toHaveLength ( 1 ) ;
105- expect ( manifests [ 0 ] . name ) . toBe ( "/ package.json" ) ;
105+ expect ( manifests [ 0 ] . name ) . toBe ( "package.json" ) ;
106106 expect ( manifests [ 0 ] . directDependencies ( ) ) . toHaveLength ( 1 ) ;
107107 expect ( manifests [ 0 ] . indirectDependencies ( ) ) . toHaveLength ( 0 ) ;
108108 expect ( manifests [ 0 ] . countDependencies ( ) ) . toBe ( 1 ) ;
@@ -135,12 +135,12 @@ describe("ComponentDetection.processComponentsToManifests", () => {
135135 }
136136 }
137137 ] ,
138- locationsFoundAt : [ "/ package.json" ]
138+ locationsFoundAt : [ "package.json" ]
139139 }
140140 ] ;
141141
142142 const dependencyGraphs : DependencyGraphs = {
143- "/ package.json" : {
143+ "package.json" : {
144144 graph : { "parent-package" : null } ,
145145 explicitlyReferencedComponentIds : [ ] ,
146146 developmentDependencies : [ ] ,
@@ -151,7 +151,7 @@ describe("ComponentDetection.processComponentsToManifests", () => {
151151 const manifests = ComponentDetection . processComponentsToManifests ( componentsFound , dependencyGraphs ) ;
152152
153153 expect ( manifests ) . toHaveLength ( 1 ) ;
154- expect ( manifests [ 0 ] . name ) . toBe ( "/ package.json" ) ;
154+ expect ( manifests [ 0 ] . name ) . toBe ( "package.json" ) ;
155155 expect ( manifests [ 0 ] . directDependencies ( ) ) . toHaveLength ( 0 ) ;
156156 expect ( manifests [ 0 ] . indirectDependencies ( ) ) . toHaveLength ( 1 ) ;
157157 expect ( manifests [ 0 ] . countDependencies ( ) ) . toBe ( 1 ) ;
@@ -184,10 +184,10 @@ describe('normalizeDependencyGraphPaths', () => {
184184 const normalized = ComponentDetection . normalizeDependencyGraphPaths ( dependencyGraphs , filePathInput ) ;
185185 // Restore process.cwd
186186 ( process as any ) . cwd = originalCwd ;
187- expect ( Object . keys ( normalized ) ) . toContain ( '/ a/package.json' ) ;
188- expect ( Object . keys ( normalized ) ) . toContain ( '/ b/package.json' ) ;
189- expect ( normalized [ '/ a/package.json' ] . graph ) . toEqual ( { 'foo' : null } ) ;
190- expect ( normalized [ '/ b/package.json' ] . graph ) . toEqual ( { 'bar' : null } ) ;
187+ expect ( Object . keys ( normalized ) ) . toContain ( 'a/package.json' ) ;
188+ expect ( Object . keys ( normalized ) ) . toContain ( 'b/package.json' ) ;
189+ expect ( normalized [ 'a/package.json' ] . graph ) . toEqual ( { 'foo' : null } ) ;
190+ expect ( normalized [ 'b/package.json' ] . graph ) . toEqual ( { 'bar' : null } ) ;
191191 } ) ;
192192} ) ;
193193
@@ -197,13 +197,50 @@ describe('normalizeDependencyGraphPaths with real output.json', () => {
197197 const dependencyGraphs = output . dependencyGraphs ;
198198 // Use the same filePath as the action default (".")
199199 const normalized = ComponentDetection . normalizeDependencyGraphPaths ( dependencyGraphs , 'test' ) ;
200- // Should contain /package.json and /package-lock.json as keys
201- expect ( Object . keys ( normalized ) ) . toContain ( '/package.json' ) ;
202- expect ( Object . keys ( normalized ) ) . toContain ( '/package-lock.json' ) ;
203- // All keys should now be relative to the repo root (cwd) and start with '/'
200+
201+ // Should contain root level manifests without leading slashes
202+ expect ( Object . keys ( normalized ) ) . toContain ( 'package.json' ) ;
203+ expect ( Object . keys ( normalized ) ) . toContain ( 'package-lock.json' ) ;
204+
205+ // Should contain nested manifests with relative paths (no leading slashes)
206+ expect ( Object . keys ( normalized ) ) . toContain ( 'nested/package.json' ) ;
207+ expect ( Object . keys ( normalized ) ) . toContain ( 'nested/package-lock.json' ) ;
208+
209+ // All keys should be relative paths without leading slashes
204210 for ( const key of Object . keys ( normalized ) ) {
205- expect ( key . startsWith ( '/' ) ) . toBe ( true ) ;
211+ expect ( key . startsWith ( '/' ) ) . toBe ( false ) ; // No leading slashes
206212 expect ( key ) . not . toMatch ( / ^ \w : \\ | ^ \/ \/ | ^ \. { 1 , 2 } \/ / ) ; // Not windows absolute, not network, not relative
207213 }
208214 } ) ;
209215} ) ;
216+
217+ test ( 'full action scan creates manifests with correct names and file source locations' , async ( ) => {
218+ await ComponentDetection . downloadLatestRelease ( ) ;
219+ const manifests = await ComponentDetection . scanAndGetManifests ( './test' ) ;
220+
221+ expect ( manifests ) . toBeDefined ( ) ;
222+ expect ( manifests ! . length ) . toBeGreaterThan ( 0 ) ;
223+
224+ for ( const manifest of manifests ! ) {
225+ expect ( manifest . name . startsWith ( '/' ) ) . toBe ( false ) ;
226+ }
227+
228+ const expectedManifestNames = [
229+ 'package.json' ,
230+ 'package-lock.json' ,
231+ 'nested/package.json' ,
232+ 'nested/package-lock.json' ,
233+ ] ;
234+
235+ const manifestsByName = manifests ! . reduce ( ( acc , manifest ) => {
236+ acc [ manifest . name ] = manifest ;
237+ return acc ;
238+ } , { } as Record < string , any > ) ;
239+
240+ for ( const expectedName of expectedManifestNames ) {
241+ const manifest = manifestsByName [ expectedName ] ;
242+ expect ( manifest ) . toBeDefined ( ) ;
243+ expect ( manifest . name ) . toBe ( expectedName ) ;
244+ expect ( manifest . file ?. source_location ) . toBe ( expectedName ) ;
245+ }
246+ } , 15000 ) ;
0 commit comments