Skip to content

Commit ff2b822

Browse files
committed
Merge branch 'main' into gitauth
2 parents 320c10d + acf000a commit ff2b822

File tree

158 files changed

+3613
-2889
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+3613
-2889
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
"stretchr",
114114
"STTY",
115115
"stuntest",
116+
"tanstack",
116117
"tailbroker",
117118
"tailcfg",
118119
"tailexchange",

Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ gen: \
424424
provisionerd/proto/provisionerd.pb.go \
425425
site/src/api/typesGenerated.ts \
426426
docs/admin/prometheus.md \
427-
docs/cli/coder.md \
427+
docs/cli.md \
428428
docs/admin/audit-logs.md \
429429
coderd/apidoc/swagger.json \
430430
.prettierignore.include \
@@ -444,7 +444,7 @@ gen/mark-fresh:
444444
provisionerd/proto/provisionerd.pb.go \
445445
site/src/api/typesGenerated.ts \
446446
docs/admin/prometheus.md \
447-
docs/cli/coder.md \
447+
docs/cli.md \
448448
docs/admin/audit-logs.md \
449449
coderd/apidoc/swagger.json \
450450
.prettierignore.include \
@@ -500,10 +500,11 @@ docs/admin/prometheus.md: scripts/metricsdocgen/main.go scripts/metricsdocgen/me
500500
cd site
501501
yarn run format:write:only ../docs/admin/prometheus.md
502502

503-
docs/cli/coder.md: scripts/clidocgen/main.go $(GO_SRC_FILES) docs/manifest.json
504-
BASE_PATH="." go run scripts/clidocgen/main.go
503+
docs/cli.md: scripts/clidocgen/main.go $(GO_SRC_FILES) docs/manifest.json
504+
rm -rf ./docs/cli/*.md
505+
BASE_PATH="." go run ./scripts/clidocgen
505506
cd site
506-
yarn run format:write:only ../docs/cli/*.md ../docs/manifest.json
507+
yarn run format:write:only ../docs/cli.md ../docs/cli/*.md ../docs/manifest.json
507508

508509
docs/admin/audit-logs.md: scripts/auditdocgen/main.go enterprise/audit/table.go
509510
go run scripts/auditdocgen/main.go

agent/agent.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,9 @@ func (a *agent) runCoordinator(ctx context.Context, network *tailnet.Conn) error
601601
}
602602
defer coordinator.Close()
603603
a.logger.Info(ctx, "connected to coordination server")
604-
sendNodes, errChan := tailnet.ServeCoordinator(coordinator, network.UpdateNodes)
604+
sendNodes, errChan := tailnet.ServeCoordinator(coordinator, func(nodes []*tailnet.Node) error {
605+
return network.UpdateNodes(nodes, false)
606+
})
605607
network.SetNodeCallback(sendNodes)
606608
select {
607609
case <-ctx.Done():

agent/agent_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,12 +1179,21 @@ func setupAgent(t *testing.T, metadata agentsdk.Metadata, ptyTimeout time.Durati
11791179
coordinator.ServeClient(serverConn, uuid.New(), agentID)
11801180
}()
11811181
sendNode, _ := tailnet.ServeCoordinator(clientConn, func(node []*tailnet.Node) error {
1182-
return conn.UpdateNodes(node)
1182+
return conn.UpdateNodes(node, false)
11831183
})
11841184
conn.SetNodeCallback(sendNode)
1185-
return &codersdk.WorkspaceAgentConn{
1185+
agentConn := &codersdk.WorkspaceAgentConn{
11861186
Conn: conn,
1187-
}, c, statsCh, fs
1187+
}
1188+
t.Cleanup(func() {
1189+
_ = agentConn.Close()
1190+
})
1191+
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
1192+
defer cancel()
1193+
if !agentConn.AwaitReachable(ctx) {
1194+
t.Fatal("agent not reachable")
1195+
}
1196+
return agentConn, c, statsCh, fs
11881197
}
11891198

11901199
var dialTestPayload = []byte("dean-was-here123")

cli/root.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919

2020
"golang.org/x/xerrors"
2121

22+
"cdr.dev/slog"
23+
2224
"github.com/charmbracelet/lipgloss"
2325
"github.com/kirsle/configdir"
2426
"github.com/mattn/go-isatty"
@@ -179,6 +181,21 @@ func Root(subcommands []*cobra.Command) *cobra.Command {
179181
return cmd
180182
}
181183

184+
type contextKey int
185+
186+
const (
187+
contextKeyLogger contextKey = iota
188+
)
189+
190+
func ContextWithLogger(ctx context.Context, l slog.Logger) context.Context {
191+
return context.WithValue(ctx, contextKeyLogger, l)
192+
}
193+
194+
func LoggerFromContext(ctx context.Context) (slog.Logger, bool) {
195+
l, ok := ctx.Value(contextKeyLogger).(slog.Logger)
196+
return l, ok
197+
}
198+
182199
// fixUnknownSubcommandError modifies the provided commands so that the
183200
// ones with subcommands output the correct error message when an
184201
// unknown subcommand is invoked.

cli/speedtest.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ func speedtest() *cobra.Command {
5151
if err != nil && !xerrors.Is(err, cliui.AgentStartError) {
5252
return xerrors.Errorf("await agent: %w", err)
5353
}
54-
logger := slog.Make(sloghuman.Sink(cmd.ErrOrStderr()))
54+
logger, ok := LoggerFromContext(ctx)
55+
if !ok {
56+
logger = slog.Make(sloghuman.Sink(cmd.ErrOrStderr()))
57+
}
5558
if cliflag.IsSetBool(cmd, varVerbose) {
5659
logger = logger.Leveled(slog.LevelDebug)
5760
}

cli/speedtest_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import (
77
"github.com/stretchr/testify/assert"
88
"github.com/stretchr/testify/require"
99

10+
"cdr.dev/slog"
1011
"cdr.dev/slog/sloggers/slogtest"
1112
"github.com/coder/coder/agent"
13+
"github.com/coder/coder/cli"
1214
"github.com/coder/coder/cli/clitest"
1315
"github.com/coder/coder/coderd/coderdtest"
1416
"github.com/coder/coder/codersdk"
@@ -19,6 +21,7 @@ import (
1921

2022
func TestSpeedtest(t *testing.T) {
2123
t.Parallel()
24+
t.Skip("Flaky test - see https://github.com/coder/coder/issues/6321")
2225
if testing.Short() {
2326
t.Skip("This test takes a minimum of 5ms per a hardcoded value in Tailscale!")
2427
}
@@ -27,7 +30,7 @@ func TestSpeedtest(t *testing.T) {
2730
agentClient.SetSessionToken(agentToken)
2831
agentCloser := agent.New(agent.Options{
2932
Client: agentClient,
30-
Logger: slogtest.Make(t, nil).Named("agent"),
33+
Logger: slogtest.Make(t, nil).Named("agent").Leveled(slog.LevelDebug),
3134
})
3235
defer agentCloser.Close()
3336
coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
@@ -49,10 +52,12 @@ func TestSpeedtest(t *testing.T) {
4952
clitest.SetupConfig(t, client, root)
5053
pty := ptytest.New(t)
5154
cmd.SetOut(pty.Output())
55+
cmd.SetErr(pty.Output())
5256

5357
ctx, cancel = context.WithTimeout(context.Background(), testutil.WaitLong)
5458
defer cancel()
5559

60+
ctx = cli.ContextWithLogger(ctx, slogtest.Make(t, nil).Named("speedtest").Leveled(slog.LevelDebug))
5661
cmdDone := tGo(t, func() {
5762
err := cmd.ExecuteContext(ctx)
5863
assert.NoError(t, err)

cli/ssh_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"golang.org/x/crypto/ssh"
2525
gosshagent "golang.org/x/crypto/ssh/agent"
2626

27+
"cdr.dev/slog"
2728
"cdr.dev/slog/sloggers/slogtest"
2829

2930
"github.com/coder/coder/agent"
@@ -47,6 +48,7 @@ func setupWorkspaceForAgent(t *testing.T, mutate func([]*proto.Agent) []*proto.A
4748
}
4849
}
4950
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
51+
client.Logger = slogtest.Make(t, nil).Named("client").Leveled(slog.LevelDebug)
5052
user := coderdtest.CreateFirstUser(t, client)
5153
agentToken := uuid.NewString()
5254
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{

cli/state.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ func state() *cobra.Command {
2727
func statePull() *cobra.Command {
2828
var buildNumber int
2929
cmd := &cobra.Command{
30-
Use: "pull <workspace> [file]",
31-
Args: cobra.MinimumNArgs(1),
30+
Use: "pull <workspace> [file]",
31+
Short: "Pull a Terraform state file from a workspace.",
32+
Args: cobra.MinimumNArgs(1),
3233
RunE: func(cmd *cobra.Command, args []string) error {
3334
client, err := CreateClient(cmd)
3435
if err != nil {
@@ -68,8 +69,9 @@ func statePull() *cobra.Command {
6869
func statePush() *cobra.Command {
6970
var buildNumber int
7071
cmd := &cobra.Command{
71-
Use: "push <workspace> <file>",
72-
Args: cobra.ExactArgs(2),
72+
Use: "push <workspace> <file>",
73+
Args: cobra.ExactArgs(2),
74+
Short: "Push a Terraform state file to a workspace.",
7375
RunE: func(cmd *cobra.Command, args []string) error {
7476
client, err := CreateClient(cmd)
7577
if err != nil {

cli/templatepull_test.go

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ package cli_test
33
import (
44
"bytes"
55
"context"
6-
"io"
6+
"crypto/sha256"
7+
"encoding/hex"
78
"os"
89
"path/filepath"
910
"testing"
1011

1112
"github.com/codeclysm/extract"
1213
"github.com/google/uuid"
13-
"github.com/ory/dockertest/v3/docker/pkg/archive"
1414
"github.com/stretchr/testify/require"
1515

1616
"github.com/coder/coder/cli/clitest"
@@ -20,6 +20,26 @@ import (
2020
"github.com/coder/coder/pty/ptytest"
2121
)
2222

23+
// dirSum calculates a checksum of the files in a directory.
24+
func dirSum(t *testing.T, dir string) string {
25+
ents, err := os.ReadDir(dir)
26+
require.NoError(t, err)
27+
sum := sha256.New()
28+
for _, e := range ents {
29+
path := filepath.Join(dir, e.Name())
30+
31+
stat, err := os.Stat(path)
32+
require.NoError(t, err)
33+
34+
byt, err := os.ReadFile(
35+
path,
36+
)
37+
require.NoError(t, err, "mode: %+v", stat.Mode())
38+
_, _ = sum.Write(byt)
39+
}
40+
return hex.EncodeToString(sum.Sum(nil))
41+
}
42+
2343
func TestTemplatePull(t *testing.T) {
2444
t.Parallel()
2545

@@ -119,18 +139,10 @@ func TestTemplatePull(t *testing.T) {
119139

120140
require.NoError(t, <-errChan)
121141

122-
expectedTarRd, err := archive.Tar(expectedDest, archive.Uncompressed)
123-
require.NoError(t, err)
124-
expectedTar, err := io.ReadAll(expectedTarRd)
125-
require.NoError(t, err)
126-
127-
actualTarRd, err := archive.Tar(actualDest, archive.Uncompressed)
128-
require.NoError(t, err)
129-
130-
actualTar, err := io.ReadAll(actualTarRd)
131-
require.NoError(t, err)
132-
133-
require.True(t, bytes.Equal(expectedTar, actualTar), "tar files differ")
142+
require.Equal(t,
143+
dirSum(t, expectedDest),
144+
dirSum(t, actualDest),
145+
)
134146
})
135147

136148
// FolderConflict tests that 'templates pull' fails when a folder with has

0 commit comments

Comments
 (0)