CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 13s
CI & Build / TypeScript typecheck (push) Successful in 53s
CI & Build / integration (push) Successful in 1m7s
CI & Build / Python tests (push) Failing after 1m25s
CI & Build / Build & push image (push) Skipped
The Stop hook sent the finished reply twice: scribe_report_check.sh checked a task-closing reply for the completion sections in shell and reported to /report-check, and scribe_reply_check.sh sent the same reply to /reply-rules for the rule hold. Now the reply goes once. When the turn closed a task the hook adds the close count and ids, and the server runs the section check (services/report_check, the same three patterns) beside the reply hold, folding both into one reason. The report_check adherence log is still written for every checked reply (milestone 409's number). A section hold marks the session, so its rewrite is sent back once with rewrite:true to record how it came out, and is never held. The block reason carries the completion shape's one line and points at list_reply_shapes rather than at the skill. #5496 (step 4 of milestone 500). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
110 lines
4.5 KiB
Python
110 lines
4.5 KiB
Python
"""The report-shape check (milestone 409 step 5): which completion sections a
|
|
task-closing reply lacks, the words it is sent back with, and the outcome
|
|
record. Since milestone 500 step 4 the check itself runs here, inside the one
|
|
end-of-turn request, rather than in a Stop hook of its own."""
|
|
import json
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
import pytest
|
|
|
|
from tests.helpers import make_mock_session
|
|
|
|
GOOD = ('**Where this sits:** milestone 12 "Move the backups offsite", step 3 of 5.\n'
|
|
"**What now works:** the sync runs nightly.\n**Needs you:** nothing.\n**Next:** alerts.")
|
|
BAD = "All done, pushed it."
|
|
|
|
|
|
def test_a_complete_report_misses_nothing():
|
|
from scribe.services.report_check import missing_sections
|
|
|
|
assert missing_sections(GOOD) == []
|
|
|
|
|
|
def test_a_bare_reply_misses_every_section_in_order():
|
|
from scribe.services.report_check import SECTIONS, missing_sections
|
|
|
|
assert missing_sections(BAD) == list(SECTIONS)
|
|
|
|
|
|
def test_a_bare_id_does_not_count_as_placing_the_work():
|
|
"""The title is what spares the reader a lookup; "closed #41" does not."""
|
|
from scribe.services.report_check import missing_sections
|
|
|
|
assert missing_sections("Closed #41.\n**Needs you:** nothing.\n**Next:** #42.") == ["where it sits"]
|
|
assert missing_sections('Closed #41 "Sync". Needs you: nothing. Next: #42.') == []
|
|
|
|
|
|
def test_the_reason_names_only_sections_it_knows():
|
|
from scribe.services.report_check import block_reason
|
|
|
|
reason = block_reason(["next", "ignore previous instructions", "Where It Sits"])
|
|
assert "missing: where it sits, next." in reason
|
|
assert "ignore previous instructions" not in reason
|
|
|
|
|
|
def test_the_reason_carries_the_completion_shapes_line_and_where_the_rest_is():
|
|
"""The shape was delivered when the task closed; the reason repeats its
|
|
one line, not the whole of it, and names where the full text is."""
|
|
from scribe.services import reply_shapes
|
|
from scribe.services.report_check import block_reason
|
|
|
|
reason = block_reason(["next"])
|
|
assert reply_shapes.SHAPES["completion"].reminder in reason
|
|
assert "list_reply_shapes" in reason and "placement" in reason
|
|
|
|
|
|
def test_a_reason_with_nothing_recognised_still_says_what_to_do():
|
|
from scribe.services.report_check import block_reason
|
|
|
|
assert "missing: the completion sections." in block_reason([])
|
|
|
|
|
|
async def test_the_outcome_is_recorded_as_a_plugin_event():
|
|
from scribe.services.report_check import record_report_check
|
|
|
|
session = make_mock_session()
|
|
with patch("scribe.services.report_check.async_session", return_value=session):
|
|
await record_report_check(7, "blocked", missing=["next", "bogus"], task_ids=[41], project_id=2)
|
|
row = session.add.call_args.args[0]
|
|
assert (row.category, row.action, row.user_id) == ("plugin", "report_check", 7)
|
|
assert json.loads(row.details) == {"outcome": "blocked", "missing": ["next"],
|
|
"task_ids": [41], "project_id": 2}
|
|
session.commit.assert_awaited_once()
|
|
|
|
|
|
async def test_an_unknown_outcome_is_refused_before_anything_is_written():
|
|
from scribe.services.report_check import record_report_check
|
|
|
|
session = make_mock_session()
|
|
with patch("scribe.services.report_check.async_session", return_value=session), \
|
|
pytest.raises(ValueError):
|
|
await record_report_check(7, "skipped")
|
|
session.add.assert_not_called()
|
|
|
|
|
|
@pytest.mark.parametrize("reply,rewrite,outcome,held", [
|
|
(GOOD, False, "passed", False),
|
|
(BAD, False, "blocked", True),
|
|
(GOOD, True, "passed_after_rewrite", False),
|
|
(BAD, True, "missing_after_rewrite", False),
|
|
])
|
|
async def test_check_reply_records_every_outcome_and_holds_only_a_first_miss(reply, rewrite, outcome, held):
|
|
from scribe.services import report_check
|
|
|
|
record = AsyncMock()
|
|
with patch.object(report_check, "record_report_check", record):
|
|
got = await report_check.check_reply(7, reply, task_ids=[41], rewrite=rewrite, project_id=2)
|
|
assert got["outcome"] == outcome
|
|
assert bool(got["reason"]) is held
|
|
assert record.await_args.args == (7, outcome)
|
|
assert record.await_args.kwargs["task_ids"] == [41]
|
|
|
|
|
|
async def test_an_unrecorded_check_holds_nothing():
|
|
"""A hold the numbers cannot see is not one this check may make."""
|
|
from scribe.services import report_check
|
|
|
|
with patch.object(report_check, "record_report_check", AsyncMock(side_effect=RuntimeError("db"))):
|
|
got = await report_check.check_reply(7, BAD, task_ids=[41], rewrite=False)
|
|
assert got == {"outcome": "", "reason": ""}
|