Skip to content

test: add build diagnostic metadata regression tests#45

Open
brain-marchine wants to merge 1 commit into
jackjin1997:mainfrom
brain-marchine:test/build-diagnostic-metadata
Open

test: add build diagnostic metadata regression tests#45
brain-marchine wants to merge 1 commit into
jackjin1997:mainfrom
brain-marchine:test/build-diagnostic-metadata

Conversation

@brain-marchine

@brain-marchine brain-marchine commented Jul 11, 2026

Copy link
Copy Markdown

Fixes #3

Summary

Add focused regression tests for build.py diagnostic JSON metadata and .logd chunking so future build changes cannot break the PR diagnostic contract.

Changes

  • tests/test_build_diagnostic.py covers successful metadata, logd failure (diagnostic_logd_error), chunked multi-file references, and split_diagnostic_logd.
  • tests/README.md documents the local test command.

Testing

  • python3 -m pytest -q tests/test_build_diagnostic.py — 6 passed
  • python3 build.py -m frailbox — diagnostic artifacts included (diagnostic/build-00000000.logd + .json)

Checklist

  • Relevant modules affected by these changes build locally
  • Tests pass locally
  • Diagnostic build log is committed in this PR
  • Documentation has been updated, if applicable
  • Configuration or schema changes are documented, if applicable
  • No generated build artifacts are committed, except the required diagnostic build log
  • Changes are scoped to the PR purpose and avoid unrelated cleanup
  • Security, privacy, and error-handling implications have been considered

Payout wallet (Base): 0x86D4FC06f553792D8c33058438Bcc7444182EB30

Summary by CodeRabbit

  • Documentation

    • Added instructions for running diagnostic regression tests.
  • Tests

    • Added coverage for diagnostic report generation, error handling, chunked logs, file splitting, and commit-based diagnostic paths.
    • Verified metadata and output behavior across successful and failure scenarios.
  • Chores

    • Regenerated diagnostic artifacts without changing their contents or conveyed information.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds deterministic regression tests for build diagnostic metadata, logd creation failures, chunked artifacts, file splitting, and commit-based paths. Documents the pytest command and refreshes diagnostic fixture representations without changing their contents.

Changes

Diagnostic regression coverage

Layer / File(s) Summary
Diagnostic report and logd tests
tests/test_build_diagnostic.py, tests/README.md, diagnostic/*
Adds tests for diagnostic report metadata, logd failures and chunking, file splitting, and commit-based paths; documents the test command and refreshes diagnostic artifacts without changing their values.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding regression tests for build diagnostic metadata.
Description check ✅ Passed The description includes summary, changes, testing, and checklist sections with concrete commands and results.
Linked Issues check ✅ Passed The changes cover the issue's required diagnostic metadata, failure, chunking, deterministic tests, and local test documentation.
Out of Scope Changes check ✅ Passed The diff stays focused on diagnostic tests, docs, and required diagnostic artifacts without unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

Warning

⚠️ This pull request has been flagged as potential spam (promotional) by CodeRabbit slop detection and should be reviewed carefully.

@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: 6

🤖 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 `@diagnostic/build-00000000.json`:
- Around line 4-9: Replace the placeholder diagnostic artifact referenced by
diagnostic_logd with the actual generated encrypted .logd archive and matching
password/decrypt_command, or mark generation as failed by setting
diagnostic_logd, password, and decrypt_command to null; do not report plain-text
stub content as a valid encrypted artifact.
- Line 22: Regenerate the golden diagnostic artifact through the current
build.py path so the pr_note metadata matches the current contract: describe the
encrypted .logd as the required diagnostic content and the JSON as metadata. Do
not hand-edit the generated JSON; refresh it using the builder and preserve the
resulting production output.

In `@diagnostic/build-00000000.logd`:
- Line 1: Replace the placeholder in the build-00000000.logd fixture with the
valid generated encrypted artifact expected by encryptly pack, ensuring it
matches the decryptable status advertised by build-00000000.json; otherwise
update that JSON to report logd creation failure.

In `@tests/test_build_diagnostic.py`:
- Around line 100-113: Update test_split_diagnostic_logd_splits_oversized_file
to retain the original 2,500-byte payload and assert that concatenating the
bytes from chunks, in returned order, exactly reproduces that payload. Keep the
existing chunk count, names, source removal, and aggregate-size assertions.
- Around line 70-87: Update test_diagnostic_report_chunked_logd_references to
assert the complete expected decrypt_command, including the derived target
diagnostic/build-deadbeef.logd, command structure, and password, instead of only
checking the suffix and commit ID.
- Around line 49-52: Expand the success test’s assertions for the module
summaries in the existing report validation, covering each module’s
elapsed_seconds, artifact, and output fields alongside name and status. Assert
the complete expected metadata values for both backend and failing modules so
regressions in the report contract are detected.
🪄 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: e93c6a25-2dbb-415a-9367-ad3aab6ed64a

📥 Commits

Reviewing files that changed from the base of the PR and between 1462fe7 and 305ee35.

📒 Files selected for processing (4)
  • diagnostic/build-00000000.json
  • diagnostic/build-00000000.logd
  • tests/README.md
  • tests/test_build_diagnostic.py

Comment on lines +4 to +9
"diagnostic_logd": "diagnostic/build-00000000.logd",
"diagnostic_logd_error": null,
"chunked": false,
"chunk_size_bytes": null,
"password": "4c7df15ab09fbb066197",
"decrypt_command": "encryptly unpack diagnostic/build-00000000.logd <outdir> --password 4c7df15ab09fbb066197",

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 | ⚡ Quick win

Do not claim a valid encrypted artifact for the placeholder .logd.

This report supplies diagnostic_logd, a password, and a decrypt command, but diagnostic/build-00000000.logd contains plain-text stub content rather than an encrypted archive. Replace it with the actual generated artifact, or mark the report as a logd-generation failure with diagnostic_logd: null and no password/decrypt command.

🤖 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 `@diagnostic/build-00000000.json` around lines 4 - 9, Replace the placeholder
diagnostic artifact referenced by diagnostic_logd with the actual generated
encrypted .logd archive and matching password/decrypt_command, or mark
generation as failed by setting diagnostic_logd, password, and decrypt_command
to null; do not report plain-text stub content as a valid encrypted artifact.

"output": "Command not found: [Errno 2] No such file or directory: 'make'"
}
],
"pr_note": "Include this JSON diagnostic report and diagnostic/build-00000000.logd in your PR. Maintainers may ask you to remove these diagnostic artifacts before merging."

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 | 🟡 Minor | ⚡ Quick win

Regenerate the report metadata from the current builder.

The current build.py contract describes the encrypted .logd as the required diagnostic content and the JSON as metadata, but this checked-in pr_note still uses the older “include this JSON diagnostic report” wording. If this is a golden artifact, regenerate it through the current build path so the fixture cannot drift from production output.

🤖 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 `@diagnostic/build-00000000.json` at line 22, Regenerate the golden diagnostic
artifact through the current build.py path so the pr_note metadata matches the
current contract: describe the encrypted .logd as the required diagnostic
content and the JSON as metadata. Do not hand-edit the generated JSON; refresh
it using the builder and preserve the resulting production output.

@@ -1 +1 @@
stub diagnostic logd placeholder
stub diagnostic logd placeholder

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 | ⚡ Quick win

Replace the stub with a valid .logd fixture.

build.py treats this path as the output of encryptly pack, while diagnostic/build-00000000.json advertises it as decryptable. A plain-text placeholder cannot satisfy that artifact contract; commit the generated encrypted artifact or update the JSON to report that logd creation failed.

🤖 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 `@diagnostic/build-00000000.logd` at line 1, Replace the placeholder in the
build-00000000.logd fixture with the valid generated encrypted artifact expected
by encryptly pack, ensuring it matches the decryptable status advertised by
build-00000000.json; otherwise update that JSON to report logd creation failure.

Comment on lines +49 to +52
assert len(report["modules"]) == 2
assert report["modules"][0]["name"] == "backend"
assert report["modules"][0]["status"] == "PASS"
assert report["modules"][1]["status"] == "FAIL"

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 | 🟡 Minor | ⚡ Quick win

Assert the complete module summaries.

The success test does not verify elapsed_seconds, artifact, or output, so regressions in those report fields would still pass despite the stated metadata-contract objective.

Suggested assertion
-    assert len(report["modules"]) == 2
-    assert report["modules"][0]["name"] == "backend"
-    assert report["modules"][0]["status"] == "PASS"
-    assert report["modules"][1]["status"] == "FAIL"
+    assert report["modules"] == [
+        {
+            "name": "backend",
+            "status": "PASS",
+            "elapsed_seconds": 1.234,
+            "artifact": "backend/target/debug/backend",
+            "output": "compiled ok",
+        },
+        {
+            "name": "frontend",
+            "status": "FAIL",
+            "elapsed_seconds": 0.5,
+            "artifact": None,
+            "output": "npm ERR!",
+        },
+    ]
📝 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
assert len(report["modules"]) == 2
assert report["modules"][0]["name"] == "backend"
assert report["modules"][0]["status"] == "PASS"
assert report["modules"][1]["status"] == "FAIL"
assert report["modules"] == [
{
"name": "backend",
"status": "PASS",
"elapsed_seconds": 1.234,
"artifact": "backend/target/debug/backend",
"output": "compiled ok",
},
{
"name": "frontend",
"status": "FAIL",
"elapsed_seconds": 0.5,
"artifact": None,
"output": "npm ERR!",
},
]
🤖 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_build_diagnostic.py` around lines 49 - 52, Expand the success
test’s assertions for the module summaries in the existing report validation,
covering each module’s elapsed_seconds, artifact, and output fields alongside
name and status. Assert the complete expected metadata values for both backend
and failing modules so regressions in the report contract are detected.

Comment on lines +70 to +87
def test_diagnostic_report_chunked_logd_references():
chunks = [
"diagnostic/build-deadbeef-part001.logd",
"diagnostic/build-deadbeef-part002.logd",
]
report = build.build_diagnostic_report(
SAMPLE_RESULTS,
"deadbeef",
logd_relpaths=chunks,
password="chunkpw",
chunked=True,
)

assert report["diagnostic_logd"] == chunks
assert report["chunked"] is True
assert report["chunk_size_bytes"] == build.DIAGNOSTIC_CHUNK_SIZE
assert report["decrypt_command"].endswith("--password chunkpw")
assert "build-deadbeef" in report["decrypt_command"]

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 | 🟡 Minor | ⚡ Quick win

Assert the exact chunked decrypt command.

Checking only that the command contains the commit ID and ends with the password would allow an incorrect archive path or command structure to pass. build.py derives the multi-file target as diagnostic/build-deadbeef.logd; assert the complete contract.

Suggested assertion
-    assert report["decrypt_command"].endswith("--password chunkpw")
-    assert "build-deadbeef" in report["decrypt_command"]
+    assert report["decrypt_command"] == (
+        "encryptly unpack diagnostic/build-deadbeef.logd "
+        "<outdir> --password chunkpw"
+    )
📝 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_diagnostic_report_chunked_logd_references():
chunks = [
"diagnostic/build-deadbeef-part001.logd",
"diagnostic/build-deadbeef-part002.logd",
]
report = build.build_diagnostic_report(
SAMPLE_RESULTS,
"deadbeef",
logd_relpaths=chunks,
password="chunkpw",
chunked=True,
)
assert report["diagnostic_logd"] == chunks
assert report["chunked"] is True
assert report["chunk_size_bytes"] == build.DIAGNOSTIC_CHUNK_SIZE
assert report["decrypt_command"].endswith("--password chunkpw")
assert "build-deadbeef" in report["decrypt_command"]
def test_diagnostic_report_chunked_logd_references():
chunks = [
"diagnostic/build-deadbeef-part001.logd",
"diagnostic/build-deadbeef-part002.logd",
]
report = build.build_diagnostic_report(
SAMPLE_RESULTS,
"deadbeef",
logd_relpaths=chunks,
password="chunkpw",
chunked=True,
)
assert report["diagnostic_logd"] == chunks
assert report["chunked"] is True
assert report["chunk_size_bytes"] == build.DIAGNOSTIC_CHUNK_SIZE
assert report["decrypt_command"] == (
"encryptly unpack diagnostic/build-deadbeef.logd "
"<outdir> --password chunkpw"
)
🧰 Tools
🪛 Ruff (0.15.20)

[error] 79-79: Possible hardcoded password assigned to argument: "password"

(S106)

🤖 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_build_diagnostic.py` around lines 70 - 87, Update
test_diagnostic_report_chunked_logd_references to assert the complete expected
decrypt_command, including the derived target diagnostic/build-deadbeef.logd,
command structure, and password, instead of only checking the suffix and commit
ID.

Comment on lines +100 to +113
def test_split_diagnostic_logd_splits_oversized_file(tmp_path: Path):
logd = tmp_path / "build-abcd1234.logd"
logd.write_bytes(b"x" * 2500)

chunks = build.split_diagnostic_logd(logd, chunk_size=1024)

assert len(chunks) == 3
assert not logd.exists()
assert [path.name for path in chunks] == [
"build-abcd1234-part001.logd",
"build-abcd1234-part002.logd",
"build-abcd1234-part003.logd",
]
assert sum(path.stat().st_size for path in chunks) == 2500

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 | 🟡 Minor | ⚡ Quick win

Verify chunk contents, not only aggregate size.

A splitter could reorder, truncate, or replace bytes while still producing three chunks whose total size is 2,500 bytes. Preserve the input payload and assert that concatenating the generated chunks reproduces it exactly.

Suggested assertion
-    logd.write_bytes(b"x" * 2500)
+    payload = b"x" * 2500
+    logd.write_bytes(payload)
...
     assert sum(path.stat().st_size for path in chunks) == 2500
+    assert b"".join(path.read_bytes() for path in chunks) == payload
📝 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_split_diagnostic_logd_splits_oversized_file(tmp_path: Path):
logd = tmp_path / "build-abcd1234.logd"
logd.write_bytes(b"x" * 2500)
chunks = build.split_diagnostic_logd(logd, chunk_size=1024)
assert len(chunks) == 3
assert not logd.exists()
assert [path.name for path in chunks] == [
"build-abcd1234-part001.logd",
"build-abcd1234-part002.logd",
"build-abcd1234-part003.logd",
]
assert sum(path.stat().st_size for path in chunks) == 2500
def test_split_diagnostic_logd_splits_oversized_file(tmp_path: Path):
logd = tmp_path / "build-abcd1234.logd"
payload = b"x" * 2500
logd.write_bytes(payload)
chunks = build.split_diagnostic_logd(logd, chunk_size=1024)
assert len(chunks) == 3
assert not logd.exists()
assert [path.name for path in chunks] == [
"build-abcd1234-part001.logd",
"build-abcd1234-part002.logd",
"build-abcd1234-part003.logd",
]
assert sum(path.stat().st_size for path in chunks) == 2500
assert b"".join(path.read_bytes() for path in chunks) == payload
🤖 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_build_diagnostic.py` around lines 100 - 113, Update
test_split_diagnostic_logd_splits_oversized_file to retain the original
2,500-byte payload and assert that concatenating the bytes from chunks, in
returned order, exactly reproduces that payload. Keep the existing chunk count,
names, source removal, and aggregate-size assertions.

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