From 01146e860b491d7cb8260d35af3e18cb636762d4 Mon Sep 17 00:00:00 2001 From: nvphungdev <283886185+nvphungdev@users.noreply.github.com> Date: Sun, 17 May 2026 09:21:05 +0700 Subject: [PATCH] refactor(render): share accuracy disclosure Signed-off-by: nvphungdev <283886185+nvphungdev@users.noreply.github.com> --- cmd/optiqor/main.go | 6 ++---- cmd/optiqor/main_test.go | 4 +++- internal/analyze/diff_render.go | 5 +++-- internal/analyze/score_render.go | 5 +++-- internal/render/text.go | 10 ++++------ internal/render/text_test.go | 7 ++++--- 6 files changed, 19 insertions(+), 18 deletions(-) diff --git a/cmd/optiqor/main.go b/cmd/optiqor/main.go index 2503180..c73baa4 100644 --- a/cmd/optiqor/main.go +++ b/cmd/optiqor/main.go @@ -39,8 +39,6 @@ var errFindings = errors.New("optiqor: findings exceed threshold") var version = "dev" -const accuracyDisclosure = "Sandbox accuracy: ±40%. Install the Optiqor agent for exact numbers (optiqor.dev/get)." - func main() { err := newRootCmd().Execute() switch { @@ -71,7 +69,7 @@ As a bonus, it also flags obvious security misconfigurations it spots while parsing your chart (runAsRoot, :latest tags, missing securityContext, host namespaces, etc.). Cost is the headline; security is a side-effect. -` + accuracyDisclosure, +` + htmlrender.AccuracyDisclosure, Example: ` # Analyze a Helm chart directory optiqor analyze ./my-chart @@ -147,7 +145,7 @@ func newAnalyzeCmd() *cobra.Command { inefficiencies. Obvious security misconfigurations are flagged as a bonus side-effect of parsing — they are not the headline feature. -` + accuracyDisclosure, +` + htmlrender.AccuracyDisclosure, Example: ` optiqor analyze ./my-chart optiqor analyze ./values.yaml --json optiqor analyze ./chart --severity=med --fail-on=high diff --git a/cmd/optiqor/main_test.go b/cmd/optiqor/main_test.go index 772db2f..d9105ab 100644 --- a/cmd/optiqor/main_test.go +++ b/cmd/optiqor/main_test.go @@ -4,6 +4,8 @@ import ( "bytes" "strings" "testing" + + "github.com/optiqor/optiqor-cli/pkg/htmlrender" ) // TestRoot_Help just exercises the top-level cobra wiring; ensures we @@ -19,7 +21,7 @@ func TestRoot_Help(t *testing.T) { for _, want := range []string{ "analyze", "demo", - accuracyDisclosure, + htmlrender.AccuracyDisclosure, "Examples:", "optiqor analyze", "--no-color", diff --git a/internal/analyze/diff_render.go b/internal/analyze/diff_render.go index cdf1e55..a918e5b 100644 --- a/internal/analyze/diff_render.go +++ b/internal/analyze/diff_render.go @@ -8,6 +8,7 @@ import ( "github.com/optiqor/optiqor-cli/internal/render" "github.com/optiqor/optiqor-cli/internal/render/style" + "github.com/optiqor/optiqor-cli/pkg/htmlrender" "github.com/optiqor/optiqor-cli/pkg/parser" ) @@ -53,7 +54,7 @@ func (r DiffReport) WriteText(w io.Writer, opts render.Options) error { t.Muted.Render("(±40%)"), ) } - fmt.Fprintf(&b, " %s\n", t.Disclosure.Render(render.AccuracyDisclosure)) + fmt.Fprintf(&b, " %s\n", t.Disclosure.Render(htmlrender.AccuracyDisclosure)) _, err := io.WriteString(w, b.String()) return err @@ -70,7 +71,7 @@ func (r DiffReport) WriteJSON(w io.Writer) error { Entries []DiffEntry `json:"entries"` MonthlyUSDDelta float64 `json:"monthly_usd_delta"` }{ - AccuracyDisclosure: render.AccuracyDisclosure, + AccuracyDisclosure: htmlrender.AccuracyDisclosure, A: r.A, B: r.B, Entries: r.Entries, diff --git a/internal/analyze/score_render.go b/internal/analyze/score_render.go index 5aabef0..b3e8590 100644 --- a/internal/analyze/score_render.go +++ b/internal/analyze/score_render.go @@ -11,6 +11,7 @@ import ( "github.com/optiqor/optiqor-cli/internal/render" "github.com/optiqor/optiqor-cli/internal/render/style" + "github.com/optiqor/optiqor-cli/pkg/htmlrender" ) const scoreDefaultWidth = 78 @@ -132,7 +133,7 @@ func writeScorePenalties(b *strings.Builder, t style.Theme, s Score) { func writeScoreFooter(b *strings.Builder, t style.Theme, width int) { fmt.Fprintf(b, "%s\n", t.DividerLine(width)) - fmt.Fprintf(b, " %s\n", t.Disclosure.Render(render.AccuracyDisclosure)) + fmt.Fprintf(b, " %s\n", t.Disclosure.Render(htmlrender.AccuracyDisclosure)) fmt.Fprintf(b, " %s %s\n", t.Muted.Render("Calibration:"), t.Muted.Render("static benchmark distribution; agent install unlocks live percentile vs your fleet."), @@ -149,7 +150,7 @@ func (s Score) WriteJSON(w io.Writer) error { AccuracyDisclosure string `json:"accuracy_disclosure"` Score Score `json:"score_report"` }{ - AccuracyDisclosure: render.AccuracyDisclosure, + AccuracyDisclosure: htmlrender.AccuracyDisclosure, Score: s, }) } diff --git a/internal/render/text.go b/internal/render/text.go index 1c84565..3cd8b98 100644 --- a/internal/render/text.go +++ b/internal/render/text.go @@ -22,12 +22,10 @@ import ( "github.com/charmbracelet/lipgloss" "github.com/optiqor/optiqor-cli/internal/render/style" + "github.com/optiqor/optiqor-cli/pkg/htmlrender" "github.com/optiqor/optiqor-cli/pkg/rules" ) -// AccuracyDisclosure is the mandatory line every output must contain. -const AccuracyDisclosure = "Sandbox accuracy: ±40%. Install the Optiqor agent for exact numbers (optiqor.dev/get)." - // Brand strings used in the header banner. const ( BrandName = "optiqor" @@ -225,7 +223,7 @@ func writeSummary(b *strings.Builder, t style.Theme, r Report, costCount, secCou if secCount > 0 { rows = append(rows, [2]string{ "Security", - t.Muted.Render(plural(secCount, "finding", "findings")+" — bonus, surfaced while parsing"), + t.Muted.Render(plural(secCount, "finding", "findings") + " — bonus, surfaced while parsing"), }) } @@ -584,7 +582,7 @@ func writeFooter(b *strings.Builder, t style.Theme, width int, totalCents int64, } // Accuracy disclosure is mandatory and exact (CLAUDE.md hard rule). // Roast can add a quip BELOW it; it never replaces it. - fmt.Fprintf(b, "%s%s\n", contentIndent, t.Disclosure.Render(AccuracyDisclosure)) + fmt.Fprintf(b, "%s%s\n", contentIndent, t.Disclosure.Render(htmlrender.AccuracyDisclosure)) linkLabel := t.CallToLink.Render("optiqor.dev/get") fmt.Fprintf(b, "%s%s %s\n", contentIndent, t.Muted.Render("→ install the agent for exact numbers:"), @@ -613,7 +611,7 @@ func JSON(w io.Writer, r Report) error { MonthlySavingsUSD float64 `json:"monthly_savings_usd"` AnnualSavingsUSD float64 `json:"annual_savings_usd"` }{ - AccuracyDisclosure: AccuracyDisclosure, + AccuracyDisclosure: htmlrender.AccuracyDisclosure, Source: r.Source, Workloads: r.Workloads, Findings: r.Findings, diff --git a/internal/render/text_test.go b/internal/render/text_test.go index d538b23..ad78fa1 100644 --- a/internal/render/text_test.go +++ b/internal/render/text_test.go @@ -6,6 +6,7 @@ import ( "strings" "testing" + "github.com/optiqor/optiqor-cli/pkg/htmlrender" "github.com/optiqor/optiqor-cli/pkg/rules" ) @@ -66,7 +67,7 @@ func TestText_PlainAlwaysIncludesAccuracyDisclosure(t *testing.T) { if err := Text(&buf, r, Options{Color: false}); err != nil { t.Fatalf("Text(%s): %v", r.Source, err) } - if !strings.Contains(buf.String(), AccuracyDisclosure) { + if !strings.Contains(buf.String(), htmlrender.AccuracyDisclosure) { t.Fatalf("Text(%s): missing accuracy disclosure:\n%s", r.Source, buf.String()) } } @@ -81,7 +82,7 @@ func TestText_ColoredAlwaysIncludesAccuracyDisclosure(t *testing.T) { t.Fatal(err) } stripped := stripANSI(buf.String()) - if !strings.Contains(stripped, AccuracyDisclosure) { + if !strings.Contains(stripped, htmlrender.AccuracyDisclosure) { t.Fatalf("colored output missing disclosure (stripped):\n%s", stripped) } } @@ -193,7 +194,7 @@ func TestJSON_IncludesDisclosureAndShape(t *testing.T) { if err := json.Unmarshal(buf.Bytes(), &got); err != nil { t.Fatalf("decode: %v\nbody=%s", err, buf.String()) } - if got.AccuracyDisclosure != AccuracyDisclosure { + if got.AccuracyDisclosure != htmlrender.AccuracyDisclosure { t.Errorf("disclosure missing or wrong: %q", got.AccuracyDisclosure) } if got.MonthlySavingsUSD != 1.0 {