-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomprehensive-test.js
More file actions
executable file
·118 lines (103 loc) · 4.08 KB
/
Copy pathcomprehensive-test.js
File metadata and controls
executable file
·118 lines (103 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env node
/**
* Comprehensive test suite for timestamp stability patch
*
* Tests various timestamp inconsistency scenarios:
* - Future modification times
* - Future access times
* - Inconsistent timestamp ordering
* - Normal timestamps (control case)
*/
const fs = require('fs');
/**
* Test cases covering different timestamp problems
*/
const testCases = [
{
name: 'Future mtime',
description: 'File with modification time in the future',
setup: (file) => {
const future = new Date('2030-01-01');
const now = new Date();
fs.utimesSync(file, now, future); // atime=now, mtime=future
}
},
{
name: 'Future atime',
description: 'File with access time in the future',
setup: (file) => {
const future = new Date('2030-01-01');
const now = new Date();
fs.utimesSync(file, future, now); // atime=future, mtime=now
}
},
{
name: 'mtime newer than atime',
description: 'File with modification time significantly newer than access time',
setup: (file) => {
const old = new Date(Date.now() - 10000); // 10 seconds ago
const newer = new Date(Date.now() - 5000); // 5 seconds ago
fs.utimesSync(file, old, newer); // atime=old, mtime=newer
}
},
{
name: 'Normal timestamps',
description: 'File with consistent, current timestamps (control case)',
setup: (file) => {
const now = new Date();
fs.utimesSync(file, now, now); // Both current time
}
}
];
/**
* Run a single test case
* @param {Object} testCase - The test case configuration
*/
function runTestCase(testCase) {
console.log(`\n=== ${testCase.name} ===`);
console.log(`Description: ${testCase.description}`);
const testFile = `/tmp/timestamp-test-${testCase.name.replace(/\s+/g, '-').toLowerCase()}.txt`;
try {
// Create and setup test file
fs.writeFileSync(testFile, `Test content for: ${testCase.name}`);
testCase.setup(testFile);
console.log('\nBefore patch:');
const statsBefore = fs.statSync(testFile);
console.log(` atime: ${statsBefore.atime}`);
console.log(` mtime: ${statsBefore.mtime}`);
console.log(` Future mtime: ${statsBefore.mtime > new Date() ? 'YES' : 'no'}`);
console.log(` Future atime: ${statsBefore.atime > new Date() ? 'YES' : 'no'}`);
console.log(` mtime > atime: ${statsBefore.mtime > statsBefore.atime ? 'YES' : 'no'}`);
// Load the timestamp stability patch
require('./fix-timestamps.js');
console.log('\nAfter patch:');
const statsAfter = fs.statSync(testFile);
console.log(` atime: ${statsAfter.atime}`);
console.log(` mtime: ${statsAfter.mtime}`);
console.log(` Future mtime: ${statsAfter.mtime > new Date() ? 'YES' : 'no'}`);
console.log(` Future atime: ${statsAfter.atime > new Date() ? 'YES' : 'no'}`);
console.log(` mtime > atime: ${statsAfter.mtime > statsAfter.atime ? 'YES' : 'no'}`);
// Validate fix worked as expected
const hasIssues = statsAfter.mtime > new Date() ||
statsAfter.atime > new Date() ||
(statsAfter.mtime.getTime() - statsAfter.atime.getTime()) > 1000;
console.log(`\nResult: ${hasIssues ? '❌ STILL HAS ISSUES' : '✅ FIXED'}`);
} catch (error) {
console.error(`❌ Test failed: ${error.message}`);
} finally {
// Clean up test file
try {
if (fs.existsSync(testFile)) {
fs.unlinkSync(testFile);
}
} catch (cleanupError) {
console.error(`Cleanup warning: ${cleanupError.message}`);
}
}
}
// Run all test cases
console.log('Starting comprehensive timestamp stability tests...\n');
testCases.forEach(runTestCase);
console.log('\n' + '='.repeat(50));
console.log('🏁 All comprehensive tests completed!');
console.log('='.repeat(50));