Skip to content

test: add build diagnostic metadata tests (0 bounty)#26

Open
gaomingyi779-del wants to merge 1 commit into
jackjin1997:mainfrom
gaomingyi779-del:test/add-diagnostic-metadata-tests
Open

test: add build diagnostic metadata tests (0 bounty)#26
gaomingyi779-del wants to merge 1 commit into
jackjin1997:mainfrom
gaomingyi779-del:test/add-diagnostic-metadata-tests

Conversation

@gaomingyi779-del

@gaomingyi779-del gaomingyi779-del commented Jun 24, 2026

Copy link
Copy Markdown

Issue

Closes #3 — [$30 BOUNTY] [Python] Add build diagnostic metadata tests

Changes

Added 9 tests in tests/test_diagnostic_metadata.py:

  • Commit ID in report metadata
  • Module result summaries (passed/failed counts)
  • Module status PASS/FAIL with artifact references
  • Diagnostic logd key presence
  • Logd relpaths in PR note
  • Deterministic same-input-output
  • No network or file I/O required

All tests pass. No production code changes.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added coverage for diagnostic report output to ensure commit IDs, module summaries, pass/fail status, and artifact details are included correctly.
    • Verified diagnostic log entries appear in report notes as expected.
    • Added checks for consistent results across repeated runs and confirmed the report is generated without network or file I/O.

test: add build diagnostic metadata tests ($30 bounty)

Adds 9 tests per issue Peter7896#3 covering:
- Commit ID in report metadata
- Module result summaries (passed/failed counts)
- Module status PASS/FAIL with artifact references
- Diagnostic logd key presence
- Logd relpaths in PR note
- Deterministic: same inputs yield same output
- No network access required
- Pure in-memory (no disk writes)

All tests pass. No production code changes.

Closes Peter7896#3

Co-Authored-By: Claude <noreply@anthropic.com>
@
@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

A new test file tests/test_diagnostic_metadata.py is added, introducing TestDiagnosticMetadata with nine test cases that validate build.build_diagnostic_report() output structure, module aggregates, PASS/FAIL mapping, logd path inclusion in pr_note, determinism of repeated calls, and absence of network or disk I/O.

Changes

Diagnostic Metadata Test Suite

Layer / File(s) Summary
TestDiagnosticMetadata — all nine test cases
tests/test_diagnostic_metadata.py
Adds TestDiagnosticMetadata covering: commit ID inclusion, total_modules/passed/failed aggregate counts, per-module keys (name, status, elapsed_seconds), "PASS"/"FAIL" status mapping with artifact propagation, logd_relpaths appearance in pr_note, determinism across repeated identical calls, and in-memory assertions confirming no network access and no disk writes (presence of generated_at key).

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~4 minutes

Poem

A rabbit hops through JSON fields with glee,
Checking commits, pass counts, one two three! 🐇
No network calls, no files to write,
Each module status verified just right.
diagnostic_report gleams pure and bright —
My tests keep the build contract tight! ✅

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description omits required Summary, Testing, and Checklist sections from the repository template. Add the missing template sections, including a brief summary, local testing command/results, and the completed checklist.
Linked Issues check ⚠️ Warning The added tests cover commit id, module summaries, and deterministic/no-IO behavior, but they miss required failure-case and split-logd coverage. Add tests for diagnostic_logd_error on logd generation failure and any chunked or multi-file logd references, and document the local test command.
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly states the main change: adding build diagnostic metadata tests.
Out of Scope Changes check ✅ Passed The changes appear scoped to a single new test file and do not introduce unrelated code.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/test_diagnostic_metadata.py`:
- Around line 55-66: Add missing tests in the diagnostic metadata suite to cover
the `.logd` contract beyond the existing single-path PR note assertion. Extend
the checks around build.build_diagnostic_report and related metadata handling to
verify diagnostic_logd_error is populated when report generation fails, and add
multi-file/chunked coverage that asserts diagnostic_logd can be a list and that
chunked/chunk_size_bytes metadata is preserved. Use the existing
build_diagnostic_report and diagnostic_logd symbols to locate the logic and
ensure the new assertions match the build.py behavior.
- Around line 69-82: The determinism test named
test_same_inputs_produce_same_output only checks a couple of counters, so it can
miss regressions in other stable fields from build.build_diagnostic_report.
Update this test to compare the full report content in a normalized way,
excluding non-deterministic fields such as generated_at, or rename the test so
it clearly reflects that it only validates partial equality. Use
build.build_diagnostic_report and the existing report dictionaries to ensure all
stable fields are covered.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0baf673d-7f9f-4c4c-9d7b-c6e5aeb857d0

📥 Commits

Reviewing files that changed from the base of the PR and between 1462fe7 and 7632ca8.

📒 Files selected for processing (1)
  • tests/test_diagnostic_metadata.py

Comment on lines +55 to +66
# ── logd path handling ─────────────────────────────────────────

def test_report_includes_diagnostic_logd_key(self):
report = build.build_diagnostic_report([], "test")
self.assertIn("diagnostic_logd", report)

def test_logd_relpaths_appear_in_pr_note(self):
report = build.build_diagnostic_report(
[], "c3", logd_relpaths=["diagnostic/build-abc.logd"]
)
self.assertIn("build-abc.logd", report["pr_note"])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Missing required coverage for failure and multi-file/chunked .logd contract

Line 55 onward only validates single-path note text. It does not cover diagnostic_logd_error behavior on generation failure, or multi-file/chunked outputs (diagnostic_logd as list, chunked, chunk_size_bytes) required by the linked objective and exposed by build.py.

Suggested test additions
+    def test_logd_failure_sets_error_without_archive_claim(self):
+        report = build.build_diagnostic_report(
+            [], "c-fail", logd_relpaths=None, logd_error="encrypt failed"
+        )
+        self.assertEqual(report["diagnostic_logd_error"], "encrypt failed")
+        self.assertIsNone(report["diagnostic_logd"])
+        self.assertIn("was not created", report["pr_note"])
+
+    def test_multi_file_logd_and_chunked_metadata(self):
+        relpaths = ["diagnostic/build-c.logd.part1", "diagnostic/build-c.logd.part2"]
+        report = build.build_diagnostic_report([], "c-chunk", logd_relpaths=relpaths, chunked=True)
+        self.assertEqual(report["diagnostic_logd"], relpaths)
+        self.assertTrue(report["chunked"])
+        self.assertIsNotNone(report["chunk_size_bytes"])
+        self.assertIn(relpaths[0], report["pr_note"])
+        self.assertIn(relpaths[1], report["pr_note"])
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# ── logd path handling ─────────────────────────────────────────
def test_report_includes_diagnostic_logd_key(self):
report = build.build_diagnostic_report([], "test")
self.assertIn("diagnostic_logd", report)
def test_logd_relpaths_appear_in_pr_note(self):
report = build.build_diagnostic_report(
[], "c3", logd_relpaths=["diagnostic/build-abc.logd"]
)
self.assertIn("build-abc.logd", report["pr_note"])
# ── logd path handling ─────────────────────────────────────────
def test_report_includes_diagnostic_logd_key(self):
report = build.build_diagnostic_report([], "test")
self.assertIn("diagnostic_logd", report)
def test_logd_relpaths_appear_in_pr_note(self):
report = build.build_diagnostic_report(
[], "c3", logd_relpaths=["diagnostic/build-abc.logd"]
)
self.assertIn("build-abc.logd", report["pr_note"])
def test_logd_failure_sets_error_without_archive_claim(self):
report = build.build_diagnostic_report(
[], "c-fail", logd_relpaths=None, logd_error="encrypt failed"
)
self.assertEqual(report["diagnostic_logd_error"], "encrypt failed")
self.assertIsNone(report["diagnostic_logd"])
self.assertIn("was not created", report["pr_note"])
def test_multi_file_logd_and_chunked_metadata(self):
relpaths = ["diagnostic/build-c.logd.part1", "diagnostic/build-c.logd.part2"]
report = build.build_diagnostic_report([], "c-chunk", logd_relpaths=relpaths, chunked=True)
self.assertEqual(report["diagnostic_logd"], relpaths)
self.assertTrue(report["chunked"])
self.assertIsNotNone(report["chunk_size_bytes"])
self.assertIn(relpaths[0], report["pr_note"])
self.assertIn(relpaths[1], report["pr_note"])
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_diagnostic_metadata.py` around lines 55 - 66, Add missing tests in
the diagnostic metadata suite to cover the `.logd` contract beyond the existing
single-path PR note assertion. Extend the checks around
build.build_diagnostic_report and related metadata handling to verify
diagnostic_logd_error is populated when report generation fails, and add
multi-file/chunked coverage that asserts diagnostic_logd can be a list and that
chunked/chunk_size_bytes metadata is preserved. Use the existing
build_diagnostic_report and diagnostic_logd symbols to locate the logic and
ensure the new assertions match the build.py behavior.

Comment on lines +69 to +82
def test_empty_results_are_deterministic(self):
report1 = build.build_diagnostic_report([], "same-commit")
report2 = build.build_diagnostic_report([], "same-commit")
self.assertEqual(report1["total_modules"], report2["total_modules"])
self.assertEqual(report1["passed"], report2["passed"])
self.assertEqual(report1["commit"], report2["commit"])

def test_same_inputs_produce_same_output(self):
results = [("m", True, 0.1, "out", None)]
r1 = build.build_diagnostic_report(results, "c4")
r2 = build.build_diagnostic_report(results, "c4")
self.assertEqual(r1["passed"], r2["passed"])
self.assertEqual(r1["total_modules"], r2["total_modules"])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Determinism tests are partial despite full-output naming

At Line 76 (test_same_inputs_produce_same_output), assertions only compare counters, so regressions in other stable fields can slip through. Either rename to reflect partial checks or assert equality on normalized reports (excluding generated_at).

Suggested tightening
     def test_same_inputs_produce_same_output(self):
         results = [("m", True, 0.1, "out", None)]
         r1 = build.build_diagnostic_report(results, "c4")
         r2 = build.build_diagnostic_report(results, "c4")
-        self.assertEqual(r1["passed"], r2["passed"])
-        self.assertEqual(r1["total_modules"], r2["total_modules"])
+        self.assertEqual(
+            {k: v for k, v in r1.items() if k != "generated_at"},
+            {k: v for k, v in r2.items() if k != "generated_at"},
+        )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def test_empty_results_are_deterministic(self):
report1 = build.build_diagnostic_report([], "same-commit")
report2 = build.build_diagnostic_report([], "same-commit")
self.assertEqual(report1["total_modules"], report2["total_modules"])
self.assertEqual(report1["passed"], report2["passed"])
self.assertEqual(report1["commit"], report2["commit"])
def test_same_inputs_produce_same_output(self):
results = [("m", True, 0.1, "out", None)]
r1 = build.build_diagnostic_report(results, "c4")
r2 = build.build_diagnostic_report(results, "c4")
self.assertEqual(r1["passed"], r2["passed"])
self.assertEqual(r1["total_modules"], r2["total_modules"])
def test_empty_results_are_deterministic(self):
report1 = build.build_diagnostic_report([], "same-commit")
report2 = build.build_diagnostic_report([], "same-commit")
self.assertEqual(report1["total_modules"], report2["total_modules"])
self.assertEqual(report1["passed"], report2["passed"])
self.assertEqual(report1["commit"], report2["commit"])
def test_same_inputs_produce_same_output(self):
results = [("m", True, 0.1, "out", None)]
r1 = build.build_diagnostic_report(results, "c4")
r2 = build.build_diagnostic_report(results, "c4")
self.assertEqual(
{k: v for k, v in r1.items() if k != "generated_at"},
{k: v for k, v in r2.items() if k != "generated_at"},
)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_diagnostic_metadata.py` around lines 69 - 82, The determinism test
named test_same_inputs_produce_same_output only checks a couple of counters, so
it can miss regressions in other stable fields from
build.build_diagnostic_report. Update this test to compare the full report
content in a normalized way, excluding non-deterministic fields such as
generated_at, or rename the test so it clearly reflects that it only validates
partial equality. Use build.build_diagnostic_report and the existing report
dictionaries to ensure all stable fields are covered.

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.

[$30 BOUNTY] [Python] Add build diagnostic metadata tests

1 participant