Skip to content

Commit c63ebfd

Browse files
committed
docs: document the report output spec and pin it with golden tests
Add an output specification block above render_report showing the exact success and failure layouts, and golden tests that assert the full rendered report byte-for-byte so the spec stays accurate as the output evolves.
1 parent 681bf18 commit c63ebfd

2 files changed

Lines changed: 131 additions & 0 deletions

File tree

‎main.py‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,69 @@ def _markdown_passed_details(results: list[ScopeResult]) -> str:
468468
return "\n".join(lines)
469469

470470

471+
# ---------------------------------------------------------------------------
472+
# Output specification
473+
#
474+
# The Markdown report shared by the job summary and the PR comment renders
475+
# as follows (values are filled from ScopeResult data):
476+
#
477+
# Success:
478+
#
479+
# # Commit Check
480+
#
481+
# ✅ **11 passed** (11 scopes)
482+
#
483+
# <details>
484+
# <summary>Show details</summary>
485+
#
486+
# ```text
487+
# Commit message
488+
# ✔ PR title (feat: add login page)
489+
# ✔ Commit 1/11 (feat: add user auth)
490+
# Branch
491+
# ✔ Branch (feature/add-login)
492+
# Author
493+
# ✔ Author name (Jane Doe)
494+
# ✔ Author email (jane@example.com)
495+
# ```
496+
#
497+
# </details>
498+
#
499+
# Failure:
500+
#
501+
# # Commit Check
502+
#
503+
# ❌ **2 failures** · ✅ **9 passed** (11 scopes)
504+
#
505+
# | Scope | Checked value | Failed checks | Result |
506+
# |---|---|---|---|
507+
# | Commit 2/11 | `bad msg` | [CC001 message](https://commit-check.com/rules/#cc001) | ❌ |
508+
#
509+
# <details>
510+
# <summary>Show details</summary>
511+
#
512+
# ```text
513+
# Commit message
514+
# ✔ PR title (feat: add login page)
515+
# ✖ Commit 2/11 (1 failure)
516+
# CC001 message: The commit message should follow Conventional Commits.
517+
# Suggest: Use <type>(<scope>): <description>
518+
# Branch
519+
# ✔ Branch (feature/add-login)
520+
# ```
521+
#
522+
# </details>
523+
#
524+
# _Rules reference: https://commit-check.com/rules/_
525+
#
526+
# Notes:
527+
# - The table lists only failed scopes; passing scopes live in the details.
528+
# - Values are capped at 60 chars (… suffix) and shown for every scope in
529+
# the details block, plus for failed scopes in the table.
530+
# - The step log output is a separate plain-text rendering (render_step_log).
531+
# ---------------------------------------------------------------------------
532+
533+
471534
def render_report(results: list[ScopeResult], include_footer: bool = True) -> str:
472535
"""Render the Markdown report shared by the job summary and PR comment.
473536

‎main_test.py‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,74 @@ def test_raw_text_fallback_is_printed(self):
629629

630630

631631
class TestRenderJobSummary(unittest.TestCase):
632+
def test_success_golden_output(self):
633+
"""Pin the full success report so the spec stays visible and exact."""
634+
results = [
635+
pass_scope("PR title", value="feat: add login page"),
636+
pass_scope("Commit 1/2", value="feat: add user auth"),
637+
pass_scope("Commit 2/2", value="fix: resolve timeout"),
638+
pass_scope("Branch", value="feature/add-login"),
639+
]
640+
body = main.render_report(results)
641+
self.assertEqual(
642+
body,
643+
"# Commit Check\n"
644+
"\n"
645+
"✅ **4 passed** (4 scopes)\n"
646+
"\n"
647+
"<details>\n"
648+
"<summary>Show details</summary>\n"
649+
"\n"
650+
"```text\n"
651+
"Commit message\n"
652+
" ✔ PR title (feat: add login page)\n"
653+
" ✔ Commit 1/2 (feat: add user auth)\n"
654+
" ✔ Commit 2/2 (fix: resolve timeout)\n"
655+
"Branch\n"
656+
" ✔ Branch (feature/add-login)\n"
657+
"```\n"
658+
"\n"
659+
"</details>",
660+
)
661+
662+
def test_failure_golden_output(self):
663+
"""Pin the full failure report: failed row in the table, all in details."""
664+
results = [
665+
pass_scope("PR title", value="feat: add login page"),
666+
fail_scope("Commit 2/2"),
667+
pass_scope("Branch", value="feature/add-login"),
668+
]
669+
body = main.render_report(results)
670+
self.assertEqual(
671+
body,
672+
"# Commit Check\n"
673+
"\n"
674+
"❌ **1 failure** · ✅ **2 passed** (3 scopes)\n"
675+
"\n"
676+
"| Scope | Checked value | Failed checks | Result |\n"
677+
"|---|---|---|---|\n"
678+
"| Commit 2/2 | `bad message` | "
679+
"[CC001 message](https://commit-check.com/rules/#cc001) | ❌ |\n"
680+
"\n"
681+
"<details>\n"
682+
"<summary>Show details</summary>\n"
683+
"\n"
684+
"```text\n"
685+
"Commit message\n"
686+
" ✔ PR title (feat: add login page)\n"
687+
" ✖ Commit 2/2 (1 failure)\n"
688+
" CC001 message: The commit message should follow "
689+
"Conventional Commits.\n"
690+
" Suggest: Use <type>(<scope>): <description>\n"
691+
"Branch\n"
692+
" ✔ Branch (feature/add-login)\n"
693+
"```\n"
694+
"\n"
695+
"</details>\n"
696+
"\n"
697+
"_Rules reference: https://commit-check.com/rules/_",
698+
)
699+
632700
def test_all_pass(self):
633701
body = main.render_job_summary([pass_scope("Branch", value="main")])
634702
self.assertTrue(body.startswith(main.REPORT_TITLE))

0 commit comments

Comments
 (0)