From 57a878340270988e79d3e3da675153aba1b9cb84 Mon Sep 17 00:00:00 2001 From: Michael Tarassov Date: Sun, 26 Jul 2026 04:59:30 +0800 Subject: [PATCH] fix: reject non-plan input, report unknown costs instead of guessing, expose Action outputs The tool could report a confidently wrong number, and the Action exposed nothing to the calling workflow. Six confirmed defects: - Any valid JSON parsed as a plan. Feeding it `terraform show -json` of *state*, or a truncated artifact download, rendered a reassuring '$0.00/mo - No cost-relevant changes detected' comment and exited 0. Plan documents are now validated and bad input exits 2 with a message naming the likely cause. - Unknown prices became invented numbers. An unrecognised instance_type fell back to a guessed $0.05/hr, so an m5.24xlarge (~$3,363/mo) was reported as $36.50/mo and passed a --threshold 100 gate. An attribute not known until apply (Terraform writes null) became $0.00 silently. Estimators now return None for unknown; such resources are listed in a 'Cost unknown' table, excluded from the total, and the headline is marked (partial). - NaN/Infinity in a price sheet disabled the threshold gate. json.load accepts them, every comparison against NaN is False, so the run exited 0 while rendering '$nan'. Non-finite JSON constants and non-finite --threshold values are now rejected. - A hostile for_each key broke out of the Markdown table. A backtick closed the code span, letting '" +# GitHub rejects an issue-comment body longer than this with HTTP 422, which +# would mean posting nothing at all on exactly the large plans people most want +# reviewed. Stay under it and say what was dropped. +COMMENT_LIMIT = 65536 + _ARROW = {"create": "🟢 create", "update": "🟡 update", "delete": "🔴 delete"} +_CONTROL = re.compile(r"[\x00-\x1f\x7f]") +_CELL_MAX = 200 + + +def _code(text: str) -> str: + """Render untrusted text as a Markdown code span that cannot break out. + + Resource addresses embed ``for_each`` keys, which are arbitrary attacker- or + typo-supplied strings. A backtick would close the code span and let the rest + of the key be interpreted as Markdown or raw HTML -- ``