create-fluxstack 1.0.0

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 (101) hide show
  1. package/.env +30 -0
  2. package/LICENSE +21 -0
  3. package/README.md +214 -0
  4. package/app/client/README.md +69 -0
  5. package/app/client/frontend-only.ts +12 -0
  6. package/app/client/index.html +13 -0
  7. package/app/client/public/vite.svg +1 -0
  8. package/app/client/src/App.css +883 -0
  9. package/app/client/src/App.tsx +669 -0
  10. package/app/client/src/assets/react.svg +1 -0
  11. package/app/client/src/components/TestPage.tsx +453 -0
  12. package/app/client/src/index.css +51 -0
  13. package/app/client/src/lib/eden-api.ts +110 -0
  14. package/app/client/src/main.tsx +10 -0
  15. package/app/client/src/vite-env.d.ts +1 -0
  16. package/app/client/tsconfig.app.json +43 -0
  17. package/app/client/tsconfig.json +7 -0
  18. package/app/client/tsconfig.node.json +25 -0
  19. package/app/server/app.ts +10 -0
  20. package/app/server/backend-only.ts +15 -0
  21. package/app/server/controllers/users.controller.ts +69 -0
  22. package/app/server/index.ts +104 -0
  23. package/app/server/routes/index.ts +25 -0
  24. package/app/server/routes/users.routes.ts +121 -0
  25. package/app/server/types/index.ts +1 -0
  26. package/app/shared/types/index.ts +18 -0
  27. package/bun.lock +1053 -0
  28. package/core/__tests__/integration.test.ts +227 -0
  29. package/core/build/index.ts +186 -0
  30. package/core/cli/command-registry.ts +334 -0
  31. package/core/cli/index.ts +394 -0
  32. package/core/cli/plugin-discovery.ts +200 -0
  33. package/core/client/standalone.ts +57 -0
  34. package/core/config/__tests__/config-loader.test.ts +591 -0
  35. package/core/config/__tests__/config-merger.test.ts +657 -0
  36. package/core/config/__tests__/env-converter.test.ts +372 -0
  37. package/core/config/__tests__/env-processor.test.ts +431 -0
  38. package/core/config/__tests__/env.test.ts +452 -0
  39. package/core/config/__tests__/integration.test.ts +418 -0
  40. package/core/config/__tests__/loader.test.ts +331 -0
  41. package/core/config/__tests__/schema.test.ts +129 -0
  42. package/core/config/__tests__/validator.test.ts +318 -0
  43. package/core/config/env-dynamic.ts +326 -0
  44. package/core/config/env.ts +597 -0
  45. package/core/config/index.ts +317 -0
  46. package/core/config/loader.ts +546 -0
  47. package/core/config/runtime-config.ts +322 -0
  48. package/core/config/schema.ts +694 -0
  49. package/core/config/validator.ts +540 -0
  50. package/core/framework/__tests__/server.test.ts +233 -0
  51. package/core/framework/client.ts +132 -0
  52. package/core/framework/index.ts +8 -0
  53. package/core/framework/server.ts +501 -0
  54. package/core/framework/types.ts +63 -0
  55. package/core/plugins/__tests__/built-in.test.ts.disabled +366 -0
  56. package/core/plugins/__tests__/manager.test.ts +398 -0
  57. package/core/plugins/__tests__/monitoring.test.ts +401 -0
  58. package/core/plugins/__tests__/registry.test.ts +335 -0
  59. package/core/plugins/built-in/index.ts +142 -0
  60. package/core/plugins/built-in/logger/index.ts +180 -0
  61. package/core/plugins/built-in/monitoring/README.md +193 -0
  62. package/core/plugins/built-in/monitoring/index.ts +912 -0
  63. package/core/plugins/built-in/static/index.ts +289 -0
  64. package/core/plugins/built-in/swagger/index.ts +229 -0
  65. package/core/plugins/built-in/vite/index.ts +316 -0
  66. package/core/plugins/config.ts +348 -0
  67. package/core/plugins/discovery.ts +350 -0
  68. package/core/plugins/executor.ts +351 -0
  69. package/core/plugins/index.ts +195 -0
  70. package/core/plugins/manager.ts +583 -0
  71. package/core/plugins/registry.ts +424 -0
  72. package/core/plugins/types.ts +254 -0
  73. package/core/server/framework.ts +123 -0
  74. package/core/server/index.ts +8 -0
  75. package/core/server/plugins/database.ts +182 -0
  76. package/core/server/plugins/logger.ts +47 -0
  77. package/core/server/plugins/swagger.ts +34 -0
  78. package/core/server/standalone.ts +91 -0
  79. package/core/templates/create-project.ts +455 -0
  80. package/core/types/api.ts +169 -0
  81. package/core/types/build.ts +174 -0
  82. package/core/types/config.ts +68 -0
  83. package/core/types/index.ts +127 -0
  84. package/core/types/plugin.ts +94 -0
  85. package/core/utils/__tests__/errors.test.ts +139 -0
  86. package/core/utils/__tests__/helpers.test.ts +297 -0
  87. package/core/utils/__tests__/logger.test.ts +141 -0
  88. package/core/utils/env-runtime-v2.ts +232 -0
  89. package/core/utils/env-runtime.ts +252 -0
  90. package/core/utils/errors/codes.ts +115 -0
  91. package/core/utils/errors/handlers.ts +63 -0
  92. package/core/utils/errors/index.ts +81 -0
  93. package/core/utils/helpers.ts +180 -0
  94. package/core/utils/index.ts +18 -0
  95. package/core/utils/logger/index.ts +161 -0
  96. package/core/utils/logger.ts +106 -0
  97. package/core/utils/monitoring/index.ts +212 -0
  98. package/create-fluxstack.ts +231 -0
  99. package/package.json +43 -0
  100. package/tsconfig.json +51 -0
  101. package/vite.config.ts +42 -0
@@ -0,0 +1,591 @@
1
+ /**
2
+ * Tests for Configuration Loader
3
+ * Tests the main configuration loading system, including file loading, caching, and fallbacks
4
+ */
5
+
6
+ import { describe, test, expect, beforeEach, afterEach, vi } from 'vitest'
7
+ import {
8
+ getConfig,
9
+ getConfigSync,
10
+ reloadConfig,
11
+ createPluginConfig,
12
+ isFeatureEnabled,
13
+ createLegacyConfig
14
+ } from '../index'
15
+ import type { FluxStackConfig } from '../schema'
16
+
17
+ // Mock file system operations
18
+ vi.mock('fs', () => ({
19
+ existsSync: vi.fn(),
20
+ promises: {
21
+ readFile: vi.fn(),
22
+ access: vi.fn()
23
+ }
24
+ }))
25
+
26
+ vi.mock('fs/promises', () => ({
27
+ readFile: vi.fn(),
28
+ access: vi.fn()
29
+ }))
30
+
31
+ describe('Configuration Loader', () => {
32
+ let originalEnv: NodeJS.ProcessEnv
33
+
34
+ beforeEach(() => {
35
+ originalEnv = { ...process.env }
36
+ // Clear relevant environment variables
37
+ for (const key in process.env) {
38
+ if (key.startsWith('FLUXSTACK_') || key.startsWith('PORT') || key.startsWith('HOST') ||
39
+ key.startsWith('NODE_ENV')) {
40
+ delete process.env[key]
41
+ }
42
+ }
43
+
44
+ // Clear any cached configurations
45
+ vi.clearAllMocks()
46
+ })
47
+
48
+ afterEach(() => {
49
+ process.env = originalEnv
50
+ })
51
+
52
+ describe('getConfigSync', () => {
53
+ test('loads configuration from environment variables', () => {
54
+ process.env.PORT = '4000'
55
+ process.env.HOST = 'example.com'
56
+ process.env.LOG_LEVEL = 'debug'
57
+ process.env.NODE_ENV = 'production'
58
+
59
+ const config = getConfigSync()
60
+
61
+ expect(config.server?.port).toBe(4000)
62
+ expect(config.server?.host).toBe('example.com')
63
+ expect(config.logging?.level).toBe('debug')
64
+ })
65
+
66
+ test('applies environment defaults based on NODE_ENV', () => {
67
+ process.env.NODE_ENV = 'production'
68
+
69
+ const config = getConfigSync()
70
+
71
+ // Should apply production defaults
72
+ expect(config.build?.optimization?.minify).toBe(true)
73
+ expect(config.monitoring?.enabled).toBe(true)
74
+ })
75
+
76
+ test('uses development defaults when NODE_ENV not set', () => {
77
+ delete process.env.NODE_ENV
78
+
79
+ const config = getConfigSync()
80
+
81
+ // Should apply development defaults
82
+ expect(config.build?.optimization?.minify).toBe(false)
83
+ expect(config.monitoring?.enabled).toBe(false)
84
+ })
85
+
86
+ test('handles custom environment variables with FluxStack prefix', () => {
87
+ process.env.FLUXSTACK_PORT = '5000'
88
+ process.env.FLUXSTACK_API_PREFIX = '/v2'
89
+ process.env.FLUXSTACK_LOG_LEVEL = 'error'
90
+
91
+ // Force reload config to pick up new env vars
92
+ reloadConfig()
93
+ const config = getConfigSync()
94
+
95
+ expect(config.server?.port).toBe(5000)
96
+ expect(config.server?.apiPrefix).toBe('/v2')
97
+ expect(config.logging?.level).toBe('error')
98
+ })
99
+
100
+ test('merges CORS configuration from environment', () => {
101
+ process.env.CORS_ORIGINS = 'http://localhost:3000,https://example.com'
102
+ process.env.CORS_METHODS = 'GET,POST,DELETE'
103
+ process.env.CORS_CREDENTIALS = 'true'
104
+
105
+ const config = getConfigSync()
106
+
107
+ expect(config.server?.cors?.origins).toEqual(['http://localhost:3000', 'https://example.com'])
108
+ expect(config.server?.cors?.methods).toEqual(['GET', 'POST', 'DELETE'])
109
+ expect(config.server?.cors?.credentials).toBe(true)
110
+ })
111
+
112
+ test('handles database configuration from environment', () => {
113
+ process.env.DATABASE_URL = 'postgresql://user:pass@localhost:5432/db'
114
+ process.env.DATABASE_HOST = 'db.example.com'
115
+ process.env.DATABASE_PORT = '5433'
116
+ process.env.DATABASE_SSL = 'true'
117
+
118
+ const config = getConfigSync()
119
+
120
+ expect(config.database?.url).toBe('postgresql://user:pass@localhost:5432/db')
121
+ expect(config.database?.host).toBe('db.example.com')
122
+ expect(config.database?.port).toBe(5433)
123
+ expect(config.database?.ssl).toBe(true)
124
+ })
125
+
126
+ test('handles authentication configuration', () => {
127
+ process.env.JWT_SECRET = 'my-secret-key'
128
+ process.env.JWT_EXPIRES_IN = '7d'
129
+ process.env.JWT_ALGORITHM = 'HS256'
130
+
131
+ const config = getConfigSync()
132
+
133
+ expect(config.auth?.secret).toBe('my-secret-key')
134
+ expect(config.auth?.expiresIn).toBe('7d')
135
+ expect(config.auth?.algorithm).toBe('HS256')
136
+ })
137
+
138
+ test('handles email configuration', () => {
139
+ process.env.SMTP_HOST = 'smtp.gmail.com'
140
+ process.env.SMTP_PORT = '587'
141
+ process.env.SMTP_USER = 'user@example.com'
142
+ process.env.SMTP_SECURE = 'true'
143
+
144
+ const config = getConfigSync()
145
+
146
+ expect(config.email?.host).toBe('smtp.gmail.com')
147
+ expect(config.email?.port).toBe(587)
148
+ expect(config.email?.user).toBe('user@example.com')
149
+ expect(config.email?.secure).toBe(true)
150
+ })
151
+
152
+ test('handles monitoring configuration', () => {
153
+ process.env.MONITORING_ENABLED = 'true'
154
+ process.env.METRICS_ENABLED = 'false'
155
+ process.env.METRICS_INTERVAL = '30000'
156
+ process.env.PROFILING_ENABLED = 'true'
157
+
158
+ const config = getConfigSync()
159
+
160
+ expect(config.monitoring?.enabled).toBe(true)
161
+ expect(config.monitoring?.metrics?.enabled).toBe(false)
162
+ expect(config.monitoring?.metrics?.collectInterval).toBe(30000)
163
+ expect(config.monitoring?.profiling?.enabled).toBe(true)
164
+ })
165
+
166
+ test('handles build configuration', () => {
167
+ process.env.BUILD_TARGET = 'docker'
168
+ process.env.BUILD_OUTDIR = 'build'
169
+ process.env.BUILD_MINIFY = 'true'
170
+ process.env.BUILD_SOURCEMAPS = 'false'
171
+
172
+ reloadConfig()
173
+ const config = getConfigSync()
174
+
175
+ expect(config.build?.target).toBe('docker')
176
+ expect(config.build?.outDir).toBe('build')
177
+ expect(config.build?.optimization?.minify).toBe(true)
178
+ expect(config.build?.sourceMaps).toBe(false)
179
+ })
180
+
181
+ test('handles plugin configuration', () => {
182
+ process.env.FLUXSTACK_PLUGINS_ENABLED = 'plugin1,plugin2,plugin3'
183
+ process.env.FLUXSTACK_PLUGINS_DISABLED = 'plugin4'
184
+
185
+ reloadConfig()
186
+ const config = getConfigSync()
187
+
188
+ expect(config.plugins?.enabled).toEqual(['plugin1', 'plugin2', 'plugin3'])
189
+ expect(config.plugins?.disabled).toEqual(['plugin4'])
190
+ })
191
+ })
192
+
193
+ describe('createPluginConfig', () => {
194
+ test('creates plugin configuration from main config', () => {
195
+ const mainConfig: FluxStackConfig = {
196
+ app: { name: 'TestApp', version: '1.0.0' },
197
+ server: {
198
+ port: 3000,
199
+ host: 'localhost',
200
+ apiPrefix: '/api',
201
+ cors: {
202
+ origins: ['*'],
203
+ methods: ['GET', 'POST'],
204
+ headers: ['Content-Type'],
205
+ credentials: false,
206
+ maxAge: 86400
207
+ },
208
+ middleware: []
209
+ },
210
+ client: {
211
+ port: 5173,
212
+ proxy: { target: 'http://localhost:3000' },
213
+ build: {
214
+ target: 'es2020',
215
+ outDir: 'dist/client',
216
+ sourceMaps: true,
217
+ minify: false
218
+ }
219
+ },
220
+ build: {
221
+ target: 'bun',
222
+ outDir: 'dist',
223
+ clean: true,
224
+ optimization: {
225
+ minify: false,
226
+ compress: false,
227
+ treeshake: false,
228
+ splitChunks: false,
229
+ bundleAnalyzer: false
230
+ },
231
+ sourceMaps: true
232
+ },
233
+ logging: {
234
+ level: 'info',
235
+ format: 'pretty',
236
+ transports: [
237
+ { type: 'console', level: 'info', format: 'pretty' }
238
+ ]
239
+ },
240
+ monitoring: {
241
+ enabled: false,
242
+ metrics: {
243
+ enabled: false,
244
+ collectInterval: 60000,
245
+ httpMetrics: true,
246
+ systemMetrics: true,
247
+ customMetrics: false
248
+ },
249
+ profiling: {
250
+ enabled: false,
251
+ sampleRate: 0.1,
252
+ memoryProfiling: false,
253
+ cpuProfiling: false
254
+ },
255
+ exporters: []
256
+ },
257
+ plugins: {
258
+ enabled: [],
259
+ disabled: [],
260
+ config: {
261
+ vite: {
262
+ port: 5174,
263
+ enabled: true
264
+ },
265
+ logger: {
266
+ logRequests: true,
267
+ logResponses: false
268
+ }
269
+ }
270
+ },
271
+ custom: {
272
+ myPlugin: {
273
+ customSetting: 'value'
274
+ }
275
+ }
276
+ } as FluxStackConfig
277
+
278
+ // Test plugin config from plugins.config
279
+ const viteConfig = createPluginConfig(mainConfig, 'vite')
280
+ expect(viteConfig).toEqual({
281
+ port: 5174,
282
+ enabled: true
283
+ })
284
+
285
+ // Test plugin config from custom section
286
+ const myPluginConfig = createPluginConfig(mainConfig, 'myPlugin')
287
+ expect(myPluginConfig).toEqual({
288
+ customSetting: 'value'
289
+ })
290
+
291
+ // Test merging both sections
292
+ const combinedConfig: FluxStackConfig = {
293
+ ...mainConfig,
294
+ plugins: {
295
+ ...mainConfig.plugins,
296
+ config: {
297
+ ...mainConfig.plugins.config,
298
+ myPlugin: {
299
+ baseSetting: 'base'
300
+ }
301
+ }
302
+ }
303
+ }
304
+
305
+ const mergedConfig = createPluginConfig(combinedConfig, 'myPlugin')
306
+ expect(mergedConfig).toEqual({
307
+ baseSetting: 'base',
308
+ customSetting: 'value' // custom should override plugins.config
309
+ })
310
+ })
311
+
312
+ test('returns empty object for non-existent plugin', () => {
313
+ const mainConfig: FluxStackConfig = {
314
+ app: { name: 'TestApp', version: '1.0.0' },
315
+ server: {
316
+ port: 3000,
317
+ host: 'localhost',
318
+ apiPrefix: '/api',
319
+ cors: {
320
+ origins: ['*'],
321
+ methods: ['GET', 'POST'],
322
+ headers: ['Content-Type'],
323
+ credentials: false,
324
+ maxAge: 86400
325
+ },
326
+ middleware: []
327
+ },
328
+ client: {
329
+ port: 5173,
330
+ proxy: { target: 'http://localhost:3000' },
331
+ build: {
332
+ target: 'es2020',
333
+ outDir: 'dist/client',
334
+ sourceMaps: true,
335
+ minify: false
336
+ }
337
+ },
338
+ build: {
339
+ target: 'bun',
340
+ outDir: 'dist',
341
+ clean: true,
342
+ optimization: {
343
+ minify: false,
344
+ compress: false,
345
+ treeshake: false,
346
+ splitChunks: false,
347
+ bundleAnalyzer: false
348
+ },
349
+ sourceMaps: true
350
+ },
351
+ logging: {
352
+ level: 'info',
353
+ format: 'pretty',
354
+ transports: [
355
+ { type: 'console', level: 'info', format: 'pretty' }
356
+ ]
357
+ },
358
+ monitoring: {
359
+ enabled: false,
360
+ metrics: {
361
+ enabled: false,
362
+ collectInterval: 60000,
363
+ httpMetrics: true,
364
+ systemMetrics: true,
365
+ customMetrics: false
366
+ },
367
+ profiling: {
368
+ enabled: false,
369
+ sampleRate: 0.1,
370
+ memoryProfiling: false,
371
+ cpuProfiling: false
372
+ },
373
+ exporters: []
374
+ },
375
+ plugins: {
376
+ enabled: [],
377
+ disabled: [],
378
+ config: {}
379
+ }
380
+ } as FluxStackConfig
381
+
382
+ const config = createPluginConfig(mainConfig, 'nonexistent')
383
+ expect(config).toEqual({})
384
+ })
385
+ })
386
+
387
+ describe('isFeatureEnabled', () => {
388
+ test('checks if feature is enabled in plugins', () => {
389
+ const config: FluxStackConfig = {
390
+ app: { name: 'TestApp', version: '1.0.0' },
391
+ server: {
392
+ port: 3000,
393
+ host: 'localhost',
394
+ apiPrefix: '/api',
395
+ cors: {
396
+ origins: ['*'],
397
+ methods: ['GET', 'POST'],
398
+ headers: ['Content-Type'],
399
+ credentials: false,
400
+ maxAge: 86400
401
+ },
402
+ middleware: []
403
+ },
404
+ client: {
405
+ port: 5173,
406
+ proxy: { target: 'http://localhost:3000' },
407
+ build: {
408
+ target: 'es2020',
409
+ outDir: 'dist/client',
410
+ sourceMaps: true,
411
+ minify: false
412
+ }
413
+ },
414
+ build: {
415
+ target: 'bun',
416
+ outDir: 'dist',
417
+ clean: true,
418
+ optimization: {
419
+ minify: false,
420
+ compress: false,
421
+ treeshake: false,
422
+ splitChunks: false,
423
+ bundleAnalyzer: false
424
+ },
425
+ sourceMaps: true
426
+ },
427
+ logging: {
428
+ level: 'info',
429
+ format: 'pretty',
430
+ transports: [
431
+ { type: 'console', level: 'info', format: 'pretty' }
432
+ ]
433
+ },
434
+ monitoring: {
435
+ enabled: true,
436
+ metrics: {
437
+ enabled: true,
438
+ collectInterval: 60000,
439
+ httpMetrics: true,
440
+ systemMetrics: true,
441
+ customMetrics: false
442
+ },
443
+ profiling: {
444
+ enabled: false,
445
+ sampleRate: 0.1,
446
+ memoryProfiling: false,
447
+ cpuProfiling: false
448
+ },
449
+ exporters: []
450
+ },
451
+ plugins: {
452
+ enabled: ['plugin1', 'plugin2'],
453
+ disabled: ['plugin3'],
454
+ config: {}
455
+ },
456
+ custom: {
457
+ customFeature: true
458
+ }
459
+ } as FluxStackConfig
460
+
461
+ expect(isFeatureEnabled(config, 'plugin1')).toBe(true)
462
+ expect(isFeatureEnabled(config, 'plugin2')).toBe(true)
463
+ expect(isFeatureEnabled(config, 'plugin3')).toBe(false) // disabled
464
+ expect(isFeatureEnabled(config, 'plugin4')).toBe(false) // not in enabled
465
+ expect(isFeatureEnabled(config, 'monitoring')).toBe(true)
466
+ expect(isFeatureEnabled(config, 'metrics')).toBe(true)
467
+ expect(isFeatureEnabled(config, 'profiling')).toBe(false)
468
+ expect(isFeatureEnabled(config, 'customFeature')).toBe(true)
469
+ expect(isFeatureEnabled(config, 'nonexistent')).toBe(false)
470
+ })
471
+ })
472
+
473
+ describe('createLegacyConfig', () => {
474
+ test('creates legacy configuration format', () => {
475
+ const config: FluxStackConfig = {
476
+ app: { name: 'TestApp', version: '1.0.0' },
477
+ server: {
478
+ port: 4000,
479
+ host: 'localhost',
480
+ apiPrefix: '/v2',
481
+ cors: {
482
+ origins: ['http://localhost:3000', 'https://example.com'],
483
+ methods: ['GET', 'POST', 'PUT'],
484
+ headers: ['Content-Type', 'Authorization'],
485
+ credentials: true,
486
+ maxAge: 86400
487
+ },
488
+ middleware: []
489
+ },
490
+ client: {
491
+ port: 5174,
492
+ proxy: { target: 'http://localhost:3000' },
493
+ build: {
494
+ target: 'es2020',
495
+ outDir: 'dist/client',
496
+ sourceMaps: true,
497
+ minify: false
498
+ }
499
+ },
500
+ build: {
501
+ target: 'docker',
502
+ outDir: 'build',
503
+ clean: true,
504
+ optimization: {
505
+ minify: false,
506
+ compress: false,
507
+ treeshake: false,
508
+ splitChunks: false,
509
+ bundleAnalyzer: false
510
+ },
511
+ sourceMaps: true
512
+ },
513
+ logging: {
514
+ level: 'info',
515
+ format: 'pretty',
516
+ transports: [
517
+ { type: 'console', level: 'info', format: 'pretty' }
518
+ ]
519
+ },
520
+ monitoring: {
521
+ enabled: false,
522
+ metrics: {
523
+ enabled: false,
524
+ collectInterval: 60000,
525
+ httpMetrics: true,
526
+ systemMetrics: true,
527
+ customMetrics: false
528
+ },
529
+ profiling: {
530
+ enabled: false,
531
+ sampleRate: 0.1,
532
+ memoryProfiling: false,
533
+ cpuProfiling: false
534
+ },
535
+ exporters: []
536
+ },
537
+ plugins: {
538
+ enabled: [],
539
+ disabled: [],
540
+ config: {}
541
+ }
542
+ } as FluxStackConfig
543
+
544
+ const legacyConfig = createLegacyConfig(config)
545
+
546
+ expect(legacyConfig).toEqual({
547
+ port: 4000,
548
+ vitePort: 5174,
549
+ clientPath: 'app/client',
550
+ apiPrefix: '/v2',
551
+ cors: {
552
+ origins: ['http://localhost:3000', 'https://example.com'],
553
+ methods: ['GET', 'POST', 'PUT'],
554
+ headers: ['Content-Type', 'Authorization']
555
+ },
556
+ build: {
557
+ outDir: 'build',
558
+ target: 'docker'
559
+ }
560
+ })
561
+ })
562
+ })
563
+
564
+ describe('error handling and warnings', () => {
565
+ test('handles configuration with warnings gracefully', () => {
566
+ // Test with invalid environment variables that should generate warnings
567
+ process.env.PORT = 'invalid-port' // Should fall back to default
568
+ process.env.LOG_LEVEL = 'invalid-level' // Should fall back to default
569
+ process.env.BUILD_TARGET = 'invalid-target' // Should fall back to default
570
+
571
+ expect(() => {
572
+ const config = getConfigSync()
573
+ // Should not throw, but use defaults
574
+ expect(typeof config.server?.port).toBe('number')
575
+ expect(['debug', 'info', 'warn', 'error']).toContain(config.logging?.level)
576
+ expect(['bun', 'node', 'docker']).toContain(config.build?.target)
577
+ }).not.toThrow()
578
+ })
579
+
580
+ test('handles missing optional configurations', () => {
581
+ // No environment variables set
582
+ const config = getConfigSync()
583
+
584
+ // Should have default values and structure
585
+ expect(config).toBeDefined()
586
+ expect(config.app).toBeDefined()
587
+ expect(config.server).toBeDefined()
588
+ expect(config.plugins).toBeDefined()
589
+ })
590
+ })
591
+ })