Files
worklane/tests/cmd_show.rs
T
Ansho ReiandClaude Opus 5 2503f9aee9 (3b7edd7) Show priority as a glyph, and bump to 0.2.0
A bare digit in a listing is easy to skip over. Levels render as a
two-segment meter that empties as the level rises: ●● 1, ●◐ 2, ●○ 3,
◐○ 4, ○○ 5, with ·· for unset and ?? for a value outside the range.

Only ●, ◐, ○ and · are used, because they are what frig draws for its
status indicators and so are known to be in the terminal font. The first
cut of this used the quadrant circles ◕ and ◔, which are in a quarter as
many fonts, so terminals substituted them from a fallback that drew them
oversized and the column came out ragged. Two cells of a three-level ramp
gives five steps of ink, 2, 1.5, 1, 0.5, 0, without leaving that safe set.
Tests pin the safe set, the equal width and the monotonic emptying.

The mark carries the level on its own, because colour cannot. Output is
colourless whenever it is piped, which is how the opencode tools and every
script read it, and NO_COLOR turns it off in a terminal too. Colour only
accentuates: brightred, red, orange, cyan, grey, skipping green because
green means title.

The number counts up while the meter empties, since 1 is the most urgent.
That is the convention, but it reads as a bug unless written down, so it
is in AGENTS.md and in the legend.

Both the ramp and the legend come from priority_mark, and `ls --help`
prints the legend, since nothing in a listing explains a mark. brightred
is indexed like grey, for the same reason: it is the spelling that
renders.

Minor bump: two new flags, a new metadata field and a changed ls row,
covering dca0b61 and this ticket.

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

423 lines
11 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()
}
fn create_ticket(
worklane_dir: &std::path::PathBuf,
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"));
}