Files
docs-review/tests/fake_claude.py
T
jaredandClaude Opus 5.5 9dea56ce98
tests / unittest (push) Successful in 23s
feat: review_only input and an enumeration check in the monthly prompt
review_only names listed documents the drafter may read but not edit. They stay
in stage 1, are listed separately in the prompt, and a change to one fails the
run like a change outside docs. Each entry must match a docs pattern.

The monthly prompt now makes checking every list and count in the top-level
documents against the repository the drafter's main job. Mode-specific text
moves to prompts/mode-pr.md and prompts/mode-monthly.md; the pr text is
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 15:40:09 -05:00

61 lines
2.5 KiB
Python
Executable File

#!/usr/bin/env python3
"""Stand-in for the claude binary. Reads the prompt on stdin.
The drafter gets an allowlisted environment, so settings come from fake_claude.json
beside this script (the tests copy both into a temporary directory). Keys:
sentinel (file touched when invoked), env_file (file receiving the env var names),
cwd_file (file receiving the working directory), argv_file (file receiving argv as
JSON), prompt_copy (file receiving the --append-system-prompt-file contents),
edit (path to append a line to), write (text to append to `edit` instead),
delete (path to remove), fail (print an error result and exit 1), stdin_copy (file
receiving the prompt read on stdin).
"""
import json
import os
import sys
from pathlib import Path
prompt = sys.stdin.read()
config_path = Path(__file__).resolve().with_name("fake_claude.json")
config = json.loads(config_path.read_text()) if config_path.exists() else {}
if config.get("stdin_copy"):
Path(config["stdin_copy"]).write_text(prompt, encoding="utf-8")
if config.get("sentinel"):
Path(config["sentinel"]).write_text("invoked\n", encoding="utf-8")
if config.get("env_file"):
Path(config["env_file"]).write_text("\n".join(sorted(os.environ)), encoding="utf-8")
if config.get("cwd_file"):
Path(config["cwd_file"]).write_text(os.getcwd(), encoding="utf-8")
if config.get("argv_file"):
Path(config["argv_file"]).write_text(json.dumps(sys.argv), encoding="utf-8")
if config.get("prompt_copy") and "--append-system-prompt-file" in sys.argv:
source = Path(sys.argv[sys.argv.index("--append-system-prompt-file") + 1])
Path(config["prompt_copy"]).write_text(source.read_text(encoding="utf-8"),
encoding="utf-8")
if config.get("delete"):
Path(config["delete"]).unlink()
if config.get("fail"):
print(json.dumps({"type": "result", "subtype": "success", "is_error": True,
"result": "credential expired"}))
sys.exit(1)
target = config.get("edit")
edits = []
if target:
path = Path(target)
path.parent.mkdir(parents=True, exist_ok=True)
with path.open("a", encoding="utf-8") as fh:
fh.write(config.get("write", "Edited by the drafter.") + "\n")
edits.append({"path": target, "why": "updated for the change"})
summary = {"edits": edits, "declined": []}
print(json.dumps({
"type": "result", "subtype": "success", "is_error": False,
"num_turns": 3, "total_cost_usd": 0.12,
"result": "Done.\n\n```json\n" + json.dumps(summary) + "\n```",
}))