mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-08 06:54:24 +00:00
fix(review): enforce behavioral sweep validation
This commit is contained in:
104
scripts/pr
104
scripts/pr
@@ -505,6 +505,13 @@ EOF_MD
|
||||
"status": "none",
|
||||
"summary": "No optional nits identified."
|
||||
},
|
||||
"behavioralSweep": {
|
||||
"performed": true,
|
||||
"status": "not_applicable",
|
||||
"summary": "No runtime branch-level behavior changes require sweep evidence.",
|
||||
"silentDropRisk": "none",
|
||||
"branches": []
|
||||
},
|
||||
"issueValidation": {
|
||||
"performed": true,
|
||||
"source": "pr_body",
|
||||
@@ -532,6 +539,7 @@ review_validate_artifacts() {
|
||||
require_artifact .local/review.md
|
||||
require_artifact .local/review.json
|
||||
require_artifact .local/pr-meta.env
|
||||
require_artifact .local/pr-meta.json
|
||||
|
||||
review_guard "$pr"
|
||||
|
||||
@@ -644,11 +652,107 @@ review_validate_artifacts() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local runtime_file_count
|
||||
runtime_file_count=$(jq '[.files[]? | (.path // "") | select(test("^(src|extensions|apps)/")) | select(test("(^|/)__tests__/|\\.test\\.|\\.spec\\.") | not) | select(test("\\.(md|mdx)$") | not)] | length' .local/pr-meta.json)
|
||||
|
||||
local runtime_review_required="false"
|
||||
if [ "$runtime_file_count" -gt 0 ]; then
|
||||
runtime_review_required="true"
|
||||
fi
|
||||
|
||||
local behavioral_sweep_performed
|
||||
behavioral_sweep_performed=$(jq -r '.behavioralSweep.performed // empty' .local/review.json)
|
||||
if [ "$behavioral_sweep_performed" != "true" ]; then
|
||||
echo "Invalid behavioral sweep in .local/review.json: behavioralSweep.performed must be true"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local behavioral_sweep_status
|
||||
behavioral_sweep_status=$(jq -r '.behavioralSweep.status // ""' .local/review.json)
|
||||
case "$behavioral_sweep_status" in
|
||||
"pass"|"needs_work"|"not_applicable")
|
||||
;;
|
||||
*)
|
||||
echo "Invalid behavioral sweep status in .local/review.json: $behavioral_sweep_status"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
local behavioral_sweep_risk
|
||||
behavioral_sweep_risk=$(jq -r '.behavioralSweep.silentDropRisk // ""' .local/review.json)
|
||||
case "$behavioral_sweep_risk" in
|
||||
"none"|"present"|"unknown")
|
||||
;;
|
||||
*)
|
||||
echo "Invalid behavioral sweep risk in .local/review.json: $behavioral_sweep_risk"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
local invalid_behavioral_summary_count
|
||||
invalid_behavioral_summary_count=$(jq '[.behavioralSweep.summary | select((type != "string") or (gsub("^\\s+|\\s+$";"") | length == 0))] | length' .local/review.json)
|
||||
if [ "$invalid_behavioral_summary_count" -gt 0 ]; then
|
||||
echo "Invalid behavioral sweep summary in .local/review.json: behavioralSweep.summary must be a non-empty string"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local behavioral_branches_is_array
|
||||
behavioral_branches_is_array=$(jq -r 'if (.behavioralSweep.branches | type) == "array" then "true" else "false" end' .local/review.json)
|
||||
if [ "$behavioral_branches_is_array" != "true" ]; then
|
||||
echo "Invalid behavioral sweep in .local/review.json: behavioralSweep.branches must be an array"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local invalid_behavioral_branch_count
|
||||
invalid_behavioral_branch_count=$(jq '[.behavioralSweep.branches[]? | select((.path|type)!="string" or (.decision|type)!="string" or (.outcome|type)!="string")] | length' .local/review.json)
|
||||
if [ "$invalid_behavioral_branch_count" -gt 0 ]; then
|
||||
echo "Invalid behavioral sweep branch entry in .local/review.json: each branch needs string path/decision/outcome"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local behavioral_branch_count
|
||||
behavioral_branch_count=$(jq '[.behavioralSweep.branches[]?] | length' .local/review.json)
|
||||
|
||||
if [ "$runtime_review_required" = "true" ] && [ "$behavioral_sweep_status" = "not_applicable" ]; then
|
||||
echo "Invalid behavioral sweep in .local/review.json: runtime file changes require behavioralSweep.status=pass|needs_work"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$runtime_review_required" = "true" ] && [ "$behavioral_branch_count" -lt 1 ]; then
|
||||
echo "Invalid behavioral sweep in .local/review.json: runtime file changes require at least one branch entry"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$behavioral_sweep_status" = "not_applicable" ] && [ "$behavioral_branch_count" -gt 0 ]; then
|
||||
echo "Invalid behavioral sweep in .local/review.json: not_applicable cannot include branch entries"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$behavioral_sweep_status" = "pass" ] && [ "$behavioral_sweep_risk" != "none" ]; then
|
||||
echo "Invalid behavioral sweep in .local/review.json: status=pass requires silentDropRisk=none"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$recommendation" = "READY FOR /prepare-pr" ] && [ "$issue_validation_status" != "valid" ]; then
|
||||
echo "Invalid recommendation in .local/review.json: READY FOR /prepare-pr requires issueValidation.status=valid"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$recommendation" = "READY FOR /prepare-pr" ] && [ "$behavioral_sweep_status" = "needs_work" ]; then
|
||||
echo "Invalid recommendation in .local/review.json: READY FOR /prepare-pr requires behavioralSweep.status!=needs_work"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$recommendation" = "READY FOR /prepare-pr" ] && [ "$runtime_review_required" = "true" ] && [ "$behavioral_sweep_status" != "pass" ]; then
|
||||
echo "Invalid recommendation in .local/review.json: READY FOR /prepare-pr on runtime changes requires behavioralSweep.status=pass"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$recommendation" = "READY FOR /prepare-pr" ] && [ "$behavioral_sweep_risk" = "present" ]; then
|
||||
echo "Invalid recommendation in .local/review.json: READY FOR /prepare-pr is not allowed when behavioralSweep.silentDropRisk=present"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local docs_status
|
||||
docs_status=$(jq -r '.docs // ""' .local/review.json)
|
||||
case "$docs_status" in
|
||||
|
||||
Reference in New Issue
Block a user