Say in plain words what a container action actually did

When someone restarts, starts, stops or updates a Docker container from
Pulse, the result dialog showed raw fact dumps such as "Container
lifecycle: phase=verify; mutation started=true; ... after=running/
unhealthy" under "Outcome contradicted". About one in five of these
actions ends unconfirmed, almost always because the container really is
still unhealthy, and nothing on screen said so.

The execution and verification summaries are now plain sentences built
from the same typed facts, for example "Docker restarted the container."
and "The container restarted, but its health check is failing. Check its
logs." They describe what Docker reports using the state and running flag
together, say "Pulse could not get its health information" when the agent
receipt carries none, and keep missing, unchanged and older start times
apart. The raw facts stay on the evidence records and the legacy output,
and the action dialog shows that output in a collapsed "Agent details"
section, so nothing a power user could see before is lost.

The verification detail lines drop "trust domain" and "intended state"
wording. Verdicts, reason codes, evidence and API fields are unchanged.

Contract-Neutral: Rewords existing ActionResultV2 summaries for Docker container actions and the verification detail copy; no field, status, reason code, evidence or API shape changes
This commit is contained in:
rcourtman
2026-11-03 16:05:26 +00:00
parent 8c248d45a0
commit 922ee650ca
8 changed files with 537 additions and 22 deletions

View File

@@ -11,12 +11,14 @@ import (
)
func dockerContainerExecutionResult(resourceID, agentID string, req agentexec.DockerContainerLifecyclePayload, facts agentexec.DockerContainerLifecycleResultPayload, independent *dockerContainerPostconditionObservation, receivedAt time.Time) (*unified.ExecutionResult, error) {
// The raw fact summary stays on the evidence and legacy output; the
// execution and verification summaries are the plain sentences people read.
summary := dockerContainerFactSummary(facts)
execution := unified.ActionExecutionTruth{Status: unified.ActionExecutionNotRun, ReasonCode: actionPreflightReasonCode(facts.ReasonCode), Summary: summary}
execution := unified.ActionExecutionTruth{Status: unified.ActionExecutionNotRun, ReasonCode: actionPreflightReasonCode(facts.ReasonCode), Summary: dockerLifecycleExecutionSummary(req.Operation, facts)}
if facts.MutationCompleted {
execution = unified.ActionExecutionTruth{Status: unified.ActionExecutionSucceeded, Summary: summary}
execution = unified.ActionExecutionTruth{Status: unified.ActionExecutionSucceeded, Summary: dockerLifecycleExecutionSummary(req.Operation, facts)}
} else if facts.MutationStarted {
execution = unified.ActionExecutionTruth{Status: unified.ActionExecutionInconclusive, ReasonCode: "possible_partial_effect", Summary: summary}
execution = unified.ActionExecutionTruth{Status: unified.ActionExecutionInconclusive, ReasonCode: "possible_partial_effect", Summary: dockerLifecycleExecutionSummary(req.Operation, facts)}
}
verification := unified.ActionVerificationTruth{Status: unified.ActionVerificationInconclusive, EvidenceClass: unified.ActionEvidenceNone, ReasonCode: "agent_readback_unavailable", Summary: "The typed operation did not return a usable container readback."}
@@ -34,7 +36,7 @@ func dockerContainerExecutionResult(resourceID, agentID string, req agentexec.Do
return nil, fmt.Errorf("normalize docker lifecycle evidence: %w", err)
}
status, reason := dockerLifecycleVerification(req.Operation, facts.Before, facts.After)
verification = unified.ActionVerificationTruth{Status: status, EvidenceClass: unified.ActionEvidenceAgentAttested, ReasonCode: reason, Summary: summary, Evidence: []unified.ActionEvidence{evidence}}
verification = unified.ActionVerificationTruth{Status: status, EvidenceClass: unified.ActionEvidenceAgentAttested, ReasonCode: reason, Summary: dockerLifecycleOutcomeSummary(req.Operation, status, reason, facts.Before, facts.After), Evidence: []unified.ActionEvidence{evidence}}
}
}
if independent != nil && freshDockerLifecycleObservation(facts.Before.ObservedAt, independent.Snapshot.ObservedAt, independent.ReceivedAt) && strings.TrimSpace(independent.TrustDomain) != "" && strings.TrimSpace(independent.TrustDomain) != "agent:"+agentID && strings.EqualFold(independent.Snapshot.ContainerID, facts.ContainerID) {
@@ -57,11 +59,12 @@ func dockerContainerExecutionResult(resourceID, agentID string, req agentexec.Do
if err != nil {
return nil, fmt.Errorf("normalize independent docker observation: %w", err)
}
status, reason := dockerLifecycleVerification(req.Operation, facts.Before, agentexec.DockerContainerLifecycleSnapshot{
observed := agentexec.DockerContainerLifecycleSnapshot{
ContainerID: independent.Snapshot.ContainerID, State: independent.Snapshot.State, Running: independent.Snapshot.Running,
Health: independent.Snapshot.Health, StartedAt: independent.Snapshot.StartedAt,
})
verification = unified.ActionVerificationTruth{Status: status, EvidenceClass: unified.ActionEvidenceIndependent, ReasonCode: reason, Summary: independentSummary, Evidence: []unified.ActionEvidence{evidence}}
}
status, reason := dockerLifecycleVerification(req.Operation, facts.Before, observed)
verification = unified.ActionVerificationTruth{Status: status, EvidenceClass: unified.ActionEvidenceIndependent, ReasonCode: reason, Summary: dockerLifecycleOutcomeSummary(req.Operation, status, reason, facts.Before, observed), Evidence: []unified.ActionEvidence{evidence}}
}
canonical := unified.ActionResultV2{
@@ -79,11 +82,11 @@ func dockerContainerExecutionResult(resourceID, agentID string, req agentexec.Do
func dockerContainerUpdateExecutionResult(resourceID, agentID string, facts agentexec.DockerContainerUpdateResultPayload, independent *dockerContainerPostconditionObservation, receivedAt time.Time) (*unified.ExecutionResult, error) {
summary := dockerContainerUpdateFactSummary(facts)
execution := unified.ActionExecutionTruth{Status: unified.ActionExecutionNotRun, ReasonCode: actionPreflightReasonCode(facts.ReasonCode), Summary: summary}
execution := unified.ActionExecutionTruth{Status: unified.ActionExecutionNotRun, ReasonCode: actionPreflightReasonCode(facts.ReasonCode), Summary: dockerUpdateExecutionSummary(facts)}
if facts.MutationCompleted {
execution = unified.ActionExecutionTruth{Status: unified.ActionExecutionSucceeded, Summary: summary}
execution = unified.ActionExecutionTruth{Status: unified.ActionExecutionSucceeded, Summary: dockerUpdateExecutionSummary(facts)}
} else if facts.MutationStarted {
execution = unified.ActionExecutionTruth{Status: unified.ActionExecutionInconclusive, ReasonCode: "possible_partial_effect", Summary: summary}
execution = unified.ActionExecutionTruth{Status: unified.ActionExecutionInconclusive, ReasonCode: "possible_partial_effect", Summary: dockerUpdateExecutionSummary(facts)}
}
verification := unified.ActionVerificationTruth{Status: unified.ActionVerificationInconclusive, EvidenceClass: unified.ActionEvidenceNone, ReasonCode: "agent_readback_unavailable", Summary: "The typed operation did not return a usable replacement-container readback."}
@@ -119,7 +122,7 @@ func dockerContainerUpdateExecutionResult(resourceID, agentID string, facts agen
status = unified.ActionVerificationConfirmed
reason = ""
}
verification = unified.ActionVerificationTruth{Status: status, EvidenceClass: unified.ActionEvidenceAgentAttested, ReasonCode: reason, Summary: summary, Evidence: []unified.ActionEvidence{evidence}}
verification = unified.ActionVerificationTruth{Status: status, EvidenceClass: unified.ActionEvidenceAgentAttested, ReasonCode: reason, Summary: dockerUpdateOutcomeSummary(status, reason, facts.After.State, facts.After.Running, facts.After.Health), Evidence: []unified.ActionEvidence{evidence}}
}
}
if independent != nil && facts.NewContainerID != "" && freshDockerUpdateObservation(independent.Snapshot.ObservedAt, independent.ReceivedAt) && strings.TrimSpace(independent.TrustDomain) != "" && strings.TrimSpace(independent.TrustDomain) != "agent:"+agentID {
@@ -165,7 +168,11 @@ func dockerContainerUpdateExecutionResult(resourceID, agentID string, facts agen
status = unified.ActionVerificationConfirmed
reason = ""
}
verification = unified.ActionVerificationTruth{Status: status, EvidenceClass: unified.ActionEvidenceIndependent, ReasonCode: reason, Summary: independentSummary, Evidence: []unified.ActionEvidence{evidence}}
outcome := dockerUpdateOutcomeSummary(status, reason, independent.Snapshot.State, independent.Snapshot.Running, independent.Snapshot.Health)
if status == unified.ActionVerificationContradicted && !dockerUpdateFactsMatch(facts, independent.Snapshot.ContainerID) {
outcome = "Pulse found a different container than the one the update created."
}
verification = unified.ActionVerificationTruth{Status: status, EvidenceClass: unified.ActionEvidenceIndependent, ReasonCode: reason, Summary: outcome, Evidence: []unified.ActionEvidence{evidence}}
}
canonical := unified.ActionResultV2{
@@ -324,3 +331,184 @@ func dockerLifecycleVerification(operation string, before, after agentexec.Docke
}
return unified.ActionVerificationContradicted, "postcondition_contradicted"
}
// dockerLifecycleVerbs returns the base and past-tense verb for a lifecycle
// operation, so summaries read "restart" and "restarted".
func dockerLifecycleVerbs(operation string) (string, string) {
switch operation {
case agentexec.DockerContainerOperationStart:
return "start", "started"
case agentexec.DockerContainerOperationStop:
return "stop", "stopped"
case agentexec.DockerContainerOperationRestart:
return "restart", "restarted"
default:
return "change", "changed"
}
}
func dockerLifecycleExecutionSummary(operation string, facts agentexec.DockerContainerLifecycleResultPayload) string {
base, past := dockerLifecycleVerbs(operation)
var summary string
switch {
case facts.MutationCompleted:
return "Docker " + past + " the container."
case facts.MutationStarted:
summary = "Docker was asked to " + base + " the container, but did not confirm it, so the change may or may not have happened."
default:
summary = "The agent did not " + base + " the container."
}
return summary + dockerAgentErrorSentence(facts.Error)
}
// dockerAgentErrorSentence appends the agent's own error text, if any, as a
// trailing sentence.
func dockerAgentErrorSentence(errText string) string {
errText = strings.TrimRight(strings.TrimSpace(errText), " .:")
if errText == "" {
return ""
}
return " Agent said: " + errText + "."
}
// dockerContainerStateWords describes what Docker reports for a container. It
// reads the state and the running flag together so the two cannot disagree.
func dockerContainerStateWords(state string, running bool) string {
state = strings.ToLower(strings.TrimSpace(state))
switch state {
case "running":
if running {
return "running"
}
return "running but not marked as running"
case "exited":
return "stopped"
case "restarting":
return "restarting, which usually means it keeps crashing"
case "created":
return "created but not started"
case "paused", "dead":
return state
case "removing":
return "being removed"
case "":
return "in an unknown state"
default:
return "in the " + state + " state"
}
}
func dockerContainerIsRunning(state string, running bool) bool {
return running && strings.EqualFold(strings.TrimSpace(state), "running")
}
const dockerHealthStartingAdvice = " Its health check was still starting when Pulse checked. Wait a moment, then refresh its status."
// dockerLifecycleOutcomeSummary says in plain words what Pulse saw after a
// container start, stop or restart. The typed facts stay on the evidence.
func dockerLifecycleOutcomeSummary(operation string, status unified.ActionVerificationStatus, reason string, before, after agentexec.DockerContainerLifecycleSnapshot) string {
running := dockerContainerIsRunning(after.State, after.Running)
healthy := strings.EqualFold(strings.TrimSpace(after.Health), agentexec.DockerContainerHealthHealthy)
unhealthy := strings.EqualFold(strings.TrimSpace(after.Health), agentexec.DockerContainerHealthUnhealthy)
switch status {
case unified.ActionVerificationConfirmed:
switch operation {
case agentexec.DockerContainerOperationStop:
return "The container is stopped."
case agentexec.DockerContainerOperationRestart:
if healthy {
return "The container restarted and is running and healthy."
}
return "The container restarted and is running."
default:
if healthy {
return "The container is running and healthy."
}
return "The container is running."
}
case unified.ActionVerificationInconclusive:
switch reason {
case "container_health_starting":
return "The container is running." + dockerHealthStartingAdvice
case "container_health_unknown":
return "Docker reports the container as " + dockerContainerStateWords(after.State, after.Running) + ". Pulse could not get its health information, so it could not confirm the result."
}
return "Pulse could not confirm the result."
case unified.ActionVerificationContradicted:
if operation == agentexec.DockerContainerOperationStop {
if running {
return "The container is still running."
}
return "Pulse expected a stopped container. Docker reports it as " + dockerContainerStateWords(after.State, after.Running) + "."
}
if !running {
return "The container is not running. Docker reports it as " + dockerContainerStateWords(after.State, after.Running) + "."
}
if operation == agentexec.DockerContainerOperationRestart && (after.StartedAt.IsZero() || !after.StartedAt.After(before.StartedAt)) {
switch {
case after.StartedAt.IsZero():
return "The container is running, but Pulse did not receive its start time, so it could not confirm a restart."
case after.StartedAt.Equal(before.StartedAt):
return "The container is running, but its start time did not change, so it did not restart."
default:
return "The container is running, but its start time is not newer than before, so Pulse could not confirm a restart."
}
}
if unhealthy {
if operation == agentexec.DockerContainerOperationRestart {
return "The container restarted, but its health check is failing. Check its logs."
}
return "The container started, but its health check is failing. Check its logs."
}
return "The container is not in the state this action should have left it in."
}
return "Pulse could not confirm the result."
}
func dockerUpdateExecutionSummary(facts agentexec.DockerContainerUpdateResultPayload) string {
var summary string
switch {
case facts.MutationCompleted:
return "Docker replaced the container with one using the new image."
case facts.MutationStarted:
summary = "The update started, but Pulse could not confirm it completed."
default:
summary = "The update stopped before changing the container."
}
return summary + dockerAgentErrorSentence(facts.Error)
}
// dockerUpdateOutcomeSummary says in plain words what Pulse saw of the
// replacement container after an update.
func dockerUpdateOutcomeSummary(status unified.ActionVerificationStatus, reason, state string, running bool, health string) string {
isRunning := dockerContainerIsRunning(state, running)
switch status {
case unified.ActionVerificationConfirmed:
if !isRunning {
return "The updated container is in place. Docker reports it as " + dockerContainerStateWords(state, running) + "."
}
if strings.EqualFold(strings.TrimSpace(health), agentexec.DockerContainerHealthHealthy) {
return "The updated container is running and healthy."
}
return "The updated container is running."
case unified.ActionVerificationInconclusive:
switch reason {
case "container_health_starting":
return "The updated container is running." + dockerHealthStartingAdvice
case "container_health_unknown":
return "Docker reports the updated container as " + dockerContainerStateWords(state, running) + ". Pulse could not get its health information, so it could not confirm the update."
case "agent_readback_unavailable":
return "The agent did not report the updated container's state, so Pulse could not confirm the update."
}
return "Pulse could not confirm the update."
case unified.ActionVerificationContradicted:
if !isRunning {
return "Docker reports the updated container as " + dockerContainerStateWords(state, running) + "."
}
if strings.EqualFold(strings.TrimSpace(health), agentexec.DockerContainerHealthUnhealthy) {
return "The updated container is running, but its health check is failing. Check its logs."
}
return "The updated container is not in the expected state."
}
return "Pulse could not confirm the update."
}

View File

@@ -1,6 +1,8 @@
package api
import (
"encoding/json"
"strings"
"testing"
"time"
@@ -303,3 +305,209 @@ func TestDockerContainerUpdateAgentReadbackMustSupportRunningClaim(t *testing.T)
})
}
}
// The execution and verification summaries are the sentences people read in
// the action result, so they must say what Pulse saw in plain words while the
// typed facts stay on the evidence.
func TestDockerContainerExecutionResultSummariesSayWhatPulseSaw(t *testing.T) {
now := time.Now().UTC()
beforeStart := now.Add(-time.Minute)
for _, tc := range []struct {
name, operation, state, health string
running bool
startedAt time.Time
status unified.ActionVerificationStatus
want string
}{
{name: "restart recovered", operation: agentexec.DockerContainerOperationRestart, state: "running", running: true, health: agentexec.DockerContainerHealthHealthy, startedAt: now, status: unified.ActionVerificationConfirmed, want: "The container restarted and is running and healthy."},
{name: "restart without health check", operation: agentexec.DockerContainerOperationRestart, state: "running", running: true, health: agentexec.DockerContainerHealthNone, startedAt: now, status: unified.ActionVerificationConfirmed, want: "The container restarted and is running."},
{name: "restart health failing", operation: agentexec.DockerContainerOperationRestart, state: "running", running: true, health: agentexec.DockerContainerHealthUnhealthy, startedAt: now, status: unified.ActionVerificationContradicted, want: "The container restarted, but its health check is failing. Check its logs."},
{name: "restart crash loop", operation: agentexec.DockerContainerOperationRestart, state: "restarting", running: true, health: agentexec.DockerContainerHealthNone, startedAt: now, status: unified.ActionVerificationContradicted, want: "The container is not running. Docker reports it as restarting, which usually means it keeps crashing."},
{name: "restart same start time", operation: agentexec.DockerContainerOperationRestart, state: "running", running: true, health: agentexec.DockerContainerHealthNone, startedAt: beforeStart, status: unified.ActionVerificationContradicted, want: "The container is running, but its start time did not change, so it did not restart."},
{name: "restart earlier start time", operation: agentexec.DockerContainerOperationRestart, state: "running", running: true, health: agentexec.DockerContainerHealthNone, startedAt: beforeStart.Add(-time.Hour), status: unified.ActionVerificationContradicted, want: "The container is running, but its start time is not newer than before, so Pulse could not confirm a restart."},
{name: "restart missing start time", operation: agentexec.DockerContainerOperationRestart, state: "running", running: true, health: agentexec.DockerContainerHealthNone, status: unified.ActionVerificationContradicted, want: "The container is running, but Pulse did not receive its start time, so it could not confirm a restart."},
{name: "restart health pending", operation: agentexec.DockerContainerOperationRestart, state: "running", running: true, health: agentexec.DockerContainerHealthStarting, startedAt: now, status: unified.ActionVerificationInconclusive, want: "The container is running. Its health check was still starting when Pulse checked. Wait a moment, then refresh its status."},
{name: "running state without running flag", operation: agentexec.DockerContainerOperationStart, state: "running", running: false, health: agentexec.DockerContainerHealthNone, startedAt: now, status: unified.ActionVerificationContradicted, want: "The container is not running. Docker reports it as running but not marked as running."},
{name: "start exited again", operation: agentexec.DockerContainerOperationStart, state: "exited", running: false, health: agentexec.DockerContainerHealthNone, startedAt: now, status: unified.ActionVerificationContradicted, want: "The container is not running. Docker reports it as stopped."},
{name: "start health failing", operation: agentexec.DockerContainerOperationStart, state: "running", running: true, health: agentexec.DockerContainerHealthUnhealthy, startedAt: now, status: unified.ActionVerificationContradicted, want: "The container started, but its health check is failing. Check its logs."},
{name: "stop still running", operation: agentexec.DockerContainerOperationStop, state: "running", running: true, health: agentexec.DockerContainerHealthNone, startedAt: beforeStart, status: unified.ActionVerificationContradicted, want: "The container is still running."},
{name: "stop paused", operation: agentexec.DockerContainerOperationStop, state: "paused", running: false, health: agentexec.DockerContainerHealthNone, startedAt: beforeStart, status: unified.ActionVerificationContradicted, want: "Pulse expected a stopped container. Docker reports it as paused."},
{name: "stop paused but flagged running", operation: agentexec.DockerContainerOperationStop, state: "paused", running: true, health: agentexec.DockerContainerHealthNone, startedAt: beforeStart, status: unified.ActionVerificationContradicted, want: "Pulse expected a stopped container. Docker reports it as paused."},
{name: "stop confirmed", operation: agentexec.DockerContainerOperationStop, state: "exited", running: false, health: agentexec.DockerContainerHealthNone, startedAt: beforeStart, status: unified.ActionVerificationConfirmed, want: "The container is stopped."},
} {
t.Run(tc.name, func(t *testing.T) {
facts := dockerResultFacts(now, true, true, true, true)
facts.ContainerID = dockerLifecycleTestID
req := agentexec.DockerContainerLifecyclePayload{ActionID: "action-1", Operation: tc.operation}
observation := &dockerContainerPostconditionObservation{
ObserverID: "docker-daemon:agent-1", TrustDomain: "docker-daemon:agent-1", Method: "typed_docker_daemon_observation",
Snapshot: agentexec.DockerContainerObservationSnapshot{ContainerID: dockerLifecycleTestID, State: tc.state, Running: tc.running, Health: tc.health, StartedAt: tc.startedAt, ObservedAt: now},
ReceivedAt: now,
}
result, err := dockerContainerExecutionResult("app-container:fixture", "agent-1", req, facts, observation, now)
if err != nil {
t.Fatal(err)
}
truth := result.ActionResultV2
if truth.Verification.Status != tc.status || truth.Verification.Summary != tc.want {
t.Fatalf("verification = %q %q, want %q %q", truth.Verification.Status, truth.Verification.Summary, tc.status, tc.want)
}
_, past := dockerLifecycleVerbs(tc.operation)
if want := "Docker " + past + " the container."; truth.Execution.Summary != want {
t.Fatalf("execution summary = %q, want %q", truth.Execution.Summary, want)
}
if len(truth.Verification.Evidence) != 1 || !strings.HasPrefix(truth.Verification.Evidence[0].Summary, "Direct daemon observation:") {
t.Fatalf("typed observation facts left the evidence: %#v", truth.Verification.Evidence)
}
if !strings.HasPrefix(result.Output, "Container lifecycle: phase=") {
t.Fatalf("legacy output lost the typed facts: %q", result.Output)
}
})
}
}
// The agent receipt does not carry health on the wire, so without a daemon
// observation the server cannot confirm a start or restart. The summary must
// say Pulse lacked the health information rather than blame Docker.
func TestDockerContainerAgentOnlySummaryAfterWireRoundTrip(t *testing.T) {
now := time.Now().UTC()
for _, tc := range []struct {
name, state string
running bool
want string
}{
{name: "running", state: "running", running: true, want: "Docker reports the container as running. Pulse could not get its health information, so it could not confirm the result."},
{name: "exited", state: "exited", running: false, want: "Docker reports the container as stopped. Pulse could not get its health information, so it could not confirm the result."},
{name: "restarting", state: "restarting", running: true, want: "Docker reports the container as restarting, which usually means it keeps crashing. Pulse could not get its health information, so it could not confirm the result."},
} {
t.Run(tc.name, func(t *testing.T) {
facts := dockerResultFacts(now, true, true, true, true)
facts.After.State, facts.After.Running = tc.state, tc.running
encoded, err := json.Marshal(facts)
if err != nil {
t.Fatal(err)
}
var wire agentexec.DockerContainerLifecycleResultPayload
if err := json.Unmarshal(encoded, &wire); err != nil {
t.Fatal(err)
}
if wire.After.Health != "" {
t.Fatalf("fixture expects health to stay off the wire, got %q", wire.After.Health)
}
result, err := dockerContainerExecutionResult("app-container:fixture", "agent-1", agentexec.DockerContainerLifecyclePayload{Operation: agentexec.DockerContainerOperationRestart}, wire, nil, now)
if err != nil {
t.Fatal(err)
}
verification := result.ActionResultV2.Verification
if verification.Status != unified.ActionVerificationInconclusive || verification.ReasonCode != "container_health_unknown" || verification.Summary != tc.want {
t.Fatalf("verification = %q %q %q, want %q", verification.Status, verification.ReasonCode, verification.Summary, tc.want)
}
if len(verification.Evidence) != 1 || !strings.HasPrefix(verification.Evidence[0].Summary, "Container lifecycle: phase=") {
t.Fatalf("agent readback facts left the evidence: %#v", verification.Evidence)
}
})
}
}
func TestDockerContainerExecutionSummariesCarryUncertaintyAndAgentError(t *testing.T) {
now := time.Now().UTC()
for _, tc := range []struct {
name string
started, completed bool
errText string
want string
}{
{name: "refused", errText: "container preflight state no longer matches the request", want: "The agent did not restart the container. Agent said: container preflight state no longer matches the request."},
{name: "partial", started: true, errText: "context deadline exceeded", want: "Docker was asked to restart the container, but did not confirm it, so the change may or may not have happened. Agent said: context deadline exceeded."},
} {
t.Run(tc.name, func(t *testing.T) {
facts := dockerResultFacts(now, tc.started, tc.completed, false, true)
facts.ReasonCode = agentexec.ActionRefusalTargetStateChanged
facts.Error = tc.errText
result, err := dockerContainerExecutionResult("app-container:fixture", "agent-1", agentexec.DockerContainerLifecyclePayload{Operation: agentexec.DockerContainerOperationRestart}, facts, nil, now)
if err != nil {
t.Fatal(err)
}
if got := result.ActionResultV2.Execution.Summary; got != tc.want {
t.Fatalf("execution summary = %q, want %q", got, tc.want)
}
if !strings.Contains(result.Output, "error="+tc.errText) {
t.Fatalf("legacy output lost the agent error: %q", result.Output)
}
})
}
}
func TestDockerContainerUpdateSummariesSayWhatPulseSaw(t *testing.T) {
now := time.Now().UTC()
for _, tc := range []struct {
name, agentState, state, health string
agentRunning, running bool
observedID string
status unified.ActionVerificationStatus
want string
}{
{name: "running healthy", agentState: "running", agentRunning: true, state: "running", running: true, health: agentexec.DockerContainerHealthHealthy, observedID: dockerLifecycleTestID, status: unified.ActionVerificationConfirmed, want: "The updated container is running and healthy."},
{name: "kept stopped", agentState: "exited", state: "exited", health: agentexec.DockerContainerHealthNone, observedID: dockerLifecycleTestID, status: unified.ActionVerificationConfirmed, want: "The updated container is in place. Docker reports it as stopped."},
{name: "kept created", agentState: "created", state: "created", health: agentexec.DockerContainerHealthNone, observedID: dockerLifecycleTestID, status: unified.ActionVerificationConfirmed, want: "The updated container is in place. Docker reports it as created but not started."},
{name: "health failing", agentState: "running", agentRunning: true, state: "running", running: true, health: agentexec.DockerContainerHealthUnhealthy, observedID: dockerLifecycleTestID, status: unified.ActionVerificationContradicted, want: "The updated container is running, but its health check is failing. Check its logs."},
{name: "exited after readback", agentState: "running", agentRunning: true, state: "exited", health: agentexec.DockerContainerHealthNone, observedID: dockerLifecycleTestID, status: unified.ActionVerificationContradicted, want: "Docker reports the updated container as stopped."},
{name: "health pending", agentState: "running", agentRunning: true, state: "running", running: true, health: agentexec.DockerContainerHealthStarting, observedID: dockerLifecycleTestID, status: unified.ActionVerificationInconclusive, want: "The updated container is running. Its health check was still starting when Pulse checked. Wait a moment, then refresh its status."},
{name: "different container", agentState: "running", agentRunning: true, state: "running", running: true, health: agentexec.DockerContainerHealthHealthy, observedID: strings.Repeat("f", 64), status: unified.ActionVerificationContradicted, want: "Pulse found a different container than the one the update created."},
{name: "readback unavailable", state: "running", running: true, health: agentexec.DockerContainerHealthHealthy, observedID: dockerLifecycleTestID, status: unified.ActionVerificationInconclusive, want: "The agent did not report the updated container's state, so Pulse could not confirm the update."},
} {
t.Run(tc.name, func(t *testing.T) {
facts := agentexec.DockerContainerUpdateResultPayload{
Operation: agentexec.DockerContainerOperationUpdate, ActionID: "action-update", ExecutionPhase: agentexec.DockerContainerPhaseComplete,
MutationStarted: true, MutationCompleted: true, ReadbackRan: tc.agentState != "", NewContainerID: dockerLifecycleTestID,
After: agentexec.DockerContainerLifecycleSnapshot{ContainerID: dockerLifecycleTestID, State: tc.agentState, Running: tc.agentRunning, ObservedAt: now},
}
observation := &dockerContainerPostconditionObservation{
ObserverID: "docker-daemon:agent-1", TrustDomain: "docker-daemon:agent-1", Method: "typed_docker_daemon_observation",
Snapshot: agentexec.DockerContainerObservationSnapshot{ContainerID: tc.observedID, State: tc.state, Running: tc.running, Health: tc.health, ObservedAt: now},
ReceivedAt: now,
}
result, err := dockerContainerUpdateExecutionResult("app-container:fixture", "agent-1", facts, observation, now)
if err != nil {
t.Fatal(err)
}
truth := result.ActionResultV2
if truth.Verification.Status != tc.status || truth.Verification.Summary != tc.want {
t.Fatalf("verification = %q %q, want %q %q", truth.Verification.Status, truth.Verification.Summary, tc.status, tc.want)
}
if truth.Execution.Summary != "Docker replaced the container with one using the new image." {
t.Fatalf("execution summary = %q", truth.Execution.Summary)
}
if !strings.HasPrefix(result.Output, "Container update: phase=") {
t.Fatalf("legacy output lost the typed facts: %q", result.Output)
}
})
}
}
func TestDockerContainerUpdateExecutionSummariesCarryUncertaintyAndAgentError(t *testing.T) {
now := time.Now().UTC()
for _, tc := range []struct {
name string
started bool
errText string
want string
}{
{name: "not started", errText: "Failed to pull image: manifest unknown: ", want: "The update stopped before changing the container. Agent said: Failed to pull image: manifest unknown."},
{name: "partial", started: true, errText: "context deadline exceeded", want: "The update started, but Pulse could not confirm it completed. Agent said: context deadline exceeded."},
} {
t.Run(tc.name, func(t *testing.T) {
facts := agentexec.DockerContainerUpdateResultPayload{
Operation: agentexec.DockerContainerOperationUpdate, ActionID: "action-update", ExecutionPhase: agentexec.DockerContainerPhasePreflight,
MutationStarted: tc.started, Error: tc.errText,
}
result, err := dockerContainerUpdateExecutionResult("app-container:fixture", "agent-1", facts, nil, now)
if err != nil {
t.Fatal(err)
}
if got := result.ActionResultV2.Execution.Summary; got != tc.want {
t.Fatalf("execution summary = %q, want %q", got, tc.want)
}
})
}
}