Commit Graph

1150 Commits

Author SHA1 Message Date
Steve Yegge
c399d177a7 Add comprehensive tests for migrations.go and batch_ops.go (bd-3b7f)
- migrations_test.go: Tests all 10 migration functions
- batch_ops_test.go: Tests batch operations and bulk helpers
- All tests passing
- Completes bd-3b7f and sqlite refactoring epic bd-fc2d

Amp-Thread-ID: https://ampcode.com/threads/T-80ad18be-cff5-46c5-9540-47b55b92b4eb
Co-authored-by: Amp <amp@ampcode.com>
2025-11-01 23:25:44 -07:00
Steve Yegge
9c62d548b6 bd sync: 2025-11-01 22:53:45 2025-11-01 22:53:45 -07:00
Steve Yegge
1849ffe17a test: add comprehensive Comments API tests (bd-d68f)
- Test AddIssueComment basic functionality
- Test GetIssueComments retrieval and ordering
- Test edge cases (empty, nonexistent issues)
- Test dirty flag marking
- Test comment isolation across issues

Improves sqlite package coverage: 69.1% → 70.6%
2025-11-01 22:53:38 -07:00
Steve Yegge
d86f359e63 fix: DetectCycles SQL bug and add comprehensive tests
- Fix SQL query bug preventing cycle detection (bd-9f20)
  - Allow revisiting start node to complete cycle
  - Remove duplicate start_id concatenation in final SELECT
- Add cycle_detection_test.go with comprehensive test coverage (bd-cdf7)
  - Simple 2-node cycles
  - Complex multi-node cycles (4-node, 10-node)
  - Self-loops
  - Multiple independent cycles
  - Acyclic graphs (diamond, chain)
  - Empty graph and single node edge cases
  - Mixed dependency types

Improves sqlite package coverage: 68.2% → 69.1%
2025-11-01 22:51:58 -07:00
Steve Yegge
e9bb1ac121 test: add sqlite collision and delete test coverage
- Add collision_test.go: comprehensive ID collision handling tests
- Add delete_test.go: test soft delete, cascade, and edge cases
- Improves sqlite package coverage from 57.8% to 68.2%

Amp-Thread-ID: https://ampcode.com/threads/T-f4a96cad-a2a4-4f6f-af47-cd56700429f7
Co-authored-by: Amp <amp@ampcode.com>
2025-11-01 22:47:07 -07:00
Steve Yegge
39b49ca4b6 bd sync: 2025-11-01 22:41:02 2025-11-01 22:41:02 -07:00
Steve Yegge
27940878cf bd sync: apply rename detection from import 2025-11-01 22:39:39 -07:00
Steve Yegge
7a47e4d108 Merge branch 'main' of github.com:steveyegge/beads 2025-11-01 22:39:38 -07:00
Steve Yegge
440d9bf913 bd sync: 2025-11-01 22:39:37 2025-11-01 22:39:37 -07:00
Steve Yegge
123a0faa8b bd sync: 2025-11-01 22:34:01 2025-11-01 22:34:01 -07:00
Steve Yegge
98ecaec2ec AGENTS.md: Strongly recommend git hooks installation 2025-11-01 22:23:59 -07:00
Steve Yegge
9c38082cbf Add pre-push hook to prevent stale JSONL exports 2025-11-01 22:22:55 -07:00
Steve Yegge
6ef3ba1d49 bd sync: 2025-11-01 22:21:05 2025-11-01 22:21:05 -07:00
Steve Yegge
14f28020c6 Sync databases after daemon race condition fix 2025-11-01 22:20:32 -07:00
Steve Yegge
43ed423575 bd sync: 2025-11-01 22:20:19 2025-11-01 22:20:19 -07:00
Steve Yegge
50edb7349e bd sync: 2025-11-01 22:18:58 2025-11-01 22:18:58 -07:00
Steve Yegge
05b2d2bdbb bd sync: 2025-11-01 22:01:47 2025-11-01 22:01:47 -07:00
Steve Yegge
7421f525fb Fix daemon race condition: prevent stale exports
- Add JSONL timestamp check in validatePreExport
- Refuse export if JSONL is newer than database
- Force daemon to import before exporting when JSONL updated
- Add test case for JSONL-newer-than-DB scenario
- Fixes bd-89e2
2025-11-01 22:01:41 -07:00
Steve Yegge
7c1ff833f4 bd sync: 2025-11-01 22:01:28 2025-11-01 22:01:41 -07:00
Steve Yegge
8cc1bb4e24 bd sync: 2025-11-01 21:49:42 2025-11-01 21:49:42 -07:00
Steve Yegge
839a4877e8 Close bd-5f26: daemon.go refactoring complete 2025-11-01 21:46:50 -07:00
Steve Yegge
ce4d7564f9 bd sync: 2025-11-01 21:45:12 2025-11-01 21:45:12 -07:00
Steve Yegge
5d046d29c7 Sync JSONL from main repo to converge databases 2025-11-01 21:33:28 -07:00
Steve Yegge
ba886698a5 bd sync: manual export to fix divergence 2025-11-01 21:29:51 -07:00
Steve Yegge
6e8907335f Add test coverage for daemon lifecycle and config modules
- Add config_test.go: tests for daemon configuration (local/global, sync behavior)
- Add daemon_test.go: tests for daemon lifecycle (creation, shutdown, database path resolution)
- Add process_test.go: tests for daemon lock acquisition and release
- Closes bd-2b34.6, bd-2b34.7

Amp-Thread-ID: https://ampcode.com/threads/T-4419d1ab-4105-4e75-bea8-1837ee80e2c2
Co-authored-by: Amp <amp@ampcode.com>
2025-11-01 21:27:09 -07:00
Steve Yegge
8a76b52cfc Merge branch 'main' of github.com:steveyegge/beads 2025-11-01 20:29:24 -07:00
Steve Yegge
c83560ddd1 bd sync: 2025-11-01 20:29:22 2025-11-01 20:29:23 -07:00
Steve Yegge
5fabb5fdcc Fix bd-c6cf: Force full export when export_hashes is cleared
When validateJSONLIntegrity() clears export_hashes due to hash mismatch
or missing JSONL, the subsequent export now correctly exports ALL issues
instead of only dirty ones, preventing permanent database divergence.

Changes:
- validateJSONLIntegrity() returns (needsFullExport, error) to signal when
  export_hashes was cleared
- flushToJSONL() moved integrity check BEFORE isDirty gate so integrity
  issues trigger export even when nothing is dirty
- Missing JSONL treated as non-fatal force-full-export case
- Increased scanner buffer from 64KB to 2MB to handle large JSON lines
- Added scanner.Err() check to catch buffer overflow errors
- Updated all tests to verify needsFullExport flag

Fixes database divergence issue where clearing export_hashes didn't
trigger re-export, causing 5 issues to disappear from JSONL in fred clone.

Amp-Thread-ID: https://ampcode.com/threads/T-bf2fdcd6-7bbd-4c30-b1db-746b928c93b8
Co-authored-by: Amp <amp@ampcode.com>
2025-11-01 20:29:13 -07:00
Steve Yegge
55ff80caee updated instructions 2025-11-01 20:23:46 -07:00
Steve Yegge
ed1eca9064 Add circular dependency detection to bd doctor
- Added checkDependencyCycles() function using recursive CTE
- Integrated as Check #10 in runDiagnostics()
- Reports error status with count and fix suggestion if cycles found
- Updated doctor command documentation
- Fixes bd-3e3b
2025-11-01 20:18:37 -07:00
Steve Yegge
b0bbe449a1 bd sync: 2025-11-01 20:18:26 2025-11-01 20:18:37 -07:00
Steve Yegge
0c1738c976 bd sync: 2025-11-01 20:11:52 2025-11-01 20:11:52 -07:00
Steve Yegge
daef76d837 bd sync: 2025-11-01 20:11:00 2025-11-01 20:11:08 -07:00
Steve Yegge
3fc8922c86 Refactor daemon runtime into internal/daemonrunner package
- Extract Daemon struct with Start/Stop methods
- Create focused modules: config, daemon, rpc, sync, git, process, logger
- Move platform-specific code to separate files (signals_*.go, flock_*.go)
- Add database fingerprint validation
- Keep import logic in cmd/bd for now (TODO: extract later)
- All builds pass, most daemon tests pass

Closes bd-b5a3
2025-11-01 20:02:30 -07:00
Steve Yegge
53e340e54f Merge branch 'main' of github.com:steveyegge/beads 2025-11-01 20:02:24 -07:00
Steve Yegge
6076651d28 bd sync: 2025-11-01 20:02:23 2025-11-01 20:02:23 -07:00
Nikolai Prokoschenko
c65cfa1ebd Add dependency and dependent counts to bd list JSON output (#198)
When using `bd list --json`, each issue now includes:
- `dependency_count`: Number of issues this issue depends on
- `dependent_count`: Number of issues that depend on this issue

This provides quick access to dependency relationship counts without
needing to fetch full dependency lists or run multiple bd show commands.

Performance:
- Uses single bulk query (GetDependencyCounts) instead of N individual queries
- Overhead: ~26% for 500 issues (24ms vs 19ms baseline)
- Avoids N+1 query problem that would have caused 2.2x slowdown

Implementation:
- Added GetDependencyCounts() to Storage interface for bulk counting
- Efficient SQLite query using UNION ALL + GROUP BY
- Memory storage implementation for testing
- Moved IssueWithCounts to types package to avoid duplication
- Both RPC and direct modes use optimized bulk query

Tests:
- Added comprehensive tests for GetDependencyCounts
- Tests cover: normal operation, empty list, nonexistent IDs
- All existing tests continue to pass

Backwards compatible: JSON structure is additive, all original fields preserved.

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

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-01 19:59:15 -07:00
Midworld Kim
21ab565819 Fix hyphenated issue prefix detection (#199)
- update prefix/number parsing to use the last hyphen across utils and nodb paths
- add regression tests covering multi-hyphen prefixes in both packages
2025-11-01 19:57:37 -07:00
Steve Yegge
b5db80c412 Refactor sqlite.go: Extract hash IDs, batch ops, validators (bd-90a5, bd-c796, bd-d9e0)
- Extract hash ID generation to hash_ids.go (bd-90a5)
  - generateHashID, getNextChildNumber, GetNextChildID
  - Reduced sqlite.go from 1880 to 1799 lines

- Extract batch operations to batch_ops.go (bd-c796)
  - validateBatchIssues, generateBatchIDs, bulkInsertIssues
  - bulkRecordEvents, bulkMarkDirty, CreateIssues
  - Reduced sqlite.go from 1799 to 1511 lines

- Extract validation functions to validators.go (bd-d9e0)
  - validatePriority, validateStatus, validateIssueType
  - validateTitle, validateEstimatedMinutes, validateFieldUpdate
  - Reduced sqlite.go from 1511 to 1447 lines

- Add comprehensive validator tests (bd-3b7f)
  - validators_test.go with full coverage

Total reduction: 2298 → 1447 lines (851 lines extracted, 37% reduction)

Part of epic bd-fc2d to modularize sqlite.go
All tests pass

Amp-Thread-ID: https://ampcode.com/threads/T-09c4383b-bc5c-455e-be24-02b4f9df7d78
Co-authored-by: Amp <amp@ampcode.com>
2025-11-01 19:55:48 -07:00
Steve Yegge
537844cb11 Fix bd-36870264: Prevent nested .beads directories with path canonicalization
- Add filepath.Abs() + EvalSymlinks() to FindDatabasePath() to normalize all database paths
- Add nested .beads directory detection in setupDaemonLock() with helpful error messages
- Prevents infinite .beads/.beads/.beads/ recursion when using relative BEADS_DB paths
- All acceptance criteria passed: singleton enforcement, lock release, no recursion

Amp-Thread-ID: https://ampcode.com/threads/T-c7fc78b8-a935-48dc-8453-a1bd47a14f72
Co-authored-by: Amp <amp@ampcode.com>
2025-11-01 19:50:34 -07:00
Steve Yegge
ce9a5164f7 Close daemon refactoring tasks and create sqlite.go refactor epic 2025-11-01 19:33:53 -07:00
Steve Yegge
3733b12f7b bd sync: 2025-11-01 19:29:40 2025-11-01 19:29:40 -07:00
Steve Yegge
a708c321fb Fix bd-11e0: Auto-upgrade database version in daemon instead of exiting 2025-11-01 19:28:37 -07:00
Steve Yegge
a4b9ae5fcf bd sync: 2025-11-01 19:28:32 2025-11-01 19:28:32 -07:00
Steve Yegge
72c4c908db bd sync: 2025-11-01 19:20:28 2025-11-01 19:20:28 -07:00
Steve Yegge
eb00ab8005 Refactor daemon.go for testability and maintainability (bd-2b34)
- Split 1567-line daemon.go into 5 focused modules
- daemon_config.go (122 lines): config/path resolution
- daemon_lifecycle.go (451 lines): start/stop/status/health/metrics
- daemon_sync.go (510 lines): export/import/sync logic
- daemon_server.go (115 lines): RPC server setup
- daemon_logger.go (43 lines): logging utilities
- Reduced main daemon.go to 389 lines (75% reduction)
- All tests pass, improved code organization

Amp-Thread-ID: https://ampcode.com/threads/T-7504c501-f962-4b82-a6d9-8e33f547757d
Co-authored-by: Amp <amp@ampcode.com>
2025-11-01 19:20:01 -07:00
Steve Yegge
d80e7a5fd2 Fix bd-6c68: preserve actual daemon failure reasons in bd info
Don't override connect_failed/health_failed with auto_start_disabled.
This preserves important diagnostic information about whether the
daemon crashed vs. was never running.

Amp-Thread-ID: https://ampcode.com/threads/T-a8da544a-3e59-4293-903c-ce6be85fc28b
Co-authored-by: Amp <amp@ampcode.com>
2025-11-01 19:14:24 -07:00
Steve Yegge
4879b1a8c4 bd sync: 2025-11-01 19:14:04 2025-11-01 19:14:04 -07:00
Steve Yegge
b5839b656d Fix compilation errors in internal/daemonrunner package
Created missing files:
- logger.go: Logger type, setupLogger method, and env helpers
- signals_unix.go: Unix signal definitions (SIGTERM, SIGINT, SIGHUP)
- signals_windows.go: Windows signal definitions
- sync.go: Sync loop implementation with export/import/validation helpers

Fixed errors:
- Added missing 'version' parameter to acquireDaemonLock call
- Removed duplicate setupLock method from process.go (kept in daemon.go)
- Removed duplicate startRPCServer from daemon.go (kept in rpc.go)
- Fixed LogPath -> LogFile config field reference
- Removed unused 'io' import from process.go

Implementation notes:
- exportToJSONL: Full implementation with dependencies, labels, comments
- importFromJSONL: Placeholder (TODO: extract from cmd/bd/import.go)
- countDBIssues: Uses SQL COUNT(*) optimization with fallback
- validatePostImport: Checks for data loss
- runSyncLoop/runEventLoop: Main daemon event loops with signal handling

All packages now compile successfully with 'go build ./...'

Amp-Thread-ID: https://ampcode.com/threads/T-36a7f730-3420-426f-9e23-f13d5fa089c4
Co-authored-by: Amp <amp@ampcode.com>
2025-11-01 19:10:27 -07:00
Steve Yegge
cbe70aa2c3 bd sync: 2025-11-01 17:00 2025-11-01 17:05:51 -07:00