Files
docs-review/tests/test_drafter.py
T
jaredandClaude Opus 5.5 ade847ba5b
tests / unittest (push) Failing after 13s
Initial public release: PR documentation review for Gitea
Stage 1 flags the living documents a pull request makes stale (no model, nothing sent).
Stage 2, on repositories that opt in with drafter: claude, has Claude Code draft the edits
in a sandboxed copy of the tree and opens them as a pull request into the feature branch.
A monthly pass re-reads the top-level documents against the whole repository.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 14:20:22 -05:00

69 lines
2.5 KiB
Python

import subprocess
import tempfile
import unittest
from pathlib import Path
from unittest import mock
from docs_review import drafter, sandbox
from docs_review.git import GitError
from docs_review.inputs import Inputs
from tests.helpers import make_repo
INPUTS = Inputs(drafter="claude", docs=("*.txt",), generated=(), top_level=(),
source_dirs=(), workstream="docs", tracking_issue=None, doc_guide=None,
model="m")
PREFIX = "drafter failed: could not export the tree for drafting: "
class ExportFailureTest(unittest.TestCase):
def setUp(self):
self._tmp = tempfile.TemporaryDirectory()
self.addCleanup(self._tmp.cleanup)
tmp = Path(self._tmp.name)
self.repo = make_repo(tmp / "repo")
(tmp / "runner").mkdir()
self.env = {"RUNNER_TEMP": str(tmp / "runner"), "PATH": "/usr/bin:/bin"}
def draft_with(self, err):
made = []
real = sandbox.make_sandbox
def make(env):
made.append(real(env))
return made[-1]
with mock.patch.object(sandbox, "make_sandbox", make), \
mock.patch.object(sandbox, "export_tree", side_effect=err), \
mock.patch.object(drafter, "run_drafter") as run:
out = drafter.draft_in_sandbox(INPUTS, "prompt", self.repo, self.env)
run.assert_not_called()
self.assertEqual(len(made), 1)
self.assertFalse(made[0].exists())
return out
def test_git_error_becomes_a_note(self):
out = self.draft_with(GitError("git archive HEAD failed: fatal: bad object"))
self.assertEqual(out, drafter.Drafted(
None, (), PREFIX + "git archive HEAD failed: fatal: bad object"))
def test_timeout_becomes_a_note(self):
out = self.draft_with(subprocess.TimeoutExpired(["tar"], 300))
self.assertIsNone(out.result)
self.assertEqual(out.changed, ())
self.assertTrue(out.note.startswith(PREFIX), out.note)
self.assertIn("timed out", out.note)
def test_oserror_becomes_a_note(self):
out = self.draft_with(FileNotFoundError(2, "No such file", "tar"))
self.assertTrue(out.note.startswith(PREFIX), out.note)
def test_long_reason_is_shortened_to_one_line(self):
out = self.draft_with(GitError("tar -x failed: " + "x" * 500 + "\nsecond line"))
reason = out.note[len(PREFIX):]
self.assertNotIn("\n", reason)
self.assertLessEqual(len(reason), drafter.EXPORT_REASON_MAX + 3)
if __name__ == "__main__":
unittest.main()