ts-runtime-validation 1.7.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +143 -0
  2. package/README.md +93 -30
  3. package/dist/SchemaGenerator.deterministic-extended.test.js +420 -0
  4. package/dist/SchemaGenerator.deterministic-extended.test.js.map +1 -0
  5. package/dist/SchemaGenerator.deterministic.test.js +251 -0
  6. package/dist/SchemaGenerator.deterministic.test.js.map +1 -0
  7. package/dist/SchemaGenerator.integration.test.js +3 -3
  8. package/dist/SchemaGenerator.integration.test.js.map +1 -1
  9. package/dist/SchemaGenerator.test.js +94 -0
  10. package/dist/SchemaGenerator.test.js.map +1 -1
  11. package/dist/cli.test.js +155 -0
  12. package/dist/cli.test.js.map +1 -0
  13. package/dist/index.js +1 -1
  14. package/dist/index.js.map +1 -1
  15. package/dist/services/CodeGenerator.js +29 -13
  16. package/dist/services/CodeGenerator.js.map +1 -1
  17. package/dist/services/FileDiscovery.js +4 -2
  18. package/dist/services/FileDiscovery.js.map +1 -1
  19. package/dist/services/FileDiscovery.test.js +1 -1
  20. package/dist/services/FileDiscovery.test.js.map +1 -1
  21. package/dist/services/SchemaProcessor.js +27 -11
  22. package/dist/services/SchemaProcessor.js.map +1 -1
  23. package/dist/services/SchemaProcessor.test.js +61 -1
  24. package/dist/services/SchemaProcessor.test.js.map +1 -1
  25. package/dist/services/SchemaWriter.test.js +1 -1
  26. package/dist/services/SchemaWriter.test.js.map +1 -1
  27. package/package.json +10 -9
  28. package/src/SchemaGenerator.deterministic-extended.test.ts +429 -0
  29. package/src/SchemaGenerator.deterministic.test.ts +276 -0
  30. package/src/SchemaGenerator.integration.test.ts +3 -3
  31. package/src/SchemaGenerator.test.ts +111 -0
  32. package/src/cli.test.ts +130 -0
  33. package/src/index.ts +1 -1
  34. package/src/services/CodeGenerator.ts +30 -12
  35. package/src/services/FileDiscovery.test.ts +1 -1
  36. package/src/services/FileDiscovery.ts +5 -2
  37. package/src/services/SchemaProcessor.test.ts +73 -1
  38. package/src/services/SchemaProcessor.ts +30 -9
  39. package/src/services/SchemaWriter.test.ts +1 -1
  40. package/.claude/settings.local.json +0 -9
  41. package/dist/test/output/duplicate-symbols-identitcal-implementation/ValidationType.js +0 -3
  42. package/dist/test/output/duplicate-symbols-identitcal-implementation/ValidationType.js.map +0 -1
  43. package/dist/test/output/duplicate-symbols-identitcal-implementation/isValidSchema.js +0 -49
  44. package/dist/test/output/duplicate-symbols-identitcal-implementation/isValidSchema.js.map +0 -1
@@ -0,0 +1,429 @@
1
+ import { SchemaGenerator } from "./SchemaGenerator";
2
+ import { ICommandOptions } from "./ICommandOptions";
3
+ import * as fs from "fs";
4
+ import * as path from "path";
5
+ import * as crypto from "crypto";
6
+
7
+ describe("SchemaGenerator - Extended Deterministic Tests", () => {
8
+ const baseTestDir = path.join(__dirname, "../.test-tmp/deterministic-extended");
9
+
10
+ const createTestEnv = (name: string) => {
11
+ const testDir = path.join(baseTestDir, name);
12
+ const outputDir1 = path.join(testDir, "output-1");
13
+ const outputDir2 = path.join(testDir, "output-2");
14
+ const srcDir = path.join(testDir, "src");
15
+
16
+ return { testDir, outputDir1, outputDir2, srcDir };
17
+ };
18
+
19
+ beforeEach(() => {
20
+ if (fs.existsSync(baseTestDir)) {
21
+ fs.rmSync(baseTestDir, { recursive: true, force: true });
22
+ }
23
+ });
24
+
25
+ afterEach(() => {
26
+ if (fs.existsSync(baseTestDir)) {
27
+ fs.rmSync(baseTestDir, { recursive: true, force: true });
28
+ }
29
+ });
30
+
31
+ const getFileHash = (filePath: string): string => {
32
+ if (!fs.existsSync(filePath)) {
33
+ return "";
34
+ }
35
+ const content = fs.readFileSync(filePath, "utf-8");
36
+ return crypto.createHash("md5").update(content).digest("hex");
37
+ };
38
+
39
+ const compareDirectories = (dir1: string, dir2: string): boolean => {
40
+ const files1 = fs.existsSync(dir1) ? fs.readdirSync(dir1).sort() : [];
41
+ const files2 = fs.existsSync(dir2) ? fs.readdirSync(dir2).sort() : [];
42
+
43
+ if (files1.length !== files2.length) return false;
44
+ if (!files1.every((f, i) => f === files2[i])) return false;
45
+
46
+ return files1.every(file => {
47
+ const hash1 = getFileHash(path.join(dir1, file));
48
+ const hash2 = getFileHash(path.join(dir2, file));
49
+ return hash1 === hash2;
50
+ });
51
+ };
52
+
53
+ const createTestFiles = async (srcDir: string, files: Record<string, string>) => {
54
+ await fs.promises.mkdir(srcDir, { recursive: true });
55
+ for (const [filename, content] of Object.entries(files)) {
56
+ await fs.promises.writeFile(path.join(srcDir, filename), content);
57
+ }
58
+ };
59
+
60
+ it("should generate identical output with complex nested interfaces", async () => {
61
+ const { srcDir, outputDir1, outputDir2 } = createTestEnv("nested-interfaces");
62
+
63
+ await createTestFiles(srcDir, {
64
+ "user.jsonschema.ts": `
65
+ export interface IAddress {
66
+ street: string;
67
+ city: string;
68
+ country: string;
69
+ }
70
+
71
+ export interface IUser {
72
+ id: string;
73
+ name: string;
74
+ addresses: IAddress[];
75
+ metadata: {
76
+ created: Date;
77
+ updated: Date;
78
+ tags: string[];
79
+ };
80
+ }
81
+ `,
82
+ "product.jsonschema.ts": `
83
+ export interface ICategory {
84
+ id: number;
85
+ name: string;
86
+ parent?: ICategory;
87
+ }
88
+
89
+ export interface IProduct {
90
+ sku: string;
91
+ name: string;
92
+ price: number;
93
+ categories: ICategory[];
94
+ }
95
+ `
96
+ });
97
+
98
+ const baseOptions: ICommandOptions = {
99
+ glob: "**/*.jsonschema.ts",
100
+ rootPath: srcDir,
101
+ output: "",
102
+ tsconfigPath: "",
103
+ helpers: true,
104
+ additionalProperties: false,
105
+ verbose: false,
106
+ progress: false,
107
+ minify: false,
108
+ cache: false,
109
+ parallel: true,
110
+ treeShaking: false,
111
+ lazyLoad: false,
112
+ };
113
+
114
+ // Generate twice
115
+ const generator1 = new SchemaGenerator({ ...baseOptions, output: outputDir1 });
116
+ await generator1.Generate();
117
+
118
+ const generator2 = new SchemaGenerator({ ...baseOptions, output: outputDir2 });
119
+ await generator2.Generate();
120
+
121
+ expect(compareDirectories(outputDir1, outputDir2)).toBe(true);
122
+ });
123
+
124
+ it("should maintain determinism with circular references", async () => {
125
+ const { srcDir, outputDir1, outputDir2 } = createTestEnv("circular-refs");
126
+
127
+ await createTestFiles(srcDir, {
128
+ "models.jsonschema.ts": `
129
+ export interface INode {
130
+ id: string;
131
+ value: any;
132
+ parent?: INode;
133
+ children: INode[];
134
+ }
135
+
136
+ export interface IGraph {
137
+ nodes: INode[];
138
+ edges: IEdge[];
139
+ }
140
+
141
+ export interface IEdge {
142
+ from: INode;
143
+ to: INode;
144
+ weight?: number;
145
+ }
146
+ `
147
+ });
148
+
149
+ const options: ICommandOptions = {
150
+ glob: "**/*.jsonschema.ts",
151
+ rootPath: srcDir,
152
+ output: "",
153
+ tsconfigPath: "",
154
+ helpers: true,
155
+ additionalProperties: false,
156
+ verbose: false,
157
+ progress: false,
158
+ minify: false,
159
+ cache: false,
160
+ parallel: true,
161
+ treeShaking: false,
162
+ lazyLoad: false,
163
+ };
164
+
165
+ const generator1 = new SchemaGenerator({ ...options, output: outputDir1 });
166
+ await generator1.Generate();
167
+
168
+ const generator2 = new SchemaGenerator({ ...options, output: outputDir2 });
169
+ await generator2.Generate();
170
+
171
+ expect(compareDirectories(outputDir1, outputDir2)).toBe(true);
172
+ });
173
+
174
+ it("should be deterministic with many files processed in parallel", async () => {
175
+ const { srcDir } = createTestEnv("many-files");
176
+
177
+ const files: Record<string, string> = {};
178
+ for (let i = 0; i < 5; i++) { // Reduced to 5 files for faster tests
179
+ files[`model${i}.jsonschema.ts`] = `
180
+ export interface IModel${i} {
181
+ id: string;
182
+ index: number;
183
+ data: {
184
+ value${i}: string;
185
+ timestamp: Date;
186
+ };
187
+ }
188
+
189
+ export type Model${i}Type = "type_${i}_a" | "type_${i}_b";
190
+ `;
191
+ }
192
+
193
+ await createTestFiles(srcDir, files);
194
+
195
+ const options: ICommandOptions = {
196
+ glob: "**/*.jsonschema.ts",
197
+ rootPath: srcDir,
198
+ output: "",
199
+ tsconfigPath: "",
200
+ helpers: true,
201
+ additionalProperties: false,
202
+ verbose: false,
203
+ progress: false,
204
+ minify: false,
205
+ cache: false,
206
+ parallel: true,
207
+ treeShaking: false,
208
+ lazyLoad: false,
209
+ };
210
+
211
+ // Run multiple times to ensure consistency
212
+ const outputs: string[] = [];
213
+ for (let run = 0; run < 2; run++) { // Reduced from 3 to 2 runs
214
+ const outputDir = path.join(baseTestDir, `many-files/output-run-${run}`);
215
+ const generator = new SchemaGenerator({ ...options, output: outputDir });
216
+ await generator.Generate();
217
+
218
+ const schemaPath = path.join(outputDir, "validation.schema.json");
219
+ const hash = getFileHash(schemaPath);
220
+ outputs.push(hash);
221
+ }
222
+
223
+ // All runs should produce identical output
224
+ expect(outputs.every(h => h === outputs[0])).toBe(true);
225
+ }, 30000); // 30 second timeout for this test
226
+
227
+ it("should be deterministic with mixed export types", async () => {
228
+ const { srcDir, outputDir1, outputDir2 } = createTestEnv("mixed-exports");
229
+
230
+ await createTestFiles(srcDir, {
231
+ "types.jsonschema.ts": `
232
+ export interface IInterface {
233
+ field: string;
234
+ }
235
+
236
+ export type StringAlias = string;
237
+
238
+ export type UnionType = "option1" | "option2" | "option3";
239
+
240
+ export type IntersectionType = IInterface & {
241
+ extra: number;
242
+ };
243
+
244
+ export enum Status {
245
+ Active = "ACTIVE",
246
+ Inactive = "INACTIVE",
247
+ Pending = "PENDING"
248
+ }
249
+
250
+ export type ComplexType = {
251
+ status: Status;
252
+ union: UnionType;
253
+ data: IInterface | null;
254
+ };
255
+ `
256
+ });
257
+
258
+ const options: ICommandOptions = {
259
+ glob: "**/*.jsonschema.ts",
260
+ rootPath: srcDir,
261
+ output: "",
262
+ tsconfigPath: "",
263
+ helpers: true,
264
+ additionalProperties: false,
265
+ verbose: false,
266
+ progress: false,
267
+ minify: false,
268
+ cache: false,
269
+ parallel: false, // Test with sequential processing too
270
+ treeShaking: false,
271
+ lazyLoad: false,
272
+ };
273
+
274
+ const generator1 = new SchemaGenerator({ ...options, output: outputDir1 });
275
+ await generator1.Generate();
276
+
277
+ const generator2 = new SchemaGenerator({ ...options, output: outputDir2, parallel: true });
278
+ await generator2.Generate();
279
+
280
+ expect(compareDirectories(outputDir1, outputDir2)).toBe(true);
281
+ });
282
+
283
+ it("should maintain order with tree-shaking and lazy-loading enabled", async () => {
284
+ const { srcDir, outputDir1, outputDir2 } = createTestEnv("optimization-flags");
285
+
286
+ await createTestFiles(srcDir, {
287
+ "api.jsonschema.ts": `
288
+ export interface IRequest {
289
+ method: string;
290
+ url: string;
291
+ headers: Record<string, string>;
292
+ body?: unknown;
293
+ }
294
+
295
+ export interface IResponse {
296
+ status: number;
297
+ headers: Record<string, string>;
298
+ data: unknown;
299
+ }
300
+ `
301
+ });
302
+
303
+ const baseOptions: ICommandOptions = {
304
+ glob: "**/*.jsonschema.ts",
305
+ rootPath: srcDir,
306
+ output: "",
307
+ tsconfigPath: "",
308
+ helpers: true,
309
+ additionalProperties: false,
310
+ verbose: false,
311
+ progress: false,
312
+ minify: true,
313
+ cache: false,
314
+ parallel: true,
315
+ treeShaking: true,
316
+ lazyLoad: true,
317
+ };
318
+
319
+ // Test multiple combinations
320
+ const generator1 = new SchemaGenerator({ ...baseOptions, output: outputDir1 });
321
+ await generator1.Generate();
322
+
323
+ const generator2 = new SchemaGenerator({ ...baseOptions, output: outputDir2 });
324
+ await generator2.Generate();
325
+
326
+ expect(compareDirectories(outputDir1, outputDir2)).toBe(true);
327
+ });
328
+
329
+ it("should handle files with same symbols consistently", async () => {
330
+ const { srcDir, outputDir1, outputDir2 } = createTestEnv("duplicate-symbols");
331
+
332
+ await createTestFiles(srcDir, {
333
+ "module1.jsonschema.ts": `
334
+ export interface IShared {
335
+ id: string;
336
+ name: string;
337
+ }
338
+
339
+ export interface IModule1 {
340
+ shared: IShared;
341
+ specific1: string;
342
+ }
343
+ `,
344
+ "module2.jsonschema.ts": `
345
+ export interface IShared {
346
+ id: string;
347
+ name: string;
348
+ }
349
+
350
+ export interface IModule2 {
351
+ shared: IShared;
352
+ specific2: number;
353
+ }
354
+ `
355
+ });
356
+
357
+ const options: ICommandOptions = {
358
+ glob: "**/*.jsonschema.ts",
359
+ rootPath: srcDir,
360
+ output: "",
361
+ tsconfigPath: "",
362
+ helpers: true,
363
+ additionalProperties: false,
364
+ verbose: false,
365
+ progress: false,
366
+ minify: false,
367
+ cache: false,
368
+ parallel: true,
369
+ treeShaking: false,
370
+ lazyLoad: false,
371
+ };
372
+
373
+ const generator1 = new SchemaGenerator({ ...options, output: outputDir1 });
374
+ await generator1.Generate();
375
+
376
+ const generator2 = new SchemaGenerator({ ...options, output: outputDir2 });
377
+ await generator2.Generate();
378
+
379
+ expect(compareDirectories(outputDir1, outputDir2)).toBe(true);
380
+ });
381
+
382
+ it("should generate deterministic output with cache enabled", async () => {
383
+ const { srcDir, outputDir1, outputDir2 } = createTestEnv("with-cache");
384
+
385
+ await createTestFiles(srcDir, {
386
+ "cached.jsonschema.ts": `
387
+ export interface ICached {
388
+ id: string;
389
+ value: number;
390
+ timestamp: Date;
391
+ }
392
+ `
393
+ });
394
+
395
+ const options: ICommandOptions = {
396
+ glob: "**/*.jsonschema.ts",
397
+ rootPath: srcDir,
398
+ output: "",
399
+ tsconfigPath: "",
400
+ helpers: true,
401
+ additionalProperties: false,
402
+ verbose: false,
403
+ progress: false,
404
+ minify: false,
405
+ cache: true, // Enable caching
406
+ parallel: true,
407
+ treeShaking: false,
408
+ lazyLoad: false,
409
+ };
410
+
411
+ // First run with cache
412
+ const generator1 = new SchemaGenerator({ ...options, output: outputDir1 });
413
+ await generator1.Generate();
414
+
415
+ // Second run should use cache
416
+ const generator2 = new SchemaGenerator({ ...options, output: outputDir2 });
417
+ await generator2.Generate();
418
+
419
+ expect(compareDirectories(outputDir1, outputDir2)).toBe(true);
420
+
421
+ // Clear cache and run again
422
+ generator2.clearCache();
423
+ const outputDir3 = path.join(baseTestDir, "with-cache/output-3");
424
+ const generator3 = new SchemaGenerator({ ...options, output: outputDir3 });
425
+ await generator3.Generate();
426
+
427
+ expect(compareDirectories(outputDir1, outputDir3)).toBe(true);
428
+ });
429
+ });
@@ -0,0 +1,276 @@
1
+ import { SchemaGenerator } from "./SchemaGenerator";
2
+ import { ICommandOptions } from "./ICommandOptions";
3
+ import * as fs from "fs";
4
+ import * as path from "path";
5
+ import * as crypto from "crypto";
6
+
7
+ describe("SchemaGenerator - Deterministic Output", () => {
8
+ const testOutputPath1 = path.join(__dirname, "../.test-tmp/deterministic-output-1");
9
+ const testOutputPath2 = path.join(__dirname, "../.test-tmp/deterministic-output-2");
10
+
11
+ beforeEach(() => {
12
+ // Clean up test directories before each test
13
+ [testOutputPath1, testOutputPath2].forEach((dir) => {
14
+ if (fs.existsSync(dir)) {
15
+ fs.rmSync(dir, { recursive: true, force: true });
16
+ }
17
+ });
18
+ });
19
+
20
+ afterEach(() => {
21
+ // Clean up test directories after each test
22
+ [testOutputPath1, testOutputPath2].forEach((dir) => {
23
+ if (fs.existsSync(dir)) {
24
+ fs.rmSync(dir, { recursive: true, force: true });
25
+ }
26
+ });
27
+ });
28
+
29
+ const getFileHash = (filePath: string): string => {
30
+ if (!fs.existsSync(filePath)) {
31
+ return "";
32
+ }
33
+ const content = fs.readFileSync(filePath, "utf-8");
34
+ return crypto.createHash("md5").update(content).digest("hex");
35
+ };
36
+
37
+ const getDirectoryHashes = (dir: string): Map<string, string> => {
38
+ const hashes = new Map<string, string>();
39
+ if (!fs.existsSync(dir)) {
40
+ return hashes;
41
+ }
42
+
43
+ const files = fs.readdirSync(dir);
44
+ files.forEach((file) => {
45
+ const filePath = path.join(dir, file);
46
+ if (fs.statSync(filePath).isFile()) {
47
+ hashes.set(file, getFileHash(filePath));
48
+ }
49
+ });
50
+
51
+ return hashes;
52
+ };
53
+
54
+ it("should generate identical output for single file on multiple runs", async () => {
55
+ const options1: ICommandOptions = {
56
+ glob: "test/basic-scenario/*.jsonschema.ts",
57
+ rootPath: path.join(__dirname),
58
+ output: "../.test-tmp/deterministic-output-1",
59
+ tsconfigPath: "",
60
+ helpers: true,
61
+ additionalProperties: false,
62
+ verbose: false,
63
+ progress: false,
64
+ minify: false,
65
+ cache: false,
66
+ parallel: true,
67
+ treeShaking: false,
68
+ lazyLoad: false,
69
+ };
70
+
71
+ const options2: ICommandOptions = {
72
+ ...options1,
73
+ output: "../.test-tmp/deterministic-output-2",
74
+ };
75
+
76
+ // First generation
77
+ const generator1 = new SchemaGenerator(options1);
78
+ await generator1.Generate();
79
+
80
+ // Second generation
81
+ const generator2 = new SchemaGenerator(options2);
82
+ await generator2.Generate();
83
+
84
+ // Compare hashes
85
+ const hashes1 = getDirectoryHashes(testOutputPath1);
86
+ const hashes2 = getDirectoryHashes(testOutputPath2);
87
+
88
+ expect(hashes1.size).toBeGreaterThan(0);
89
+ expect(hashes1.size).toBe(hashes2.size);
90
+
91
+ hashes1.forEach((hash, fileName) => {
92
+ expect(hashes2.get(fileName)).toBe(hash);
93
+ });
94
+ });
95
+
96
+ it("should generate identical output for multiple files with identical symbols", async () => {
97
+ const options1: ICommandOptions = {
98
+ glob: "test/duplicate-symbols-identitcal-implementation/*.jsonschema.ts",
99
+ rootPath: path.join(__dirname),
100
+ output: "../.test-tmp/deterministic-output-1",
101
+ tsconfigPath: "",
102
+ helpers: true,
103
+ additionalProperties: false,
104
+ verbose: false,
105
+ progress: false,
106
+ minify: false,
107
+ cache: false,
108
+ parallel: true,
109
+ treeShaking: false,
110
+ lazyLoad: false,
111
+ };
112
+
113
+ const options2: ICommandOptions = {
114
+ ...options1,
115
+ output: "../.test-tmp/deterministic-output-2",
116
+ };
117
+
118
+ // First generation
119
+ const generator1 = new SchemaGenerator(options1);
120
+ await generator1.Generate();
121
+
122
+ // Second generation
123
+ const generator2 = new SchemaGenerator(options2);
124
+ await generator2.Generate();
125
+
126
+ // Compare hashes
127
+ const hashes1 = getDirectoryHashes(testOutputPath1);
128
+ const hashes2 = getDirectoryHashes(testOutputPath2);
129
+
130
+ expect(hashes1.size).toBeGreaterThan(0);
131
+ expect(hashes1.size).toBe(hashes2.size);
132
+
133
+ hashes1.forEach((hash, fileName) => {
134
+ expect(hashes2.get(fileName)).toStrictEqual(hash);
135
+ });
136
+ });
137
+
138
+ it("should generate identical output regardless of parallel vs sequential processing", async () => {
139
+ const baseOptions: Omit<ICommandOptions, "output" | "parallel"> = {
140
+ glob: "test/basic-scenario/*.jsonschema.ts",
141
+ rootPath: path.join(__dirname),
142
+ tsconfigPath: "",
143
+ helpers: true,
144
+ additionalProperties: false,
145
+ verbose: false,
146
+ progress: false,
147
+ minify: false,
148
+ cache: false,
149
+ treeShaking: false,
150
+ lazyLoad: false,
151
+ };
152
+
153
+ const optionsParallel: ICommandOptions = {
154
+ ...baseOptions,
155
+ output: "../.test-tmp/deterministic-output-1",
156
+ parallel: true,
157
+ };
158
+
159
+ const optionsSequential: ICommandOptions = {
160
+ ...baseOptions,
161
+ output: "../.test-tmp/deterministic-output-2",
162
+ parallel: false,
163
+ };
164
+
165
+ // Parallel generation
166
+ const generatorParallel = new SchemaGenerator(optionsParallel);
167
+ await generatorParallel.Generate();
168
+
169
+ // Sequential generation
170
+ const generatorSequential = new SchemaGenerator(optionsSequential);
171
+ await generatorSequential.Generate();
172
+
173
+ // Compare hashes
174
+ const hashesParallel = getDirectoryHashes(testOutputPath1);
175
+ const hashesSequential = getDirectoryHashes(testOutputPath2);
176
+
177
+ expect(hashesParallel.size).toBeGreaterThan(0);
178
+ expect(hashesParallel.size).toBe(hashesSequential.size);
179
+
180
+ hashesParallel.forEach((hash, fileName) => {
181
+ expect(hashesSequential.get(fileName)).toBe(hash);
182
+ });
183
+ });
184
+
185
+ it("should generate identical output with different output generation options", async () => {
186
+ // Test that tree-shaking and lazy-load options produce deterministic output
187
+ const baseOptions: Omit<ICommandOptions, "output" | "treeShaking" | "lazyLoad"> = {
188
+ glob: "test/basic-scenario/*.jsonschema.ts",
189
+ rootPath: path.join(__dirname),
190
+ tsconfigPath: "",
191
+ helpers: true,
192
+ additionalProperties: false,
193
+ verbose: false,
194
+ progress: false,
195
+ minify: false,
196
+ cache: false,
197
+ parallel: true,
198
+ };
199
+
200
+ const optionsTreeShaking1: ICommandOptions = {
201
+ ...baseOptions,
202
+ output: "../.test-tmp/deterministic-output-1",
203
+ treeShaking: true,
204
+ lazyLoad: false,
205
+ };
206
+
207
+ const optionsTreeShaking2: ICommandOptions = {
208
+ ...baseOptions,
209
+ output: "../.test-tmp/deterministic-output-2",
210
+ treeShaking: true,
211
+ lazyLoad: false,
212
+ };
213
+
214
+ // First generation with tree-shaking
215
+ const generator1 = new SchemaGenerator(optionsTreeShaking1);
216
+ await generator1.Generate();
217
+
218
+ // Second generation with tree-shaking
219
+ const generator2 = new SchemaGenerator(optionsTreeShaking2);
220
+ await generator2.Generate();
221
+
222
+ // Compare hashes
223
+ const hashes1 = getDirectoryHashes(testOutputPath1);
224
+ const hashes2 = getDirectoryHashes(testOutputPath2);
225
+
226
+ expect(hashes1.size).toBeGreaterThan(0);
227
+ expect(hashes1.size).toBe(hashes2.size);
228
+
229
+ hashes1.forEach((hash, fileName) => {
230
+ expect(hashes2.get(fileName)).toBe(hash);
231
+ });
232
+ });
233
+
234
+ it("should maintain consistent import order in generated files", async () => {
235
+ const options: ICommandOptions = {
236
+ glob: "test/duplicate-symbols-identitcal-implementation/*.jsonschema.ts",
237
+ rootPath: path.join(__dirname),
238
+ output: "../.test-tmp/deterministic-output-1",
239
+ tsconfigPath: "",
240
+ helpers: true,
241
+ additionalProperties: false,
242
+ verbose: false,
243
+ progress: false,
244
+ minify: false,
245
+ cache: false,
246
+ parallel: true,
247
+ treeShaking: false,
248
+ lazyLoad: false,
249
+ };
250
+
251
+ const generator = new SchemaGenerator(options);
252
+ await generator.Generate();
253
+
254
+ // Check that SchemaDefinition.ts has sorted imports
255
+ const schemaDefPath = path.join(testOutputPath1, "SchemaDefinition.ts");
256
+ expect(fs.existsSync(schemaDefPath)).toBe(true);
257
+
258
+ const schemaDefContent = fs.readFileSync(schemaDefPath, "utf-8");
259
+ const importLines = schemaDefContent.split("\n").filter((line) => line.startsWith("import"));
260
+
261
+ // Verify imports are in alphabetical order
262
+ const sortedImports = [...importLines].sort();
263
+ expect(importLines).toEqual(sortedImports);
264
+
265
+ // Check that ValidationType.ts has sorted imports
266
+ const validationTypePath = path.join(testOutputPath1, "ValidationType.ts");
267
+ expect(fs.existsSync(validationTypePath)).toBe(true);
268
+
269
+ const validationTypeContent = fs.readFileSync(validationTypePath, "utf-8");
270
+ const validationImportLines = validationTypeContent.split("\n").filter((line) => line.startsWith("import"));
271
+
272
+ // Verify imports are in alphabetical order
273
+ const sortedValidationImports = [...validationImportLines].sort();
274
+ expect(validationImportLines).toEqual(sortedValidationImports);
275
+ });
276
+ });