Commit Graph

157 Commits

Author SHA1 Message Date
Steve Yegge
a126debb99 bd-b245: Add migration registry and simplify New() 2025-11-02 12:40:55 -08:00
David Laing
50a324db85 Fix #202: Add dependency_type to bd show --json output (#203)
The JSON output from bd show now includes the dependency_type field
for both dependencies and dependents, enabling programmatic
differentiation between dependency types (blocks, related,
parent-child, discovered-from).

Implementation approach:
- Added IssueWithDependencyMetadata type with embedded Issue and
  DependencyType field
- Extended GetDependenciesWithMetadata and GetDependentsWithMetadata
  to include dependency type from SQL JOIN
- Made GetDependencies and GetDependents wrap the WithMetadata
  methods for backward compatibility
- Added scanIssuesWithDependencyType helper to handle scanning with
  dependency type field
- Updated bd show --json to use WithMetadata methods

Tests added:
- TestGetDependenciesWithMetadata - basic functionality
- TestGetDependentsWithMetadata - dependent retrieval
- TestGetDependenciesWithMetadataEmpty - edge case handling
- TestGetDependenciesWithMetadataMultipleTypes - multiple types

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Happy <yesreply@happy.engineering>
2025-11-02 08:40:10 -08:00
Steve Yegge
2b086951c4 fix: Address all errcheck and misspell linter errors 2025-11-01 23:56:03 -07:00
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
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
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
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
a4b4778ced test: improve coverage for importer and sqlite utils
- Fix TestImportIssues_Update by adding timestamps to test issue
- Add comprehensive tests for sqlite utility functions (IsUniqueConstraintError, QueryContext, BeginTx, ExecInTransaction)
- Coverage improvements: sqlite util.go 0% -> 95%, sqlite package 56.4% -> 57.1%

Amp-Thread-ID: https://ampcode.com/threads/T-17e6a3e4-f881-4f53-b670-bdd796d58f68
Co-authored-by: Amp <amp@ampcode.com>
2025-11-01 11:35:31 -07:00
Steve Yegge
cc7918daf4 Implement bd stale command (bd-c01f, closes #184)
- Add bd stale command to find abandoned/forgotten issues
- Support --days (default 30), --status, --limit, --json flags
- Implement GetStaleIssues in SQLite and Memory storage
- Add full RPC/daemon support
- Comprehensive test suite (6 tests, all passing)
- Update AGENTS.md documentation

Resolves GitHub issue #184

Amp-Thread-ID: https://ampcode.com/threads/T-f021ddb8-54e3-41bf-ba7a-071749663c1d
Co-authored-by: Amp <amp@ampcode.com>
2025-10-31 23:03:56 -07:00
Steve Yegge
0b852f52d9 Remove obsolete renumber and stale commands, fix test
- Remove renumber.go: Hash IDs eliminated need for ID compaction
- Remove stale.go: Executor/heartbeat tables were never implemented
- Fix TestListCommand: duplicate dependency constraint violation
- Update comments removing references to removed commands

Amp-Thread-ID: https://ampcode.com/threads/T-3dcd8681-c7d3-4fe1-9750-b38279b56cdb
Co-authored-by: Amp <amp@ampcode.com>
2025-10-31 21:27:33 -07:00
Steve Yegge
39d5608497 Merge branch 'main' of github.com:steveyegge/beads
# Conflicts:
#	.beads/beads.jsonl
2025-10-31 15:12:08 -07:00
Steve Yegge
ddab26315f Remove dead code found by deadcode analyzer
- Removed 5 unreachable functions (~200 LOC)
- computeIssueContentHash, shouldSkipExport from autoflush.go
- addDependencyUnchecked, removeDependencyIfExists from dependencies.go
- isUniqueConstraintError alias from util.go
- All tests still pass
- Closes bd-7c5915ae
2025-10-31 15:12:01 -07:00
Steve Yegge
aa567f6b9a feat: add Mermaid.js format for dependency tree visualization (#191)
Adds `bd dep tree --format mermaid` to export dependency trees as Mermaid.js flowcharts.

Features:
- Status indicators: ☐ open, ◧ in_progress, ⚠ blocked, ☑ closed
- Theme-agnostic design
- Works with --reverse flag
- Comprehensive unit tests following TDD

Co-authored-by: David Laing <david@davidlaing.com>
2025-10-31 15:11:29 -07:00
Steve Yegge
d5488cb97f Remove collision-era language from docs and code
- Updated FAQ.md, ADVANCED.md, TROUBLESHOOTING.md to explain hash IDs eliminate collisions
- Removed --resolve-collisions references from all documentation and examples
- Renamed handleCollisions() to detectUpdates() to reflect update semantics
- Updated test names: TestAutoImportWithCollision → TestAutoImportWithUpdate
- Clarified: with hash IDs, same-ID = update operation, not collision

Closes: bd-50a7, bd-b84f, bd-bda8, bd-650c, bd-3ef2, bd-c083, bd-85a6
2025-10-31 14:24:50 -07:00
Steve Yegge
64fe51d6bb Remove obsolete collision remapping code and tests
- Deleted collision remapping tests (obsolete with hash IDs bd-8e05)
- Simplified collision.go from 704 to 138 lines
- Removed RemapCollisions, ScoreCollisions, and reference update code
- Removed issue_counters table dependencies (bd-807b)
- Added COLLISION_MATH.md documentation
- Fixed RenameCounterPrefix and ResetCounter to be no-ops
- Closed bd-a58f, bd-3d65, bd-807b

Hash-based IDs make collision remapping unnecessary since collisions
are extremely rare (same ID = same content).

Amp-Thread-ID: https://ampcode.com/threads/T-cbb0f111-6a95-4598-b03e-c137112f9875
Co-authored-by: Amp <amp@ampcode.com>
2025-10-31 00:19:42 -07:00
Steve Yegge
5d137ffeeb Remove sequential ID generation and SyncAllCounters (bd-c7af, bd-8e05, bd-4c74)
- Removed SyncAllCounters() and all call sites (already no-op with hash IDs)
- Removed AllocateNextID() and getNextIDForPrefix() - sequential ID generation
- Removed collision remapping logic in internal/storage/sqlite/collision.go
- Removed rename collision handling in internal/importer/importer.go
- Removed branch-merge example (collision resolution no longer needed)
- Updated EXTENDING.md to remove counter sync examples

These were all deprecated code paths for sequential IDs that are obsolete
with hash-based IDs. Hash ID collisions are handled by extending the hash,
not by remapping to new sequential IDs.
2025-10-30 22:24:42 -07:00
Steve Yegge
e3afecca37 Remove sequential ID code path (bd-aa744b)
- Removed nextSequentialID() and getIDMode() functions
- Removed issue_counters table from schema
- Made SyncAllCounters() a no-op for backward compatibility
- Simplified ID generation to hash-only (adaptive length)
- Removed id_mode config setting
- Removed sequential ID tests and migration code
- Updated CONFIG.md and AGENTS.md to remove sequential ID references

Follow-up bd-2a70 will remove obsolete test files and renumber command.
2025-10-30 21:51:39 -07:00
Steve Yegge
76d3403d0a Implement adaptive ID length scaling (bd-ea2a13)
- Start with 4-char IDs for small databases (0-500 issues)
- Scale to 5-char at 500-1500 issues, 6-char at 1500+
- Configurable via max_collision_prob, min/max_hash_length
- Birthday paradox math ensures collision probability stays under threshold
- Comprehensive tests and documentation
- Collision calculator tool for analysis

Also filed bd-aa744b to remove sequential ID code path.
2025-10-30 21:40:52 -07:00
Steve Yegge
cd7bdb301d Generate 6-char hash IDs with progressive 7/8-char fallback on collision (bd-7c87cf24)
- Changed generateHashID to start with 6 chars (3 bytes), expand to 7/8 on collision
- Updated both CreateIssue and CreateIssues (batch) to use progressive length fallback
- Updated tests to accept 9-11 char IDs (bd- + 6-8 hex chars)
- All new issues now generate with shorter, more readable IDs
- Existing 8-char IDs preserved (no migration needed)

Amp-Thread-ID: https://ampcode.com/threads/T-8a6058af-9f42-4bff-be02-8c8bce41eeb5
Co-authored-by: Amp <amp@ampcode.com>
2025-10-30 18:16:24 -07:00
Steve Yegge
1fbfe58ba7 Make hash IDs opt-in via id_mode config (bd-5404)
- Add id_mode config (sequential|hash), defaults to sequential
- Update CreateIssue/CreateIssues to check id_mode and generate appropriate IDs
- Implement lazy counter initialization from existing issues
- Update migrate --to-hash-ids to set id_mode=hash after migration
- Fix hash ID tests to set id_mode=hash
- Fix renumber test to use explicit IDs
- All 183 test packages pass

This makes hash IDs backward-compatible opt-in rather than forced default.
2025-10-30 16:50:38 -07:00
Steve Yegge
3ed2aa07cb Implement hierarchical child ID generation (bd-171)
- Add GetNextChildID to storage interface for generating child IDs
- Implement in SQLiteStorage with atomic counter using child_counters table
- Implement in MemoryStorage with in-memory counter
- Add --parent flag to bd create command
- Support hierarchical IDs (bd-a3f8e9.1, bd-a3f8e9.1.5) in CreateIssue
- Validate parent exists when creating hierarchical issues
- Enforce max depth of 3 levels
- Update ID validation to accept hierarchical IDs with dots
- Add comprehensive tests for child ID generation
- Manual testing confirms: sequential children, nested hierarchies, depth enforcement
2025-10-30 14:42:08 -07:00
Steve Yegge
2276d5e428 Implement hash ID generation (bd-168)
- Add generateHashID function with SHA256-based IDs
- Update CreateIssue and CreateIssues to use hash IDs
- Add collision detection with nonce retry logic
- Add comprehensive tests for hash ID generation
- Hash IDs format: prefix-<8 hex chars> (e.g., bd-a3f8e9a2)

Amp-Thread-ID: https://ampcode.com/threads/T-48f75379-427f-4d72-bbc2-42bad0d0d62d
Co-authored-by: Amp <amp@ampcode.com>
2025-10-30 14:16:35 -07:00
Steve Yegge
6091e87cd1 Revert "Implement hash ID generation (bd-168)"
This reverts commit 2480316248.
2025-10-30 14:16:24 -07:00
Steve Yegge
2480316248 Implement hash ID generation (bd-168)
- Add generateHashID function with SHA256-based IDs
- Update CreateIssue and CreateIssues to use hash IDs
- Add collision detection with nonce retry logic
- Add comprehensive tests for hash ID generation
- Hash IDs format: prefix-<8 hex chars> (e.g., bd-a3f8e9a2)

Amp-Thread-ID: https://ampcode.com/threads/T-48f75379-427f-4d72-bbc2-42bad0d0d62d
Co-authored-by: Amp <amp@ampcode.com>
2025-10-30 14:12:29 -07:00
Steve Yegge
2b05ec65f8 Implement 6-char progressive hash IDs (bd-166, bd-167)
- Hash ID generation now returns full 64-char SHA256
- Progressive collision handling: 6→7→8 chars on INSERT failure
- Added child_counters table for hierarchical IDs
- Updated all docs to reflect 6-char design
- Collision math: 97% of 1K issues stay at 6 chars

Next: Implement progressive retry logic in CreateIssue (bd-168)
Amp-Thread-ID: https://ampcode.com/threads/T-9931c1b7-c989-47a1-8e6a-a04469bd937d
Co-authored-by: Amp <amp@ampcode.com>
2025-10-30 14:04:03 -07:00
Steve Yegge
c34b93fa1a Fix bd-160: Implement JSONL integrity validation and prevent export deduplication data loss
## Problem
Export deduplication feature broke when JSONL and export_hashes diverged
(e.g., after git pull/reset). This caused exports to skip issues that
weren't actually in the file, leading to silent data loss.

## Solution
1. JSONL integrity validation before every export
   - Store JSONL file hash after export
   - Validate hash before export, clear export_hashes if mismatch
   - Automatically recovers from git operations changing JSONL

2. Clear export_hashes on all imports
   - Prevents stale hashes from causing future export failures
   - Import operations invalidate export_hashes state

3. Add Storage interface methods:
   - GetJSONLFileHash/SetJSONLFileHash for integrity tracking
   - ClearAllExportHashes for recovery

## Tests Added
- TestJSONLIntegrityValidation: Unit tests for validation logic
- TestImportClearsExportHashes: Verifies imports clear hashes
- TestExportIntegrityAfterJSONLTruncation: Simulates git reset (would have caught bd-160)
- TestExportIntegrityAfterJSONLDeletion: Tests recovery from file deletion
- TestMultipleExportsStayConsistent: Tests repeated export integrity

## Follow-up
Created bd-179 epic for remaining integration test gaps (multi-repo sync,
daemon auto-sync, corruption recovery tests).

Closes bd-160
2025-10-29 21:57:15 -07:00
Steve Yegge
84fd068e3f Add TestSymmetricCollision unit test for deterministic collision resolution 2025-10-29 17:49:46 -07:00
Steve Yegge
55f803a7c9 Fix multi-round convergence for N-way collisions (bd-108)
- Add AllocateNextID() public method to SQLiteStorage for cross-package ID allocation
- Enhance handleRename() to handle collision during rename with retry logic
- Fix stale ID map issue by removing deleted IDs from dbByID after rename
- Update edge case tests to use convergence rounds consistently
- All N-way collision tests now pass (TestFiveCloneCollision, TestEdgeCases)
2025-10-29 11:08:28 -07:00
Steve Yegge
ebb425388c bd-109: Add retry logic and race condition handling for N-way collisions
- Added ExecInTransaction helper for atomic database operations
- Added IsUniqueConstraintError to detect UNIQUE constraint violations
- Wrapped RemapCollisions with retry logic (3 attempts with counter sync)
- Enhanced handleRename to detect race conditions where target ID exists
- Added defensive checks for when old ID has been deleted by another clone

Progress: Improves N-way collision handling, though full solution requires
more work (tracked in bd-108). Tests now reach later convergence rounds
before hitting complex collision scenarios.

Amp-Thread-ID: https://ampcode.com/threads/T-2b850a80-f8bd-4e38-b661-e33d1cfa7281
Co-authored-by: Amp <amp@ampcode.com>
2025-10-29 10:45:25 -07:00
Steve Yegge
ff02615f61 Implement content-first idempotent import (bd-98)
- Refactored upsertIssues to match by content hash first, then by ID
- Added buildHashMap, buildIDMap, and handleRename helper functions
- Import now detects and handles renames (same content, different ID)
- Importing same data multiple times is idempotent (reports Unchanged)
- Exported BuildReplacementCache and ReplaceIDReferencesWithCache for reuse
- All 30+ existing import tests pass
- Improved convergence for N-way collision scenarios

Changes:
- internal/importer/importer.go: Content-first matching in upsertIssues
- internal/storage/sqlite/collision.go: Exported helper functions
- internal/storage/sqlite/collision_test.go: Updated function names

Amp-Thread-ID: https://ampcode.com/threads/T-3df96ad8-7c0e-4190-87b5-6d5327718f0a
Co-authored-by: Amp <amp@ampcode.com>
2025-10-28 20:40:36 -07:00
Steve Yegge
b0d28bbdbd Remove spurious collision-related code after ultrathink review
After 2 weeks of collision/stale-data fixes, reviewed all changes to identify
spurious code that is no longer needed after content-hash resolution was implemented.

**Removed:**
1. countReferences() function from collision.go (lines 274-328)
   - Was used for reference-count based collision scoring
   - Completely unused after switching to content-hash based resolution (commit 2e87329)
   - Still exists in duplicates.go for deduplication (different use case)

2. ReferenceScore field from CollisionDetail struct
   - Marked as DEPRECATED but never removed
   - No longer used by ScoreCollisions() which now uses content hashing

3. TestCountReferences and TestCountReferencesWordBoundary tests
   - Tested the now-deleted countReferences() function
   - No longer relevant

**Fixed:**
- Updated CheckpointWAL comments to remove misleading "staleness detection" claim
  - Staleness detection uses metadata (last_import_time), NOT file mtime
  - CheckpointWAL is still valuable for data persistence and WAL size reduction
  - Comments now accurately reflect actual benefits

**Verified:**
- All tests pass (internal/storage/sqlite)
- Content-hash collision resolution still works correctly
- No behavioral changes, just cleanup

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-28 20:07:01 -07:00
Steve Yegge
9644d61de2 Make DetectCollisions read-only (bd-96)
- Add RenameDetail type to track content matches with different IDs
- Remove deletion logic from DetectCollisions (now read-only)
- Create ApplyCollisionResolution to handle all modifications
- Update importer.go to use two-phase approach (detect then apply)
- Fix dependency preservation in RemapCollisions
  - Collect all dependencies before CASCADE DELETE
  - Recreate with updated IDs after remapping
- Add tests: TestDetectCollisionsReadOnly, TestApplyCollisionResolution
- Update collision tests for content-hash scoring behavior
- Create bd-100 to track fixing autoimport tests
2025-10-28 19:16:51 -07:00
Steve Yegge
d9eb273e15 Complete bd-95: Add content-addressable identity (ContentHash field) 2025-10-28 18:57:16 -07:00
Steve Yegge
ceb1b922a9 bd sync: 2025-10-28 17:19:28 2025-10-28 17:19:28 -07:00
Steve Yegge
2e87329cf8 WIP: Implement content-hash based collision resolution (bd-89)
- Replace timestamp-based collision scoring with deterministic content hashing
- Add hashIssueContent() using SHA-256 of all substantive fields
- Modify ScoreCollisions to compare hashes and set RemapIncoming flag
- Update RemapCollisions to handle both directions (remap incoming OR existing)
- Add CollisionDetail.RemapIncoming field to control which version gets remapped
- Add unit tests for hash function and deterministic collision resolution

Status: Hash-based resolution works correctly, but TestTwoCloneCollision still
fails due to missing rename detection. After Clone B resolves collision,
Clone A needs to recognize its issue was remapped to a different ID.

Next: Add content-based rename detection during import to prevent
re-resolving already-resolved collisions.

Progress on bd-86.

Amp-Thread-ID: https://ampcode.com/threads/T-b19b49e8-b52a-463d-b052-8a526a500260
Co-authored-by: Amp <amp@ampcode.com>
2025-10-28 17:11:40 -07:00
Steve Yegge
d47378cfbc Remove skipped tests and unreachable RPC methods (bd-212, bd-213)
bd-212: Delete 3 permanently skipped test functions (~150 LOC)
- TestImportDependencyUpdates (import_collision_test.go)
- TestImportChainDependencies (import_collision_test.go)
- TestUpdateDependencyReferences (collision_test.go)

bd-213: Remove 4 unreachable RPC methods (~80 LOC)
- Server.GetLastImportTime
- Server.SetLastImportTime
- Server.findJSONLPath
- Client.Import

All tests pass. Phase 1 dead code cleanup continues.
2025-10-27 20:52:52 -07:00
Steve Yegge
298d559407 Remove unreachable utility functions (bd-224, bd-214)
- Remove duplicate computeIssueContentHash from sqlite/hash.go
- Remove FileUsed() from internal/config/config.go
- Remove verifyIssueOpen() test helper from git_sync_test.go
- Remove unimplemented SummarizeTier2 and all tier2 infrastructure from haiku.go

Removes ~120 LOC of dead code identified by deadcode analyzer.

Amp-Thread-ID: https://ampcode.com/threads/T-5f150c35-8d67-4dae-bb92-a7b5887d649d
Co-authored-by: Amp <amp@ampcode.com>
2025-10-27 20:45:59 -07:00
Steve Yegge
db1458bfed Fix bd-206: Handle status transitions and closed_at constraint
- Updated manageClosedAt to handle both string and types.Status type assertions
- Added equalTime function for comparing timestamps in import change detection
- Added tests for open→closed and closed→open transitions
- Added comment clarifying closed_at is managed automatically

The bug occurred when UpdateIssue received types.Status instead of string,
causing manageClosedAt to skip setting closed_at when status changed to closed.

Amp-Thread-ID: https://ampcode.com/threads/T-ee774f6d-3b90-4311-976d-60c8dd8fe677
Co-authored-by: Amp <amp@ampcode.com>
2025-10-27 19:14:46 -07:00
Steve Yegge
49dac2b767 Fix test failures: add missing issue_prefix config and use valid bd- prefixes
- Add SetConfig('issue_prefix', 'bd') to collision tests (bd-166)
- Update test cases to use 'bd-' prefix instead of invalid custom IDs (bd-177)
- Fixes 5 test failures in TestDetectCollisions, TestScoreCollisions, TestRemapCollisions, TestCreateIssues

All tests now pass.

Amp-Thread-ID: https://ampcode.com/threads/T-b2413b0e-2720-45b1-9b3d-acaa7d4cf9b4
Co-authored-by: Amp <amp@ampcode.com>
2025-10-27 13:11:45 -07:00
Steve Yegge
d2989dd0f3 Merge main into PR #160 - combine reverse mode with substring bugfix
Amp-Thread-ID: https://ampcode.com/threads/T-b2413b0e-2720-45b1-9b3d-acaa7d4cf9b4
Co-authored-by: Amp <amp@ampcode.com>
2025-10-27 13:07:12 -07:00
David Laing
8c2679a80e Fix substring bug in dependency tree cycle detection (#159)
* Add .worktrees/ to .gitignore

Prevents git worktree contents from being tracked in the repository.

* Fix substring bug in dependency tree cycle detection

The cycle detection in GetDependencyTree() was using a simple substring
match which incorrectly flagged valid nodes as cycles. For example,
"bd-1" would be blocked because "bd-10" contains "bd-1" as a substring.

This bug affects any beads project where issue IDs contain each other as
substrings (BD-1/BD-10, ISSUE-1/ISSUE-10, etc).

Changed from:
  AND t.path NOT LIKE '%' || i.id || '%'

To delimiter-aware checks that respect the → separator:
  AND t.path != i.id
  AND t.path NOT LIKE i.id || '→%'
  AND t.path NOT LIKE '%→' || i.id || '→%'
  AND t.path NOT LIKE '%→' || i.id

This ensures we only match complete issue IDs, not substrings.

Added TestGetDependencyTree_SubstringBug to demonstrate and prevent
regression of this issue. The test creates a chain from bd-10 to bd-1
and verifies all nodes appear in the dependency tree.

Discovered while testing dependency tree visualization with bd-1/bd-10.
2025-10-27 12:51:41 -07:00
Steve Yegge
68ffb9ed40 Complete bd-175, bd-176, bd-177: Memory tests, corruption docs, prefix validation
- bd-175: Added comprehensive test coverage for internal/storage/memory backend
  - All CRUD operations, dependencies, labels, comments
  - Thread safety with race detection
  - LoadFromIssues and counter sync
  - Fixed batch duplicate detection

- bd-176: Documented corruption vs collision distinction
  - Added FAQ entry explaining logical vs physical corruption
  - Updated TROUBLESHOOTING with clear guidance
  - Clarified when to use collision resolution vs reimport

- bd-177: Added prefix validation in SQLite mode
  - Validates explicit IDs match configured prefix
  - Works in both CreateIssue and CreateIssues
  - Comprehensive tests for single and batch operations
2025-10-27 11:29:08 -07:00
David Laing
dd8f51c433 feat: add reverse mode to dependency tree traversal
- Add reverse parameter to GetDependencyTree interface
- Implement reverse SQL traversal (dependents vs dependencies)
- Add comprehensive test for reverse mode (TDD: test-first approach)
- Update existing test calls with reverse=false for backward compatibility

Reverse mode inverts tree direction to show dependents instead of dependencies:
- Normal: JOIN dependencies d ON i.id = d.depends_on_id (traverse UP)
- Reverse: JOIN dependencies d ON i.id = d.issue_id (traverse DOWN)

All storage tests passing. No regressions.
2025-10-27 09:25:57 +00: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
648ecfafe7 Address gosec security warnings (bd-102)
- Enable gosec linter in .golangci.yml
- Tighten file permissions: 0755→0750 for directories, 0644→0600 for configs
- Git hooks remain 0700 (executable, user-only access)
- Add #nosec comments for safe cases with justifications:
  - G204: Safe subprocess launches (git show, bd daemon)
  - G304: File inclusions with controlled paths
  - G201: SQL formatting with controlled column names
  - G115: Integer conversions with controlled values

All gosec warnings resolved (20→0). All tests passing.

Amp-Thread-ID: https://ampcode.com/threads/T-d7166b9e-cbbe-4c7b-9e48-3df36b20f0d0
Co-authored-by: Amp <amp@ampcode.com>
2025-10-26 22:48:19 -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
09e881022e Fix bd-166: Prevent duplicate issues with wrong prefix
Critical fix for silent data corruption where database created 173
duplicate issues with wrong prefix (beads- instead of bd-).

Root cause: When issue_prefix config was missing, CreateIssue fell
back to deriving prefix from database filename (beads.db → 'beads'),
while auto-import imported bd- issues from git with SkipPrefixValidation.
This created duplicates.

Changes:
1. Removed derivePrefixFromPath() - never derive prefix from filename
2. CreateIssue/CreateIssues now REJECT if issue_prefix config missing
   - Fail-fast with clear error message
3. Auto-import now SETS issue_prefix from first imported issue if missing
   - Handles fresh clone scenario safely
4. Added newTestStore() helper that sets issue_prefix for tests
5. Updated test setup in multiple files to prevent test failures

Follow-ups filed: bd-167, bd-168, bd-169

Closes bd-166

Amp-Thread-ID: https://ampcode.com/threads/T-b2ee0738-b90b-40ef-ae44-f2d93729842c
Co-authored-by: Amp <amp@ampcode.com>
2025-10-26 21:55:01 -07:00
Steve Yegge
a02729ea57 Complete bd-164: Fix timestamp-only export deduplication
- Add export_hashes table to track last exported content state
- Implement GetExportHash/SetExportHash in storage interface
- Update shouldSkipExport to use export_hashes instead of dirty_issues
- Call SetExportHash after successful export
- Clean up dirty_issues table (remove content_hash column)
- Simplify MarkIssueDirty functions (no longer compute hashes)
- Update markIssuesDirtyTx signature (remove store parameter)

Testing:
- Timestamp-only updates are skipped during export ✓
- Real content changes trigger export ✓
- export_hashes table populated correctly ✓

Fixes bd-159, bd-164
2025-10-26 20:35:37 -07:00