Skip to content

fix(reports): normalize output paths with wrong extensions#209

Merged
himanshu231204 merged 2 commits into
OpenAgentHQ:mainfrom
syf2211:fix/reports-generate-to-file-suffix
Jul 22, 2026
Merged

fix(reports): normalize output paths with wrong extensions#209
himanshu231204 merged 2 commits into
OpenAgentHQ:mainfrom
syf2211:fix/reports-generate-to-file-suffix

Conversation

@syf2211

@syf2211 syf2211 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix generate_to_file() in MarkdownReport, JSONReport, and ComparisonReport so paths with a non-matching extension (e.g. results.txt) are normalized via with_suffix() instead of creating nested directory paths like results.txt/report.md.

Motivation

Fixes #84. HTMLReport and TerminalReport already used the correct path.suffix / with_suffix() pattern; the other three report generators still relied on endswith(), which misclassified wrong-extension paths as directories.

Changes

  • openagent_eval/reports/markdown.py: normalize .md output paths
  • openagent_eval/reports/json_report.py: normalize .json output paths
  • openagent_eval/reports/comparison.py: normalize .txt output paths and align call order with other generators
  • Added regression tests in tests/unit/test_reports/test_markdown.py, test_json_report.py, and test_comparison.py

Tests

python3 -m pytest tests/unit/test_reports/test_markdown.py tests/unit/test_reports/test_json_report.py tests/unit/test_reports/test_comparison.py -v

Result: 44 passed

Notes

  • Behavior for extensionless paths (treated as directories) is unchanged.
  • Case-insensitive suffix matching (.MD.md) matches the existing HTMLReport/TerminalReport behavior.

syf2211 and others added 2 commits July 22, 2026 12:03
Align MarkdownReport, JSONReport, and ComparisonReport with the
HTMLReport/TerminalReport pattern: treat extensionless paths as
directories and replace mismatched suffixes via with_suffix().

Fixes OpenAgentHQ#84
@himanshu231204

Copy link
Copy Markdown
Member

/oc review pr in details

@opencode-agent

Copy link
Copy Markdown

Review summary — strongly positive, approve.

Bug analysis

The old code in all three generators used str(path).endswith(".ext"):

# Before (broken)
path = Path(output_path)
if not str(path).endswith(".md"):      # e.g. "results.txt" → False
    path = path / "report.md"          # → "results.txt/report.md" ☠️

When given results.txt, endswith(".md") is False, so the code incorrectly treated it as a directory and created results.txt/report.md instead of normalizing to results.md.

What the fix does

Replaces endswith() with path.suffix-based three-way logic, matching the existing pattern in HTMLReport and TerminalReport:

# After (fixed)
path = Path(output_path)
if path.suffix == "":                   # no ext → directory
    path = path / "report.md"
elif path.suffix.lower() != ".md":      # wrong ext → normalize
    path = path.with_suffix(".md")

Per-file changes

File Extension Default filename Bonus fix
markdown.py .md report.md
json_report.py .json report.json
comparison.py .txt comparison.txt Moved _prepare_output_file() after path resolution (was called too early on raw output_path, creating spurious directories)

Tests

Each test file adds a regression test: report.txtreport.md (or .json / .txt), verifying equality, existence, and content validity. All 44 tests pass.

Minor observations

  1. Duplicated logic — The suffix / with_suffix() pattern is now copy-pasted across all 5 generators. Worth extracting into a ReportGenerator._resolve_output_path() helper as a follow-up.
  2. No case-insensitive test.MD.md works via .lower() but isn't tested (same gap in existing HTML/Terminal tests).
  3. Comparison gapcomparison.py is missing the "extensionless → adds .txt" test that markdown.py and json_report.py have. Pre-existing, not introduced here.

Overall: Correct, minimal, consistent with existing patterns, well-tested.

New%20session%20-%202026-07-22T13%3A52%3A54.291Z
opencode session  |  github run

@himanshu231204
himanshu231204 merged commit baa51b6 into OpenAgentHQ:main Jul 22, 2026
8 checks passed
@github-actions

Copy link
Copy Markdown

🎉 Congratulations @syf2211!

Your pull request has been successfully merged into main. 🚀

Thank you for contributing to OpenAgentHQ and helping improve the project.

We truly appreciate your contribution and hope to see you back with more amazing PRs!

Happy Open Sourcing! ❤️

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.

reports(markdown/json/comparison): generate_to_file creates nested paths for non-matching extensions

2 participants