Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clerk/src/clerk/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

# The Python core owns diagnostics, help/explain/version, manifest gating,
# doctor, read-only item query windows, Capture/text-based Inbox mutations,
# Planning graph mutations/claims, and the Inbox ready/drop bridge.
# Unported workflow verb bodies remain on the shell fallback for this slice.
# Planning graph mutations/claims, the Inbox ready/drop bridge, and the Backlog
# Claim lifecycle. Unported workflow verb bodies remain on the shell fallback.
PYTHON_QUERY_VERBS: frozenset[tuple[str, ...]] = frozenset(QUERY_HANDLERS)
PYTHON_MUTATION_VERBS: frozenset[tuple[str, ...]] = frozenset(MUTATION_HANDLERS)
PYTHON_PROJECT_GATE_VERBS: frozenset[tuple[str, ...]] = frozenset({("backlog", "submit"), ("backlog", "gate")})
Expand Down
359 changes: 359 additions & 0 deletions clerk/src/clerk/commands.py

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions clerk/src/clerk/ownership.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

This slice moves Clerk's command-boundary diagnostics, read-only item query
windows, Capture/text-based Inbox mutations, Planning graph mutations/claims,
and the Inbox ready/drop bridge to Python while leaving delivery workflow verb
bodies on the legacy shell fallback. Ownership is therefore split: Python owns
global help/explain/version, manifest gating, doctor, and the explicit command
tables; unported workflow mutations are exec'd into the fallback after the
Python gate accepts them.
the Inbox ready/drop bridge, and the Backlog Claim lifecycle to Python while
leaving later delivery workflow verb bodies on the legacy shell fallback.
Ownership is therefore split: Python owns global help/explain/version, manifest
gating, doctor, and the explicit command tables; unported workflow mutations
are exec'd into the fallback after the Python gate accepts them.
"""

from __future__ import annotations
Expand Down
4 changes: 4 additions & 0 deletions clerk/src/clerk/proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def run(
cwd: str | Path | None = None,
env: Mapping[str, str] | None = None,
input: str | None = None,
timeout: float | None = None,
) -> CommandResult:
try:
proc = subprocess.run(
Expand All @@ -37,7 +38,10 @@ def run(
stderr=subprocess.PIPE,
text=True,
check=False,
timeout=timeout,
)
except FileNotFoundError as exc:
return CommandResult(tuple(args), 127, "", str(exc))
except subprocess.TimeoutExpired as exc:
return CommandResult(tuple(args), 124, exc.stdout or "", exc.stderr or "")
return CommandResult(tuple(args), proc.returncode, proc.stdout, proc.stderr)
19 changes: 17 additions & 2 deletions clerk/src/clerk/work_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ def load(self) -> WorkGraph:
def backlog(self) -> Backlog:
return self.load().backlog()

def _inspect(self, id_: str) -> dict[str, Any]:
result = self._runner.run(["bd", "show", id_, "--readonly", "--json"])
def _inspect(self, id_: str, *, cwd: str | None = None) -> dict[str, Any]:
result = self._runner.run(["bd", "show", id_, "--readonly", "--json"], cwd=cwd)
if result.returncode != 0:
raise WorkGraphBackendError(f"bd show did not succeed for {id_}", result)
try:
Expand All @@ -287,6 +287,9 @@ def close(self, id_: str, reason: str) -> CommandResult:
def inspect(self, id_: str) -> dict[str, Any]:
return self._inspect(id_)

def inspect_at(self, id_: str, cwd: str) -> dict[str, Any]:
return self._inspect(id_, cwd=cwd)

def parent_cycle_would_form(self, child: str, parent: str) -> bool:
seen: set[str] = set()
current = parent
Expand Down Expand Up @@ -342,3 +345,15 @@ def add_blocker(self, child: str, blocker: str) -> CommandResult:

def remove_blocker(self, child: str, blocker: str) -> CommandResult:
return self._runner.run(["bd", "dep", "remove", child, blocker])

def claim(self, id_: str) -> CommandResult:
return self._runner.run(["bd", "update", id_, "--claim"])

def release(self, id_: str) -> CommandResult:
return self._runner.run(["bd", "update", id_, "--status", "open", "--assignee", ""])

def return_to_inbox(self, id_: str) -> CommandResult:
return self._runner.run(["bd", "update", id_, "--status", "open", "--remove-label", "stage:ready", "--assignee", ""])

def create_impediment(self, title: str, body: str) -> CommandResult:
return self._runner.run(["bd", "create", title, "--description", body, "--type", "impediment", "--silent"])
21 changes: 9 additions & 12 deletions tests/clerk/claim.bats
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,19 @@ advance_main() { # $1=repo $2=file $3=content $4=subject
id=$(mk_ac_unit "bootstrap failure unit")
short="${id#*-}"
fake="$BATS_TEST_TMPDIR/fake-bin"
real_python=$(command -v python3)
mkdir -p "$fake"
cat >"$fake/bd" <<'EOF'
#!/bin/sh
if [ "$1" = bootstrap ]; then
/bin/cp "$BEADS_TEST_METADATA" .beads/metadata.json
exit 0
cat >"$fake/python" <<EOF
#!/usr/bin/env bash
if [ "\$1" = - ]; then
exec "$real_python" "\$@"
fi
exec /usr/local/bin/bd "$@"
shift 2
exec "$real_python" -c 'import shutil, sys; shutil.copyfile = lambda *_: (_ for _ in ()).throw(OSError()); from clerk.cli import main; raise SystemExit(main(sys.argv[1:]))' "\$@"
EOF
cat >"$fake/cp" <<'EOF'
#!/bin/sh
exit 1
EOF
chmod +x "$fake/bd" "$fake/cp"
chmod +x "$fake/python"

run env PATH="$fake:$PATH" BEADS_TEST_METADATA="$repo/.beads/metadata.json" "$CLERK" backlog claim "$id"
run env CLERK_PYTHON="$fake/python" "$CLERK" backlog claim "$id"
[ "$status" -eq 5 ]
[[ "$output" == *"could not provision or verify the worktree"* ]]
[[ "$output" != *"worktree ready"* ]]
Expand Down
18 changes: 18 additions & 0 deletions tests/clerk/release-return.bats
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,24 @@ break_origin() { # $1 = repo
[ "$(jq -r '(.[0].labels // []) | index("stage:ready")' <<<"$json")" != null ]
}

@test "release (bd): running from inside the delivery worktree tears down the primary checkout claim" {
repo=$(make_claim_repo rel_from_worktree)
cd "$repo"
id=$(mk_ready_unit "release from worktree unit")
short="${id#*-}"
"$CLERK" backlog claim "$id" >/dev/null
wt="$repo/.worktrees/$short"

cd "$wt"
run "$CLERK" backlog release "$id"
[ "$status" -eq 0 ]
[ ! -d "$wt" ]
! git -C "$repo" show-ref --verify --quiet "refs/heads/delivery/$short"
git -C "$repo" fetch -q origin
! git -C "$repo" show-ref --verify --quiet "refs/remotes/origin/delivery/$short"
[ "$(bd -C "$repo" show "$id" --readonly --json | jq -r '.[0].status')" = open ]
}

@test "release (bd): a branch with commits beyond main is refused, exit 2, branch and worktree left intact" {
repo=$(make_claim_repo rel_work)
cd "$repo"
Expand Down
10 changes: 7 additions & 3 deletions tests/clerk_python/test_ownership.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ def test_text_and_graph_mutation_verbs_are_python_owned(self):
with self.subTest(argv=argv):
self.assertTrue(is_python_owned(argv))

def test_unported_workflow_verb_bodies_still_route_to_legacy_fallback(self):
def test_delivery_claim_lifecycle_is_python_owned(self):
for argv in (
["backlog", "claim", "dotfiles-123"],
["glean"],
["backlog", "release", "dotfiles-123"],
["backlog", "return", "dotfiles-123", "--reason", "blocked"],
):
with self.subTest(argv=argv):
self.assertFalse(is_python_owned(argv))
self.assertTrue(is_python_owned(argv))

def test_unported_workflow_verbs_still_route_to_legacy_fallback(self):
self.assertFalse(is_python_owned(["glean"]))

def test_public_verb_path_identifies_roster_paths_without_validating_args(self):
self.assertEqual(public_verb_path(["backlog", "claim", "dotfiles-123"]), ("backlog", "claim"))
Expand Down
Loading