Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
582f603dd2 | ||
|
|
c225632c1e | ||
|
|
8d2608a73e |
@@ -116,6 +116,22 @@ _TARGET_BRANCH_SHA_RE = re.compile(
|
|||||||
r"target branch sha\s*:\s*[0-9a-f]{40}",
|
r"target branch sha\s*:\s*[0-9a-f]{40}",
|
||||||
re.IGNORECASE,
|
re.IGNORECASE,
|
||||||
)
|
)
|
||||||
|
_WORKFLOW_LOAD_HELPER_RE = re.compile(
|
||||||
|
r"workflow[- ]load helper result\s*:",
|
||||||
|
re.IGNORECASE,
|
||||||
|
)
|
||||||
|
_WORKFLOW_LOAD_HASH_RE = re.compile(
|
||||||
|
r"workflow[- ]load helper result[\s\S]{0,400}?workflow[_ ]hash\s*:\s*[0-9a-f]{12}",
|
||||||
|
re.IGNORECASE,
|
||||||
|
)
|
||||||
|
_WORKFLOW_LOAD_BOUNDARY_RE = re.compile(
|
||||||
|
r"workflow[- ]load helper result[\s\S]{0,400}?boundary[_ ]status\s*:\s*(?:clean|violation)",
|
||||||
|
re.IGNORECASE,
|
||||||
|
)
|
||||||
|
_WORKFLOW_FILE_VIEW_NARRATIVE_RE = re.compile(
|
||||||
|
r"(?:read|viewed|loaded)\s+(?:the\s+)?(?:canonical\s+)?(?:workflow|review-merge-pr\.md)",
|
||||||
|
re.IGNORECASE,
|
||||||
|
)
|
||||||
_FULL_SHA_RE = re.compile(r"\b[0-9a-f]{40}\b", re.IGNORECASE)
|
_FULL_SHA_RE = re.compile(r"\b[0-9a-f]{40}\b", re.IGNORECASE)
|
||||||
_RECONCILE_STALE_FIELDS = (
|
_RECONCILE_STALE_FIELDS = (
|
||||||
"pr number opened",
|
"pr number opened",
|
||||||
@@ -919,6 +935,54 @@ def _rule_shared_author_reviewer_same_run(report_text: str) -> list[dict[str, st
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _rule_reviewer_workflow_load_boundary(report_text: str) -> list[dict[str, str]]:
|
||||||
|
"""#403: require structured workflow-load helper result, not file-view narrative."""
|
||||||
|
if not report_text.strip():
|
||||||
|
return []
|
||||||
|
findings: list[dict[str, str]] = []
|
||||||
|
has_helper = bool(_WORKFLOW_LOAD_HELPER_RE.search(report_text))
|
||||||
|
has_hash = bool(_WORKFLOW_LOAD_HASH_RE.search(report_text))
|
||||||
|
has_boundary = bool(_WORKFLOW_LOAD_BOUNDARY_RE.search(report_text))
|
||||||
|
has_narrative_only = bool(_WORKFLOW_FILE_VIEW_NARRATIVE_RE.search(report_text))
|
||||||
|
|
||||||
|
if has_narrative_only and not has_helper:
|
||||||
|
findings.append(validator_finding(
|
||||||
|
"reviewer.workflow_load_boundary",
|
||||||
|
"block",
|
||||||
|
"Workflow-load helper result",
|
||||||
|
(
|
||||||
|
"canonical workflow file-view narrative without structured "
|
||||||
|
"gitea_load_review_workflow helper result"
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"include Workflow-load helper result with workflow_hash and "
|
||||||
|
"boundary_status from gitea_load_review_workflow"
|
||||||
|
),
|
||||||
|
))
|
||||||
|
return findings
|
||||||
|
|
||||||
|
if has_helper and (not has_hash or not has_boundary):
|
||||||
|
missing = []
|
||||||
|
if not has_hash:
|
||||||
|
missing.append("workflow_hash")
|
||||||
|
if not has_boundary:
|
||||||
|
missing.append("boundary_status")
|
||||||
|
findings.append(validator_finding(
|
||||||
|
"reviewer.workflow_load_boundary",
|
||||||
|
"block",
|
||||||
|
"Workflow-load helper result",
|
||||||
|
(
|
||||||
|
"workflow-load helper result incomplete; missing "
|
||||||
|
+ ", ".join(missing)
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"copy workflow_load_helper_result fields from "
|
||||||
|
"gitea_load_review_workflow into the final report"
|
||||||
|
),
|
||||||
|
))
|
||||||
|
return findings
|
||||||
|
|
||||||
|
|
||||||
def _rule_reviewer_review_mutation(
|
def _rule_reviewer_review_mutation(
|
||||||
report_text: str,
|
report_text: str,
|
||||||
*,
|
*,
|
||||||
@@ -963,6 +1027,7 @@ _RULES_BY_TASK: dict[str, list[Callable[..., list[dict[str, str]]]]] = {
|
|||||||
_rule_reviewer_already_landed_eligible,
|
_rule_reviewer_already_landed_eligible,
|
||||||
_rule_reviewer_already_landed_state,
|
_rule_reviewer_already_landed_state,
|
||||||
_rule_reviewer_target_branch_freshness,
|
_rule_reviewer_target_branch_freshness,
|
||||||
|
_rule_reviewer_workflow_load_boundary,
|
||||||
_rule_reviewer_mutation_ledger,
|
_rule_reviewer_mutation_ledger,
|
||||||
_rule_reviewer_review_mutation,
|
_rule_reviewer_review_mutation,
|
||||||
],
|
],
|
||||||
|
|||||||
+117
-1
@@ -536,6 +536,8 @@ import role_session_router # noqa: E402
|
|||||||
import role_namespace_gate # noqa: E402
|
import role_namespace_gate # noqa: E402
|
||||||
import task_capability_map # noqa: E402
|
import task_capability_map # noqa: E402
|
||||||
import review_proofs # noqa: E402
|
import review_proofs # noqa: E402
|
||||||
|
import review_workflow_boundary # noqa: E402
|
||||||
|
import review_workflow_load # noqa: E402
|
||||||
import agent_temp_artifacts
|
import agent_temp_artifacts
|
||||||
import issue_lock_worktree # noqa: E402
|
import issue_lock_worktree # noqa: E402
|
||||||
import issue_lock_provenance # noqa: E402
|
import issue_lock_provenance # noqa: E402
|
||||||
@@ -2010,6 +2012,7 @@ def init_review_decision_lock(remote: str | None, task: str | None):
|
|||||||
"""Seed read-only-until-ready state for reviewer PR review tasks."""
|
"""Seed read-only-until-ready state for reviewer PR review tasks."""
|
||||||
if task != "review_pr":
|
if task != "review_pr":
|
||||||
return
|
return
|
||||||
|
review_workflow_load.clear_review_workflow_load()
|
||||||
profile = get_profile()
|
profile = get_profile()
|
||||||
profile_name = (profile.get("profile_name") or "").strip()
|
profile_name = (profile.get("profile_name") or "").strip()
|
||||||
session_lock = (
|
session_lock = (
|
||||||
@@ -2035,6 +2038,11 @@ def init_review_decision_lock(remote: str | None, task: str | None):
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def _review_workflow_load_gate_reasons() -> list[str]:
|
||||||
|
"""Fail closed when canonical review workflow was not loaded (#389)."""
|
||||||
|
return review_workflow_load.review_workflow_load_blockers(PROJECT_ROOT)
|
||||||
|
|
||||||
|
|
||||||
def check_review_decision_gate(
|
def check_review_decision_gate(
|
||||||
pr_number: int,
|
pr_number: int,
|
||||||
action: str,
|
action: str,
|
||||||
@@ -2045,7 +2053,10 @@ def check_review_decision_gate(
|
|||||||
repo: str | None = None,
|
repo: str | None = None,
|
||||||
) -> list[str]:
|
) -> list[str]:
|
||||||
"""Fail closed unless validation completed and the final decision is ready."""
|
"""Fail closed unless validation completed and the final decision is ready."""
|
||||||
reasons = []
|
reasons = list(_review_workflow_load_gate_reasons())
|
||||||
|
if reasons:
|
||||||
|
reasons.extend(review_workflow_load.recovery_handoff_without_replay())
|
||||||
|
return reasons
|
||||||
lock = _load_review_decision_lock()
|
lock = _load_review_decision_lock()
|
||||||
if lock is None:
|
if lock is None:
|
||||||
reasons.append(
|
reasons.append(
|
||||||
@@ -2401,6 +2412,7 @@ def _evaluate_pr_review_submission(
|
|||||||
"""Shared gate chain for live submit and dry-run review tools."""
|
"""Shared gate chain for live submit and dry-run review tools."""
|
||||||
verify_preflight_purity(remote)
|
verify_preflight_purity(remote)
|
||||||
action = (action or "").strip().lower()
|
action = (action or "").strip().lower()
|
||||||
|
workflow_blockers = _review_workflow_load_gate_reasons() if live else []
|
||||||
result = {
|
result = {
|
||||||
"requested_action": action,
|
"requested_action": action,
|
||||||
"performed": False,
|
"performed": False,
|
||||||
@@ -2416,6 +2428,10 @@ def _evaluate_pr_review_submission(
|
|||||||
"reasons": [],
|
"reasons": [],
|
||||||
}
|
}
|
||||||
reasons = result["reasons"]
|
reasons = result["reasons"]
|
||||||
|
if workflow_blockers:
|
||||||
|
reasons.extend(workflow_blockers)
|
||||||
|
reasons.extend(review_workflow_load.recovery_handoff_without_replay())
|
||||||
|
return result
|
||||||
|
|
||||||
if action not in _REVIEW_ACTIONS:
|
if action not in _REVIEW_ACTIONS:
|
||||||
reasons.append(
|
reasons.append(
|
||||||
@@ -2600,6 +2616,13 @@ def gitea_mark_final_review_decision(
|
|||||||
}
|
}
|
||||||
org = resolved_org
|
org = resolved_org
|
||||||
repo = resolved_repo
|
repo = resolved_repo
|
||||||
|
workflow_blockers = _review_workflow_load_gate_reasons()
|
||||||
|
if workflow_blockers:
|
||||||
|
return {
|
||||||
|
"marked_ready": False,
|
||||||
|
"reasons": workflow_blockers + (
|
||||||
|
review_workflow_load.recovery_handoff_without_replay()),
|
||||||
|
}
|
||||||
hard_stop = terminal_review_hard_stop_reasons(pr_number, "mark_ready")
|
hard_stop = terminal_review_hard_stop_reasons(pr_number, "mark_ready")
|
||||||
if hard_stop:
|
if hard_stop:
|
||||||
return {"marked_ready": False, "reasons": hard_stop}
|
return {"marked_ready": False, "reasons": hard_stop}
|
||||||
@@ -3197,6 +3220,7 @@ def gitea_merge_pr(
|
|||||||
available. Never secrets.
|
available. Never secrets.
|
||||||
"""
|
"""
|
||||||
verify_preflight_purity(remote)
|
verify_preflight_purity(remote)
|
||||||
|
workflow_blockers = _review_workflow_load_gate_reasons()
|
||||||
do = (do or "").strip().lower()
|
do = (do or "").strip().lower()
|
||||||
result = {
|
result = {
|
||||||
"performed": False,
|
"performed": False,
|
||||||
@@ -3214,6 +3238,10 @@ def gitea_merge_pr(
|
|||||||
"reasons": [],
|
"reasons": [],
|
||||||
}
|
}
|
||||||
reasons = result["reasons"]
|
reasons = result["reasons"]
|
||||||
|
if workflow_blockers:
|
||||||
|
reasons.extend(workflow_blockers)
|
||||||
|
reasons.extend(review_workflow_load.recovery_handoff_without_replay())
|
||||||
|
return result
|
||||||
|
|
||||||
# Gate 1 — valid merge method (no API call on a bad method).
|
# Gate 1 — valid merge method (no API call on a bad method).
|
||||||
if do not in _MERGE_METHODS:
|
if do not in _MERGE_METHODS:
|
||||||
@@ -4950,6 +4978,8 @@ _PROJECT_SKILLS = {
|
|||||||
"steps": [
|
"steps": [
|
||||||
"Resolve task first: gitea_resolve_task_capability(task='review_pr') "
|
"Resolve task first: gitea_resolve_task_capability(task='review_pr') "
|
||||||
"to confirm reviewer namespace and avoid author-profile blocks.",
|
"to confirm reviewer namespace and avoid author-profile blocks.",
|
||||||
|
"Load canonical workflow proof with gitea_load_review_workflow "
|
||||||
|
"before any review/merge mutation (#389).",
|
||||||
"Verify reviewer identity with gitea_whoami; the PR author "
|
"Verify reviewer identity with gitea_whoami; the PR author "
|
||||||
"must be a different user.",
|
"must be a different user.",
|
||||||
"Reconcile live queue state FIRST (do not trust prior handoffs): "
|
"Reconcile live queue state FIRST (do not trust prior handoffs): "
|
||||||
@@ -5873,6 +5903,8 @@ def gitea_get_runtime_context(
|
|||||||
),
|
),
|
||||||
"role_kind": _role_kind(allowed, forbidden),
|
"role_kind": _role_kind(allowed, forbidden),
|
||||||
"shell_health": native_mcp_preference.shell_health_status(),
|
"shell_health": native_mcp_preference.shell_health_status(),
|
||||||
|
"workflow_load_proof": review_workflow_load.workflow_load_status(
|
||||||
|
PROJECT_ROOT),
|
||||||
}
|
}
|
||||||
|
|
||||||
if reveal and h:
|
if reveal and h:
|
||||||
@@ -5881,6 +5913,80 @@ def gitea_get_runtime_context(
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
@mcp.tool()
|
||||||
|
def gitea_record_pre_review_command(
|
||||||
|
command: str,
|
||||||
|
cwd: str | None = None,
|
||||||
|
classification: str | None = None,
|
||||||
|
) -> dict:
|
||||||
|
"""Classify and record a command executed before workflow load (#403).
|
||||||
|
|
||||||
|
Read-only with respect to Gitea API. Pre-review inventory/diagnostic commands
|
||||||
|
may be recorded as allowed; boundary violations block reviewer mutations.
|
||||||
|
"""
|
||||||
|
recorded = review_workflow_boundary.record_pre_review_command(
|
||||||
|
command,
|
||||||
|
cwd=cwd,
|
||||||
|
project_root=PROJECT_ROOT,
|
||||||
|
classification=classification,
|
||||||
|
)
|
||||||
|
boundary_state = review_workflow_boundary.assess_boundary_status(PROJECT_ROOT)
|
||||||
|
return {
|
||||||
|
"success": True,
|
||||||
|
"recorded": recorded,
|
||||||
|
"boundary_status": boundary_state.get("boundary_status"),
|
||||||
|
"boundary_clean": boundary_state.get("boundary_clean"),
|
||||||
|
"reasons": list(boundary_state.get("reasons") or []),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@mcp.tool()
|
||||||
|
def gitea_load_review_workflow(
|
||||||
|
prompt_text: str | None = None,
|
||||||
|
) -> dict:
|
||||||
|
"""Load and record canonical review-merge workflow proof for this session (#389, #403).
|
||||||
|
|
||||||
|
Read-only with respect to Gitea API; records in-process workflow source/hash
|
||||||
|
proof and session boundary state required before reviewer review or merge
|
||||||
|
mutations.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
recorded = review_workflow_load.record_review_workflow_load(
|
||||||
|
PROJECT_ROOT, prompt_text=prompt_text)
|
||||||
|
except OSError as exc:
|
||||||
|
return {
|
||||||
|
"success": False,
|
||||||
|
"loaded": False,
|
||||||
|
"reasons": [str(exc)],
|
||||||
|
"recovery_handoff": review_workflow_load.recovery_handoff_without_replay(),
|
||||||
|
}
|
||||||
|
boundary_reasons = review_workflow_boundary.boundary_blockers(PROJECT_ROOT)
|
||||||
|
helper = review_workflow_boundary.workflow_load_helper_result(
|
||||||
|
recorded, PROJECT_ROOT)
|
||||||
|
return {
|
||||||
|
"success": not boundary_reasons,
|
||||||
|
"loaded": True,
|
||||||
|
"workflow_source": recorded["workflow_source"],
|
||||||
|
"task_mode": recorded["task_mode"],
|
||||||
|
"workflow_hash": recorded["workflow_hash"],
|
||||||
|
"workflow_version": recorded["workflow_version"],
|
||||||
|
"final_report_schema_path": recorded["final_report_schema_path"],
|
||||||
|
"final_report_schema_hash": recorded["final_report_schema_hash"],
|
||||||
|
"prompt_conflicts_with_workflow": recorded[
|
||||||
|
"prompt_conflicts_with_workflow"],
|
||||||
|
"prompt_conflict_reasons": recorded.get("prompt_conflict_reasons") or [],
|
||||||
|
"workflow_load_proof_present": True,
|
||||||
|
"boundary_status": recorded.get("boundary_status"),
|
||||||
|
"boundary_clean": recorded.get("boundary_clean"),
|
||||||
|
"workflow_load_helper_result": helper,
|
||||||
|
"reasons": boundary_reasons,
|
||||||
|
"recovery_handoff": (
|
||||||
|
review_workflow_load.recovery_handoff_without_replay()
|
||||||
|
if boundary_reasons else []
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
def gitea_list_profiles() -> dict:
|
def gitea_list_profiles() -> dict:
|
||||||
"""Read-only: list all Gitea MCP profiles with redacted metadata.
|
"""Read-only: list all Gitea MCP profiles with redacted metadata.
|
||||||
@@ -6936,6 +7042,16 @@ def gitea_resolve_task_capability(
|
|||||||
}
|
}
|
||||||
if reason_msg:
|
if reason_msg:
|
||||||
result["reason"] = reason_msg
|
result["reason"] = reason_msg
|
||||||
|
if task in ("review_pr", "merge_pr"):
|
||||||
|
result["workflow_load_proof"] = review_workflow_load.workflow_load_status(
|
||||||
|
PROJECT_ROOT)
|
||||||
|
if not result["workflow_load_proof"].get("workflow_load_valid"):
|
||||||
|
guidance = (
|
||||||
|
"Call gitea_load_review_workflow before any reviewer review "
|
||||||
|
"or merge mutation."
|
||||||
|
)
|
||||||
|
if guidance not in task_role_guidance:
|
||||||
|
task_role_guidance.append(guidance)
|
||||||
role_session_router.sync_route_from_capability(result)
|
role_session_router.sync_route_from_capability(result)
|
||||||
was_terminal = capability_stop_terminal.is_active()
|
was_terminal = capability_stop_terminal.is_active()
|
||||||
terminal = capability_stop_terminal.sync_from_capability_result(result)
|
terminal = capability_stop_terminal.sync_from_capability_result(result)
|
||||||
|
|||||||
@@ -0,0 +1,259 @@
|
|||||||
|
"""Reviewer session boundary tracking for workflow-load gate (#403).
|
||||||
|
|
||||||
|
Pre-review commands executed before ``gitea_load_review_workflow`` must be
|
||||||
|
classified. Boundary violations block downstream reviewer mutations even when
|
||||||
|
workflow hash proof is present.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
CLASSIFICATION_READ_ONLY_INVENTORY = "read_only_inventory"
|
||||||
|
CLASSIFICATION_DIAGNOSTIC = "diagnostic"
|
||||||
|
CLASSIFICATION_BOUNDARY_VIOLATION = "boundary_violation"
|
||||||
|
CLASSIFICATION_UNCLASSIFIED = "unclassified"
|
||||||
|
|
||||||
|
ALLOWED_CLASSIFICATIONS = frozenset({
|
||||||
|
CLASSIFICATION_READ_ONLY_INVENTORY,
|
||||||
|
CLASSIFICATION_DIAGNOSTIC,
|
||||||
|
CLASSIFICATION_BOUNDARY_VIOLATION,
|
||||||
|
CLASSIFICATION_UNCLASSIFIED,
|
||||||
|
})
|
||||||
|
|
||||||
|
_PRE_REVIEW_COMMANDS: list[dict[str, Any]] = []
|
||||||
|
|
||||||
|
_READ_ONLY_INVENTORY_PATTERNS = (
|
||||||
|
re.compile(
|
||||||
|
r"\bgitea[_-](?:list|view|whoami|get[-_]|resolve[-_]task|check[-_]pr|route[-_]task)",
|
||||||
|
re.I,
|
||||||
|
),
|
||||||
|
re.compile(r"\bgit\s+(?:fetch|remote\s+update|branch\s+-a|log|show|rev-parse)\b", re.I),
|
||||||
|
re.compile(r"\bgit\s+status\b", re.I),
|
||||||
|
re.compile(r"\bgit\s+worktree\s+list\b", re.I),
|
||||||
|
)
|
||||||
|
|
||||||
|
_DIAGNOSTIC_PATTERNS = (
|
||||||
|
re.compile(r"\bgit\s+diff(?:\s+--stat)?\b", re.I),
|
||||||
|
re.compile(r"\bwhich\s+pytest\b", re.I),
|
||||||
|
re.compile(r"\bpytest\s+--version\b", re.I),
|
||||||
|
)
|
||||||
|
|
||||||
|
_BOUNDARY_VIOLATION_PATTERNS: tuple[tuple[re.Pattern[str], str], ...] = (
|
||||||
|
(re.compile(r"\b(?:pytest|python\s+-m\s+pytest|python\s+-m\s+unittest)\b", re.I),
|
||||||
|
"validation command before workflow load"),
|
||||||
|
(re.compile(r"\bprofiles\.json\b", re.I), "local profile config inspection"),
|
||||||
|
(re.compile(r"\bgitea-mcp(?:\.v2-contexts)?\.json\b", re.I),
|
||||||
|
"local Gitea MCP config inspection"),
|
||||||
|
(re.compile(r"\b\.env(?:\.|$|\b)", re.I), "credential file inspection"),
|
||||||
|
(re.compile(r"\bkeychain\b", re.I), "credential store inspection"),
|
||||||
|
(re.compile(r"\bpkill\b", re.I), "MCP repair activity"),
|
||||||
|
(re.compile(r"\b(?:edit|write|modify).{0,40}\bmcp\b", re.I),
|
||||||
|
"MCP config exploration"),
|
||||||
|
(re.compile(r"\bgit\s+(?:add|commit|reset|clean|checkout|merge|rebase|push)\b", re.I),
|
||||||
|
"git mutation before workflow load"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def clear_pre_review_commands() -> None:
|
||||||
|
"""Test helper and session reset."""
|
||||||
|
global _PRE_REVIEW_COMMANDS
|
||||||
|
_PRE_REVIEW_COMMANDS = []
|
||||||
|
|
||||||
|
|
||||||
|
def pre_review_commands() -> list[dict[str, Any]]:
|
||||||
|
"""Return a shallow copy of recorded pre-review commands."""
|
||||||
|
return [dict(entry) for entry in _PRE_REVIEW_COMMANDS]
|
||||||
|
|
||||||
|
|
||||||
|
def _normalize_path(path: str | None) -> str:
|
||||||
|
return os.path.realpath(os.path.abspath((path or "").strip() or os.getcwd()))
|
||||||
|
|
||||||
|
|
||||||
|
def is_main_checkout_path(cwd: str | None, project_root: str | None) -> bool:
|
||||||
|
"""True when *cwd* is the stable control checkout (not under branches/)."""
|
||||||
|
if not project_root:
|
||||||
|
return False
|
||||||
|
root = _normalize_path(project_root)
|
||||||
|
path = _normalize_path(cwd)
|
||||||
|
if path != root:
|
||||||
|
return False
|
||||||
|
marker = f"{os.sep}branches{os.sep}"
|
||||||
|
return marker not in path
|
||||||
|
|
||||||
|
|
||||||
|
def classify_pre_review_command(
|
||||||
|
command: str,
|
||||||
|
*,
|
||||||
|
cwd: str | None = None,
|
||||||
|
project_root: str | None = None,
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Classify a command executed before workflow load."""
|
||||||
|
text = (command or "").strip()
|
||||||
|
path = _normalize_path(cwd)
|
||||||
|
root = _normalize_path(project_root) if project_root else None
|
||||||
|
reasons: list[str] = []
|
||||||
|
|
||||||
|
for pattern, label in _BOUNDARY_VIOLATION_PATTERNS:
|
||||||
|
if pattern.search(text):
|
||||||
|
if label.startswith("validation") and root and not is_main_checkout_path(path, root):
|
||||||
|
continue
|
||||||
|
if label.startswith("git mutation") and root and not is_main_checkout_path(path, root):
|
||||||
|
continue
|
||||||
|
reasons.append(label)
|
||||||
|
return {
|
||||||
|
"command": text,
|
||||||
|
"cwd": path,
|
||||||
|
"classification": CLASSIFICATION_BOUNDARY_VIOLATION,
|
||||||
|
"reasons": reasons,
|
||||||
|
}
|
||||||
|
|
||||||
|
for pattern in _READ_ONLY_INVENTORY_PATTERNS:
|
||||||
|
if pattern.search(text):
|
||||||
|
return {
|
||||||
|
"command": text,
|
||||||
|
"cwd": path,
|
||||||
|
"classification": CLASSIFICATION_READ_ONLY_INVENTORY,
|
||||||
|
"reasons": [],
|
||||||
|
}
|
||||||
|
|
||||||
|
for pattern in _DIAGNOSTIC_PATTERNS:
|
||||||
|
if pattern.search(text):
|
||||||
|
return {
|
||||||
|
"command": text,
|
||||||
|
"cwd": path,
|
||||||
|
"classification": CLASSIFICATION_DIAGNOSTIC,
|
||||||
|
"reasons": [],
|
||||||
|
}
|
||||||
|
|
||||||
|
if root and is_main_checkout_path(path, root):
|
||||||
|
if re.search(r"\b(?:cat|head|less|read)\b", text, re.I):
|
||||||
|
if re.search(r"workflow|skill|runbook", text, re.I):
|
||||||
|
return {
|
||||||
|
"command": text,
|
||||||
|
"cwd": path,
|
||||||
|
"classification": CLASSIFICATION_BOUNDARY_VIOLATION,
|
||||||
|
"reasons": [
|
||||||
|
"canonical workflow viewed as local file without "
|
||||||
|
"gitea_load_review_workflow (narrative load is not proof)"
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
"command": text,
|
||||||
|
"cwd": path,
|
||||||
|
"classification": CLASSIFICATION_UNCLASSIFIED,
|
||||||
|
"reasons": [
|
||||||
|
"pre-review command not classified; record via "
|
||||||
|
"gitea_record_pre_review_command before workflow load"
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def record_pre_review_command(
|
||||||
|
command: str,
|
||||||
|
*,
|
||||||
|
cwd: str | None = None,
|
||||||
|
project_root: str | None = None,
|
||||||
|
classification: str | None = None,
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Record and classify a pre-review command for the current session."""
|
||||||
|
assessed = classify_pre_review_command(
|
||||||
|
command, cwd=cwd, project_root=project_root)
|
||||||
|
if classification:
|
||||||
|
if classification not in ALLOWED_CLASSIFICATIONS:
|
||||||
|
assessed["classification"] = CLASSIFICATION_UNCLASSIFIED
|
||||||
|
assessed["reasons"] = [
|
||||||
|
f"unknown classification '{classification}'; fail closed"
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
assessed["classification"] = classification
|
||||||
|
assessed["reasons"] = []
|
||||||
|
entry = {
|
||||||
|
**assessed,
|
||||||
|
"session_pid": os.getpid(),
|
||||||
|
}
|
||||||
|
_PRE_REVIEW_COMMANDS.append(entry)
|
||||||
|
return dict(entry)
|
||||||
|
|
||||||
|
|
||||||
|
def assess_boundary_status(project_root: str | None = None) -> dict[str, Any]:
|
||||||
|
"""Summarize pre-review boundary state for session proof and reports."""
|
||||||
|
violations = [
|
||||||
|
entry for entry in _PRE_REVIEW_COMMANDS
|
||||||
|
if entry.get("classification") == CLASSIFICATION_BOUNDARY_VIOLATION
|
||||||
|
]
|
||||||
|
unclassified = [
|
||||||
|
entry for entry in _PRE_REVIEW_COMMANDS
|
||||||
|
if entry.get("classification") == CLASSIFICATION_UNCLASSIFIED
|
||||||
|
]
|
||||||
|
reasons: list[str] = []
|
||||||
|
for entry in violations:
|
||||||
|
reasons.extend(entry.get("reasons") or [
|
||||||
|
f"boundary violation: {entry.get('command', '')[:80]}"
|
||||||
|
])
|
||||||
|
for entry in unclassified:
|
||||||
|
reasons.extend(entry.get("reasons") or [
|
||||||
|
"unclassified pre-review command blocks reviewer mutations"
|
||||||
|
])
|
||||||
|
|
||||||
|
clean = not reasons
|
||||||
|
return {
|
||||||
|
"boundary_status": "clean" if clean else "violation",
|
||||||
|
"boundary_clean": clean,
|
||||||
|
"pre_review_command_count": len(_PRE_REVIEW_COMMANDS),
|
||||||
|
"boundary_violation_count": len(violations),
|
||||||
|
"unclassified_command_count": len(unclassified),
|
||||||
|
"violations": [
|
||||||
|
{
|
||||||
|
"command": v.get("command"),
|
||||||
|
"cwd": v.get("cwd"),
|
||||||
|
"reasons": list(v.get("reasons") or []),
|
||||||
|
}
|
||||||
|
for v in violations
|
||||||
|
],
|
||||||
|
"reasons": reasons,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def boundary_blockers(project_root: str | None = None) -> list[str]:
|
||||||
|
"""Reasons reviewer mutations must fail closed due to boundary state."""
|
||||||
|
status = assess_boundary_status(project_root)
|
||||||
|
if status.get("boundary_clean"):
|
||||||
|
return []
|
||||||
|
return list(status.get("reasons") or [
|
||||||
|
"reviewer session boundary violation before workflow load"
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
def workflow_load_helper_result(
|
||||||
|
load: dict | None,
|
||||||
|
project_root: str | None = None,
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Structured helper result for final reports (#403)."""
|
||||||
|
boundary = assess_boundary_status(project_root)
|
||||||
|
if load is None:
|
||||||
|
return {
|
||||||
|
"workflow_load_proof_present": False,
|
||||||
|
"workflow_source": None,
|
||||||
|
"workflow_hash": None,
|
||||||
|
"final_report_schema_hash": None,
|
||||||
|
"boundary_status": boundary.get("boundary_status"),
|
||||||
|
"boundary_clean": False,
|
||||||
|
"reasons": [
|
||||||
|
"gitea_load_review_workflow helper result missing from report"
|
||||||
|
],
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
"workflow_load_proof_present": True,
|
||||||
|
"workflow_source": load.get("workflow_source"),
|
||||||
|
"workflow_hash": load.get("workflow_hash"),
|
||||||
|
"final_report_schema_path": load.get("final_report_schema_path"),
|
||||||
|
"final_report_schema_hash": load.get("final_report_schema_hash"),
|
||||||
|
"boundary_status": load.get("boundary_status", boundary.get("boundary_status")),
|
||||||
|
"boundary_clean": bool(load.get("boundary_clean", boundary.get("boundary_clean"))),
|
||||||
|
"pre_review_command_count": boundary.get("pre_review_command_count"),
|
||||||
|
"reasons": [],
|
||||||
|
}
|
||||||
@@ -0,0 +1,217 @@
|
|||||||
|
"""Canonical review-merge workflow load proof for reviewer mutations (#389, #403)."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import hashlib
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import review_workflow_boundary as boundary
|
||||||
|
|
||||||
|
WORKFLOW_REL_PATH = (
|
||||||
|
"skills/llm-project-workflow/workflows/review-merge-pr.md"
|
||||||
|
)
|
||||||
|
SCHEMA_REL_PATH = (
|
||||||
|
"skills/llm-project-workflow/schemas/review-merge-final-report.md"
|
||||||
|
)
|
||||||
|
TASK_MODE = "review-merge-pr"
|
||||||
|
LOAD_TOOL_NAME = "gitea_load_review_workflow"
|
||||||
|
|
||||||
|
_REVIEW_WORKFLOW_LOAD: dict | None = None
|
||||||
|
|
||||||
|
|
||||||
|
def compute_content_hash(text: str) -> str:
|
||||||
|
"""Short deterministic hash for workflow/schema version proof."""
|
||||||
|
return hashlib.sha256((text or "").encode("utf-8")).hexdigest()[:12]
|
||||||
|
|
||||||
|
|
||||||
|
def _read_text(path: Path) -> str:
|
||||||
|
return path.read_text(encoding="utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
def _canonical_paths(project_root: str) -> tuple[Path, Path]:
|
||||||
|
root = Path(project_root)
|
||||||
|
workflow = root / WORKFLOW_REL_PATH
|
||||||
|
schema = root / SCHEMA_REL_PATH
|
||||||
|
if not workflow.is_file():
|
||||||
|
raise FileNotFoundError(f"canonical workflow missing: {workflow}")
|
||||||
|
if not schema.is_file():
|
||||||
|
raise FileNotFoundError(f"final report schema missing: {schema}")
|
||||||
|
return workflow, schema
|
||||||
|
|
||||||
|
|
||||||
|
def build_canonical_workflow_metadata(
|
||||||
|
project_root: str,
|
||||||
|
*,
|
||||||
|
prompt_text: str | None = None,
|
||||||
|
) -> dict:
|
||||||
|
"""Load workflow + schema from disk and compute proof metadata."""
|
||||||
|
workflow_path, schema_path = _canonical_paths(project_root)
|
||||||
|
workflow_text = _read_text(workflow_path)
|
||||||
|
schema_text = _read_text(schema_path)
|
||||||
|
workflow_hash = compute_content_hash(workflow_text)
|
||||||
|
schema_hash = compute_content_hash(schema_text)
|
||||||
|
conflict, conflict_reasons = assess_prompt_conflict(prompt_text)
|
||||||
|
return {
|
||||||
|
"workflow_source": WORKFLOW_REL_PATH,
|
||||||
|
"workflow_path": str(workflow_path),
|
||||||
|
"task_mode": TASK_MODE,
|
||||||
|
"workflow_hash": workflow_hash,
|
||||||
|
"workflow_version": workflow_hash,
|
||||||
|
"final_report_schema_path": SCHEMA_REL_PATH,
|
||||||
|
"final_report_schema_hash": schema_hash,
|
||||||
|
"prompt_conflicts_with_workflow": conflict,
|
||||||
|
"prompt_conflict_reasons": conflict_reasons,
|
||||||
|
"load_tool": LOAD_TOOL_NAME,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def assess_prompt_conflict(prompt_text: str | None) -> tuple[bool, list[str]]:
|
||||||
|
"""Detect obvious task-mode conflicts between prompt and review workflow."""
|
||||||
|
if not (prompt_text or "").strip():
|
||||||
|
return False, []
|
||||||
|
text = prompt_text.lower()
|
||||||
|
reasons: list[str] = []
|
||||||
|
conflicting = (
|
||||||
|
(r"\bwork[- ]issue\b", "work-issue author mode"),
|
||||||
|
(r"\bcreate[- ]issue\b", "create-issue mode"),
|
||||||
|
(r"\bauthor/coder\b", "author/coder mode"),
|
||||||
|
(r"\breconcile[- ]landed\b", "reconcile-landed mode"),
|
||||||
|
)
|
||||||
|
for pattern, label in conflicting:
|
||||||
|
if re.search(pattern, text):
|
||||||
|
reasons.append(
|
||||||
|
f"active prompt appears to request {label} while loading "
|
||||||
|
f"{TASK_MODE} workflow"
|
||||||
|
)
|
||||||
|
return bool(reasons), reasons
|
||||||
|
|
||||||
|
|
||||||
|
def record_review_workflow_load(
|
||||||
|
project_root: str,
|
||||||
|
*,
|
||||||
|
prompt_text: str | None = None,
|
||||||
|
) -> dict:
|
||||||
|
"""Record in-process workflow load proof for the current MCP session."""
|
||||||
|
global _REVIEW_WORKFLOW_LOAD
|
||||||
|
meta = build_canonical_workflow_metadata(
|
||||||
|
project_root, prompt_text=prompt_text)
|
||||||
|
boundary_state = boundary.assess_boundary_status(project_root)
|
||||||
|
_REVIEW_WORKFLOW_LOAD = {
|
||||||
|
**meta,
|
||||||
|
"session_pid": os.getpid(),
|
||||||
|
"loaded": True,
|
||||||
|
"boundary_status": boundary_state.get("boundary_status"),
|
||||||
|
"boundary_clean": boundary_state.get("boundary_clean"),
|
||||||
|
"pre_review_command_count": boundary_state.get("pre_review_command_count"),
|
||||||
|
"boundary_violation_count": boundary_state.get("boundary_violation_count"),
|
||||||
|
"boundary_reasons": list(boundary_state.get("reasons") or []),
|
||||||
|
}
|
||||||
|
return dict(_REVIEW_WORKFLOW_LOAD)
|
||||||
|
|
||||||
|
|
||||||
|
def clear_review_workflow_load() -> None:
|
||||||
|
"""Test helper and review_pr session reset."""
|
||||||
|
global _REVIEW_WORKFLOW_LOAD
|
||||||
|
_REVIEW_WORKFLOW_LOAD = None
|
||||||
|
boundary.clear_pre_review_commands()
|
||||||
|
|
||||||
|
|
||||||
|
def workflow_load_status(project_root: str | None = None) -> dict:
|
||||||
|
"""Non-throwing status for capability/runtime reports."""
|
||||||
|
load = _REVIEW_WORKFLOW_LOAD
|
||||||
|
if load is None:
|
||||||
|
return {
|
||||||
|
"workflow_load_proof_present": False,
|
||||||
|
"workflow_load_valid": False,
|
||||||
|
"workflow_source": None,
|
||||||
|
"workflow_hash": None,
|
||||||
|
"final_report_schema_path": SCHEMA_REL_PATH,
|
||||||
|
"reasons": [
|
||||||
|
f"{LOAD_TOOL_NAME} has not been called in this session "
|
||||||
|
"(fail closed for reviewer mutations)"
|
||||||
|
],
|
||||||
|
}
|
||||||
|
reasons = _session_validation_reasons(load, project_root)
|
||||||
|
boundary_reasons = boundary.boundary_blockers(project_root)
|
||||||
|
if boundary_reasons:
|
||||||
|
reasons = list(reasons) + boundary_reasons
|
||||||
|
return {
|
||||||
|
"workflow_load_proof_present": True,
|
||||||
|
"workflow_load_valid": not reasons,
|
||||||
|
"workflow_source": load.get("workflow_source"),
|
||||||
|
"workflow_hash": load.get("workflow_hash"),
|
||||||
|
"task_mode": load.get("task_mode"),
|
||||||
|
"final_report_schema_path": load.get("final_report_schema_path"),
|
||||||
|
"final_report_schema_hash": load.get("final_report_schema_hash"),
|
||||||
|
"prompt_conflicts_with_workflow": load.get(
|
||||||
|
"prompt_conflicts_with_workflow"),
|
||||||
|
"session_pid": load.get("session_pid"),
|
||||||
|
"boundary_status": load.get("boundary_status"),
|
||||||
|
"boundary_clean": load.get("boundary_clean"),
|
||||||
|
"workflow_load_helper_result": boundary.workflow_load_helper_result(
|
||||||
|
load, project_root),
|
||||||
|
"reasons": reasons,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _session_validation_reasons(
|
||||||
|
load: dict,
|
||||||
|
project_root: str | None,
|
||||||
|
) -> list[str]:
|
||||||
|
reasons: list[str] = []
|
||||||
|
if load.get("session_pid") != os.getpid():
|
||||||
|
reasons.append(
|
||||||
|
"workflow load proof was recorded in a different process "
|
||||||
|
"(fail closed)"
|
||||||
|
)
|
||||||
|
return reasons
|
||||||
|
if load.get("prompt_conflicts_with_workflow"):
|
||||||
|
reasons.extend(load.get("prompt_conflict_reasons") or [
|
||||||
|
"active prompt conflicts with loaded review-merge workflow"
|
||||||
|
])
|
||||||
|
if project_root:
|
||||||
|
try:
|
||||||
|
current = build_canonical_workflow_metadata(project_root)
|
||||||
|
except OSError as exc:
|
||||||
|
reasons.append(f"cannot re-verify workflow hash: {exc}")
|
||||||
|
return reasons
|
||||||
|
if current["workflow_hash"] != load.get("workflow_hash"):
|
||||||
|
reasons.append(
|
||||||
|
"stored workflow hash is stale; reload via "
|
||||||
|
f"{LOAD_TOOL_NAME} (fail closed)"
|
||||||
|
)
|
||||||
|
if current["final_report_schema_hash"] != load.get(
|
||||||
|
"final_report_schema_hash"):
|
||||||
|
reasons.append(
|
||||||
|
"stored final-report schema hash is stale; reload via "
|
||||||
|
f"{LOAD_TOOL_NAME} (fail closed)"
|
||||||
|
)
|
||||||
|
return reasons
|
||||||
|
|
||||||
|
|
||||||
|
def review_workflow_load_blockers(
|
||||||
|
project_root: str | None = None,
|
||||||
|
) -> list[str]:
|
||||||
|
"""Reasons reviewer mutations must fail closed."""
|
||||||
|
boundary_reasons = boundary.boundary_blockers(project_root)
|
||||||
|
if boundary_reasons and _REVIEW_WORKFLOW_LOAD is None:
|
||||||
|
return boundary_reasons
|
||||||
|
status = workflow_load_status(project_root)
|
||||||
|
if not status.get("workflow_load_proof_present"):
|
||||||
|
return list(status.get("reasons") or []) + boundary_reasons
|
||||||
|
if not status.get("workflow_load_valid"):
|
||||||
|
return list(status.get("reasons") or [])
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
def recovery_handoff_without_replay() -> list[str]:
|
||||||
|
"""Safe next-step lines that must not include approve/merge replay."""
|
||||||
|
return [
|
||||||
|
"Reload the canonical workflow via gitea_load_review_workflow, then "
|
||||||
|
"rerun the full review-merge workflow from inventory.",
|
||||||
|
"Do not call gitea_submit_pr_review, gitea_mark_final_review_decision, "
|
||||||
|
"or gitea_merge_pr until workflow-load proof is present.",
|
||||||
|
"Do not include approve/merge replay commands in the recovery handoff.",
|
||||||
|
]
|
||||||
@@ -63,8 +63,14 @@ Do not use legacy fields: `Pinned reviewed head`, `Scratch worktree used`,
|
|||||||
- Current status:
|
- Current status:
|
||||||
- Safe next action:
|
- Safe next action:
|
||||||
- Safety statement:
|
- Safety statement:
|
||||||
|
- Workflow-load helper result:
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The **Workflow-load helper result** field must carry structured output from
|
||||||
|
`gitea_load_review_workflow` (workflow_hash, final_report_schema_hash,
|
||||||
|
boundary_status). Narrative claims that workflow files were viewed locally are
|
||||||
|
not sufficient (#403).
|
||||||
|
|
||||||
### Already-landed handoff overrides
|
### Already-landed handoff overrides
|
||||||
|
|
||||||
When eligibility class is `ALREADY_LANDED_RECONCILE_REQUIRED`:
|
When eligibility class is `ALREADY_LANDED_RECONCILE_REQUIRED`:
|
||||||
|
|||||||
@@ -36,6 +36,44 @@ If available, load it first and report:
|
|||||||
|
|
||||||
If the canonical workflow cannot be loaded and the project requires it, stop and produce a recovery handoff only.
|
If the canonical workflow cannot be loaded and the project requires it, stop and produce a recovery handoff only.
|
||||||
|
|
||||||
|
## 0A. Workflow-load and session boundary anchor (#403)
|
||||||
|
|
||||||
|
The MCP gate is the authority — not local file viewing.
|
||||||
|
|
||||||
|
Before any reviewer mutation:
|
||||||
|
|
||||||
|
1. Record pre-review commands with `gitea_record_pre_review_command` when they
|
||||||
|
are not automatically classified (inventory/diagnostic commands may be
|
||||||
|
recorded explicitly for proof).
|
||||||
|
2. Call `gitea_load_review_workflow` to establish workflow hash proof **and**
|
||||||
|
session boundary state in the same in-process session proof.
|
||||||
|
3. Do not claim the workflow was loaded by reading
|
||||||
|
`skills/llm-project-workflow/workflows/review-merge-pr.md` as a local file;
|
||||||
|
that narrative does not satisfy the validator.
|
||||||
|
|
||||||
|
Allowed before workflow load (classify as `read_only_inventory` or
|
||||||
|
`diagnostic`):
|
||||||
|
|
||||||
|
* `gitea_whoami`, `gitea_resolve_task_capability`, `gitea_list_prs`,
|
||||||
|
`gitea_view_pr`, `gitea_get_runtime_context`
|
||||||
|
* `git fetch` / `git remote update` for inventory
|
||||||
|
* `git status`, `git worktree list` (read-only)
|
||||||
|
|
||||||
|
Boundary violations (block downstream reviewer mutations even after load):
|
||||||
|
|
||||||
|
* validation commands (`pytest`, `python -m unittest`) in the main checkout
|
||||||
|
* local profile/credential/config inspection (`profiles.json`, `gitea-mcp.json`,
|
||||||
|
`.env`, keychain dumps)
|
||||||
|
* MCP repair (`pkill`, MCP config edits)
|
||||||
|
* git mutations before workflow load
|
||||||
|
|
||||||
|
Final reports must include a structured **Workflow-load helper result** block
|
||||||
|
copied from `gitea_load_review_workflow`, including at minimum:
|
||||||
|
|
||||||
|
* `workflow_hash`
|
||||||
|
* `final_report_schema_hash`
|
||||||
|
* `boundary_status` (`clean` or `violation`)
|
||||||
|
|
||||||
## 1. Start with live identity, profile, runtime, and capability checks
|
## 1. Start with live identity, profile, runtime, and capability checks
|
||||||
|
|
||||||
Prove:
|
Prove:
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ from unittest.mock import patch
|
|||||||
|
|
||||||
sys.path.insert(0, str(__import__("pathlib").Path(__file__).resolve().parent.parent))
|
sys.path.insert(0, str(__import__("pathlib").Path(__file__).resolve().parent.parent))
|
||||||
|
|
||||||
|
import mcp_server # noqa: E402
|
||||||
from mcp_server import ( # noqa: E402
|
from mcp_server import ( # noqa: E402
|
||||||
gitea_check_pr_eligibility,
|
gitea_check_pr_eligibility,
|
||||||
gitea_merge_pr,
|
gitea_merge_pr,
|
||||||
@@ -130,6 +131,7 @@ class TestShaCannotBypassSelfReview(unittest.TestCase):
|
|||||||
]
|
]
|
||||||
from mcp_server import init_review_decision_lock, gitea_mark_final_review_decision
|
from mcp_server import init_review_decision_lock, gitea_mark_final_review_decision
|
||||||
init_review_decision_lock("prgs", "review_pr")
|
init_review_decision_lock("prgs", "review_pr")
|
||||||
|
mcp_server.gitea_load_review_workflow()
|
||||||
gitea_mark_final_review_decision(9, "approve", remote="prgs")
|
gitea_mark_final_review_decision(9, "approve", remote="prgs")
|
||||||
env = self._env(SHA_WOULD_BE_REVIEWER, "reviewer")
|
env = self._env(SHA_WOULD_BE_REVIEWER, "reviewer")
|
||||||
with patch.dict(os.environ, env, clear=True):
|
with patch.dict(os.environ, env, clear=True):
|
||||||
|
|||||||
@@ -55,6 +55,12 @@ _NO_BLOCKER_FEEDBACK = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _init_reviewer_session(remote="prgs"):
|
||||||
|
"""Seed review decision lock and required workflow-load proof (#389)."""
|
||||||
|
init_review_decision_lock(remote, "review_pr")
|
||||||
|
mcp_server.gitea_load_review_workflow()
|
||||||
|
|
||||||
|
|
||||||
def _mark_request_changes_ready(pr_number=8, **kwargs):
|
def _mark_request_changes_ready(pr_number=8, **kwargs):
|
||||||
"""Mark a request_changes decision ready with the #332 duplicate-
|
"""Mark a request_changes decision ready with the #332 duplicate-
|
||||||
suppression feedback fetch stubbed to 'no existing blocker'."""
|
suppression feedback fetch stubbed to 'no existing blocker'."""
|
||||||
@@ -539,6 +545,9 @@ class TestViewPR(unittest.TestCase):
|
|||||||
class TestMergePR(unittest.TestCase):
|
class TestMergePR(unittest.TestCase):
|
||||||
"""Gated merge workflow (#16). gitea_merge_pr is the only merge path."""
|
"""Gated merge workflow (#16). gitea_merge_pr is the only merge path."""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
mcp_server.gitea_load_review_workflow()
|
||||||
|
|
||||||
def _pr(self, author, state="open", sha="abc123", mergeable=True):
|
def _pr(self, author, state="open", sha="abc123", mergeable=True):
|
||||||
return {
|
return {
|
||||||
"user": {"login": author},
|
"user": {"login": author},
|
||||||
@@ -1011,8 +1020,7 @@ class TestReviewPR(unittest.TestCase):
|
|||||||
{"login": "jcwalker3"}, # /api/v1/user (submit eligibility)
|
{"login": "jcwalker3"}, # /api/v1/user (submit eligibility)
|
||||||
{"user": {"login": "jcwalker3"}, "state": "open", "head": {"sha": "abc1234"}, "mergeable": True}, # /pulls/1
|
{"user": {"login": "jcwalker3"}, "state": "open", "head": {"sha": "abc1234"}, "mergeable": True}, # /pulls/1
|
||||||
]
|
]
|
||||||
from mcp_server import init_review_decision_lock
|
_init_reviewer_session("prgs")
|
||||||
init_review_decision_lock("prgs", "review_pr")
|
|
||||||
gitea_mark_final_review_decision(1, "approve", remote="prgs")
|
gitea_mark_final_review_decision(1, "approve", remote="prgs")
|
||||||
result = gitea_review_pr(
|
result = gitea_review_pr(
|
||||||
pr_number=1,
|
pr_number=1,
|
||||||
@@ -1680,7 +1688,7 @@ class TestReviewDecisionValidationGate(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
init_review_decision_lock("prgs", "review_pr")
|
_init_reviewer_session("prgs")
|
||||||
|
|
||||||
def _env(self):
|
def _env(self):
|
||||||
return patch.dict(os.environ, {
|
return patch.dict(os.environ, {
|
||||||
@@ -1775,7 +1783,7 @@ class TestSubmitPrReview(unittest.TestCase):
|
|||||||
"""Gated review-mutation tool (#15)."""
|
"""Gated review-mutation tool (#15)."""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
init_review_decision_lock("prgs", "review_pr")
|
_init_reviewer_session("prgs")
|
||||||
gitea_mark_final_review_decision(8, "approve", remote="prgs")
|
gitea_mark_final_review_decision(8, "approve", remote="prgs")
|
||||||
|
|
||||||
def _pr(self, author, state="open", sha="abc123", mergeable=True):
|
def _pr(self, author, state="open", sha="abc123", mergeable=True):
|
||||||
@@ -2168,7 +2176,7 @@ class TestSubmitPrReview(unittest.TestCase):
|
|||||||
os.remove(spoof_path)
|
os.remove(spoof_path)
|
||||||
|
|
||||||
def test_mark_final_decision_rejects_remote_mismatch(self):
|
def test_mark_final_decision_rejects_remote_mismatch(self):
|
||||||
init_review_decision_lock("prgs", "review_pr")
|
_init_reviewer_session("prgs")
|
||||||
r = gitea_mark_final_review_decision(8, "approve", remote="dadeschools")
|
r = gitea_mark_final_review_decision(8, "approve", remote="dadeschools")
|
||||||
self.assertFalse(r["marked_ready"])
|
self.assertFalse(r["marked_ready"])
|
||||||
self.assertTrue(any("does not match locked remote" in x for x in r["reasons"]))
|
self.assertTrue(any("does not match locked remote" in x for x in r["reasons"]))
|
||||||
@@ -2250,6 +2258,7 @@ if __name__ == "__main__":
|
|||||||
class TestTrackerHygieneCleanup(unittest.TestCase):
|
class TestTrackerHygieneCleanup(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
mcp_server.gitea_load_review_workflow()
|
||||||
self.mock_api = patch("mcp_server.api_request").start()
|
self.mock_api = patch("mcp_server.api_request").start()
|
||||||
self.mock_auth = patch("mcp_server.get_auth_header", return_value=FAKE_AUTH).start()
|
self.mock_auth = patch("mcp_server.get_auth_header", return_value=FAKE_AUTH).start()
|
||||||
patch("gitea_audit.audit_enabled", return_value=True).start()
|
patch("gitea_audit.audit_enabled", return_value=True).start()
|
||||||
|
|||||||
@@ -230,6 +230,7 @@ class TestEligibilityDenialReport(PermissionReportBase):
|
|||||||
return PR_PAYLOAD
|
return PR_PAYLOAD
|
||||||
mock_api.side_effect = fake_api
|
mock_api.side_effect = fake_api
|
||||||
mcp_server.init_review_decision_lock("prgs", "review_pr")
|
mcp_server.init_review_decision_lock("prgs", "review_pr")
|
||||||
|
mcp_server.gitea_load_review_workflow()
|
||||||
mcp_server.gitea_mark_final_review_decision(42, "approve", remote="prgs")
|
mcp_server.gitea_mark_final_review_decision(42, "approve", remote="prgs")
|
||||||
with patch.dict(os.environ, self._env("author-profile")):
|
with patch.dict(os.environ, self._env("author-profile")):
|
||||||
res = mcp_server.gitea_submit_pr_review(
|
res = mcp_server.gitea_submit_pr_review(
|
||||||
@@ -272,6 +273,7 @@ class TestReviewCommentPathUsesCanonicalOp(PermissionReportBase):
|
|||||||
return PR_PAYLOAD
|
return PR_PAYLOAD
|
||||||
mock_api.side_effect = fake_api
|
mock_api.side_effect = fake_api
|
||||||
mcp_server.init_review_decision_lock("prgs", "review_pr")
|
mcp_server.init_review_decision_lock("prgs", "review_pr")
|
||||||
|
mcp_server.gitea_load_review_workflow()
|
||||||
mcp_server.gitea_mark_final_review_decision(42, "comment", remote="prgs")
|
mcp_server.gitea_mark_final_review_decision(42, "comment", remote="prgs")
|
||||||
with patch.dict(os.environ, self._env("author-profile")):
|
with patch.dict(os.environ, self._env("author-profile")):
|
||||||
res = mcp_server.gitea_submit_pr_review(
|
res = mcp_server.gitea_submit_pr_review(
|
||||||
|
|||||||
@@ -0,0 +1,138 @@
|
|||||||
|
"""Tests for workflow-load session boundary tracking (#403)."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import unittest
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
sys.path.insert(0, str(__import__("pathlib").Path(__file__).resolve().parent.parent))
|
||||||
|
|
||||||
|
import final_report_validator
|
||||||
|
import review_workflow_boundary
|
||||||
|
import review_workflow_load
|
||||||
|
import mcp_server
|
||||||
|
|
||||||
|
|
||||||
|
class TestPreReviewClassification(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
review_workflow_boundary.clear_pre_review_commands()
|
||||||
|
review_workflow_load.clear_review_workflow_load()
|
||||||
|
|
||||||
|
def test_inventory_command_allowed(self):
|
||||||
|
result = review_workflow_boundary.classify_pre_review_command(
|
||||||
|
"gitea_list_prs remote=prgs",
|
||||||
|
cwd="/tmp",
|
||||||
|
project_root="/repo/Gitea-Tools",
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
result["classification"],
|
||||||
|
review_workflow_boundary.CLASSIFICATION_READ_ONLY_INVENTORY,
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_main_checkout_pytest_is_boundary_violation(self):
|
||||||
|
root = "/repo/Gitea-Tools"
|
||||||
|
result = review_workflow_boundary.classify_pre_review_command(
|
||||||
|
"python -m pytest tests/",
|
||||||
|
cwd=root,
|
||||||
|
project_root=root,
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
result["classification"],
|
||||||
|
review_workflow_boundary.CLASSIFICATION_BOUNDARY_VIOLATION,
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_profiles_json_inspection_is_boundary_violation(self):
|
||||||
|
result = review_workflow_boundary.classify_pre_review_command(
|
||||||
|
"cat profiles.json",
|
||||||
|
cwd="/repo/Gitea-Tools",
|
||||||
|
project_root="/repo/Gitea-Tools",
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
result["classification"],
|
||||||
|
review_workflow_boundary.CLASSIFICATION_BOUNDARY_VIOLATION,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TestWorkflowLoadBoundaryGate(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
review_workflow_boundary.clear_pre_review_commands()
|
||||||
|
review_workflow_load.clear_review_workflow_load()
|
||||||
|
mcp_server.init_review_decision_lock("prgs", "review_pr")
|
||||||
|
mcp_server.record_preflight_check("whoami")
|
||||||
|
mcp_server.record_preflight_check("capability", "reviewer")
|
||||||
|
|
||||||
|
def _root(self) -> str:
|
||||||
|
return str(__import__("pathlib").Path(__file__).resolve().parent.parent)
|
||||||
|
|
||||||
|
def test_boundary_violation_blocks_mutation_after_load(self):
|
||||||
|
root = self._root()
|
||||||
|
review_workflow_boundary.record_pre_review_command(
|
||||||
|
"python -m pytest tests/",
|
||||||
|
cwd=root,
|
||||||
|
project_root=root,
|
||||||
|
)
|
||||||
|
res = mcp_server.gitea_load_review_workflow()
|
||||||
|
self.assertFalse(res["success"])
|
||||||
|
self.assertEqual(res["boundary_status"], "violation")
|
||||||
|
blocked = mcp_server.gitea_mark_final_review_decision(
|
||||||
|
42, "approve", remote="prgs")
|
||||||
|
self.assertFalse(blocked["marked_ready"])
|
||||||
|
joined = " ".join(blocked["reasons"]).lower()
|
||||||
|
self.assertTrue(
|
||||||
|
"validation" in joined or "boundary" in joined or "workflow" in joined
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_clean_inventory_then_load_passes(self):
|
||||||
|
root = self._root()
|
||||||
|
review_workflow_boundary.record_pre_review_command(
|
||||||
|
"gitea_list_prs remote=prgs",
|
||||||
|
cwd=root,
|
||||||
|
project_root=root,
|
||||||
|
)
|
||||||
|
res = mcp_server.gitea_load_review_workflow()
|
||||||
|
self.assertTrue(res["success"])
|
||||||
|
self.assertEqual(res["boundary_status"], "clean")
|
||||||
|
blockers = review_workflow_load.review_workflow_load_blockers(root)
|
||||||
|
self.assertEqual(blockers, [])
|
||||||
|
|
||||||
|
def test_file_view_narrative_fails_validator_without_helper(self):
|
||||||
|
report = (
|
||||||
|
"## Controller Handoff\n"
|
||||||
|
"- Task: review-merge-pr\n"
|
||||||
|
"- I read the canonical workflow review-merge-pr.md before review.\n"
|
||||||
|
)
|
||||||
|
findings = final_report_validator.assess_final_report_validator(
|
||||||
|
report,
|
||||||
|
task_kind="review_pr",
|
||||||
|
)
|
||||||
|
self.assertTrue(any(
|
||||||
|
f["rule_id"] == "reviewer.workflow_load_boundary"
|
||||||
|
for f in findings.get("findings") or []
|
||||||
|
))
|
||||||
|
|
||||||
|
def test_helper_result_passes_validator(self):
|
||||||
|
root = self._root()
|
||||||
|
review_workflow_load.record_review_workflow_load(root)
|
||||||
|
helper = review_workflow_boundary.workflow_load_helper_result(
|
||||||
|
review_workflow_load._REVIEW_WORKFLOW_LOAD,
|
||||||
|
root,
|
||||||
|
)
|
||||||
|
report = (
|
||||||
|
"## Controller Handoff\n"
|
||||||
|
"- Task: review-merge-pr\n"
|
||||||
|
f"- Workflow-load helper result: workflow_hash: {helper['workflow_hash']}; "
|
||||||
|
f"boundary_status: {helper['boundary_status']}\n"
|
||||||
|
)
|
||||||
|
findings = final_report_validator.assess_final_report_validator(
|
||||||
|
report,
|
||||||
|
task_kind="review_pr",
|
||||||
|
)
|
||||||
|
boundary_findings = [
|
||||||
|
f for f in (findings.get("findings") or [])
|
||||||
|
if f.get("rule_id") == "reviewer.workflow_load_boundary"
|
||||||
|
]
|
||||||
|
self.assertEqual(boundary_findings, [])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
"""Tests for canonical review workflow load proof (#389)."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import unittest
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
sys.path.insert(0, str(__import__("pathlib").Path(__file__).resolve().parent.parent))
|
||||||
|
|
||||||
|
import review_workflow_load
|
||||||
|
import mcp_server
|
||||||
|
|
||||||
|
|
||||||
|
class TestReviewWorkflowLoadModule(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
review_workflow_load.clear_review_workflow_load()
|
||||||
|
mcp_server._save_review_decision_lock(None)
|
||||||
|
|
||||||
|
def test_load_records_hash_and_schema(self):
|
||||||
|
root = str(__import__("pathlib").Path(__file__).resolve().parent.parent)
|
||||||
|
recorded = review_workflow_load.record_review_workflow_load(root)
|
||||||
|
self.assertEqual(
|
||||||
|
recorded["workflow_source"],
|
||||||
|
review_workflow_load.WORKFLOW_REL_PATH,
|
||||||
|
)
|
||||||
|
self.assertEqual(recorded["task_mode"], "review-merge-pr")
|
||||||
|
self.assertRegex(recorded["workflow_hash"], r"^[0-9a-f]{12}$")
|
||||||
|
self.assertEqual(
|
||||||
|
recorded["final_report_schema_path"],
|
||||||
|
review_workflow_load.SCHEMA_REL_PATH,
|
||||||
|
)
|
||||||
|
status = review_workflow_load.workflow_load_status(root)
|
||||||
|
self.assertTrue(status["workflow_load_proof_present"])
|
||||||
|
self.assertTrue(status["workflow_load_valid"])
|
||||||
|
|
||||||
|
def test_stale_session_pid_blocks(self):
|
||||||
|
root = str(__import__("pathlib").Path(__file__).resolve().parent.parent)
|
||||||
|
review_workflow_load.record_review_workflow_load(root)
|
||||||
|
review_workflow_load._REVIEW_WORKFLOW_LOAD["session_pid"] = 0
|
||||||
|
blockers = review_workflow_load.review_workflow_load_blockers(root)
|
||||||
|
self.assertTrue(any("different process" in b for b in blockers))
|
||||||
|
|
||||||
|
def test_prompt_conflict_detected(self):
|
||||||
|
conflict, reasons = review_workflow_load.assess_prompt_conflict(
|
||||||
|
"Run work-issue author implementation only")
|
||||||
|
self.assertTrue(conflict)
|
||||||
|
self.assertTrue(reasons)
|
||||||
|
|
||||||
|
|
||||||
|
class TestReviewWorkflowLoadGates(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
review_workflow_load.clear_review_workflow_load()
|
||||||
|
mcp_server.init_review_decision_lock("prgs", "review_pr")
|
||||||
|
mcp_server.record_preflight_check("whoami")
|
||||||
|
mcp_server.record_preflight_check("capability", "reviewer")
|
||||||
|
|
||||||
|
def _load_workflow(self):
|
||||||
|
return mcp_server.gitea_load_review_workflow()
|
||||||
|
|
||||||
|
def test_mcp_helper_returns_required_fields(self):
|
||||||
|
res = self._load_workflow()
|
||||||
|
self.assertTrue(res["success"])
|
||||||
|
self.assertTrue(res["loaded"])
|
||||||
|
self.assertIn("workflow_source", res)
|
||||||
|
self.assertIn("workflow_hash", res)
|
||||||
|
self.assertIn("final_report_schema_path", res)
|
||||||
|
self.assertIn("final_report_schema_hash", res)
|
||||||
|
|
||||||
|
def test_mark_final_blocked_without_load(self):
|
||||||
|
res = mcp_server.gitea_mark_final_review_decision(
|
||||||
|
42, "approve", remote="prgs")
|
||||||
|
self.assertFalse(res["marked_ready"])
|
||||||
|
self.assertTrue(any(
|
||||||
|
"gitea_load_review_workflow" in r for r in res["reasons"]))
|
||||||
|
self.assertTrue(any(
|
||||||
|
"approve/merge replay" in r.lower() or "Do not call" in r
|
||||||
|
for r in res["reasons"]))
|
||||||
|
|
||||||
|
def test_submit_review_blocked_without_load(self):
|
||||||
|
with patch("mcp_server.gitea_check_pr_eligibility") as elig:
|
||||||
|
elig.return_value = {
|
||||||
|
"eligible": True,
|
||||||
|
"authenticated_user": "rev",
|
||||||
|
"profile_name": "prgs-reviewer",
|
||||||
|
"pr_author": "author",
|
||||||
|
"head_sha": "abc123",
|
||||||
|
"reasons": [],
|
||||||
|
}
|
||||||
|
res = mcp_server.gitea_submit_pr_review(
|
||||||
|
42,
|
||||||
|
"approve",
|
||||||
|
remote="prgs",
|
||||||
|
final_review_decision_ready=True,
|
||||||
|
)
|
||||||
|
self.assertFalse(res["performed"])
|
||||||
|
self.assertTrue(any(
|
||||||
|
"gitea_load_review_workflow" in r for r in res["reasons"]))
|
||||||
|
|
||||||
|
def test_merge_blocked_without_load(self):
|
||||||
|
res = mcp_server.gitea_merge_pr(
|
||||||
|
42,
|
||||||
|
confirmation="MERGE PR 42",
|
||||||
|
remote="prgs",
|
||||||
|
)
|
||||||
|
self.assertFalse(res["performed"])
|
||||||
|
self.assertTrue(any(
|
||||||
|
"gitea_load_review_workflow" in r for r in res["reasons"]))
|
||||||
|
|
||||||
|
def test_resolve_capability_reports_missing_load(self):
|
||||||
|
with patch.object(mcp_server, "_ensure_matching_profile"):
|
||||||
|
with patch.object(
|
||||||
|
mcp_server.gitea_config, "is_runtime_switching_enabled",
|
||||||
|
return_value=False):
|
||||||
|
with patch.object(
|
||||||
|
mcp_server, "_authenticated_username",
|
||||||
|
return_value="rev"):
|
||||||
|
res = mcp_server.gitea_resolve_task_capability(
|
||||||
|
"review_pr", remote="prgs")
|
||||||
|
proof = res.get("workflow_load_proof") or {}
|
||||||
|
self.assertFalse(proof.get("workflow_load_valid"))
|
||||||
|
self.assertTrue(any(
|
||||||
|
"gitea_load_review_workflow" in g
|
||||||
|
for g in res.get("task_role_guidance") or []))
|
||||||
|
|
||||||
|
def test_init_review_lock_clears_prior_load(self):
|
||||||
|
self._load_workflow()
|
||||||
|
mcp_server.init_review_decision_lock("prgs", "review_pr")
|
||||||
|
blockers = review_workflow_load.review_workflow_load_blockers(
|
||||||
|
str(__import__("pathlib").Path(__file__).resolve().parent.parent))
|
||||||
|
self.assertTrue(blockers)
|
||||||
|
|
||||||
|
def test_dry_run_allowed_without_load(self):
|
||||||
|
with patch("mcp_server.gitea_check_pr_eligibility") as elig:
|
||||||
|
elig.return_value = {
|
||||||
|
"eligible": True,
|
||||||
|
"authenticated_user": "rev",
|
||||||
|
"profile_name": "prgs-reviewer",
|
||||||
|
"pr_author": "author",
|
||||||
|
"head_sha": "abc123",
|
||||||
|
"reasons": [],
|
||||||
|
}
|
||||||
|
res = mcp_server.gitea_dry_run_pr_review(
|
||||||
|
42, "approve", remote="prgs")
|
||||||
|
self.assertNotIn(
|
||||||
|
"gitea_load_review_workflow",
|
||||||
|
" ".join(res.get("reasons") or []),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Reference in New Issue
Block a user