11/**
22 * File structure validation tests
33 *
4- * These tests ensure there are no duplicate core files that could cause
5- * conflicting behavior at runtime .
4+ * These tests verify that core files have the correct content and capabilities
5+ * (not just that they exist - the filesystem guarantees uniqueness by path) .
66 */
77
88import * as assert from 'assert' ;
@@ -11,40 +11,10 @@ import * as path from 'path';
1111
1212suite ( 'File Structure Validation' , ( ) => {
1313
14- test ( 'exactly one import-organizer.ts exists' , ( ) => {
15- // When tests run from out/test/, we need to go up to project root then into src
14+ test ( 'import-types.ts supports attributes and comments' , ( ) => {
1615 const projectRoot = path . resolve ( __dirname , '../..' ) ;
17- const srcDir = path . join ( projectRoot , 'src/imports' ) ;
18- const files = findFilesRecursive ( srcDir , 'import-organizer.ts' ) ;
19-
20- assert . strictEqual (
21- files . length ,
22- 1 ,
23- `Expected exactly 1 import-organizer.ts, found ${ files . length } : ${ files . join ( ', ' ) } `
24- ) ;
25- } ) ;
26-
27- test ( 'exactly one import-types.ts exists' , ( ) => {
28- // When tests run from out/test/, we need to go up to project root then into src
29- const projectRoot = path . resolve ( __dirname , '../..' ) ;
30- const srcDir = path . join ( projectRoot , 'src/imports' ) ;
31- const files = findFilesRecursive ( srcDir , 'import-types.ts' ) ;
32-
33- assert . strictEqual (
34- files . length ,
35- 1 ,
36- `Expected exactly 1 import-types.ts, found ${ files . length } : ${ files . join ( ', ' ) } `
37- ) ;
38- } ) ;
39-
40- test ( 'import-types.ts supports attributes' , ( ) => {
41- const projectRoot = path . resolve ( __dirname , '../..' ) ;
42- const srcDir = path . join ( projectRoot , 'src/imports' ) ;
43- const files = findFilesRecursive ( srcDir , 'import-types.ts' ) ;
44-
45- assert . strictEqual ( files . length , 1 , 'Should have exactly one import-types.ts' ) ;
46-
47- const content = fs . readFileSync ( files [ 0 ] , 'utf8' ) ;
16+ const filePath = path . join ( projectRoot , 'src/imports/import-types.ts' ) ;
17+ const content = fs . readFileSync ( filePath , 'utf8' ) ;
4818
4919 // Check for attributes field in the Import interface
5020 assert . ok (
@@ -72,12 +42,8 @@ suite('File Structure Validation', () => {
7242
7343 test ( 'import-organizer.ts does not register old command alias' , ( ) => {
7444 const projectRoot = path . resolve ( __dirname , '../..' ) ;
75- const srcDir = path . join ( projectRoot , 'src/imports' ) ;
76- const files = findFilesRecursive ( srcDir , 'import-organizer.ts' ) ;
77-
78- assert . strictEqual ( files . length , 1 , 'Should have exactly one import-organizer.ts' ) ;
79-
80- const content = fs . readFileSync ( files [ 0 ] , 'utf8' ) ;
45+ const filePath = path . join ( projectRoot , 'src/imports/import-organizer.ts' ) ;
46+ const content = fs . readFileSync ( filePath , 'utf8' ) ;
8147
8248 // Check that it does NOT register the old command
8349 assert . ok (
@@ -92,62 +58,4 @@ suite('File Structure Validation', () => {
9258 ) ;
9359 } ) ;
9460
95- test ( 'no conflicting source files exist' , ( ) => {
96- const projectRoot = path . resolve ( __dirname , '../..' ) ;
97- const srcDir = path . join ( projectRoot , 'src' ) ;
98-
99- // These are the canonical files that must be unique
100- const coreFiles = [
101- 'imports/import-organizer.ts' ,
102- 'imports/import-types.ts' ,
103- 'imports/import-manager.ts' ,
104- 'configuration/imports-config.ts' ,
105- ] ;
106-
107- for ( const relativePath of coreFiles ) {
108- const fullPath = path . join ( srcDir , relativePath ) ;
109- assert . ok (
110- fs . existsSync ( fullPath ) ,
111- `Core file must exist: ${ relativePath } `
112- ) ;
113-
114- // Check that no duplicates exist anywhere else
115- const filename = path . basename ( relativePath ) ;
116- const allMatches = findFilesRecursive ( srcDir , filename ) ;
117-
118- assert . strictEqual (
119- allMatches . length ,
120- 1 ,
121- `Found multiple copies of ${ filename } : ${ allMatches . join ( ', ' ) } `
122- ) ;
123- }
124- } ) ;
12561} ) ;
126-
127- /**
128- * Recursively find all files with a given name in a directory.
129- */
130- function findFilesRecursive ( dir : string , filename : string ) : string [ ] {
131- const results : string [ ] = [ ] ;
132-
133- if ( ! fs . existsSync ( dir ) ) {
134- return results ;
135- }
136-
137- const entries = fs . readdirSync ( dir , { withFileTypes : true } ) ;
138-
139- for ( const entry of entries ) {
140- const fullPath = path . join ( dir , entry . name ) ;
141-
142- if ( entry . isDirectory ( ) ) {
143- // Skip node_modules and test directories
144- if ( entry . name !== 'node_modules' && entry . name !== 'test' && entry . name !== 'out' ) {
145- results . push ( ...findFilesRecursive ( fullPath , filename ) ) ;
146- }
147- } else if ( entry . isFile ( ) && entry . name === filename ) {
148- results . push ( fullPath ) ;
149- }
150- }
151-
152- return results ;
153- }
0 commit comments