Skip to content
Merged
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
3 changes: 2 additions & 1 deletion promptpilot/merge_done_proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def _history(gh, config, cp, pr, main):
intents = [n for n in comments if pp.comment_id(n) == iid]
_need(len(intents) == 1, "missing checkpoint intent")
saved = intents[0]
match = lineage._INTENT.fullmatch(saved["body"])
match = lineage.intent_line(saved["body"])
_proven(match and match[1] == old, "invalid checkpoint intent")
intent_base, review, claim, completion, ship, previous = match.groups()[1:]
fields = f"from={old} to={head} base={base} previous={previous} ship-event={ship}"
Expand Down Expand Up @@ -445,6 +445,7 @@ def _history(gh, config, cp, pr, main):
previous != "none"
and (
lineage._INTENT.fullmatch(protocol)
or lineage.intent_line(n["body"])
or lineage._DONE.fullmatch(protocol)
),
"unknown protocol marker in source epoch",
Expand Down
16 changes: 6 additions & 10 deletions promptpilot/merge_finish_proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import subprocess

from . import base_sync_carry, project_pipeline as pp
from .merge_ship_authorization import intent_line
from .review_routing_policy import require_legacy


Expand Down Expand Up @@ -225,9 +226,10 @@ def _history(gh, config, checkpoint):
if len(intents) != 1 or len(dones) > 1:
raise OutsideScope("terminal route requires a unique first-hop intent and at most one done")
saved = intents[0]
marker = intent_line(saved["body"])
_need(
pp.comment_id(saved) == intent
and saved["body"] == intent_body
and marker and marker[0] == intent_body
and saved["lastEditedAt"] is None
and saved["author"]["login"] == TRUSTED,
"checkpoint differs from canonical intent",
Expand Down Expand Up @@ -338,16 +340,10 @@ def observe_delivery(gh, record, *, config, expected_node_id=None):
):
return None
general = record.get("proof_kind") == "legacy-general-done-v1"
intent_base = "[0-9a-f]{40}" if general else base
previous_pattern = r"(none|[1-9][0-9]*)" if general else "(none)"
match = re.fullmatch(
rf"<!-- pp:base-sync-intent from={old} base={intent_base} review-comment=[1-9][0-9]* "
rf"claim=[1-9][0-9]* completion=[1-9][0-9]* ship-event=([A-Za-z0-9_=-]+) previous={previous_pattern} -->",
saved["body"],
)
if not match:
marker = intent_line(saved["body"])
if not marker or marker[1] != old or (not general and (marker[2] != base or marker[7] != "none")):
return None
ship, previous = match.groups()
ship, previous = marker[6], marker[7]
expected = f"{prefix}from={old} to={head} base={base} previous={previous} ship-event={ship} -->"
order = [n.get("id") for n in nodes]
if (
Expand Down
13 changes: 13 additions & 0 deletions promptpilot/merge_ship_authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ def _protocol_body(body):
return '\n'.join(lines)


def intent_line(body):
"""Read an intent alongside prose. Callers retain the entire body for bytewise readback."""
# The whole comment is removed when reconstructing the previous epoch.
# Never remove another transaction, a review reset, or an HTML example with it.
if (body.count('<!--') != 1 or has_review_again(body)
or re.search(r'(?i)<(?:pre|code|blockquote|script|style|textarea)(?=[\s>])', body)):
return None
marker = _INTENT.search(_protocol_body(body))
if marker and not any(marker[index].startswith('0') for index in (3, 4, 5, 7)):
return marker
return None


def _need(value,message):
if not value:raise ShipAuthorizationError(message)

Expand Down
3 changes: 3 additions & 0 deletions promptpilot/pipeline_insights.py
Original file line number Diff line number Diff line change
Expand Up @@ -4504,6 +4504,9 @@ def execution_route(task, fallback_prompt: str, working_dir: str | None = None,
"--base", "<second_parent>", "--to", "<new>", "--tree", "<tree>",
"--intent", "<intent_comment_id>", *gate_command[-2:]]
pre_review_guard += (
"При создании нового pp:base-sync-intent отправь ровно одну строку маркера из "
"канонической процедуры. Для существующего intent сохрани полное исходное тело "
"комментария и сверь его без изменений в REST и GraphQL. "
"После подтверждённого обновления ветки вызови checkpoint_record_command, подставив "
"проверенные SHA и ID комментария. При state=refused сверь причину. "
"При выборе нового HEAD восстанови отсутствующую запись после полной сверки. После записи "
Expand Down
53 changes: 53 additions & 0 deletions tests/test_merge_done_proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from promptpilot import (
merge_done_proof as full,
merge_finish_proof as finish,
merge_ship_authorization as lineage,
project_pipeline as pp,
)
from tests.test_base_sync_carry import git, commit
Expand All @@ -20,6 +21,8 @@
CONFIG,
DONE,
HEAD,
INTENT,
INTENT_PREAMBLE,
N,
OLD,
TREE,
Expand Down Expand Up @@ -116,6 +119,56 @@ def test_first_hop_and_post_readback(replay):
assert not replay.posts


def test_verbatim_2731_comment_and_multihop_preparation(replay):
# ivanarama/onebase issuecomment-7049065664, including its explanatory first line.
actual = (
"PromptPilot service marker: MERGE base synchronization intent.\n"
"<!-- pp:base-sync-intent from=32c32c993b26795014b93ca7a3546b3969307add "
"base=ad337867f31bbdfb54bbe65ccc66d05c7aa1fc69 review-comment=7009432714 claim=7009433577 "
"completion=7009435441 ship-event=LE_lADOSKrn-s8AAAABgsRv-c8AAAAIiJB2SA previous=none -->"
)
assert hashlib.sha256(actual.encode()).hexdigest() == "4c5c522e4213d3a4b05f51d061c8ac7cf326b2dcb4aa809db1344f5e6c48ea65"
assert lineage.intent_line(actual)[0] == actual.split("\n")[1]
intent = replay.edges[-2]["node"]
body, _, fingerprint = replay.prepare()
intent["body"] = INTENT_PREAMBLE + INTENT
observed, receipt, with_preamble = replay.prepare()
assert observed == body and receipt is None and with_preamble != fingerprint
replay.add_hop()
replay.edges[-2]["node"]["body"] = INTENT_PREAMBLE + replay.edges[-2]["node"]["body"]
assert "previous=888" in replay.prepare()[0] and not replay.posts


@pytest.mark.parametrize("body", [
"> " + INTENT, " " + INTENT, "`" + INTENT + "`", "~~~md\n" + INTENT + "\n~~~",
"````\n```\n" + INTENT + "\n````", "<blockquote>\n" + INTENT + "\n</blockquote>",
INTENT + "\n" + INTENT, INTENT + "\n<!-- pp:base-sync-intent malformed -->",
INTENT + "\n" + DONE, INTENT + "\npp:review-again", INTENT.replace("claim=102", "claim=0102"),
INTENT.replace("from=" + OLD, "from=" + HEAD),
])
def test_one_standalone_intent_required_before_recovery(replay, body):
replay.edges[-2]["node"]["body"] = body
with pytest.raises(pp.PipelineError):
replay.prepare()
assert not replay.posts


def test_full_preparation_requires_identical_explanatory_text_in_rest(replay, monkeypatch):
replay.edges[-2]["node"]["body"] = INTENT_PREAMBLE + INTENT
get = replay.json

def drift(verb, path, *args, **kwargs):
value = get(verb, path, *args, **kwargs)
if path.endswith("/issues/comments/164"):
return dict(value, body="Different explanation.\n" + INTENT)
return value

monkeypatch.setattr(replay, "json", drift)
with pytest.raises(pp.PipelineError, match="exact UTF-8 readback"):
replay.prepare()
assert not replay.posts


@pytest.mark.parametrize("state", ["failure", None, "absent"])
def test_new_ci_is_observed_even_before_it_passes(replay, state):
green = replay.prepare()[2]
Expand Down
35 changes: 35 additions & 0 deletions tests/test_merge_finish_proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
f"<!-- pp:base-sync-intent from={OLD} base={BASE} review-comment=101 "
"claim=102 completion=103 ship-event=ship previous=none -->"
)
INTENT_PREAMBLE = "PromptPilot service marker: MERGE base synchronization intent.\n"
DONE = (
f"<!-- pp:base-sync-done intent=164 from={OLD} to={HEAD} base={BASE} previous=none ship-event=ship -->"
)
Expand Down Expand Up @@ -243,6 +244,40 @@ def test_confirm_and_recover_existing_done(replay):
assert replay.posts == [{"body": DONE}] and len(replay.gates) == 1


def test_2731_service_comment_and_its_uncertain_delivery_keep_exact_bytes(replay, monkeypatch):
intent = replay.edges[-2]["node"]
intent["body"] = INTENT_PREAMBLE + INTENT
replay.drop_post = True
with pytest.raises(pp.PipelineError, match="lost"):
replay.run()
assert replay.run()["published"] is False and replay.posts == [{"body": DONE}]
record = dict(CHECKPOINT, body_sha256=hashlib.sha256(DONE.encode()).hexdigest())
assert finish.observe_receipt(replay, record, config=CONFIG) == 888
get = replay.json

def drift(verb, path, *args, **kwargs):
value = get(verb, path, *args, **kwargs)
if path.endswith("/issues/comments/164"):
return dict(value, body=INTENT)
return value

monkeypatch.setattr(replay, "json", drift)
with pytest.raises(pp.PipelineError, match="exact UTF-8 readback"):
finish.observe_receipt(replay, record, config=CONFIG)
with pytest.raises(pp.PipelineError, match="exact UTF-8 readback"):
replay.run()
assert replay.posts == [{"body": DONE}]


def test_only_the_explanatory_line_changes_across_final_source(replay):
intent = replay.edges[-2]["node"]
intent["body"] = INTENT_PREAMBLE + INTENT
replay.on_source = lambda: intent.update(body="Another description.\n" + INTENT)
with pytest.raises(pp.PipelineError, match="changed across final Source"):
replay.run()
assert not replay.posts and not replay.past_send


@pytest.mark.parametrize(
"change",
[
Expand Down
Loading