Repository navigation
fix: stop get trail table output panicking on partial commit info - #1365
Conversation
|
Claude finished @tooky's task in 1m 34s —— View job Follow-up review (commits
|
Follow-up review (commits
|
|
Follow-up on the Sha1 consistency nit: done in 110e9ca. The markdown Sha1 cell now uses |
|
#1368 fixes Snyk tests |
Commit info on a trail may carry only a sha1 (the trails API accepts partial commit info), and the table renderer used unchecked type assertions on author, timestamp and message, so it panicked. Render missing fields as N/A, matching the markdown output.
…ssing, so markdown and table output agree. In `cmd/kosli/getTrail.go:119` the cell uses `mdCell(stringOrNA(commitInfo["sha1"]))`, the same pattern the Author and Message cells already use. The Timestamp cell already gave N/A through `formattedTimestamp`, so every field in the Git commit section now handles a missing value. When sha1 is present, `stringOrNA` returns it unchanged, so normal output and the commit-URL link are the same as before. `TestPrintTrailAsMarkdownPartialCommitInfo` (`cmd/kosli/getTrail_markdown_test.go`) has a new case: commit info with only an author renders `| Sha1 | N/A |`. With the production change reverted, that assertion fails; with the fix, it passes. All `TestPrintTrailAsMarkdown*` tests pass, and `go vet` and `golangci-lint` report no issues. The Snyk CI findings the user declined earlier were not touched. Nothing has been committed
110e9ca to
f31f718
Compare
mbevc1
left a comment
There was a problem hiding this comment.
Left a small nit about n/a capitalisation, but looks good otherwise
kosli get trail(default table output) panics when a trail'sgit_commit_infois missingauthor,timestampormessage, or has them asnull. The server already accepts such trails throughPUT /api/v2/trails/{org}/{flow}, so this crash can happen today. This PR shows missing fields asN/Ainstead. Trails with full commit info display exactly as before.What changed
printTrailAsTable(cmd/kosli/getTrail.go) no longer uses unchecked type assertions (commitInfo["author"].(string)etc.).stringOrNAhelper, which returnsN/Afor a missing,nullor empty value.formattedTimestamp, which already returnsN/Afor nil.urlrow only appears when the URL is a non-empty string. Previously"url": nullprintedurl: %!s(<nil>).stringOrNAtoo. Markdown didn't panic before, but it left blank cells; now both formats showN/A.TestPrintTrailAsTableCommitInfocovers sha1 only, sha1 + branch, explicit nulls and full commit info, using regexps so it doesn't depend on tabwriter padding.TestPrintTrailAsMarkdownPartialCommitInfocovers sha1-only and missing-sha1 commit info.Known edge, out of scope: a commit with a url but no sha1 renders
[N/A](url)in markdown. The server always sends a sha1.Merge order
This PR doesn't depend on any server change. It should be released before kosli-dev/server#7994 (draft), which fixes kosli-dev/server#7988 by letting artifacts be reported with sha1-only commit info. A reported artifact creates its trail with the same commit info, so once #7994 ships, ordinary artifact reporting can produce trails that crash this command in CLIs without this fix.
Older CLIs are only partly exposed:
kosli attest artifactalways sendssha1,author,message,branchandtimestamp, so trails it creates stay complete.kosli attest in-toto(feat: add kosli attest in-toto, recording attestations from bundle files #1362) when a bundle carries no commit metadata.Testing
get trailagainst a local stub of the trails API serving sha1-only, all-null, no-author and full commit info. The base binary panics on sha1-only and no-author (interface conversion: interface {} is nil, not string,getTrail.go:372). The fixed binary printsN/Aand exits 0, and full commit info renders unchanged.N/Ain markdown) is covered by the markdown test.The two failing checks,
license/snyk (kosli)andsecurity/snyk (kosli), come from a Snyk project setup issue, not from this change. They aren't required onmain.