flurdy/agent-skills / skills/next
next
VerifiedRank ready beads across validated workspace stores or one local store. List read-only, or claim one selected bead, show its details, and continue into its work.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 50.1 KB |
| pi/index.ts | script | 2.5 KB |
| pi/lease-selection.ts | script | 16.9 KB |
| references/dolt-recovery.md | markdown | 7.7 KB |
| references/source-scope.md | markdown | 12.5 KB |
| scripts/bd-showexecutable | script | 1.1 KB |
| scripts/collect.pyexecutable | script | 25.5 KB |
| scripts/next-bdexecutable | script | 16.5 KB |
| scripts/next-selectexecutable | script | 21.3 KB |
| tests/lease-extension.test.mjs | script | 7.4 KB |
| tests/lease-kernel.test.mjs | script | 3.7 KB |
| tests/lease-selection.test.mjs | script | 20.1 KB |
| tests/test_defer_dates.py | script | 6.8 KB |
| tests/test_dolt_recovery_contract.py | script | 3.3 KB |
| tests/test_machine_routing.py | script | 10.1 KB |
| tests/test_next_bd.py | script | 43.8 KB |
| tests/test_next_select.py | script | 36.2 KB |
| tests/test_ownership_contract.py | script | 2.8 KB |
| tests/test_read_deadlines.py | script | 8.2 KB |
| tests/test_related.py | script | 11.4 KB |
| tests/test_source_scope.py | script | 10.1 KB |
| tests/workspace_fixture.py | script | 10.8 KB |
tests/test_next_bd.py
View on GitHubfrom __future__ import annotations
import importlib.util
import json
import os
import shutil
import subprocess
import sys
import unittest
from unittest import mock
from pathlib import Path
from typing import Any
from workspace_fixture import SKILL_DIR, WorkspaceFixture, issue
SCRIPT = SKILL_DIR / "scripts" / "next-bd"
class NextBdTest(WorkspaceFixture):
def run_next(self, directory: Path, *arguments: str) -> subprocess.CompletedProcess[str]:
return self.run_script(SCRIPT, directory, *arguments)
def test_parent_context_is_display_only_and_survives_filtered_parents(self) -> None:
date = "2026-01-01T00:00:00Z"
child = {**issue("child", 2, "task", date), "parent": "group"}
epic = issue("group", 2, "epic", date)
hidden = {**issue("hidden-child", 3, "feature", date), "parent": "closed-task"}
standalone = issue("group.1", 3, "task", date)
data = {
"ready": [epic, child, hidden, standalone,
{**issue("backlog", 4, "task", date), "parent": "group"}],
"other": [{**issue("closed-task", 2, "task", date), "status": "closed"}],
**{category: [{**issue(category, 2, "task", date), "parent": "a|b\n\u001b"}]
for category in ("in_progress", "blocked", "deferred")},
}
workspace = self.create_workspace(root_data=data, repositories={
"repo-a": {"ready": [{**child, "parent": "other-group"}, epic]},
})
local = self.base / "local"
self.create_store(local, **data)
for directory, owner in ((workspace, "workspace | "), (local, "")):
with self.subTest(workspace=bool(owner)):
expected = ["child", "group", "group.1", "hidden-child"]
rows = json.loads(self.run_next(directory, "--json").stdout)
owned = [row for row in rows if row.get("repository", "workspace") == "workspace"]
self.assertEqual([row["id"] for row in owned], expected)
self.assertEqual(owned[0]["parent"], "group")
for flags in (("--list", "--backlog"), ("--safe",), ("--in-progress",)):
output = self.run_next(directory, *flags).stdout
self.assertIn("| Labels | Title | Parent |", output)
self.assertIn(f"| {owner}child | P2 | task | - | Title for child | group |", output)
self.assertIn(f"| {owner}group.1 | P3 | task | - | Title for group.1 | — |", output)
self.assertIn("Title for hidden-child | closed-task |", output)
self.assertNotIn("| Title for closed-task |", output)
if "--in-progress" not in flags:
for category in ("in_progress", "blocked", "deferred"):
self.assertIn(f"Title for {category} | a|b |", output)
self.assertNotIn("\u001b", output)
if "--backlog" in flags:
self.assertIn("Title for backlog | group |", output)
if owner:
self.assertIn("| repo-a | child | P2 | task | - | Title for child | other-group |", output)
filtered = self.run_next(directory, "--type=task").stdout
self.assertIn("Title for child | group |", filtered)
self.assertNotIn("Title for group |", filtered)
safe = json.loads(self.run_next(directory, "--safe-json").stdout)
self.assertEqual([(row["id"], row.get("parent"), row["rank"]) for row in safe["candidates"]],
[(row["id"], row.get("parent"), row["rank"]) for row in rows])
calls = self.recorded_calls()
self.assertTrue(all("--readonly" in call["arguments"] for call in calls))
self.assertTrue(all(call["arguments"][0] in ("list", "blocked") for call in calls))
def test_help_prints_supported_options_without_collecting(self) -> None:
result = self.run_next(self.base, "--help")
self.assertIn("Usage: next-bd [OPTIONS]", result.stdout)
for option in ("--list", "--backlog", "--status", "--in-progress", "--avoid-busy", "--json", "--type=TYPE"):
self.assertIn(option, result.stdout)
self.assertEqual(result.stderr, "")
self.assertEqual(self.recorded_calls(), [])
def test_workspace_candidates_are_globally_ranked_and_owned(self) -> None:
workspace = self.create_workspace(
root_data={
"ready": [
issue("root-task", 2, "task", "2026-01-04T00:00:00Z"),
issue("root-blocked", 2, "task", "2026-01-01T00:00:00Z"),
issue("root-p4", 4, "bug", "2026-01-01T00:00:00Z"),
],
"blocked": [issue("root-blocked", 2, "task", "2026-01-01T00:00:00Z")],
},
repositories={
"repo-a": {
"ready": [issue("repo-feature", 1, "feature", "2026-01-03T00:00:00Z")]
},
"repo-b": {
"ready": [
issue("repo-bug", 2, "bug", "2026-01-02T00:00:00Z"),
issue("root-blocked", 2, "task", "2026-01-03T00:00:00Z"),
]
},
},
)
candidates = json.loads(self.run_next(workspace, "--json").stdout)
self.assertEqual(
[(candidate["repository"], candidate["id"]) for candidate in candidates],
[
("repo-a", "repo-feature"),
("repo-b", "repo-bug"),
("repo-b", "root-blocked"),
("workspace", "root-task"),
],
)
self.assertTrue(
all(
candidate["selector"] == f"{candidate['repository']}:{candidate['id']}"
and candidate["repository_path"] in {".", "repos/repo-a", "repos/repo-b"}
for candidate in candidates
)
)
def test_priority_then_type_then_age_across_candidate_views(self) -> None:
types = ("bug", "task", "feature", "spike", "chore", "epic")
rows = [
issue(f"p{priority}-{kind}", priority, kind,
f"2026-01-{20 - index:02}T00:00:00Z")
for priority in range(5)
for index, kind in enumerate(types)
]
workspace = self.create_workspace(root_data={"ready": list(reversed(rows))})
expected = [
f"p{priority}-{kind}" for priority in range(4)
for kind in ("bug", "feature", "task", "chore", "spike", "epic")
]
for flags in (("--json",), ("--json", "--avoid-busy"), ("--safe-json",)):
with self.subTest(flags=flags):
result = json.loads(self.run_next(workspace, *flags).stdout)
candidates = result["candidates"] if "--safe-json" in flags else result
self.assertEqual([row["id"] for row in candidates], expected)
self.assertEqual([row["rank"] for row in candidates],
sorted(row["rank"] for row in candidates))
if "--avoid-busy" in flags:
quick = [row for row in candidates if row["issue_type"] != "epic"]
self.assertEqual([row["id"] for row in quick],
[key for key in expected if not key.endswith("-epic")])
for flag in ("--list", "--safe"):
markdown = self.run_next(workspace, flag).stdout
positions = [markdown.index(f"| {key} |") for key in expected]
self.assertEqual(positions, sorted(positions))
for priority in range(4):
self.assertIn(f"| {priority * 6 + 1} | workspace | p{priority}-bug |", markdown)
self.assertNotIn("| p4-", markdown)
bugs = json.loads(self.run_next(workspace, "--json", "--type=bug").stdout)
self.assertEqual([row["id"] for row in bugs], [f"p{p}-bug" for p in range(4)])
def test_equal_priority_type_and_age_use_repository_then_id(self) -> None:
date = "2026-01-01T00:00:00Z"
workspace = self.create_workspace(
root_data={"ready": [issue("root", 1, "task", date)]},
repositories={
"repo-b": {"ready": [issue("a", 1, "feature", date)]},
"repo-a": {"ready": [issue("z", 1, "task", date), issue("a", 1, "feature", date)]},
},
)
candidates = json.loads(self.run_next(workspace, "--json").stdout)
self.assertEqual([(row["repository"], row["id"]) for row in candidates],
[("repo-a", "a"), ("repo-a", "z"), ("repo-b", "a"), ("workspace", "root")])
def test_auto_pick_and_sprint_instructions_preserve_collector_order(self) -> None:
skill = (SKILL_DIR / "SKILL.md").read_text()
quick = skill.split("## Quick Task Selection", 1)[1].split("## Sprint Mode", 1)[0]
for required in ("--json --avoid-busy", "Exclude epics", "preserving the collector's priority/type/age order",
"first remaining candidate", "never fall back to P4 or busy work"):
self.assertIn(required, quick)
self.assertNotIn("P3 > P2 > P1", skill)
self.assertIn("Within each bucket, preserve the `next-bd` rank order", skill)
self.assertIn("`task`: Use `next-bd --json`, auto-select the top-ranked bead", skill)
self.assertIn("`bug`: Use `next-bd --json --type=bug`, auto-select the top-ranked bug", skill)
def test_safe_filter_and_in_progress_output_are_owner_scoped(self) -> None:
workspace = self.create_workspace(
repositories={
"repo-a": {
"ready": [
issue(
"same-owner-busy",
2,
"task",
"2026-01-01T00:00:00Z",
labels=["shared"],
),
issue("unlabelled", 2, "task", "2026-01-02T00:00:00Z"),
],
"in_progress": [
issue(
"active-a",
2,
"feature",
"2026-01-01T00:00:00Z",
labels=["shared"],
)
],
},
"repo-b": {
"ready": [
issue(
"other-owner-ready",
2,
"task",
"2026-01-01T00:00:00Z",
labels=["shared"],
)
]
},
}
)
candidates = json.loads(
self.run_next(workspace, "--json", "--avoid-busy").stdout
)
self.assertEqual(
{(candidate["repository"], candidate["id"]) for candidate in candidates},
{("repo-a", "unlabelled"), ("repo-b", "other-owner-ready")},
)
markdown = self.run_next(workspace, "--in-progress").stdout
self.assertIn("| # | Repo | ID | Pri | Type | Labels | Title | Parent |", markdown)
self.assertIn(
"Tracker status: in progress (session activity unverified):", markdown
)
self.assertNotIn("other sessions", markdown)
self.assertIn('[repo-a] `active-a`', markdown)
def test_full_listing_renders_complete_non_selectable_tables(self) -> None:
data = {
category: [
issue(f"{category}-{index}", 2 if category == "ready" else 4,
"task", "2026-01-01T00:00:00Z", labels=["scope"])
for index in range(55)
]
for category in ("ready", "in_progress", "blocked", "deferred")
}
data["blocked"][0]["blocked_by"] = ["dep-a", "dep-b"]
data["blocked"][1]["blocked_by_count"] = 3
data["deferred"][0]["defer_until"] = "2026-10-01T12:00:00Z"
workspace = self.create_workspace(repositories={"repo-a": data})
local = self.base / "local"
self.create_store(local, **data)
for directory, owner in ((workspace, "repo-a | "), (local, "")):
with self.subTest(workspace=bool(owner)):
result = self.run_next(directory, "--list")
self.assertEqual(result.stderr, "")
self.assertIn("## Ready to Work (55 beads)", result.stdout)
for heading in ("In Progress", "Blocked", "Deferred"):
self.assertIn(f"## {heading} (55 beads; not selectable)", result.stdout)
self.assertIn("session activity unverified", result.stdout)
self.assertIn("| Blocked by |", result.stdout)
self.assertIn("| Defer until |", result.stdout)
self.assertIn("dep-a, dep-b", result.stdout)
self.assertIn("3 blockers", result.stdout)
self.assertIn("2026-10-01T12:00:00Z", result.stdout)
for category in ("in_progress", "blocked", "deferred"):
for index in range(55):
self.assertIn(f"| {owner}{category}-{index} | P4 |", result.stdout)
self.assertIn(f"| {owner}deferred-1 | P4 | task | scope | Title for deferred-1 | — | — |", result.stdout)
self.assertEqual("| Repo |" in result.stdout, bool(owner))
self.assertEqual(result.stdout.count("| # |"), 1)
self.assertEqual(result.stdout.count("| 1 |"), 1)
combined = self.run_next(directory, "--list", "--in-progress").stdout
self.assertEqual(combined, result.stdout)
candidates = self.run_next(directory, "--json").stdout
self.assertEqual(self.run_next(directory, "--list", "--json").stdout, candidates)
self.assertEqual(len(json.loads(candidates)), 55)
calls = self.recorded_calls()
self.assertTrue(all("--readonly" in call["arguments"] for call in calls))
for call in calls:
if call["arguments"][0] == "list":
self.assertIn("--limit=0", call["arguments"])
self.assertTrue(any("--status=deferred" in call["arguments"] for call in calls))
def test_status_view_shows_only_non_ready_tables(self) -> None:
date = "2026-01-01T00:00:00Z"
data = {
"ready": [issue("ready-task", 2, "task", date),
issue("elsewhere", 2, "task", date, labels=["run-on:nowhere"]),
issue("backlog-task", 4, "task", date)],
"in_progress": [issue("claimed", 2, "task", date)],
"deferred": [{**issue("snoozed", 3, "task", date), "defer_until": "2026-01-02T00:00:00Z"}],
}
workspace = self.create_workspace(repositories={
"repo-a": data,
"down": {"faults": {"ready": "dolt-down"}},
})
local = self.base / "local"
self.create_store(local, **data)
for directory, owner in ((workspace, "repo-a | "), (local, "")):
with self.subTest(workspace=bool(owner)):
self.assertIn("## Other machines", self.run_next(directory, "--list", "--backlog").stdout)
result = self.run_next(directory, "--status")
self.assertEqual(result.returncode, 0, result.stderr)
output = result.stdout
self.assertIn("## In Progress (1 beads; not selectable)", output)
self.assertIn("## Blocked (0 beads; not selectable)", output)
self.assertIn("## Deferred (1 beads; not selectable)", output)
self.assertIn("_None._", output)
self.assertIn(f"| {owner}claimed | P2 |", output)
self.assertIn("2026-01-02T00:00:00Z ⏰ elapsed", output)
self.assertEqual("| Repo |" in output, bool(owner))
for absent in ("## Ready to Work", "| # |", "## Backlog", "## Other machines",
"ready-task", "elsewhere", "backlog-task", "Pick a number"):
self.assertNotIn(absent, output)
self.assertEqual(self.run_next(directory, "--status", "--list", "--backlog").stdout, output)
self.assertEqual(self.run_next(directory, "--status", "--json").stdout,
self.run_next(directory, "--json").stdout)
if owner:
self.assertTrue(output.startswith("## ⚠️ Beads store unavailable (1)"), output)
self.assertIn("**down**", output)
calls = self.recorded_calls()
self.assertTrue(all("--readonly" in call["arguments"] for call in calls))
def test_full_listing_shows_empty_categories(self) -> None:
workspace = self.create_workspace()
local = self.base / "local"
self.create_store(local)
for directory in (workspace, local):
with self.subTest(directory=directory):
markdown = self.run_next(directory, "--list").stdout
self.assertIn("## Ready to Work (0 beads)", markdown)
for heading in ("In Progress", "Blocked", "Deferred"):
self.assertIn(f"## {heading} (0 beads; not selectable)", markdown)
self.assertEqual(markdown.count("_None._"), 3)
def test_full_listing_shows_backlog_when_ready_work_is_scarce(self) -> None:
backlog = issue("backlog-chore", 4, "chore", "2026-01-01T00:00:00Z")
backlog["updated_at"] = "2026-05-29T10:04:41Z"
data = {
"ready": [
issue("ready-task", 2, "task", "2026-01-02T00:00:00Z"),
backlog,
issue("blocked-p4", 4, "task", "2026-01-03T00:00:00Z"),
],
"blocked": [issue("blocked-p4", 4, "task", "2026-01-03T00:00:00Z")],
}
workspace = self.create_workspace(repositories={"repo-a": data})
local = self.base / "local"
self.create_store(local, **data)
for directory, owner in ((workspace, "repo-a | "), (local, "")):
with self.subTest(workspace=bool(owner)):
markdown = self.run_next(directory, "--list").stdout
self.assertIn("## Backlog (1 P4 beads; not auto-pickable, start by ID)", markdown)
self.assertIn("| Updated |", markdown)
self.assertIn(
f"| {owner}backlog-chore | P4 | chore | - | Title for backlog-chore | — | 2026-05-29 |",
markdown,
)
self.assertNotIn("| blocked-p4 | P4 | task | - | Title for blocked-p4 | — | 2026-01-03 |", markdown)
self.assertEqual(markdown.count("| # |"), 1)
candidates = json.loads(self.run_next(directory, "--list", "--json").stdout)
self.assertEqual([row["id"] for row in candidates], ["ready-task"])
def test_backlog_is_hidden_when_ready_work_is_plentiful_unless_requested(self) -> None:
local = self.base / "local"
self.create_store(
local,
ready=[
*(issue(f"ready-{index}", 2, "task", "2026-01-01T00:00:00Z") for index in range(3)),
issue("backlog-task", 4, "task", "2026-01-01T00:00:00Z"),
],
)
self.assertNotIn("## Backlog", self.run_next(local, "--list").stdout)
requested = self.run_next(local, "--list", "--backlog").stdout
self.assertIn("## Backlog (1 P4 beads; not auto-pickable, start by ID)", requested)
self.assertIn("| backlog-task | P4 |", requested)
empty = self.base / "empty"
self.create_store(empty)
self.assertNotIn("## Backlog", self.run_next(empty, "--list").stdout)
self.assertIn("## Backlog (0 P4 beads", self.run_next(empty, "--list", "--backlog").stdout)
def test_every_category_failure_discards_source_including_local(self) -> None:
categories = ("ready", "blocked", "in_progress", "deferred")
for category in categories:
for fault in ("error", "invalid-json"):
with self.subTest(category=category, fault=fault):
broken = {
key: [issue(f"unsafe-{key}", 0, "bug", "2026-01-01T00:00:00Z")]
for key in categories
}
broken["faults"] = {category: fault}
local = self.base / f"{category}-{fault}"
self.create_store(local, **broken)
result = self.run_next(local, "--list")
self.assertNotIn("unsafe-", result.stdout)
self.assertIn(f"local: {category}:", result.stdout)
result = self.run_next(local, "--json")
self.assertEqual(json.loads(result.stdout), [])
self.assertIn(f"local: {category}:", result.stderr)
workspace = self.create_workspace(
root_data={"ready": [issue("healthy", 2, "task", "2026-01-01T00:00:00Z")]},
repositories={"broken": broken},
)
for category in categories:
for fault in ("error", "invalid-json"):
with self.subTest(workspace=True, category=category, fault=fault):
broken["faults"] = {category: fault}
(self.base / "sources/broken/.beads/fixture.json").write_text(json.dumps(broken))
result = self.run_next(workspace, "--list")
self.assertIn("| workspace | healthy |", result.stdout)
self.assertNotIn("unsafe-", result.stdout)
self.assertIn(f"broken: {category}:", result.stdout)
result = self.run_next(workspace, "--json")
self.assertEqual([row["id"] for row in json.loads(result.stdout)], ["healthy"])
self.assertIn(f"broken: {category}:", result.stderr)
def test_full_listing_preserves_ready_index_resolution(self) -> None:
data = {
"ready": [
issue("task", 2, "task", "2026-01-01T00:00:00Z"),
issue("bug", 1, "bug", "2026-01-02T00:00:00Z"),
],
"in_progress": [issue("claimed", 0, "bug", "2026-01-01T00:00:00Z")],
"blocked": [issue("blocked", 0, "bug", "2026-01-01T00:00:00Z")],
"deferred": [issue("deferred", 0, "bug", "2026-01-01T00:00:00Z")],
}
workspace = self.create_workspace(repositories={"repo-a": data})
local = self.base / "local"
self.create_store(local, **data)
for directory, owner in ((workspace, "repo-a | "), (local, "")):
markdown = self.run_next(directory, "--list").stdout
for index, issue_id in enumerate(("bug", "task"), 1):
with self.subTest(directory=directory, index=index):
self.assertIn(f"| {index} | {owner}{issue_id} |", markdown)
result = self.run_script(
SKILL_DIR / "scripts/next-select", directory,
"resolve", str(index), "--expect-id", issue_id,
)
self.assertEqual(json.loads(result.stdout)["id"], issue_id)
def test_full_listings_show_ready_work_last(self) -> None:
agents = self.home / ".agents"
agents.mkdir()
(agents / "AGENTS.local.md").write_text("- Machine: Rivelino.\n", encoding="utf-8")
data = {
"ready": [
issue("ready-task", 2, "task", "2026-01-01T00:00:00Z"),
issue("elsewhere", 2, "task", "2026-01-01T00:00:00Z", labels=["run-on:leonidas"]),
issue("backlog-chore", 4, "chore", "2026-01-01T00:00:00Z"),
],
"in_progress": [issue("claimed", 2, "task", "2026-01-01T00:00:00Z")],
"blocked": [issue("blocked", 2, "task", "2026-01-01T00:00:00Z")],
"deferred": [issue("later", 3, "task", "2026-01-01T00:00:00Z")],
}
workspace = self.create_workspace(
root_data=data, repositories={"broken": {"faults": {"ready": "error"}}}
)
local = self.base / "local"
self.create_store(local, **data)
for directory, owner, notice in ((workspace, "workspace | ", ["## ⚠️ Beads store unavailable"]),
(local, "", [])):
for arguments in (("--list",), ("--list", "--backlog")):
with self.subTest(directory=directory, arguments=arguments):
output = self.run_next(directory, *arguments).stdout
headings = [line.split(" (")[0] for line in output.splitlines() if line.startswith("## ")]
self.assertEqual(headings, notice + ["## In Progress", "## Blocked", "## Deferred", "## Backlog",
"## Other machines", "## Ready to Work"])
head, tail = output.split("## Ready to Work (1 beads)", 1)
self.assertEqual("Source diagnostics:" in head, bool(notice))
if notice:
self.assertLess(head.index("## Backlog"), head.index("Source diagnostics:"))
self.assertLess(head.index("Source diagnostics:"), head.index("## Other machines"))
self.assertNotIn("## ", tail)
self.assertNotIn("Source diagnostics", tail)
self.assertTrue(output.rstrip("\n").endswith(
f"| 1 | {owner}ready-task | P2 | task | - | Title for ready-task | — |"), tail)
self.assertEqual(output.count("| # |"), 1)
with self.subTest(directory=directory, arguments="--safe"):
safe = self.run_next(directory, "--safe").stdout
headings = [line.split(" (")[0] for line in safe.splitlines() if line.startswith("## ")]
self.assertEqual(headings, notice + ["## Claimed — in progress", "## Waiting — blocked",
"## Later — deferred", "## Other machines", "## Ready to review"])
tail = safe.split("## Ready to review (1 beads)", 1)[1]
self.assertNotIn("## ", tail)
blocks = tail.strip("\n").split("\n\n")
self.assertEqual([block[:12] for block in blocks], ["| # | " + ("Repo |" if owner else "ID | P"),
"Lease check:", "Numbers are "])
compact = self.run_next(local).stdout
self.assertTrue(compact.startswith("Machine: rivelino"), compact[:80])
self.assertIn("## Ready to Work (1 beads)", compact.split("## Other machines", 1)[0])
def test_listing_instructions_require_all_sections(self) -> None:
skill = (SKILL_DIR / "SKILL.md").read_text()
listing = skill.split("## Listing Mode (default and `list`)", 1)[1].split("## Handling Edge Cases", 1)[0]
for required in ("next-bd --list", "all four sections", "in-progress, blocked, and deferred",
"_None._", "non-selectable", "never picker indexes",
"Backlog section", "--backlog", "Never list bead IDs in prose"):
self.assertIn(required, listing)
def test_status_instructions_are_read_only_without_picker(self) -> None:
skill = (SKILL_DIR / "SKILL.md").read_text()
self.assertIn("/next status", skill.split("## What This Skill Does", 1)[0])
status = skill.split("## Status Mode", 1)[1].split("\n## ", 1)[0]
for required in ("next-bd --status", "in-progress, blocked, and deferred", "_None._",
"Never mark", "no picker prompt"):
self.assertIn(required, status)
def test_non_ready_cells_cannot_split_markdown_rows(self) -> None:
local = self.base / "local"
row = issue("blocked", 2, "task", "2026-01-01T00:00:00Z")
row["title"] = "first | second\nthird"
row["blocked_by"] = ["dep|one", "dep\ntwo"]
self.create_store(local, blocked=[row])
markdown = self.run_next(local, "--list").stdout
self.assertIn("first | second third", markdown)
self.assertIn("dep|one, dep two", markdown)
def test_bug_filter_preserves_global_ranking(self) -> None:
workspace = self.create_workspace(
root_data={
"ready": [issue("root-bug", 3, "bug", "2026-01-01T00:00:00Z")]
},
repositories={
"repo-a": {
"ready": [issue("feature", 1, "feature", "2026-01-01T00:00:00Z")]
},
"repo-b": {
"ready": [issue("repo-bug", 2, "bug", "2026-01-02T00:00:00Z")]
},
},
)
candidates = json.loads(
self.run_next(workspace, "--json", "--type=bug").stdout
)
self.assertEqual(
[(candidate["repository"], candidate["id"]) for candidate in candidates],
[("repo-b", "repo-bug"), ("workspace", "root-bug")],
)
def test_invalid_workspace_lookalike_falls_back_to_root_store(self) -> None:
workspace = self.create_workspace(
root_data={
"ready": [issue("root-task", 2, "task", "2026-01-01T00:00:00Z")]
},
repositories={
"repo-a": {
"ready": [issue("repo-task", 1, "task", "2026-01-01T00:00:00Z")]
}
},
)
readme = workspace / "README.md"
valid_readme = readme.read_text(encoding="utf-8")
readme.write_text(valid_readme.replace("`repo-a`", "`other`", 1), encoding="utf-8")
candidates = json.loads(self.run_next(workspace, "--json").stdout)
self.assertEqual([candidate["id"] for candidate in candidates], ["root-task"])
self.assertNotIn("repository", candidates[0])
readme.write_text(valid_readme, encoding="utf-8")
agents = workspace / "AGENTS.md"
agents.unlink()
candidates = json.loads(self.run_next(workspace, "--json").stdout)
self.assertEqual([candidate["id"] for candidate in candidates], ["root-task"])
self.assertNotIn("repository", candidates[0])
agents.write_text("# Fixture agents\n", encoding="utf-8")
docs = workspace / "docs"
shutil.rmtree(docs)
docs_target = self.base / "docs-target"
for name in ("prds", "adrs", "architecture", "runbooks"):
(docs_target / name).mkdir(parents=True)
docs.symlink_to(os.path.relpath(docs_target, docs.parent), target_is_directory=True)
candidates = json.loads(self.run_next(workspace, "--json").stdout)
self.assertEqual([candidate["id"] for candidate in candidates], ["root-task"])
self.assertNotIn("repository", candidates[0])
def test_failing_source_keeps_healthy_candidates_and_reports_diagnostic(self) -> None:
workspace = self.create_workspace(
root_data={
"ready": [issue("root-task", 2, "task", "2026-01-01T00:00:00Z")]
},
repositories={
"healthy": {
"ready": [issue("healthy-task", 1, "task", "2026-01-01T00:00:00Z")]
},
"broken": {
"ready": [issue("hidden-task", 0, "bug", "2026-01-01T00:00:00Z")],
"faults": {"ready": "error"},
},
},
)
result = self.run_next(workspace, "--json")
candidates = json.loads(result.stdout)
self.assertEqual(
[(candidate["repository"], candidate["id"]) for candidate in candidates],
[("healthy", "healthy-task"), ("workspace", "root-task")],
)
self.assertIn("next-bd: broken: ready: simulated ready failure", result.stderr)
calls = self.recorded_calls()
self.assertTrue(all("--readonly" in call["arguments"] for call in calls))
self.assertFalse(any(call["arguments"][0] == "update" for call in calls))
def test_unavailable_store_notice_leads_every_text_view(self) -> None:
workspace = self.create_workspace(
root_data={"ready": [issue("root-task", 2, "task", "2026-01-01T00:00:00Z")]},
repositories={
"down": {"ready": [issue("hidden-task", 0, "bug", "2026-01-01T00:00:00Z")],
"faults": {"ready": "dolt-down"}},
"broken": {"faults": {"blocked": "error"}},
"healthy": {},
},
)
packet = json.loads(self.run_next(workspace, "--safe-json").stdout)
stores = {entry["repository"]: entry for entry in packet["unavailable_stores"]}
self.assertEqual(set(stores), {"down", "broken"})
self.assertIn("dolt start", stores["down"]["hint"])
self.assertIn("bd -C ", stores["down"]["hint"])
self.assertIn("down", stores["down"]["hint"])
self.assertIn("/next recover down", stores["down"]["hint"])
self.assertIn("eligibility", stores["down"]["hint"])
self.assertIn("confirmation", stores["down"]["hint"])
self.assertIsNone(stores["broken"]["hint"])
self.assertEqual(stores["broken"]["reason"], "blocked: simulated blocked failure")
for arguments, heading in ((("--list",), "## Ready to Work"), ((), "## Ready to Work"),
(("--in-progress",), "## Ready to Work"), (("--safe",), "## Ready to review")):
with self.subTest(arguments=arguments):
output = self.run_next(workspace, *arguments).stdout
notice, rest = output.split(heading, 1)
self.assertIn("## ⚠️ Beads store unavailable (2)", notice)
self.assertIn("not an empty backlog", notice)
self.assertIn("**down**", notice)
self.assertIn("dolt start", notice)
self.assertIn("**broken** — blocked: simulated blocked failure", notice)
self.assertNotIn("healthy", notice)
self.assertNotIn("root-task", notice)
self.assertIn("root-task", rest)
self.assertNotIn("hidden-task", output)
safe = self.run_next(workspace, "--safe").stdout
self.assertIn("Lease check: 0 free, 1 not checked", safe)
candidates = json.loads(self.run_next(workspace, "--json").stdout)
self.assertEqual([row["id"] for row in candidates], ["root-task"])
calls = self.recorded_calls()
self.assertTrue(all("--readonly" in call["arguments"] for call in calls))
self.assertFalse(any("dolt" in call["arguments"] for call in calls))
def test_all_stores_unavailable_is_not_presented_as_empty_work(self) -> None:
local = self.base / "down"
self.create_store(local, ready=[issue("hidden", 2, "task", "2026-01-01T00:00:00Z")],
faults={"ready": "dolt-down"})
safe = self.run_next(local, "--safe").stdout
self.assertTrue(safe.startswith("## ⚠️ Beads store unavailable (1)"), safe)
self.assertIn("**local**", safe)
self.assertIn("/next recover local", safe)
self.assertIn("dolt start", safe)
self.assertNotIn("_No candidates without", safe)
self.assertNotIn("Lease check: 0 free, 0 not checked", safe)
self.assertIn("Ready work unknown", safe)
self.assertIn("Source diagnostics:", safe)
listing = self.run_next(local, "--list").stdout
self.assertTrue(listing.startswith("## ⚠️ Beads store unavailable (1)"), listing)
self.assertNotIn("hidden", listing)
healthy = self.base / "healthy"
self.create_store(healthy)
for arguments in (("--safe",), ("--list",)):
output = self.run_next(healthy, *arguments).stdout
self.assertNotIn("Beads store unavailable", output)
self.assertEqual(json.loads(self.run_next(healthy, "--safe-json").stdout)["unavailable_stores"], [])
def test_late_source_failure_discards_its_partial_results(self) -> None:
workspace = self.create_workspace(
root_data={
"ready": [issue("root-task", 2, "task", "2026-01-01T00:00:00Z")]
},
repositories={
"broken": {
"ready": [issue("unsafe-task", 0, "bug", "2026-01-01T00:00:00Z")],
"faults": {"blocked": "error"},
}
},
)
result = self.run_next(workspace, "--json")
self.assertEqual(
[candidate["id"] for candidate in json.loads(result.stdout)],
["root-task"],
)
self.assertIn("broken: blocked: simulated blocked failure", result.stderr)
def test_malformed_and_unusable_sources_have_concise_diagnostics(self) -> None:
workspace = self.create_workspace(
root_data={
"ready": [issue("root-task", 2, "task", "2026-01-01T00:00:00Z")]
},
repositories={
"malformed": {"faults": {"ready": "invalid-json"}},
"missing": {},
"symlinked": {},
},
)
shutil.rmtree(self.base / "sources" / "missing" / ".beads")
symlinked = self.base / "sources" / "symlinked" / ".beads"
shutil.rmtree(symlinked)
symlinked.symlink_to(self.base / "external-beads", target_is_directory=True)
result = self.run_next(workspace)
self.assertIn("workspace | root-task", result.stdout)
self.assertIn("malformed: ready: invalid bd JSON", result.stdout)
self.assertIn("missing: missing .beads store", result.stdout)
self.assertIn("symlinked: unusable .beads store: symlink", result.stdout)
def test_timed_out_source_is_reported_without_hiding_healthy_source(self) -> None:
spec = importlib.util.spec_from_file_location(
"next_collect_test", SKILL_DIR / "scripts" / "collect.py"
)
collector = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = collector
spec.loader.exec_module(collector)
source = collector.Source("slow", "repos/slow", self.base / "slow")
with mock.patch.object(
collector.subprocess,
"run",
side_effect=subprocess.TimeoutExpired(["bd"], 60),
):
issues, error = collector.load_issues(source, ["list", "--ready"])
self.assertEqual(issues, [])
self.assertRegex(error, r"Beads read timed out \(elapsed [0-9.]+s, deadline 60s;")
workspace = self.create_workspace(
repositories={"healthy": {}, "slow": {}}
)
def load_fixture(
source: Any, arguments: list[str]
) -> tuple[list[dict[str, Any]], str | None]:
if source.name == "slow":
return [], error
if "--ready" in arguments and source.name == "healthy":
return [issue("healthy-task", 1, "task", "2026-01-01T00:00:00Z")], None
return [], None
with mock.patch.object(collector, "load_issues", side_effect=load_fixture):
payload = collector.collect(workspace)
self.assertEqual([item["id"] for item in payload["ready"]], ["healthy-task"])
self.assertEqual(
payload["diagnostics"], [f"slow: ready: {error}"]
)
def test_declared_workspace_store_is_not_queried_or_duplicated(self) -> None:
workspace = self.create_workspace(
root_data={"ready": [issue("root-task", 2, "task", "2026-01-01T00:00:00Z")]},
repositories={
"delegated": {}, "missing": {},
"healthy": {"ready": [issue("member-task", 2, "task", "2026-01-01T00:00:00Z")]},
},
)
self.declare_tracking(workspace, delegated="workspace", missing="local", healthy="local")
for name in ("delegated", "missing"):
shutil.rmtree(self.base / "sources" / name / ".beads")
result = self.run_next(workspace, "--json")
candidates = json.loads(result.stdout)
self.assertEqual(
{(row["repository"], row["id"]) for row in candidates},
{("workspace", "root-task"), ("healthy", "member-task")},
)
self.assertEqual(len(candidates), 2)
self.assertIn("missing: missing .beads store", result.stderr)
self.assertNotIn("delegated", result.stderr)
calls = self.recorded_calls()
self.assertEqual(sum(Path(call["directory"]) == workspace.resolve() for call in calls), 4)
self.assertEqual(len(calls), 8)
self.assertTrue(all("--readonly" in call["arguments"] for call in calls))
def test_invalid_ownership_does_not_fall_back_to_root_local_mode(self) -> None:
workspace = self.create_workspace(
root_data={"ready": [issue("root-task", 2, "task", "2026-01-01T00:00:00Z")]},
repositories={"invalid": {}},
)
for value in (None, True, [], {}, "", "WORKSPACE", "central"):
with self.subTest(value=value):
self.declare_tracking(workspace, invalid=value)
result = self.run_next(workspace, "--json")
self.assertEqual(json.loads(result.stdout)[0]["repository"], "workspace")
self.assertIn("invalid: invalid beadsStore declaration", result.stderr)
self.assertTrue(all(Path(call["directory"]) == workspace.resolve() for call in self.recorded_calls()))
def test_workspace_ownership_conflicts_remain_visible_without_queries(self) -> None:
workspace = self.create_workspace(repositories={"delegated": {}})
self.declare_tracking(workspace, delegated="workspace")
beads = self.base / "sources" / "delegated" / ".beads"
for kind in ("directory", "file", "symlink"):
with self.subTest(kind=kind):
if kind == "file":
shutil.rmtree(beads)
beads.write_text("not a store", encoding="utf-8")
elif kind == "symlink":
beads.unlink()
beads.symlink_to(self.base / "absent-target")
result = self.run_next(workspace, "--list")
self.assertIn("delegated: unexpected .beads store for workspace-owned repository", result.stdout)
self.assertTrue(all(Path(call["directory"]) == workspace.resolve() for call in self.recorded_calls()))
def test_explicit_local_stores_preserve_error_diagnostics(self) -> None:
workspace = self.create_workspace(repositories={
"malformed": {"faults": {"ready": "invalid-json"}},
"missing": {}, "symlinked": {},
})
self.declare_tracking(workspace, malformed="local", missing="local", symlinked="local")
for name in ("missing", "symlinked"):
shutil.rmtree(self.base / "sources" / name / ".beads")
(self.base / "sources" / "symlinked" / ".beads").symlink_to(self.base / "absent")
result = self.run_next(workspace, "--list")
self.assertIn("malformed: ready: invalid bd JSON", result.stdout)
self.assertIn("missing: missing .beads store", result.stdout)
self.assertIn("symlinked: unusable .beads store: symlink", result.stdout)
def test_single_store_output_remains_compatible(self) -> None:
local = self.base / "local"
self.create_store(
local,
ready=[issue("local-task", 2, "task", "2026-01-01T00:00:00Z")],
in_progress=[
issue("local-claimed", 2, "bug", "2026-01-02T00:00:00Z")
],
)
candidates = json.loads(self.run_next(local, "--json").stdout)
self.assertEqual(candidates[0]["id"], "local-task")
self.assertEqual(candidates[0]["rank"], 10)
self.assertNotIn("repository", candidates[0])
self.assertNotIn("repository_path", candidates[0])
self.assertNotIn("selector", candidates[0])
markdown = self.run_next(local, "--in-progress").stdout
self.assertIn("| # | ID | Pri | Type | Labels | Title | Parent |", markdown)
self.assertNotIn("| Repo |", markdown)
self.assertIn(
"Tracker status: in progress (session activity unverified):", markdown
)
self.assertNotIn("other sessions", markdown)
self.assertIn('`local-claimed` (P2 bug)', markdown)
if __name__ == "__main__":
unittest.main()
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |