Files
worklane/tests/cmd_show.rs
T
Ansho ReiandClaude Opus 5 8013c2b74d (d8e78cd) Clear the clippy warnings, and bump to 0.8.1
`cargo clippy --all-targets` was reporting 96 warnings, 14 of them in the
binary. It is now clean from a cold cache, and the 211 tests still pass.

`clippy --fix` took the mechanical ones: needless borrows, `map_or` that is
`is_some_and`, `push_str` of a single character, manual `split_once`, and
`&PathBuf` parameters in the test fixtures. It also moved the `handlers.rs`
test module to the end of the file, which is what `items_after_test_module`
was pointing at.

Three by hand. `cmd_add` took nine parameters threaded from `main`, and now
takes `AddArgs`, which is how `set`, `append` and `check` already pass theirs;
the handler destructures it so the body reads as before, and `add --help` is
unchanged. The collapsed `if` in `content_trim` needed reindenting, since
`--fix` left its body at the old depth. And the two `split_once` rewrites read
as `.split_once(..).map(|(_, value)| value)` rather than clippy's `.map(|x|
x.1)`.

The two eight-argument `create_ticket` test fixtures keep an
`allow(too_many_arguments)` carrying the reason: the lint is right that
twenty-five positional call sites read as a wall of strings, but replacing them
with a named-field struct is a refactor and not a warning sweep. a34a316 tracks
it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-21 15:37:11 +02:00

681 lines
19 KiB
Rust

use assert_cmd::Command;
use assert_fs::TempDir;
use assert_fs::fixture::{PathChild, PathCreateDir};
use std::fs;
const BIN_NAME: &str = env!("CARGO_BIN_EXE_worklane");
fn setup_worklane(temp: &TempDir) -> std::path::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()
}
/// Same fixture, same trade as `cmd_mv.rs`: positional today, a struct when the call
/// sites in both files are converted together.
#[allow(clippy::too_many_arguments)]
fn create_ticket(
worklane_dir: &std::path::Path,
status: &str,
title: &str,
description: &str,
id: &str,
owner: &str,
due: &str,
tags: &str,
) -> String {
let slug = title
.to_lowercase()
.chars()
.filter(|c| c.is_alphanumeric() || *c == ' ' || *c == '-' || *c == '_')
.map(|c| if c == ' ' { '-' } else { c })
.collect::<String>();
let filename = format!("{}_{}.md", id, slug);
let ticket_body = format!(
"# {}\n\
\n\
## Description\n\
{}\n\
\n\
## Acceptance Criteria\n\
- [ ] test\n\
\n\
## Implementation Plan\n\
- test\n\
\n\
## Metadata\n\
\n\
- **ID**: {}\n\
- **Tags**: {}\n\
- **Due**: {}\n\
- **Owner**: {}\n\
- **Status**: {}\n\
",
title, description, id, tags, due, owner, status
);
fs::write(worklane_dir.join(status).join(&filename), ticket_body).unwrap();
filename
}
fn get_stdout(cmd: &mut Command) -> String {
let assert = cmd.assert();
String::from_utf8(assert.get_output().stdout.clone()).unwrap()
}
fn get_stderr(cmd: &mut Command) -> String {
let assert = cmd.assert();
String::from_utf8(assert.get_output().stderr.clone()).unwrap()
}
#[test]
fn show_displays_ticket_by_full_uuid() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let _filename = create_ticket(
&worklane,
"backlog",
"Test Ticket",
"This is a test ticket description.",
"abc123def456789012345678901234567890",
"alice",
"2026-12-31",
"test",
);
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
cmd.current_dir(temp.path())
.arg("show")
.arg("abc123def456789012345678901234567890")
.assert()
.success();
let stdout = get_stdout(&mut cmd);
assert!(stdout.contains("Test Ticket"));
assert!(stdout.contains("This is a test ticket description."));
assert!(stdout.contains("alice"));
assert!(stdout.contains("2026-12-31"));
assert!(stdout.contains("test"));
}
#[test]
fn show_displays_ticket_by_partial_uuid() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let uuid = "abc123def456789012345678901234567890";
create_ticket(
&worklane,
"backlog",
"Test Ticket",
"This is a test ticket description.",
uuid,
"alice",
"2026-12-31",
"test",
);
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
cmd.current_dir(temp.path())
.arg("show")
.arg("abc123def4567890")
.assert()
.success();
let stdout = get_stdout(&mut cmd);
assert!(stdout.contains("Test Ticket"));
assert!(stdout.contains("This is a test ticket description."));
}
#[test]
fn show_displays_ticket_by_title() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let uuid = "abc123def456789012345678901234567890";
create_ticket(
&worklane,
"backlog",
"Fix Login Bug",
"Users cannot log in.",
uuid,
"bob",
"2026-11-15",
"bug,frontend",
);
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
cmd.current_dir(temp.path())
.arg("show")
.arg("login")
.assert()
.success();
let stdout = get_stdout(&mut cmd);
assert!(stdout.contains("Fix Login Bug"));
assert!(stdout.contains("Users cannot log in."));
assert!(stdout.contains("bob"));
assert!(stdout.contains("2026-11-15"));
}
#[test]
fn show_displays_ticket_by_partial_title() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let uuid = "abc123def456789012345678901234567890";
create_ticket(
&worklane,
"backlog",
"Fix Login Bug",
"Users cannot log in.",
uuid,
"bob",
"2026-11-15",
"bug,frontend",
);
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
cmd.current_dir(temp.path())
.arg("show")
.arg("fix")
.assert()
.success();
let stdout = get_stdout(&mut cmd);
assert!(stdout.contains("Fix Login Bug"));
}
#[test]
fn show_shows_both_uuid_and_title_in_output() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let uuid = "abc123def456789012345678901234567890";
create_ticket(
&worklane,
"backlog",
"Test Ticket",
"Description here.",
uuid,
"charlie",
"2026-09-01",
"test",
);
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
cmd.current_dir(temp.path())
.arg("show")
.arg("test")
.assert()
.success();
let stdout = get_stdout(&mut cmd);
assert!(stdout.contains("abc123def456789012345678901234567890"));
}
#[test]
fn show_fails_for_nonexistent_ticket() {
let temp = TempDir::new().unwrap();
setup_worklane(&temp);
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
cmd.current_dir(temp.path())
.arg("show")
.arg("nonexistent")
.assert()
.failure();
}
#[test]
fn show_asks_for_disambiguation_when_multiple_matches() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let uuid1 = "abc123def456789012345678901234567890";
create_ticket(
&worklane,
"backlog",
"Test Ticket A",
"First test ticket.",
uuid1,
"alice",
"2026-12-31",
"test",
);
let uuid2 = "fedcba0987654321fedcba09876543210987654321";
create_ticket(
&worklane,
"backlog",
"Test Ticket B",
"Second test ticket.",
uuid2,
"bob",
"2026-10-15",
"test",
);
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
cmd.current_dir(temp.path()).arg("show").arg("est");
let stderr = get_stderr(&mut cmd);
assert!(stderr.contains("Multiple tickets found"));
assert!(stderr.contains("Test Ticket A"));
assert!(stderr.contains("Test Ticket B"));
assert!(stderr.contains("abc123d"));
assert!(stderr.contains("fedcba0"));
assert!(stderr.contains("Use the displayed ID"));
}
/// The candidate list has to travel the same way every other error does, or the
/// opencode wrapper throws on the exit code and discards it.
#[test]
fn show_reports_ambiguity_on_stderr_with_a_failing_exit() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
create_ticket(
&worklane,
"backlog",
"Ambiguous One",
"First.",
"abc123def456789012345678901234567890",
"alice",
"2026-12-31",
"test",
);
create_ticket(
&worklane,
"backlog",
"Ambiguous Two",
"Second.",
"fedcba0987654321fedcba09876543210987654321",
"bob",
"2026-10-15",
"test",
);
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
cmd.current_dir(temp.path())
.arg("show")
.arg("ambiguous")
.assert()
.failure();
let stderr = get_stderr(&mut cmd);
assert!(stderr.contains("Ambiguous One"));
assert!(stderr.contains("Ambiguous Two"));
// Nothing on stdout: that is where it used to go, and where it was lost
let stdout = get_stdout(&mut cmd);
assert!(stdout.is_empty(), "stdout was {stdout:?}");
}
/// Filenames shorter than the displayed id width used to panic while printing
/// the disambiguation list.
#[test]
fn show_disambiguates_tickets_with_short_filenames() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
fs::write(
worklane.join("backlog").join("abc.md"),
"# Short One\n\n## Metadata\n\n- **ID**: 1234\n",
)
.unwrap();
fs::write(
worklane.join("backlog").join("xy.md"),
"# Short Two\n\n## Metadata\n\n- **ID**: 5678\n",
)
.unwrap();
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
cmd.current_dir(temp.path()).arg("show").arg("short");
let stderr = get_stderr(&mut cmd);
assert!(stderr.contains("Multiple tickets found"));
assert!(stderr.contains("Short One"));
assert!(stderr.contains("Short Two"));
}
/// A multibyte character straddling the cut used to panic.
#[test]
fn show_disambiguates_tickets_with_non_ascii_filenames() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
for (filename, title) in [("émigré-un.md", "Accented One"), ("日本語-二.md", "Accented Two")] {
fs::write(
worklane.join("backlog").join(filename),
format!("# {}\n\n## Metadata\n\n- **ID**: 1234\n", title),
)
.unwrap();
}
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
cmd.current_dir(temp.path()).arg("show").arg("accented");
let stderr = get_stderr(&mut cmd);
assert!(stderr.contains("Multiple tickets found"));
assert!(stderr.contains("Accented One"));
assert!(stderr.contains("Accented Two"));
}
#[test]
fn show_searches_across_all_statuses() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
// Create ticket in committed status
let uuid = "abc123def456789012345678901234567890";
create_ticket(
&worklane,
"committed",
"Committed Task",
"This is in committed.",
uuid,
"charlie",
"2026-08-01",
"task",
);
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
cmd.current_dir(temp.path())
.arg("show")
.arg("committed")
.assert()
.success();
let stdout = get_stdout(&mut cmd);
assert!(stdout.contains("Committed Task"));
assert!(stdout.contains("This is in committed."));
}
#[test]
fn show_renders_the_priority_mark_beside_the_number() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let filename = "abc123def456789012345678901234567890_prio.md";
fs::write(
worklane.join("backlog").join(filename),
"# Prio Ticket\n\n## Metadata\n\n- **ID**: abc123def456789012345678901234567890\n\
- **Priority**: 2\n- **Status**: backlog\n",
)
.unwrap();
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
cmd.current_dir(temp.path()).arg("show").arg("Prio");
let stdout = get_stdout(&mut cmd);
// Mark for the eye, number still there for the file's sake
assert!(stdout.contains("\u{25cf}\u{25d0}"), "no mark in {stdout:?}");
assert!(stdout.contains("Priority"));
assert!(stdout.contains('2'));
// And the file itself is untouched
let content = fs::read_to_string(worklane.join("backlog").join(filename)).unwrap();
assert!(content.contains("- **Priority**: 2"));
}
#[test]
fn show_prints_the_title_once() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
create_ticket(
&worklane,
"backlog",
"Once Only",
"A description that does not name the title.",
"abc123def456789012345678901234567890",
"alice",
"2026-12-31",
"test",
);
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
cmd.current_dir(temp.path()).arg("show").arg("Once Only");
let stdout = get_stdout(&mut cmd);
assert_eq!(
stdout.matches("Once Only").count(),
1,
"title repeated in {stdout:?}"
);
// The rule under it is still the width of the title
assert!(stdout.contains("Once Only\n─────────\n"), "{stdout:?}");
}
#[test]
fn show_renders_the_metadata_as_an_aligned_table() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let filename = "abc123def456789012345678901234567890_table.md";
fs::write(
worklane.join("backlog").join(filename),
"# Table Ticket\n\n## Metadata\n\n\
- **ID**: abc123def456789012345678901234567890\n\
- **Created At**: 2026-08-20 15:51:01\n\
- **Owner**: alice\n\
- **Status**: backlog\n",
)
.unwrap();
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
cmd.current_dir(temp.path()).arg("show").arg("Table");
let stdout = get_stdout(&mut cmd);
// Every value starts in the same column, sized by the longest field name
assert!(
stdout.contains(
"ID abc123def456789012345678901234567890\n\
Created At 2026-08-20 15:51:01\n\
Owner alice\n\
Status backlog\n"
),
"{stdout:?}"
);
// Display only: the file is still the markdown list it was
let content = fs::read_to_string(worklane.join("backlog").join(filename)).unwrap();
assert!(content.contains("- **Owner**: alice"));
}
/// Write a ticket with an exact uuid and title, since both matter to resolution.
fn ticket_with(worklane: &std::path::Path, status: &str, uuid: &str, title: &str, slug: &str) {
fs::write(
worklane.join(status).join(format!("{}_{}.md", uuid, slug)),
format!(
"# {}\n\n## Metadata\n\n- **ID**: {}\n- **Status**: {}\n",
title, uuid, status
),
)
.unwrap();
}
fn show(temp: &TempDir, search: &str) -> std::process::Output {
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
cmd.current_dir(temp.path()).arg("show").arg(search);
cmd.assert().get_output().clone()
}
/// The bug. A flat OR of the three predicates put an exact uuid prefix and a title
/// that merely mentions it in the same list, so the search reported as ambiguous
/// the very id the listing had just printed.
#[test]
fn show_prefers_a_uuid_prefix_over_a_title_that_mentions_it() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
ticket_with(
&worklane,
"backlog",
"641e3d5d-ef23-4213-8346-e8b0114b84e9",
"Alpha",
"alpha",
);
ticket_with(
&worklane,
"backlog",
"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"Notes on 641e3d5 regression",
"notes",
);
let out = show(&temp, "641e3d5");
let stdout = String::from_utf8_lossy(&out.stdout);
assert!(out.status.success(), "{:?}", String::from_utf8_lossy(&out.stderr));
assert!(stdout.contains("Alpha"), "{stdout:?}");
assert!(!stdout.contains("Notes on"), "{stdout:?}");
}
/// `ls` prints SHORT_ID_WIDTH characters, so pasting that back has to resolve. This
/// is the guard against reinstating an eight character minimum.
#[test]
fn show_resolves_the_short_id_the_listing_prints() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let uuid = "641e3d5d-ef23-4213-8346-e8b0114b84e9";
ticket_with(&worklane, "backlog", uuid, "Alpha", "alpha");
let mut ls = Command::cargo_bin(BIN_NAME).unwrap();
ls.current_dir(temp.path()).args(["ls", "backlog"]);
let listing = String::from_utf8(ls.assert().success().get_output().stdout.clone()).unwrap();
// Take the id exactly as printed, so this couples to the display width rather
// than to a hardcoded number
let printed = listing
.split('(')
.nth(1)
.and_then(|rest| rest.split(')').next())
.expect("no id in the listing")
.to_string();
assert!(printed.len() < 8, "the listing prints {} chars", printed.len());
// A decoy whose title quotes that id. Without it the search would still land on
// Alpha through the filename tier, since the filename contains the uuid, and the
// test would pass under a minimum longer than the printed id.
ticket_with(
&worklane,
"backlog",
"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
&format!("Notes on {} regression", printed),
"notes",
);
let out = show(&temp, &printed);
let stdout = String::from_utf8_lossy(&out.stdout);
assert!(out.status.success(), "{printed} did not resolve");
assert!(stdout.contains("Alpha"), "{stdout:?}");
assert!(!stdout.contains("Notes on"), "{stdout:?}");
}
#[test]
fn show_resolves_a_four_character_uuid_prefix() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
ticket_with(
&worklane,
"backlog",
"641e3d5d-ef23-4213-8346-e8b0114b84e9",
"Alpha",
"alpha",
);
let out = show(&temp, "641e");
assert!(out.status.success());
assert!(String::from_utf8_lossy(&out.stdout).contains("Alpha"));
}
/// Below four characters the search is text, so it must not be read as a prefix
/// matching a large slice of the board.
#[test]
fn show_treats_a_search_below_four_characters_as_text() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
ticket_with(
&worklane,
"backlog",
"641e3d5d-ef23-4213-8346-e8b0114b84e9",
"Alpha",
"alpha",
);
ticket_with(
&worklane,
"backlog",
"aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"Notes on 641 regression",
"notes",
);
// "641" prefixes Alpha's uuid, but it is too short to be read as one, so the
// title match is the only match
let out = show(&temp, "641");
let stdout = String::from_utf8_lossy(&out.stdout);
assert!(out.status.success(), "{:?}", String::from_utf8_lossy(&out.stderr));
assert!(stdout.contains("Notes on"), "{stdout:?}");
assert!(!stdout.contains("Alpha"), "{stdout:?}");
}
/// The last tier earns its place: it reaches the middle of a uuid, which the prefix
/// tier cannot.
#[test]
fn show_falls_back_to_the_filename_for_a_mid_uuid_substring() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
ticket_with(
&worklane,
"backlog",
"641e3d5d-ef23-4213-8346-e8b0114b84e9",
"Alpha",
"alpha",
);
let out = show(&temp, "ef23");
assert!(out.status.success());
assert!(String::from_utf8_lossy(&out.stdout).contains("Alpha"));
}
/// Tiering removes false ambiguity across tiers, not real ambiguity inside one.
#[test]
fn show_still_reports_ambiguity_within_the_uuid_tier() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
ticket_with(
&worklane,
"backlog",
"5eeddeed-1111-2222-3333-444444444444",
"Beta",
"beta",
);
ticket_with(
&worklane,
"backlog",
"5eedbeef-9999-8888-7777-666666666666",
"Gamma",
"gamma",
);
let out = show(&temp, "5eed");
let stderr = String::from_utf8_lossy(&out.stderr);
assert!(!out.status.success());
assert!(stderr.contains("Multiple tickets found"), "{stderr:?}");
assert!(stderr.contains("Beta") && stderr.contains("Gamma"), "{stderr:?}");
}