/ scripts / test-deduplication.js
test-deduplication.js
 1  /**
 2   * Manual test script for human review queue deduplication
 3   */
 4  
 5  import { addReviewItem, getPendingReviews } from '../src/utils/human-review-queue.js';
 6  
 7  console.log('Testing deduplication...\n');
 8  
 9  // Get initial count
10  const before = getPendingReviews();
11  console.log(`Before: ${before.length} pending reviews`);
12  
13  if (before.length > 0) {
14    console.log('\nExisting pending reviews:');
15    before.forEach(r => {
16      console.log(`  - ${r.file} (${r.type}): ${(r.reason ?? '').substring(0, 60)}...`);
17    });
18  }
19  
20  // Try to add a duplicate (file+type already exists)
21  console.log('\nAttempting to add duplicate "Test Coverage" + "test"...');
22  addReviewItem({
23    file: 'Test Coverage',
24    reason: 'Test coverage is now 99.9% (UPDATED)',
25    type: 'test',
26    priority: 'low',
27  });
28  
29  const after = getPendingReviews();
30  console.log(`\nAfter adding duplicate: ${after.length} pending reviews`);
31  
32  if (after.length === before.length) {
33    console.log('✓ Count unchanged - existing item was updated instead of creating duplicate!\n');
34  } else {
35    console.log('✗ Count increased - duplicate was created!\n');
36  }
37  
38  // Check if the reason was updated
39  const testItem = after.find(r => r.file === 'Test Coverage' && r.type === 'test');
40  if (testItem) {
41    console.log('Test Coverage item details:');
42    console.log(`  Reason: ${testItem.reason}`);
43    console.log(`  Priority: ${testItem.priority}`);
44  
45    if (testItem.reason.includes('UPDATED')) {
46      console.log('\n✅ Deduplication working correctly - existing item was updated!');
47    }
48  }
49  
50  // Test adding a different type for the same file (should be allowed)
51  console.log('\n---\nTesting different type for same file...');
52  addReviewItem({
53    file: 'Test Coverage',
54    reason: 'Security vulnerability detected in test coverage tool',
55    type: 'security',
56    priority: 'high',
57  });
58  
59  const afterDifferentType = getPendingReviews();
60  console.log(`After adding different type: ${afterDifferentType.length} pending reviews`);
61  
62  if (afterDifferentType.length === before.length + 1) {
63    console.log('✅ Different type allowed - created new item as expected!');
64  } else {
65    console.log('✗ Unexpected behavior with different type');
66  }
67  
68  console.log('\nFinal pending reviews:');
69  afterDifferentType.forEach(r => {
70    console.log(`  - ${r.file} (${r.type}, priority: ${r.priority})`);
71  });