(03bdc76) Draw a symmetric relation once, and refuse the mirror, and bump to 0.32.1
`relate` refused a relation the ticket already held but never looked at what the target held, so both ends of a `relates to` could store a line. `show` then drew the same neighbour twice under the same label, since `RelatesTo` maps to itself in `inverse_label`: one row from the stored line and one derived from the far ticket's mirror of it, indistinguishable. Live on this board, where 8556048 and 8c8a520 each stored the other. Both ends of the fix, because they do different jobs. `relation_rows` drops a derived row that reads exactly like a stored one, which repairs the boards that already hold both directions without an edit. `cmd_relate` refuses to store the mirror in the first place, reporting no change since the edge is already recorded at the far end, which stops it recurring. Neither alone closes it. The dedupe keys on the **label** and the target, not the kind and the target. Two tickets each blocking the other is two facts and the block has to say both, `blocked by` from this end and `blocks` from the other; keying on the kind would fold them into one row and lose half of what the ticket says. Only a symmetric kind can collide with its own stored line, and `RelationKind::is_symmetric` derives that from `label() == inverse_label()` rather than naming `RelatesTo`, so a kind added later answers by construction. The same gate is what keeps the refusal off a cycle: a target holding `blocked by <this>` is not a duplicate. The stored row is the survivor, not the derived one, because it is the line `relate --clear` can address. The consequence is worth knowing and is written down: with both ends holding a line, clearing one leaves the other's, which then draws as the derived row. Correct, since the far end still asserts the relation. 4179958 decided that `relates to` is symmetric and "written once, not onto both files". Nothing enforced it until now. The board's own data is left alone. 8556048 and 8c8a520 still both store the line and the block now draws it once, which is what the criterion asked for. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
0f0767ac00
commit
00a64adca8
@@ -714,3 +714,89 @@ fn a_clear_with_one_value_is_a_usage_error() {
|
||||
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}"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user