fix(docgov): drop thin pi_narrative stub after agent PU7 merge
Use ResolveChangeReport from feature/pu7-pi-narrative. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,64 +0,0 @@
|
||||
package docrevision
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// PIChangeReportNarrativeEnabled reports PI_CHANGE_REPORT_NARRATIVE (default off).
|
||||
func PIChangeReportNarrativeEnabled() bool {
|
||||
v := strings.TrimSpace(os.Getenv("PI_CHANGE_REPORT_NARRATIVE"))
|
||||
return v == "1" || strings.EqualFold(v, "true") || strings.EqualFold(v, "yes")
|
||||
}
|
||||
|
||||
// SelectChangeReportJSON chooses PI narrative JSON only when the flag is on and
|
||||
// the payload validates; otherwise returns deterministic fallback JSON. Never
|
||||
// mixes partial PI fields with factual risk/hunks.
|
||||
func SelectChangeReportJSON(piJSON, deterministicJSON, inputSHA, outputSHA, ruleRisk string, impacts []DocImpact, hunks []DiffHunk) string {
|
||||
if !PIChangeReportNarrativeEnabled() {
|
||||
return deterministicJSON
|
||||
}
|
||||
piJSON = strings.TrimSpace(piJSON)
|
||||
if piJSON == "" {
|
||||
return deterministicJSON
|
||||
}
|
||||
rep, err := ValidateChangeReportJSON(piJSON, inputSHA, outputSHA, ruleRisk, impacts, hunks)
|
||||
if err != nil || rep == nil {
|
||||
return deterministicJSON
|
||||
}
|
||||
// Forbid overriding server risk floor via narrative.
|
||||
if rep.RiskLevel != "" && riskRank(rep.RiskLevel) < riskRank(ruleRisk) {
|
||||
return deterministicJSON
|
||||
}
|
||||
return piJSON
|
||||
}
|
||||
|
||||
func riskRank(level string) int {
|
||||
switch strings.ToLower(strings.TrimSpace(level)) {
|
||||
case "low":
|
||||
return 1
|
||||
case "medium":
|
||||
return 2
|
||||
case "high":
|
||||
return 3
|
||||
case "critical":
|
||||
return 4
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
// NarrativeMetaForUI marks whether the active report body is PI narrative or factual fallback.
|
||||
func NarrativeMetaForUI(analysisStatus string) map[string]any {
|
||||
meta := map[string]any{
|
||||
"narrative_enabled": PIChangeReportNarrativeEnabled(),
|
||||
"source": "deterministic_fallback",
|
||||
}
|
||||
if analysisStatus == AnalysisComplete && PIChangeReportNarrativeEnabled() {
|
||||
meta["source"] = "pi_narrative"
|
||||
}
|
||||
b, _ := json.Marshal(meta)
|
||||
_ = b
|
||||
return meta
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package docrevision
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestPINarrativeFlagDefaultOff(t *testing.T) {
|
||||
t.Setenv("PI_CHANGE_REPORT_NARRATIVE", "")
|
||||
if PIChangeReportNarrativeEnabled() {
|
||||
t.Fatal("default off")
|
||||
}
|
||||
det := `{"ok":true}`
|
||||
got := SelectChangeReportJSON(`{"pi":true}`, det, "a", "b", "low", nil, nil)
|
||||
if got != det {
|
||||
t.Fatalf("flag off must use deterministic, got %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPINarrativeMalformedFallsBack(t *testing.T) {
|
||||
t.Setenv("PI_CHANGE_REPORT_NARRATIVE", "1")
|
||||
det := BuildDeterministicChangeReportJSON("from", "to", "medium", nil, DiffResult{})
|
||||
got := SelectChangeReportJSON("{not-json", det, "from", "to", "medium", nil, nil)
|
||||
if got != det {
|
||||
t.Fatal("malformed must full fallback")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user