test: check the vendored MADR files against the blob SHAs in NOTICE #864

Merged
hexajon merged 1 commit from issue-520-madr-notice-blob-sha-test into main 2026-10-21 16:55:53 +00:00
Owner

Summary

What was wrong

internal/service/adr/madr/NOTICE records the upstream git blob SHA-1 of each vendored MADR 4.0.0 file. It says the files are vendored byte for byte, because adr new and adr init write them out verbatim. No test checked this. A reformat, a stray edit, or a normalised newline would pass every gate.

What changed

I added two test files in internal/service/adr/madr/. No production code changes.

  • notice_helpers_test.go holds two helpers.
    • gitBlobSHA1 computes the git blob id: SHA-1 over the header blob <len>\x00 followed by the bytes. It does not run git, because this repo uses the sha256 object format.
    • parseNoticeRows reads the NOTICE rows that start with template/. It maps each file base name to its SHA-1. It returns an error for a bad SHA-1, a duplicate name, a row with the wrong field count, or a table with no rows.
  • notice_test.go holds the tests.

What the tests cover

  • TestNoticeBlobSHAs hashes each vendored file from disk and from the embedded bytes (TemplateBare, Template, Record0000). It compares both hashes with the SHA in NOTICE. A mismatch fails with the file name and both hashes. It also checks that the embedded bytes equal the file on disk. It fails when NOTICE does not list exactly the *.md files in the directory, so NOTICE and the files must change together.
  • TestGitBlobSHA1 locks the helper against known git hash-object ids for an empty file and for hello\n. It also shows that flipping one bit of adr-template-bare.md changes the hash. This covers the acceptance point that a one-byte change fails the check.
  • TestParseNoticeRows checks that a short SHA, a missing SHA, a duplicate row, and a table with no rows are errors.

Refs #520

./scripts/gate.sh passes on this commit.

Closes #520

## Summary ## What was wrong `internal/service/adr/madr/NOTICE` records the upstream git blob SHA-1 of each vendored MADR 4.0.0 file. It says the files are vendored byte for byte, because `adr new` and `adr init` write them out verbatim. No test checked this. A reformat, a stray edit, or a normalised newline would pass every gate. ## What changed I added two test files in `internal/service/adr/madr/`. No production code changes. - `notice_helpers_test.go` holds two helpers. - `gitBlobSHA1` computes the git blob id: SHA-1 over the header `blob <len>\x00` followed by the bytes. It does not run git, because this repo uses the sha256 object format. - `parseNoticeRows` reads the `NOTICE` rows that start with `template/`. It maps each file base name to its SHA-1. It returns an error for a bad SHA-1, a duplicate name, a row with the wrong field count, or a table with no rows. - `notice_test.go` holds the tests. ## What the tests cover - `TestNoticeBlobSHAs` hashes each vendored file from disk and from the embedded bytes (`TemplateBare`, `Template`, `Record0000`). It compares both hashes with the SHA in `NOTICE`. A mismatch fails with the file name and both hashes. It also checks that the embedded bytes equal the file on disk. It fails when `NOTICE` does not list exactly the `*.md` files in the directory, so `NOTICE` and the files must change together. - `TestGitBlobSHA1` locks the helper against known `git hash-object` ids for an empty file and for `hello\n`. It also shows that flipping one bit of `adr-template-bare.md` changes the hash. This covers the acceptance point that a one-byte change fails the check. - `TestParseNoticeRows` checks that a short SHA, a missing SHA, a duplicate row, and a table with no rows are errors. Refs #520 `./scripts/gate.sh` passes on this commit. Closes #520
test: check the vendored MADR files against the blob SHAs in NOTICE
Some checks failed
drift / govulncheck (pull_request) Has been skipped
drift / surface-diff (pull_request) Successful in 47s
drift / forgejo-smoke (pull_request) Has been skipped
drift / govulncheck (push) Has been skipped
drift / surface-diff (push) Successful in 3m23s
drift / forgejo-smoke (push) Has been skipped
ci / gate (push) Failing after 24m49s
ci / gate (pull_request) Failing after 48m58s
e3d43cb2b4
The test computes the git blob SHA-1 of each vendored MADR file, from disk
and from the embedded bytes, and compares it with the SHA in NOTICE. It
fails with the file name and both hashes. It also fails when NOTICE does not
list exactly the vendored markdown files, so NOTICE and the files change
together.

Refs #520
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
sixfold-space/madtea!864
No description provided.