refactor: hoist comparison-html gate into a single condition (Greptile DRY)

Greptile flagged that `entity_reports and args.emit == "html"` appeared in
two places — once when computing the footer display path, again when calling
save_output. The else-branches differ between the two callsites (the display
needs `report.topic` as fallback; the save call needs `None` so save_output
falls back to the report's own topic), so collapsing into one shared
expression would be wrong, but hoisting just the condition into a single
`is_comparison_html` bool eliminates the risk of drift while keeping the
two callsites' fallback semantics distinct.
This commit is contained in:
Trevin Chow
2026-05-16 19:32:49 -07:00
parent cd34966b4f
commit 4d4ac97ffb
+8 -13
View File
@@ -881,15 +881,15 @@ def main() -> int:
pass pass
fun_level = config.get("FUN_LEVEL", "medium").lower() fun_level = config.get("FUN_LEVEL", "medium").lower()
# Comparison HTML is the one case where the saved file's title and content
# have to be overridden away from the leading entity's report. Compute the
# gate once so the footer-display and save-output paths can't disagree.
is_comparison_html = bool(entity_reports) and args.emit == "html"
footer_save_path = None footer_save_path = None
if args.save_dir: if args.save_dir:
save_topic = ( save_topic_for_display = comparison_topic(entity_reports) if is_comparison_html else report.topic
comparison_topic(entity_reports)
if entity_reports and args.emit == "html"
else report.topic
)
footer_save_path = compute_save_path_display( footer_save_path = compute_save_path_display(
args.save_dir, save_topic, args.save_suffix or "", args.emit args.save_dir, save_topic_for_display, args.save_suffix or "", args.emit
) )
# Signal to render_compact whether pre-research flags were supplied. # Signal to render_compact whether pre-research flags were supplied.
@@ -924,19 +924,14 @@ def main() -> int:
) )
if args.save_dir: if args.save_dir:
# Save the main topic's raw file (single-entity or comparison main). # Save the main topic's raw file (single-entity or comparison main).
save_topic = (
comparison_topic(entity_reports)
if entity_reports and args.emit == "html"
else None
)
save_path = save_output( save_path = save_output(
report, report,
args.emit, args.emit,
args.save_dir, args.save_dir,
suffix=args.save_suffix or "", suffix=args.save_suffix or "",
synthesis_md=synthesis_md, synthesis_md=synthesis_md,
topic_override=save_topic, topic_override=comparison_topic(entity_reports) if is_comparison_html else None,
rendered_content=rendered if entity_reports and args.emit == "html" else None, rendered_content=rendered if is_comparison_html else None,
) )
sys.stderr.write(f"[last30days] Saved output to {save_path}\n") sys.stderr.write(f"[last30days] Saved output to {save_path}\n")
# Competitor / vs-mode: also save a per-entity raw file for each peer. # Competitor / vs-mode: also save a per-entity raw file for each peer.