You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
2.8 KiB
Markdown
96 lines
2.8 KiB
Markdown
---
|
|
# nbd-56ho
|
|
title: Tests for nbd graph command
|
|
status: completed
|
|
type: task
|
|
priority: normal
|
|
created_at: 2026-03-10T23:30:31Z
|
|
updated_at: 2026-03-10T23:30:32Z
|
|
blocked_by:
|
|
- nbd-d9dh
|
|
---
|
|
|
|
Add comprehensive unit and integration tests for the `nbd graph` command introduced across tickets `9c9ebe`, `e14172`, and `9ad11f`.
|
|
|
|
## Unit tests (src/tests.rs)
|
|
|
|
These test `graph.rs` and the rendering helpers in `display.rs` in isolation using in-memory `Ticket` values (no temp files needed).
|
|
|
|
### graph.rs tests
|
|
|
|
```
|
|
test_graph_build_empty
|
|
TicketGraph::build(&[]) has no nodes.
|
|
|
|
test_graph_roots_no_deps
|
|
Two tickets with no dependencies → both appear in roots().
|
|
|
|
test_graph_roots_with_chain
|
|
Ticket B depends on A → only A is a root.
|
|
|
|
test_graph_subtree_linear
|
|
A → B → C; subtree("a") returns ["a", "b", "c"] (DFS order).
|
|
|
|
test_graph_subtree_single
|
|
subtree of a leaf returns just that ID.
|
|
|
|
test_graph_subtree_cycle
|
|
A.deps = [B], B.deps = [A] → subtree("a") returns both without panic/infinite loop.
|
|
|
|
test_graph_to_json_nodes_and_edges
|
|
Three tickets with two edges → JSON "nodes" has 3 entries, "edges" has 2.
|
|
```
|
|
|
|
### display.rs tests
|
|
|
|
```
|
|
test_format_graph_single_ticket
|
|
One ticket, no deps → output contains the ID, status, and title on one line; no connector chars.
|
|
|
|
test_format_graph_two_ticket_chain
|
|
A → B; output has A at col 0 and B indented with "└──".
|
|
|
|
test_format_graph_branching
|
|
A has two dependents B and C; B's line uses "├──" and C's uses "└──".
|
|
|
|
test_format_subtree_scope
|
|
A → B, C (unrelated root); format_subtree(graph, "a") does not contain C's ID.
|
|
|
|
test_format_graph_cycle_label
|
|
Cycle present → output contains "[cycle]" and does not repeat infinitely.
|
|
```
|
|
|
|
## Integration tests (tests/integration.rs)
|
|
|
|
Use a real temp directory set up with `cargo run -- init` and tickets created via `cmd_create`.
|
|
|
|
```
|
|
test_graph_empty_store
|
|
`nbd graph` on an empty store produces an empty line (or at least exits 0).
|
|
|
|
test_graph_all_no_deps
|
|
Create two tickets without deps; `nbd graph` output contains both IDs with no indentation.
|
|
|
|
test_graph_chain
|
|
Create A (no deps) and B (--deps A); `nbd graph` output shows A at top level and B indented.
|
|
|
|
test_graph_single_ticket
|
|
`nbd graph <id>` for A returns only A and its subtree, not unrelated tickets.
|
|
|
|
test_graph_json_output
|
|
`nbd graph --json` parses as valid JSON with "nodes" and "edges" arrays.
|
|
|
|
test_graph_json_subtree
|
|
`nbd graph <id> --json` returns JSON whose "nodes" array contains only reachable tickets.
|
|
|
|
test_graph_filter
|
|
`nbd graph --filter type=bug` only shows bug tickets and their reachable deps.
|
|
|
|
test_graph_partial_id
|
|
`nbd graph <3-char-prefix>` resolves to the correct ticket (prefix resolution).
|
|
```
|
|
|
|
## Files touched
|
|
- `src/tests.rs` — unit tests for `TicketGraph` and `format_graph` / `format_subtree`
|
|
- `tests/integration.rs` — CLI-level integration tests
|