-
Notifications
You must be signed in to change notification settings - Fork 17
feat: add HTML report exporter for SuiteResult #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
aviralgarg05
merged 1 commit into
aviralgarg05:main
from
anshiky73-svg:feature/html-report-exporter
Dec 27, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from html import escape | ||
| from typing import TYPE_CHECKING | ||
|
|
||
|
|
||
| if TYPE_CHECKING: | ||
| from agentunit.reporting.results import SuiteResult | ||
|
|
||
|
|
||
| def render_html_report(result: SuiteResult) -> str: | ||
| scenarios = result.scenarios | ||
|
|
||
| total_runs = sum(len(s.runs) for s in scenarios) | ||
| failed_runs = sum(1 for s in scenarios for r in s.runs if not r.success) | ||
| passed_runs = total_runs - failed_runs | ||
| duration = (result.finished_at - result.started_at).total_seconds() | ||
|
|
||
| scenario_rows: list[str] = [] | ||
|
|
||
| for scenario in scenarios: | ||
| scenario_rows.append( | ||
| f""" | ||
| <tr> | ||
| <td>{escape(scenario.name)}</td> | ||
| <td>{scenario.success_rate:.2%}</td> | ||
| <td>{len(scenario.runs)}</td> | ||
| </tr> | ||
| """ | ||
| ) | ||
|
|
||
| return f"""<!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>AgentUnit Report</title> | ||
| <style> | ||
| body {{ | ||
| font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif; | ||
| padding: 24px; | ||
| }} | ||
| h1, h2 {{ | ||
| margin-bottom: 0.5em; | ||
| }} | ||
| table {{ | ||
| width: 100%; | ||
| border-collapse: collapse; | ||
| margin-top: 12px; | ||
| }} | ||
| th, td {{ | ||
| border: 1px solid #ddd; | ||
| padding: 8px; | ||
| text-align: left; | ||
| }} | ||
| th {{ | ||
| background-color: #f4f4f4; | ||
| }} | ||
| .bar {{ | ||
| height: 18px; | ||
| margin: 6px 0; | ||
| }} | ||
| .passed {{ | ||
| background-color: #4CAF50; | ||
| width: {passed_runs * 20}px; | ||
| }} | ||
| .failed {{ | ||
| background-color: #F44336; | ||
| width: {failed_runs * 20}px; | ||
| }} | ||
| .meta {{ | ||
| color: #555; | ||
| font-size: 0.9em; | ||
| }} | ||
| </style> | ||
| </head> | ||
|
|
||
| <body> | ||
|
|
||
| <h1>AgentUnit HTML Report</h1> | ||
| <p class="meta"> | ||
| Duration: {duration:.2f}s · Total runs: {total_runs} | ||
| </p> | ||
|
|
||
| <h2>Summary</h2> | ||
| <p>Passed: {passed_runs} · Failed: {failed_runs}</p> | ||
|
|
||
| <div class="bar passed"></div> | ||
| <div class="bar failed"></div> | ||
|
|
||
| <h2>Scenarios</h2> | ||
| <table> | ||
| <tr> | ||
| <th>Name</th> | ||
| <th>Success rate</th> | ||
| <th>Runs</th> | ||
| </tr> | ||
| {"".join(scenario_rows)} | ||
| </table> | ||
|
|
||
| </body> | ||
| </html> | ||
| """ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bar chart width calculation creates UX issues with larger test suites.
The fixed-pixel width calculation (
passed_runs * 20px) causes horizontal scrolling when test suites have many runs. For example, a suite with 100 test runs produces 2000px-wide bars, making the report difficult to view. Consider using percentage-based widths or a capped maximum width with proportional scaling.🔎 Proposed fix using percentage-based widths
Modify the CSS and HTML to use a container with proportional bars:
.bar {{ - height: 18px; + display: inline-block; + height: 20px; margin: 6px 0; + color: white; + padding: 2px 8px; + font-size: 0.85em; }} + .bar-container {{ + display: flex; + width: 100%; + max-width: 600px; + margin: 12px 0; + }} .passed {{ background-color: #4CAF50; - width: {passed_runs * 20}px; }} .failed {{ background-color: #F44336; - width: {failed_runs * 20}px; }}And update the HTML section:
<h2>Summary</h2> <p>Passed: {passed_runs} · Failed: {failed_runs}</p> -<div class="bar passed"></div> -<div class="bar failed"></div> +<div class="bar-container"> + <div class="bar passed" style="flex: {passed_runs}">Passed: {passed_runs}</div> + <div class="bar failed" style="flex: {failed_runs}">Failed: {failed_runs}</div> +</div>This approach uses flexbox to proportionally distribute space and includes text labels within the bars.
Also applies to: 87-88
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anshiky73-svg pls fix this issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok i will fix this issue @aviralgarg05