Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 19 additions & 5 deletions pkg/cmd/internal/templates/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ func WriteStatusList(data StatusListData) {
maxState := 5 // "STATE"
maxStarted := 7 // "STARTED"
for _, a := range data.Applies {
maxID = maxLen(maxID, len(a.ApplyID))
maxID = maxLen(maxID, len(statusApplyID(data, a)))
if data.ShowExternalID {
maxExternal = maxLen(maxExternal, len(statusExternalID(data, a)))
}
Expand Down Expand Up @@ -1127,7 +1127,7 @@ func WriteStatusList(data StatusListData) {
switch {
case data.ShowExternalID && showDeployment:
fmt.Printf(" %-*s %-*s %-*s %-*s %-*s %s %-*s %s\n",
maxID, a.ApplyID,
maxID, statusApplyID(data, a),
maxExternal, statusExternalID(data, a),
maxDB, a.Database,
maxEnv, a.Environment,
Expand All @@ -1137,7 +1137,7 @@ func WriteStatusList(data StatusListData) {
caller.Short(a.Caller))
case data.ShowExternalID:
fmt.Printf(" %-*s %-*s %-*s %-*s %s %-*s %s\n",
maxID, a.ApplyID,
maxID, statusApplyID(data, a),
maxExternal, statusExternalID(data, a),
maxDB, a.Database,
maxEnv, a.Environment,
Expand All @@ -1146,7 +1146,7 @@ func WriteStatusList(data StatusListData) {
caller.Short(a.Caller))
case showDeployment:
fmt.Printf(" %-*s %-*s %-*s %-*s %s %-*s %s\n",
maxID, a.ApplyID,
maxID, statusApplyID(data, a),
maxDB, a.Database,
maxEnv, a.Environment,
maxDeployment, a.Deployment,
Expand All @@ -1155,7 +1155,7 @@ func WriteStatusList(data StatusListData) {
caller.Short(a.Caller))
default:
fmt.Printf(" %-*s %-*s %-*s %s %-*s %s\n",
maxID, a.ApplyID,
maxID, statusApplyID(data, a),
maxDB, a.Database,
maxEnv, a.Environment,
coloredState,
Expand Down Expand Up @@ -1215,6 +1215,20 @@ func writeFailedStatusList(data StatusListData) {
}
}

// statusApplyID returns the identifier rendered in the APPLY ID column. A
// deployment-filtered list is the deployment's view of each apply, and the
// deployment's data-plane apply id is the handle its operator correlates
// with the data plane's own storage and logs, so it takes the column when
// one is recorded. Rows without one — not yet dispatched, locally driven, or
// omitted because the deployment's operations disagree — keep the
// control-plane apply id so every row carries a usable handle.
func statusApplyID(data StatusListData, a ActiveApplyData) string {
if data.Deployment != "" && a.ExternalID != "" {
return a.ExternalID
}
return a.ApplyID
}

func statusExternalID(data StatusListData, a ActiveApplyData) string {
if a.ExternalOperationID != "" {
return a.ExternalOperationID
Expand Down
38 changes: 35 additions & 3 deletions pkg/cmd/internal/templates/progress_states_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,11 @@ func TestWriteStatusListExternalID(t *testing.T) {
assert.Contains(t, output, "apply-complete")
}

func TestWriteStatusListDeploymentExternalOperationID(t *testing.T) {
// A deployment-filtered list is the deployment's view of each apply: the
// APPLY ID column carries the deployment's data-plane apply id — the handle
// its operator greps in the data plane's own storage and logs — and the
// EXTERNAL OP ID column carries the per-operation remote row id.
func TestWriteStatusListDeploymentRendersDataPlaneApplyID(t *testing.T) {
output := captureStdout(t, func() {
WriteStatusList(StatusListData{
ActiveCount: 1,
Expand All @@ -209,7 +213,7 @@ func TestWriteStatusListDeploymentExternalOperationID(t *testing.T) {
Applies: []ActiveApplyData{
{
ApplyID: "apply-running",
ExternalID: "parent-external",
ExternalID: "apply-remote-a",
ExternalOperationID: "remote-operation-a",
Database: "orders",
Environment: "staging",
Expand All @@ -225,10 +229,38 @@ func TestWriteStatusListDeploymentExternalOperationID(t *testing.T) {
assert.Contains(t, output, "EXTERNAL OP ID")
assert.Contains(t, output, "DEPLOYMENT")
assert.Contains(t, output, "remote-operation-a")
assert.NotContains(t, output, "parent-external")
assert.Contains(t, output, "apply-remote-a")
assert.NotContains(t, output, "apply-running",
"the deployment view renders the data-plane apply id in place of the control-plane one")
assert.Contains(t, output, "deploy-a")
}

// A deployment row without a recorded data-plane apply id — not yet
// dispatched, locally driven, or omitted after divergence — keeps the
// control-plane apply id, so every row carries a usable handle.
func TestWriteStatusListDeploymentFallsBackToControlPlaneApplyID(t *testing.T) {
output := captureStdout(t, func() {
WriteStatusList(StatusListData{
ActiveCount: 1,
Limit: 20,
MaxLimit: 1000,
Deployment: "deploy-a",
Applies: []ActiveApplyData{
{
ApplyID: "apply-pending",
Database: "orders",
Environment: "staging",
Deployment: "deploy-a",
State: state.Apply.Pending,
Caller: "cli",
},
},
})
})

assert.Contains(t, output, "apply-pending")
}

func TestWriteStatusListFailedOnly(t *testing.T) {
output := captureStdout(t, func() {
WriteStatusList(StatusListData{
Expand Down
Loading