Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6178d7bd3d | ||
|
|
f740e42d1c | ||
|
|
220789efea | ||
|
|
c1137f29cf | ||
|
|
77bf2d9e2a |
@@ -176,12 +176,29 @@ worklane comment "My Ticket" "Needs changes to the UI"
|
||||
worklane comment a1b2c3d4 "LGTM, approved"
|
||||
```
|
||||
|
||||
## Workflow
|
||||
## Working a ticket
|
||||
|
||||
1. Use `worklane add` to create tickets with all relevant details
|
||||
2. Use `worklane ls [status]` to view tickets by status
|
||||
3. Use `worklane show <id>` to view full ticket details
|
||||
4. Use `worklane mv <id> --status <target>` to move tickets through the workflow
|
||||
5. Use `worklane set <ticket>` to correct a field, or `worklane append <ticket>` to add to a section
|
||||
6. Use `worklane check <ticket> <n>` to tick a criterion as it is met
|
||||
7. Use `worklane comment <ticket> <body>` to add notes to tickets
|
||||
Move the ticket as you work it, not afterwards. The board should say what is happening
|
||||
now, not only what already landed.
|
||||
|
||||
1. `worklane show <id>` to read it
|
||||
2. **`worklane mv <id> --status committed` before writing any code.** This is what marks
|
||||
the ticket as being worked on, so it belongs at the start
|
||||
3. Do the work. `worklane check <id> <n>` as each criterion is met
|
||||
4. `worklane comment <id> <body>` with anything worth recording: a decision, a rejected
|
||||
acceptance criterion, something the ticket got wrong
|
||||
5. **`worklane mv <id> --status reviewing` once it is done and the tests pass**
|
||||
|
||||
Only one stage forward is allowed at a time, so a ticket left in `backlog` until the end
|
||||
cannot go straight to `reviewing`. It has to be walked through `committed` anyway, which
|
||||
makes moving it up front the same two commands in a more useful order.
|
||||
|
||||
## Commands
|
||||
|
||||
- `worklane add` creates tickets with all relevant details
|
||||
- `worklane ls [status]` views tickets by status
|
||||
- `worklane show <id>` views full ticket details
|
||||
- `worklane mv <id> --status <target>` moves tickets through the workflow
|
||||
- `worklane set <ticket>` corrects a field, `worklane append <ticket>` adds to a section
|
||||
- `worklane check <ticket> <n>` ticks a criterion as it is met
|
||||
- `worklane comment <ticket> <body>` adds notes to tickets
|
||||
|
||||
@@ -6,12 +6,15 @@
|
||||
- `src/handlers.rs` - one `cmd_*` per subcommand
|
||||
- `src/util.rs` - the ticket format, resolution, rendering and the palette
|
||||
- `src/tui.rs` - board state, the change digest, and the ratatui draw
|
||||
- `src/install.rs` - the embedded agent assets and the compare-and-refuse install
|
||||
- `assets/SKILL.md` - the agent skill `install-skill` ships, embedded with `include_str!`
|
||||
- `tests/` - Integration tests using `assert_cmd` and `assert_fs`, one file per command
|
||||
- Unit tests live beside the code in `#[cfg(test)] mod tests`, in `util.rs`, `handlers.rs` and `tui.rs`
|
||||
- Ticket files stored as `.md` in `.worklane/<status>/` directories
|
||||
|
||||
## Ticket File Format
|
||||
- Filenames: `<uuid_v4>_<slug>.md`
|
||||
- The slug is the title through `slug()`: lowercased, alphanumerics plus `-` and `_` kept, spaces turned into dashes. `Ticket 06` lands as `<uuid>_ticket-06.md`. Derive fixture filenames through `slug()`, never by hand
|
||||
- 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`
|
||||
@@ -20,6 +23,12 @@
|
||||
## Status Workflow
|
||||
`backlog` → `committed` → `reviewing` → `done`
|
||||
|
||||
**How to use worklane is in `assets/SKILL.md`, not here.** That document is what
|
||||
`worklane install-skill` ships, so it is the one place the flow, the move-as-you-work
|
||||
rule and the argument traps are written down. Read it before working a ticket in this
|
||||
repo. Do not restate any of it in this file: a second copy is a copy that goes stale,
|
||||
and this file is for what someone changing worklane's own code needs.
|
||||
|
||||
## Testing
|
||||
- Run: `cargo test`
|
||||
- Tests use `assert_cmd` and `assert_fs` for CLI testing
|
||||
@@ -74,9 +83,28 @@
|
||||
- The digest guards the *rescan*, not the draw. ratatui diffs its buffer, so drawing every iteration is free; reading the tree every iteration is not
|
||||
- `notify` is deliberately not a dependency. Polling a tree of tens of small files on the 250ms tick is enough, and the reason is recorded on f6af387
|
||||
- Cards come from `collect_ticket_items`, the same source `ls` uses, so there is no second parser. `TicketItem::path` exists for the detail view
|
||||
- **The detail view scrolls on `pgup` and `pgdn`, not on up and down.** Up and down stay on the selection with the modal open, so a whole column can be read without closing it, and the modal follows. That is worth more than the two keys, which is why the scroll went elsewhere rather than taking them
|
||||
- The scroll offset is clamped against the *wrapped* line count, from `Paragraph::line_count`, which is why `ratatui` carries the `unstable-rendered-line-info` feature. The paragraph wraps on words, so a clamp on the raw lines would stop short of the end or scroll past it into blank space. Counting the wrapping by hand would only agree with the widget until one of the two changed
|
||||
- The clamp runs on the keypress and again in the draw. The terminal can be resized between the two, and a tick can shorten the ticket under a reader who is already at the end
|
||||
- The offset resets when the selection moves and when the modal is closed, so a ticket opens at its top. It deliberately does *not* reset on a tick: an edit elsewhere in the tree must not throw the reader back to the top of what they are reading
|
||||
- **Columns scroll to keep the selected card in view.** `Board::offsets` holds one offset per column, parallel to `columns` and resized in step by `reload`, so a column you leave stays where it was. The keypress aligns the focused column via `follow_selection(screen)`, taking the screen size for the same reason `scroll_detail` does: the visible height belongs to the terminal, which only the caller measures between draws
|
||||
- Card heights are measured on `card_lines`, never assumed, on both the keypress and the draw side (`card_height`, and the `starts` vec as the cards are built). An alignment that trusted a fixed card height would drift from the renderer the first time the card changed shape
|
||||
- The draw aligns the focused column again on its own geometry, so a resize between keypress and frame cannot hide the selection, and caps every column against blank space past its last card. The stored value may go stale after a tick shrinks the column; that is fine, because what is drawn is corrected immediately and the next navigation writes the correction back
|
||||
- Entering another column follows the selection rather than resetting to its top. The card index carries across columns, so a reset would open the column with the highlight below the fold whenever it was — the opposite of the detail view's reset-on-selection-move, where each ticket genuinely starts at its own top. The index is shared and clamps permanently when a shorter column pulls it down, so a column you return to follows the selection to where it now sits rather than holding your old place
|
||||
- **The footer names only keys that work.** It read `↑↓ scroll` when nothing scrolled at all, which sends the reader looking for their own mistake. A UI that misdescribes itself is worse than one that is merely incomplete
|
||||
- The detail view renders with colour off. ratatui draws styled spans, so an escape sequence in a paragraph would be printed as literal bytes. `content_trim` and `format_comments_with` take the colour decision for that reason
|
||||
- Read only. Moving a card by keypress is a follow-up, deliberately kept out until the watch and render loop were solid
|
||||
|
||||
### Shipping the Agent Assets
|
||||
- The skill is embedded with `include_str!` from `assets/SKILL.md`, not copied by an install script. `cargo install` places binaries and nothing else, so an installed document that is not in the binary is a document that drifts from it
|
||||
- **One install path serves both agents:** `~/.claude/skills/worklane/SKILL.md`. Claude Code reads it, and opencode loads that directory as an external skill source alongside its own `~/.config/opencode/skill/`. Verified against opencode 1.15.10, whose built-in `customize-opencode` skill documents the table and whose `opencode debug skill` lists what it found there. Do not add the second path: it is two copies of one document, free to drift, for no gain
|
||||
- `Asset` carries the content, the path under its root and the word used in messages, so `install-tool` adds an entry and its own root rather than a second copy of the compare-and-refuse logic. That is why the module is `install.rs` and not `skill.rs`
|
||||
- `install()` takes the root as an argument. That is what lets the tests install into a temp directory instead of the home of whoever runs the suite, and the integration test redirects `HOME` for the same reason
|
||||
- **A modified copy is refused, not overwritten.** Someone may have edited it on purpose, and the message names `--print` so it can be diffed and `--force` so it can be replaced. A read error is not treated as absent either: the write reports the real reason
|
||||
- Three tests guard the document rather than the mechanism, and they are the ones that earn their keep: the frontmatter has to parse (both agents silently ignore a document without it), every `worklane <x>` the skill shows has to be a real subcommand, and every subcommand outside `NOT_FOR_AGENTS` has to appear in the skill. The last one catches a new command that nothing tells an agent about
|
||||
- `install-skill` looks for no board. The skill is what teaches an agent worklane, so needing a `.worklane` to install it would put it out of reach exactly when it is wanted
|
||||
- The assets under `.opencode/` are the user's, not this repo's to ship. Do not embed or install them
|
||||
|
||||
### Color and Output
|
||||
- Use `color_text()` for coloured output — it respects `should_use_colors()` (terminal detection), and `paint()` is the same with the decision passed in
|
||||
- **The palette is the `Color` enum, not a string.** `Color::ansi()` gives the CLI its SGR sequence and `From<Color> for ratatui::style::Color` gives the TUI its equivalent, so a colour that exists for one renderer and not the other is a compile error. The stringly-typed version needed a test for exactly that, and a missing entry silently produced an empty prefix, which is how `magenta` came to be undefined
|
||||
|
||||
Generated
+1
-1
@@ -1494,7 +1494,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "worklane"
|
||||
version = "0.7.0"
|
||||
version = "0.8.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"assert_cmd",
|
||||
|
||||
+5
-2
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "worklane"
|
||||
version = "0.7.0"
|
||||
version = "0.8.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
@@ -9,7 +9,10 @@ anyhow = "1"
|
||||
uuid = { version = "1", features = ["v4"] }
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
libc = "0.2"
|
||||
ratatui = "0.29"
|
||||
# unstable-rendered-line-info for Paragraph::line_count, which is how the detail view
|
||||
# knows where its text ends. Counting the wrapping by hand would only agree with the
|
||||
# widget until one of us changed.
|
||||
ratatui = { version = "0.29", features = ["unstable-rendered-line-info"] }
|
||||
crossterm = "0.28"
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -5,7 +5,7 @@ Worklane is a local Kanban flow for agentic software development.
|
||||
## Commands
|
||||
| Command | Description |
|
||||
|---------|-------------|
|
||||
| `worklane` or `worklane tui` | Opens the board: four status columns, redrawn when the tree changes. Read only. Arrows or `hjkl` to move, `enter` for detail, `q` to quit |
|
||||
| `worklane` or `worklane tui` | Opens the board: four status columns, redrawn when the tree changes. Read only. Arrows or `hjkl` to move, `enter` for detail, `pgup`/`pgdn` to scroll an open ticket, `q` to quit |
|
||||
| `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 ls [status]` | Lists tickets, sorted by priority then title. Optional positional status, and `--priority <1-5>` |
|
||||
@@ -16,6 +16,7 @@ Worklane is a local Kanban flow for agentic software development.
|
||||
| `worklane check <ticket> [criterion]` | Ticks one acceptance criterion, by number as shown by `show` or by a substring. Prompts with the numbered list if omitted, or errors with it when there is no terminal |
|
||||
| `worklane uncheck <ticket> [criterion]` | Unticks one acceptance criterion, addressed the same way |
|
||||
| `worklane comment <ticket> <body>` | Adds a comment to a ticket by UUID or title |
|
||||
| `worklane install-skill` | Writes the embedded agent skill to `~/.claude/skills/worklane/SKILL.md`, which Claude Code and opencode both read. Leaves a modified copy alone unless `--force`; `--print` writes it to stdout instead |
|
||||
|
||||
## Exit codes
|
||||
| Code | Meaning |
|
||||
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
---
|
||||
name: worklane
|
||||
description: Manage tickets on a local worklane kanban board with the `worklane` CLI, backed by markdown files in a `.worklane/` directory. Use whenever you need to file, find, read, update, comment on or move a ticket, when asked what is on the board or what to pick up next, and when reporting work you are not going to do in the change at hand. Covers the four statuses, how a ticket is addressed, what belongs in each section, and the argument traps that silently swallow a flag.
|
||||
---
|
||||
|
||||
# worklane
|
||||
|
||||
A kanban board as files. Every ticket is one markdown file in `.worklane/<status>/`,
|
||||
named `<uuid>_<slug>.md`, and comments live in `.worklane/comments/<uuid>/`. The CLI is
|
||||
the only thing that writes there: do not hand-edit or hand-place a file, because the
|
||||
filename, the `Status` field and the directory have to agree and the commands are what
|
||||
keep them agreeing.
|
||||
|
||||
Commands walk up from the working directory to find the nearest `.worklane`, so **run
|
||||
`worklane` inside the repo the ticket belongs to**. Which directory you run it in is
|
||||
what decides which board the ticket lands on.
|
||||
|
||||
`worklane` with no subcommand opens an interactive board and needs a terminal. It is for
|
||||
a person, not for you: it takes over the screen and does not return until quit.
|
||||
|
||||
## The flow
|
||||
|
||||
`backlog` → `committed` → `reviewing` → `done`
|
||||
|
||||
**Move the ticket as you work it, not afterwards.** `worklane mv <id> --status committed`
|
||||
before writing any code, and `--status reviewing` once it is done and the tests pass. The
|
||||
board is then true while the work is in progress, not only after it lands, which is the
|
||||
whole point of having a `committed` column.
|
||||
|
||||
Only one stage at a time is allowed, so a ticket left in `backlog` until the end cannot
|
||||
go straight to `reviewing` and has to be walked through `committed` anyway. Doing it up
|
||||
front is the same two commands in a more useful order. `-f` allows a backward or
|
||||
skipping move, for correcting a mistake.
|
||||
|
||||
## Reading the board
|
||||
|
||||
```
|
||||
worklane ls # every status, counts then tickets
|
||||
worklane ls backlog # one status
|
||||
worklane ls --priority 1 # only the most urgent
|
||||
worklane show 1b78a24 # one ticket, body and comments
|
||||
```
|
||||
|
||||
`ls` prints a seven-character id per ticket. That is what you address it by.
|
||||
|
||||
## Working a ticket
|
||||
|
||||
```
|
||||
worklane mv 1b78a24 --status committed
|
||||
worklane check 1b78a24 3 # tick acceptance criterion 3
|
||||
worklane check 1b78a24 "the footer describes" # or a substring of it
|
||||
worklane uncheck 1b78a24 3
|
||||
worklane comment 1b78a24 "Found the cause: the offset was never passed to the widget."
|
||||
worklane mv 1b78a24 --status reviewing
|
||||
```
|
||||
|
||||
Criteria are numbered by `show`. With the criterion omitted, `check` prompts when there
|
||||
is a terminal and otherwise fails with the numbered list, so **always pass the criterion
|
||||
when you are not sitting at a prompt**.
|
||||
|
||||
## Filing a ticket
|
||||
|
||||
```
|
||||
worklane add \
|
||||
--title "The tui detail view cannot scroll" \
|
||||
--description "Opening a ticket and pressing down moves to the next one instead." \
|
||||
--description "" \
|
||||
--description "Up and down are bound to select_card unconditionally, src/main.rs." \
|
||||
--acceptance "PageUp and PageDown scroll the detail view" \
|
||||
--acceptance "The footer describes the keys that exist" \
|
||||
--plan "Add a scroll offset to Board and pass it to Paragraph::scroll" \
|
||||
--plan "Clamp against the wrapped line count, not the raw line count" \
|
||||
--priority 2 --tags bug,tui
|
||||
```
|
||||
|
||||
`add` always lands in `backlog`. Nothing is created without `--title`.
|
||||
|
||||
- **`--description`** is the case for the ticket: the symptom, then what is actually
|
||||
wrong, naming the files, functions and settings involved. Repeat the flag for more
|
||||
lines; an empty `--description ""` between two values is a paragraph break.
|
||||
- **`--acceptance`** takes one criterion per flag, each a statement that can be
|
||||
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.
|
||||
|
||||
Editing afterwards, on a ticket in any status:
|
||||
|
||||
```
|
||||
worklane set 1b78a24 --priority 1 # replace a field
|
||||
worklane set 1b78a24 --title "A better title" # renames the file, keeps the uuid
|
||||
worklane append 1b78a24 --acceptance "One more criterion"
|
||||
worklane append 1b78a24 --description "What was learned since."
|
||||
```
|
||||
|
||||
`set` replaces, `append` adds. Neither has `--owner` or `--status`: owner is its own
|
||||
command's, and status is `mv`'s. A field set to the value it already holds is reported
|
||||
unchanged and nothing is written.
|
||||
|
||||
`worklane init` creates `.worklane/` with the four status directories, for a repo that
|
||||
has no board yet.
|
||||
|
||||
## Search the backlog before filing
|
||||
|
||||
Run `worklane ls` in the directory the ticket would land in and look for the same issue,
|
||||
including tickets already committed, in review or done. Search by the symptom and by the
|
||||
name of the function or setting involved, not only by your own phrasing of the title: an
|
||||
existing ticket will have been written from a different angle.
|
||||
|
||||
- Already there and still open: add what you learned as a comment, not a second ticket.
|
||||
- Already there and closed, but the issue is back: file a **new** ticket naming the old
|
||||
id, and say it is a regression. There is no way to reopen one, and moving a done
|
||||
ticket back would destroy the record of the original fix.
|
||||
- Related but not the same: file it and reference the neighbour by id.
|
||||
|
||||
## Addressing a ticket
|
||||
|
||||
Every command that takes a ticket accepts, in this order of precedence:
|
||||
|
||||
1. a UUID prefix, from four characters up
|
||||
2. a substring of the title
|
||||
3. a substring of the filename
|
||||
|
||||
The first tier that matches anything wins outright; the later tiers are not consulted.
|
||||
This matters because ticket titles quote other tickets' ids, and a flat search reported
|
||||
an exact id as ambiguous against whichever title mentioned it. An ambiguous match prints
|
||||
the candidates and exits 1 rather than guessing.
|
||||
|
||||
## Traps
|
||||
|
||||
- **Prose arguments accept a leading hyphen**: `--title`, `--description`,
|
||||
`--acceptance`, `--plan` and the `comment` body. A criterion reading
|
||||
`--print is supported` is stored, not parsed as a flag. The cost is that a genuinely
|
||||
mistyped flag there lands as content instead of failing, so read back what you wrote
|
||||
with `worklane show`.
|
||||
- `--due`, `--priority`, `--tags`, `--owner` and `--status` do *not* accept one, so a
|
||||
mistyped flag on those is a usage error and nothing is written.
|
||||
- A ticket argument that starts with a hyphen needs the flags first and a separator:
|
||||
`worklane mv --status committed -- -leading-title`.
|
||||
- A comment body of exactly `--` needs its own separator:
|
||||
`worklane comment 1b78a24 -- --`.
|
||||
- An empty value for a scalar is a usage error. Clearing a field back to unset is not
|
||||
supported yet.
|
||||
- Piping is safe: `worklane ls | head -3` exits on the closed pipe instead of panicking.
|
||||
@@ -163,6 +163,17 @@ pub enum Command {
|
||||
#[arg(short, long)]
|
||||
owner: Option<String>,
|
||||
},
|
||||
|
||||
/// Install the agent skill that teaches an agent to use worklane
|
||||
InstallSkill {
|
||||
/// Overwrite an existing copy that has been modified
|
||||
#[arg(long)]
|
||||
force: bool,
|
||||
|
||||
/// Write it to stdout instead of installing it
|
||||
#[arg(long)]
|
||||
print: bool,
|
||||
},
|
||||
}
|
||||
|
||||
/// `set` replaces a field outright. Owner is deliberately absent: `chown` owns that
|
||||
|
||||
@@ -5,6 +5,7 @@ use std::io::{BufRead, IsTerminal, Write};
|
||||
use std::path::Path;
|
||||
|
||||
use crate::command::{AppendArgs, CheckArgs, SetArgs};
|
||||
use crate::install;
|
||||
use crate::util::*;
|
||||
|
||||
pub fn cmd_init(start: &Path) -> Result<()> {
|
||||
@@ -868,3 +869,33 @@ pub fn cmd_check(args: &CheckArgs, checked: bool, start: &Path) -> Result<()> {
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Install the agent skill, or print it so a modified copy can be diffed.
|
||||
///
|
||||
/// No board is looked for. The document is what teaches an agent worklane, so needing
|
||||
/// a `.worklane` to install it would put it out of reach exactly when it is wanted.
|
||||
pub fn cmd_install_skill(force: bool, print: bool) -> Result<()> {
|
||||
if print {
|
||||
print!("{}", install::SKILL.content);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let root = install::skills_root()?;
|
||||
match install::SKILL.install(&root, force)? {
|
||||
install::Outcome::Written(path) => {
|
||||
println!("Installed the worklane {} to: {}", install::SKILL.what, path.display());
|
||||
println!("Claude Code and opencode pick it up on their next session");
|
||||
}
|
||||
install::Outcome::Unchanged(path) => {
|
||||
println!("Already up to date: {}", path.display());
|
||||
}
|
||||
install::Outcome::Refused(path) => {
|
||||
println!("Differs from the version in this binary: {}", path.display());
|
||||
println!(
|
||||
"Compare with `worklane install-skill --print`, or overwrite with --force"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
+282
@@ -0,0 +1,282 @@
|
||||
//! Shipping the agent assets with the binary.
|
||||
//!
|
||||
//! The skill document lives at `assets/SKILL.md` in this repo and is embedded with
|
||||
//! `include_str!` rather than copied by an install script, because `cargo install`
|
||||
//! places binaries and nothing else. Embedding means the document can never be a
|
||||
//! different version from the binary it describes, and there is no second file to
|
||||
//! lose track of.
|
||||
//!
|
||||
//! The machinery is written once for both assets this repo will ship. The tool file
|
||||
//! for opencode is executable code needing Bun, so it gets its own command and its
|
||||
//! own root, but the compare-and-refuse logic is the same and lives here.
|
||||
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use anyhow::{Result, anyhow};
|
||||
|
||||
/// One thing the binary carries and can write into a user's agent configuration.
|
||||
pub struct Asset {
|
||||
/// What it is called in messages, e.g. `skill`.
|
||||
pub what: &'static str,
|
||||
/// Where it goes under its root, e.g. `worklane/SKILL.md`.
|
||||
pub relative: &'static str,
|
||||
pub content: &'static str,
|
||||
}
|
||||
|
||||
/// The skill document, as of the commit this binary was built from.
|
||||
pub const SKILL: Asset = Asset {
|
||||
what: "skill",
|
||||
relative: "worklane/SKILL.md",
|
||||
content: include_str!("../assets/SKILL.md"),
|
||||
};
|
||||
|
||||
/// Where a skill has to sit to be found, for both agents worklane is used from.
|
||||
///
|
||||
/// One path serves both. Claude Code reads `~/.claude/skills/<name>/SKILL.md`, and
|
||||
/// opencode loads that same directory as an external skill source, alongside its own
|
||||
/// `~/.config/opencode/skill/`. Checked against opencode 1.15.10, whose built-in
|
||||
/// `customize-opencode` skill documents it and whose `opencode debug skill` lists the
|
||||
/// documents found there. Writing both paths would be two copies of one document, free
|
||||
/// to drift apart, for no gain.
|
||||
pub fn skills_root() -> Result<PathBuf> {
|
||||
let home = std::env::var_os("HOME").ok_or_else(|| {
|
||||
anyhow!("cannot tell where your skills live because HOME is not set in the environment")
|
||||
})?;
|
||||
|
||||
Ok(Path::new(&home).join(".claude/skills"))
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum Outcome {
|
||||
Written(PathBuf),
|
||||
/// Already byte-identical, so writing it again would be a no-op.
|
||||
Unchanged(PathBuf),
|
||||
/// Present but different, and no `--force`. Refused rather than overwritten: it
|
||||
/// may have been edited on purpose, and silently discarding that is worse than
|
||||
/// stopping.
|
||||
Refused(PathBuf),
|
||||
}
|
||||
|
||||
impl Asset {
|
||||
pub fn path(&self, root: &Path) -> PathBuf {
|
||||
root.join(self.relative)
|
||||
}
|
||||
|
||||
/// Write the asset under `root`, unless what is there is the same or was changed.
|
||||
///
|
||||
/// The root is passed in rather than looked up, so a test can install into a
|
||||
/// temporary directory instead of the home of whoever runs the suite.
|
||||
pub fn install(&self, root: &Path, force: bool) -> io::Result<Outcome> {
|
||||
let path = self.path(root);
|
||||
|
||||
// A read error is not treated as "absent": the write below reports it, with
|
||||
// the real reason, rather than this guessing that the file is missing.
|
||||
match std::fs::read_to_string(&path) {
|
||||
Ok(existing) if existing == self.content => return Ok(Outcome::Unchanged(path)),
|
||||
Ok(_) if !force => return Ok(Outcome::Refused(path)),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
if let Some(parent) = path.parent() {
|
||||
std::fs::create_dir_all(parent)?;
|
||||
}
|
||||
std::fs::write(&path, self.content)?;
|
||||
|
||||
Ok(Outcome::Written(path))
|
||||
}
|
||||
}
|
||||
|
||||
/// The `name:` and `description:` from the YAML frontmatter.
|
||||
///
|
||||
/// Used by the tests that guard the shipping mechanism, which is the only thing that
|
||||
/// needs it: both agents decide whether to load a document from these two fields, and
|
||||
/// a document missing them is ignored in silence.
|
||||
#[cfg_attr(not(test), allow(dead_code))]
|
||||
fn frontmatter_field(text: &str, key: &str) -> Option<String> {
|
||||
let body = text.strip_prefix("---\n")?;
|
||||
let end = body.find("\n---")?;
|
||||
body[..end]
|
||||
.lines()
|
||||
.find_map(|line| line.strip_prefix(&format!("{key}:")))
|
||||
.map(|value| value.trim().to_string())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn root() -> tempfile::TempDir {
|
||||
tempfile::tempdir().unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_skill_installs_into_a_directory_that_does_not_exist_yet() {
|
||||
let root = root();
|
||||
let path = SKILL.path(root.path());
|
||||
|
||||
assert_eq!(
|
||||
SKILL.install(root.path(), false).unwrap(),
|
||||
Outcome::Written(path.clone())
|
||||
);
|
||||
assert_eq!(std::fs::read_to_string(&path).unwrap(), SKILL.content);
|
||||
}
|
||||
|
||||
/// Installing twice is a no-op rather than a rewrite, so the mtime of an
|
||||
/// up-to-date copy does not move.
|
||||
#[test]
|
||||
fn a_second_install_reports_the_copy_unchanged() {
|
||||
let root = root();
|
||||
SKILL.install(root.path(), false).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
SKILL.install(root.path(), false).unwrap(),
|
||||
Outcome::Unchanged(SKILL.path(root.path()))
|
||||
);
|
||||
}
|
||||
|
||||
/// The case worth being careful about: an edited copy is someone's work.
|
||||
#[test]
|
||||
fn a_modified_copy_is_refused_and_left_alone() {
|
||||
let root = root();
|
||||
let path = SKILL.path(root.path());
|
||||
SKILL.install(root.path(), false).unwrap();
|
||||
std::fs::write(&path, "hand written\n").unwrap();
|
||||
|
||||
assert_eq!(
|
||||
SKILL.install(root.path(), false).unwrap(),
|
||||
Outcome::Refused(path.clone())
|
||||
);
|
||||
assert_eq!(std::fs::read_to_string(&path).unwrap(), "hand written\n");
|
||||
|
||||
assert_eq!(
|
||||
SKILL.install(root.path(), true).unwrap(),
|
||||
Outcome::Written(path.clone())
|
||||
);
|
||||
assert_eq!(std::fs::read_to_string(&path).unwrap(), SKILL.content);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_skill_lands_where_both_agents_look_for_it() {
|
||||
let root = skills_root().unwrap();
|
||||
assert!(root.ends_with(".claude/skills"), "{}", root.display());
|
||||
assert!(
|
||||
SKILL.path(&root).ends_with(".claude/skills/worklane/SKILL.md"),
|
||||
"{}",
|
||||
SKILL.path(&root).display()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_embedded_skill_has_usable_frontmatter() {
|
||||
// Guards the whole shipping mechanism: without frontmatter, or under a name
|
||||
// that does not match its directory, both agents ignore the document and
|
||||
// nothing else would notice.
|
||||
assert_eq!(frontmatter_field(SKILL.content, "name").as_deref(), Some("worklane"));
|
||||
|
||||
let description =
|
||||
frontmatter_field(SKILL.content, "description").expect("a description to trigger on");
|
||||
assert!(
|
||||
description.len() > 80,
|
||||
"the description is what decides whether the skill loads at all"
|
||||
);
|
||||
}
|
||||
|
||||
/// Every code span and fenced-block line, which is where commands live.
|
||||
///
|
||||
/// Prose has to be excluded: the document opens by calling worklane a kanban
|
||||
/// board, and treating that sentence as a command makes the check useless.
|
||||
fn code_snippets(text: &str) -> Vec<String> {
|
||||
let mut snippets = Vec::new();
|
||||
let mut fenced = false;
|
||||
for line in text.lines() {
|
||||
if line.trim_start().starts_with("```") {
|
||||
fenced = !fenced;
|
||||
continue;
|
||||
}
|
||||
if fenced {
|
||||
snippets.push(line.to_string());
|
||||
continue;
|
||||
}
|
||||
// Inline spans: the odd-numbered pieces between backticks.
|
||||
for (index, piece) in line.split('`').enumerate() {
|
||||
if index % 2 == 1 {
|
||||
snippets.push(piece.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
snippets
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_embedded_skill_only_names_commands_that_exist() {
|
||||
// Taken from clap rather than written out here. A hand-maintained list is the
|
||||
// very drift this test exists to catch.
|
||||
use clap::CommandFactory;
|
||||
let mut known: Vec<String> = crate::Cli::command()
|
||||
.get_subcommands()
|
||||
.map(|c| c.get_name().to_string())
|
||||
.collect();
|
||||
known.push("--help".to_string());
|
||||
known.push("--version".to_string());
|
||||
|
||||
let mut checked = 0;
|
||||
for snippet in code_snippets(SKILL.content) {
|
||||
let mut words = snippet.split_whitespace();
|
||||
// Only a snippet that *starts* with worklane is a command being shown.
|
||||
if words.next() != Some("worklane") {
|
||||
continue;
|
||||
}
|
||||
let Some(candidate) = words.next() else { continue };
|
||||
// A flag before the subcommand, as in the `mv -- -leading-title` example.
|
||||
if candidate.starts_with("--") && !known.iter().any(|k| k == candidate) {
|
||||
continue;
|
||||
}
|
||||
checked += 1;
|
||||
assert!(
|
||||
known.iter().any(|k| k == candidate),
|
||||
"the skill shows `worklane {candidate}`, which is not a subcommand"
|
||||
);
|
||||
}
|
||||
assert!(checked > 8, "expected the skill to show commands, checked only {checked}");
|
||||
}
|
||||
|
||||
/// Subcommands the skill has no business teaching: the board is interactive and
|
||||
/// belongs to a person, `install-skill` is how the document arrived, and `help`
|
||||
/// is clap's own.
|
||||
const NOT_FOR_AGENTS: [&str; 3] = ["tui", "install-skill", "help"];
|
||||
|
||||
/// The converse, and the one that goes stale on its own: a *new* subcommand absent
|
||||
/// from the skill is invisible to an agent, and nothing else would notice.
|
||||
#[test]
|
||||
fn every_agent_facing_subcommand_is_documented() {
|
||||
use clap::CommandFactory;
|
||||
for command in crate::Cli::command().get_subcommands() {
|
||||
let name = command.get_name();
|
||||
if NOT_FOR_AGENTS.contains(&name) {
|
||||
continue;
|
||||
}
|
||||
assert!(
|
||||
SKILL.content.contains(&format!("worklane {name}")),
|
||||
"the skill never mentions `worklane {name}`, so an agent will not know it exists"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The facts an agent cannot infer from the help output and would get wrong.
|
||||
#[test]
|
||||
fn the_embedded_skill_documents_what_the_help_does_not() {
|
||||
for required in [
|
||||
"committed",
|
||||
"as you work it",
|
||||
"UUID prefix",
|
||||
"leading hyphen",
|
||||
"Search the backlog before filing",
|
||||
] {
|
||||
assert!(
|
||||
SKILL.content.contains(required),
|
||||
"the skill no longer mentions {required:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
-4
@@ -3,6 +3,7 @@ use clap::Parser;
|
||||
|
||||
mod command;
|
||||
mod handlers;
|
||||
mod install;
|
||||
mod tui;
|
||||
mod util;
|
||||
|
||||
@@ -82,6 +83,9 @@ fn main() -> Result<()> {
|
||||
body,
|
||||
owner,
|
||||
}) => cmd_comment(&ticket, &body, &owner, &start),
|
||||
// No board is looked for: the point of the skill is to teach an agent worklane
|
||||
// before there is a `.worklane` anywhere.
|
||||
Some(Command::InstallSkill { force, print }) => cmd_install_skill(force, print),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,6 +145,9 @@ fn run_tui(start: &std::path::Path) -> Result<()> {
|
||||
board.tick()?;
|
||||
terminal.draw(|frame| tui::draw(frame, &board))?;
|
||||
|
||||
// Taken after the draw, so a scroll measures the overlay that is on screen.
|
||||
let screen = terminal.size()?;
|
||||
|
||||
// Bounded, so the tick still runs when nobody is typing.
|
||||
if !event::poll(tui::POLL)? {
|
||||
continue;
|
||||
@@ -164,10 +171,15 @@ fn run_tui(start: &std::path::Path) -> Result<()> {
|
||||
None => board.should_quit = true,
|
||||
},
|
||||
KeyCode::Enter | KeyCode::Char(' ') => board.toggle_detail(),
|
||||
KeyCode::Left | KeyCode::Char('h') => board.select_column(-1),
|
||||
KeyCode::Right | KeyCode::Char('l') => board.select_column(1),
|
||||
KeyCode::Up | KeyCode::Char('k') => board.select_card(-1),
|
||||
KeyCode::Down | KeyCode::Char('j') => board.select_card(1),
|
||||
KeyCode::Left | KeyCode::Char('h') => board.select_column(-1, screen),
|
||||
KeyCode::Right | KeyCode::Char('l') => board.select_column(1, screen),
|
||||
// Up and down stay on the selection, open detail view or not, so a
|
||||
// column can be read through without closing the modal. Scrolling the
|
||||
// open ticket is a page at a time.
|
||||
KeyCode::Up | KeyCode::Char('k') => board.select_card(-1, screen),
|
||||
KeyCode::Down | KeyCode::Char('j') => board.select_card(1, screen),
|
||||
KeyCode::PageUp => board.scroll_detail(-1, screen),
|
||||
KeyCode::PageDown => board.scroll_detail(1, screen),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
+594
-19
@@ -12,7 +12,7 @@ use std::path::{Path, PathBuf};
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use anyhow::Result;
|
||||
use ratatui::layout::{Constraint, Direction, Layout, Rect};
|
||||
use ratatui::layout::{Constraint, Direction, Layout, Margin, Rect, Size};
|
||||
use ratatui::style::{Modifier, Style};
|
||||
use ratatui::text::{Line, Span};
|
||||
use ratatui::widgets::{Block, Borders, Clear, Paragraph, Wrap};
|
||||
@@ -35,8 +35,13 @@ pub struct Board {
|
||||
pub columns: Vec<Column>,
|
||||
pub column: usize,
|
||||
pub card: usize,
|
||||
/// First visible line of each column, counted in card lines. Parallel to
|
||||
/// `columns`, so a tick that reshapes the board resizes it in step.
|
||||
pub offsets: Vec<u16>,
|
||||
/// The body and comments of the selected ticket, when the detail view is open.
|
||||
pub detail: Option<String>,
|
||||
/// First visible line of the detail view, counted in wrapped lines.
|
||||
pub offset: u16,
|
||||
pub should_quit: bool,
|
||||
worklane_dir: PathBuf,
|
||||
digest: u64,
|
||||
@@ -48,7 +53,9 @@ impl Board {
|
||||
columns: Vec::new(),
|
||||
column: 0,
|
||||
card: 0,
|
||||
offsets: Vec::new(),
|
||||
detail: None,
|
||||
offset: 0,
|
||||
should_quit: false,
|
||||
worklane_dir: worklane_dir.to_path_buf(),
|
||||
digest: 0,
|
||||
@@ -83,10 +90,18 @@ impl Board {
|
||||
})
|
||||
.collect();
|
||||
|
||||
// One scroll position per column, kept by index. A tick that adds or removes
|
||||
// columns is not a thing statuses do, but the resize keeps the two in step
|
||||
// regardless; `resize` both pads and truncates.
|
||||
self.offsets.resize(self.columns.len(), 0);
|
||||
|
||||
self.digest = digest(&self.worklane_dir);
|
||||
self.clamp();
|
||||
|
||||
// The selected ticket may have moved or gone, so the open detail follows it.
|
||||
// The scroll offset stays where the reader put it: an edit elsewhere in the tree
|
||||
// should not throw them back to the top of what they are reading. A ticket that
|
||||
// got shorter is caught by the clamp in the draw.
|
||||
if self.detail.is_some() {
|
||||
self.detail = self.selected().map(detail_of);
|
||||
}
|
||||
@@ -117,7 +132,7 @@ impl Board {
|
||||
}
|
||||
|
||||
/// Move between columns, keeping the card index where it can land.
|
||||
pub fn select_column(&mut self, delta: isize) {
|
||||
pub fn select_column(&mut self, delta: isize, screen: Size) {
|
||||
if self.columns.is_empty() {
|
||||
return;
|
||||
}
|
||||
@@ -126,10 +141,15 @@ impl Board {
|
||||
let next = (self.column as isize + delta).clamp(0, last);
|
||||
self.column = next as usize;
|
||||
self.clamp();
|
||||
// Entering a column shows the card the selection landed on rather than
|
||||
// resetting to its top: the card index carries across columns, so a reset
|
||||
// would open the column with the highlight below the fold whenever it was.
|
||||
// The rest of the place the column was left in is kept.
|
||||
self.follow_selection(screen);
|
||||
self.refresh_detail();
|
||||
}
|
||||
|
||||
pub fn select_card(&mut self, delta: isize) {
|
||||
pub fn select_card(&mut self, delta: isize, screen: Size) {
|
||||
let count = match self.columns.get(self.column) {
|
||||
Some(column) => column.tickets.len(),
|
||||
None => return,
|
||||
@@ -140,18 +160,76 @@ impl Board {
|
||||
|
||||
let next = (self.card as isize + delta).clamp(0, count as isize - 1);
|
||||
self.card = next as usize;
|
||||
self.follow_selection(screen);
|
||||
self.refresh_detail();
|
||||
}
|
||||
|
||||
/// Move the focused column's offset so the selected card sits inside the view.
|
||||
///
|
||||
/// Measured on the same card lines the draw renders, so the two cannot disagree
|
||||
/// about how tall a card is. The screen comes in because the visible height
|
||||
/// belongs to the terminal, which only the caller measures between draws — the
|
||||
/// same reason `scroll_detail` takes it. The draw aligns the focused column again
|
||||
/// on its own geometry, so a resize between this and the next frame is corrected
|
||||
/// there; what is stored here is the place an unfocused column keeps.
|
||||
fn follow_selection(&mut self, screen: Size) {
|
||||
let Some(column) = self.columns.get(self.column) else {
|
||||
return;
|
||||
};
|
||||
let Some(slot) = self.offsets.get_mut(self.column) else {
|
||||
return;
|
||||
};
|
||||
|
||||
let start: u16 = column
|
||||
.tickets
|
||||
.get(..self.card)
|
||||
.map(|before| before.iter().map(card_height).sum())
|
||||
.unwrap_or(0);
|
||||
let end = start
|
||||
+ column
|
||||
.tickets
|
||||
.get(self.card)
|
||||
.map(card_height)
|
||||
.unwrap_or(0);
|
||||
let total: u16 = column.tickets.iter().map(card_height).sum();
|
||||
|
||||
*slot = aligned_offset(*slot, start, end, column_text_height(screen), total);
|
||||
}
|
||||
|
||||
/// Open the detail view on the selected card, or close it if it is already open.
|
||||
pub fn toggle_detail(&mut self) {
|
||||
self.offset = 0;
|
||||
self.detail = match self.detail {
|
||||
Some(_) => None,
|
||||
None => self.selected().map(detail_of),
|
||||
};
|
||||
}
|
||||
|
||||
/// Scroll the open detail view by whole screenfuls, one line kept for overlap.
|
||||
///
|
||||
/// Up and down move the selection, so the scroll is on PageUp and PageDown. That is
|
||||
/// worth keeping either way: with the modal open, up and down step through the
|
||||
/// tickets and the modal follows, so a column can be read without closing it.
|
||||
///
|
||||
/// Clamped against the wrapped text rather than the raw lines, so the last page ends
|
||||
/// with the ticket instead of running on into blank space, and against zero at the
|
||||
/// top. The screen is asked for because both ends belong to the overlay, which only
|
||||
/// the draw otherwise measures.
|
||||
pub fn scroll_detail(&mut self, pages: isize, screen: Size) {
|
||||
let Some(detail) = &self.detail else { return };
|
||||
|
||||
let text = detail_text_area(Rect::new(0, 0, screen.width, screen.height));
|
||||
// A screenful less a line, so the eye has something to land on after the jump.
|
||||
let step = text.height.saturating_sub(1).max(1) as isize;
|
||||
let last = last_offset(detail, text) as isize;
|
||||
|
||||
self.offset = (self.offset as isize + pages.saturating_mul(step)).clamp(0, last) as u16;
|
||||
}
|
||||
|
||||
fn refresh_detail(&mut self) {
|
||||
// A newly selected ticket starts at its top, not partway down where the last one
|
||||
// was left.
|
||||
self.offset = 0;
|
||||
if self.detail.is_some() {
|
||||
self.detail = self.selected().map(detail_of);
|
||||
}
|
||||
@@ -243,7 +321,7 @@ pub fn draw(frame: &mut Frame, board: &Board) {
|
||||
draw_footer(frame, board, rows[1]);
|
||||
|
||||
if let Some(detail) = &board.detail {
|
||||
draw_detail(frame, detail, area);
|
||||
draw_detail(frame, detail, board.offset, area);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,17 +359,75 @@ fn draw_columns(frame: &mut Frame, board: &Board, area: Rect) {
|
||||
Color::Grey.into()
|
||||
}));
|
||||
|
||||
// The cards go into one paragraph, and where each card starts is recorded as
|
||||
// it is added: the scroll has to measure what is really drawn, not assume a
|
||||
// card size the renderer has to agree with.
|
||||
let mut lines: Vec<Line> = Vec::new();
|
||||
let mut starts: Vec<u16> = Vec::new();
|
||||
for (card, ticket) in column.tickets.iter().enumerate() {
|
||||
let selected = focused && card == board.card;
|
||||
starts.push(lines.len() as u16);
|
||||
lines.extend(card_lines(ticket, selected));
|
||||
}
|
||||
let total = lines.len() as u16;
|
||||
let text = areas[index].inner(Margin::new(1, 1));
|
||||
let stored = board.offsets.get(index).copied().unwrap_or(0);
|
||||
|
||||
// The focused column follows its selection here as well as on the keypress:
|
||||
// the terminal can be resized between the two, and a tick can shorten the
|
||||
// column under a reader who is already at the end. An unfocused column keeps
|
||||
// the place it was left in, capped so it cannot show blank space past its
|
||||
// last card.
|
||||
let offset = if focused {
|
||||
let start = starts.get(board.card).copied().unwrap_or(total);
|
||||
let end = starts.get(board.card + 1).copied().unwrap_or(total);
|
||||
aligned_offset(stored, start, end, text.height, total)
|
||||
} else {
|
||||
stored.min(total.saturating_sub(text.height))
|
||||
};
|
||||
|
||||
// An empty status is an empty column, not a column that is not there.
|
||||
frame.render_widget(Paragraph::new(lines).block(block), areas[index]);
|
||||
frame.render_widget(
|
||||
Paragraph::new(lines)
|
||||
.block(block)
|
||||
.scroll((offset, 0)),
|
||||
areas[index],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The lines one card occupies, measured the way `draw_columns` renders it.
|
||||
fn card_height(ticket: &TicketItem) -> u16 {
|
||||
card_lines(ticket, false).len() as u16
|
||||
}
|
||||
|
||||
/// The rows a column's cards share: above the footer row and inside the border.
|
||||
///
|
||||
/// Mirrors the vertical layout in `draw`: one footer row, then a border row on either
|
||||
/// side of the text. The draw measures the real inner rectangle instead, so a terminal
|
||||
/// too short for this arithmetic is corrected there.
|
||||
fn column_text_height(screen: Size) -> u16 {
|
||||
screen.height.saturating_sub(3)
|
||||
}
|
||||
|
||||
/// The offset that keeps the lines `start..end` in view, inside content `0..total`.
|
||||
///
|
||||
/// A range below the view lands its last line on the bottom row; one above the view
|
||||
/// puts its first line on the top row; inside, the offset stays where it was. Capped
|
||||
/// against `total - inner` last, so neither path runs past the end of the content into
|
||||
/// blank space — the same both-ends clamp `scroll_detail` applies to the overlay.
|
||||
fn aligned_offset(offset: u16, start: u16, end: u16, inner: u16, total: u16) -> u16 {
|
||||
let offset = if end > offset.saturating_add(inner) {
|
||||
end.saturating_sub(inner)
|
||||
} else if start < offset {
|
||||
start
|
||||
} else {
|
||||
offset
|
||||
};
|
||||
|
||||
offset.min(total.saturating_sub(inner))
|
||||
}
|
||||
|
||||
/// One card: the priority mark and short id, the title, then owner and due.
|
||||
fn card_lines(ticket: &TicketItem, selected: bool) -> Vec<Line<'static>> {
|
||||
let (glyph, colour) = priority_mark(ticket.priority);
|
||||
@@ -329,7 +465,7 @@ fn card_lines(ticket: &TicketItem, selected: bool) -> Vec<Line<'static>> {
|
||||
|
||||
fn draw_footer(frame: &mut Frame, board: &Board, area: Rect) {
|
||||
let keys = match board.detail {
|
||||
Some(_) => " ↑↓ scroll enter close q quit ",
|
||||
Some(_) => " ←→↑↓ select pgup/pgdn scroll enter close q quit ",
|
||||
None => " ←→ column ↑↓ card enter detail q quit ",
|
||||
};
|
||||
|
||||
@@ -339,16 +475,47 @@ fn draw_footer(frame: &mut Frame, board: &Board, area: Rect) {
|
||||
);
|
||||
}
|
||||
|
||||
fn draw_detail(frame: &mut Frame, detail: &str, area: Rect) {
|
||||
// Inset, so the board stays visible around the edges and the overlay reads as one.
|
||||
/// Where the detail overlay sits in the frame.
|
||||
///
|
||||
/// Inset, so the board stays visible around the edges and the overlay reads as one.
|
||||
fn detail_overlay(area: Rect) -> Rect {
|
||||
let width = area.width.saturating_sub(area.width / 5).max(20);
|
||||
let height = area.height.saturating_sub(area.height / 6).max(6);
|
||||
let overlay = Rect {
|
||||
Rect {
|
||||
x: area.x + (area.width.saturating_sub(width)) / 2,
|
||||
y: area.y + (area.height.saturating_sub(height)) / 2,
|
||||
width: width.min(area.width),
|
||||
height: height.min(area.height),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// The part of the overlay that holds text: the border takes a row and a column on
|
||||
/// either side, and the title sits on the top border rather than below it.
|
||||
fn detail_text_area(area: Rect) -> Rect {
|
||||
detail_overlay(area).inner(Margin::new(1, 1))
|
||||
}
|
||||
|
||||
/// The furthest the detail view can scroll: the last screenful, and no further.
|
||||
///
|
||||
/// Measured by the widget rather than counted by hand, since it wraps on words. A clamp
|
||||
/// on the raw lines would stop short of the end on a wrapped ticket, and one that
|
||||
/// ignored the wrapping the other way would scroll past it into blank space.
|
||||
fn last_offset(detail: &str, text: Rect) -> u16 {
|
||||
let wrapped = Paragraph::new(detail)
|
||||
.wrap(Wrap { trim: false })
|
||||
.line_count(text.width);
|
||||
|
||||
u16::try_from(wrapped)
|
||||
.unwrap_or(u16::MAX)
|
||||
.saturating_sub(text.height)
|
||||
}
|
||||
|
||||
fn draw_detail(frame: &mut Frame, detail: &str, offset: u16, area: Rect) {
|
||||
let overlay = detail_overlay(area);
|
||||
|
||||
// Clamped here as well as on the keypress: the terminal may have been resized since,
|
||||
// and a ticket read to its end can grow shorter under a tick.
|
||||
let offset = offset.min(last_offset(detail, detail_text_area(area)));
|
||||
|
||||
let block = Block::default()
|
||||
.borders(Borders::ALL)
|
||||
@@ -362,7 +529,8 @@ fn draw_detail(frame: &mut Frame, detail: &str, area: Rect) {
|
||||
frame.render_widget(
|
||||
Paragraph::new(detail.to_string())
|
||||
.block(block)
|
||||
.wrap(Wrap { trim: false }),
|
||||
.wrap(Wrap { trim: false })
|
||||
.scroll((offset, 0)),
|
||||
overlay,
|
||||
);
|
||||
}
|
||||
@@ -397,6 +565,22 @@ mod tests {
|
||||
path
|
||||
}
|
||||
|
||||
/// A section of numbered lines, so a test can say which of them is on screen.
|
||||
///
|
||||
/// Long enough not to fit any overlay the tests draw, which is true of every real
|
||||
/// ticket in the repo as well.
|
||||
fn long_section(lines: usize) -> String {
|
||||
let body: String = (1..=lines).map(|n| format!("Line {n:03}\n")).collect();
|
||||
format!("\n## Notes\n{body}")
|
||||
}
|
||||
|
||||
/// The screen the scrolling tests draw on, so the keypress and the draw measure the
|
||||
/// same overlay.
|
||||
const SCREEN: Size = Size {
|
||||
width: 120,
|
||||
height: 20,
|
||||
};
|
||||
|
||||
/// The rendered buffer as lines of text, escapes and styling dropped.
|
||||
fn render(board: &Board, width: u16, height: u16) -> Vec<String> {
|
||||
let mut terminal = Terminal::new(TestBackend::new(width, height)).unwrap();
|
||||
@@ -556,23 +740,23 @@ mod tests {
|
||||
let mut board = Board::new(&dir).unwrap();
|
||||
assert_eq!(board.selected().map(|t| t.title.clone()), Some("Alpha".to_string()));
|
||||
|
||||
board.select_card(1);
|
||||
board.select_card(1, SCREEN);
|
||||
assert_eq!(board.selected().map(|t| t.title.clone()), Some("Beta".to_string()));
|
||||
|
||||
// Clamped at both ends rather than wrapping
|
||||
board.select_card(5);
|
||||
board.select_card(5, SCREEN);
|
||||
assert_eq!(board.selected().map(|t| t.title.clone()), Some("Beta".to_string()));
|
||||
board.select_card(-9);
|
||||
board.select_card(-9, SCREEN);
|
||||
assert_eq!(board.selected().map(|t| t.title.clone()), Some("Alpha".to_string()));
|
||||
|
||||
board.select_column(1);
|
||||
board.select_column(1, SCREEN);
|
||||
assert_eq!(board.selected().map(|t| t.title.clone()), Some("Gamma".to_string()));
|
||||
|
||||
// reviewing is empty, so there is nothing selected there
|
||||
board.select_column(1);
|
||||
board.select_column(1, SCREEN);
|
||||
assert!(board.selected().is_none());
|
||||
|
||||
board.select_column(-9);
|
||||
board.select_column(-9, SCREEN);
|
||||
assert_eq!(board.column, 0);
|
||||
}
|
||||
|
||||
@@ -587,13 +771,191 @@ mod tests {
|
||||
write_ticket(&dir, "committed", "44444444-0000-4000-8000-000000000000", "Delta", "");
|
||||
|
||||
let mut board = Board::new(&dir).unwrap();
|
||||
board.select_card(2);
|
||||
board.select_column(1);
|
||||
board.select_card(2, SCREEN);
|
||||
board.select_column(1, SCREEN);
|
||||
|
||||
assert_eq!(board.card, 0);
|
||||
assert_eq!(board.selected().map(|t| t.title.clone()), Some("Delta".to_string()));
|
||||
}
|
||||
|
||||
/// A column long enough that one window cannot hold it: twelve cards at four lines
|
||||
/// each against seventeen visible rows on [`SCREEN`].
|
||||
fn fill_column(dir: &Path, status: &str, count: usize) {
|
||||
for n in 1..=count {
|
||||
write_ticket(
|
||||
dir,
|
||||
status,
|
||||
&format!("{n:08}-0000-4000-8000-000000000000"),
|
||||
&format!("Ticket {n:02}"),
|
||||
"",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The reported bug: walking the selection down past the fold left the highlight on
|
||||
/// a card the window could not see, so from the keyboard nothing appeared to move.
|
||||
#[test]
|
||||
fn selecting_down_past_the_fold_brings_the_selected_card_into_view() {
|
||||
let dir = board_dir();
|
||||
fill_column(&dir, "backlog", 12);
|
||||
|
||||
let mut board = Board::new(&dir).unwrap();
|
||||
|
||||
let top = render(&board, SCREEN.width, SCREEN.height).join("\n");
|
||||
assert!(top.contains("Ticket 01"), "{top}");
|
||||
assert!(
|
||||
!top.contains("Ticket 12"),
|
||||
"the fixture fits without scrolling:\n{top}"
|
||||
);
|
||||
|
||||
board.select_card(11, SCREEN);
|
||||
|
||||
let scrolled = render(&board, SCREEN.width, SCREEN.height).join("\n");
|
||||
assert!(
|
||||
scrolled.contains("Ticket 12"),
|
||||
"the selection fell below the fold:\n{scrolled}"
|
||||
);
|
||||
assert!(!scrolled.contains("Ticket 01"), "nothing scrolled:\n{scrolled}");
|
||||
}
|
||||
|
||||
/// And back up again: reaching the top returns the column to its head.
|
||||
#[test]
|
||||
fn selecting_up_scrolls_back_to_the_top() {
|
||||
let dir = board_dir();
|
||||
fill_column(&dir, "backlog", 12);
|
||||
|
||||
let mut board = Board::new(&dir).unwrap();
|
||||
board.select_card(11, SCREEN);
|
||||
assert_eq!(board.offsets[0], 31);
|
||||
|
||||
board.select_card(-99, SCREEN);
|
||||
assert_eq!(board.offsets[0], 0, "the column stayed where the bottom left it");
|
||||
|
||||
let top = render(&board, SCREEN.width, SCREEN.height).join("\n");
|
||||
assert!(top.contains("Ticket 01"), "{top}");
|
||||
assert!(!top.contains("Ticket 12"), "{top}");
|
||||
}
|
||||
|
||||
/// Down stops at the last card rather than running into blank space past it, and
|
||||
/// the last card is what ends the view.
|
||||
#[test]
|
||||
fn the_column_scroll_stops_at_the_last_card() {
|
||||
let dir = board_dir();
|
||||
fill_column(&dir, "backlog", 12);
|
||||
|
||||
let mut board = Board::new(&dir).unwrap();
|
||||
// More downs than the column has, since the clamp and the cap are what stop it.
|
||||
for _ in 0..30 {
|
||||
board.select_card(1, SCREEN);
|
||||
}
|
||||
|
||||
assert_eq!(board.card, 11);
|
||||
// Twelve cards at four lines, seventeen visible rows.
|
||||
assert_eq!(board.offsets[0], 48 - 17);
|
||||
|
||||
let end = render(&board, SCREEN.width, SCREEN.height).join("\n");
|
||||
assert!(end.contains("Ticket 12"), "the end is out of reach:\n{end}");
|
||||
assert!(!end.contains("Ticket 01"), "nothing scrolled:\n{end}");
|
||||
}
|
||||
|
||||
/// A ticket moved elsewhere shortens the column under the reader; the draw has to
|
||||
/// take that without waiting for a keypress, and the stored offset heals on the
|
||||
/// next one rather than throwing the reader anywhere first.
|
||||
#[test]
|
||||
fn a_tick_that_shrinks_a_column_keeps_the_selection_in_view() {
|
||||
let dir = board_dir();
|
||||
fill_column(&dir, "backlog", 12);
|
||||
|
||||
let mut board = Board::new(&dir).unwrap();
|
||||
board.select_card(11, SCREEN);
|
||||
|
||||
for n in 6..=12 {
|
||||
let uuid = format!("{n:08}-0000-4000-8000-000000000000");
|
||||
let name = format!("{uuid}_ticket-{n:02}.md");
|
||||
std::fs::remove_file(dir.join("backlog").join(name)).unwrap();
|
||||
}
|
||||
|
||||
assert!(board.tick().unwrap(), "the tick saw no change");
|
||||
assert_eq!(board.card, 4, "the selection was not clamped to the new end");
|
||||
|
||||
let shrunk = render(&board, SCREEN.width, SCREEN.height).join("\n");
|
||||
assert!(shrunk.contains("Ticket 05"), "the new end is out of reach:\n{shrunk}");
|
||||
assert!(!shrunk.contains("Ticket 06"), "{shrunk}");
|
||||
|
||||
// The stored value is stale until the next navigation, which is fine: the draw
|
||||
// corrected what was shown, and this is what writes the correction back.
|
||||
board.select_card(0, SCREEN);
|
||||
assert_eq!(board.offsets[0], 3);
|
||||
}
|
||||
|
||||
/// Each column keeps its own place: leaving one must not snap it back to the top,
|
||||
/// and entering one must show the card the selection landed on, not its head.
|
||||
#[test]
|
||||
fn each_column_keeps_its_place_and_entering_one_shows_the_selection() {
|
||||
let dir = board_dir();
|
||||
fill_column(&dir, "backlog", 12);
|
||||
for n in 1..=3 {
|
||||
write_ticket(
|
||||
&dir,
|
||||
"committed",
|
||||
&format!("{:08}-0000-4000-8000-000000000000", n + 20),
|
||||
&format!("Other {n:02}"),
|
||||
"",
|
||||
);
|
||||
}
|
||||
|
||||
let mut board = Board::new(&dir).unwrap();
|
||||
board.select_card(11, SCREEN);
|
||||
|
||||
board.select_column(1, SCREEN);
|
||||
// The card index carried over and clamps onto committed's last card.
|
||||
assert_eq!(board.card, 2);
|
||||
|
||||
let away = render(&board, SCREEN.width, SCREEN.height).join("\n");
|
||||
assert!(
|
||||
away.contains("Ticket 12"),
|
||||
"leaving snapped the column back to its top:\n{away}"
|
||||
);
|
||||
assert!(away.contains("Other 03"), "{away}");
|
||||
|
||||
board.select_column(-1, SCREEN);
|
||||
// Back in backlog the selection is card 2: the index is shared and it moved
|
||||
// while we were away, so the column follows where it is now rather than
|
||||
// holding a scroll position for a highlight it no longer has.
|
||||
assert_eq!(board.card, 2);
|
||||
let back = render(&board, SCREEN.width, SCREEN.height).join("\n");
|
||||
assert!(
|
||||
back.contains("Ticket 03"),
|
||||
"returning lost the selection:\n{back}"
|
||||
);
|
||||
assert!(!back.contains("Ticket 12"), "{back}");
|
||||
}
|
||||
|
||||
/// The terminal can shrink between the keypress and the draw; the draw measures the
|
||||
/// real geometry, so the selection cannot be left above or below the fold.
|
||||
#[test]
|
||||
fn a_resize_between_the_keypress_and_the_draw_is_taken_at_draw_time() {
|
||||
let dir = board_dir();
|
||||
fill_column(&dir, "backlog", 12);
|
||||
|
||||
// Tall enough that every card fits, so the keypress stores no scroll at all.
|
||||
let roomy = Size {
|
||||
width: 120,
|
||||
height: 60,
|
||||
};
|
||||
|
||||
let mut board = Board::new(&dir).unwrap();
|
||||
board.select_card(11, roomy);
|
||||
assert_eq!(board.offsets[0], 0);
|
||||
|
||||
let shrunk = render(&board, SCREEN.width, SCREEN.height).join("\n");
|
||||
assert!(
|
||||
shrunk.contains("Ticket 12"),
|
||||
"the smaller window hid the selection:\n{shrunk}"
|
||||
);
|
||||
assert!(!shrunk.contains("Ticket 01"), "{shrunk}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_detail_view_shows_the_body_and_the_comments() {
|
||||
let dir = board_dir();
|
||||
@@ -658,6 +1020,219 @@ mod tests {
|
||||
assert!(!board.tick().unwrap());
|
||||
}
|
||||
|
||||
/// The reported bug: a ticket longer than the overlay had no way to be read past its
|
||||
/// first screenful, comments included.
|
||||
#[test]
|
||||
fn paging_down_reaches_the_end_of_a_long_ticket() {
|
||||
let dir = board_dir();
|
||||
let uuid = "11111111-0000-4000-8000-000000000000";
|
||||
write_ticket(&dir, "backlog", uuid, "First one", &long_section(60));
|
||||
|
||||
let comments = dir.join("comments").join(uuid);
|
||||
std::fs::create_dir_all(&comments).unwrap();
|
||||
std::fs::write(
|
||||
comments.join("20260821_120000_000000.md"),
|
||||
"**Comment**\nThe last word.\n\n**Author**: bob\n**Time**: 2026-08-21 12:00:00\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut board = Board::new(&dir).unwrap();
|
||||
board.toggle_detail();
|
||||
|
||||
let top = render(&board, SCREEN.width, SCREEN.height).join("\n");
|
||||
assert!(top.contains("A description."), "not at the top:\n{top}");
|
||||
assert!(!top.contains("Line 060"), "the fixture is too short:\n{top}");
|
||||
|
||||
// More pages than the ticket has, since the clamp is what stops it.
|
||||
for _ in 0..20 {
|
||||
board.scroll_detail(1, SCREEN);
|
||||
}
|
||||
|
||||
let end = render(&board, SCREEN.width, SCREEN.height).join("\n");
|
||||
assert!(end.contains("Line 060"), "the end is out of reach:\n{end}");
|
||||
assert!(end.contains("The last word."), "the comments are out of reach:\n{end}");
|
||||
assert!(!end.contains("A description."), "nothing scrolled:\n{end}");
|
||||
}
|
||||
|
||||
/// The end of the scroll is the end of the text, not blank space past it, and the top
|
||||
/// of it is the top of the ticket.
|
||||
#[test]
|
||||
fn the_scroll_offset_stops_at_both_ends() {
|
||||
let dir = board_dir();
|
||||
write_ticket(
|
||||
&dir,
|
||||
"backlog",
|
||||
"11111111-0000-4000-8000-000000000000",
|
||||
"First one",
|
||||
&long_section(60),
|
||||
);
|
||||
|
||||
let mut board = Board::new(&dir).unwrap();
|
||||
board.toggle_detail();
|
||||
|
||||
for _ in 0..20 {
|
||||
board.scroll_detail(1, SCREEN);
|
||||
}
|
||||
let settled = board.offset;
|
||||
assert!(settled > 0, "a long ticket did not scroll at all");
|
||||
|
||||
board.scroll_detail(1, SCREEN);
|
||||
assert_eq!(board.offset, settled, "the offset ran past the end");
|
||||
|
||||
// The last screenful is full: text on the bottom row of the overlay, not the
|
||||
// blank space a clamp on the raw lines would have left there.
|
||||
let lines = render(&board, SCREEN.width, SCREEN.height);
|
||||
let text = detail_text_area(Rect::new(0, 0, SCREEN.width, SCREEN.height));
|
||||
let bottom: String = lines[(text.bottom() - 1) as usize]
|
||||
.chars()
|
||||
.skip(text.x as usize)
|
||||
.take(text.width as usize)
|
||||
.collect();
|
||||
assert!(
|
||||
!bottom.trim().is_empty(),
|
||||
"the last page ran into blank space:\n{}",
|
||||
lines.join("\n")
|
||||
);
|
||||
|
||||
board.scroll_detail(-40, SCREEN);
|
||||
assert_eq!(board.offset, 0, "the offset went above the top");
|
||||
}
|
||||
|
||||
/// A ticket that fits has nothing to scroll, so the keys do nothing to it.
|
||||
#[test]
|
||||
fn a_ticket_shorter_than_the_overlay_does_not_scroll() {
|
||||
let dir = board_dir();
|
||||
write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "First one", "");
|
||||
|
||||
// Tall enough that the whole ticket is on screen at once.
|
||||
let roomy = Size {
|
||||
width: 120,
|
||||
height: 60,
|
||||
};
|
||||
|
||||
let mut board = Board::new(&dir).unwrap();
|
||||
board.toggle_detail();
|
||||
let before = render(&board, roomy.width, roomy.height);
|
||||
|
||||
board.scroll_detail(1, roomy);
|
||||
assert_eq!(board.offset, 0);
|
||||
assert_eq!(render(&board, roomy.width, roomy.height), before);
|
||||
}
|
||||
|
||||
/// Up and down still move the selection with the detail view open, and the modal
|
||||
/// follows, which is the reason the scroll went on pgup and pgdn in the first place.
|
||||
#[test]
|
||||
fn the_selection_still_moves_under_an_open_detail_view() {
|
||||
let dir = board_dir();
|
||||
write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "Alpha", "");
|
||||
write_ticket(&dir, "backlog", "22222222-0000-4000-8000-000000000000", "Beta", "");
|
||||
|
||||
let mut board = Board::new(&dir).unwrap();
|
||||
board.toggle_detail();
|
||||
// By id rather than title: the body leaves the title to the caller that prints
|
||||
// the heading, so the detail text does not carry it.
|
||||
assert!(board.detail.clone().unwrap().contains("11111111"), "{:?}", board.detail);
|
||||
|
||||
board.select_card(1, SCREEN);
|
||||
assert_eq!(board.selected().map(|t| t.title.clone()), Some("Beta".to_string()));
|
||||
assert!(board.detail.clone().unwrap().contains("22222222"), "{:?}", board.detail);
|
||||
}
|
||||
|
||||
/// A newly selected ticket starts at its own top, not where the last one was left.
|
||||
#[test]
|
||||
fn the_scroll_offset_resets_when_the_selection_moves() {
|
||||
let dir = board_dir();
|
||||
let long = long_section(60);
|
||||
write_ticket(&dir, "backlog", "11111111-0000-4000-8000-000000000000", "Alpha", &long);
|
||||
write_ticket(&dir, "backlog", "22222222-0000-4000-8000-000000000000", "Beta", &long);
|
||||
write_ticket(&dir, "committed", "33333333-0000-4000-8000-000000000000", "Gamma", &long);
|
||||
|
||||
let mut board = Board::new(&dir).unwrap();
|
||||
board.toggle_detail();
|
||||
|
||||
board.scroll_detail(1, SCREEN);
|
||||
assert!(board.offset > 0);
|
||||
board.select_card(1, SCREEN);
|
||||
assert_eq!(board.offset, 0, "the next card opened partway down");
|
||||
|
||||
board.scroll_detail(1, SCREEN);
|
||||
assert!(board.offset > 0);
|
||||
board.select_column(1, SCREEN);
|
||||
assert_eq!(board.offset, 0, "the next column opened partway down");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_scroll_offset_resets_when_the_detail_view_is_reopened() {
|
||||
let dir = board_dir();
|
||||
write_ticket(
|
||||
&dir,
|
||||
"backlog",
|
||||
"11111111-0000-4000-8000-000000000000",
|
||||
"First one",
|
||||
&long_section(60),
|
||||
);
|
||||
|
||||
let mut board = Board::new(&dir).unwrap();
|
||||
board.toggle_detail();
|
||||
board.scroll_detail(1, SCREEN);
|
||||
assert!(board.offset > 0);
|
||||
|
||||
board.toggle_detail();
|
||||
board.toggle_detail();
|
||||
assert_eq!(board.offset, 0, "the ticket reopened where it was left");
|
||||
}
|
||||
|
||||
/// An edit elsewhere in the tree must not throw the reader back to the top.
|
||||
#[test]
|
||||
fn a_tick_leaves_the_scroll_where_the_reader_put_it() {
|
||||
let dir = board_dir();
|
||||
let uuid = "11111111-0000-4000-8000-000000000000";
|
||||
write_ticket(&dir, "backlog", uuid, "First one", &long_section(60));
|
||||
|
||||
let mut board = Board::new(&dir).unwrap();
|
||||
board.toggle_detail();
|
||||
board.scroll_detail(1, SCREEN);
|
||||
let offset = board.offset;
|
||||
|
||||
let comments = dir.join("comments").join(uuid);
|
||||
std::fs::create_dir_all(&comments).unwrap();
|
||||
std::fs::write(
|
||||
comments.join("20260821_120000_000000.md"),
|
||||
"**Comment**\nA late note.\n\n**Author**: bob\n**Time**: 2026-08-21 12:00:00\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert!(board.tick().unwrap(), "the tick saw no change");
|
||||
assert_eq!(board.offset, offset);
|
||||
}
|
||||
|
||||
/// The footer is what sent the reporter looking for their own mistake, so it has to
|
||||
/// name the keys that exist and only those.
|
||||
#[test]
|
||||
fn the_footer_names_the_keys_that_work() {
|
||||
let dir = board_dir();
|
||||
write_ticket(
|
||||
&dir,
|
||||
"backlog",
|
||||
"11111111-0000-4000-8000-000000000000",
|
||||
"First one",
|
||||
&long_section(60),
|
||||
);
|
||||
|
||||
let mut board = Board::new(&dir).unwrap();
|
||||
|
||||
let closed = render(&board, SCREEN.width, SCREEN.height).join("\n");
|
||||
assert!(closed.contains("↑↓ card"), "{closed}");
|
||||
assert!(closed.contains("enter detail"), "{closed}");
|
||||
assert!(!closed.contains("scroll"), "a scroll offered with nothing open:\n{closed}");
|
||||
|
||||
board.toggle_detail();
|
||||
let open = render(&board, SCREEN.width, SCREEN.height).join("\n");
|
||||
assert!(open.contains("pgup/pgdn scroll"), "{open}");
|
||||
assert!(open.contains("select"), "{open}");
|
||||
assert!(open.contains("enter close"), "{open}");
|
||||
}
|
||||
|
||||
/// The board and the listing draw from the same palette, so a colour cannot exist
|
||||
/// for one and not the other. The enum makes that a compile error; this pins the
|
||||
/// mapping itself.
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
use assert_cmd::Command;
|
||||
use assert_fs::TempDir;
|
||||
|
||||
const BIN_NAME: &str = env!("CARGO_BIN_EXE_worklane");
|
||||
|
||||
/// The document as this test's binary carries it, so the print path is pinned to the
|
||||
/// file in the repo rather than to a description of it.
|
||||
const SKILL: &str = include_str!("../assets/SKILL.md");
|
||||
|
||||
/// `HOME` is redirected, so the suite never writes into the home of whoever runs it.
|
||||
/// A temp directory rather than the real one is also what makes the already-installed
|
||||
/// and the modified cases reachable at all.
|
||||
fn run(home: &TempDir, args: &[&str]) -> std::process::Output {
|
||||
let mut cmd = Command::cargo_bin(BIN_NAME).unwrap();
|
||||
cmd.env("HOME", home.path()).args(args);
|
||||
cmd.assert().get_output().clone()
|
||||
}
|
||||
|
||||
fn installed(home: &TempDir) -> std::path::PathBuf {
|
||||
home.path().join(".claude/skills/worklane/SKILL.md")
|
||||
}
|
||||
|
||||
/// Nothing about the skill needs a board, and it is wanted before there is one.
|
||||
#[test]
|
||||
fn the_skill_installs_outside_a_worklane_directory() {
|
||||
let home = TempDir::new().unwrap();
|
||||
|
||||
let out = run(&home, &["install-skill"]);
|
||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||
|
||||
assert_eq!(out.status.code(), Some(0), "{stdout}");
|
||||
assert!(stdout.contains("Installed the worklane skill"), "{stdout}");
|
||||
assert!(stdout.contains(".claude/skills/worklane/SKILL.md"), "{stdout}");
|
||||
assert_eq!(std::fs::read_to_string(installed(&home)).unwrap(), SKILL);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_second_install_says_it_is_already_up_to_date() {
|
||||
let home = TempDir::new().unwrap();
|
||||
run(&home, &["install-skill"]);
|
||||
|
||||
let out = run(&home, &["install-skill"]);
|
||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||
|
||||
assert_eq!(out.status.code(), Some(0), "{stdout}");
|
||||
assert!(stdout.contains("Already up to date"), "{stdout}");
|
||||
}
|
||||
|
||||
/// A copy someone edited is theirs. The command says what to do next rather than
|
||||
/// discarding it, and only `--force` overwrites.
|
||||
#[test]
|
||||
fn a_modified_copy_is_reported_and_needs_force() {
|
||||
let home = TempDir::new().unwrap();
|
||||
run(&home, &["install-skill"]);
|
||||
std::fs::write(installed(&home), "hand written\n").unwrap();
|
||||
|
||||
let out = run(&home, &["install-skill"]);
|
||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||
|
||||
assert_eq!(out.status.code(), Some(0), "{stdout}");
|
||||
assert!(stdout.contains("Differs from the version in this binary"), "{stdout}");
|
||||
assert!(stdout.contains("--force"), "{stdout}");
|
||||
assert!(stdout.contains("--print"), "the message never says how to compare: {stdout}");
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(installed(&home)).unwrap(),
|
||||
"hand written\n",
|
||||
"the modified copy was overwritten anyway"
|
||||
);
|
||||
|
||||
let out = run(&home, &["install-skill", "--force"]);
|
||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||
assert!(stdout.contains("Installed the worklane skill"), "{stdout}");
|
||||
assert_eq!(std::fs::read_to_string(installed(&home)).unwrap(), SKILL);
|
||||
}
|
||||
|
||||
/// The print path is what makes a modified copy diffable, so it has to be the document
|
||||
/// byte for byte and it must not install anything on the way past.
|
||||
#[test]
|
||||
fn print_writes_the_document_to_stdout_and_installs_nothing() {
|
||||
let home = TempDir::new().unwrap();
|
||||
|
||||
let out = run(&home, &["install-skill", "--print"]);
|
||||
|
||||
assert_eq!(out.status.code(), Some(0));
|
||||
assert_eq!(String::from_utf8_lossy(&out.stdout), SKILL);
|
||||
assert!(!installed(&home).exists(), "--print installed the skill anyway");
|
||||
}
|
||||
|
||||
/// The command has to be findable by someone who does not already know it exists.
|
||||
#[test]
|
||||
fn the_help_lists_the_install_skill_command() {
|
||||
let home = TempDir::new().unwrap();
|
||||
|
||||
let stdout = String::from_utf8_lossy(&run(&home, &["--help"]).stdout).to_string();
|
||||
assert!(stdout.contains("install-skill"), "{stdout}");
|
||||
}
|
||||
Reference in New Issue
Block a user