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>
299 lines
10 KiB
Rust
299 lines
10 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,
|
|
owner: &str,
|
|
due: &str,
|
|
) {
|
|
let ticket_body = format!(
|
|
"# {}\n\
|
|
\n\
|
|
## Description\n\
|
|
test desc\n\
|
|
\n\
|
|
## Acceptance Criteria\n\
|
|
- [ ] test\n\
|
|
\n\
|
|
## Implementation Plan\n\
|
|
- test\n\
|
|
\n\
|
|
## Metadata\n\
|
|
\n\
|
|
- **ID**: 00000000-0000-0000-0000-000000000001\n\
|
|
- **Tags**: test\n\
|
|
- **Due**: {}\n\
|
|
- **Owner**: {}\n\
|
|
- **Status**: {}\n\
|
|
",
|
|
title, due, owner, status
|
|
);
|
|
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!("00000000-0000-0000-0000-000000000001_{}.md", slug);
|
|
fs::write(worklane_dir.join(status).join(&filename), ticket_body).unwrap();
|
|
}
|
|
|
|
fn get_stdout(cmd: &mut Command) -> String {
|
|
let assert = cmd.assert();
|
|
String::from_utf8(assert.get_output().stdout.clone()).unwrap()
|
|
}
|
|
|
|
#[test]
|
|
fn ls_without_status_shows_overview() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
create_ticket(&worklane, "backlog", "Feature A", "alice", "2026-06-01");
|
|
create_ticket(&worklane, "backlog", "Feature B", "bob", "2026-07-01");
|
|
create_ticket(&worklane, "committed", "Feature C", "charlie", "2026-08-01");
|
|
create_ticket(&worklane, "done", "Feature D", "dave", "2026-09-01");
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(&temp.path()).arg("ls").assert().success();
|
|
|
|
let stdout = get_stdout(&mut cmd);
|
|
assert!(stdout.contains("BACKLOG"));
|
|
assert!(stdout.contains("2 tickets"));
|
|
assert!(stdout.contains("COMMITTED"));
|
|
assert!(stdout.contains("1 ticket"));
|
|
assert!(stdout.contains("DONE"));
|
|
assert!(stdout.contains("Feature A"));
|
|
assert!(stdout.contains("Feature B"));
|
|
assert!(stdout.contains("Feature C"));
|
|
}
|
|
|
|
#[test]
|
|
fn ls_with_status_filters_tickets() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
create_ticket(&worklane, "backlog", "Feature A", "alice", "2026-06-01");
|
|
create_ticket(&worklane, "committed", "Feature B", "bob", "2026-07-01");
|
|
create_ticket(&worklane, "reviewing", "Feature C", "charlie", "2026-08-01");
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(&temp.path()).arg("ls").args(["committed"]);
|
|
|
|
cmd.assert().success();
|
|
|
|
let stdout = get_stdout(&mut cmd);
|
|
assert!(stdout.contains("Feature B"));
|
|
}
|
|
|
|
#[test]
|
|
fn ls_with_invalid_status_fails() {
|
|
let temp = TempDir::new().unwrap();
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(&temp.path())
|
|
.arg("ls")
|
|
.args(["nonexistent"])
|
|
.assert()
|
|
.failure();
|
|
}
|
|
|
|
#[test]
|
|
fn ls_listed_tickets_sorted_alphabetically() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
create_ticket(&worklane, "backlog", "Zebra", "alice", "2026-06-01");
|
|
create_ticket(&worklane, "backlog", "Apple", "bob", "2026-07-01");
|
|
create_ticket(&worklane, "backlog", "Mango", "charlie", "2026-08-01");
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(&temp.path())
|
|
.arg("ls")
|
|
.args(["backlog"])
|
|
.assert()
|
|
.success();
|
|
|
|
let stdout = get_stdout(&mut cmd);
|
|
let apple_pos = stdout.find("Apple");
|
|
let mango_pos = stdout.find("Mango");
|
|
let zebra_pos = stdout.find("Zebra");
|
|
assert!(apple_pos.is_some() && mango_pos.is_some() && zebra_pos.is_some());
|
|
assert!(apple_pos.unwrap() < mango_pos.unwrap());
|
|
assert!(mango_pos.unwrap() < zebra_pos.unwrap());
|
|
}
|
|
|
|
#[test]
|
|
fn ls_empty_status_shows_message() {
|
|
let temp = TempDir::new().unwrap();
|
|
let _worklane = setup_worklane(&temp);
|
|
|
|
// Intentionally leave "done" empty
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(&temp.path())
|
|
.arg("ls")
|
|
.args(["done"])
|
|
.assert()
|
|
.success();
|
|
|
|
let stdout = get_stdout(&mut cmd);
|
|
assert!(stdout.contains("No tickets in 'done'"));
|
|
}
|
|
|
|
#[test]
|
|
fn ls_displays_owner_and_due() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
create_ticket(&worklane, "backlog", "Test ticket", "alice", "2026-12-31");
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(&temp.path())
|
|
.arg("ls")
|
|
.args(["backlog"])
|
|
.assert()
|
|
.success();
|
|
|
|
let stdout = get_stdout(&mut cmd);
|
|
assert!(stdout.contains("alice"));
|
|
assert!(stdout.contains("2026-12-31"));
|
|
}
|
|
|
|
/// Both the abbreviated id and the created-at column used to slice by byte
|
|
/// offset, so either a short name or a multibyte character panicked.
|
|
#[test]
|
|
fn ls_handles_short_and_non_ascii_filenames() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
for filename in ["ab.md", "émigré-ticket.md", "日本語.md"] {
|
|
fs::write(
|
|
worklane.join("backlog").join(filename),
|
|
"# Odd Name\n\n## Metadata\n\n- **Owner**: alice\n- **Status**: backlog\n",
|
|
)
|
|
.unwrap();
|
|
}
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(&temp.path()).arg("ls").arg("backlog").assert().success();
|
|
|
|
let stdout = get_stdout(&mut cmd);
|
|
assert_eq!(stdout.matches("Odd Name").count(), 3);
|
|
}
|
|
|
|
#[test]
|
|
fn ls_survives_a_malformed_created_at() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
fs::write(
|
|
worklane.join("backlog").join("00000000-0000-0000-0000-000000000009_bad-date.md"),
|
|
"# Bad Date\n\n## Metadata\n\n- **Created At**: 日本語日本語日本語\n- **Status**: backlog\n",
|
|
)
|
|
.unwrap();
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(&temp.path()).arg("ls").arg("backlog").assert().success();
|
|
|
|
let stdout = get_stdout(&mut cmd);
|
|
assert!(stdout.contains("Bad Date"));
|
|
// Unparseable, so the timestamp column is dropped rather than printed raw
|
|
assert!(!stdout.contains("日本語"));
|
|
}
|
|
|
|
fn create_ticket_with_priority(worklane_dir: &std::path::PathBuf, title: &str, priority: &str) {
|
|
let slug: String = title.to_lowercase().replace(' ', "-");
|
|
let body = format!(
|
|
"# {}\n\n## Metadata\n\n- **ID**: 00000000-0000-0000-0000-00000000000{}\n\
|
|
- **Priority**: {}\n- **Tags**: test\n- **Due**: _Not set_\n\
|
|
- **Owner**: alice\n- **Status**: backlog\n",
|
|
title,
|
|
slug.len() % 10,
|
|
priority
|
|
);
|
|
let filename = format!("0000000{}-0000-0000-0000-000000000001_{}.md", slug.len() % 10, slug);
|
|
fs::write(worklane_dir.join("backlog").join(filename), body).unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn ls_sorts_by_priority_then_title() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
create_ticket_with_priority(&worklane, "Zebra urgent", "1");
|
|
create_ticket_with_priority(&worklane, "Apple later", "4");
|
|
create_ticket_with_priority(&worklane, "Middle one", "2");
|
|
create_ticket(&worklane, "backlog", "No priority at all", "alice", "_Not set_");
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(&temp.path()).arg("ls").arg("backlog");
|
|
let stdout = get_stdout(&mut cmd);
|
|
|
|
let at = |needle: &str| stdout.find(needle).unwrap_or_else(|| panic!("{needle} missing"));
|
|
assert!(at("Zebra urgent") < at("Middle one"), "priority 1 must lead");
|
|
assert!(at("Middle one") < at("Apple later"), "2 before 4");
|
|
// Unset sorts last even though its title would come first alphabetically
|
|
assert!(at("Apple later") < at("No priority at all"), "unset must trail");
|
|
}
|
|
|
|
#[test]
|
|
fn ls_filters_by_priority_and_composes_with_status() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
create_ticket_with_priority(&worklane, "Urgent one", "1");
|
|
create_ticket_with_priority(&worklane, "Lower one", "3");
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(&temp.path())
|
|
.args(["ls", "backlog", "--priority", "1"]);
|
|
let stdout = get_stdout(&mut cmd);
|
|
assert!(stdout.contains("Urgent one"));
|
|
assert!(!stdout.contains("Lower one"), "filter let a level 3 through");
|
|
|
|
// Same filter without a status, through the grouped listing
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(&temp.path()).args(["ls", "--priority", "3"]);
|
|
let stdout = get_stdout(&mut cmd);
|
|
assert!(stdout.contains("Lower one"));
|
|
assert!(!stdout.contains("Urgent one"));
|
|
}
|
|
|
|
#[test]
|
|
fn ls_shows_a_mark_for_the_level() {
|
|
let temp = TempDir::new().unwrap();
|
|
let worklane = setup_worklane(&temp);
|
|
|
|
create_ticket_with_priority(&worklane, "Top level", "1");
|
|
create_ticket_with_priority(&worklane, "Bottom level", "5");
|
|
create_ticket(&worklane, "backlog", "Nothing set", "alice", "_Not set_");
|
|
|
|
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
|
cmd.current_dir(&temp.path()).arg("ls").arg("backlog");
|
|
let stdout = get_stdout(&mut cmd);
|
|
|
|
// Piped, so no escapes: the glyph is carrying the level by itself
|
|
assert!(!stdout.contains('\u{1b}'));
|
|
assert!(stdout.contains("\u{25cf}\u{25cf} "), "no full meter for level 1 in {stdout:?}");
|
|
assert!(stdout.contains("\u{25cb}\u{25cb} "), "no empty meter for level 5");
|
|
assert!(stdout.contains("\u{b7}\u{b7} "), "no unset mark");
|
|
// The raw number is not what the listing shows
|
|
assert!(!stdout.contains(" 1 "), "the digit leaked into the row");
|
|
}
|