Repository navigation
feat: attestation progress events, M1 automatic progress (#3825) #3859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
f330ca5
feat(controlplane): store workflow run progress events
migmartri 3f1b486
feat(controlplane): delete workflow run events after a retention period
migmartri 5c9a84d
feat(cli): record attestation progress and show it in workflow run de…
migmartri 09fd46e
refactor: fold policy results into the attestation and push events
migmartri 80312ef
refactor: simplify run events after review
migmartri b1cf3df
fix(cli): record the push event just before the store
migmartri 7a96475
fix: address review of the run events
migmartri 481dad5
feat(controlplane): bound the size of run event fields
migmartri e52da9b
feat(cli): record one summary event for a large archive add
migmartri 08ac78c
feat(cli): record the evidence material of an archive add
migmartri 63baecf
feat(cli): show the run timeline as a tree in workflow run describe
migmartri c5d1de3
feat: record the push in the closing event of the store
migmartri 7b54ead
refactor: take the push result from the attestation, not the closing …
migmartri 785d267
docs(cli): correct the comment on the policy status of the timeline
migmartri dba4b39
feat: return the run progress and events in the workflow run view
migmartri b99a43c
test: use constants for repeated strings in the progress tests
migmartri 6dfba1c
docs: align the plan with the progress in the run view
migmartri d920087
fix: show a failed add with no error text as failed in the progress
migmartri 26ef6ca
feat: serve the run progress and events in their own GetProgress call
migmartri 7cb98bf
docs: fix a doc comment and a stale plan line after GetProgress
migmartri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| // | ||
| // Copyright 2026 The Chainloop Authors. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/chainloop-dev/chainloop/app/cli/pkg/action" | ||
| "github.com/jedib0t/go-pretty/v6/text" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestRenderRunTimeline(t *testing.T) { | ||
| text.DisableColors() | ||
| t.Cleanup(text.EnableColors) | ||
|
|
||
| start := time.Date(2026, 11, 30, 10, 0, 2, 0, time.Local) | ||
| at := func(d time.Duration) *time.Time { | ||
| v := start.Add(d) | ||
| return &v | ||
| } | ||
| started := &action.RunEvent{CreatedAt: at(0), Source: timelineSourceCLI, Key: timelineKeyAttestation, Status: "started", Attestation: &action.RunEventAttestation{ | ||
| ContractName: "build", ContractRevision: 3, RunnerType: "GITHUB_ACTION", Policies: &action.RunEventPolicyCount{Evaluated: 2, Passed: 2}}} | ||
| material := func(d time.Duration, name, status, msg string, policies *action.RunEventPolicyCount) *action.RunEvent { | ||
| return &action.RunEvent{CreatedAt: at(d), Source: timelineSourceCLI, Key: "chainloop.material." + name, Status: status, Message: msg, | ||
| Material: &action.RunEventMaterial{Name: name, Policies: policies}} | ||
| } | ||
|
|
||
| testCases := []struct { | ||
| name string | ||
| events []*action.RunEvent | ||
| progress *action.RunProgress | ||
| stored *action.PolicyEvaluationStatus | ||
| want string | ||
| }{ | ||
| { | ||
| name: "run in progress, with a failed then repeated add and a missing material", | ||
| events: []*action.RunEvent{ | ||
| started, | ||
| material(139*time.Second, "sast-report", "succeeded", "", &action.RunEventPolicyCount{Evaluated: 2, Passed: 1, Violated: 1}), | ||
| material(188*time.Second, "sbom", "failed", "invalid CycloneDX document: missing bomFormat", nil), | ||
| material(243*time.Second, "sbom", "succeeded", "", &action.RunEventPolicyCount{Evaluated: 2, Passed: 2}), | ||
| material(328*time.Second, "build-log", "succeeded", "", nil), | ||
| }, | ||
| progress: &action.RunProgress{ | ||
| RequiredTotal: 2, RequiredProvided: 1, | ||
| AttestationPolicies: &action.RunEventPolicyCount{Evaluated: 2, Passed: 2}, | ||
| Materials: []*action.RunProgressMaterial{ | ||
| {Name: "sbom", Requirement: action.RunMaterialRequired, Status: action.RunMaterialProvided}, | ||
| {Name: "image", Requirement: action.RunMaterialRequired, Status: action.RunMaterialMissing}, | ||
| {Name: "sast-report", Requirement: action.RunMaterialOptional, Status: action.RunMaterialProvided}, | ||
| {Name: "build-log", Requirement: action.RunMaterialNotInContract, Status: action.RunMaterialProvided}, | ||
| }, | ||
| }, | ||
| want: "Timeline (reported progress) · started 10:00:02 · running for 5m43s · 1 of 2 required provided · attestation policies: 2 passed\n" + | ||
| "├─ 10:00:02 ✓ initialized contract build rev 3 · GITHUB_ACTION · local state · policies: 2 passed\n" + | ||
| "├─ 10:02:21 ✓ added evidence `sast-report` optional · policies: 1 passed, 1 violated\n" + | ||
| "├─ 10:03:10 ✓ added evidence `sbom` required · policies: 2 passed · 1 failed attempt\n" + | ||
| "│ ├─ 10:03:10 ✗ invalid CycloneDX document: missing bomFormat\n" + | ||
| "│ └─ 10:04:05 ✓ succeeded\n" + | ||
| "├─ 10:05:30 ✓ added evidence `build-log` not in contract\n" + | ||
| "├─ ○ missing evidence `image` required\n" + | ||
| "└─ ● waiting for push\n", | ||
| }, | ||
| { | ||
| name: "provided, then a rejected duplicate add", | ||
| events: []*action.RunEvent{ | ||
| started, | ||
| material(60*time.Second, "sbom", "succeeded", "", nil), | ||
| material(120*time.Second, "sbom", "failed", "material already exists in the attestation", nil), | ||
| }, | ||
| progress: &action.RunProgress{ | ||
| RequiredTotal: 1, RequiredProvided: 1, | ||
| Materials: []*action.RunProgressMaterial{ | ||
| {Name: "sbom", Requirement: action.RunMaterialRequired, Status: action.RunMaterialProvided, LastError: "material already exists in the attestation", FailedAttempts: 1}, | ||
| }, | ||
| }, | ||
| want: "Timeline (reported progress) · started 10:00:02 · running for 5m43s · 1 of 1 required provided\n" + | ||
| "├─ 10:00:02 ✓ initialized contract build rev 3 · GITHUB_ACTION · local state · policies: 2 passed\n" + | ||
| "├─ 10:01:02 ✓ added evidence `sbom` required · 1 failed attempt\n" + | ||
| "│ ├─ 10:01:02 ✓ succeeded\n" + | ||
| "│ └─ 10:02:02 ✗ material already exists in the attestation\n" + | ||
| "└─ ● waiting for push\n", | ||
| }, | ||
| { | ||
| name: "stored run", | ||
| events: []*action.RunEvent{ | ||
| started, | ||
| material(451*time.Second, "vulnerability-report", "succeeded", "", nil), | ||
| {CreatedAt: at(501 * time.Second), Key: timelineKeyAttestation, Status: timelineSucceeded, Attestation: &action.RunEventAttestation{ | ||
| AttestationDigest: "sha256:4de7a1b2c3d4e5f60718293a4b5c6d7e8f"}}, | ||
| }, | ||
| stored: &action.PolicyEvaluationStatus{Total: 3, Passed: 3}, | ||
| want: "Timeline · started 10:00:02 · finished 10:08:23 (8m21s) · stored\n" + | ||
| "├─ 10:00:02 ✓ initialized contract build rev 3 · GITHUB_ACTION · local state · policies: 2 passed\n" + | ||
| "├─ 10:07:33 ✓ added evidence `vulnerability-report`\n" + | ||
| "└─ 10:08:23 ✓ pushed and stored policies: 3 passed · sha256:4de7a1b2c3d4…\n", | ||
| }, | ||
| { | ||
| name: "stored run blocked by a gate", | ||
| events: []*action.RunEvent{ | ||
| started, | ||
| {CreatedAt: at(60 * time.Second), Key: timelineKeyAttestation, Status: "succeeded", Attestation: &action.RunEventAttestation{ | ||
| AttestationDigest: "sha256:4de7"}}, | ||
| }, | ||
| stored: &action.PolicyEvaluationStatus{Total: 3, Passed: 2, Violated: 1, Blocked: true, HasGatedViolations: true}, | ||
| want: "Timeline · started 10:00:02 · finished 10:01:02 (1m0s) · stored\n" + | ||
| "├─ 10:00:02 ✓ initialized contract build rev 3 · GITHUB_ACTION · local state · policies: 2 passed\n" + | ||
| "└─ 10:01:02 ✓ pushed and stored policies: 2 passed, 1 violated · blocked by policy gates · sha256:4de7\n", | ||
| }, | ||
| { | ||
| name: "expired run", | ||
| events: []*action.RunEvent{ | ||
| started, | ||
| {CreatedAt: at(3600 * time.Second), Key: timelineKeyAttestation, Status: "failed", Message: "expired"}, | ||
| }, | ||
| want: "Timeline · started 10:00:02 · finished 11:00:02 (1h0m0s) · failed\n" + | ||
| "├─ 10:00:02 ✓ initialized contract build rev 3 · GITHUB_ACTION · local state · policies: 2 passed\n" + | ||
| "└─ 11:00:02 ✗ failed expired\n", | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| var buf bytes.Buffer | ||
| renderRunTimeline(&buf, tc.events, tc.progress, tc.stored, start.Add(343*time.Second)) | ||
| assert.Equal(t, tc.want, buf.String()) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // A run of an older CLI has no events, or only the closing event of the control plane. It | ||
| // shows as before, with no timeline. | ||
| func TestRenderRunTimelineNoCLIEvents(t *testing.T) { | ||
| now := time.Now() | ||
| closing := &action.RunEvent{CreatedAt: &now, Source: "control_plane", Key: timelineKeyAttestation, Status: "succeeded", | ||
| Attestation: &action.RunEventAttestation{AttestationDigest: "sha256:4de7"}} | ||
|
|
||
| for _, events := range [][]*action.RunEvent{nil, {closing}} { | ||
| var buf bytes.Buffer | ||
| renderRunTimeline(&buf, events, nil, nil, now) | ||
| assert.Empty(t, buf.String()) | ||
| } | ||
| } |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.