This directory contains integration tests for the BragDoc CLI's extraction functionality.
The integration tests verify that:
- All extraction detail levels (minimal, standard, detailed, comprehensive) work correctly
- Each detail level produces the expected output format
- Output is consistent across runs (deterministic)
- Extraction properly filters/prioritizes files based on configuration
cli-extraction.sh: Main integration test scriptnormalize-output.sh: Output normalization for snapshot comparison../scripts/create-test-repo.sh: Deterministic test repository generator
- Create test repo: Generates a deterministic git repository with various commit types
- Build CLI: Ensures latest code is tested
- Initialize project: Sets up BragDoc in non-interactive mode
- Run extractions: Executes extraction with all 4 detail levels
- Normalize output: Removes timestamps/hashes for consistent comparison
- Compare snapshots: Verifies output matches expected baseline
- Verify differences: Ensures detail levels differ as expected
The test script will refuse to run if it finds an existing ~/.bragdoc/config.yml file, to protect your personal configuration. This is intentional - the tests are designed to run in CI (where no config exists) or locally after moving your config aside.
If you need to run tests locally:
# Move your config aside
mv ~/.bragdoc/config.yml ~/.bragdoc/config.yml.bak
# Run the tests
./tests/integration/cli-extraction.sh
# Restore your config
mv ~/.bragdoc/config.yml.bak ~/.bragdoc/config.yml./cli-extraction.shThis compares current output against stored snapshots.
When extraction output changes intentionally:
UPDATE_SNAPSHOTS=1 ./cli-extraction.shImportant: Always review snapshot changes before committing to ensure they're correct!
The test repository contains these commit types:
- Small commits: 1-2 files, <50 lines (tests basic extraction)
- Medium commits: 5-10 files, 100-500 lines (tests typical commits)
- Large commits: 20+ files, 1000+ lines (tests truncation)
- Edge cases: Lock files, dist files (tests filtering)
- Source changes: src/** files (tests prioritization)
Tests verify these behaviors:
- ✓ Includes commit messages
- ✓ NO file statistics
- ✓ NO code diffs
- ✓ Includes commit messages
- ✓ Includes file statistics
- ✓ NO code diffs
- ✓ Includes commit messages
- ✓ Includes file statistics
- ✓ Includes code diffs (limited: 1000 lines/commit, 200 lines/file, 30 files)
- ✓ Filters lock files and dist files
- ✓ Prioritizes src/** files
- ✓ Includes commit messages
- ✓ Includes file statistics
- ✓ Includes code diffs (extensive: 2000 lines/commit, 500 lines/file, 50 files)
- ✓ Filters lock files and dist files
- ✓ Prioritizes src/** files
Tests run automatically in GitHub Actions on every push. See .github/workflows/test.yml.
If tests fail unexpectedly:
- Check if extraction output format changed intentionally
- Review the diff shown in test output
- If changes are correct, update snapshots:
UPDATE_SNAPSHOTS=1 ./cli-extraction.sh - If changes are incorrect, fix the code
If the test repo generates different commits each time:
- Check that
create-test-repo.shusesGIT_AUTHOR_DATEandGIT_COMMITTER_DATE - Verify git config is set correctly (
user.name,user.email,commit.gpgsign) - Ensure no random/time-based content in commit files
Tests should be platform-agnostic, but if issues arise:
- Check line ending differences (LF vs CRLF)
- Verify bash script compatibility
- Consider platform-specific snapshots if necessary
To test a specific detail level:
# Run the full test script, then check specific output
./cli-extraction.sh
# Or manually test a single level
cd /tmp/bragdoc-test-repo-$$
node ../../packages/cli/dist/index.js extract --dry-run --detail-level minimalTo see what's different between current output and snapshots:
# Run tests (they'll show diffs)
./cli-extraction.sh
# Or manually compare
./cli-extraction.sh # Let it fail
diff -u ../snapshots/extraction-minimal.txt /tmp/bragdoc-test-output-*/output-minimal-normalized.txtSnapshots are stored in ../snapshots/:
extraction-minimal.txt- Expected output for minimal detail levelextraction-standard.txt- Expected output for standard detail levelextraction-detailed.txt- Expected output for detailed detail levelextraction-comprehensive.txt- Expected output for comprehensive detail level
Snapshots contain normalized output with:
- Commit hashes replaced with "HASH"
- Dates replaced with "DATE"
- Timestamps replaced with "TIME"
- Absolute paths replaced with "REPO"
This ensures consistent comparison across different environments and runs.
To add new integration tests:
- Modify test repository: Update
create-test-repo.shto add new commit types - Update test script: Add new verification checks to
cli-extraction.sh - Generate new snapshots: Run
UPDATE_SNAPSHOTS=1 ./cli-extraction.sh - Verify manually: Review snapshot content to ensure correctness
- Commit changes: Include both script updates and new/updated snapshots
# 1. Update create-test-repo.sh to add commits that exercise the feature
vim ../../scripts/create-test-repo.sh
# 2. Update cli-extraction.sh to verify the feature behavior
vim cli-extraction.sh
# 3. Generate snapshots with the new behavior
UPDATE_SNAPSHOTS=1 ./cli-extraction.sh
# 4. Review the changes
git diff ../snapshots/
# 5. Run tests to ensure they pass
./cli-extraction.sh
# 6. Commit everything
git add ../../scripts/create-test-repo.sh cli-extraction.sh ../snapshots/
git commit -m "feat: add integration test for new feature"Integration tests typically complete in:
- Local development: 30-60 seconds
- CI environment: 60-120 seconds
Most time is spent:
- Building the CLI (15-30s)
- Creating test repository (5-10s)
- Running extractions (10-30s)
- Comparing snapshots (1-5s)
If tests become slow:
- Check if CLI build is using cache
- Verify test repository isn't growing too large
- Consider parallelizing extractions (currently sequential)
- Always review snapshot changes: Never blindly commit snapshot updates
- Test locally first: Run tests before pushing to avoid CI failures
- Keep test repo small: Only add commits that test specific behaviors
- Document changes: Update this README when adding new test cases
- Use meaningful commit messages: Test repo commits should be descriptive
- Verify determinism: If adding commits to test repo, verify they're deterministic
- CLI README - CLI usage and features
- PLAN.md - Implementation plan
- SPEC.md - Original specification