Add OpsProof post-change reports
This commit is contained in:
parent
675404374b
commit
778fb69038
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
})
|
||||
}
|
||||
|
|
@ -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},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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})
|
||||
}
|
||||
|
|
@ -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"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.')}
|
||||
</pre>
|
||||
{active && <p className="mt-3 text-xs text-slate-500">Refreshing every two seconds.</p>}
|
||||
{!active && view.execution.report_id > 0 && (
|
||||
<a href={`/reports/${view.execution.report_id}`} className="mt-5 inline-flex rounded-lg bg-cyan-300 px-4 py-2 text-sm font-semibold text-slate-950">
|
||||
Open incident report
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<main className="min-h-screen bg-[#071019] px-5 py-8 text-slate-100">
|
||||
<div className="mx-auto max-w-5xl">
|
||||
<p className="text-xs uppercase tracking-[0.2em] text-cyan-300">Evidence-backed incident report</p>
|
||||
<div className="mt-3 flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between">
|
||||
<h1 className="text-3xl font-semibold">{report.scope} / {report.target}</h1>
|
||||
<span className="w-fit rounded-md border border-cyan-300/20 bg-cyan-300/10 px-3 py-1 text-xs uppercase text-cyan-200">
|
||||
{report.outcome}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="mt-8 grid gap-4">
|
||||
{[
|
||||
['Findings', report.findings],
|
||||
['Diagnostic', report.diagnostic],
|
||||
['Mitigation', report.mitigation],
|
||||
['Validation', report.validation],
|
||||
['Recommendation', report.recommendation],
|
||||
].map(([heading, body]) => (
|
||||
<section key={heading} className="rounded-2xl border border-white/10 bg-[#0a141e] p-6">
|
||||
<h2 className="text-xs uppercase tracking-[0.18em] text-cyan-200">{heading}</h2>
|
||||
<p className="mt-3 text-sm leading-6 text-slate-400">{body}</p>
|
||||
</section>
|
||||
))}
|
||||
|
||||
<section className="rounded-2xl border border-white/10 bg-[#0a141e] p-6">
|
||||
<h2 className="text-xs uppercase tracking-[0.18em] text-cyan-200">Five Whys</h2>
|
||||
<ol className="mt-3 space-y-3 text-sm leading-6 text-slate-400">
|
||||
{list(report.five_whys_json).map((item, index) => <li key={item}>{index + 1}. {item}</li>)}
|
||||
</ol>
|
||||
</section>
|
||||
|
||||
<section className="rounded-2xl border border-white/10 bg-[#0a141e] p-6">
|
||||
<h2 className="text-xs uppercase tracking-[0.18em] text-cyan-200">Bounded execution output</h2>
|
||||
<pre className="mt-3 max-h-80 overflow-auto whitespace-pre-wrap rounded-xl bg-black/20 p-4 text-xs leading-5 text-slate-400">
|
||||
{report.execution_output || 'No execution output was returned.'}
|
||||
</pre>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<p className="mt-6 text-xs text-slate-600">Approved by {report.approved_by} · report {report.id} · execution {report.execution_id}</p>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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?
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in New Issue