Skip to content

reports(terminal): generate_to_file missing extension handling (inconsistent with all other generators) #83

Description

@himanshu231204

Summary

In openagent_eval/reports/terminal.py, the generate_to_file() method does no extension handling or default filename appending — unlike every other report generator (HTMLReport, MarkdownReport, JSONReport, ComparisonReport), which all check the output path and either append a default filename or replace the extension.

Steps to Reproduce

  1. Call TerminalReport().generate_to_file(report, "./output") (a path without extension).
  2. Observe that a file named output (no extension) is created.
  3. Compare with MarkdownReport().generate_to_file(report, "./output") which correctly creates ./output/report.md.

Expected Behavior

TerminalReport.generate_to_file() should be consistent with the other report generators — if the path has no extension, it should be treated as a directory and a default filename (e.g., report.txt) should be appended.

Actual Behavior

The path is used as-is, producing an extensionless file.

Relevant Code

# Lines 88-94 in terminal.py
    def generate_to_file(self, report: Any, output_path: Path | str) -> Path:
        path = self._ensure_output_dir(output_path)
        content = self.generate(report)
        path.write_text(content, encoding="utf-8")
        return path

Compare with html.py which correctly distinguishes directory paths from file paths:

    path = Path(output_path)
    if path.suffix == "":
        path = path / "report.html"       # treat as directory
    elif path.suffix.lower() != ".html":
        path = path.with_suffix(".html")   # replace extension

Impact

Low severity, but a clear API inconsistency. Users who follow the same pattern across report generators will get extensionless files from TerminalReport.

Suggested Fix

Adopt the same pattern as HTMLReport.generate_to_file():

    path = Path(output_path)
    if path.suffix == "":
        path = path / "report.txt"
    elif path.suffix.lower() != ".txt":
        path = path.with_suffix(".txt")
    path = self._ensure_output_dir(path)

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions