(t *testing.T)
| 499 | } |
| 500 | |
| 501 | func TestGraphCommand_RootDownstream(t *testing.T) { |
| 502 | tmpDir := createTestTaskFiles(t) |
| 503 | |
| 504 | // Reset flags |
| 505 | graphFormat = "json" |
| 506 | graphExcludeStatus = []string{} |
| 507 | graphRoot = "001" |
| 508 | graphFocus = "" |
| 509 | graphUpstream = false |
| 510 | graphDownstream = true |
| 511 | graphOut = "" |
| 512 | |
| 513 | // Capture stdout |
| 514 | oldStdout := os.Stdout |
| 515 | r, w, _ := os.Pipe() |
| 516 | os.Stdout = w |
| 517 | |
| 518 | // Run command |
| 519 | err := runGraph(graphCmd, []string{tmpDir}) |
| 520 | if err != nil { |
| 521 | t.Fatalf("runGraph failed: %v", err) |
| 522 | } |
| 523 | |
| 524 | // Restore stdout |
| 525 | w.Close() |
| 526 | os.Stdout = oldStdout |
| 527 | |
| 528 | // Read output |
| 529 | var buf bytes.Buffer |
| 530 | buf.ReadFrom(r) |
| 531 | output := buf.String() |
| 532 | |
| 533 | // Parse JSON |
| 534 | var result map[string]any |
| 535 | err = json.Unmarshal([]byte(output), &result) |
| 536 | if err != nil { |
| 537 | t.Fatalf("Failed to parse JSON output: %v", err) |
| 538 | } |
| 539 | |
| 540 | // Verify only downstream tasks are included |
| 541 | nodes, ok := result["nodes"].([]any) |
| 542 | if !ok { |
| 543 | t.Fatal("Expected 'nodes' to be an array") |
| 544 | } |
| 545 | |
| 546 | // Should include: 001 (root), 002, 003, 004 (all depend on 001 directly or indirectly) |
| 547 | // Should NOT include: 005 (no dependency on 001) |
| 548 | if len(nodes) != 4 { |
| 549 | t.Errorf("Expected 4 nodes (001 and its downstream), got %d", len(nodes)) |
| 550 | } |
| 551 | |
| 552 | // Verify 005 is not included |
| 553 | for _, node := range nodes { |
| 554 | nodeMap := node.(map[string]any) |
| 555 | if nodeMap["id"].(string) == "005" { |
| 556 | t.Error("Task 005 should not be included in downstream of 001") |
| 557 | } |
| 558 | } |
nothing calls this directly
no test coverage detected