-
-
Notifications
You must be signed in to change notification settings - Fork 1
testing guide
Guide to running and understanding CyberPatchMaker's comprehensive test suite.
CyberPatchMaker includes a comprehensive test suite with 61 tests (59 standard + 2 optional) that validate all core functionality including generation, application, verification, error handling, backup system, and advanced scenarios like multi-hop patching, bidirectional patching, downgrade testing, compression formats, and automatic rollback.
Key Feature: Test data is automatically generated on first run - no bloat files committed to the repository!
File: advanced-test.ps1
Shell: PowerShell 5.1 or later
Platform: Windows (PowerShell)
Tests: 61 comprehensive tests (59 standard + 2 optional)
Test Data: Auto-generated on first run (1.0.0, 1.0.1, 1.0.2)
Optional Test Flags: -run1gbtest, -runlargefile
Command Visibility: Shows exact command-line for each operation (displayed in cyan)
Bidirectional Testing: Includes upgrade/downgrade cycle verification
# Run the comprehensive test suite
.\advanced-test.ps1
# First run output (auto-generates test data):
Checking for test versions...
Version 1.0.0 not found, creating...
Creating version 1.0.0...
Version 1.0.0 created (3 files, 2 directories)
Version 1.0.1 not found, creating...
Creating version 1.0.1...
Version 1.0.1 created (4 files, 2 directories)
Version 1.0.2 not found, creating...
Creating version 1.0.2...
Version 1.0.2 created (11 files, 6 directories, 3 levels deep)
Created 3 test version(s)
# Then runs all tests with command visibility:
Running CyberPatchMaker Advanced Test Suite
========================================
Testing: Generate complex patch (1.0.1 → 1.0.2) with zstd
Generating patch from 1.0.1 to 1.0.2 with zstd compression...
Command: patch-gen.exe --versions-dir .\testdata\versions --from 1.0.1 --to 1.0.2 --output .\testdata\advanced-output\patches --compression zstd
Patch generated (zstd): 1627 bytes
✓ PASSED: Generate complex patch (1.0.1 → 1.0.2) with zstd
Testing: Apply zstd patch to complex directory structure
Copying version 1.0.1 to test-zstd...
Applying zstd patch...
Command: patch-apply.exe --patch .\testdata\advanced-output\patches\1.0.1-to-1.0.2.patch --current-dir .\testdata\advanced-output\test-zstd --verify
Zstd patch applied successfully
✓ PASSED: Apply zstd patch to complex directory structure
...
(All 61 tests with command visibility)
========================================
Advanced Test Results
========================================
Passed: 61
Failed: 0
✓ All advanced tests passed!
Would you like to clean up test data now? (Y/N): Y
Cleaning up test data...
✓ Test data removed successfullyNote: The test script automatically generates test versions on first run. Subsequent runs will use the existing test data unless you delete the testdata/versions/ directory.
The test suite includes an intelligent cleanup system to help manage test data:
Interactive Cleanup Prompt:
- After all tests complete, you'll be prompted to clean up test data
-
Press Y to immediately delete the
testdata/directory - Press N to keep test data for inspection
Auto-Delete Behavior:
- If you choose to keep test data (N), a
.cleanup-deferredstate file is created - On the next test run, the system automatically detects deferred cleanup
- Previous test data is automatically deleted before creating fresh test data
- This ensures clean test runs while giving you time to inspect results
Example Workflow:
# First run - Choose to keep data for inspection
.\advanced-test.ps1
# ... tests complete ...
# Would you like to clean up test data now? (Y/N): N
# Test data kept in testdata/ directory (cleanup deferred to next run)
# Inspect test data manually
ls testdata/versions/
ls testdata/patches/
# Second run - Auto cleanup of old data
.\advanced-test.ps1
# Previous test data detected (cleanup was deferred)...
# Removing old test data...
# ✓ Old test data removed
# ... tests run with fresh data ...
# Would you like to clean up test data now? (Y/N): Y
# Cleaning up test data...
# ✓ Test data removed successfullyState File:
-
Location:
testdata/.cleanup-deferred - Purpose: Tracks that cleanup was deferred
- Behavior: Triggers auto-delete on next run
- Cleanup: Automatically removed when test data is deleted
The advanced test suite includes 61 comprehensive tests organized into several categories:
- Verify executables exist - Confirms patch-gen.exe and patch-apply.exe build successfully
- Setup advanced test environment - Creates the test output directory structure
- Verify test versions exist - Confirms all three test versions (1.0.0, 1.0.1, 1.0.2) are present
- Generate complex patch (1.0.1 -> 1.0.2) with zstd - zstd compression
- Generate same patch with gzip compression - gzip compression
- Generate same patch with no compression - uncompressed
- Compare compression efficiency - Verify all three methods produce valid patches
- Dry-run complex patch application - Preview mode without changes
- Apply zstd patch to complex directory structure - Apply zstd-compressed patch
- Apply gzip patch to complex directory structure - Apply gzip-compressed patch
- Apply uncompressed patch to complex directory structure - Apply uncompressed patch
- Verify complex directory structure after patching - Verify file tree integrity
- Verify new files added in nested paths - Check added files in subdirectories
- Verify modified files match version 1.0.2 - Check modified files
- Verify all compression methods produce identical results - Cross-compression validation
- Test multi-hop patching scenario - Sequential patching (1.0.0 -> 1.0.1 -> 1.0.2)
- Generate downgrade patch (1.0.2 -> 1.0.1) - Downgrade patch generation
- Apply downgrade patch to revert version - Downgrade patch application
- Verify downgrade results match version 1.0.1 - Verify downgrade correctness
- Test bidirectional patching cycle - Complete upgrade/downgrade cycle
- Verify patch rejection for wrong source version - Wrong version rejection
- Verify detection of corrupted files in source - Corruption detection
- Verify backup creation and mirror structure - Backup with mirror directory structure
- Verify selective backup (only modified/deleted files) - Only changed files backed up
- Verify backup is preserved after successful patching - Backup preserved post-patch
- Verify manual rollback from backup works - Manual restore from backup
- Verify backup handles complex nested paths - Deep path backup 27b. Verify deleted directories are backed up with all contents - Deleted directory backup
- Verify patch generation performance - Speed benchmarking
- Test custom paths mode with different directories - Custom --from-dir/--to-dir
- Apply patch generated with custom paths mode - Apply custom paths patch
- Test custom paths with complex nested directories - Complex custom paths
- Verify version number extraction from directory names - Version from dir name
- Test compression options with custom paths - Compression with custom paths
- Test error handling for non-existent directories - Error handling
- Verify backward compatibility with legacy --versions-dir mode - Legacy mode
- Test CLI self-contained executable creation - --create-exe flag
- Verify CLI executable structure and header - Magic bytes verification
- Test batch mode with CLI executable creation - Batch exe creation
- Test 1GB bypass with large patch creation (optional: -run1gbtest) - Large patches
- Verify CLI executables use CLI applier - CLI applier verification
- Verify backup.cyberpatcher directories are excluded - Backup exclusion
- Verify .cyberignore file pattern matching - Cyberignore patterns
- Verify self-contained executable --silent flag for automation - Silent mode
- Verify silent mode generates timestamped log files - Log file generation
- Verify generator --silent flag embeds silent mode in created executables - Embedded silent
- Verify --crp flag creates reverse patches for downgrades - Reverse patches
- Verify scan cache basic functionality with --savescans - Cache creation
- Verify scan cache custom directory with --scandata - Custom cache dir
- Verify force rescan with --rescan flag - Force rescan
- Verify scan cache performance improvement - Performance comparison
- Verify scan cache works with custom paths mode - Cache + custom paths
- Verify scan cache file structure and content - Cache file validation
- Verify scan cache invalidation on file changes - Cache invalidation
- Verify Simple Mode struct field and encoding - SimpleMode field in Patch struct
- Verify runSimpleMode function exists - Simplified applier interface
- Verify Simple Mode workflow infrastructure - End-to-end (field exists, function callable)
- Verify Simple Mode documentation and feature completeness - Feature validation
- Verify Simple Mode addresses real-world use cases - Use case scenarios
Note: The SimpleMode field and runSimpleMode() function exist in the codebase but no generator code path currently sets SimpleMode = true. These tests verify the infrastructure exists.
- Verify .cyberignore absolute path pattern support - Absolute path patterns
- Verify large file chunked processing and memory optimization (optional: -runlargefile) - Chunked processing
Auto-generated test versions:
Version 1.0.0 (Baseline - 3 files, 2 directories):
Expected result: All directories and files present
testdata/versions/1.0.0/
├── program.exe # "Test Program v1.0.0\n"
├── data/
│ └── config.json # JSON config file
└── libs/
└── core.dll # "Core Library v1.0.0\n"
Version 1.0.1 (Simple update - 4 files, 2 directories):
testdata/versions/1.0.1/
├── program.exe # Modified: "Test Program v1.0.1\n"
├── data/
│ └── config.json # Modified: updated features
└── libs/
├── core.dll # Modified: "Core Library v1.5.0\n"
└── newfeature.dll # NEW: "New Feature v1.0.0\n"
Version 1.0.2 (Complex structure - 11 files, 6 directories, 3 levels deep):
testdata/versions/1.0.2/
├── program.exe # Modified: v1.0.2
├── data/
│ ├── config.json # Modified: added features
│ ├── assets/images/ # NEW: 3 levels deep
│ │ ├── logo.png # NEW: binary PNG file
│ │ └── icon.png # NEW: binary PNG file
│ └── locale/ # NEW: directory
│ └── en-US.json # NEW: localization file
├── libs/
│ ├── core.dll # Modified: v2.5.0
│ ├── newfeature.dll # Modified: v1.5.0
│ └── plugins/ # NEW: directory
│ └── api.dll # NEW: plugin file
└── plugins/ # NEW: root-level directory
├── sample.plugin # NEW: plugin file
└── sample.json # NEW: plugin config
Test 1: Build tools... ✓ PASS
Meaning: Test passed all checks
Test 5: Apply patch with verification... ✗ FAIL
Expected exit code 0, got 1
Meaning: Test failed, explanation provided
What to do:
- Read the error message
- Check if test expectations are correct
- Debug the failing component
- Fix the issue
- Re-run tests
If a test fails, you may see additional details:
Test 8: Pre-verification failure... ✗ FAIL
Expected exit code ≠ 0, got 0
Expected file to remain corrupted, but it was restored
# Create test versions
mkdir -p testdata/manual/1.0.0
mkdir -p testdata/manual/1.0.1
echo "Version 1.0.0" > testdata/manual/1.0.0/app.exe
echo "Version 1.0.1" > testdata/manual/1.0.1/app.exe
# Generate patch
./patch-gen.exe --versions-dir testdata/manual \
--new-version 1.0.1 \
--output testdata/manual/patches
# Verify patch exists
ls testdata/manual/patches/
# Should show: 1.0.0-to-1.0.1.patch# Create test application
mkdir -p testdata/manual/test-app
cp testdata/manual/1.0.0/app.exe testdata/manual/test-app/
# Apply patch
./patch-apply.exe --patch testdata/manual/patches/1.0.0-to-1.0.1.patch \
--current-dir testdata/manual/test-app \
--verify
# Verify version updated
cat testdata/manual/test-app/app.exe
# Should show: Version 1.0.1# Reset to version 1.0.0
rm -rf testdata/manual/test-app
mkdir -p testdata/manual/test-app
cp testdata/manual/1.0.0/app.exe testdata/manual/test-app/
# Dry-run (no changes)
./patch-apply.exe --patch testdata/manual/patches/1.0.0-to-1.0.1.patch \
--current-dir testdata/manual/test-app \
--dry-run
# Verify version unchanged
cat testdata/manual/test-app/app.exe
# Should still show: Version 1.0.0# Create corrupted installation
mkdir -p testdata/manual/corrupted
echo "Corrupted Version" > testdata/manual/corrupted/app.exe
# Try to apply patch (should fail)
./patch-apply.exe --patch testdata/manual/patches/1.0.0-to-1.0.1.patch \
--current-dir testdata/manual/corrupted \
--verify
# Should see error: "key file checksum mismatch"
# No backup should be created
ls testdata/manual/corrupted.backup
# Should show: directory not foundGenerating a downgrade patch:
# Generate downgrade patch (1.0.1 -> 1.0.0)
./patch-gen.exe --versions-dir testdata/manual \
--from 1.0.1 \
--to 1.0.0 \
--output testdata/manual/patches
# Verify downgrade patch exists
ls testdata/manual/patches/
# Should show: 1.0.1-to-1.0.0.patchApplying a downgrade patch:
# Create test installation with version 1.0.1
mkdir -p testdata/manual/test-downgrade
cp testdata/manual/1.0.1/app.exe testdata/manual/test-downgrade/
# Apply downgrade patch
./patch-apply.exe --patch testdata/manual/patches/1.0.1-to-1.0.0.patch \
--current-dir testdata/manual/test-downgrade \
--verify
# Verify version downgraded to 1.0.0
cat testdata/manual/test-downgrade/app.exe
# Should show: Version 1.0.0Testing bidirectional patching cycle:
# Start with version 1.0.0
mkdir -p testdata/manual/test-bidirectional
cp testdata/manual/1.0.0/app.exe testdata/manual/test-bidirectional/
# Upgrade to 1.0.1
./patch-apply.exe --patch testdata/manual/patches/1.0.0-to-1.0.1.patch \
--current-dir testdata/manual/test-bidirectional \
--verify
cat testdata/manual/test-bidirectional/app.exe
# Should show: Version 1.0.1
# Downgrade back to 1.0.0
./patch-apply.exe --patch testdata/manual/patches/1.0.1-to-1.0.0.patch \
--current-dir testdata/manual/test-bidirectional \
--verify
cat testdata/manual/test-bidirectional/app.exe
# Should show: Version 1.0.0 (back to original)Note: For comprehensive downgrade documentation, see the Downgrade Guide.
The test suite supports optional flags for testing advanced features:
# Test large patches >1GB (requires significant disk space and time)
.\advanced-test.ps1 -run1gbtest
# Test chunked processing for 1.5GB file (memory optimization)
.\advanced-test.ps1 -runlargefile
# Combine flags
.\advanced-test.ps1 -run1gbtest -runlargefile# Create new version directory
mkdir testdata/versions/1.0.3
# Add test files
echo "Version 1.0.3" > testdata/versions/1.0.3/test-app.txt
echo "New feature data" > testdata/versions/1.0.3/feature.txt
# Generate patches
./patch-gen.exe --versions-dir testdata/versions \
--new-version 1.0.3 \
--output testdata/patches# Remove generated patches
rm -rf testdata/patches/*.patch
# Remove test applications
rm -rf test-app
rm -rf testdata/1.0.0-test
rm -rf testdata/1.0.1-test
# Remove executables (rebuild from source)
rm patch-gen.exe patch-apply.exeSymptom: Build step fails with compilation errors
Solutions:
- Check Go version:
go version(need 1.24.0+) - Verify code compiles:
go build ./... - Check for syntax errors
- Update dependencies:
go mod tidy
Symptom: Setup fails to find testdata
Solutions:
- Run tests from project root
- Check testdata/ directory exists
- Check version folders exist (1.0.0, 1.0.1, 1.0.2)
- Check test-app.txt files exist in each version
Symptom: Generator command fails
Solutions:
- Check generator executable exists
- Verify testdata structure is correct
- Check disk space
- Run generator manually with verbose output
- Check error messages in test output
Symptom: Applier command fails
Solutions:
- Check applier executable exists
- Verify patch file exists
- Check test-app directory is correct
- Verify test-app has correct version
- Run applier manually with verbose output
Symptom: Corruption detection test passes when it should report failure
Solutions:
- Verify corruption step actually modifies file
- Check that verification is enabled
- Check that pre-verification rejects corrupted installations
- Verify NO backup is created on failure
- This is the critical backup timing test!
To add new tests to the advanced test suite:
- Edit advanced-test.ps1
-
Add new test function following the pattern:
function Test-NewFeature { Write-Host "Test N: New feature description... " -NoNewline # Setup # ... prepare test environment ... # Execute $result = # ... run command ... # Verify if ($result) { Write-Host "✓ PASS" -ForegroundColor Green return $true } else { Write-Host "✗ FAIL" -ForegroundColor Red Write-Host " Error description" return $false } }
- Add test to main execution block
- Update test count in summary section
- Test thoroughly before committing
- Quick Start - Getting started guide
- Generator Guide - Generator tool usage
- Applier Guide - Applier tool usage
- Troubleshooting - Common issues