Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b28ddb9210 | ||
|
|
f557437f62 | ||
|
|
75fb2b3a6d | ||
|
|
8b440593e2 | ||
|
|
ab1dae098c | ||
|
|
2503f9aee9 | ||
|
|
ddbd45e332 | ||
|
|
b7781a830c | ||
|
|
3abe8755c8 | ||
|
|
b6d0b55d4b | ||
|
|
3fcb0ddc0a |
@@ -37,6 +37,7 @@ Add a new ticket to the backlog.
|
||||
- `--tags` (or `-g`): Tags (comma-separated)
|
||||
- `--due` (or `--due`): Due date in YYYY-MM-DD format
|
||||
- `--owner` (or `-o`): Owner name
|
||||
- `--priority`: Priority level, 1 (most urgent) to 5 (least). Unset if omitted
|
||||
|
||||
```bash
|
||||
worklane add -t "Implement login" -d "Add user login page" -t login,auth -p "Design UI" "Build backend" "Write tests" --due 2026-06-01 --owner "ilya"
|
||||
@@ -56,11 +57,15 @@ List tickets, optionally filtered by status.
|
||||
**Valid statuses:** `backlog`, `committed`, `reviewing`, `done`
|
||||
|
||||
```
|
||||
worklane ls # List all tickets
|
||||
worklane ls backlog # List tickets in backlog
|
||||
worklane ls done # List completed tickets
|
||||
worklane ls # List all tickets
|
||||
worklane ls backlog # List tickets in backlog
|
||||
worklane ls done # List completed tickets
|
||||
worklane ls --priority 1 # Only the most urgent, any status
|
||||
worklane ls backlog --priority 2 # Composes with the status filter
|
||||
```
|
||||
|
||||
Tickets are listed priority first, then by title. Tickets with no priority sort last.
|
||||
|
||||
### `worklane show`
|
||||
|
||||
Show the full details of a single ticket by UUID or title.
|
||||
|
||||
@@ -76,6 +76,10 @@ export const add = tool({
|
||||
owner: tool.schema
|
||||
.string()
|
||||
.describe("Ticket owner name. If omitted, defaults to the git user."),
|
||||
priority: tool.schema
|
||||
.string()
|
||||
.describe("Priority level, 1 (most urgent) to 5 (least). Left unset if omitted.")
|
||||
.optional(),
|
||||
},
|
||||
async execute(args: Record<string, any>, context: ToolContext) {
|
||||
if (!args.title) {
|
||||
@@ -109,6 +113,7 @@ export const add = tool({
|
||||
if (args.tags) cmd.push("--tags", args.tags);
|
||||
if (args.due) cmd.push("--due", args.due);
|
||||
if (args.owner) cmd.push("--owner", args.owner);
|
||||
if (args.priority) cmd.push("--priority", String(args.priority));
|
||||
|
||||
try {
|
||||
return await run(cmd, context);
|
||||
@@ -120,15 +125,20 @@ export const add = tool({
|
||||
|
||||
export const ls = tool({
|
||||
description:
|
||||
"List all worklane tickets. Optionally filter by status (backlog, committed, reviewing, done).",
|
||||
"List all worklane tickets, sorted by priority then title. Optionally filter by status and by priority.",
|
||||
args: {
|
||||
status: tool.schema
|
||||
.enum(["backlog", "committed", "reviewing", "done"])
|
||||
.describe("Filter by status")
|
||||
.optional(),
|
||||
priority: tool.schema
|
||||
.string()
|
||||
.describe("Only show tickets at this priority, 1 (most urgent) to 5 (least)")
|
||||
.optional(),
|
||||
},
|
||||
async execute(args: Record<string, any>, context: ToolContext) {
|
||||
const cmd = args.status ? ["ls", args.status] : ["ls"];
|
||||
if (args.priority) cmd.push("--priority", String(args.priority));
|
||||
try {
|
||||
return await run(cmd, context);
|
||||
} catch (err: any) {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
## Ticket File Format
|
||||
- Filenames: `<uuid_v4>_<slug>.md`
|
||||
- Metadata fields parsed by `parse_ticket_field()`: `ID`, `Tags`, `Due`, `Owner`, `Created At`, `Status`
|
||||
- Metadata fields parsed by `parse_ticket_field()`: `ID`, `Priority`, `Tags`, `Due`, `Owner`, `Created At`, `Status`
|
||||
- Format: `**Field Name**: value`
|
||||
- Ticket structure: `# Title` → `## Description` → `## Acceptance Criteria` → `## Implementation Plan` → `## Metadata`
|
||||
- Comments stored in `.worklane/comments/<ticket_uuid>/<timestamp>.md` with `**Comment**`, `**Author**`, `**Time**` fields
|
||||
@@ -33,22 +33,29 @@
|
||||
|
||||
### Color and Output
|
||||
- Use `color_text()` helper for colored output — it respects `should_use_colors()` (terminal detection)
|
||||
- Color codes are defined in `get_color()`: red (31), cyan (36), orange (33), green (32), grey (90)
|
||||
- Color codes are defined in `get_color()`: red (31), cyan (36), orange (33), green (32), grey (38;5;8), magenta (1;35), brightred (38;5;9)
|
||||
- Reset color with `\x1b[0m` after colored text
|
||||
- Bold uses `\x1b[1;35m` (magenta bold)
|
||||
- Always test color output works correctly in both terminal and pipe modes
|
||||
- `quiet_broken_pipe()` runs first in `main`, restoring the default `SIGPIPE` disposition. A truncated pipe therefore kills the process with signal 13, which a shell reports as 141, instead of making `println!` panic. Do not wrap prints to handle write errors and do not reinstate `SIG_IGN`; the exit codes are documented in the README
|
||||
|
||||
### Color Guideline
|
||||
- UUID → red (31)
|
||||
- Status → orange (33)
|
||||
- Timestamp → cyan (36)
|
||||
- Title → green (32)
|
||||
- Unknown values (`_None_`, `_Not set_`) → grey (90)
|
||||
- Unknown values (`_None_`, `_Not set_`) → grey (38;5;8)
|
||||
- Priority ramp → brightred (1), red (2), orange (3), cyan (4), grey (5). Green is deliberately absent: it means title
|
||||
- Grey is indexed colour 8 in the 256-colour form, not SGR 90 or 37. Both of those failed on a real palette: 90 leans on the bright-black slot and 37 can sit on top of the default foreground. `\x1b[38;5;8m` is byte for byte what crossterm emits for ratatui's `Color::DarkGray`, the grey frig and pantop use for dimmed rows
|
||||
|
||||
### Code Organization
|
||||
- Colorization functions (`colorize_line`, `colorize_metadata`, `colorize_ordered`, `content_trim_colored`) handle markdown formatting
|
||||
- Colorization functions (`colorize_line`, `colorize_ordered`, `content_trim_colored`) handle markdown formatting
|
||||
- `show` renders the Metadata section as a two column table via `render_metadata_table`, not line by line. Column width is measured on the raw field names in characters and padding is applied before anything is styled: measuring a coloured string counts its escapes towards its width. `paint()` is `color_text()` with the colour decision passed in, which is what lets a test render both ways in one process
|
||||
- The title is printed once, by `cmd_show`. `content_trim_colored` skips the `# ` heading in the file content
|
||||
- Rules under headings are measured on the displayed name in characters, never on the raw line or in bytes
|
||||
- `resolve_ticket()` scans all status directories — it's the single source for ticket lookup by UUID prefix, title, or filename
|
||||
- `parse_ticket_field()` handles extracting metadata values from markdown format
|
||||
- Field lookup, read and write, is scoped to the lines under the `## Metadata` heading and anchored to the start of the line. Prose above it is free text: tickets in this repo quote field markers in their descriptions, and an unscoped search reads or rewrites those instead. `set_status_field()` carries the same scoping
|
||||
|
||||
### Ticket Resolution
|
||||
- `resolve_ticket()` returns `(status, title, content)` tuple
|
||||
@@ -68,4 +75,6 @@
|
||||
- No bump for docs-only, tests-only or `--fixup` commits
|
||||
- When one body of work spans several commits, bump once on the final commit rather than on each
|
||||
- Bump `Cargo.toml` and the `worklane` entry in `Cargo.lock` together, in the commit that carries the bump
|
||||
- Every bump gets a matching annotated tag, `v<version>`, on the bump commit — a bumped version is never left untagged
|
||||
- Tag locally only; never push a tag unless asked
|
||||
- `worklane --version` reports the crate version alongside the build sha, so the bump is what makes one release distinguishable from another
|
||||
|
||||
Generated
+2
-1
@@ -1029,13 +1029,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "worklane"
|
||||
version = "0.1.1"
|
||||
version = "0.3.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"assert_cmd",
|
||||
"assert_fs",
|
||||
"chrono",
|
||||
"clap",
|
||||
"libc",
|
||||
"tempfile",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
+2
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "worklane"
|
||||
version = "0.1.1"
|
||||
version = "0.3.1"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
@@ -8,6 +8,7 @@ clap = { version = "4", features = ["derive"] }
|
||||
anyhow = "1"
|
||||
uuid = { version = "1", features = ["v4"] }
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
libc = "0.2"
|
||||
|
||||
[dev-dependencies]
|
||||
assert_cmd = "2"
|
||||
|
||||
@@ -6,8 +6,21 @@ Worklane is a local Kanban flow for agentic software development.
|
||||
| Command | Description |
|
||||
|---------|-------------|
|
||||
| `worklane init` | Creates `.worklane/` with backlog, committed, reviewing, done directories |
|
||||
| `worklane add` | Creates a ticket in backlog with `--title`, `--description`, `--acceptance`, `--plan`, `--tags`, `--due`, `--owner` flags |
|
||||
| `worklane ls` | Lists tickets, optionally filtered by `--status` |
|
||||
| `worklane add` | Creates a ticket in backlog with `--title`, `--description`, `--acceptance`, `--plan`, `--tags`, `--due`, `--owner`, `--priority` flags |
|
||||
| `worklane ls [status]` | Lists tickets, sorted by priority then title. Optional positional status, and `--priority <1-5>` |
|
||||
| `worklane show <id>` | Shows ticket by UUID prefix (8+ chars) or title substring |
|
||||
| `worklane mv <id> --status <target> [-f]` | Moves ticket between statuses. Default: forward only, one stage at a time. `-f` bypasses both restrictions |
|
||||
| `worklane comment <ticket> <body>` | Adds a comment to a ticket by UUID or title |
|
||||
|
||||
## Exit codes
|
||||
| Code | Meaning |
|
||||
|------|---------|
|
||||
| 0 | Success |
|
||||
| 1 | An error, such as no matching ticket or an ambiguous search |
|
||||
| 2 | A usage mistake, such as an unknown flag |
|
||||
| 141 | Output was piped to a reader that stopped early, for example `worklane ls \| head -3` |
|
||||
|
||||
141 is 128 + 13, the shell's way of reporting death by `SIGPIPE`. Worklane restores
|
||||
the default signal disposition so a truncated pipe is quiet, the way `head` and
|
||||
`sort` are, rather than printing a panic. A script using `set -o pipefail` will see
|
||||
141 for a case that is not a failure, so guard for it there.
|
||||
|
||||
@@ -1,5 +1,25 @@
|
||||
use clap::Parser;
|
||||
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use crate::util::{PRIORITY_RANGE, priority_legend};
|
||||
|
||||
/// clap wants a `&str` with a long enough lifetime, and the legend is built from
|
||||
/// the same ramp the listing uses rather than spelled out a second time.
|
||||
static PRIORITY_LEGEND: LazyLock<String> = LazyLock::new(priority_legend);
|
||||
|
||||
/// Reject a level outside the range at parse time, so no command has to.
|
||||
fn priority_level(raw: &str) -> Result<u8, String> {
|
||||
match raw.parse::<u8>() {
|
||||
Ok(level) if PRIORITY_RANGE.contains(&level) => Ok(level),
|
||||
_ => Err(format!(
|
||||
"priority must be a whole number from {} to {}",
|
||||
PRIORITY_RANGE.start(),
|
||||
PRIORITY_RANGE.end()
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
/// What `--version` prints: the crate version and the commit it was built from.
|
||||
///
|
||||
/// The sha is the part that matters. Two binaries built weeks apart both call
|
||||
@@ -51,12 +71,21 @@ pub enum Command {
|
||||
/// Owner
|
||||
#[arg(short, long)]
|
||||
owner: Option<String>,
|
||||
|
||||
/// Priority, 1 (most urgent) to 5 (least). Left unset if omitted.
|
||||
#[arg(long, value_parser = priority_level)]
|
||||
priority: Option<u8>,
|
||||
},
|
||||
|
||||
/// List tickets, optionally filtered by status
|
||||
#[command(after_help = PRIORITY_LEGEND.as_str())]
|
||||
Ls {
|
||||
/// Filter by status (backlog, committed, reviewing, done)
|
||||
status: Option<String>,
|
||||
|
||||
/// Only show tickets at this priority, 1 (most urgent) to 5 (least)
|
||||
#[arg(long, value_parser = priority_level)]
|
||||
priority: Option<u8>,
|
||||
},
|
||||
|
||||
/// Show a ticket by UUID or title
|
||||
|
||||
+31
-7
@@ -29,7 +29,11 @@ pub fn cmd_init(start: &Path) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn cmd_ls(status_filter: &Option<String>, worklane_dir: &Path) -> Result<()> {
|
||||
pub fn cmd_ls(
|
||||
status_filter: &Option<String>,
|
||||
priority_filter: Option<u8>,
|
||||
worklane_dir: &Path,
|
||||
) -> Result<()> {
|
||||
if let Some(status) = status_filter {
|
||||
let status_path = worklane_dir.join(status);
|
||||
if !status_path.exists() {
|
||||
@@ -39,7 +43,7 @@ pub fn cmd_ls(status_filter: &Option<String>, worklane_dir: &Path) -> Result<()>
|
||||
));
|
||||
}
|
||||
|
||||
let items = collect_ticket_items(&status_path)?;
|
||||
let items = filter_by_priority(collect_ticket_items(&status_path)?, priority_filter);
|
||||
|
||||
if items.is_empty() {
|
||||
println!("No tickets in '{}' status.", status);
|
||||
@@ -57,8 +61,8 @@ pub fn cmd_ls(status_filter: &Option<String>, worklane_dir: &Path) -> Result<()>
|
||||
if !status_path.exists() {
|
||||
continue;
|
||||
}
|
||||
let entries: Vec<_> = fs::read_dir(&status_path)?.filter_map(|e| e.ok()).collect();
|
||||
let count = entries.len();
|
||||
let items = filter_by_priority(collect_ticket_items(&status_path)?, priority_filter);
|
||||
let count = items.len();
|
||||
let label = if count == 1 { "ticket" } else { "tickets" };
|
||||
println!(" [{}] {} {}", status.to_uppercase(), count, label);
|
||||
}
|
||||
@@ -73,7 +77,7 @@ pub fn cmd_ls(status_filter: &Option<String>, worklane_dir: &Path) -> Result<()>
|
||||
continue;
|
||||
}
|
||||
let items = match collect_ticket_items(&status_path) {
|
||||
Ok(items) => items,
|
||||
Ok(items) => filter_by_priority(items, priority_filter),
|
||||
Err(_) => continue,
|
||||
};
|
||||
if items.is_empty() {
|
||||
@@ -88,6 +92,17 @@ pub fn cmd_ls(status_filter: &Option<String>, worklane_dir: &Path) -> Result<()>
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Keep only the tickets at `level`, or everything when no level was asked for.
|
||||
fn filter_by_priority(items: Vec<TicketItem>, level: Option<u8>) -> Vec<TicketItem> {
|
||||
match level {
|
||||
Some(level) => items
|
||||
.into_iter()
|
||||
.filter(|item| item.priority == Priority::Level(level))
|
||||
.collect(),
|
||||
None => items,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cmd_add(
|
||||
title: &str,
|
||||
description: &[String],
|
||||
@@ -96,6 +111,7 @@ pub fn cmd_add(
|
||||
tags: &[String],
|
||||
due: &Option<String>,
|
||||
owner: &Option<String>,
|
||||
priority: Option<u8>,
|
||||
start: &Path,
|
||||
) -> Result<()> {
|
||||
let owner = match owner {
|
||||
@@ -141,6 +157,7 @@ pub fn cmd_add(
|
||||
## Metadata\n\
|
||||
\n\
|
||||
- **ID**: {}\n\
|
||||
- **Priority**: {}\n\
|
||||
- **Tags**: {}\n\
|
||||
- **Due**: {}\n\
|
||||
- **Owner**: {}\n\
|
||||
@@ -168,6 +185,10 @@ pub fn cmd_add(
|
||||
.join("\n")
|
||||
},
|
||||
id,
|
||||
match priority {
|
||||
Some(level) => level.to_string(),
|
||||
None => "_Not set_".to_string(),
|
||||
},
|
||||
if tags.is_empty() {
|
||||
"_None_".to_string()
|
||||
} else {
|
||||
@@ -273,8 +294,11 @@ pub fn cmd_show(search: &str, worklane_dir: &Path) -> Result<()> {
|
||||
let (_status, title, content) = resolve_ticket(search, worklane_dir)?;
|
||||
let ticket_uuid = parse_ticket_field(&content, "ID");
|
||||
|
||||
println!("{}", title);
|
||||
println!("{}", "─".repeat(title.len()));
|
||||
// The only title in the output: content_trim_colored used to print it a second
|
||||
// time from the file content. Green per the colour guideline, and the rule is
|
||||
// measured in characters so a non-ASCII title is not over-drawn.
|
||||
println!("{}", color_text(&title, "green"));
|
||||
println!("{}", "─".repeat(title.chars().count()));
|
||||
println!("\n{}", content_trim_colored(&content));
|
||||
|
||||
if ticket_uuid != "_Not set_" {
|
||||
|
||||
+25
-2
@@ -9,7 +9,28 @@ use command::*;
|
||||
use handlers::*;
|
||||
use util::*;
|
||||
|
||||
/// Die quietly when stdout is closed early, the way every other Unix tool does.
|
||||
///
|
||||
/// Rust sets `SIGPIPE` to `SIG_IGN` at startup, which turns a closed pipe into an
|
||||
/// io error that `println!` panics on. So `worklane ls | head -3` printed a panic
|
||||
/// and a backtrace instead of three lines, which is both alarming and easy to
|
||||
/// mistake for a real fault. Restoring the default handler makes `| head` behave.
|
||||
///
|
||||
/// The cost is that a truncated pipe now kills the process with signal 13 rather
|
||||
/// than returning a code, so `pipefail` sees 141 instead of 101. That is what
|
||||
/// `head` and `sort` do, and it is recorded in the README.
|
||||
fn quiet_broken_pipe() {
|
||||
// SAFETY: setting a signal disposition to the default is always valid, and
|
||||
// this runs before any thread is spawned.
|
||||
unsafe {
|
||||
libc::signal(libc::SIGPIPE, libc::SIG_DFL);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
// Before any output, so no write can beat it to a closed pipe.
|
||||
quiet_broken_pipe();
|
||||
|
||||
let cli = Cli::parse();
|
||||
|
||||
let start = std::env::current_dir()?;
|
||||
@@ -24,6 +45,7 @@ fn main() -> Result<()> {
|
||||
tags,
|
||||
due,
|
||||
owner,
|
||||
priority,
|
||||
} => cmd_add(
|
||||
&title,
|
||||
&description,
|
||||
@@ -32,11 +54,12 @@ fn main() -> Result<()> {
|
||||
&tags,
|
||||
&due,
|
||||
&owner,
|
||||
priority,
|
||||
&start,
|
||||
),
|
||||
Command::Ls { status } => {
|
||||
Command::Ls { status, priority } => {
|
||||
let worklane_dir = find_worklane_dir(&start)?;
|
||||
cmd_ls(&status, &worklane_dir)
|
||||
cmd_ls(&status, priority, &worklane_dir)
|
||||
}
|
||||
Command::Show { id } => {
|
||||
let worklane_dir = find_worklane_dir(&start)?;
|
||||
|
||||
+887
-101
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,173 @@
|
||||
use assert_fs::TempDir;
|
||||
use assert_fs::fixture::{PathChild, PathCreateDir};
|
||||
use std::fs;
|
||||
use std::os::unix::process::ExitStatusExt;
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
const BIN_NAME: &str = env!("CARGO_BIN_EXE_worklane");
|
||||
|
||||
/// What a truncated pipe costs: the process dies by signal rather than returning a
|
||||
/// code, so a shell reports 128 + 13. Asserted here so the README and the code stay
|
||||
/// honest about what `pipefail` sees.
|
||||
const SIGPIPE: i32 = 13;
|
||||
|
||||
/// A pipe holds 64 KiB on Linux before a write blocks. Below that the whole listing
|
||||
/// lands in the buffer, the writer never notices the reader is gone, and a test
|
||||
/// proves nothing. Every ticket here is one `ls` row of roughly a hundred bytes.
|
||||
const TICKETS: usize = 1200;
|
||||
|
||||
fn setup_crowded_board(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();
|
||||
}
|
||||
|
||||
let backlog = worklane.path().join("backlog");
|
||||
for i in 0..TICKETS {
|
||||
let id = format!("{:08x}-0000-4000-8000-000000000000", i);
|
||||
let title = format!("A ticket with a title long enough to fill a row {}", i);
|
||||
fs::write(
|
||||
backlog.join(format!("{}_ticket-{}.md", id, i)),
|
||||
format!(
|
||||
"# {}\n\n## Metadata\n\n\
|
||||
- **ID**: {}\n\
|
||||
- **Owner**: someone with a name\n\
|
||||
- **Status**: backlog\n",
|
||||
title, id
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
temp.path().to_path_buf()
|
||||
}
|
||||
|
||||
fn panic_text(stderr: &str) -> bool {
|
||||
stderr.contains("panicked")
|
||||
|| stderr.contains("failed printing to stdout")
|
||||
|| stderr.contains("Broken pipe")
|
||||
}
|
||||
|
||||
/// The reader closed before the writer finished: dropping the read end here is the
|
||||
/// same thing `head` does when it has seen enough, without the timing luck.
|
||||
fn run_with_stdout_dropped(dir: &std::path::Path, args: &[&str]) -> std::process::Output {
|
||||
let mut child = Command::new(BIN_NAME)
|
||||
.args(args)
|
||||
.current_dir(dir)
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap();
|
||||
|
||||
drop(child.stdout.take().unwrap());
|
||||
child.wait_with_output().unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ls_says_nothing_when_the_reader_goes_away() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let dir = setup_crowded_board(&temp);
|
||||
|
||||
let output = run_with_stdout_dropped(&dir, &["ls", "backlog"]);
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
|
||||
assert!(!panic_text(&stderr), "stderr was {stderr:?}");
|
||||
assert_ne!(output.status.code(), Some(101), "panicked instead of dying");
|
||||
assert_eq!(
|
||||
output.status.signal(),
|
||||
Some(SIGPIPE),
|
||||
"expected death by SIGPIPE, got {:?}",
|
||||
output.status
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn show_says_nothing_when_the_reader_goes_away() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let dir = setup_crowded_board(&temp);
|
||||
|
||||
// A ticket carrying more comments than a pipe will hold, since the comment list
|
||||
// is the longest thing show prints and the last thing it reaches.
|
||||
let comments = temp
|
||||
.path()
|
||||
.join(".worklane")
|
||||
.join("comments")
|
||||
.join("00000000-0000-4000-8000-000000000000");
|
||||
fs::create_dir_all(&comments).unwrap();
|
||||
for i in 0..800 {
|
||||
fs::write(
|
||||
comments.join(format!("2026082{}_120000_{:06}.md", i % 10, i)),
|
||||
format!(
|
||||
"**Comment**\nA comment body long enough to be worth buffering, number {}.\n\n\
|
||||
**Author**: someone\n**Time**: 2026-08-20 12:00:00\n",
|
||||
i
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let output = run_with_stdout_dropped(&dir, &["show", "00000000-0000-4000"]);
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
|
||||
assert!(!panic_text(&stderr), "stderr was {stderr:?}");
|
||||
assert_ne!(output.status.code(), Some(101), "panicked instead of dying");
|
||||
assert_eq!(
|
||||
output.status.signal(),
|
||||
Some(SIGPIPE),
|
||||
"expected death by SIGPIPE, got {:?}",
|
||||
output.status
|
||||
);
|
||||
}
|
||||
|
||||
/// The real invocation, through a shell into `head`, which is how this was found.
|
||||
/// Whether the writer gets far enough to notice is up to the scheduler, so this
|
||||
/// asserts only what must hold either way: `head` gets its lines and nothing
|
||||
/// alarming reaches stderr.
|
||||
#[test]
|
||||
fn a_shell_pipeline_into_head_prints_lines_and_not_a_panic() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let dir = setup_crowded_board(&temp);
|
||||
|
||||
let output = Command::new("sh")
|
||||
.arg("-c")
|
||||
.arg(format!("{} ls backlog | head -3", BIN_NAME))
|
||||
.current_dir(&dir)
|
||||
.output()
|
||||
.unwrap();
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
|
||||
assert_eq!(stdout.lines().count(), 3, "stdout was {stdout:?}");
|
||||
assert!(!panic_text(&stderr), "stderr was {stderr:?}");
|
||||
}
|
||||
|
||||
/// The reset must not touch anything else: a real failure still returns its code.
|
||||
#[test]
|
||||
fn real_exit_codes_are_unchanged() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let dir = setup_crowded_board(&temp);
|
||||
|
||||
let ok = Command::new(BIN_NAME)
|
||||
.args(["ls", "backlog"])
|
||||
.current_dir(&dir)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert_eq!(ok.status.code(), Some(0));
|
||||
|
||||
let missing = Command::new(BIN_NAME)
|
||||
.args(["show", "no-such-ticket-anywhere"])
|
||||
.current_dir(&dir)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert_eq!(missing.status.code(), Some(1));
|
||||
|
||||
let misuse = Command::new(BIN_NAME)
|
||||
.arg("--bogus")
|
||||
.current_dir(&dir)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert_eq!(misuse.status.code(), Some(2));
|
||||
}
|
||||
@@ -199,3 +199,66 @@ fn add_file_has_uuid_prefix() {
|
||||
assert_eq!(parts[0].len(), 36);
|
||||
assert_eq!(parts[0].chars().filter(|c| c.is_ascii_hexdigit()).count(), 32);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_writes_the_priority_field() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
setup_worklane(&temp);
|
||||
|
||||
Command::cargo_bin(BIN_NAME)
|
||||
.unwrap()
|
||||
.current_dir(&temp.path())
|
||||
.args(["add", "--title", "Urgent thing", "--priority", "1"])
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
let files: Vec<_> = fs::read_dir(temp.child(".worklane").join("backlog"))
|
||||
.unwrap()
|
||||
.filter_map(|e| e.ok())
|
||||
.collect();
|
||||
let content = fs::read_to_string(files[0].path()).unwrap();
|
||||
assert!(content.contains("- **Priority**: 1"), "was {content:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_leaves_priority_unset_when_omitted() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
setup_worklane(&temp);
|
||||
|
||||
Command::cargo_bin(BIN_NAME)
|
||||
.unwrap()
|
||||
.current_dir(&temp.path())
|
||||
.args(["add", "--title", "Whenever"])
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
let files: Vec<_> = fs::read_dir(temp.child(".worklane").join("backlog"))
|
||||
.unwrap()
|
||||
.filter_map(|e| e.ok())
|
||||
.collect();
|
||||
let content = fs::read_to_string(files[0].path()).unwrap();
|
||||
assert!(content.contains("- **Priority**: _Not set_"), "was {content:?}");
|
||||
}
|
||||
|
||||
/// Rejected at parse time, so no ticket is written at all.
|
||||
#[test]
|
||||
fn add_rejects_a_level_outside_the_range() {
|
||||
let temp = TempDir::new().unwrap();
|
||||
let worklane = setup_worklane(&temp);
|
||||
|
||||
// The `=` form, so a negative value reaches the validator instead of being
|
||||
// read as a flag.
|
||||
for bad in ["0", "6", "high", "-1"] {
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.current_dir(&temp.path())
|
||||
.args(["add", "--title", "Bad level", &format!("--priority={bad}")])
|
||||
.assert()
|
||||
.failure();
|
||||
|
||||
let stderr = String::from_utf8(cmd.assert().get_output().stderr.clone()).unwrap();
|
||||
assert!(stderr.contains("priority must be"), "for {bad}: {stderr}");
|
||||
}
|
||||
|
||||
let count = fs::read_dir(worklane.join("backlog")).unwrap().count();
|
||||
assert_eq!(count, 0, "a ticket was written despite a bad level");
|
||||
}
|
||||
|
||||
@@ -216,3 +216,83 @@ fn ls_survives_a_malformed_created_at() {
|
||||
// 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");
|
||||
}
|
||||
|
||||
@@ -393,3 +393,95 @@ fn show_searches_across_all_statuses() {
|
||||
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"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user