(d4ce964) Record status, owner and tag changes in a history log, and bump to 0.29.0
The comments directory was already an append-only log with one event kind. It is now .worklane/history/<uuid>/, with the kind in the entry and in the filename after the stamp, so a ticket says how it got where it is and not only what was said about it. mv, chown and set --tags each write an entry after their own save and behind their own no-change return, so a refused or no-op edit records nothing. --actor is on all four writers now. An old comments directory is adopted on first access and a file with no marker reads as the comment it is, so nothing is migrated or rewritten. The log moves to src/history.rs, out of util.rs and handlers.rs, and the card's counter counts comments only: a ticket that has moved three times has not been talked about. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
a1bdb5df49
commit
f454d212a4
+614
@@ -0,0 +1,614 @@
|
||||
//! What happened to a ticket, one file per entry.
|
||||
//!
|
||||
//! The comments directory was already an append-only log with exactly one event kind:
|
||||
//! one file per entry under a directory named by the ticket's uuid, stamped to the
|
||||
//! microsecond and written with `create_new` so two writers cannot clobber each other.
|
||||
//! This is that log with the kind named in it, so a status change, an owner change and a
|
||||
//! tag change are recorded beside what somebody said about them.
|
||||
//!
|
||||
//! What is deliberately not logged: ticking or unticking a criterion, and edits to the
|
||||
//! title, description, plan, priority or due. Those change often and a log of them is
|
||||
//! noise. When one of them matters, whoever made it adds a comment saying why, which is
|
||||
//! the record actually worth keeping.
|
||||
//!
|
||||
//! Every entry names its author, from [`resolve_actor`], so a board several agents write
|
||||
//! to says which of them did what.
|
||||
//!
|
||||
//! [`resolve_actor`]: crate::util::resolve_actor
|
||||
|
||||
use std::fs;
|
||||
use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use anyhow::{Result, anyhow};
|
||||
use chrono::Local;
|
||||
|
||||
use crate::util::{Color, TIMESTAMP_FORMAT, paint, should_use_colors};
|
||||
|
||||
/// Where a ticket's history lives, under the board.
|
||||
///
|
||||
/// Beside the status directories rather than among them, the way `campaigns_dir` is: an
|
||||
/// entry has no status of its own. Spelled once here, so the writer, the reader and the
|
||||
/// card's counter cannot disagree about the path.
|
||||
pub const HISTORY_DIR: &str = "history";
|
||||
|
||||
/// The name the same directory had while a comment was the only entry it could hold.
|
||||
///
|
||||
/// Kept so a board written by an older version is adopted rather than migrated by hand.
|
||||
/// See [`adopt_comments`].
|
||||
pub const COMMENTS_DIR: &str = "comments";
|
||||
|
||||
/// How an entry filename is stamped.
|
||||
///
|
||||
/// Microseconds, not seconds: at second resolution two entries in the same second
|
||||
/// produced the same name and the second silently truncated the first. Fixed width and
|
||||
/// first in the name, so the lexicographic sort in [`read_history`] stays chronological
|
||||
/// whatever kind follows it.
|
||||
pub const ENTRY_FILE_FORMAT: &str = "%Y%m%d_%H%M%S_%6f";
|
||||
|
||||
/// The history root of a board.
|
||||
pub fn history_root(board: &Path) -> PathBuf {
|
||||
board.join(HISTORY_DIR)
|
||||
}
|
||||
|
||||
/// The history directory for one ticket, named by its full uuid.
|
||||
pub fn history_dir(board: &Path, uuid: &str) -> PathBuf {
|
||||
history_root(board).join(uuid)
|
||||
}
|
||||
|
||||
/// What an entry records.
|
||||
///
|
||||
/// An enum rather than a string, so a kind the reader does not know is a compile error
|
||||
/// instead of a word that renders as itself. The variants are the four things worth
|
||||
/// keeping: what somebody said, and the three fields whose history answers a question.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Kind {
|
||||
Comment,
|
||||
Status,
|
||||
Owner,
|
||||
Tags,
|
||||
}
|
||||
|
||||
impl Kind {
|
||||
/// Every kind, which is what the reader matches a marker against and what the
|
||||
/// counter matches a filename against.
|
||||
pub const ALL: [Kind; 4] = [Kind::Comment, Kind::Status, Kind::Owner, Kind::Tags];
|
||||
|
||||
/// The width the mechanical labels are padded to, `status` being the longest of the
|
||||
/// three. `comment` is longer and is not padded to: a comment renders as a header
|
||||
/// and a body, not as a row.
|
||||
const LABEL_WIDTH: usize = 6;
|
||||
|
||||
/// The word in the filename, and the label a mechanical entry renders under.
|
||||
pub fn slug(self) -> &'static str {
|
||||
match self {
|
||||
Kind::Comment => "comment",
|
||||
Kind::Status => "status",
|
||||
Kind::Owner => "owner",
|
||||
Kind::Tags => "tags",
|
||||
}
|
||||
}
|
||||
|
||||
/// The marker the file opens with, which is what the reader keys the kind off.
|
||||
///
|
||||
/// The file is the record and the filename is an index into it: a name can be
|
||||
/// changed by anything that touches the directory, so the kind is read from the
|
||||
/// content and only counted from the name.
|
||||
fn marker(self) -> &'static str {
|
||||
match self {
|
||||
Kind::Comment => "**Comment**",
|
||||
Kind::Status => "**Status**",
|
||||
Kind::Owner => "**Owner**",
|
||||
Kind::Tags => "**Tags**",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// One entry: what happened, who wrote it and when.
|
||||
#[derive(Debug)]
|
||||
pub struct Entry {
|
||||
/// The file stem, which is what the entries are sorted by.
|
||||
pub filename: String,
|
||||
pub kind: Kind,
|
||||
pub author: String,
|
||||
pub time: String,
|
||||
/// A comment's text, or the before and after of the field a mechanical entry names.
|
||||
pub body: String,
|
||||
}
|
||||
|
||||
/// Rename an old `comments` directory to `history`, before anything reads or writes it.
|
||||
///
|
||||
/// One rename rather than a migration command: the entries themselves need no rewriting,
|
||||
/// since [`parse_entry`] reads a file with no marker as the comment it is. Called by the
|
||||
/// reader, the writer and the counter, so no caller has to remember it and a board can
|
||||
/// never be reached through a path that skips it.
|
||||
///
|
||||
/// Both directories at once is refused rather than merged. Only the CLI writes there, so
|
||||
/// it cannot arrive at that state on its own, and choosing which of two entries with the
|
||||
/// same name survives is not a decision to make silently.
|
||||
pub fn adopt_comments(board: &Path) -> Result<()> {
|
||||
let old = board.join(COMMENTS_DIR);
|
||||
if !old.exists() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let new = history_root(board);
|
||||
if new.exists() {
|
||||
return Err(anyhow!(
|
||||
"Board holds both {} and {}. Only worklane writes there, so this needs a \
|
||||
person: move the entries under {} into the matching directories in {}, \
|
||||
then remove it.",
|
||||
old.display(),
|
||||
new.display(),
|
||||
COMMENTS_DIR,
|
||||
HISTORY_DIR,
|
||||
));
|
||||
}
|
||||
|
||||
fs::rename(&old, &new)
|
||||
.map_err(|e| anyhow!("Could not rename {} to {}: {}", old.display(), new.display(), e))
|
||||
}
|
||||
|
||||
/// One entry, from its filename and its content.
|
||||
///
|
||||
/// Split out from the directory walk so the parse can be tested without a fixture, and
|
||||
/// because it is where the compatibility lives: a file with no marker is a comment,
|
||||
/// which is what every entry written before the kinds existed is.
|
||||
fn parse_entry(filename: &str, content: &str) -> Entry {
|
||||
let field = |name: &str| {
|
||||
let marker = format!("**{}**:", name);
|
||||
content
|
||||
.lines()
|
||||
.find(|line| line.starts_with(&marker))
|
||||
.and_then(|line| line.split_once(&marker))
|
||||
.map(|(_, value)| value.trim().to_string())
|
||||
.unwrap_or_else(|| "unknown".to_string())
|
||||
};
|
||||
|
||||
let kind = Kind::ALL
|
||||
.into_iter()
|
||||
.find(|kind| content.starts_with(&format!("{}\n", kind.marker())))
|
||||
.unwrap_or(Kind::Comment);
|
||||
|
||||
let body = content
|
||||
.strip_prefix(&format!("{}\n", kind.marker()))
|
||||
.map(|rest| match rest.find("\n\n**Author**") {
|
||||
Some(end) => rest[..end].trim(),
|
||||
None => rest.trim(),
|
||||
})
|
||||
.unwrap_or("");
|
||||
|
||||
Entry {
|
||||
filename: filename.to_string(),
|
||||
kind,
|
||||
author: field("Author"),
|
||||
time: field("Time"),
|
||||
body: body.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Every entry on a ticket, oldest first.
|
||||
///
|
||||
/// Public for the TUI's detail view, which shows the same sequence `show` does.
|
||||
pub fn read_history(board: &Path, uuid: &str) -> Result<Vec<Entry>> {
|
||||
adopt_comments(board)?;
|
||||
|
||||
let dir = history_dir(board, uuid);
|
||||
if !dir.exists() {
|
||||
return Ok(vec![]);
|
||||
}
|
||||
|
||||
let mut entries: Vec<Entry> = Vec::new();
|
||||
|
||||
for entry in fs::read_dir(&dir)? {
|
||||
let path = entry?.path();
|
||||
if path.extension().is_some_and(|ext| ext == "md") {
|
||||
let content = fs::read_to_string(&path)?;
|
||||
let filename = path
|
||||
.file_stem()
|
||||
.map(|stem| stem.to_string_lossy().to_string())
|
||||
.unwrap_or_default();
|
||||
entries.push(parse_entry(&filename, &content));
|
||||
}
|
||||
}
|
||||
|
||||
// The stamp is fixed width and leads the name, so this is chronological.
|
||||
entries.sort_by(|a, b| a.filename.cmp(&b.filename));
|
||||
|
||||
Ok(entries)
|
||||
}
|
||||
|
||||
/// The kind a filename names, which is what the count reads instead of the file.
|
||||
///
|
||||
/// A stem with no kind in it is a comment, the same compatibility [`parse_entry`] has.
|
||||
/// The collision suffix is a number and matches no slug, so it is skipped.
|
||||
fn kind_from_stem(stem: &str) -> Kind {
|
||||
stem.split('_')
|
||||
.find_map(|part| Kind::ALL.into_iter().find(|kind| kind.slug() == part))
|
||||
.unwrap_or(Kind::Comment)
|
||||
}
|
||||
|
||||
/// How many comments a ticket carries, counted off the directory rather than read.
|
||||
///
|
||||
/// Comments only, so the card's counter still says how many things somebody said: a
|
||||
/// ticket that has moved three times has not been talked about. `.md` only, the filter
|
||||
/// [`read_history`] applies, so a stray file dropped in there is not counted. A missing
|
||||
/// directory is none, which is what a ticket nothing has happened to has.
|
||||
pub fn count_comments(board: &Path, uuid: &str) -> usize {
|
||||
// Swallowed, unlike the reader's: a count is drawn on every card and a board that
|
||||
// cannot be adopted has to draw as the zero it looks like rather than take the TUI
|
||||
// down. The next write reports the real reason.
|
||||
let _ = adopt_comments(board);
|
||||
|
||||
let Ok(entries) = fs::read_dir(history_dir(board, uuid)) else {
|
||||
return 0;
|
||||
};
|
||||
|
||||
entries
|
||||
.filter_map(|entry| entry.ok())
|
||||
.filter(|entry| entry.path().extension().is_some_and(|ext| ext == "md"))
|
||||
.filter(|entry| {
|
||||
let stem = entry.path().file_stem().map(|s| s.to_string_lossy().to_string());
|
||||
stem.is_some_and(|stem| kind_from_stem(&stem) == Kind::Comment)
|
||||
})
|
||||
.count()
|
||||
}
|
||||
|
||||
/// The file an entry is written as.
|
||||
///
|
||||
/// A comment's file is byte for byte what `comment` wrote before the kinds existed, so
|
||||
/// nothing has to be rewritten and a board can be read by either version.
|
||||
fn entry_content(kind: Kind, body: &str, author: &str, time: &str) -> String {
|
||||
format!(
|
||||
"{}\n\
|
||||
{}\n\
|
||||
\n\
|
||||
**Author**: {}\n\
|
||||
**Time**: {}\n\
|
||||
",
|
||||
kind.marker(),
|
||||
body,
|
||||
author,
|
||||
time
|
||||
)
|
||||
}
|
||||
|
||||
/// Write an entry under the first free name derived from the stamp.
|
||||
///
|
||||
/// `create_new` rather than `fs::write`: a name that already exists means another entry
|
||||
/// landed in the same microsecond, and truncating it is exactly the data loss this
|
||||
/// guards against. The suffix is zero padded so the names keep sorting in the order they
|
||||
/// were written.
|
||||
fn write_new(dir: &Path, stem: &str, content: &str) -> Result<String> {
|
||||
for attempt in 0..100 {
|
||||
let filename = match attempt {
|
||||
0 => format!("{}.md", stem),
|
||||
n => format!("{}_{:02}.md", stem, n),
|
||||
};
|
||||
|
||||
match fs::OpenOptions::new()
|
||||
.write(true)
|
||||
.create_new(true)
|
||||
.open(dir.join(&filename))
|
||||
{
|
||||
Ok(mut file) => {
|
||||
file.write_all(content.as_bytes())?;
|
||||
return Ok(filename);
|
||||
}
|
||||
Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => continue,
|
||||
Err(e) => return Err(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
Err(anyhow!("No free entry filename for '{}' in {}", stem, dir.display()))
|
||||
}
|
||||
|
||||
/// Record one entry on a ticket, returning the filename it landed under.
|
||||
///
|
||||
/// Called after the edit it describes has been written, never before: an entry for a
|
||||
/// move that was refused would be a log of things that did not happen. The cost of that
|
||||
/// order is that a failed write here leaves the edit in place and reports the failure,
|
||||
/// which is the right way round — the ticket is the record and this is the story of it.
|
||||
pub fn write_entry(
|
||||
board: &Path,
|
||||
uuid: &str,
|
||||
kind: Kind,
|
||||
body: &str,
|
||||
author: &str,
|
||||
) -> Result<String> {
|
||||
adopt_comments(board)?;
|
||||
|
||||
let dir = history_dir(board, uuid);
|
||||
fs::create_dir_all(&dir)?;
|
||||
|
||||
let now = Local::now();
|
||||
let stem = format!("{}_{}", now.format(ENTRY_FILE_FORMAT), kind.slug());
|
||||
let content = entry_content(kind, body, author, &now.format(TIMESTAMP_FORMAT).to_string());
|
||||
|
||||
write_new(&dir, &stem, &content)
|
||||
}
|
||||
|
||||
/// What a mechanical entry records: the field before the edit and after it.
|
||||
///
|
||||
/// The values as the ticket holds them, sentinels included, so `_Not set_` reads the way
|
||||
/// the field it came from does rather than being translated into a word this module
|
||||
/// invented.
|
||||
pub fn change(before: &str, after: &str) -> String {
|
||||
format!("{} → {}", before, after)
|
||||
}
|
||||
|
||||
pub fn format_history(entries: &[Entry]) -> String {
|
||||
format_history_with(entries, should_use_colors())
|
||||
}
|
||||
|
||||
/// As above, with the colour decision passed in for the TUI.
|
||||
pub fn format_history_with(entries: &[Entry], colored: bool) -> String {
|
||||
if entries.is_empty() {
|
||||
return paint("No history yet.", Color::Grey, colored);
|
||||
}
|
||||
|
||||
let mut result = String::new();
|
||||
result.push('\n');
|
||||
result.push_str(&paint("HISTORY", Color::Orange, colored));
|
||||
result.push_str(&format!("\n{}\n", "─".repeat(20)));
|
||||
|
||||
for entry in entries {
|
||||
result.push('\n');
|
||||
let stamp = paint(&format!("{} ({})", entry.author, entry.time), Color::Cyan, colored);
|
||||
|
||||
match entry.kind {
|
||||
// As it has always read: a header naming who said it, then the text.
|
||||
Kind::Comment => {
|
||||
result.push_str(&paint(
|
||||
&format!("From {} ({})", entry.author, entry.time),
|
||||
Color::Cyan,
|
||||
colored,
|
||||
));
|
||||
result.push('\n');
|
||||
if !entry.body.is_empty() {
|
||||
result.push_str(" ");
|
||||
result.push_str(&entry.body);
|
||||
}
|
||||
result.push('\n');
|
||||
}
|
||||
// One line: a field change is one fact and a paragraph for it would bury the
|
||||
// comments it sits between.
|
||||
_ => {
|
||||
let label = paint(entry.kind.slug(), Color::Orange, colored);
|
||||
let padding = Kind::LABEL_WIDTH.saturating_sub(entry.kind.slug().chars().count());
|
||||
result.push_str(&format!(
|
||||
"{}{} {} {}\n",
|
||||
label,
|
||||
" ".repeat(padding),
|
||||
entry.body,
|
||||
stamp
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::util::Fixture;
|
||||
|
||||
fn board() -> Fixture {
|
||||
Fixture::new("worklane-history")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_entry_names_its_kind_in_the_file_and_in_the_filename() {
|
||||
let board = board();
|
||||
let filename =
|
||||
write_entry(&board, "uuid", Kind::Status, "committed → reviewing", "claude").unwrap();
|
||||
|
||||
assert!(filename.ends_with("_status.md"), "was {filename}");
|
||||
|
||||
let entries = read_history(&board, "uuid").unwrap();
|
||||
assert_eq!(entries.len(), 1);
|
||||
assert_eq!(entries[0].kind, Kind::Status);
|
||||
assert_eq!(entries[0].body, "committed → reviewing");
|
||||
assert_eq!(entries[0].author, "claude");
|
||||
}
|
||||
|
||||
/// The stamp leads the name and is fixed width, so the kind that follows it cannot
|
||||
/// reorder the log.
|
||||
#[test]
|
||||
fn the_kind_in_the_name_does_not_disturb_the_order() {
|
||||
let mut names = [
|
||||
"20260824_120000_000000_status",
|
||||
"20260824_115959_999999_tags",
|
||||
"20260824_120000_000001_comment",
|
||||
];
|
||||
names.sort();
|
||||
assert_eq!(
|
||||
names,
|
||||
[
|
||||
"20260824_115959_999999_tags",
|
||||
"20260824_120000_000000_status",
|
||||
"20260824_120000_000001_comment",
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/// A file written before the kinds existed: no marker, so it is the comment it was,
|
||||
/// and nothing rewrites it.
|
||||
#[test]
|
||||
fn an_entry_with_no_marker_is_a_comment() {
|
||||
let legacy = parse_entry(
|
||||
"20260820_143012_123456",
|
||||
"**Comment**\nSomething said\n\n**Author**: Ansho Rei\n**Time**: 2026-08-20 14:30:12\n",
|
||||
);
|
||||
assert_eq!(legacy.kind, Kind::Comment);
|
||||
assert_eq!(legacy.body, "Something said");
|
||||
assert_eq!(legacy.author, "Ansho Rei");
|
||||
|
||||
// And one with no marker at all, which is what `read_comments` read as empty.
|
||||
let bare = parse_entry("20260820_143012_123457", "notes\n");
|
||||
assert_eq!(bare.kind, Kind::Comment);
|
||||
assert_eq!(bare.body, "");
|
||||
}
|
||||
|
||||
/// The comment file is byte for byte what `comment` wrote before this module, which
|
||||
/// is what lets an old board be read without a migration.
|
||||
#[test]
|
||||
fn a_comment_file_is_shaped_as_it_always_was() {
|
||||
let content = entry_content(Kind::Comment, "A body", "claude", "2026-08-24 12:00:00");
|
||||
assert_eq!(
|
||||
content,
|
||||
"**Comment**\nA body\n\n**Author**: claude\n**Time**: 2026-08-24 12:00:00\n"
|
||||
);
|
||||
}
|
||||
|
||||
/// Same microsecond, three entries: the guard is `create_new`, and the suffix keeps
|
||||
/// them in the order they were written.
|
||||
#[test]
|
||||
fn entries_in_one_microsecond_get_names_of_their_own() {
|
||||
let board = board();
|
||||
let dir = history_dir(&board, "uuid");
|
||||
fs::create_dir_all(&dir).unwrap();
|
||||
|
||||
let first = write_new(&dir, "20260820_143012_123456_comment", "first").unwrap();
|
||||
let second = write_new(&dir, "20260820_143012_123456_comment", "second").unwrap();
|
||||
let third = write_new(&dir, "20260820_143012_123456_comment", "third").unwrap();
|
||||
|
||||
assert_eq!(first, "20260820_143012_123456_comment.md");
|
||||
assert_eq!(second, "20260820_143012_123456_comment_01.md");
|
||||
assert_eq!(third, "20260820_143012_123456_comment_02.md");
|
||||
|
||||
// Nothing was truncated on the way through
|
||||
assert_eq!(fs::read_to_string(dir.join(&first)).unwrap(), "first");
|
||||
assert_eq!(fs::read_to_string(dir.join(&second)).unwrap(), "second");
|
||||
assert_eq!(fs::read_to_string(dir.join(&third)).unwrap(), "third");
|
||||
|
||||
// read_history sorts on the stem, so the names must sort in write order
|
||||
assert!(first < second && second < third, "the names lost their order");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_old_comments_directory_is_adopted_on_access() {
|
||||
let board = board();
|
||||
let comments = board.join(COMMENTS_DIR).join("uuid");
|
||||
fs::create_dir_all(&comments).unwrap();
|
||||
fs::write(
|
||||
comments.join("20260820_143012_123456.md"),
|
||||
"**Comment**\nOld news\n\n**Author**: Ansho Rei\n**Time**: 2026-08-20 14:30:12\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let entries = read_history(&board, "uuid").unwrap();
|
||||
assert_eq!(entries.len(), 1);
|
||||
assert_eq!(entries[0].body, "Old news");
|
||||
|
||||
assert!(!board.join(COMMENTS_DIR).exists(), "the old directory survived");
|
||||
assert!(history_dir(&board, "uuid").exists(), "the entries did not arrive");
|
||||
}
|
||||
|
||||
/// Refused rather than merged: only the CLI writes there, so this is a board somebody
|
||||
/// has been in by hand, and picking a survivor per name is not a silent decision.
|
||||
#[test]
|
||||
fn a_board_holding_both_directories_is_refused() {
|
||||
let board = board();
|
||||
fs::create_dir_all(board.join(COMMENTS_DIR).join("uuid")).unwrap();
|
||||
fs::create_dir_all(history_dir(&board, "uuid")).unwrap();
|
||||
|
||||
let refused = read_history(&board, "uuid");
|
||||
let message = refused.unwrap_err().to_string();
|
||||
assert!(
|
||||
message.contains(COMMENTS_DIR) && message.contains(HISTORY_DIR),
|
||||
"{message}"
|
||||
);
|
||||
}
|
||||
|
||||
/// The count is the card's, and a card counts what somebody said.
|
||||
#[test]
|
||||
fn only_comments_are_counted() {
|
||||
let board = board();
|
||||
write_entry(&board, "uuid", Kind::Comment, "said", "claude").unwrap();
|
||||
write_entry(&board, "uuid", Kind::Status, "backlog → committed", "claude").unwrap();
|
||||
write_entry(&board, "uuid", Kind::Owner, "_Not set_ → alice", "claude").unwrap();
|
||||
write_entry(&board, "uuid", Kind::Tags, "bug → bug, cli", "claude").unwrap();
|
||||
|
||||
assert_eq!(read_history(&board, "uuid").unwrap().len(), 4);
|
||||
assert_eq!(count_comments(&board, "uuid"), 1);
|
||||
}
|
||||
|
||||
/// A stem written before the kinds existed counts as the comment it is.
|
||||
#[test]
|
||||
fn a_legacy_name_counts_as_a_comment() {
|
||||
assert_eq!(kind_from_stem("20260820_143012_123456"), Kind::Comment);
|
||||
assert_eq!(kind_from_stem("20260820_143012_123456_01"), Kind::Comment);
|
||||
assert_eq!(kind_from_stem("20260820_143012_123456_status"), Kind::Status);
|
||||
assert_eq!(kind_from_stem("20260820_143012_123456_status_01"), Kind::Status);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_mechanical_entry_renders_as_one_line_and_a_comment_as_it_did() {
|
||||
let entries = vec![
|
||||
parse_entry(
|
||||
"20260824_120000_000000_status",
|
||||
"**Status**\ncommitted → reviewing\n\n**Author**: claude\n**Time**: 2026-08-24 12:00:00\n",
|
||||
),
|
||||
parse_entry(
|
||||
"20260824_120001_000000_comment",
|
||||
"**Comment**\nThe offset was never passed\n\n**Author**: Ansho Rei\n**Time**: 2026-08-24 12:00:01\n",
|
||||
),
|
||||
];
|
||||
|
||||
let rendered = format_history_with(&entries, false);
|
||||
assert!(rendered.contains("HISTORY"), "{rendered}");
|
||||
assert!(
|
||||
rendered.contains("status committed → reviewing claude (2026-08-24 12:00:00)\n"),
|
||||
"{rendered}"
|
||||
);
|
||||
assert!(
|
||||
rendered
|
||||
.contains("From Ansho Rei (2026-08-24 12:00:01)\n The offset was never passed"),
|
||||
"{rendered}"
|
||||
);
|
||||
assert!(!rendered.contains('\x1b'), "colour off still painted: {rendered:?}");
|
||||
}
|
||||
|
||||
/// Padded to the longest of the three, so every body starts in the same column
|
||||
/// however short the label above it is.
|
||||
#[test]
|
||||
fn the_mechanical_labels_are_aligned() {
|
||||
let bodies = [
|
||||
("status", "backlog → committed"),
|
||||
("owner", "_Not set_ → alice"),
|
||||
("tags", "bug → bug, cli"),
|
||||
];
|
||||
let entries: Vec<Entry> = bodies
|
||||
.into_iter()
|
||||
.map(|(kind, body)| {
|
||||
let marker = format!("**{}{}**", kind[..1].to_uppercase(), &kind[1..]);
|
||||
parse_entry(
|
||||
&format!("20260824_120000_000000_{kind}"),
|
||||
&format!(
|
||||
"{marker}\n{body}\n\n**Author**: claude\n**Time**: 2026-08-24 12:00:00\n"
|
||||
),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
let rendered = format_history_with(&entries, false);
|
||||
let columns: Vec<usize> = bodies
|
||||
.into_iter()
|
||||
.map(|(_, body)| rendered.find(body).expect("body missing"))
|
||||
.map(|at| {
|
||||
let line_start = rendered[..at].rfind('\n').map_or(0, |nl| nl + 1);
|
||||
at - line_start
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(columns.len(), 3);
|
||||
assert!(columns.windows(2).all(|pair| pair[0] == pair[1]), "{rendered}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nothing_recorded_says_so() {
|
||||
assert_eq!(format_history_with(&[], false), "No history yet.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user