Skip to content

Conversation

@nirs
Copy link
Member

@nirs nirs commented Jan 15, 2026

This branch adds HTML report generation for validate commands.

  • Design document - Architecture for per-command report types with shared template infrastructure
  • Command-specific report types - Dedicated report structs for each command (application.Report, clusters.Report) that embed common fields and add command-specific data
  • Shared template infrastructure - Common templates (header, footer, summary, style) in pkg/report/templates/, with Template() function for composition
  • HTML generation for validate commands - Each command has its own template, templateData wrapper, and golden file tests
  • Include/indent template functions - WYSIWYG template syntax where visual indentation matches output
  • Include ApplicationStatus
  • Include ClusterStatus
  • Include report.Base content
  • Include report.Report content
  • Add real CSS styling
  • Integrate with validate commands

Out of Scope

  • Gather command reports (will use the same infrastructure later)

Example output

Screenshot 2026-01-15 at 23 13 47

@nirs nirs requested a review from parikshithb January 15, 2026 21:43
@nirs nirs force-pushed the html-report-impl branch 4 times, most recently from f76d712 to f2f6693 Compare January 16, 2026 11:05
Use product name (e.g., "Claude Opus 4.5") instead of API model ID
(e.g., "claude-4-opus-20250514") for consistency.

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
@nirs nirs force-pushed the html-report-impl branch from f2f6693 to e7a8a01 Compare January 16, 2026 11:33
nirs added 7 commits January 16, 2026 13:54
Document the architecture for generating HTML reports from command output.
Each command will have its own report type with specific data, while sharing
common templates for header, footer, and summary sections.

Key design decisions:

- Separate report types per command (application.Report, clusters.Report, etc.)
- All reports embed report.Report with common fields
- Template composition using Go's html/template with {{define}} and {{template}}
- Shared templates in report/templates/*.tmpl, command templates in each package
- Struct-based data passing (HeaderData, SummaryData) for type safety
- report.Template() returns fresh template set, commands add their template
- Base.SummaryData(order) converts Summary to template data with specified key order,
  key names are used directly as CSS classes

This document will be updated as implementation progresses.

Assisted-by: Cursor/Claude Opus 4.5
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
Git on Windows converts LF to CRLF on checkout, causing golden file
comparisons to fail. Add .gitattributes to force LF for *.html and
*.tmpl files.

Example failed test:

    === RUN   TestIncludeIndent
        html_test.go:153: output mismatch:
            --- expected
            +++ actual
            @@ -1,7 +1,7 @@
            -<div>
            +<div>
            -    <section>
            +    <section>
            -        <ul>
            +        <ul>
            -            <li>Item</li>
            +            <li>Item</li>
            -        </ul>
            +        </ul>
            -    </section>
            +    </section>
             </div>
            \ No newline at end of file
    --- FAIL: TestIncludeIndent (0.00s)

Example attributes:

    % git check-attr eol pkg/**/*.{html,tmpl}
    pkg/report/testdata/include-indent.html: eol: lf
    pkg/validate/application/testdata/report.html: eol: lf
    pkg/validate/clusters/testdata/report.html: eol: lf
    pkg/report/templates/application.tmpl: eol: lf
    pkg/report/templates/base.tmpl: eol: lf
    pkg/report/templates/style.tmpl: eol: lf
    pkg/validate/application/report.tmpl: eol: lf
    pkg/validate/clusters/report.tmpl: eol: lf

Assisted-by: Cursor/Claude Opus 4.5
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
Create dedicated report types for validate-application and validate-clusters
commands in new sub-packages. This is preparation for command-specific HTML
report generation.

Each report type embeds report.Report (which includes Base, Config, Namespaces)
and adds only command-specific fields:

- application.Report: report.Application, report.ApplicationStatus
- clusters.Report: report.ClustersStatus

This structure:
- Clearly defines what data each command produces
- Avoids optional fields that belong to other commands
- Enables command-specific HTML templates
- Reuses report.Report.Equal() for comparison

The existing validate package code continues to use report.Report for now.
Migration to the new types will follow in subsequent commits.

Assisted-by: Cursor/Claude Opus 4.5
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
Templates (pkg/report/templates/):
- base.tmpl: Defines header, footer, and summary blocks. Header shows
  title, optional subtitle, and status. Summary renders items as a list
  with CSS classes.
- style.tmpl: Placeholder CSS reset (full styling to be added later).
- application.tmpl: Shared block for displaying application name and
  namespace, used by validate-application and gather-application
  reports.

Code (pkg/report/html.go):
- Template() returns a fresh template set with shared definitions and
  Funcs
- HeaderData, SummaryData, SummaryItem types for passing data to shared
  templates
- Base.SummaryData(order) converts Summary map to template data with
  specified order

Templates use consistent whitespace trimming:

    {{define "name" -}}
    ...
    {{- end}}

so callers don't need to manage whitespace at call sites.

Assisted-by: Cursor/Claude Opus 4.5
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
Each command has:
- report.tmpl: Command-specific HTML template defining the "report" block
- html.go: templateData wrapper with HeaderData() and SummaryData() methods,
  Template() that combines shared and command templates
- html_test.go: Golden file test for WriteHTML, unit tests for helper methods
- testdata/report.html: Golden file for output verification

The templateData wrapper embeds *Report so templates can access both report
fields directly ({{.Application.Name}}) and wrapper methods ({{.HeaderData}}).

SummaryOrder in pkg/validate/report.go defines display order: OK, Problem, Stale.
Each package passes this to Base.SummaryData() for consistent ordering.

Template whitespace pattern: only trim at definition boundaries
({{define "report" -}}...{{- end}}), template calls need no trimming.

Assisted-by: Cursor/Claude Opus 4.5
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
Add 'includeHTML', 'includeCSS' and 'indent' template functions to allow
proper indentation of the output HTML.

- includeHTML: execute a template and return the rendered HTML. Must be
  called in HTML context.
- includeCSS: execute a template and return the rendered CSS. Must be
  called in stylesheet context. (<style>...</style>).
- indent: indent all lines except the first (which is already
  indented in the outer template)

This enables clean, readable templates where visual indentation
matches output.

Helm-style (visual indentation doesn't match output):

    <div>
    {{ include "section" . | indent 4 }}
    </div>

Our style (WYSIWYG):

    <div>
        {{ includeHTML "section" . | indent 4 }}
    </div>

Output (properly nested):

    <div>
        <section>
            <ul>
                <li>Item</li>
            </ul>
        </section>
    </div>

Assisted-by: Cursor/Claude Opus 4.5
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
Update validate templates to use the new include*/indent functions,
producing properly indented HTML output.

Before:

    <section>
        <h2>Report Details</h2>
        <h3>Summary</h3>
    <ul>
        <li class="ok">ok: 2</li>
    </ul>

After:

    <section>
        <h2>Report Details</h2>
        <h3>Summary</h3>
        <ul>
            <li class="ok">ok: 2</li>
        </ul>

Assisted-by: Cursor/Claude Opus 4.5
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
@nirs nirs force-pushed the html-report-impl branch from e7a8a01 to 3ac078a Compare January 16, 2026 11:54
@nirs nirs force-pushed the html-report-impl branch 3 times, most recently from 9b2f836 to 15b8545 Compare January 18, 2026 20:19
- Simplify report template to keep the shared report structure
- The command template contains now only the specific content
- Remove unused application template
- Remove summary template and infrastructure, we will add it later if
  needed

Need to update the previous commit with the changes.

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
@nirs nirs force-pushed the html-report-impl branch from 15b8545 to 11e22d5 Compare January 18, 2026 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants