Skip to content
Open
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: 4 additions & 0 deletions code_review_graph/skills.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ def generate_hooks_config(repo_root: Path) -> dict[str, Any]:
{
"type": "command",
"command": (
"cat >/dev/null || true; "
"git rev-parse --git-dir >/dev/null 2>&1"
f" && code-review-graph update --skip-flows"
f" --repo {repo_arg}"
Expand All @@ -577,6 +578,7 @@ def generate_hooks_config(repo_root: Path) -> dict[str, Any]:
{
"type": "command",
"command": (
"cat >/dev/null || true; "
"git rev-parse --git-dir >/dev/null 2>&1"
f" && code-review-graph status --repo {repo_arg}"
" || echo 'Not a git repo, skipping'"
Expand All @@ -601,6 +603,7 @@ def generate_codex_hooks_config(repo_root: Path) -> dict[str, Any]:
{
"type": "command",
"command": (
"cat >/dev/null || true; "
"git rev-parse --git-dir >/dev/null 2>&1"
" && code-review-graph update --skip-flows"
" || true"
Expand All @@ -618,6 +621,7 @@ def generate_codex_hooks_config(repo_root: Path) -> dict[str, Any]:
{
"type": "command",
"command": (
"cat >/dev/null || true; "
"git rev-parse --git-dir >/dev/null 2>&1"
" && code-review-graph status"
" || echo 'Not a git repo, skipping'"
Expand Down
33 changes: 33 additions & 0 deletions tests/test_skills.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
import os
import subprocess
import stat
import sys
from pathlib import Path
Expand Down Expand Up @@ -121,6 +122,7 @@ def test_has_post_tool_use(self):
inner = entry["hooks"][0]
assert inner["type"] == "command"
assert "update" in inner["command"]
assert inner["command"].startswith("cat >/dev/null || true; ")
assert 0 < inner["timeout"] <= 600

def test_has_session_start(self):
Expand All @@ -131,6 +133,7 @@ def test_has_session_start(self):
inner = entry["hooks"][0]
assert inner["type"] == "command"
assert "status" in inner["command"]
assert inner["command"].startswith("cat >/dev/null || true; ")
assert 0 < inner["timeout"] <= 600

def test_does_not_emit_invalid_pre_commit_hook(self):
Expand Down Expand Up @@ -278,6 +281,7 @@ def test_has_post_tool_use(self, tmp_path):
inner = entry["hooks"][0]
assert inner["type"] == "command"
assert "update" in inner["command"]
assert inner["command"].startswith("cat >/dev/null || true; ")
assert inner["statusMessage"] == "Updating code-review-graph"

def test_has_session_start(self, tmp_path):
Expand All @@ -288,8 +292,37 @@ def test_has_session_start(self, tmp_path):
inner = entry["hooks"][0]
assert inner["type"] == "command"
assert "status" in inner["command"]
assert inner["command"].startswith("cat >/dev/null || true; ")
assert inner["statusMessage"] == "Checking code-review-graph status"


def test_post_tool_use_command_handles_large_stdin_payload(self, tmp_path):
config = generate_codex_hooks_config(tmp_path)
cmd = config["hooks"]["PostToolUse"][0]["hooks"][0]["command"]

payload = ("x" * 1024 + "\n") * 20000
proc = subprocess.Popen(
["bash", "-lc", cmd],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
cwd=tmp_path,
)

broken_pipe = None
try:
assert proc.stdin is not None
proc.stdin.write(payload)
proc.stdin.close()
except BrokenPipeError as exc: # pragma: no cover - regression guard
broken_pipe = exc

proc.stdin = None
stdout, stderr = proc.communicate()
assert broken_pipe is None, f"hook command raised BrokenPipeError: {stderr}"
assert proc.returncode == 0, stderr

def test_commands_do_not_pin_a_specific_repo_path(self, tmp_path):
config = generate_codex_hooks_config(tmp_path / "repo with spaces")
post_cmd = config["hooks"]["PostToolUse"][0]["hooks"][0]["command"]
Expand Down