use assert_cmd::Command; use assert_fs::TempDir; use assert_fs::fixture::{PathChild, PathCreateDir}; use std::fs; use std::path::{Path, PathBuf}; const BIN_NAME: &str = env!("CARGO_BIN_EXE_worklane"); /// The ticket under edit, the one it points at, and one that is already done. const GATED: &str = "641e3d5c-1b0e-4d2f-9a7e-3c8b5f0a2d61"; const BLOCKER: &str = "b1b2c3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d"; const FIXED: &str = "f1f2f3f4-5a6b-4c7d-8e9f-0a1b2c3d4e5f"; fn setup_worklane(temp: &TempDir) -> PathBuf { let worklane = temp.child(".worklane"); worklane.create_dir_all().unwrap(); for dir in ["backlog", "committed", "reviewing", "done"] { worklane.child(dir).create_dir_all().unwrap(); } worklane.path().to_path_buf() } fn slug(title: &str) -> String { title .to_lowercase() .chars() .filter(|c| c.is_alphanumeric() || *c == ' ' || *c == '-' || *c == '_') .map(|c| if c == ' ' { '-' } else { c }) .collect() } /// A ticket with a ticked criterion and a section the tool knows nothing about, so /// every test can check that recording a relation leaves both exactly as they were. fn create_ticket(worklane: &Path, status: &str, title: &str, uuid: &str) -> PathBuf { let path = worklane .join(status) .join(format!("{}_{}.md", uuid, slug(title))); fs::write( &path, format!( "# {}\n\ \n\ ## Description\n\ Prose.\n\ \n\ ## Acceptance Criteria\n\ - [x] Crit one\n\ \n\ ## Implementation Plan\n\ 1. Step one\n\ \n\ ## Notes\n\ A handwritten note the tool knows nothing about.\n\ \n\ ## Metadata\n\ \n\ - **ID**: {}\n\ - **Priority**: 3\n\ - **Tags**: alpha\n\ - **Due**: _Not set_\n\ - **Owner**: alice\n\ - **Created At**: 2026-08-21 02:10:17\n\ - **Status**: {}\n", title, uuid, status ), ) .unwrap(); path } /// The three tickets every test starts from: the one being edited, one it can wait on, /// and one in done. fn board(temp: &TempDir) -> PathBuf { let worklane = setup_worklane(temp); create_ticket(&worklane, "backlog", "The gated one", GATED); create_ticket(&worklane, "backlog", "The blocker", BLOCKER); create_ticket(&worklane, "done", "The old fix", FIXED); worklane } fn run(temp: &TempDir, args: &[&str]) -> std::process::Output { let mut cmd = Command::cargo_bin(BIN_NAME).unwrap(); cmd.current_dir(temp.path()).args(args); cmd.assert().get_output().clone() } fn stdout(out: &std::process::Output) -> String { String::from_utf8_lossy(&out.stdout).to_string() } fn find(worklane: &Path, uuid: &str) -> PathBuf { for status in ["backlog", "committed", "reviewing", "done"] { let dir = worklane.join(status); for entry in fs::read_dir(&dir).unwrap().filter_map(|e| e.ok()) { if entry.file_name().to_string_lossy().starts_with(uuid) { return entry.path(); } } } panic!("no file for ticket {uuid}"); } fn ticket(worklane: &Path, uuid: &str) -> String { fs::read_to_string(find(worklane, uuid)).unwrap() } /// All three tiers, since the target is a ticket argument like any other: a uuid /// prefix, a title substring, and a substring reaching the middle of the filename. #[test] fn a_target_resolves_by_uuid_prefix_title_or_filename() { for search in ["b1b2", "blocker", "4a7b"] { let temp = TempDir::new().unwrap(); let worklane = board(&temp); let out = run(&temp, &["relate", GATED, "--blocked-by", search]); assert!(out.status.success(), "{search}: {}", String::from_utf8_lossy(&out.stderr)); assert!( ticket(&worklane, GATED).contains(&format!("- blocked by {}", BLOCKER)), "{search}: {}", ticket(&worklane, GATED) ); } } #[test] fn every_kind_is_recorded_under_its_own_label() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); let out = run( &temp, &[ "relate", GATED, "--blocked-by", BLOCKER, "--regression-of", FIXED, "--relates-to", "old fix", ], ); assert!(out.status.success()); let content = ticket(&worklane, GATED); assert!(content.contains(&format!("- blocked by {}", BLOCKER)), "{content}"); assert!(content.contains(&format!("- regression of {}", FIXED)), "{content}"); assert!(content.contains(&format!("- relates to {}", FIXED)), "{content}"); // Each kind named once in the report, whatever the order of the flags. let reported = stdout(&out); for kind in ["blocked by", "regression of", "relates to"] { assert!(reported.contains(kind), "{reported}"); } } /// The kinds are flags, so anything else never reaches the file: clap refuses it with /// a usage error, exit code 2, and nothing is written. #[test] fn an_unknown_kind_is_a_usage_error() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); let before = ticket(&worklane, GATED); let out = run(&temp, &["relate", GATED, "--depends-on", BLOCKER]); assert_eq!(out.status.code(), Some(2), "{}", stdout(&out)); assert_eq!(ticket(&worklane, GATED), before); } /// A bare `relate ` is a usage error too, not a silent no-op, the same way a /// bare `set` and a bare `append` are. #[test] fn a_relate_with_no_kind_is_a_usage_error() { let temp = TempDir::new().unwrap(); board(&temp); assert_eq!(run(&temp, &["relate", GATED]).status.code(), Some(2)); } /// Between the plan and the metadata, created for a ticket written before the section /// existed, and behind a handwritten section rather than in front of it. #[test] fn the_section_is_created_in_its_place() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); run(&temp, &["relate", GATED, "--blocked-by", BLOCKER]); let content = ticket(&worklane, GATED); let at = |heading: &str| content.find(heading).unwrap_or_else(|| panic!("{heading}")); assert!(at("## Implementation Plan") < at("## Relations"), "{content}"); assert!(at("## Notes") < at("## Relations"), "{content}"); assert!(at("## Relations") < at("## Metadata"), "{content}"); } /// The full uuid, not the seven characters `ls` prints, which is what makes the link /// survive a rename of the target and stay unambiguous as the board grows. #[test] fn the_stored_target_is_the_full_uuid() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); run(&temp, &["relate", GATED, "--blocked-by", BLOCKER]); assert!( ticket(&worklane, GATED).contains(&format!("- blocked by {}\n", BLOCKER)), "{}", ticket(&worklane, GATED) ); run(&temp, &["set", BLOCKER, "--title", "Renamed entirely"]); let shown = stdout(&run(&temp, &["show", GATED])); assert!(shown.contains("Renamed entirely"), "{shown}"); } #[test] fn a_ticket_cannot_relate_to_itself() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); let before = ticket(&worklane, GATED); let out = run(&temp, &["relate", GATED, "--relates-to", "gated"]); assert!(!out.status.success()); assert!( String::from_utf8_lossy(&out.stderr).contains("cannot relate to itself"), "{}", String::from_utf8_lossy(&out.stderr) ); assert_eq!(ticket(&worklane, GATED), before); } #[test] fn a_relation_already_held_reports_no_change_and_writes_nothing() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); run(&temp, &["relate", GATED, "--blocked-by", BLOCKER]); let before = ticket(&worklane, GATED); let out = run(&temp, &["relate", GATED, "--blocked-by", BLOCKER]); assert!(out.status.success()); assert!(stdout(&out).contains("No changes"), "{}", stdout(&out)); assert_eq!(ticket(&worklane, GATED), before, "the relation was recorded twice"); } /// One direction is stored. The inverse is derived by a scan, so the ticket at the /// other end is not touched at all. #[test] fn only_the_ticket_named_is_written() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); let before = ticket(&worklane, BLOCKER); run(&temp, &["relate", GATED, "--blocked-by", BLOCKER]); assert_eq!(ticket(&worklane, BLOCKER), before); assert!(!ticket(&worklane, BLOCKER).contains("Relations")); } /// The tick, the handwritten section and the prose are what a regenerated file would /// lose, and the section is spliced in rather than rewritten around them. #[test] fn relate_leaves_everything_it_was_not_asked_about_alone() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); run(&temp, &["relate", GATED, "--blocked-by", BLOCKER]); let content = ticket(&worklane, GATED); assert!(content.contains("- [x] Crit one"), "the tick was lost: {content}"); assert!( content.contains("## Notes\nA handwritten note the tool knows nothing about.\n"), "the unknown section was lost: {content}" ); assert!(content.contains("1. Step one"), "{content}"); assert!(content.contains("- **Owner**: alice"), "{content}"); } /// The mark each kind prints before the id. Written out rather than imported: these /// tests drive the binary, so they see only its output. /// /// The cross is the one a held-up card already carries, since both say the same word. const BLOCKED_MARK: &str = "\u{d7}"; const RELATES_MARK: &str = "\u{2192}"; /// And the mark for the status of the ticket the row names, which follows the kind: a /// circle filling up as the target moves through the flow. const BACKLOG_MARK: &str = "\u{25cb}"; const DONE_MARK: &str = "\u{25cf}"; /// A target the board no longer holds has no status, and `?` holds the column so the id /// does not move. const NO_STATUS_MARK: &str = "?"; /// The kind, the short id and the title, so the section reads without a second lookup. #[test] fn show_renders_the_kind_the_short_id_and_the_title() { let temp = TempDir::new().unwrap(); board(&temp); run(&temp, &["relate", GATED, "--blocked-by", BLOCKER]); let shown = stdout(&run(&temp, &["show", GATED])); assert!(shown.contains("Relations"), "{shown}"); assert!( shown.contains(&format!("blocked by {BLOCKED_MARK} {BACKLOG_MARK} (b1b2c3d) The blocker")), "{shown}" ); // Never the stored line: a bare uuid says nothing about what it points at. assert!(!shown.contains(BLOCKER), "{shown}"); } /// Derived by scanning, since the file at this end holds nothing at all. #[test] fn show_lists_the_relation_the_other_ticket_holds() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); run(&temp, &["relate", GATED, "--blocked-by", BLOCKER]); run(&temp, &["relate", GATED, "--relates-to", FIXED]); let shown = stdout(&run(&temp, &["show", BLOCKER])); assert!( shown.contains(&format!("blocks {BLOCKED_MARK} {BACKLOG_MARK} (641e3d5) The gated one")), "{shown}" ); assert!(!ticket(&worklane, BLOCKER).contains("Relations")); // Two kinds on one ticket, each with its own mark, and the second mark is the state // of the ticket at the far end: the old fix is in done and the blocker is not. That // is the pair the block is for, which kind of edge and whether it is finished. let shown = stdout(&run(&temp, &["show", GATED])); assert!( shown.contains(&format!("blocked by {BLOCKED_MARK} {BACKLOG_MARK} (b1b2c3d) The blocker")), "{shown}" ); assert!( shown.contains(&format!("relates to {RELATES_MARK} {DONE_MARK} (f1f2f3f) The old fix")), "{shown}" ); // `relates to` is symmetric, so it reads the same way from either end. let shown = stdout(&run(&temp, &["show", FIXED])); assert!( shown.contains(&format!( "relates to {RELATES_MARK} {BACKLOG_MARK} (641e3d5) The gated one" )), "{shown}" ); } #[test] fn a_target_that_no_longer_exists_renders_as_missing() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); run(&temp, &["relate", GATED, "--blocked-by", BLOCKER]); fs::remove_file(find(&worklane, BLOCKER)).unwrap(); let shown = stdout(&run(&temp, &["show", GATED])); assert!( shown.contains(&format!("blocked by {BLOCKED_MARK} {NO_STATUS_MARK} (b1b2c3d) _missing_")), "{shown}" ); } /// The section is the one part of a ticket read back by machine, so a line nobody can /// parse is an error naming the ticket rather than a line quietly skipped. #[test] fn a_line_that_is_not_a_relation_is_an_error() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); let path = find(&worklane, GATED); let content = fs::read_to_string(&path).unwrap().replace( "## Metadata", &format!("## Relations\n- depends on {}\n\n## Metadata", BLOCKER), ); fs::write(&path, content).unwrap(); let out = run(&temp, &["show", GATED]); assert!(!out.status.success()); let stderr = String::from_utf8_lossy(&out.stderr); assert!(stderr.contains("is not a relation"), "{stderr}"); assert!(stderr.contains("The gated one"), "{stderr}"); } // --------------------------------------------------------------- clearing -- /// Two blockers, one taken off by name. The other survives, which is the whole reason /// `--clear` names the target and not just the kind: a ticket can hold several of one /// kind, and emptying all of them is not usually what is wanted. #[test] fn a_relation_is_taken_off_by_its_kind_and_its_target() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); run( &temp, &[ "relate", GATED, "--blocked-by", BLOCKER, "--blocked-by", FIXED, ], ); let out = run(&temp, &["relate", GATED, "--clear", "blocked-by", BLOCKER]); assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr)); assert!(stdout(&out).contains("Cleared blocked by"), "{}", stdout(&out)); let content = ticket(&worklane, GATED); assert!( !content.contains(BLOCKER), "the cleared relation is still there: {content}" ); assert!( content.contains(&format!("- blocked by {}", FIXED)), "the other one went too: {content}" ); } /// Both spellings of the kind, because both are in front of the reader: `blocked-by` is /// the flag that recorded it and `blocked by` is what `show` prints and what the file /// stores. Refusing the form the tool itself prints would be a trap. #[test] fn the_kind_takes_the_flag_spelling_and_the_label_spelling() { for kind in ["blocked-by", "blocked by", "Blocked-By"] { let temp = TempDir::new().unwrap(); let worklane = board(&temp); run(&temp, &["relate", GATED, "--blocked-by", BLOCKER]); let out = run(&temp, &["relate", GATED, "--clear", kind, BLOCKER]); assert!(out.status.success(), "{kind}: {}", String::from_utf8_lossy(&out.stderr)); assert!(!ticket(&worklane, GATED).contains(BLOCKER), "{kind} did not clear it"); } } /// The target is a ticket argument like any other, so it resolves by title too. #[test] fn a_cleared_target_resolves_by_title() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); run(&temp, &["relate", GATED, "--blocked-by", BLOCKER]); let out = run(&temp, &["relate", GATED, "--clear", "blocked-by", "blocker"]); assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr)); assert!(!ticket(&worklane, GATED).contains(BLOCKER)); } /// A relation the ticket does not hold is the state the caller asked for, so it reports /// no change rather than failing. The target resolves; the edge is simply not there. #[test] fn clearing_a_relation_the_ticket_does_not_hold_reports_no_change() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); run(&temp, &["relate", GATED, "--blocked-by", BLOCKER]); let before = ticket(&worklane, GATED); // A kind it does not hold at all, and a target it holds under another kind. for args in [["relates-to", BLOCKER], ["blocked-by", FIXED]] { let out = run(&temp, &["relate", GATED, "--clear", args[0], args[1]]); assert!(out.status.success(), "{args:?}: {}", String::from_utf8_lossy(&out.stderr)); assert!(stdout(&out).contains("No changes"), "{args:?}: {}", stdout(&out)); assert_eq!(ticket(&worklane, GATED), before, "{args:?} wrote something"); } } /// A search naming nothing at all is a typo, not a state to report. Reporting no change /// for it would swallow it, which is the one thing the no-change rule must not do. #[test] fn clearing_a_target_that_names_nothing_is_an_error() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); run(&temp, &["relate", GATED, "--blocked-by", BLOCKER]); let before = ticket(&worklane, GATED); let out = run(&temp, &["relate", GATED, "--clear", "blocked-by", "9999zzzz"]); assert!(!out.status.success(), "{}", stdout(&out)); assert_eq!(ticket(&worklane, GATED), before); } /// The inverse is derived by a scan rather than stored, so taking the stored line off is /// what takes it off both ends. The other ticket's own file was never touched either way. #[test] fn the_derived_inverse_goes_with_the_stored_line() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); let untouched = ticket(&worklane, BLOCKER); run(&temp, &["relate", GATED, "--blocked-by", BLOCKER]); let shown = stdout(&run(&temp, &["show", BLOCKER])); assert!(shown.contains("blocks"), "the inverse was never derived: {shown}"); run(&temp, &["relate", GATED, "--clear", "blocked-by", BLOCKER]); let after = stdout(&run(&temp, &["show", BLOCKER])); assert!(!after.contains("blocks"), "the inverse outlived the stored line: {after}"); assert_eq!(ticket(&worklane, BLOCKER), untouched, "the other ticket was written to"); } /// The case most likely to need clearing, and the only one no search of the board can /// reach: the target's ticket is gone, so the prefix tier over the stored targets is what /// finds it. `show` renders it as `_missing_` until it is cleared, and `mv` warns about it /// on every move. #[test] fn a_dangling_relation_can_be_cleared() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); run(&temp, &["relate", GATED, "--blocked-by", BLOCKER]); fs::remove_file(find(&worklane, BLOCKER)).unwrap(); assert!( stdout(&run(&temp, &["show", GATED])).contains("_missing_"), "the fixture is not dangling" ); // By the short id, which is all a reader has once the title is gone. let out = run(&temp, &["relate", GATED, "--clear", "blocked-by", &BLOCKER[..7]]); assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr)); assert!(!ticket(&worklane, GATED).contains(BLOCKER), "{}", ticket(&worklane, GATED)); assert!(!stdout(&run(&temp, &["show", GATED])).contains("_missing_")); } /// A prefix short enough to reach two stored targets names the candidates rather than /// guessing, the way an ambiguous ticket search does, and writes nothing. #[test] fn an_ambiguous_prefix_over_the_stored_targets_names_the_candidates() { const ONE: &str = "aaaa1111-0000-4000-8000-000000000000"; const TWO: &str = "aaaa2222-0000-4000-8000-000000000000"; let temp = TempDir::new().unwrap(); let worklane = board(&temp); create_ticket(&worklane, "backlog", "Twin one", ONE); create_ticket(&worklane, "backlog", "Twin two", TWO); run(&temp, &["relate", GATED, "--blocked-by", ONE, "--blocked-by", TWO]); let before = ticket(&worklane, GATED); let out = run(&temp, &["relate", GATED, "--clear", "blocked-by", "aaaa"]); assert!(!out.status.success(), "{}", stdout(&out)); // The stored-target tier and not the board search, which would find the same two // tickets by their own uuid prefix and report them the same way. The wording is what // tells the two apart, so it is what this asserts. let reason = String::from_utf8_lossy(&out.stderr); assert!( reason.contains("'blocked by' relations on"), "the board answered instead: {reason}" ); assert!(reason.contains(&ONE[..7]) && reason.contains(&TWO[..7]), "{reason}"); assert_eq!(ticket(&worklane, GATED), before); } /// The last edge leaves the placeholder `add` writes, not an empty body, so the section /// can be written to again without the placeholder ending up above what follows it. #[test] fn clearing_the_last_relation_leaves_the_placeholder() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); run(&temp, &["relate", GATED, "--blocked-by", BLOCKER]); run(&temp, &["relate", GATED, "--clear", "blocked-by", BLOCKER]); let content = ticket(&worklane, GATED); assert!( content.contains( "## Relations _No relations._ " ), "{content}" ); // And it is written to again without the placeholder being left behind. run(&temp, &["relate", GATED, "--relates-to", FIXED]); let again = ticket(&worklane, GATED); assert!(again.contains(&format!("- relates to {}", FIXED)), "{again}"); assert!( !again.contains("_No relations._"), "the placeholder outlived the edge: {again}" ); } /// The same file surgery `relate` already does, so the tick, the handwritten section and /// the prose survive a clear the way they survive a record. #[test] fn clearing_leaves_everything_it_was_not_asked_about_alone() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); run( &temp, &[ "relate", GATED, "--blocked-by", BLOCKER, "--relates-to", FIXED, ], ); run(&temp, &["relate", GATED, "--clear", "blocked-by", BLOCKER]); let content = ticket(&worklane, GATED); assert!(content.contains("- [x] Crit one"), "the tick was lost: {content}"); assert!( content.contains("## Notes\nA handwritten note the tool knows nothing about.\n"), "the unknown section was lost: {content}" ); assert!(content.contains("1. Step one"), "{content}"); assert!(content.contains("- **Owner**: alice"), "{content}"); assert!(content.contains("- **Status**: backlog"), "{content}"); } /// One call does both, and each half reports itself in its own words. #[test] fn one_call_records_and_clears_different_relations() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); run(&temp, &["relate", GATED, "--blocked-by", BLOCKER]); let out = run( &temp, &[ "relate", GATED, "--clear", "blocked-by", BLOCKER, "--relates-to", FIXED, ], ); assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr)); let reported = stdout(&out); assert!(reported.contains("Recorded relates to"), "{reported}"); assert!(reported.contains("Cleared blocked by"), "{reported}"); let content = ticket(&worklane, GATED); assert!(!content.contains(BLOCKER), "{content}"); assert!(content.contains(&format!("- relates to {}", FIXED)), "{content}"); } /// Recording and clearing the same relation in one call is refused outright, the way /// `set` refuses a field it is also replacing: nothing is written rather than one of the /// two silently winning. /// /// It has to be caught on what the call *asked* for and not on what it would write. A /// relation already in the file is not among the additions, so comparing against those /// would let this call quietly remove one. #[test] fn recording_and_clearing_the_same_relation_is_refused() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); run(&temp, &["relate", GATED, "--blocked-by", BLOCKER]); let before = ticket(&worklane, GATED); let out = run( &temp, &[ "relate", GATED, "--blocked-by", BLOCKER, "--clear", "blocked-by", BLOCKER, ], ); assert!(!out.status.success(), "{}", stdout(&out)); assert!( String::from_utf8_lossy(&out.stderr).contains("nothing was written"), "{}", String::from_utf8_lossy(&out.stderr) ); assert_eq!(ticket(&worklane, GATED), before, "the relation was removed anyway"); } /// A kind that is not one of the three is refused before the ticket is resolved, so /// nothing is written. Exit 1 rather than clap's 2: the value is one of a pair clap /// cannot type apart, so the kind is parsed by `RelateArgs::cleared`. #[test] fn an_unknown_kind_in_a_clear_is_refused() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); run(&temp, &["relate", GATED, "--blocked-by", BLOCKER]); let before = ticket(&worklane, GATED); let out = run(&temp, &["relate", GATED, "--clear", "depends-on", BLOCKER]); assert!(!out.status.success(), "{}", stdout(&out)); let reason = String::from_utf8_lossy(&out.stderr); assert!(reason.contains("not a relation kind"), "{reason}"); // The message names the three, in the spelling the flags and the completions use. for kind in ["blocked-by", "regression-of", "relates-to"] { assert!(reason.contains(kind), "{reason}"); } assert_eq!(ticket(&worklane, GATED), before); } /// `--clear` takes exactly two values per occurrence, so clap refuses an odd number with /// a usage error and nothing reaches the handler. #[test] fn a_clear_with_one_value_is_a_usage_error() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); let before = ticket(&worklane, GATED); let out = run(&temp, &["relate", GATED, "--clear", "blocked-by"]); assert_eq!(out.status.code(), Some(2), "{}", stdout(&out)); assert_eq!(ticket(&worklane, GATED), before); } /// The far end already stores it, so the edge is already recorded: `show` derives it onto /// this ticket by scanning. A line here would be the same edge on two files, which /// 4179958 decided against and nothing enforced until 03bdc76. #[test] fn a_relates_to_the_target_already_stores_is_not_stored_again() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); run(&temp, &["relate", BLOCKER, "--relates-to", GATED]); let before = ticket(&worklane, GATED); let out = run(&temp, &["relate", GATED, "--relates-to", BLOCKER]); assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr)); assert!(stdout(&out).contains("No changes"), "{}", stdout(&out)); assert_eq!(ticket(&worklane, GATED), before, "the mirror was stored anyway"); // Still shown, since it was recorded at the other end. let shown = stdout(&run(&temp, &["show", GATED])); assert_eq!(shown.matches("relates to").count(), 1, "{shown}"); } /// A board that already holds both directions draws the edge once. The refusal above /// stops it recurring; this is what repairs a ticket that already has it, without an edit. #[test] fn a_relates_to_stored_at_both_ends_is_drawn_once() { let temp = TempDir::new().unwrap(); let worklane = board(&temp); // Both lines written directly, which is the state a board recorded before the refusal // is in. The CLI will not produce it any more, so nothing else can set this up. for (holder, target) in [(GATED, BLOCKER), (BLOCKER, GATED)] { let path = find(&worklane, holder); let content = fs::read_to_string(&path).unwrap().replace( "## Metadata", &format!("## Relations\n- relates to {target}\n\n## Metadata"), ); fs::write(&path, content).unwrap(); } let shown = stdout(&run(&temp, &["show", GATED])); assert_eq!(shown.matches("relates to").count(), 1, "the edge is drawn twice:\n{shown}"); assert_eq!(shown.matches(&BLOCKER[..7]).count(), 1, "{shown}"); // And from the other end, which stores its own line and derives this one. let far = stdout(&run(&temp, &["show", BLOCKER])); assert_eq!(far.matches("relates to").count(), 1, "{far}"); } /// Only where the row reads the same. Two tickets each blocking the other is two facts, /// and the block says both: `blocked by` from this end, `blocks` from the other. #[test] fn a_mutual_block_is_still_drawn_from_both_ends() { let temp = TempDir::new().unwrap(); board(&temp); run(&temp, &["relate", GATED, "--blocked-by", BLOCKER]); let out = run(&temp, &["relate", BLOCKER, "--blocked-by", GATED]); assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr)); assert!( !stdout(&out).contains("No changes"), "the second was refused: {}", stdout(&out) ); let shown = stdout(&run(&temp, &["show", GATED])); assert!(shown.contains("blocked by"), "{shown}"); assert!(shown.contains("blocks"), "the derived direction was dropped:\n{shown}"); } /// The same for the other asymmetric kind, whose inverse label also differs from its own. #[test] fn a_mutual_regression_is_still_drawn_from_both_ends() { let temp = TempDir::new().unwrap(); board(&temp); run(&temp, &["relate", GATED, "--regression-of", BLOCKER]); run(&temp, &["relate", BLOCKER, "--regression-of", GATED]); let shown = stdout(&run(&temp, &["show", GATED])); assert!(shown.contains("regression of"), "{shown}"); assert!( shown.contains("regressed by"), "the derived direction was dropped:\n{shown}" ); }