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
13 changes: 11 additions & 2 deletions clerk/legacy/clerk.bash
Original file line number Diff line number Diff line change
Expand Up @@ -643,10 +643,19 @@ cmd_capture() {
fi
# mutation self-verify (ADR 0015): confirm the id landed before declaring success
local seen
seen=$(bd show "$id" --readonly --json 2>/dev/null | jq -r '.[0].id // empty')
if [ "$seen" != "$id" ]; then
seen=$(bd show "$id" --readonly --json 2>/dev/null | jq -c '.[0] // empty')
if [ "$(jq -r '.id // empty' <<<"$seen")" != "$id" ]; then
backend_fail "capture failed — $id was not confirmed after creation"
fi
if [ "$(jq -r '(.labels // []) | index("stage:ready") != null' <<<"$seen")" = true ]; then
if ! bd update "$id" --remove-label stage:ready >/dev/null; then
backend_fail "capture failed — $id could not be restored to the Inbox"
fi
seen=$(bd show "$id" --readonly --json 2>/dev/null | jq -c '.[0] // empty')
if [ "$(jq -r '.id // empty' <<<"$seen")" != "$id" ] || [ "$(jq -r '(.labels // []) | index("stage:ready") != null' <<<"$seen")" = true ]; then
backend_fail "capture failed — $id remained ready after creation"
fi
fi
if [ "$issue_type" = impediment ]; then
printf '%sclerk:%s filed %s (type: impediment)\n' "$C_GRN" "$C_RST" "$id"
else
Expand Down
11 changes: 10 additions & 1 deletion clerk/src/clerk/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,8 @@ def cmd_capture(backend: str, _root: Path, argv: Sequence[str], runner: CommandR
if parent and parent_id(blocker_json) != parent:
usage(f"clerk capture: --blocked-by {blocker} must be a sibling under {parent}")

result = BdWorkGraphAdapter(runner).create(
graph = BdWorkGraphAdapter(runner)
result = graph.create(
title,
use_stdin=use_stdin,
issue_type=issue_type,
Expand All @@ -600,6 +601,14 @@ def cmd_capture(backend: str, _root: Path, argv: Sequence[str], runner: CommandR
seen = _bd_issue_json_or_backend(runner, id_, f"capture failed — {id_} was not confirmed after creation")
if seen.get("id") != id_:
backend_fail(f"capture failed — {id_} was not confirmed after creation")
if _is_ready_promoted(seen):
result = graph.remove_ready_label(id_)
_emit_stderr(result)
if result.returncode != 0:
backend_fail(f"capture failed — {id_} could not be restored to the Inbox")
seen = _bd_issue_json_or_backend(runner, id_, f"capture failed — {id_} was not confirmed after restoring it to the Inbox")
if seen.get("id") != id_ or _is_ready_promoted(seen):
backend_fail(f"capture failed — {id_} remained ready after creation")
suffix = " (type: impediment)" if issue_type == "impediment" else ""
_success(f"filed {id_}{suffix}", env)
return 0
Expand Down
3 changes: 3 additions & 0 deletions clerk/src/clerk/work_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ def create(self, title: str, *, use_stdin: bool = False, issue_type: str = "", p
args.extend(["--deps", blocker])
return self._runner.run(args)

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

def set_parent(self, child: str, parent: str) -> CommandResult:
return self._runner.run(["bd", "update", child, "--parent", parent])

Expand Down
73 changes: 60 additions & 13 deletions tests/clerk/inbox-graph.bats
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ make_bd_repo() {
[ "$(jq -r '.[0].issue_type' <<<"$json")" = decision ]
[ "$(jq -r '.[0].parent' <<<"$json")" = "$parent" ]
jq -e --arg blocker "$blocker" '.[0].dependencies | any(.dependency_type == "blocks" and .id == $blocker)' <<<"$json" >/dev/null
[ "$(jq -r '.[0].labels | index("stage:ready")' <<<"$json")" = null ]

run "$CLERK" capture "bad" --impediment --type task
[ "$status" -eq 2 ]
Expand All @@ -53,20 +54,66 @@ make_bd_repo() {
[ "$(bd show "$custom" --readonly --json | jq -r '.[0].issue_type')" = research ]
}

@test "capture can add children under a ready parent and depend on a ready sibling" {
repo=$(make_bd_repo capture_ready_parent)
cd "$repo"
parent=$(bd create "ready parent" --acceptance "parent ac" --silent)
ready_sibling=$(bd create "ready sibling" --parent "$parent" --acceptance "sibling ac" --silent)
"$CLERK" inbox ready "$parent" >/dev/null
"$CLERK" inbox ready "$ready_sibling" >/dev/null
@test "capture keeps a child of ready Work in the Inbox in both command paths" {
for force_legacy in 0 1; do
repo=$(make_bd_repo "capture_ready_parent_$force_legacy")
cd "$repo"
parent=$(bd create "ready parent" --acceptance "parent ac" --silent)
"$CLERK" inbox ready "$parent" >/dev/null

if [ "$force_legacy" -eq 1 ]; then
run env CLERK_FORCE_LEGACY=1 "$CLERK" capture "new child" --parent "$parent"
else
run "$CLERK" capture "new child" --parent "$parent"
fi
[ "$status" -eq 0 ]
child="${output#clerk: filed }"
json=$(bd show "$child" --readonly --json)
[ "$(jq -r '.[0].parent' <<<"$json")" = "$parent" ]
[ "$(jq -r '.[0].labels | index("stage:ready")' <<<"$json")" = null ]

if [ "$force_legacy" -eq 1 ]; then
run env CLERK_FORCE_LEGACY=1 "$CLERK" backlog next
else
run "$CLERK" backlog next
fi
[ "$status" -eq 0 ]
[[ "$output" != *"$child"* ]]

printf 'child design\n' >"$repo/design"
printf '%s\n' '- child acceptance' >"$repo/acceptance"
if [ "$force_legacy" -eq 1 ]; then
run env CLERK_FORCE_LEGACY=1 "$CLERK" inbox ready "$child" --design-file "$repo/design" --acceptance-file "$repo/acceptance"
else
run "$CLERK" inbox ready "$child" --design-file "$repo/design" --acceptance-file "$repo/acceptance"
fi
[ "$status" -eq 0 ]
json=$(bd show "$child" --readonly --json)
[ "$(jq -r '.[0].labels | index("stage:ready")' <<<"$json")" != null ]
done
}

run "$CLERK" capture "new blocked child" --parent "$parent" --blocked-by "$ready_sibling"
[ "$status" -eq 0 ]
child="${output#clerk: filed }"
json=$(bd show "$child" --readonly --json)
[ "$(jq -r '.[0].parent' <<<"$json")" = "$parent" ]
jq -e --arg blocker "$ready_sibling" '.[0].dependencies | any(.dependency_type == "blocks" and .id == $blocker)' <<<"$json" >/dev/null
@test "capture preserves ready-parent sibling blockers in both command paths" {
for force_legacy in 0 1; do
repo=$(make_bd_repo "capture_ready_parent_blocked_$force_legacy")
cd "$repo"
parent=$(bd create "ready parent" --acceptance "parent ac" --silent)
ready_sibling=$(bd create "ready sibling" --parent "$parent" --acceptance "sibling ac" --silent)
"$CLERK" inbox ready "$parent" >/dev/null
"$CLERK" inbox ready "$ready_sibling" >/dev/null

if [ "$force_legacy" -eq 1 ]; then
run env CLERK_FORCE_LEGACY=1 "$CLERK" capture "new blocked child" --parent "$parent" --blocked-by "$ready_sibling"
else
run "$CLERK" capture "new blocked child" --parent "$parent" --blocked-by "$ready_sibling"
fi
[ "$status" -eq 0 ]
child="${output#clerk: filed }"
json=$(bd show "$child" --readonly --json)
[ "$(jq -r '.[0].parent' <<<"$json")" = "$parent" ]
jq -e --arg blocker "$ready_sibling" '.[0].dependencies | any(.dependency_type == "blocks" and .id == $blocker)' <<<"$json" >/dev/null
[ "$(jq -r '.[0].labels | index("stage:ready")' <<<"$json")" = null ]
done
}

@test "children/frontier/blockers/blocked return normalized JSON and frontier only open unblocked unclaimed direct children" {
Expand Down
21 changes: 21 additions & 0 deletions tests/clerk_python/test_text_mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,27 @@ def test_capture_files_bd_capture_with_parent_blockers_type_and_stdin_then_self_
["bd", "show", "dotfiles-new", "--readonly", "--json"],
])

def test_capture_removes_a_ready_label_inherited_from_its_parent_before_success(self):
parent = [{"id": "p", "status": "open", "labels": ["stage:ready"]}]
inherited_ready = [{"id": "dotfiles-new", "status": "open", "parent": "p", "labels": ["stage:ready"]}]
inbox_child = [{"id": "dotfiles-new", "status": "open", "parent": "p", "labels": []}]
code, out, err, calls = self.invoke(
("capture",),
["title", "--parent", "p"],
[
lambda args: ok(args, json.dumps(parent)),
lambda args: ok(args, "dotfiles-new\n"),
lambda args: ok(args, json.dumps(inherited_ready)),
lambda args: ok(args),
lambda args: ok(args, json.dumps(inbox_child)),
],
)
self.assertEqual((code, out, err), (0, "clerk: filed dotfiles-new\n", ""))
self.assertEqual(calls[-2:], [
["bd", "update", "dotfiles-new", "--remove-label", "stage:ready"],
["bd", "show", "dotfiles-new", "--readonly", "--json"],
])

def test_capture_failed_self_verification_is_backend_failure_without_success_output(self):
code, out, err, calls = self.invoke(
("capture",),
Expand Down
Loading