@karaplay/file-coder 1.5.0 → 1.5.2

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.
@@ -0,0 +1,456 @@
1
+ # EMK Test Suite - Duration Verification System
2
+
3
+ **Version:** 1.5.1+
4
+ **Created:** 2026-01-13
5
+
6
+ ## 📋 Overview
7
+
8
+ This test suite provides automated verification for EMK to KAR conversions, ensuring duration accuracy, tempo ratio correctness, and consistency across library updates.
9
+
10
+ ---
11
+
12
+ ## 🚀 Quick Start
13
+
14
+ ### Run All Tests
15
+
16
+ ```bash
17
+ npm run test:emk
18
+ ```
19
+
20
+ **Output:**
21
+ ```
22
+ ✅ Passed: 9/9
23
+ âš ī¸ Warnings: 0/9
24
+ ❌ Failed: 0/9
25
+
26
+ 🎉 All tests passed!
27
+ ```
28
+
29
+ ### Run with Verbose Output
30
+
31
+ ```bash
32
+ npm run test:emk:verbose
33
+ ```
34
+
35
+ Shows detailed information for each test including tempo, duration, and format.
36
+
37
+ ### Test Specific File
38
+
39
+ ```bash
40
+ node verify-emk-reference.js --file=001.emk
41
+ ```
42
+
43
+ ---
44
+
45
+ ## 📁 Files in This Suite
46
+
47
+ ### 1. **EMK_REFERENCE_DATA.json**
48
+
49
+ Reference data for all EMK files containing:
50
+ - Expected tempo and duration
51
+ - Format (ZXIO/MThd)
52
+ - Tempo ratio
53
+ - Track/note counts
54
+ - Generated timestamp
55
+
56
+ **Example:**
57
+ ```json
58
+ {
59
+ "filename": "001.emk",
60
+ "status": "success",
61
+ "title": "ā¸„ā¸™ā¸ā¸Ŗā¸°ā¸ˆā¸­ā¸",
62
+ "artist": "ā¸šā¸¸āšŠā¸„ ā¸¨ā¸¸ā¸ ā¸ā¸˛ā¸ā¸ˆā¸™āšŒ",
63
+ "format": "ZXIO",
64
+ "karTempo": 79.36,
65
+ "tempoRatio": 1.24,
66
+ "expectedRatio": 1.24,
67
+ "duration": 283.52,
68
+ "durationFormatted": "4:43"
69
+ }
70
+ ```
71
+
72
+ ### 2. **verify-emk-reference.js**
73
+
74
+ Main test script that:
75
+ - Converts each EMK file
76
+ - Validates output against reference data
77
+ - Reports discrepancies
78
+
79
+ **Tolerance:**
80
+ - Duration: Âą2 seconds
81
+ - Tempo: Âą0.1 BPM
82
+ - Tempo Ratio: Âą0.1x
83
+
84
+ ### 3. **EMK_SONGS_INFO.md**
85
+
86
+ Documentation containing:
87
+ - Song information (title, artist, duration)
88
+ - Expected results for each file
89
+ - Format distribution statistics
90
+ - Troubleshooting guide
91
+ - Internet resources for verification
92
+
93
+ ---
94
+
95
+ ## 🔄 Workflow
96
+
97
+ ### When to Run Tests
98
+
99
+ 1. **After Library Updates**
100
+ ```bash
101
+ npm run test:emk
102
+ ```
103
+ Ensures new version doesn't break existing conversions.
104
+
105
+ 2. **After Tempo Logic Changes**
106
+ ```bash
107
+ npm run analyze:emk # Regenerate reference data
108
+ npm run test:emk # Verify against new reference
109
+ ```
110
+
111
+ 3. **Before npm Publish**
112
+ ```bash
113
+ npm run test:emk
114
+ ```
115
+ Ensure all conversions are stable.
116
+
117
+ 4. **When Adding New EMK Files**
118
+ ```bash
119
+ # Add files to songs/emk/
120
+ npm run analyze:emk # Update reference data
121
+ npm run test:emk # Verify
122
+ ```
123
+
124
+ ---
125
+
126
+ ## đŸŽ¯ Test Results Interpretation
127
+
128
+ ### ✅ PASS
129
+ ```
130
+ [1/9] Testing: 001.emk
131
+ ✅ PASS: All checks passed
132
+ ```
133
+ **Meaning:**
134
+ - Duration matches expected (Âą2s)
135
+ - Tempo matches expected (Âą0.1 BPM)
136
+ - Tempo ratio is correct
137
+ - Format is consistent
138
+
139
+ ### âš ī¸ WARNING
140
+ ```
141
+ [2/9] Testing: Z2510003.emk
142
+ âš ī¸ WARNING: 1 minor issue(s)
143
+ - Duration mismatch: expected 18.61s, got 20.15s (diff: 1.54s)
144
+ ```
145
+ **Meaning:**
146
+ - Minor discrepancy within acceptable range
147
+ - Non-critical issues (e.g., slight duration variance)
148
+ - Conversion still successful
149
+
150
+ ### ❌ FAIL
151
+ ```
152
+ [3/9] Testing: 500006.emk
153
+ ❌ FAIL: 1 issue(s) found
154
+ - Tempo ratio mismatch: expected 4x, got 8.00x
155
+ ```
156
+ **Meaning:**
157
+ - Significant discrepancy detected
158
+ - May indicate:
159
+ - Regression in tempo logic
160
+ - Incorrect reference data
161
+ - New file format variant
162
+
163
+ **Action:** Investigate and fix before publishing!
164
+
165
+ ---
166
+
167
+ ## 📊 Reference Data Structure
168
+
169
+ ### Generation
170
+
171
+ ```bash
172
+ npm run analyze:emk
173
+ ```
174
+
175
+ This script:
176
+ 1. Scans all `.emk` files in `songs/emk/`
177
+ 2. Converts each to KAR
178
+ 3. Extracts metadata (tempo, duration, format)
179
+ 4. Saves to `EMK_REFERENCE_DATA.json`
180
+
181
+ ### Manual Update (if needed)
182
+
183
+ ```javascript
184
+ // Load reference data
185
+ const ref = require('./EMK_REFERENCE_DATA.json');
186
+
187
+ // Update specific song
188
+ const song = ref.songs.find(s => s.filename === '001.emk');
189
+ song.duration = 283.52; // Update expected duration
190
+ song.expectedRatio = 1.24; // Update expected ratio
191
+
192
+ // Save
193
+ fs.writeFileSync('EMK_REFERENCE_DATA.json',
194
+ JSON.stringify(ref, null, 2));
195
+ ```
196
+
197
+ ---
198
+
199
+ ## đŸ§Ē Test Examples
200
+
201
+ ### Example 1: All Tests Pass
202
+
203
+ ```bash
204
+ $ npm run test:emk
205
+
206
+ ✅ Passed: 9/9
207
+ âš ī¸ Warnings: 0/9
208
+ ❌ Failed: 0/9
209
+
210
+ 🎉 All tests passed!
211
+ ```
212
+
213
+ **Meaning:** All conversions match reference data. ✅ Safe to publish!
214
+
215
+ ---
216
+
217
+ ### Example 2: One Test Fails
218
+
219
+ ```bash
220
+ $ npm run test:emk
221
+
222
+ ✅ Passed: 8/9
223
+ âš ī¸ Warnings: 0/9
224
+ ❌ Failed: 1/9
225
+
226
+ ❌ Some tests failed. Review the output above.
227
+
228
+ Failed files:
229
+ - Z2510003.emk
230
+ Tempo ratio mismatch: expected 4x, got 8.00x
231
+ ```
232
+
233
+ **Action Steps:**
234
+
235
+ 1. **Investigate the file:**
236
+ ```bash
237
+ node verify-emk-reference.js --verbose --file=Z2510003.emk
238
+ ```
239
+
240
+ 2. **Check if reference data is wrong:**
241
+ - If actual ratio (8x) is correct, update reference data
242
+ - Run `npm run analyze:emk` to regenerate
243
+
244
+ 3. **Check if conversion is wrong:**
245
+ - Review tempo logic in `src/ncntokar.ts`
246
+ - Fix and rebuild: `npm run build`
247
+ - Re-test: `npm run test:emk`
248
+
249
+ ---
250
+
251
+ ## 🔍 Debugging Failed Tests
252
+
253
+ ### Step 1: Run Verbose Test
254
+
255
+ ```bash
256
+ node verify-emk-reference.js --verbose --file=FAILED_FILE.emk
257
+ ```
258
+
259
+ **Output:**
260
+ ```
261
+ [1/1] Testing: FAILED_FILE.emk
262
+ Reference: Song Title - Artist Name
263
+ Expected Duration: 4:43 (283.52s)
264
+ Expected Tempo: 79.36 BPM
265
+
266
+ ❌ FAIL: 1 issue(s) found
267
+ - Duration mismatch: expected 283.52s, got 290.00s (diff: 6.48s)
268
+ ```
269
+
270
+ ### Step 2: Manual Conversion
271
+
272
+ ```bash
273
+ node -e "
274
+ const { convertEmkToKar, validateKarTempo } = require('./dist/index.js');
275
+ const fs = require('fs');
276
+
277
+ convertEmkToKar({
278
+ inputEmk: 'songs/emk/FAILED_FILE.emk',
279
+ outputKar: 'temp/debug.kar'
280
+ });
281
+
282
+ const karBuffer = fs.readFileSync('temp/debug.kar');
283
+ const validation = validateKarTempo(karBuffer);
284
+
285
+ console.log('Tempo:', validation.tempo);
286
+ console.log('Duration:', validation.duration);
287
+ console.log('Warnings:', validation.warnings);
288
+ console.log('Errors:', validation.errors);
289
+ "
290
+ ```
291
+
292
+ ### Step 3: Compare with Original
293
+
294
+ ```bash
295
+ # Check original EMK
296
+ node -e "
297
+ const { decodeEmkServer } = require('./dist/index.js');
298
+ const { Midi } = require('@tonejs/midi');
299
+ const fs = require('fs');
300
+
301
+ const emkBuffer = fs.readFileSync('songs/emk/FAILED_FILE.emk');
302
+ const decoded = decodeEmkServer(emkBuffer);
303
+ const midi = new Midi(decoded.midi);
304
+
305
+ console.log('EMK Tempo:', midi.header.tempos[0].bpm);
306
+ console.log('EMK Duration:', midi.duration);
307
+ console.log('Format:', decoded.isZxioFormat ? 'ZXIO' : 'MThd');
308
+ "
309
+ ```
310
+
311
+ ---
312
+
313
+ ## 📈 Statistics & Reporting
314
+
315
+ ### Generate Report
316
+
317
+ ```bash
318
+ npm run test:emk > test-report.txt
319
+ ```
320
+
321
+ ### View Summary Statistics
322
+
323
+ ```javascript
324
+ const ref = require('./EMK_REFERENCE_DATA.json');
325
+
326
+ console.log('Total Files:', ref.totalFiles);
327
+ console.log('Successful:', ref.successful);
328
+ console.log('Failed:', ref.failed);
329
+ console.log('Success Rate:',
330
+ `${(ref.successful / ref.totalFiles * 100).toFixed(1)}%`);
331
+
332
+ // Format distribution
333
+ const formats = {};
334
+ ref.songs.forEach(s => {
335
+ if (s.status === 'success') {
336
+ formats[s.format] = (formats[s.format] || 0) + 1;
337
+ }
338
+ });
339
+ console.log('Formats:', formats);
340
+ // → { ZXIO: 3, MThd: 6 }
341
+ ```
342
+
343
+ ---
344
+
345
+ ## 🎓 Best Practices
346
+
347
+ ### 1. Run Tests Before Publishing
348
+
349
+ ```bash
350
+ npm run build
351
+ npm test
352
+ npm run test:emk # ← DON'T FORGET THIS!
353
+ npm publish
354
+ ```
355
+
356
+ ### 2. Keep Reference Data Updated
357
+
358
+ ```bash
359
+ # After fixing tempo logic
360
+ npm run build
361
+ npm run analyze:emk # Regenerate reference
362
+ npm run test:emk # Should all pass now
363
+ ```
364
+
365
+ ### 3. Document Changes
366
+
367
+ When updating reference data, document why:
368
+ ```json
369
+ {
370
+ "_comment": "Updated Z2510003.emk ratio from 4x to 8x (2026-01-13)",
371
+ "filename": "Z2510003.emk",
372
+ "expectedRatio": 8.0
373
+ }
374
+ ```
375
+
376
+ ### 4. Verify Against Real Songs
377
+
378
+ For critical files (e.g., 001.emk):
379
+ - Find song on YouTube/Spotify
380
+ - Verify actual duration matches converted duration
381
+ - Document source: `"_realDuration": "4:45 (YouTube)"`
382
+
383
+ ---
384
+
385
+ ## 🔧 Maintenance
386
+
387
+ ### Monthly Tasks
388
+
389
+ 1. **Re-verify all conversions:**
390
+ ```bash
391
+ npm run test:emk
392
+ ```
393
+
394
+ 2. **Update documentation if needed:**
395
+ - Check for new EMK format variants
396
+ - Update `EMK_SONGS_INFO.md`
397
+
398
+ 3. **Check for library dependency updates:**
399
+ ```bash
400
+ npm outdated
401
+ # Especially @tonejs/midi
402
+ ```
403
+
404
+ ### When Tests Start Failing
405
+
406
+ 1. **Don't panic!** - Check if it's:
407
+ - Regression (fix code)
408
+ - Expected change (update reference)
409
+ - New file format (extend decoder)
410
+
411
+ 2. **Investigate systematically:**
412
+ ```bash
413
+ # Step 1: Identify failing files
414
+ npm run test:emk
415
+
416
+ # Step 2: Debug specific file
417
+ node verify-emk-reference.js --verbose --file=FAILED.emk
418
+
419
+ # Step 3: Compare with previous version
420
+ git diff EMK_REFERENCE_DATA.json
421
+ ```
422
+
423
+ 3. **Fix and verify:**
424
+ ```bash
425
+ # After fix
426
+ npm run build
427
+ npm run test:emk
428
+ ```
429
+
430
+ ---
431
+
432
+ ## 📚 Related Documentation
433
+
434
+ - **[README.md](./README.md)** - Main library documentation
435
+ - **[EMK_SONGS_INFO.md](./EMK_SONGS_INFO.md)** - Song information & expected results
436
+ - **[TEMPO_TRICKS_SUMMARY.md](./TEMPO_TRICKS_SUMMARY.md)** - Tempo handling best practices
437
+ - **[RELEASE_v1.5.1.md](./RELEASE_v1.5.1.md)** - Validation utilities release notes
438
+
439
+ ---
440
+
441
+ ## ✅ Success Criteria
442
+
443
+ A test suite is working correctly when:
444
+
445
+ - ✅ `npm run test:emk` passes with 0 failures
446
+ - ✅ All ZXIO files use 1.24x ratio
447
+ - ✅ All MThd files use 4x, 8x, or 20x ratios
448
+ - ✅ Durations match expected (±2s)
449
+ - ✅ Reference data is up-to-date
450
+ - ✅ No regressions after updates
451
+
452
+ ---
453
+
454
+ **Last Updated:** 2026-01-13
455
+ **Maintainer:** @karaplay/file-coder
456
+ **Status:** ✅ Production Ready
@@ -0,0 +1,197 @@
1
+ ================================================================================
2
+ EMK TEST SUITE SUMMARY
3
+ ================================================================================
4
+
5
+ Created: 2026-01-13
6
+ Version: 1.5.1+
7
+ Purpose: Automated duration verification for EMK to KAR conversions
8
+
9
+ ================================================================================
10
+ FILES CREATED
11
+ ================================================================================
12
+
13
+ 1. EMK_REFERENCE_DATA.json
14
+ - Reference data for 11 EMK files
15
+ - Contains: tempo, duration, format, ratio for each song
16
+ - Auto-generated from actual conversions
17
+ - Used as baseline for regression testing
18
+
19
+ 2. verify-emk-reference.js
20
+ - Main test script
21
+ - Converts EMK → KAR and compares with reference
22
+ - Reports: PASS / WARNING / FAIL
23
+ - Supports --verbose and --file=<filename> flags
24
+
25
+ 3. EMK_SONGS_INFO.md
26
+ - Human-readable song information
27
+ - Expected results for each file
28
+ - Internet resources for verification
29
+ - Statistics and troubleshooting guide
30
+
31
+ 4. EMK_TEST_SUITE_README.md
32
+ - Complete usage guide
33
+ - Examples and best practices
34
+ - Debugging workflows
35
+ - Maintenance procedures
36
+
37
+ ================================================================================
38
+ TEST RESULTS
39
+ ================================================================================
40
+
41
+ Total EMK Files: 11
42
+ Successfully Converted: 9 (82%)
43
+ Failed to Convert: 2 (18%)
44
+
45
+ TEST BREAKDOWN:
46
+ ✅ PASS: 9/9 successful conversions verified
47
+ âš ī¸ WARNING: 0/9 minor issues
48
+ ❌ FAIL: 0/9 critical issues
49
+
50
+ FAILED FILES (cannot convert):
51
+ - 500006.emk: MIDI data block not found
52
+ - f0000001.emk: Conversion error (undefined)
53
+
54
+ ================================================================================
55
+ FORMAT DISTRIBUTION
56
+ ================================================================================
57
+
58
+ ZXIO Format: 3 files (27%)
59
+ - Ratio: 1.24x (ticksPerBeat / 77.42)
60
+ - Files: 001.emk, 001_original_emk.emk, failed01.emk
61
+
62
+ MThd Format: 6 files (55%)
63
+ - 4x ratio: 4 files (Z2510001, Z2510002, Z2510004, Z2510005)
64
+ - 8x ratio: 1 file (Z2510003)
65
+ - 20x ratio: 1 file (Z2510006)
66
+
67
+ ================================================================================
68
+ NPM SCRIPTS
69
+ ================================================================================
70
+
71
+ npm run test:emk Run all EMK conversion tests
72
+ npm run test:emk:verbose Run with detailed output
73
+ npm run analyze:emk Regenerate reference data
74
+
75
+ ================================================================================
76
+ EXAMPLE USAGE
77
+ ================================================================================
78
+
79
+ # Run all tests
80
+ $ npm run test:emk
81
+
82
+ Output:
83
+ ✅ Passed: 9/9
84
+ âš ī¸ Warnings: 0/9
85
+ ❌ Failed: 0/9
86
+ 🎉 All tests passed!
87
+
88
+ # Test specific file
89
+ $ node verify-emk-reference.js --file=001.emk
90
+
91
+ [1/1] Testing: 001.emk
92
+ ✅ PASS: All checks passed
93
+
94
+ # Regenerate reference data
95
+ $ npm run analyze:emk
96
+
97
+ Found 11 EMK files
98
+ ...
99
+ 💾 Reference data saved to: EMK_REFERENCE_DATA.json
100
+
101
+ ================================================================================
102
+ KEY INSIGHTS
103
+ ================================================================================
104
+
105
+ 1. DURATION ACCURACY
106
+ - ZXIO files (e.g., 001.emk): 4:43 duration ✅
107
+ - Matches real song (YouTube: ~4:45) ✅
108
+ - Within ±2 second tolerance ✅
109
+
110
+ 2. TEMPO RATIOS
111
+ - 1.24x for ZXIO (v1.5.0 fix from 2.78x) ✅
112
+ - 4x for standard MThd ✅
113
+ - 8x and 20x for special MThd variants ✅
114
+
115
+ 3. TEST COVERAGE
116
+ - All successful conversions verified
117
+ - Reference data auto-generated
118
+ - Regression tests automated
119
+ - CI/CD ready
120
+
121
+ ================================================================================
122
+ VALIDATION CHECKLIST
123
+ ================================================================================
124
+
125
+ Before publishing new version:
126
+ ☑ Run: npm run build
127
+ ☑ Run: npm test
128
+ ☑ Run: npm run test:emk
129
+ ☑ Verify: All tests pass (9/9)
130
+ ☑ Check: Duration accuracy within ±2s
131
+ ☑ Verify: Tempo ratios correct
132
+ ☑ Update: Reference data if needed
133
+ ☑ Document: Changes in release notes
134
+
135
+ ================================================================================
136
+ MAINTENANCE
137
+ ================================================================================
138
+
139
+ WHEN TO UPDATE REFERENCE DATA:
140
+ 1. After changing tempo logic in src/ncntokar.ts
141
+ 2. After adding new EMK files to songs/emk/
142
+ 3. After fixing bugs that affect duration/tempo
143
+ 4. When expected ratios change
144
+
145
+ HOW TO UPDATE:
146
+ $ npm run analyze:emk
147
+ $ npm run test:emk # Should all pass
148
+
149
+ WHEN TO RUN TESTS:
150
+ 1. Before every npm publish
151
+ 2. After library updates
152
+ 3. When debugging conversion issues
153
+ 4. Monthly verification (best practice)
154
+
155
+ ================================================================================
156
+ STATISTICS
157
+ ================================================================================
158
+
159
+ Duration Range:
160
+ Min: 0:12 (Z2510006.emk)
161
+ Max: 4:43 (001.emk)
162
+ Avg: 1:18 (78 seconds)
163
+
164
+ Tempo Ratio Distribution:
165
+ 1.24x: 33% (3 files - ZXIO)
166
+ 4.00x: 44% (4 files - MThd standard)
167
+ 8.00x: 11% (1 file - MThd rare)
168
+ 20.0x: 11% (1 file - MThd very rare)
169
+
170
+ Success Rate:
171
+ Conversion: 82% (9/11 files)
172
+ Verification: 100% (9/9 successful conversions pass tests)
173
+
174
+ ================================================================================
175
+ DOCUMENTATION LINKS
176
+ ================================================================================
177
+
178
+ 1. README.md - Main library documentation
179
+ 2. EMK_SONGS_INFO.md - Song information & expected results
180
+ 3. EMK_TEST_SUITE_README.md - Complete test suite guide
181
+ 4. TEMPO_TRICKS_SUMMARY.md - Tempo handling best practices
182
+ 5. RELEASE_v1.5.1.md - Validation utilities release
183
+ 6. RELEASE_v1.5.0.md - ZXIO ratio fix (1.24x)
184
+
185
+ ================================================================================
186
+ STATUS
187
+ ================================================================================
188
+
189
+ ✅ Test Suite: Complete and Working
190
+ ✅ Reference Data: Generated and Verified
191
+ ✅ Documentation: Complete
192
+ ✅ NPM Scripts: Configured
193
+ ✅ Regression Tests: Automated
194
+
195
+ READY FOR PRODUCTION ✅
196
+
197
+ ================================================================================