mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
fix(cli): show ready sync start dependencies (#25546)
## Problem Follow-on to: - https://github.com/coder/coder/pull/25089 `coder exp sync start` still printed a generic success message when the unit was ready on the first status check. That hid whether the unit had no dependencies or had dependencies that were already satisfied before `sync start` ran. Before: ```text Success ``` ## Solution Print explicit startup output for both ready-at-first-check cases. After, dependencies already satisfied: ```text Unit "test-unit" started immediately, dependencies already satisfied: [dep-unit, dep-unit-2] ``` After, no dependencies: ```text Unit "test-unit" started with no dependencies ``` The existing waiting path is unchanged and still reports the dependencies while waiting and after waiting finishes. Co-authored-by: Sas Swart <sas.swart.cdk@gmail.com>
This commit is contained in:
+19
-12
@@ -57,15 +57,19 @@ func (*RootCmd) syncStart(socketPath *string) *serpent.Command {
|
||||
}
|
||||
ready := statusResp.IsReady
|
||||
|
||||
var waitedFor []string
|
||||
if !ready {
|
||||
for _, dep := range statusResp.Dependencies {
|
||||
if !dep.IsSatisfied {
|
||||
waitedFor = append(waitedFor, string(dep.DependsOn))
|
||||
}
|
||||
var allDependencies []string
|
||||
var unsatisfiedDependencies []string
|
||||
for _, dep := range statusResp.Dependencies {
|
||||
allDependencies = append(allDependencies, string(dep.DependsOn))
|
||||
if !dep.IsSatisfied {
|
||||
unsatisfiedDependencies = append(unsatisfiedDependencies, string(dep.DependsOn))
|
||||
}
|
||||
slices.Sort(waitedFor)
|
||||
waitedForList := strings.Join(waitedFor, ", ")
|
||||
}
|
||||
slices.Sort(allDependencies)
|
||||
slices.Sort(unsatisfiedDependencies)
|
||||
|
||||
if !ready {
|
||||
waitedForList := strings.Join(unsatisfiedDependencies, ", ")
|
||||
|
||||
cliui.Infof(i.Stdout, "Unit %q is waiting for dependencies to be satisfied: [%s]", unitName, waitedForList)
|
||||
|
||||
@@ -96,10 +100,13 @@ func (*RootCmd) syncStart(socketPath *string) *serpent.Command {
|
||||
return xerrors.Errorf("start unit failed: %w", err)
|
||||
}
|
||||
|
||||
if len(waitedFor) == 0 {
|
||||
cliui.Info(i.Stdout, "Success")
|
||||
} else {
|
||||
cliui.Info(i.Stdout, fmt.Sprintf("Unit %q finished waiting for dependencies: [%s]", unitName, strings.Join(waitedFor, ", ")))
|
||||
switch {
|
||||
case len(allDependencies) == 0:
|
||||
cliui.Info(i.Stdout, fmt.Sprintf("Unit %q started with no dependencies", unitName))
|
||||
case len(unsatisfiedDependencies) == 0:
|
||||
cliui.Info(i.Stdout, fmt.Sprintf("Unit %q started immediately, dependencies already satisfied: [%s]", unitName, strings.Join(allDependencies, ", ")))
|
||||
default:
|
||||
cliui.Info(i.Stdout, fmt.Sprintf("Unit %q finished waiting for dependencies: [%s]", unitName, strings.Join(unsatisfiedDependencies, ", ")))
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -158,6 +158,42 @@ func TestSyncCommands_Golden(t *testing.T) {
|
||||
clitest.TestGoldenFile(t, "TestSyncCommands_Golden/start_with_dependencies", outBuf.Bytes(), nil)
|
||||
})
|
||||
|
||||
t.Run("start_with_satisfied_dependencies", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
path, cleanup := setupSocketServer(t)
|
||||
defer cleanup()
|
||||
|
||||
ctx := testutil.Context(t, testutil.WaitShort)
|
||||
|
||||
// Set up dependencies: test-unit depends on dep-unit and dep-unit-2.
|
||||
client, err := agentsocket.NewClient(ctx, agentsocket.WithPath(path))
|
||||
require.NoError(t, err)
|
||||
|
||||
err = client.SyncWant(ctx, "test-unit", "dep-unit")
|
||||
require.NoError(t, err)
|
||||
err = client.SyncWant(ctx, "test-unit", "dep-unit-2")
|
||||
require.NoError(t, err)
|
||||
err = client.SyncStart(ctx, "dep-unit")
|
||||
require.NoError(t, err)
|
||||
err = client.SyncComplete(ctx, "dep-unit")
|
||||
require.NoError(t, err)
|
||||
err = client.SyncStart(ctx, "dep-unit-2")
|
||||
require.NoError(t, err)
|
||||
err = client.SyncComplete(ctx, "dep-unit-2")
|
||||
require.NoError(t, err)
|
||||
client.Close()
|
||||
|
||||
var outBuf bytes.Buffer
|
||||
inv, _ := clitest.New(t, "exp", "sync", "start", "test-unit", "--socket-path", path)
|
||||
inv.Stdout = &outBuf
|
||||
inv.Stderr = &outBuf
|
||||
|
||||
err = inv.WithContext(ctx).Run()
|
||||
require.NoError(t, err)
|
||||
|
||||
clitest.TestGoldenFile(t, "TestSyncCommands_Golden/start_with_satisfied_dependencies", outBuf.Bytes(), nil)
|
||||
})
|
||||
|
||||
t.Run("want", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
path, cleanup := setupSocketServer(t)
|
||||
|
||||
@@ -1 +1 @@
|
||||
Success
|
||||
Unit "test-unit" started with no dependencies
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Unit "test-unit" started immediately, dependencies already satisfied: [dep-unit, dep-unit-2]
|
||||
Reference in New Issue
Block a user