Compare commits

..
2 Commits
Author SHA1 Message Date
Ansho ReiandClaude Opus 5 3d6a74bc53 (daa0e79) Validate the due date at parse time, and bump to 0.13.3
A clap value_parser beside priority_level rather than a check inside cmd_add,
so a bad date is a usage error with nothing written at all rather than
written and then rejected.

On set --due as well as add --due, from one definition. The planning skill
sets dates through set and never through add, so validating only the command
that files a ticket would have left the path the validation exists to
protect still accepting "next friday".

The shape is checked before chrono sees it. %Y-%m-%d accepts an unpadded
2026-8-9, which would be stored as typed and sort before 2026-10-01. Strict
on the way in, tolerant on the way out: util::due_date still cuts a datetime
down to its date, since a file written earlier can hold one.

PLAN.md told the planner the value was not validated. That is corrected, and
the guard test that failed on the edit now pins the half of the warning that
is still true: a date cannot be cleared, only replaced.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-22 03:22:04 +02:00
Ansho ReiandClaude Opus 5 7a0dd625ce (1e7b1a9) Colour a tag by its name, and bump to 0.13.2
FNV-1a over the tag bytes into an eight-colour reserved palette, so the same
tag is the same colour on every card and on every board with nothing stored.
The hash is written out rather than taken from std, whose output is not
promised stable across releases.

The index is multiply-shift, not `% len`. The length is a power of two, so a
modulus keeps the low three bits of the hash, and FNV-1a's low bits carry
only the low bits of the input bytes: nothing moves information downwards.
Every pair of tags differing above bit 2 landed in one slot, `bug` and `BUG`
among them. It looked like a good palette, two colliding cards in sixty-four
on this board, because the vocabulary had been folded into a handful of
slots. Using the whole hash gives 14/64, which is the real arithmetic for
eight colours.

The palette is reserved as a list and disjoint from the seven colours that
already mean something: a tag in red reads as a uuid, in green as a title.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-22 03:13:56 +02:00
12 changed files with 511 additions and 20 deletions
+9
View File
@@ -53,6 +53,10 @@ and this file is for what someone changing worklane's own code needs.
### CLI Arguments
- The prose arguments carry `allow_hyphen_values`, via the `PROSE` constant in `command.rs`: `add --title`, `--description`, `--acceptance`, `--plan`, and the `comment` body. Ticket text quotes flag names constantly, and without it a criterion reading `--print is supported` is parsed as a flag and the whole ticket is refused with nothing written
- **The trade:** on those five arguments a genuinely mistyped flag now lands as content rather than raising a usage error. That is the right way round for prose and the wrong way round for anything else, which is why `due`, `priority`, `tags`, `owner` and `status` are deliberately left without it. A mistyped flag there is still a usage error, exit 2, and no ticket is written. Do not add `PROSE` to a new argument unless it holds prose
- **`--due` is validated at parse time by `iso_date`, the way `--priority` is by `priority_level`.** A date that is not real is a usage error, exit 2, with nothing written, which is the whole point of leaving the scalars without `PROSE`. One parser serves `add` and `set`: the field has one definition of what it accepts, and validating only `add` would leave `set` open, which is the command a grooming sweep actually uses
- **The shape is checked before chrono is asked.** `%Y-%m-%d` accepts an unpadded `2026-8-9`, which would be stored exactly as typed and sort before `2026-10-01` in any string comparison. Checking the length and the two dashes first is what lets a valid date be stored unchanged instead of normalised on the way in, which is the difference between validating and rewriting
- **Strict on the way in, tolerant on the way out.** `util::due_date` still cuts `2026-12-31T09:30:00Z` down to its date. A file written before the parser existed, or by hand, can hold one and still has to render; refusing to display what is already stored would punish the reader for the writer's mistake
- An empty `--due` keeps `non_empty`'s message about clearing rather than the date message. Somebody typing it is reaching for a way to clear the field, and the useful answer is that clearing is not supported yet
- The ticket positionals (`show <id>`, `mv <ticket>`, `comment <ticket>`) are also left alone, so a search term starting with a hyphen is a usage error. Reachable now that a hyphen-leading title can be stored: use the UUID, or put the flags first and separate with `--`, as in `mv --status committed -- -leading-title`
- A bare `--` is a value when it follows an option (`--title -- ` stores `--`) and clap's end-of-options marker when it sits in a positional. So a `comment` body of exactly `--` needs its own separator, `comment <ticket> -- --`. Without it the body is reported missing and nothing is written, which is a clear failure rather than a silent drop
- `add` has no positionals, so anything after a bare `--` is an unexpected argument and fails
@@ -201,6 +205,11 @@ and this file is for what someone changing worklane's own code needs.
- Title → green (32)
- 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
- **The palette splits in two: seven colours that each mean one thing, and `TAG_COLORS`, the eight a tag may be drawn in.** A tag in red would read as a uuid, in green as a title, in grey as an unset value, so the tag slots are reserved as a list rather than picked at the call site. Do not assign a new meaning to a colour in `TAG_COLORS`, and do not draw a tag in one outside it
- `tag_color()` is a pure function of the tag string, so the same tag is the same colour on every card, in every view and on every board, with nothing stored. Case sensitive, because `Bug` and `bug` are two different tags to the field and to every search
- **The hash is FNV-1a written out here, not `DefaultHasher`.** std does not promise its output is stable across releases, and a board that repaints itself on a toolchain upgrade has lost the only property the mapping is for. `the_tag_mapping_is_pinned` fails on any change to it, so a repaint is a decision rather than a surprise
- **The index is multiply-shift, not `% TAG_COLORS.len()`.** The length is a power of two, so a modulus keeps only the low three bits of the hash, and FNV-1a's low bits carry only the low bits of the input bytes: multiplication cannot move information downwards. Under a modulus every pair of tags differing above bit 2, `bug` and `BUG` among them, landed in one slot regardless of the rest of the string. It looked like a *good* palette on this board, two colliding cards out of sixty-four, because the vocabulary had been folded into a handful of slots. Taking the top bits of a 128-bit product uses the whole hash
- Eight tag colours means roughly one card in five shows two tags alike. That is arithmetic and is accepted: the colour groups a tag across cards, it does not tell two tags apart within one, and the tag text is beside it either way. Do not widen the list to chase the number on one board
- 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
Generated
+1 -1
View File
@@ -1494,7 +1494,7 @@ dependencies = [
[[package]]
name = "worklane"
version = "0.13.1"
version = "0.13.3"
dependencies = [
"anyhow",
"assert_cmd",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "worklane"
version = "0.13.1"
version = "0.13.3"
edition = "2024"
[dependencies]
+1 -1
View File
@@ -7,7 +7,7 @@ Worklane is a local Kanban flow for agentic software development.
|---------|-------------|
| `worklane` or `worklane tui [path...]` | Opens the board: four status columns, redrawn when the tree changes. Read only. Opens on backlog, committed and reviewing; `d` shows or hides done, whose count stays in the footer either way. Arrows or `hjkl` to move, `enter` for detail, `pgup`/`pgdn` to scroll an open ticket, `q` to quit. Each path opens the first `.worklane` at or above it, the working directory by default. Several paths are monitored together, as a tab per project plus an `all` tab that merges them, with `tab` and `shift+tab` between them |
| `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`, `--priority` flags |
| `worklane add` | Creates a ticket in backlog with `--title`, `--description`, `--acceptance`, `--plan`, `--tags`, `--due`, `--owner`, `--priority` flags. `--due` takes `YYYY-MM-DD` and refuses anything else at parse time |
| `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 (4+ chars), title substring, or filename substring |
| `worklane mv <id> --status <target> [-f]` | Moves ticket between statuses. Default: forward only, one stage at a time. `-f` bypasses both restrictions |
+5 -4
View File
@@ -17,7 +17,7 @@ which command owns which field. Read it too. This document is the judgement.
**Propose the whole set of edits, wait, then apply exactly what was approved.**
Every job here writes to many tickets at once, and no field can be cleared back to unset
yet, so a due date written by mistake can only be overwritten with another guess. A wrong
yet, so a date written onto the wrong ticket can only be overwritten, never taken off. A wrong
edit to one ticket is a mistake; a wrong sweep is thirty of them with no undo. So a
proposal is a list, one line per intended edit, each naming the ticket and the command
that would make it:
@@ -96,9 +96,10 @@ What to look for:
`worklane set <ticket> --due 2026-08-29`, format `YYYY-MM-DD`.
**The value is not validated.** A typo is stored as written rather than refused, and it
cannot be cleared afterwards, only replaced. Write it once, carefully, and read it back
with `show`.
A value that is not a real calendar date in that exact form is refused before anything
is written, so a typo costs nothing. `2026-8-9` is refused too: the padding is part of
the format. What is still true is that a date, once written, **cannot be cleared**, only
replaced by another date, so a plan applied to the wrong ticket has no undo.
Ask the system what today is rather than assuming it. A plan built on a guessed date is
wrong by however much the guess was wrong.
+3
View File
@@ -85,6 +85,9 @@ worklane add \
checked off as true or false.
- **`--plan`** takes one step per flag, numbered for you.
- **`--priority`** runs 1 (most urgent) to 5 (least), and is left unset if omitted.
- **`--due`** takes `YYYY-MM-DD` and nothing else. Anything that is not a real calendar
date in that exact form, `2026-8-9` and `2026-02-30` included, is a usage error with
nothing written. The same parser guards `set --due`.
Editing afterwards, on a ticket in any status:
+44 -2
View File
@@ -2,6 +2,8 @@ use clap::Parser;
use std::sync::LazyLock;
use chrono::NaiveDate;
use crate::util::{PRIORITY_RANGE, RelationKind, priority_legend};
/// clap wants a `&str` with a long enough lifetime, and the legend is built from
@@ -53,6 +55,42 @@ fn non_empty(raw: &str) -> Result<String, String> {
Ok(raw.to_string())
}
/// Reject a due date that is not a real calendar date in the promised form.
///
/// At parse time, like `priority_level`, so a mistyped date is a usage error with
/// nothing written rather than a value the board goes on showing. `--due` is one of the
/// scalars deliberately left without `PROSE`, so this is the same bargain: nothing here
/// holds prose, and a wrong value should stop the command.
///
/// **The shape is checked before chrono sees it.** `%Y-%m-%d` accepts an unpadded
/// `2026-8-9`, which would then be stored exactly as typed and sort before `2026-10-01`
/// in any comparison of the strings. Checking the length and the two dashes first is
/// what lets a valid date be stored unchanged rather than normalised on the way in.
///
/// Strict on the way in, tolerant on the way out: `util::due_date` still cuts a
/// datetime down to its date, because a file written before this existed, or by hand,
/// can hold one and still has to render.
fn iso_date(raw: &str) -> Result<String, String> {
// An empty value keeps the message that explains why it is refused, since somebody
// typing it is reaching for a way to clear the field rather than mistyping a date.
non_empty(raw)?;
let bytes = raw.as_bytes();
let shaped = raw.len() == 10 && bytes[4] == b'-' && bytes[7] == b'-';
if !shaped || NaiveDate::parse_from_str(raw, "%Y-%m-%d").is_err() {
// Not echoing the value: clap has already printed `invalid value '...' for
// '--due <DUE>'` above this line, and `priority_level` says its piece the same
// way.
return Err(
"due date must be a real calendar date written as YYYY-MM-DD, for example 2026-08-29"
.to_string(),
);
}
Ok(raw.to_string())
}
/// Arguments that carry prose, and therefore have to accept a value starting with
/// a hyphen.
///
@@ -275,7 +313,7 @@ pub struct AddArgs {
pub tags: Vec<String>,
/// Due date (YYYY-MM-DD)
#[arg(long)]
#[arg(long, value_parser = iso_date)]
pub due: Option<String>,
/// Owner
@@ -324,7 +362,11 @@ pub struct SetArgs {
pub tags: Vec<String>,
/// Replace the due date (YYYY-MM-DD)
#[arg(long, value_parser = non_empty)]
///
/// The same parser as `add`: one field, one definition of what a due date is. The
/// planning skill sets dates through `set` rather than `add`, so validating only
/// the one that files a ticket would leave the path that is actually used open.
#[arg(long, value_parser = iso_date)]
pub due: Option<String>,
/// Replace the priority, 1 (most urgent) to 5 (least)
+1 -1
View File
@@ -387,7 +387,7 @@ mod tests {
for required in [
"Propose the whole set of edits",
"replaces the whole\nfield", // `set --tags` is the destructive one
"not validated", // and a due date cannot be taken back
"cannot be cleared", // and a due date cannot be taken back
"blocked by", // ordering constrains any dating plan
"worklane campaign ls",
"does not touch",
+33 -9
View File
@@ -921,6 +921,10 @@ fn card_lines(card: &Card, selected: bool, width: u16) -> Vec<Line<'static>> {
/// corner: a cut list reads as a shorter one, and `bug` and `bugfix` truncated to the
/// same width say the same thing. An untagged ticket spends no row at all, the way a
/// short title spends no second one.
///
/// Each tag carries its own colour, from `tag_color`, so the same tag is the same
/// colour on every card in every column. The row is spans rather than one string for
/// that reason alone; it is still measured as one string.
fn tags_line(tags: &[String], width: u16) -> Option<Line<'static>> {
if tags.is_empty() {
return None;
@@ -932,14 +936,25 @@ fn tags_line(tags: &[String], width: u16) -> Option<Line<'static>> {
.collect::<Vec<_>>()
.join(" ");
// Measured on the raw row, before anything is styled. What fits must not depend on
// the colour decision, or a card would hold its tags in one render and drop them in
// the other.
if row.chars().count() > width as usize {
return None;
}
Some(Line::from(Span::styled(
row,
Style::default().fg(Color::Grey.into()),
)))
let mut spans = Vec::with_capacity(tags.len() * 2);
for (index, tag) in tags.iter().enumerate() {
if index > 0 {
spans.push(Span::raw(" "));
}
spans.push(Span::styled(
format!("#{tag}"),
Style::default().fg(tag_color(tag).into()),
));
}
Some(Line::from(spans))
}
/// The project name as it fits beside the mark and the id.
@@ -1645,14 +1660,23 @@ mod tests {
assert!(rows[3].starts_with("alice"), "the owner moved: {rows:?}");
}
/// Dimmed like the owner and the count beside it: the row is there to be scanned,
/// not to compete with the title.
/// Each tag carries its own colour, so the row can be scanned for one tag rather
/// than read word by word. The row used to be a single grey span, which is what
/// made a card of three tags one undifferentiated run.
#[test]
fn the_tag_row_is_dimmed() {
fn each_tag_on_a_card_carries_its_own_colour() {
let dir = board_dir();
write_tagged_card(&dir, "Short", "2026-12-31", "- [ ] One", "cli, tui");
write_tagged_card(&dir, "Short", "2026-12-31", "- [ ] One", "cli, docs");
assert_eq!(card_colour(&dir, 120, "#cli #tui"), Some(Color::Grey.into()));
let cli = card_colour(&dir, 120, "#cli");
let docs = card_colour(&dir, 120, "#docs");
// Through `tag_color`, not against a literal: the card has to use the mapping,
// and the mapping is pinned by its own test in util.rs.
assert_eq!(cli, Some(tag_color("cli").into()));
assert_eq!(docs, Some(tag_color("docs").into()));
assert_ne!(cli, docs, "two tags rendered in one colour");
assert_ne!(cli, Some(Color::Grey.into()), "the row is still flat grey");
}
/// And an untagged one spends no row on them, the way a short title spends no
+262 -1
View File
@@ -68,6 +68,17 @@ pub enum Color {
Grey,
Magenta,
BrightRed,
// The eight the tag palette draws from. Named as colours rather than as `TagBlue`,
// because the enum is the palette and `TAG_COLORS` is what reserves them: a use
// belongs to the list that claims it, not to the name of the colour it claims.
Blue,
Sky,
Violet,
Pink,
Turquoise,
Olive,
Tan,
Steel,
}
impl Color {
@@ -88,11 +99,23 @@ impl Color {
Color::Magenta => "\x1b[1;35m",
// Indexed, for the same reason grey is: this is the spelling that renders.
Color::BrightRed => "\x1b[38;5;9m",
// The tag palette, indexed throughout. The basic slots are themed by the
// terminal and drift towards each other on a real palette, which is fine
// for seven colours that each mean something and useless for six that have
// to stay apart from those seven and from one another.
Color::Blue => "\x1b[38;5;33m",
Color::Sky => "\x1b[38;5;117m",
Color::Violet => "\x1b[38;5;99m",
Color::Pink => "\x1b[38;5;205m",
Color::Turquoise => "\x1b[38;5;43m",
Color::Olive => "\x1b[38;5;106m",
Color::Tan => "\x1b[38;5;137m",
Color::Steel => "\x1b[38;5;67m",
}
}
/// Every colour in the palette, so a test can walk them without listing them.
pub const ALL: [Color; 7] = [
pub const ALL: [Color; 15] = [
Color::Red,
Color::Cyan,
Color::Orange,
@@ -100,9 +123,95 @@ impl Color {
Color::Grey,
Color::Magenta,
Color::BrightRed,
Color::Blue,
Color::Sky,
Color::Violet,
Color::Pink,
Color::Turquoise,
Color::Olive,
Color::Tan,
Color::Steel,
];
}
/// The colours a tag may be drawn in.
///
/// Deliberately disjoint from the seven that already carry a meaning, per the guideline
/// in AGENTS.md: a tag in red reads as a uuid, in green as a title, in grey as an unset
/// value. Reserving slots here rather than picking at the call site is what keeps the
/// next colour someone assigns from landing on top of the tags.
///
/// Eight, and a real board carries more tags than that, so two tags will share a
/// colour. That is accepted rather than designed around: the colour groups one tag
/// across cards, it does not identify it, and the tag is written out beside it either
/// way. Nothing pure can do better, since a function of the tag alone cannot know what
/// else sits on the card.
///
/// Eight rather than six because two tags on one card collide at roughly `1 / n`, so
/// the only lever is the size of the list. It stops here because these are the slots
/// the assigned meanings leave: red, orange, green, cyan, magenta and grey are spoken
/// for, and a ninth would have to be a shade of one of the eight. Two colours nobody
/// can tell apart are a collision by another name.
///
/// At eight, about a fifth of the cards on this board show two tags in one colour. That
/// is the arithmetic, not a fault to fix: the colour groups one tag *across* cards, so
/// a repeat within a card costs nothing that the tag text beside it does not answer.
///
/// Do not tune this against the tags on one board. The count of collisions on any given
/// board swings either side of the average on the luck of the hash, and picking the
/// length that flatters today's vocabulary would be fitting to noise. An earlier draft
/// scored two collisions in sixty-four here, which looked like a good palette and was
/// really a broken index folding the whole vocabulary into a handful of slots.
pub const TAG_COLORS: [Color; 8] = [
Color::Blue,
Color::Sky,
Color::Violet,
Color::Pink,
Color::Turquoise,
Color::Olive,
Color::Tan,
Color::Steel,
];
/// FNV-1a, 64 bit, over the bytes of the tag.
///
/// Written out rather than taken from `std`: `DefaultHasher` is explicitly not promised
/// to keep its output stable across releases, and a board that repaints itself on a
/// toolchain upgrade has lost the one property this is for. Nine lines and no
/// dependency buys a mapping that is the same on every machine and every version.
fn fnv1a(bytes: &[u8]) -> u64 {
const OFFSET: u64 = 0xcbf2_9ce4_8422_2325;
const PRIME: u64 = 0x0000_0100_0000_01b3;
let mut hash = OFFSET;
for byte in bytes {
hash ^= u64::from(*byte);
hash = hash.wrapping_mul(PRIME);
}
hash
}
/// The colour a tag is drawn in, derived from the tag itself.
///
/// A pure function of the string, so the same tag is the same colour on every card, in
/// every view and on every board, with nothing stored and nothing to keep in step. Two
/// boards that have never met agree about `bug`.
///
/// Case sensitive, because `Bug` and `bug` are two different tags everywhere else in
/// worklane. Colouring them alike would be the display claiming a sameness the filter
/// and the field do not have.
pub fn tag_color(tag: &str) -> Color {
// Multiply-shift, not `% len`. The palette length is a power of two, so a modulus
// would keep the low three bits of the hash, and FNV-1a's low bits carry only the
// low bits of the input bytes: the multiply cannot move information downwards and
// the xor never does. `bug` and `BUG` differ in bit 5 of every letter, so under a
// modulus they landed in the same slot no matter what else the strings held, as did
// every other pair differing only above bit 2. Taking the top bits of the product
// uses the whole hash, which is where the avalanche is.
let index = (u128::from(fnv1a(tag.as_bytes())) * TAG_COLORS.len() as u128) >> 64;
TAG_COLORS[index as usize]
}
/// The same palette as ratatui sees it.
///
/// Chosen to match what crossterm emits for the escape above, so a card in the TUI and
@@ -119,6 +228,16 @@ impl From<Color> for ratatui::style::Color {
Color::Grey => Tui::DarkGray,
Color::Magenta => Tui::Magenta,
Color::BrightRed => Tui::LightRed,
// Indexed on both sides, so the card and the listing are the same colour
// by construction rather than by two guesses that happen to agree.
Color::Blue => Tui::Indexed(33),
Color::Sky => Tui::Indexed(117),
Color::Violet => Tui::Indexed(99),
Color::Pink => Tui::Indexed(205),
Color::Turquoise => Tui::Indexed(43),
Color::Olive => Tui::Indexed(106),
Color::Tan => Tui::Indexed(137),
Color::Steel => Tui::Indexed(67),
}
}
}
@@ -673,9 +792,40 @@ fn metadata_value_cell(name: &str, value: &str, colored: bool, campaign: &str) -
return paint(value, Color::Grey, colored);
}
if name == "Tags" {
return paint_tags(value, colored);
}
value.to_string()
}
/// The stored tag list with each tag in its own colour.
///
/// Painted in place rather than split and rejoined, so whatever separators the file
/// holds come back unchanged. `bug, cli` and `bug,cli` are both written by hand at some
/// point, and a cell that normalised them would be the display quietly disagreeing with
/// the file it is showing.
fn paint_tags(value: &str, colored: bool) -> String {
value
.split(',')
.map(|piece| {
let tag = piece.trim();
if tag.is_empty() {
return piece.to_string();
}
let lead = piece.len() - piece.trim_start().len();
format!(
"{}{}{}",
&piece[..lead],
paint(tag, tag_color(tag), colored),
&piece[lead + tag.len()..]
)
})
.collect::<Vec<_>>()
.join(",")
}
/// Render the Metadata section as two aligned columns.
///
/// Taken as a block rather than a line at a time because the field column cannot be
@@ -2801,6 +2951,117 @@ mod tests {
assert_eq!(seen.len(), Color::ALL.len());
}
/// The text a cell holds once its colour is taken off, so a test can assert the
/// separators survived without spelling out the escapes around them.
fn strip_escapes(text: &str) -> String {
let mut out = String::with_capacity(text.len());
let mut rest = text;
while let Some(at) = rest.find('\x1b') {
out.push_str(&rest[..at]);
match rest[at..].find('m') {
Some(end) => rest = &rest[at + end + 1..],
None => return out,
}
}
out.push_str(rest);
out
}
#[test]
fn a_tag_keeps_its_colour_and_different_tags_do_not_all_share_one() {
assert_eq!(tag_color("bug"), tag_color("bug"));
assert_eq!(tag_color("frontend"), tag_color("frontend"));
let spread: std::collections::HashSet<Color> =
["bug", "feature", "cli", "tui", "docs", "chore", "output", "skills"]
.iter()
.map(|tag| tag_color(tag))
.collect();
assert!(spread.len() > 3, "the mapping collapses the vocabulary: {spread:?}");
}
/// Case sensitive on purpose: `Bug` and `bug` are two different tags to the field
/// and to every search, so one colour for both would be the display claiming a
/// sameness nothing else has.
///
/// Over a set rather than one pair. Any single pair can land in the same slot by
/// luck, one time in `TAG_COLORS.len()`, and a test that reads that accident as
/// case folding would be asserting the hash rather than the rule.
#[test]
fn tag_colour_does_not_fold_case() {
let folded = ["bug", "cli", "tui", "docs", "chore"]
.iter()
.all(|tag| tag_color(tag) == tag_color(&tag.to_uppercase()));
assert!(!folded, "tag_color lowercases before hashing");
}
/// Pinned so that a change to the hash is a failing test rather than a board that
/// quietly repaints itself. If this fails, the mapping moved: decide whether that
/// was intended before rewriting the expectations.
#[test]
fn the_tag_mapping_is_pinned() {
assert_eq!(tag_color("bug"), Color::Blue);
assert_eq!(tag_color("feature"), Color::Blue);
assert_eq!(tag_color("cli"), Color::Steel);
assert_eq!(tag_color("tui"), Color::Violet);
assert_eq!(tag_color("docs"), Color::Tan);
assert_eq!(tag_color("chore"), Color::Sky);
assert_eq!(tag_color("skills"), Color::Tan);
assert_eq!(tag_color("output"), Color::Blue);
}
/// The whole reason the tag palette is a reserved list rather than a pick at the
/// call site: a tag drawn in red reads as a uuid, in green as a title, in grey as
/// an unset value.
#[test]
fn no_tag_colour_carries_another_meaning() {
for assigned in [
Color::Red,
Color::Orange,
Color::Cyan,
Color::Green,
Color::Grey,
Color::Magenta,
Color::BrightRed,
] {
assert!(
!TAG_COLORS.contains(&assigned),
"{assigned:?} means something else already"
);
}
// The priority ramp is the other list that claims colours, and it is built from
// the assigned seven rather than named here, so ask it directly.
for level in PRIORITY_RANGE {
let ramp = priority_mark(Priority::Level(level)).1;
assert!(!TAG_COLORS.contains(&ramp), "{ramp:?} is a priority colour");
}
}
#[test]
fn the_tags_cell_paints_each_tag_and_leaves_the_separators_alone() {
let plain = metadata_value_cell("Tags", "bug, cli", false, "");
assert_eq!(plain, "bug, cli", "colour off must be the stored value");
let painted = metadata_value_cell("Tags", "bug, cli", true, "");
assert!(painted.contains(&paint("bug", tag_color("bug"), true)));
assert!(painted.contains(&paint("cli", tag_color("cli"), true)));
// The separator the file holds comes back as it went in, spacing and all.
assert_eq!(strip_escapes(&painted), "bug, cli");
assert_eq!(strip_escapes(&metadata_value_cell("Tags", "bug,cli", true, "")), "bug,cli");
assert_eq!(strip_escapes(&metadata_value_cell("Tags", " bug , cli ", true, "")), " bug , cli ");
}
/// An unset value stays grey, since the Tags branch sits behind the unknown check.
#[test]
fn an_unset_tags_cell_is_still_grey() {
assert_eq!(
metadata_value_cell("Tags", "_None_", true, ""),
paint("_None_", Color::Grey, true)
);
}
/// Pinned deliberately. Both SGR spellings of grey failed on a real palette,
/// 90 reading nearly as light as the foreground and 37 sitting on top of it.
/// This is the exact sequence crossterm emits for ratatui's Color::DarkGray,
+104
View File
@@ -457,3 +457,107 @@ fn add_treats_an_all_blank_description_as_none() {
"was {content:?}"
);
}
/// The help, the README and the skill all promise `YYYY-MM-DD`, and until this the
/// value was written to the ticket whatever it said.
#[test]
fn add_stores_a_valid_due_date_unchanged() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
cmd.current_dir(temp.path())
.arg("add")
.args(["--title", "Dated"])
.args(["--due", "2026-08-29"])
.assert()
.success();
let content = read_only_ticket(&worklane.join("backlog"));
assert!(content.contains("- **Due**: 2026-08-29"), "{content}");
}
/// Every one of these is refused at parse time, so the exit code is 2 and nothing is
/// written. A date that cannot happen is as wrong as a word: `2026-02-30` has the shape
/// and is not a day.
#[test]
fn add_refuses_a_due_date_that_is_not_a_real_iso_date() {
for value in ["next friday", "29-08-2026", "2026-13-01", "2026-02-30", "2026/08/29", ""] {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
let out = cmd
.current_dir(temp.path())
.arg("add")
.args(["--title", "Dated"])
.args(["--due", value])
.assert()
.failure()
.get_output()
.clone();
assert_eq!(out.status.code(), Some(2), "{value:?} was not a usage error");
assert_eq!(
fs::read_dir(worklane.join("backlog")).unwrap().count(),
0,
"{value:?} wrote a ticket anyway"
);
}
}
/// An unpadded date parses as a date and would be stored as typed, which sorts before
/// `2026-10-01` and is not the format anything promises.
#[test]
fn add_refuses_an_unpadded_due_date_rather_than_padding_it() {
let temp = TempDir::new().unwrap();
setup_worklane(&temp);
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
let stderr = String::from_utf8_lossy(
&cmd.current_dir(temp.path())
.arg("add")
.args(["--title", "Dated"])
.args(["--due", "2026-8-9"])
.assert()
.failure()
.get_output()
.stderr,
)
.to_string();
assert!(stderr.contains("YYYY-MM-DD"), "the error never names the format: {stderr}");
}
/// An empty value keeps the message about clearing, since that is what somebody typing
/// it is reaching for.
#[test]
fn an_empty_due_date_says_clearing_is_not_supported() {
let temp = TempDir::new().unwrap();
setup_worklane(&temp);
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
let stderr = String::from_utf8_lossy(
&cmd.current_dir(temp.path())
.arg("add")
.args(["--title", "Dated"])
.args(["--due", ""])
.assert()
.failure()
.get_output()
.stderr,
)
.to_string();
assert!(stderr.contains("clearing a field is not supported"), "{stderr}");
}
fn read_only_ticket(dir: &Path) -> String {
let file = fs::read_dir(dir)
.unwrap()
.filter_map(|e| e.ok())
.find(|e| e.path().extension().is_some_and(|ext| ext == "md"))
.expect("no ticket written");
fs::read_to_string(file.path()).unwrap()
}
+47
View File
@@ -415,3 +415,50 @@ fn neither_command_can_write_owner_or_status() {
assert!(content.contains("- **Owner**: alice"));
assert!(content.contains("- **Status**: backlog"));
}
/// The same parser `add` uses, from one definition. Grooming a board sets dates through
/// `set`, so validating only the command that files a ticket would leave the path that
/// is actually used wide open.
#[test]
fn set_refuses_a_due_date_that_is_not_a_real_iso_date() {
for value in ["next friday", "2026-02-30", "2026-8-9"] {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let filename = create_ticket(&worklane);
let before = fs::read_to_string(worklane.join("backlog").join(&filename)).unwrap();
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
let out = cmd
.current_dir(temp.path())
.args(["set", UUID])
.args(["--due", value])
.assert()
.failure()
.get_output()
.clone();
assert_eq!(out.status.code(), Some(2), "{value:?} was not a usage error");
assert_eq!(
fs::read_to_string(worklane.join("backlog").join(&filename)).unwrap(),
before,
"{value:?} changed the ticket anyway"
);
}
}
#[test]
fn set_stores_a_valid_due_date_unchanged() {
let temp = TempDir::new().unwrap();
let worklane = setup_worklane(&temp);
let filename = create_ticket(&worklane);
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
cmd.current_dir(temp.path())
.args(["set", UUID])
.args(["--due", "2026-12-31"])
.assert()
.success();
let content = fs::read_to_string(worklane.join("backlog").join(&filename)).unwrap();
assert!(content.contains("- **Due**: 2026-12-31"), "{content}");
}