refactor(attest): record attestations through one attestation submitter - #1243
Merged
Merged
Conversation
… attestation submitter
…ch now owns evidence packaging
Contributor
|
Claude finished @dangrondahl's task in 2m 25s —— View job Review of PR #1243 —
|
| Check | Result |
|---|---|
go build ./... |
✅ passes |
go vet ./cmd/... ./internal/... |
✅ passes |
go mod tidy + git diff --exit-code go.mod go.sum |
✅ no changes |
I couldn't run go test in this environment because it needs approval. The new unit tests are left to CI.
Findings
I found no bugs or regressions. I checked each migrated command against main line by line:
- Success messages are unchanged. That includes
custom:<type>and<provider> <label>. - URL slugs are unchanged. decision and sbom still go to
system. - jira
--asserterrors keep their order and their\nError:join: "no references" comes before "not found/unconfirmed". - PR
--asserterrors keep their order and join in the same way. - The server-error rewording still covers assert errors.
wrapAttestationErrorruns on the joined error, as it did before. - Dry-run still drops assert failures.
One nit, posted inline:
cmd/kosli/attestSbom.go:265: the doc comment onevidence()was only partly reflowed. The first line is about 130 columns long. There is a suggestion block on the comment.
Optional, not blocking:
attestationSubmitter.formcovers three different evidence sources: in-memory, none, and file paths. That is easy to follow now. If a fourth source ever comes along, a smallevidenceSourceinterface would read better than more branches. You don't need it yet.- Three earlier review points are fixed in 2595236, and the fixes are pinned by tests:
- the staging directory is now removed when an attachment copy fails
- the logger is now passed in rather than taken from a global
formnow rejectsevidenceandattachmentstogether
What's good
- Clean seam. The submitter takes its client, host, org, token, dry-run flag and logger as fields, and
newAttestationSubmitter()is the only place that reads globals. That makes thehttptesttests possible without a live server. - Assert failures are values.
assertFailures []errorreplaces two copies of theerrStringstring building. It also makes the rule "record first, then fail" explicit and testable. - The sbom guarantee still holds.
evidence()still takes the bytes as a parameter, so the bytes that are uploaded are always the bytes that were hashed.TestSbomUploadsTheBytesItHashedstill checks this. - The tests are well targeted. Tarball cleanup is checked after both a success and a server rejection, and the staging directory is checked after a failed copy. The fake server's handler also avoids
requireoff the test goroutine. - Thorough testing for a pure refactor. You compared 45 command outputs between
mainand this branch, and listed the known differences on error paths up front.
I'd be happy to see this merged once CI is green.
… to copy The staging dir's cleanup was registered only after every attachment had been copied, so a missing or unreadable attachment left it in $TMPDIR. Also from review on #1243: - getPathOfEvidenceFileToUpload takes the submitter's logger - a submission with both in-memory evidence and attachments is rejected instead of silently dropping the attachments - the fake attestation server reports failures with assert and a 500, since require's FailNow is unsafe off the test goroutine - the endpoint variable no longer shadows net/url
Contributor
Follow-up review of latest commit (2595236)All three previously raised findings are resolved:
No new bugs/regressions found in the changed lines (cmd/kosli/attestationSubmit.go, cmd/kosli/attestationSubmit_test.go, cmd/kosli/cli_utils_test.go). |
dangrondahl
marked this pull request as ready for review
October 2, 2026 13:49
Contributor
Author
AlexKantor87
approved these changes
Oct 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Every
attestcommand repeated the same steps for sending an attestation: build the URL, build the form, tar the evidence and delete the tarball afterwards, handle dry-run, log success, join the--assertfailures, and reword the server's error. This PR moves those steps into oneattestationSubmitter(cmd/kosli/attestationSubmit.go). Each command now just builds its payload and callssubmit(...).It is a pure refactor: output and request bodies should be unchanged.
Migrated: generic, custom, decision, junit, snyk, sonar, jira, sbom, and the four
attest pullrequestcommands.Not migrated:
attest override, which posts JSON rather than a form.attest artifact, which uses a different endpoint.Removed and moved:
prepareAttestationFormwas a pass-through and is deleted, along withnewAttestationForm.getPathOfEvidenceFileToUploadandwrapAttestationErrormoved out ofcli_utils.goandattestation.gointo the new file.sbom: it now hands over its already-read bytes in a new
evidencefield and no longer builds its own form. The guarantee that the uploaded bytes are exactly the bytes that were hashed still holds and is still tested.Testing
httptestserver. They check:data_jsonandattachment_filepartsmainand this branch and diffed their output for 15 commands. Each ran in dry-run, against a stub that returns 201, and against a stub that returns 400. All 45 runs matched byte for byte:--assert), github/gitlab PR (±--assert), sbom (CycloneDX, SPDX, invalid file) and a missing attachment.Known differences from main
These only affect error paths:
--hostis now reported after the payload is resolved, not before.--attachmentsnow fails after the "found N pull request(s)" line, not before.Checklist
charts/k8s-reporter/) updated, if needed. Note: these changes live in a separate PR (n/a)