Commit Graph

7 Commits

Author SHA1 Message Date
Alberto Garcia Illera
4669de7625 feat(export): add --id and --parent filters (#1292)
Add two new filter flags to the export command:
- --id: Filter by specific issue IDs (comma-separated)
- --parent: Filter by parent issue ID (shows children)

Also fix safety checks (empty DB, staleness) to skip when filters
are active, since filtered exports intentionally produce subsets.

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-24 17:12:26 -08:00
Steve Yegge
a17e4af725 Fix context propagation lifecycle bugs
Critical fixes to context propagation implementation (bd-rtp, bd-yb8, bd-2o2):

1. Fix rootCtx lifecycle in main.go:
   - Removed premature defer rootCancel() from PersistentPreRun (line 132)
   - Added proper cleanup in PersistentPostRun (lines 544-547)
   - Context now properly spans from setup through command execution to cleanup

2. Fix test context contamination in cli_fast_test.go:
   - Reset rootCtx and rootCancel to nil in test cleanup (lines 139-140)
   - Prevents cancelled contexts from affecting subsequent tests

3. Fix export tests missing context in export_test.go:
   - Added rootCtx initialization in 5 export test subtests
   - Tests now properly set up context before calling exportCmd.Run()

These fixes ensure:
- Signal-aware contexts work correctly for graceful cancellation
- Ctrl+C properly cancels import/export operations
- Database integrity is maintained after cancellation
- All cancellation tests pass (TestImportCancellation, TestExportCommand)

Tested:
- go build ./cmd/bd ✓
- go test ./cmd/bd -run TestImportCancellation ✓
- go test ./cmd/bd -run TestExportCommand ✓

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-20 21:54:11 -05:00
Steve Yegge
92b10b0806 Implement bd-zbq2: Export JSONL line count verification
After atomic rename during export, verify that the JSONL file contains
exactly the same number of lines as issues exported. This catches silent
export failures where the operation appears to succeed but doesn't
actually write all issues.

Real-world scenario that motivated this:
- SQL DELETE removed 240 issues
- 'bd export' appeared to succeed
- But JSONL was never updated
- Later session found all 240 deleted issues 'came back'

Changes:
- Add verification after os.Rename in exportCmd
- Reuse existing countIssuesInJSONL() helper
- Exit with clear error if mismatch detected
- Add test case that verifies detection works

Error message shown on mismatch:
  Error: Export verification failed
    Expected: 276 issues
    JSONL file: 516 lines
    Mismatch indicates export failed to write all issues

Tests:
✓ All existing export tests pass
✓ New test verifies line counting works correctly
✓ Test simulates corruption by truncating file

Performance: Verification is fast (just counts lines), minimal overhead
2025-11-05 14:31:41 -08:00
Steve Yegge
571a596641 Fix export test failures with ClearAllExportHashes for test isolation
Amp-Thread-ID: https://ampcode.com/threads/T-5335d274-44e1-4811-b63f-15c52ea3394f
Co-authored-by: Amp <amp@ampcode.com>
2025-10-26 23:06:03 -07:00
Steve Yegge
4ea347e08a Fix all test failures from bd-166 (missing issue_prefix)
Completed bd-167: Fixed all tests that failed with 'database not initialized: issue_prefix config is missing' error.

Changes:
- Created test helper functions in 3 locations:
  * cmd/bd/test_helpers_test.go (already existed)
  * internal/rpc/test_helpers.go (new)
  * internal/storage/sqlite/test_helpers.go (new)

- Updated all affected test files to use newTestStore():
  * cmd/bd: comments, export, git_sync, label, list, reopen, direct_mode
  * internal/rpc: rpc_test, version_test
  * internal/storage/sqlite: sqlite_test, underlying_db_test

- Fixed config test: updated flush-debounce default from 5s to 30s

- Removed unused sqlite imports from test files

All tests now passing 

Also:
- Closed bd-167, bd-170 (cleanup of beads-* duplicates)
- Removed corrupt backup files

Amp-Thread-ID: https://ampcode.com/threads/T-4a8c6002-9384-45b6-81f6-2907d1e4c6c2
Co-authored-by: Amp <amp@ampcode.com>
2025-10-26 22:31:24 -07:00
Steve Yegge
de03466da9 Fix bd-143: Prevent daemon auto-sync from wiping out issues.jsonl with empty database
- Added safety check to exportToJSONLWithStore (daemon path)
- Refuses to export 0 issues over non-empty JSONL file
- Added --force flag to override safety check when intentional
- Added test coverage for empty database export protection
- Prevents data loss when daemon has wrong/empty database

Amp-Thread-ID: https://ampcode.com/threads/T-de18e0ad-bd17-46ec-994b-0581e257dcde
Co-authored-by: Amp <amp@ampcode.com>
2025-10-25 16:36:18 -07:00
Steve Yegge
8023a6cd6c Improve test coverage to 57.7% (+13.5%)
Added comprehensive test coverage for previously untested commands:
- version_test.go: Plain text and JSON version output
- list_test.go: All filter operations and label normalization
- export_test.go: JSONL export with labels & dependencies
- stale_test.go: Duration formatting and stale issue detection
- comments_test.go: Comment management and error handling
- delete_test.go: Batch deletion helpers
- metrics_test.go: RPC metrics recording and snapshots

Coverage improvement:
- Overall: 44.2% → 57.7% (+13.5%)
- cmd/bd: 17.9% → 19.8% (+1.9%)
- internal/rpc: 45.2% → 45.8% (+0.6%)

All tests passing with no new linter warnings.

Amp-Thread-ID: https://ampcode.com/threads/T-1ee1734e-0164-4c6f-834e-cb8051d14302
Co-authored-by: Amp <amp@ampcode.com>
2025-10-24 00:56:18 -07:00