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.
This commit is contained in:
David Laing
2025-10-27 09:17:07 +00:00
parent 969f3ac03b
commit dd8f51c433
3 changed files with 166 additions and 43 deletions

View File

@@ -25,7 +25,7 @@ type Storage interface {
GetDependents(ctx context.Context, issueID string) ([]*types.Issue, error)
GetDependencyRecords(ctx context.Context, issueID string) ([]*types.Dependency, error)
GetAllDependencyRecords(ctx context.Context) (map[string][]*types.Dependency, error)
GetDependencyTree(ctx context.Context, issueID string, maxDepth int, showAllPaths bool) ([]*types.TreeNode, error)
GetDependencyTree(ctx context.Context, issueID string, maxDepth int, showAllPaths bool, reverse bool) ([]*types.TreeNode, error)
DetectCycles(ctx context.Context) ([][]*types.Issue, error)
// Labels
@@ -53,7 +53,7 @@ type Storage interface {
// Dirty tracking (for incremental JSONL export)
GetDirtyIssues(ctx context.Context) ([]string, error)
GetDirtyIssueHash(ctx context.Context, issueID string) (string, error) // For timestamp-only dedup (bd-164)
ClearDirtyIssues(ctx context.Context) error // WARNING: Race condition (bd-52), use ClearDirtyIssuesByID
ClearDirtyIssues(ctx context.Context) error // WARNING: Race condition (bd-52), use ClearDirtyIssuesByID
ClearDirtyIssuesByID(ctx context.Context, issueIDs []string) error
// Export hash tracking (for timestamp-only dedup, bd-164)