Skip to content
Merged
Show file tree
Hide file tree
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 Nov 30, 2026
3f1b486
feat(controlplane): delete workflow run events after a retention period
migmartri Nov 30, 2026
5c9a84d
feat(cli): record attestation progress and show it in workflow run de…
migmartri Nov 30, 2026
09fd46e
refactor: fold policy results into the attestation and push events
migmartri Nov 30, 2026
80312ef
refactor: simplify run events after review
migmartri Nov 30, 2026
b1cf3df
fix(cli): record the push event just before the store
migmartri Nov 30, 2026
7a96475
fix: address review of the run events
migmartri Nov 30, 2026
481dad5
feat(controlplane): bound the size of run event fields
migmartri Nov 30, 2026
e52da9b
feat(cli): record one summary event for a large archive add
migmartri Nov 30, 2026
08ac78c
feat(cli): record the evidence material of an archive add
migmartri Nov 30, 2026
63baecf
feat(cli): show the run timeline as a tree in workflow run describe
migmartri Nov 30, 2026
c5d1de3
feat: record the push in the closing event of the store
migmartri Nov 30, 2026
7b54ead
refactor: take the push result from the attestation, not the closing …
migmartri Nov 30, 2026
785d267
docs(cli): correct the comment on the policy status of the timeline
migmartri Nov 30, 2026
dba4b39
feat: return the run progress and events in the workflow run view
migmartri Dec 1, 2026
b99a43c
test: use constants for repeated strings in the progress tests
migmartri Dec 1, 2026
6dfba1c
docs: align the plan with the progress in the run view
migmartri Dec 1, 2026
d920087
fix: show a failed add with no error text as failed in the progress
migmartri Dec 1, 2026
26ef6ca
feat: serve the run progress and events in their own GetProgress call
migmartri Dec 1, 2026
7cb98bf
docs: fix a doc comment and a stale plan line after GetProgress
migmartri Dec 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
411 changes: 411 additions & 0 deletions app/cli/cmd/workflow_run_timeline.go

Large diffs are not rendered by default.

159 changes: 159 additions & 0 deletions app/cli/cmd/workflow_run_timeline_test.go
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())
}
}
30 changes: 30 additions & 0 deletions app/cli/cmd/workflow_workflow_run_describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,23 @@ func workflowRunDescribeTableOutput(run *action.WorkflowRunItemFull) error {
gt.AppendRow(table.Row{"Policy Status", wr.PolicyStatus})
gt.AppendRow(table.Row{"Runner Link", wr.RunURL})

if run.Progress != nil {
gt.Render()
renderRunTimeline(os.Stdout, run.Events, run.Progress, nil, time.Now())
return nil
}

if run.WorkflowRun.FinishedAt == nil {
gt.Render()
renderRunTimeline(os.Stdout, run.Events, nil, nil, time.Now())
logger.Info().Msg("the attestation crafting process is in progress, it has not been received yet")
return nil
}

att := run.Attestation
if att == nil {
gt.Render()
renderRunTimeline(os.Stdout, run.Events, nil, nil, time.Now())
logger.Warn().Msg("there was an issue retrieving the attestation")
return nil
}
Expand Down Expand Up @@ -175,10 +183,32 @@ func workflowRunDescribeTableOutput(run *action.WorkflowRunItemFull) error {
gt.Render()

predicateV1Table(att)
// The timeline is history: the signed attestation above is the source of truth
renderRunTimeline(os.Stdout, run.Events, nil, att.PolicyEvaluationStatus, time.Now())
logger.Info().Msg("you can use the flag \"--output statement\" to see the full in-toto statement")
return nil
}

// runPolicyCountSummary returns for example "2 passed, 1 violated", or an empty string with no evaluations
func runPolicyCountSummary(c *action.RunEventPolicyCount) string {
if c == nil || c.Evaluated == 0 {
return ""
}

parts := make([]string, 0, 3)
if c.Passed > 0 {
parts = append(parts, fmt.Sprintf("%d passed", c.Passed))
}
if c.Violated > 0 {
parts = append(parts, fmt.Sprintf("%d violated", c.Violated))
}
if c.Skipped > 0 {
parts = append(parts, fmt.Sprintf("%d skipped", c.Skipped))
}

return strings.Join(parts, ", ")
}

// appendPolicyStrategyRows adds the policy enforcement rows of a run.
// Only show the strategy when it is enforced. Showing "ADVISORY" is misleading
// when individual policies are configured as gates.
Expand Down
34 changes: 34 additions & 0 deletions app/cli/pkg/action/attestation_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,40 @@ func (action *AttestationAdd) Run(ctx context.Context, attestationID, materialNa
return nil, err
}

// Progress events are best effort, they never change the result of the add
events := newRunEventRecorderFromState(action.CPConnection, crafter.CraftingState.CraftingState, action.Logger)
results, err := action.addMaterial(ctx, crafter, attestationID, materialName, materialValue, materialType, annotations, policyInputFiles, runtimeInputs)
if err != nil {
_ = events.Record(ctx, materialFailedEvent(crafter, materialName, materialType, materialValue, err))
Comment thread
migmartri marked this conversation as resolved.
Resolved
return nil, err
}

recordMaterialEvents(ctx, events, crafter, materialName, materialType, materialValue, results)

return results, nil
}

// recordMaterialEvents records the events of a successful add. A large archive records one
// summary event, so that it does not use up the events of the run. An archive add also records
// the EVIDENCE material that stores the archive itself.
func recordMaterialEvents(ctx context.Context, events *runEventRecorder, c *crafter.Crafter, materialName, materialType, materialValue string, results []*AttestationStatusMaterial) {
if len(results) > runEventMaxArchiveMaterials {
_ = events.Record(ctx, archiveAddedEvent(c, materialName, materialType, materialValue, results))
} else {
for _, r := range results {
_ = events.Record(ctx, materialAddedEvent(c, r, false))
}
}

if format, err := shouldExplode(materialType, materialValue); err == nil && format != materials.ArchiveNone {
if archive := archiveEvidenceMaterial(c, results); archive != nil {
_ = events.Record(ctx, materialAddedEvent(c, archive, false))
}
}
}

// addMaterial adds the material, or the materials of an archive, to the loaded crafting state
func (action *AttestationAdd) addMaterial(ctx context.Context, crafter *crafter.Crafter, attestationID, materialName, materialValue, materialType string, annotations map[string]string, policyInputFiles []*PolicyInputFromFile, runtimeInputs *policies.RuntimeInputs) ([]*AttestationStatusMaterial, error) {
// Default to inline CASBackend and override if we are not in dry-run mode
casBackend := &casclient.CASBackend{
Name: "not-set",
Expand Down
8 changes: 8 additions & 0 deletions app/cli/pkg/action/attestation_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,14 @@ func (action *AttestationInit) Run(ctx context.Context, opts *AttestationInitRun
return "", fmt.Errorf("evaluating attestation policies: %w", err)
}

// Progress events are best effort, they never stop the attestation. The start of the
// timeline holds the init policy results, then come the materials that collectors added.
events := newRunEventRecorder(action.CPConnection, attestationID, action.Logger)
_ = events.Record(ctx, attestationStartedEvent(action.c.CraftingState.CraftingState, action.useRemoteState, action.CLIVersion))
for _, ev := range collectedMaterialEvents(action.c, action.Logger) {
_ = events.Record(ctx, ev)
}

return attestationID, nil
}

Expand Down
Loading
Loading