test: add build diagnostic metadata regression tests#45
Conversation
📝 WalkthroughWalkthroughAdds 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. ChangesDiagnostic regression coverage
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment Warning |
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
diagnostic/build-00000000.jsondiagnostic/build-00000000.logdtests/README.mdtests/test_build_diagnostic.py
| "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", |
There was a problem hiding this comment.
🗄️ 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." |
There was a problem hiding this comment.
🗄️ 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 | |||
There was a problem hiding this comment.
🗄️ 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.
| assert len(report["modules"]) == 2 | ||
| assert report["modules"][0]["name"] == "backend" | ||
| assert report["modules"][0]["status"] == "PASS" | ||
| assert report["modules"][1]["status"] == "FAIL" |
There was a problem hiding this comment.
🎯 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.
| 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.
| 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"] |
There was a problem hiding this comment.
🎯 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.
| 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.
| 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 |
There was a problem hiding this comment.
🗄️ 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.
| 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.
Fixes #3
Summary
Add focused regression tests for
build.pydiagnostic JSON metadata and.logdchunking so future build changes cannot break the PR diagnostic contract.Changes
tests/test_build_diagnostic.pycovers successful metadata, logd failure (diagnostic_logd_error), chunked multi-file references, andsplit_diagnostic_logd.tests/README.mddocuments the local test command.Testing
python3 -m pytest -q tests/test_build_diagnostic.py— 6 passedpython3 build.py -m frailbox— diagnostic artifacts included (diagnostic/build-00000000.logd+.json)Checklist
Payout wallet (Base):
0x86D4FC06f553792D8c33058438Bcc7444182EB30Summary by CodeRabbit
Documentation
Tests
Chores