--- # nbd-lins title: 'Fix nbd graph : show ancestry path through ticket, not just subtree' status: todo type: bug priority: normal created_at: 2026-03-10T23:30:29Z updated_at: 2026-03-10T23:30:31Z blocked_by: - nbd-l38k --- ## Problem Currently `nbd graph ` renders the subtree **below** the given ticket via dependent edges (tickets blocked by it). After the graph orientation fix (see ticket 668150), `nbd graph ` will render the dependency subtree **below** the given ticket. But the desired behavior for `nbd graph B` (where A depends on B, C, and D) is more specific: > `nbd graph B` should graph up to the root level, down to B, and the rest of the way down from B, but not include siblings like C and D. ## Desired behavior ``` A [todo] High-level goal └── B [todo] Implement feature B └── E [todo] Write unit tests for B ``` - A is shown because it depends on B (ancestor) - C and D are NOT shown (they are sibling dependencies of A, not on the path to B) - E is shown because B depends on E (B's own dependency subtree) ## Algorithm 1. **Ancestors of B**: traverse the `dependents` edges upward (who depends on B, and who depends on those, etc.) — collecting all ancestor tickets 2. **Filtered ancestor tree**: when rendering ancestors, only show the branch that leads toward B — i.e., at each ancestor, only the child that is on the path to B is shown (not siblings like C and D) 3. **B's dependency subtree**: show B and all its dependencies recursively (as per the corrected subtree logic from ticket 668150) ## Implementation approach In `src/graph.rs`: - Add `ancestors(target_id: &str) -> Vec<&str>`: collect all IDs that transitively depend on `target_id` (follow `dependents` edges upward) - Add `ancestry_path_subtree(target_id: &str) -> ???`: returns the combined view — ancestor tree filtered to the path, plus target's dependency subtree In `src/display.rs`: - New or updated `format_subtree()` to render the ancestry+subtree combined view - The ancestry portion must filter children to only show the branch toward the target (not all dependents of each ancestor) In `src/main.rs`: - Update `cmd_graph()` to use the new combined view when an ID is provided ## Edge cases - If B has no dependents (it is itself a root), just show B's dependency subtree (no ancestor section) - If B appears in multiple dependency chains, show all paths to it - Cycle detection still applies (mark revisited nodes with `*`) ## Tests Add integration tests in `tests/integration.rs`: - Create tickets A, B, C, D, E with A depending on B/C/D, and B depending on E - Assert `nbd graph B` output contains A and E but not C and D