From 778fb690389a5305aee7b1e77dc1dc698102eab2 Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Fri, 4 Dec 2026 16:26:50 -0600 Subject: [PATCH] Add OpsProof post-change reports --- apps/opsproof/README.md | 14 +++- ..._000003_create_opsproof_workflow_tables.go | 1 + ...04_000004_create_incident_reports_table.go | 29 ++++++++ .../overlay/database/migrations/migrations.go | 1 + .../overlay/handlers/execution/show.go | 71 ++++++++++++++++++ apps/opsproof/overlay/handlers/report/show.go | 21 ++++++ apps/opsproof/overlay/models/remediation.go | 22 ++++++ .../overlay/resources/js/pages/Execution.tsx | 6 ++ .../overlay/resources/js/pages/Report.tsx | 74 +++++++++++++++++++ apps/opsproof/overlay/routes/web.go | 2 + .../overlay/tests/feature/proposal_test.go | 7 +- docs/opsproof-architecture.md | 3 + .../jeannie/test_privacy_services_pipeline.py | 13 ++++ 13 files changed, 257 insertions(+), 7 deletions(-) create mode 100644 apps/opsproof/overlay/database/migrations/2026_12_04_000004_create_incident_reports_table.go create mode 100644 apps/opsproof/overlay/handlers/report/show.go create mode 100644 apps/opsproof/overlay/resources/js/pages/Report.tsx diff --git a/apps/opsproof/README.md b/apps/opsproof/README.md index 80a3807..d5c5127 100644 --- a/apps/opsproof/README.md +++ b/apps/opsproof/README.md @@ -67,9 +67,8 @@ names and cannot become arbitrary Jeannie arguments. For warning or failing evidence, the same page now builds a proposal-only view model tied to the Doctor execution and evidence IDs. It shows the exact focused Jeannie/Holmes action, preconditions, risk, deterministic validation, -and the absence of a target-specific rollback. A proposal stays blocked and -cannot be approved or executed until later slices add identity, authorization, -current-evidence validation, and a validated rollback. +and the absence of a target-specific rollback. It cannot become durable until +an authenticated operator supplies that rollback procedure. Operator mode uses a dedicated Dex OAuth client through Laravel Go's social provider support. The authorization-code flow uses PKCE and server-side @@ -88,6 +87,13 @@ the fixed argument shape, and then records the returned execution ID. The execution page polls that ID and persists bounded progress output; it never submits another command while refreshing. +After an execution reaches a terminal state, OpsProof automatically runs the +same focused Doctor target again. It retains the before/after evidence and +bounded execution output in a durable incident report with findings, +diagnostic, Five Whys, mitigation, validation, and recommendation sections. +Failed or incomplete validation is recorded explicitly instead of being shown +as a successful repair. + ## Security boundary OpsProof is not a shell console. @@ -116,7 +122,7 @@ Each slice should be a small, independently testable commit: blocked, non-executable proposal); 6. Dex login and operator authorization (implemented); 7. approval-gated execution and live progress (implemented); -8. post-change validation and incident report; +8. post-change validation and incident report (implemented); 9. sanitized public demo mode and portfolio link. ## Initial demonstration diff --git a/apps/opsproof/overlay/database/migrations/2026_12_04_000003_create_opsproof_workflow_tables.go b/apps/opsproof/overlay/database/migrations/2026_12_04_000003_create_opsproof_workflow_tables.go index 7b8b88d..2e8aa4a 100644 --- a/apps/opsproof/overlay/database/migrations/2026_12_04_000003_create_opsproof_workflow_tables.go +++ b/apps/opsproof/overlay/database/migrations/2026_12_04_000003_create_opsproof_workflow_tables.go @@ -41,6 +41,7 @@ func createOpsProofWorkflowTables(ctx context.Context) error { table.String("status") table.LongText("output") table.Text("error") + table.BigInteger("report_id").Default(0) table.Timestamps() }) } diff --git a/apps/opsproof/overlay/database/migrations/2026_12_04_000004_create_incident_reports_table.go b/apps/opsproof/overlay/database/migrations/2026_12_04_000004_create_incident_reports_table.go new file mode 100644 index 0000000..5364256 --- /dev/null +++ b/apps/opsproof/overlay/database/migrations/2026_12_04_000004_create_incident_reports_table.go @@ -0,0 +1,29 @@ +package migrations + +import ( + "context" + + "go.laravel.com/schema" +) + +func createIncidentReportsTable(ctx context.Context) error { + return schema.Create(ctx, "incident_reports", func(table *schema.Blueprint) { + table.ID() + table.BigInteger("execution_id") + table.BigInteger("proposal_id") + table.String("scope") + table.String("target") + table.String("outcome") + table.LongText("findings") + table.LongText("diagnostic") + table.LongText("five_whys_json") + table.LongText("mitigation") + table.LongText("validation") + table.LongText("recommendation") + table.LongText("before_evidence_json") + table.LongText("after_evidence_json") + table.LongText("execution_output") + table.String("approved_by") + table.Timestamps() + }) +} diff --git a/apps/opsproof/overlay/database/migrations/migrations.go b/apps/opsproof/overlay/database/migrations/migrations.go index a49b58c..30cb11b 100644 --- a/apps/opsproof/overlay/database/migrations/migrations.go +++ b/apps/opsproof/overlay/database/migrations/migrations.go @@ -7,4 +7,5 @@ var All = []db.Migration{ {Name: "0001_01_01_000001_create_cache_table", Run: createCacheTable}, {Name: "0001_01_01_000002_create_jobs_table", Run: createJobsTable}, {Name: "2026_12_04_000003_create_opsproof_workflow_tables", Run: createOpsProofWorkflowTables}, + {Name: "2026_12_04_000004_create_incident_reports_table", Run: createIncidentReportsTable}, } diff --git a/apps/opsproof/overlay/handlers/execution/show.go b/apps/opsproof/overlay/handlers/execution/show.go index 42dbb29..5e24948 100644 --- a/apps/opsproof/overlay/handlers/execution/show.go +++ b/apps/opsproof/overlay/handlers/execution/show.go @@ -1,6 +1,10 @@ package execution import ( + "encoding/json" + "fmt" + "strings" + "go.laravel.com/db" "go.laravel.com/inertia" "go.laravel.com/model" @@ -32,12 +36,79 @@ func Show(request *web.Request) *web.Response { }); err != nil { return web.Fail(err) } + execution.Status, execution.Output, execution.Error = remote.Status, remote.Output, remote.Error if remote.Status == "succeeded" || remote.Status == "failed" { if err := model.Update(request, &proposal, db.Values{"status": remote.Status}); err != nil { return web.Fail(err) } + if execution.ReportID == 0 { + reportID, err := createReport(request, &execution, proposal) + if err != nil { + return web.Fail(err) + } + execution.ReportID = reportID + } } return inertia.Render("Execution", inertia.Props{ "view": inertia.Props{"execution": execution, "proposal": proposal}, }) } + +func createReport(request *web.Request, execution *models.OperationExecution, proposal models.RemediationProposal) (int64, error) { + client := services.From(request.Context()).Jeannie + after, validationErr := client.Doctor(request.Context(), proposal.Scope, proposal.Target) + afterJSON := "[]" + remaining := 0 + firstCause := "No warning or failing evidence remained after the action." + if validationErr == nil { + encoded, err := json.Marshal(after.Evidence) + if err != nil { + return 0, err + } + afterJSON = string(encoded) + for _, evidence := range after.Evidence { + if evidence.Status == "warn" || evidence.Status == "fail" { + remaining++ + if firstCause == "No warning or failing evidence remained after the action." && strings.TrimSpace(evidence.Cause) != "" { + firstCause = evidence.Cause + } + } + } + } + + outcome := "validated" + validation := fmt.Sprintf("A fresh focused Doctor run found %d warning or failing evidence item(s).", remaining) + if validationErr != nil { + outcome = "validation-failed" + validation = "Fresh focused Doctor validation could not complete: " + validationErr.Error() + } else if execution.Status != "succeeded" || remaining > 0 { + outcome = "needs-attention" + } + + arguments := proposal.ArgumentsJSON + findings := fmt.Sprintf("Proposal %d cited evidence fingerprint %s. Jeannie execution %s finished with status %s.", proposal.ID, proposal.EvidenceHash, execution.JeannieExecutionID, execution.Status) + diagnostic := "Before the action, focused Doctor evidence supported the reviewed proposal. After the action: " + firstCause + whys, _ := json.Marshal([]string{ + "Why was an operation considered? The stored focused Doctor run contained warning or failing evidence.", + "Why was this exact operation selected? It was the immutable Jeannie command and argument set attached to the proposal.", + "Why was it allowed to run? A logged-in operator approved the proposal after its evidence fingerprint was revalidated.", + "Why is the result considered " + outcome + "? The terminal execution state and fresh Doctor evidence produced that outcome.", + "Why can recurrence be acted on? Keep the focused Doctor check, rollback procedure, and this before/after report as the repeatable control.", + }) + report := models.IncidentReport{ + ExecutionID: execution.ID, ProposalID: proposal.ID, Scope: proposal.Scope, Target: proposal.Target, + Outcome: outcome, Findings: findings, Diagnostic: diagnostic, FiveWhysJSON: string(whys), + Mitigation: fmt.Sprintf("Jeannie executed %s with arguments %s. The operator-supplied rollback procedure was: %s", proposal.Command, arguments, proposal.Rollback), + Validation: validation, + Recommendation: "If the same evidence returns, compare it with this report before approving another action; update the focused Doctor check when it cannot distinguish desired from actual state.", + BeforeEvidenceJSON: proposal.EvidenceJSON, AfterEvidenceJSON: afterJSON, + ExecutionOutput: execution.Output, ApprovedBy: proposal.CreatedBy, + } + if err := model.Create(request, &report); err != nil { + return 0, err + } + if err := model.Update(request, execution, db.Values{"report_id": report.ID}); err != nil { + return 0, err + } + return report.ID, nil +} diff --git a/apps/opsproof/overlay/handlers/report/show.go b/apps/opsproof/overlay/handlers/report/show.go new file mode 100644 index 0000000..6fb16ba --- /dev/null +++ b/apps/opsproof/overlay/handlers/report/show.go @@ -0,0 +1,21 @@ +package report + +import ( + "go.laravel.com/inertia" + "go.laravel.com/model" + "go.laravel.com/web" + + "app/models" +) + +func Show(request *web.Request) *web.Response { + id, err := request.PathInt("report") + if err != nil { + return web.Fail(err) + } + report, err := model.Query[models.IncidentReport]().Find(request, id) + if err != nil { + return web.Fail(err) + } + return inertia.Render("Report", inertia.Props{"report": report}) +} diff --git a/apps/opsproof/overlay/models/remediation.go b/apps/opsproof/overlay/models/remediation.go index 288c52a..3dad9a5 100644 --- a/apps/opsproof/overlay/models/remediation.go +++ b/apps/opsproof/overlay/models/remediation.go @@ -36,6 +36,28 @@ type OperationExecution struct { Status string `json:"status"` Output string `json:"output"` Error string `json:"error"` + ReportID int64 `json:"report_id"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` +} + +type IncidentReport struct { + ID int64 `json:"id"` + ExecutionID int64 `json:"execution_id"` + ProposalID int64 `json:"proposal_id"` + Scope string `json:"scope"` + Target string `json:"target"` + Outcome string `json:"outcome"` + Findings string `json:"findings"` + Diagnostic string `json:"diagnostic"` + FiveWhysJSON string `json:"five_whys_json"` + Mitigation string `json:"mitigation"` + Validation string `json:"validation"` + Recommendation string `json:"recommendation"` + BeforeEvidenceJSON string `json:"before_evidence_json"` + AfterEvidenceJSON string `json:"after_evidence_json"` + ExecutionOutput string `json:"execution_output"` + ApprovedBy string `json:"approved_by"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } diff --git a/apps/opsproof/overlay/resources/js/pages/Execution.tsx b/apps/opsproof/overlay/resources/js/pages/Execution.tsx index 1fca85c..32627a5 100644 --- a/apps/opsproof/overlay/resources/js/pages/Execution.tsx +++ b/apps/opsproof/overlay/resources/js/pages/Execution.tsx @@ -8,6 +8,7 @@ interface ExecutionView { status: string; output: string; error: string; + report_id: number; }; proposal: { id: number; @@ -41,6 +42,11 @@ export default function ExecutionPage({ view }: { view: ExecutionView }) { {view.execution.output || (active ? 'Waiting for Jeannie output…' : view.execution.error || 'No output returned.')} {active &&

Refreshing every two seconds.

} + {!active && view.execution.report_id > 0 && ( + + Open incident report + + )} diff --git a/apps/opsproof/overlay/resources/js/pages/Report.tsx b/apps/opsproof/overlay/resources/js/pages/Report.tsx new file mode 100644 index 0000000..d2a726f --- /dev/null +++ b/apps/opsproof/overlay/resources/js/pages/Report.tsx @@ -0,0 +1,74 @@ +interface Report { + id: number; + execution_id: number; + scope: string; + target: string; + outcome: string; + findings: string; + diagnostic: string; + five_whys_json: string; + mitigation: string; + validation: string; + recommendation: string; + before_evidence_json: string; + after_evidence_json: string; + execution_output: string; + approved_by: string; + created_at: string; +} + +function list(value: string): string[] { + try { + const parsed = JSON.parse(value); + return Array.isArray(parsed) ? parsed.map(String) : []; + } catch { + return []; + } +} + +export default function ReportPage({ report }: { report: Report }) { + return ( +
+
+

Evidence-backed incident report

+
+

{report.scope} / {report.target}

+ + {report.outcome} + +
+ +
+ {[ + ['Findings', report.findings], + ['Diagnostic', report.diagnostic], + ['Mitigation', report.mitigation], + ['Validation', report.validation], + ['Recommendation', report.recommendation], + ].map(([heading, body]) => ( +
+

{heading}

+

{body}

+
+ ))} + +
+

Five Whys

+
    + {list(report.five_whys_json).map((item, index) =>
  1. {index + 1}. {item}
  2. )} +
+
+ +
+

Bounded execution output

+
+                            {report.execution_output || 'No execution output was returned.'}
+                        
+
+
+ +

Approved by {report.approved_by} · report {report.id} · execution {report.execution_id}

+
+
+ ); +} diff --git a/apps/opsproof/overlay/routes/web.go b/apps/opsproof/overlay/routes/web.go index aa159e4..dfc0c90 100644 --- a/apps/opsproof/overlay/routes/web.go +++ b/apps/opsproof/overlay/routes/web.go @@ -12,6 +12,7 @@ import ( "app/handlers/execution" "app/handlers/incident" "app/handlers/proposal" + "app/handlers/report" "app/handlers/welcome" appmiddleware "app/middleware" ) @@ -28,6 +29,7 @@ func Web(route *routing.Router, cfg *config.Config) { operator.Get("/proposals/{proposal}", proposal.Show) operator.Post("/proposals/{proposal}/approval", proposal.Approve) operator.Get("/executions/{execution}", execution.Show) + operator.Get("/reports/{report}", report.Show) route.Fallback(func(*web.Request) *web.Response { return web.Abort(http.StatusNotFound) diff --git a/apps/opsproof/overlay/tests/feature/proposal_test.go b/apps/opsproof/overlay/tests/feature/proposal_test.go index a818f61..e37e3c3 100644 --- a/apps/opsproof/overlay/tests/feature/proposal_test.go +++ b/apps/opsproof/overlay/tests/feature/proposal_test.go @@ -31,10 +31,10 @@ func TestProposalApprovalRevalidatesAndSubmitsExactDoctorAction(t *testing.T) { } doctorRequests++ _, _ = response.Write([]byte(`{"id":"doctor-` + string(rune('0'+doctorRequests)) + `","status":"queued"}`)) - case "/v1/executions/doctor-1", "/v1/executions/doctor-2": + case "/v1/executions/doctor-1", "/v1/executions/doctor-2", "/v1/executions/doctor-3": _, _ = response.Write([]byte(`{"id":"doctor","status":"failed","output":"{\"title\":\"Doctor\",\"rows\":[{\"status\":\"fail\",\"area\":\"Kubernetes apps\",\"check\":\"n8n\",\"summary\":\"CrashLoopBackOff\",\"detail\":\"container exits\",\"cause\":\"startup failure\"}]}"}`)) case "/v1/executions/execution-approved": - _, _ = response.Write([]byte(`{"id":"execution-approved","status":"running","output":"repair in progress"}`)) + _, _ = response.Write([]byte(`{"id":"execution-approved","status":"succeeded","output":"repair completed"}`)) default: http.NotFound(response, request) } @@ -51,5 +51,6 @@ func TestProposalApprovalRevalidatesAndSubmitsExactDoctorAction(t *testing.T) { }).AssertRedirect("/proposals/1") client.Get("/proposals/1").AssertOK().AssertInertia("Proposal") client.WithoutRedirects().Post("/proposals/1/approval", url.Values{}).AssertRedirect("/executions/1") - client.Get("/executions/1").AssertOK().AssertInertia("Execution").AssertProp("view.execution.status", "running") + client.Get("/executions/1").AssertOK().AssertInertia("Execution").AssertProp("view.execution.status", "succeeded").AssertProp("view.execution.report_id", float64(1)) + client.Get("/reports/1").AssertOK().AssertInertia("Report").AssertProp("report.outcome", "needs-attention") } diff --git a/docs/opsproof-architecture.md b/docs/opsproof-architecture.md index ba3e8f0..0c2b47e 100644 --- a/docs/opsproof-architecture.md +++ b/docs/opsproof-architecture.md @@ -80,6 +80,9 @@ confirmed by deterministic validation. the command remains advertised by Jeannie, and its arguments still match the constrained target. Progress reads the recorded execution; it never retries the state-changing POST. +- Run the focused Doctor target once after a terminal execution and write a + durable before/after report. Preserve a failed validation as an explicit + outcome rather than inferring success from the execution status alone. ## Why not Laravel Rust now? diff --git a/tests/jeannie/test_privacy_services_pipeline.py b/tests/jeannie/test_privacy_services_pipeline.py index 32a9637..387c208 100644 --- a/tests/jeannie/test_privacy_services_pipeline.py +++ b/tests/jeannie/test_privacy_services_pipeline.py @@ -153,6 +153,7 @@ class OpsProofPipelineTests(unittest.TestCase): self.assertIn('operator.Post("/incidents/{scope}/{target}/proposals"', routes) self.assertIn('operator.Post("/proposals/{proposal}/approval"', routes) self.assertIn('operator.Get("/executions/{execution}"', routes) + self.assertIn('operator.Get("/reports/{report}"', routes) proposal_handler = (ROOT / "apps/opsproof/overlay/handlers/proposal/proposal.go").read_text( encoding="utf-8" @@ -170,6 +171,18 @@ class OpsProofPipelineTests(unittest.TestCase): self.assertIn('"remediation_approvals"', migration) self.assertIn('"operation_executions"', migration) + execution_page = ( + ROOT / "apps/opsproof/overlay/resources/js/pages/Execution.tsx" + ).read_text(encoding="utf-8") + self.assertIn("Open incident report", execution_page) + + report_page = ( + ROOT / "apps/opsproof/overlay/resources/js/pages/Report.tsx" + ).read_text(encoding="utf-8") + self.assertIn("Evidence-backed incident report", report_page) + self.assertIn("Five Whys", report_page) + self.assertIn("Bounded execution output", report_page) + if __name__ == "__main__": unittest.main()