Skip to content

feat(html): add --data-url flag to decouple benchmark UI#119

Merged
fahimfaisaal merged 13 commits into
mainfrom
worktree-html-api-flag
Jun 3, 2026
Merged

feat(html): add --data-url flag to decouple benchmark UI#119
fahimfaisaal merged 13 commits into
mainfrom
worktree-html-api-flag

Conversation

@fahimfaisaal

@fahimfaisaal fahimfaisaal commented Jun 2, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds vizb html --data-url <url> / -U — generated HTML fetches benchmark JSON from a URL at runtime instead of embedding it
  • Useful when the benchmark JSON exceeds ~1 MB (large history, many merged runs); keeps the HTML a fixed ~784 KB viewer shell regardless of data size
  • [file] arg becomes optional — --data-url alone is sufficient, no file parse needed
  • Default embed mode (vizb html bench.json) is unchanged

Changes

Go:

  • shared/flag_state.go: new DataURL string field
  • pkg/template/generate-ui.go: extracted renderPage helper, added GenerateRemoteHTMLBenchmarkUI
  • cmd/html.go: --data-url / -U flag, MaximumNArgs(1), branches on remote vs embed path
  • cmd/flag_validation_rules.go: URL validation via validateAPIURL (must be http(s)://), consistent with existing flag validation pattern
  • cmd/html_test.go: updated TestHtmlCmd_NoArgs, added TestHtmlCmd_APIFlag and TestHtmlCmd_APIFlag_InvalidURL

UI:

  • ui/vite.config.ts: injects window.VIZB_DATA_URL = {{ .DataURL }}; into template script
  • ui/src/global.d.ts: VIZB_DATA_URL?: string on Window
  • ui/src/composables/useBenchmarkData.ts: fetch branch + loading / loadError refs exported
  • ui/src/views/Dashboard.vue: animate-pulse skeleton loading state + error state with CORS hint
  • pkg/template/vizb-ui.gen.go: regenerated

Docs: docs/src/content/docs/commands/html.mdx updated with new flag, when-to-use guidance, CORS note

Usage

# remote mode — lean ~784 KB viewer, data fetched at runtime
vizb html --data-url https://raw.githubusercontent.com/org/repo/main/bench.json -o report.html

# embed mode — unchanged, fully self-contained offline
vizb html bench.json -o report.html

The JSON host must send Access-Control-Allow-Origin: *. Most static hosts (GitHub raw, GH Pages, public S3, Cloudflare Pages) already do this.

Test plan

  • go test ./... passes
  • vizb html --data-url https://... -o lean.html → ~784 KB HTML, no data inlined, URL present
  • vizb html bench.json -o embed.html → unchanged embed behaviour
  • vizb html (no args, no flag) → clear error
  • vizb html --data-url not-a-url → validation warning, falls through to no-args error
  • Open lean.html with JSON server running → skeleton → charts render
  • Open lean.html with server stopped → error state with CORS hint shown

Adds `vizb html --api <url>` mode so the generated HTML fetches benchmark
JSON from a URL at runtime instead of embedding it. This keeps the output
file at a fixed ~765KB regardless of benchmark data size.

- `file` arg is now optional; `--api` alone produces a viewer HTML
- URL must be http(s)://; validated before generation
- Dashboard shows loading state while fetching and a clear error message
  on fetch failure (including CORS hint)
- Default embed path (no --api) is byte-for-byte unchanged
@codecov-commenter

codecov-commenter commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.92308% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/template/generate-ui.go 53.84% 6 Missing ⚠️
cmd/html.go 85.00% 2 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

…tate

- URL validation extracted to flagValidationRules (validateAPIURL) so it
  follows the same warn-and-reset pattern as all other flag validators;
  manual strings.HasPrefix check removed from runHTML
- Loading state replaced with animate-pulse skeleton matching real layout
  (title, badge, description, chart card placeholders)
@fahimfaisaal fahimfaisaal changed the title feat: add --api flag to html subcommand for remote data fetching feat(html): add --data-url flag to decouple benchmark data from HTML output Jun 2, 2026
fahimfaisaal and others added 3 commits June 3, 2026 15:47
Exposes the --data-url/-U flag so CI workflows can generate an HTML
that fetches benchmark JSON from a remote URL instead of embedding it.
Resolve step now accepts data-url as a standalone input source.
@fahimfaisaal fahimfaisaal changed the title feat(html): add --data-url flag to decouple benchmark data from HTML output feat(html): add --data-url flag to decouple benchmark UI Jun 3, 2026
.Version strips the v prefix; .Tag preserves it, matching
the format returned by debug.ReadBuildInfo().
@fahimfaisaal
fahimfaisaal merged commit 0285f32 into main Jun 3, 2026
1 check passed
@fahimfaisaal
fahimfaisaal deleted the worktree-html-api-flag branch July 22, 2026 07:40
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