utils/todo_hooks/tests/_closer_helpers.py
Krzysztof kuhy Rudnicki aec96eefd3 Add todo_hooks closer, drift sweep, PR import
Python 3.14 stdlib package wiring git to the todo MCP server:
- closer (post-commit): runs the done_check of each Todo: trailer
  task and close_task's it only on exit 0. It FAILS OPEN: the commit
  already happened, so a down server, bad token or no gh prints one
  warning and exits 0 instead of failing the hook.
- sweep: nightly drift report (systemd units shipped, not enabled).
- import-pr: a merged PR's '## Todo:' items become tasks, deduped.
- A done_check runs only if its sha256 is in
  ~/.config/todo-hooks/trusted-checks; 'Check: manual' notes are
  never auto-closed.
- Hooks exposed in .pre-commit-hooks.yaml (post-commit, post-merge,
  post-rewrite).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 12:24:29 +01:00

37 lines
1019 B
Python

"""Setup shared by the closer tests."""
from __future__ import annotations
from typing import TYPE_CHECKING
from todo_hooks.trust import add_trusted
if TYPE_CHECKING:
from collections.abc import Callable
from pathlib import Path
from todo_hooks.context import Context
from todo_hooks.paths import Paths
from todo_hooks.tests._fakes import FakeClient
ID = "0123abcd-0000-4000-8000-000000000001"
ID2 = "4567ef01-0000-4000-8000-000000000002"
MSG = "feat: x\n\nTodo: 0123abcd"
def setup( # noqa: PLR0913
make_repo: Callable[..., Path],
make_ctx: Callable[..., tuple[Context, list[str]]],
paths: Paths,
client: FakeClient,
*,
check: str | None = "true",
trust: bool = True,
message: str = MSG,
) -> tuple[Path, Context, list[str]]:
root = make_repo("demo", origin="git@github.com:kuhyx/demo.git", message=message)
if trust and check:
add_trusted(paths.trust_file, check, "test")
ctx, lines = make_ctx(client, root)
return root, ctx, lines