@aiready/context-analyzer 0.9.25 → 0.9.28

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.
package/dist/index.mjs CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  getCoUsageData,
13
13
  getSmartDefaults,
14
14
  inferDomainFromSemantics
15
- } from "./chunk-HOUDVRG2.mjs";
15
+ } from "./chunk-M64RHH4D.mjs";
16
16
  import "./chunk-Y6FXYEAI.mjs";
17
17
  export {
18
18
  adjustFragmentationForClassification,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiready/context-analyzer",
3
- "version": "0.9.25",
3
+ "version": "0.9.28",
4
4
  "description": "AI context window cost analysis - detect fragmented code, deep import chains, and expensive context budgets",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -49,7 +49,7 @@
49
49
  "commander": "^14.0.0",
50
50
  "chalk": "^5.3.0",
51
51
  "prompts": "^2.4.2",
52
- "@aiready/core": "0.9.22"
52
+ "@aiready/core": "0.9.25"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/node": "^24.0.0",
@@ -2,6 +2,7 @@ import { describe, it, expect } from 'vitest';
2
2
  import {
3
3
  classifyFile,
4
4
  adjustFragmentationForClassification,
5
+ adjustCohesionForClassification,
5
6
  getClassificationRecommendations,
6
7
  } from '../analyzer';
7
8
  import type { DependencyNode, FileClassification } from '../types';
@@ -49,6 +50,49 @@ describe('file classification', () => {
49
50
  expect(classification).toBe('type-definition');
50
51
  });
51
52
 
53
+ it('should classify files in /types/ directory as type-definition', () => {
54
+ const node = createNode({
55
+ file: 'shared/src/types/audit/parser.ts',
56
+ exports: [
57
+ { name: 'AuditParserConfig', type: 'interface', inferredDomain: 'audit' },
58
+ { name: 'ParseResult', type: 'type', inferredDomain: 'parse' },
59
+ ],
60
+ linesOfCode: 50,
61
+ });
62
+
63
+ const classification = classifyFile(node, 0.5, ['audit', 'parse']);
64
+ expect(classification).toBe('type-definition');
65
+ });
66
+
67
+ it('should classify files in nested /types/ subdirectories as type-definition', () => {
68
+ const node = createNode({
69
+ file: 'shared/src/types/audit/status.ts',
70
+ exports: [
71
+ { name: 'AuditStatus', type: 'type', inferredDomain: 'audit' },
72
+ { name: 'StatusMapping', type: 'interface', inferredDomain: 'status' },
73
+ ],
74
+ linesOfCode: 30,
75
+ });
76
+
77
+ const classification = classifyFile(node, 0.5, ['audit', 'status']);
78
+ expect(classification).toBe('type-definition');
79
+ });
80
+
81
+ it('should classify pure type files (only type/interface exports) as type-definition', () => {
82
+ const node = createNode({
83
+ file: 'src/models/user-models.ts', // NOT in /types/ but only type exports
84
+ exports: [
85
+ { name: 'UserCreateInput', type: 'interface', inferredDomain: 'user' },
86
+ { name: 'UserUpdateInput', type: 'interface', inferredDomain: 'user' },
87
+ { name: 'UserFilter', type: 'type', inferredDomain: 'user' },
88
+ ],
89
+ linesOfCode: 80,
90
+ });
91
+
92
+ const classification = classifyFile(node, 0.5, ['user']);
93
+ expect(classification).toBe('type-definition');
94
+ });
95
+
52
96
  it('should classify cohesive module files correctly', () => {
53
97
  const node = createNode({
54
98
  file: 'src/calculator.ts',
@@ -84,19 +128,19 @@ describe('file classification', () => {
84
128
 
85
129
  it('should classify files with multiple domains and very low cohesion as mixed-concerns', () => {
86
130
  const node = createNode({
87
- file: 'src/services/mixed-service.ts', // NOT a utility/config path
131
+ file: 'src/modules/mixed-module.ts', // NOT a utility/config/service path
88
132
  exports: [
89
- { name: 'DateFormatter', type: 'class', inferredDomain: 'date' }, // Use class to avoid utility detection
90
- { name: 'JSONParser', type: 'class', inferredDomain: 'json' },
91
- { name: 'EmailValidator', type: 'class', inferredDomain: 'email' },
133
+ { name: 'DateCalculator', type: 'class', inferredDomain: 'date' }, // Use class to avoid utility detection
134
+ { name: 'ReportBuilder', type: 'class', inferredDomain: 'report' },
135
+ { name: 'AuditLogger', type: 'class', inferredDomain: 'audit' },
92
136
  ],
93
137
  imports: [],
94
138
  linesOfCode: 150,
95
139
  });
96
140
 
97
141
  // Multiple domains + very low cohesion (< 0.4) = mixed concerns
98
- // Note: NOT in /utils/ or /helpers/ path, uses classes (not just functions/consts)
99
- const classification = classifyFile(node, 0.3, ['date', 'json', 'email']);
142
+ // Note: NOT in /utils/ or /helpers/ or /services/ path
143
+ const classification = classifyFile(node, 0.3, ['date', 'report', 'audit']);
100
144
  expect(classification).toBe('mixed-concerns');
101
145
  });
102
146
 
@@ -120,7 +164,7 @@ describe('file classification', () => {
120
164
  file: 'src/utils/helpers.ts',
121
165
  exports: [
122
166
  { name: 'formatDate', type: 'function', inferredDomain: 'date' },
123
- { name: 'parseJSON', type: 'function', inferredDomain: 'json' },
167
+ { name: 'stringifyJSON', type: 'function', inferredDomain: 'json' },
124
168
  { name: 'validateEmail', type: 'function', inferredDomain: 'email' },
125
169
  ],
126
170
  imports: [],
@@ -129,7 +173,7 @@ describe('file classification', () => {
129
173
 
130
174
  // Utility files are classified as cohesive by design
131
175
  const classification = classifyFile(node, 0.4, ['date', 'json', 'email']);
132
- expect(classification).toBe('cohesive-module');
176
+ expect(classification).toBe('utility-module');
133
177
  });
134
178
 
135
179
  it('should classify config/schema files as cohesive-module', () => {
@@ -248,4 +292,511 @@ describe('file classification', () => {
248
292
  expect(classification).toBe('cohesive-module');
249
293
  });
250
294
  });
251
- });
295
+
296
+ describe('new classification patterns', () => {
297
+ describe('lambda-handler detection', () => {
298
+ it('should classify files in handlers directory as lambda-handler', () => {
299
+ const node = createNode({
300
+ file: 'src/handlers/tier1-immediate.ts',
301
+ exports: [
302
+ { name: 'handler', type: 'function', inferredDomain: 'match' },
303
+ ],
304
+ imports: ['../services/matcher', '../services/db'],
305
+ linesOfCode: 150,
306
+ });
307
+
308
+ const classification = classifyFile(node, 0.21, ['match', 'db']);
309
+ expect(classification).toBe('lambda-handler');
310
+ });
311
+
312
+ it('should classify files with handler export as lambda-handler', () => {
313
+ const node = createNode({
314
+ file: 'src/api/process.ts',
315
+ exports: [
316
+ { name: 'processHandler', type: 'function', inferredDomain: 'process' },
317
+ ],
318
+ imports: ['../services/queue'],
319
+ linesOfCode: 80,
320
+ });
321
+
322
+ const classification = classifyFile(node, 0.3, ['process']);
323
+ expect(classification).toBe('lambda-handler');
324
+ });
325
+
326
+ it('should classify files in lambdas directory as lambda-handler', () => {
327
+ const node = createNode({
328
+ file: 'src/lambdas/match-single-document.ts',
329
+ exports: [
330
+ { name: 'handler', type: 'function', inferredDomain: 'match' },
331
+ ],
332
+ imports: ['../services/matcher'],
333
+ linesOfCode: 100,
334
+ });
335
+
336
+ const classification = classifyFile(node, 0.22, ['match']);
337
+ expect(classification).toBe('lambda-handler');
338
+ });
339
+
340
+ it('should classify single export functions as lambda-handler', () => {
341
+ const node = createNode({
342
+ file: 'src/functions/process.ts',
343
+ exports: [
344
+ { name: 'default', type: 'default', inferredDomain: 'process' },
345
+ ],
346
+ imports: ['../services/processor'],
347
+ linesOfCode: 60,
348
+ });
349
+
350
+ const classification = classifyFile(node, 0.4, ['process']);
351
+ expect(classification).toBe('lambda-handler');
352
+ });
353
+ });
354
+
355
+ describe('service-file detection', () => {
356
+ it('should classify files with -service.ts pattern as service-file', () => {
357
+ const node = createNode({
358
+ file: 'src/services/email-service.ts',
359
+ exports: [
360
+ { name: 'EmailService', type: 'class', inferredDomain: 'email' },
361
+ ],
362
+ imports: ['../utils/smtp', '../templates'],
363
+ linesOfCode: 200,
364
+ });
365
+
366
+ const classification = classifyFile(node, 0.07, ['email', 'smtp', 'templates']);
367
+ expect(classification).toBe('service-file');
368
+ });
369
+
370
+ it('should classify files in services directory as service-file', () => {
371
+ const node = createNode({
372
+ file: 'src/services/notification.ts',
373
+ exports: [
374
+ { name: 'sendNotification', type: 'function', inferredDomain: 'notification' },
375
+ { name: 'queueNotification', type: 'function', inferredDomain: 'notification' },
376
+ ],
377
+ imports: ['../db', '../email'],
378
+ linesOfCode: 120,
379
+ });
380
+
381
+ const classification = classifyFile(node, 0.35, ['notification']);
382
+ expect(classification).toBe('service-file');
383
+ });
384
+
385
+ it('should classify class exports in services directory as service-file', () => {
386
+ const node = createNode({
387
+ file: 'src/api/user-service.ts',
388
+ exports: [
389
+ { name: 'UserService', type: 'class', inferredDomain: 'user' },
390
+ ],
391
+ imports: ['../db', '../auth'],
392
+ linesOfCode: 180,
393
+ });
394
+
395
+ const classification = classifyFile(node, 0.25, ['user']);
396
+ expect(classification).toBe('service-file');
397
+ });
398
+ });
399
+
400
+ describe('email-template detection', () => {
401
+ it('should classify receipt-writer files as email-template', () => {
402
+ const node = createNode({
403
+ file: 'src/emails/receipt-writer.ts',
404
+ exports: [
405
+ { name: 'generateReceipt', type: 'function', inferredDomain: 'receipt' },
406
+ ],
407
+ imports: ['../templates/base', '../services/db'],
408
+ linesOfCode: 150,
409
+ });
410
+
411
+ const classification = classifyFile(node, 0.08, ['receipt', 'templates', 'db']);
412
+ expect(classification).toBe('email-template');
413
+ });
414
+
415
+ it('should classify files in emails directory as email-template', () => {
416
+ const node = createNode({
417
+ file: 'src/emails/welcome.ts',
418
+ exports: [
419
+ { name: 'renderWelcomeEmail', type: 'function', inferredDomain: 'email' },
420
+ ],
421
+ imports: ['../templates/layout'],
422
+ linesOfCode: 80,
423
+ });
424
+
425
+ const classification = classifyFile(node, 0.15, ['email']);
426
+ expect(classification).toBe('email-template');
427
+ });
428
+
429
+ it('should classify files with template patterns as email-template', () => {
430
+ const node = createNode({
431
+ file: 'src/templates/invoice-template.ts',
432
+ exports: [
433
+ { name: 'renderInvoice', type: 'function', inferredDomain: 'invoice' },
434
+ ],
435
+ imports: ['../services/pdf'],
436
+ linesOfCode: 100,
437
+ });
438
+
439
+ const classification = classifyFile(node, 0.20, ['invoice']);
440
+ expect(classification).toBe('email-template');
441
+ });
442
+ });
443
+
444
+ describe('parser-file detection', () => {
445
+ it('should classify parser files correctly', () => {
446
+ const node = createNode({
447
+ file: 'src/parsers/base-parser-deterministic.ts',
448
+ exports: [
449
+ { name: 'parseDeterministic', type: 'function', inferredDomain: 'parse' },
450
+ { name: 'parseNonDeterministic', type: 'function', inferredDomain: 'parse' },
451
+ ],
452
+ imports: ['../utils/transform'],
453
+ linesOfCode: 120,
454
+ });
455
+
456
+ const classification = classifyFile(node, 0.15, ['parse']);
457
+ expect(classification).toBe('parser-file');
458
+ });
459
+
460
+ it('should classify files with parser in name as parser-file', () => {
461
+ const node = createNode({
462
+ file: 'src/parsers/data-parser.ts',
463
+ exports: [
464
+ { name: 'parseData', type: 'function', inferredDomain: 'data' },
465
+ { name: 'transformData', type: 'function', inferredDomain: 'data' },
466
+ ],
467
+ imports: [],
468
+ linesOfCode: 90,
469
+ });
470
+
471
+ const classification = classifyFile(node, 0.25, ['data']);
472
+ expect(classification).toBe('parser-file');
473
+ });
474
+
475
+ it('should classify converter files as parser-file', () => {
476
+ const node = createNode({
477
+ file: 'src/converters/xml-converter.ts',
478
+ exports: [
479
+ { name: 'convertXmlToJson', type: 'function', inferredDomain: 'xml' },
480
+ { name: 'convertJsonToXml', type: 'function', inferredDomain: 'xml' },
481
+ ],
482
+ imports: ['xml2js'],
483
+ linesOfCode: 60,
484
+ });
485
+
486
+ const classification = classifyFile(node, 0.30, ['xml']);
487
+ expect(classification).toBe('parser-file');
488
+ });
489
+ });
490
+
491
+ describe('utility-module detection', () => {
492
+ it('should classify dynamodb-utils.ts as utility-module', () => {
493
+ const node = createNode({
494
+ file: 'src/utils/dynamodb-utils.ts',
495
+ exports: [
496
+ { name: 'getItem', type: 'function', inferredDomain: 'db' },
497
+ { name: 'putItem', type: 'function', inferredDomain: 'db' },
498
+ { name: 'queryItems', type: 'function', inferredDomain: 'db' },
499
+ ],
500
+ imports: ['aws-sdk'],
501
+ linesOfCode: 100,
502
+ });
503
+
504
+ const classification = classifyFile(node, 0.21, ['db']);
505
+ expect(classification).toBe('utility-module');
506
+ });
507
+
508
+ it('should classify s3-utils.ts as utility-module', () => {
509
+ const node = createNode({
510
+ file: 'src/utils/s3-utils.ts',
511
+ exports: [
512
+ { name: 'uploadFile', type: 'function', inferredDomain: 's3' },
513
+ { name: 'downloadFile', type: 'function', inferredDomain: 's3' },
514
+ { name: 'deleteFile', type: 'function', inferredDomain: 's3' },
515
+ ],
516
+ imports: ['aws-sdk'],
517
+ linesOfCode: 80,
518
+ });
519
+
520
+ const classification = classifyFile(node, 0.26, ['s3']);
521
+ expect(classification).toBe('utility-module');
522
+ });
523
+
524
+ it('should classify files ending with -utils.ts as utility-module', () => {
525
+ const node = createNode({
526
+ file: 'src/helpers/date-utils.ts',
527
+ exports: [
528
+ { name: 'formatDate', type: 'function', inferredDomain: 'date' },
529
+ { name: 'validateDate', type: 'function', inferredDomain: 'date' },
530
+ ],
531
+ imports: [],
532
+ linesOfCode: 50,
533
+ });
534
+
535
+ const classification = classifyFile(node, 0.30, ['date']);
536
+ expect(classification).toBe('utility-module');
537
+ });
538
+ });
539
+
540
+ describe('session file detection', () => {
541
+ it('should classify session.ts as cohesive-module', () => {
542
+ const node = createNode({
543
+ file: 'src/session.ts',
544
+ exports: [
545
+ { name: 'createSession', type: 'function', inferredDomain: 'session' },
546
+ { name: 'getSession', type: 'function', inferredDomain: 'session' },
547
+ { name: 'destroySession', type: 'function', inferredDomain: 'session' },
548
+ ],
549
+ imports: ['../db', '../auth'],
550
+ linesOfCode: 100,
551
+ });
552
+
553
+ const classification = classifyFile(node, 0.26, ['session']);
554
+ expect(classification).toBe('cohesive-module');
555
+ });
556
+ });
557
+ });
558
+
559
+ describe('adjustCohesionForClassification', () => {
560
+ it('should return 1 for barrel exports', () => {
561
+ const result = adjustCohesionForClassification(0.3, 'barrel-export');
562
+ expect(result).toBe(1);
563
+ });
564
+
565
+ it('should return 1 for type definitions', () => {
566
+ const result = adjustCohesionForClassification(0.2, 'type-definition');
567
+ expect(result).toBe(1);
568
+ });
569
+
570
+ it('should boost cohesion for utility modules', () => {
571
+ const result = adjustCohesionForClassification(0.21, 'utility-module');
572
+ expect(result).toBeGreaterThan(0.21);
573
+ expect(result).toBeLessThanOrEqual(1);
574
+ });
575
+
576
+ it('should boost cohesion for service files', () => {
577
+ const result = adjustCohesionForClassification(0.07, 'service-file');
578
+ expect(result).toBeGreaterThan(0.07);
579
+ expect(result).toBeLessThanOrEqual(1);
580
+ });
581
+
582
+ it('should boost cohesion for lambda handlers', () => {
583
+ const result = adjustCohesionForClassification(0.21, 'lambda-handler');
584
+ expect(result).toBeGreaterThan(0.21);
585
+ expect(result).toBeLessThanOrEqual(1);
586
+ });
587
+
588
+ it('should boost cohesion for email templates', () => {
589
+ const result = adjustCohesionForClassification(0.08, 'email-template');
590
+ expect(result).toBeGreaterThan(0.08);
591
+ expect(result).toBeLessThanOrEqual(1);
592
+ });
593
+
594
+ it('should boost cohesion for parser files', () => {
595
+ const result = adjustCohesionForClassification(0.15, 'parser-file');
596
+ expect(result).toBeGreaterThan(0.15);
597
+ expect(result).toBeLessThanOrEqual(1);
598
+ });
599
+
600
+ it('should keep original cohesion for mixed-concerns', () => {
601
+ const result = adjustCohesionForClassification(0.3, 'mixed-concerns');
602
+ expect(result).toBe(0.3);
603
+ });
604
+
605
+ it('should boost cohesion for utility module with related export names', () => {
606
+ const node = createNode({
607
+ file: 'src/utils/dynamodb-utils.ts',
608
+ exports: [
609
+ { name: 'getItem', type: 'function', inferredDomain: 'db' },
610
+ { name: 'putItem', type: 'function', inferredDomain: 'db' },
611
+ { name: 'deleteItem', type: 'function', inferredDomain: 'db' },
612
+ ],
613
+ imports: ['aws-sdk'],
614
+ linesOfCode: 100,
615
+ });
616
+
617
+ // Related names (all Item operations) should get higher boost
618
+ const result = adjustCohesionForClassification(0.21, 'utility-module', node);
619
+ expect(result).toBeGreaterThan(0.5); // Significant boost for related names
620
+ });
621
+
622
+ it('should boost cohesion for lambda handler with single entry point', () => {
623
+ const node = createNode({
624
+ file: 'src/handlers/process.ts',
625
+ exports: [
626
+ { name: 'handler', type: 'function', inferredDomain: 'process' },
627
+ ],
628
+ imports: ['../services/queue'],
629
+ linesOfCode: 80,
630
+ });
631
+
632
+ // Single entry point should get higher boost
633
+ const result = adjustCohesionForClassification(0.22, 'lambda-handler', node);
634
+ expect(result).toBeGreaterThan(0.5); // Significant boost for single entry
635
+ });
636
+
637
+ it('should boost cohesion for class-based service files', () => {
638
+ const node = createNode({
639
+ file: 'src/services/email-service.ts',
640
+ exports: [
641
+ { name: 'EmailService', type: 'class', inferredDomain: 'email' },
642
+ ],
643
+ imports: ['../utils/smtp'],
644
+ linesOfCode: 200,
645
+ });
646
+
647
+ // Class-based service should get higher boost
648
+ const result = adjustCohesionForClassification(0.15, 'service-file', node);
649
+ expect(result).toBeGreaterThan(0.45); // Significant boost for class-based
650
+ });
651
+ });
652
+
653
+ describe('new classification recommendations', () => {
654
+ it('should provide utility-module recommendations', () => {
655
+ const recommendations = getClassificationRecommendations(
656
+ 'utility-module',
657
+ 'src/utils/helpers.ts',
658
+ ['Low cohesion']
659
+ );
660
+ expect(recommendations).toContain('Utility module detected - multiple domains are acceptable here');
661
+ });
662
+
663
+ it('should provide service-file recommendations', () => {
664
+ const recommendations = getClassificationRecommendations(
665
+ 'service-file',
666
+ 'src/services/email.ts',
667
+ ['Multiple domains']
668
+ );
669
+ expect(recommendations).toContain('Service file detected - orchestration of multiple dependencies is expected');
670
+ });
671
+
672
+ it('should provide lambda-handler recommendations', () => {
673
+ const recommendations = getClassificationRecommendations(
674
+ 'lambda-handler',
675
+ 'src/handlers/process.ts',
676
+ ['Low cohesion']
677
+ );
678
+ expect(recommendations).toContain('Lambda handler detected - coordination of services is expected');
679
+ });
680
+
681
+ it('should provide email-template recommendations', () => {
682
+ const recommendations = getClassificationRecommendations(
683
+ 'email-template',
684
+ 'src/emails/receipt.ts',
685
+ ['Multiple domains']
686
+ );
687
+ expect(recommendations).toContain('Email template detected - references multiple domains for rendering');
688
+ });
689
+
690
+ it('should provide parser-file recommendations', () => {
691
+ const recommendations = getClassificationRecommendations(
692
+ 'parser-file',
693
+ 'src/parsers/data.ts',
694
+ ['Multiple domains']
695
+ );
696
+ expect(recommendations).toContain('Parser/transformer file detected - handles multiple data sources');
697
+ });
698
+ });
699
+
700
+ describe('Next.js page detection', () => {
701
+ it('should classify Next.js calculator pages as nextjs-page', () => {
702
+ const node = createNode({
703
+ file: 'app/cents-per-km-calculator/page.tsx',
704
+ exports: [
705
+ { name: 'metadata', type: 'const', inferredDomain: 'seo' },
706
+ { name: 'faqJsonLd', type: 'const', inferredDomain: 'jsonld' },
707
+ { name: 'default', type: 'default', inferredDomain: 'page' },
708
+ { name: 'icon', type: 'const', inferredDomain: 'ui' },
709
+ ],
710
+ imports: ['../components/Calculator', '../lib/utils'],
711
+ linesOfCode: 208,
712
+ });
713
+
714
+ const classification = classifyFile(node, 0.25, ['seo', 'jsonld', 'page', 'ui']);
715
+ expect(classification).toBe('nextjs-page');
716
+ });
717
+
718
+ it('should classify investment property calculator page as nextjs-page', () => {
719
+ const node = createNode({
720
+ file: 'app/investment-property-tax-calculator/page.tsx',
721
+ exports: [
722
+ { name: 'metadata', type: 'const', inferredDomain: 'seo' },
723
+ { name: 'faqJsonLd', type: 'const', inferredDomain: 'jsonld' },
724
+ { name: 'default', type: 'default', inferredDomain: 'page' },
725
+ ],
726
+ imports: ['../components/Form'],
727
+ linesOfCode: 204,
728
+ });
729
+
730
+ const classification = classifyFile(node, 0.30, ['seo', 'jsonld', 'page']);
731
+ expect(classification).toBe('nextjs-page');
732
+ });
733
+
734
+ it('should not classify non-page.tsx files in /app/ as nextjs-page', () => {
735
+ const node = createNode({
736
+ file: 'app/components/Header.tsx',
737
+ exports: [
738
+ { name: 'Header', type: 'function', inferredDomain: 'ui' },
739
+ ],
740
+ imports: ['react'],
741
+ linesOfCode: 50,
742
+ });
743
+
744
+ const classification = classifyFile(node, 0.8, ['ui']);
745
+ expect(classification).toBe('cohesive-module');
746
+ });
747
+
748
+ it('should not classify page.tsx files outside /app/ as nextjs-page', () => {
749
+ const node = createNode({
750
+ file: 'src/pages/page.tsx', // Pages Router, not App Router
751
+ exports: [
752
+ { name: 'default', type: 'default', inferredDomain: 'page' },
753
+ ],
754
+ imports: ['react'],
755
+ linesOfCode: 100,
756
+ });
757
+
758
+ const classification = classifyFile(node, 0.5, ['page']);
759
+ expect(classification).not.toBe('nextjs-page');
760
+ });
761
+
762
+ it('should classify Next.js page with generateMetadata as nextjs-page', () => {
763
+ const node = createNode({
764
+ file: 'app/dynamic-page/page.tsx',
765
+ exports: [
766
+ { name: 'generateMetadata', type: 'function', inferredDomain: 'seo' },
767
+ { name: 'default', type: 'default', inferredDomain: 'page' },
768
+ ],
769
+ imports: ['../lib/api'],
770
+ linesOfCode: 150,
771
+ });
772
+
773
+ const classification = classifyFile(node, 0.4, ['seo', 'page']);
774
+ expect(classification).toBe('nextjs-page');
775
+ });
776
+ });
777
+
778
+ describe('nextjs-page cohesion adjustment', () => {
779
+ it('should return 1 for nextjs-page', () => {
780
+ const result = adjustCohesionForClassification(0.25, 'nextjs-page');
781
+ expect(result).toBe(1);
782
+ });
783
+ });
784
+
785
+ describe('nextjs-page fragmentation adjustment', () => {
786
+ it('should reduce fragmentation by 80% for nextjs-page', () => {
787
+ const result = adjustFragmentationForClassification(0.5, 'nextjs-page');
788
+ expect(result).toBe(0.1); // 0.5 * 0.2
789
+ });
790
+ });
791
+
792
+ describe('nextjs-page recommendations', () => {
793
+ it('should provide nextjs-page recommendations', () => {
794
+ const recommendations = getClassificationRecommendations(
795
+ 'nextjs-page',
796
+ 'app/calculator/page.tsx',
797
+ ['Low cohesion']
798
+ );
799
+ expect(recommendations).toContain('Next.js App Router page detected - metadata/JSON-LD/component pattern is cohesive');
800
+ });
801
+ });
802
+ });