Skip to content

Commit e85bc1f

Browse files
committed
Merge remote-tracking branch 'origin/main' into jjs/dau-history-backend
2 parents dbebf0b + 3f1795f commit e85bc1f

File tree

70 files changed

+906
-4910
lines changed

Some content is hidden

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

70 files changed

+906
-4910
lines changed

.github/workflows/ci.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,15 @@ jobs:
271271
# coderd/rbac/object_gen.go:1:1: syntax error: package statement must be first
272272
run: "make --output-sync -B gen"
273273

274+
- name: make update-golden-files
275+
run: |
276+
make clean/golden-files
277+
# Notifications require DB, we could start a DB instance here but
278+
# let's just restore for now.
279+
git checkout -- coderd/notifications/testdata/rendered-templates
280+
# As above, skip `-j` flag.
281+
make --output-sync -B update-golden-files
282+
274283
- name: Check for unstaged files
275284
run: ./scripts/check_unstaged.sh
276285

.github/workflows/typos.toml

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ extend-exclude = [
3535
# These files contain base64 strings that confuse the detector
3636
"**XService**.ts",
3737
"**identity.go",
38-
"scripts/ci-report/testdata/**",
3938
"**/*_test.go",
4039
"**/*.test.tsx",
4140
"**/pnpm-lock.yaml",

CONTRIBUTING.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://coder.com/docs/CONTRIBUTING

Makefile

+22-12
Original file line numberDiff line numberDiff line change
@@ -701,19 +701,33 @@ coderd/apidoc/swagger.json: $(shell find ./scripts/apidocgen $(FIND_EXCLUSIONS)
701701

702702
update-golden-files: \
703703
cli/testdata/.gen-golden \
704-
helm/coder/tests/testdata/.gen-golden \
705-
helm/provisioner/tests/testdata/.gen-golden \
706-
scripts/ci-report/testdata/.gen-golden \
707-
enterprise/cli/testdata/.gen-golden \
708-
enterprise/tailnet/testdata/.gen-golden \
709-
tailnet/testdata/.gen-golden \
710704
coderd/.gen-golden \
711705
coderd/notifications/.gen-golden \
712-
provisioner/terraform/testdata/.gen-golden
706+
enterprise/cli/testdata/.gen-golden \
707+
enterprise/tailnet/testdata/.gen-golden \
708+
helm/coder/tests/testdata/.gen-golden \
709+
helm/provisioner/tests/testdata/.gen-golden \
710+
provisioner/terraform/testdata/.gen-golden \
711+
tailnet/testdata/.gen-golden
713712
.PHONY: update-golden-files
714713

714+
clean/golden-files:
715+
find . -type f -name '.gen-golden' -delete
716+
find \
717+
cli/testdata \
718+
coderd/notifications/testdata \
719+
coderd/testdata \
720+
enterprise/cli/testdata \
721+
enterprise/tailnet/testdata \
722+
helm/coder/tests/testdata \
723+
helm/provisioner/tests/testdata \
724+
provisioner/terraform/testdata \
725+
tailnet/testdata \
726+
-type f -name '*.golden' -delete
727+
.PHONY: clean/golden-files
728+
715729
cli/testdata/.gen-golden: $(wildcard cli/testdata/*.golden) $(wildcard cli/*.tpl) $(GO_SRC_FILES) $(wildcard cli/*_test.go)
716-
go test ./cli -run="Test(CommandHelp|ServerYAML|ErrorExamples)" -update
730+
go test ./cli -run="Test(CommandHelp|ServerYAML|ErrorExamples|.*Golden)" -update
717731
touch "$@"
718732

719733
enterprise/cli/testdata/.gen-golden: $(wildcard enterprise/cli/testdata/*.golden) $(wildcard cli/*.tpl) $(GO_SRC_FILES) $(wildcard enterprise/cli/*_test.go)
@@ -754,10 +768,6 @@ provisioner/terraform/testdata/version:
754768
fi
755769
.PHONY: provisioner/terraform/testdata/version
756770

757-
scripts/ci-report/testdata/.gen-golden: $(wildcard scripts/ci-report/testdata/*) $(wildcard scripts/ci-report/*.go)
758-
go test ./scripts/ci-report -run=TestOutputMatchesGoldenFile -update
759-
touch "$@"
760-
761771
# Combine .gitignore with .prettierignore.include to generate .prettierignore.
762772
.prettierignore: .gitignore .prettierignore.include
763773
echo "# Code generated by Makefile ($^). DO NOT EDIT." > "$@"

apiversion/doc.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Package apiversion provides an API version type that can be used to validate
2+
// compatibility between two API versions.
3+
//
4+
// NOTE: API VERSIONS ARE NOT SEMANTIC VERSIONS.
5+
//
6+
// API versions are represented as major.minor where major and minor are both
7+
// positive integers.
8+
//
9+
// API versions are not directly tied to a specific release of the software.
10+
// Instead, they are used to represent the capabilities of the server. For
11+
// example, a server that supports API version 1.2 should be able to handle
12+
// requests from clients that support API version 1.0, 1.1, or 1.2.
13+
// However, a server that supports API version 2.0 is not required to handle
14+
// requests from clients that support API version 1.x.
15+
// Clients may need to negotiate with the server to determine the highest
16+
// supported API version.
17+
//
18+
// When making a change to the API, use the following rules to determine the
19+
// next API version:
20+
// 1. If the change is backward-compatible, increment the minor version.
21+
// Examples of backward-compatible changes include adding new fields to
22+
// a response or adding new endpoints.
23+
// 2. If the change is not backward-compatible, increment the major version.
24+
// Examples of non-backward-compatible changes include removing or renaming
25+
// fields.
26+
package apiversion

cli/cliui/table.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"github.com/fatih/structtag"
1010
"github.com/jedib0t/go-pretty/v6/table"
1111
"golang.org/x/xerrors"
12+
13+
"github.com/coder/coder/v2/codersdk"
1214
)
1315

1416
// Table creates a new table with standardized styles.
@@ -195,6 +197,12 @@ func renderTable(out any, sort string, headers table.Row, filterColumns []string
195197
if val != nil {
196198
v = val.Format(time.RFC3339)
197199
}
200+
case codersdk.NullTime:
201+
if val.Valid {
202+
v = val.Time.Format(time.RFC3339)
203+
} else {
204+
v = nil
205+
}
198206
case *int64:
199207
if val != nil {
200208
v = *val
@@ -204,8 +212,13 @@ func renderTable(out any, sort string, headers table.Row, filterColumns []string
204212
v = val.String()
205213
}
206214
case fmt.Stringer:
207-
if val != nil {
215+
// Protect against typed nils since fmt.Stringer is an interface.
216+
vv := reflect.ValueOf(v)
217+
nilPtr := vv.Kind() == reflect.Ptr && vv.IsNil()
218+
if val != nil && !nilPtr {
208219
v = val.String()
220+
} else if nilPtr {
221+
v = nil
209222
}
210223
}
211224

cli/cliui/table_test.go

+38-27
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cliui_test
22

33
import (
4+
"database/sql"
45
"fmt"
56
"log"
67
"strings"
@@ -11,6 +12,7 @@ import (
1112
"github.com/stretchr/testify/require"
1213

1314
"github.com/coder/coder/v2/cli/cliui"
15+
"github.com/coder/coder/v2/codersdk"
1416
)
1517

1618
type stringWrapper struct {
@@ -24,18 +26,20 @@ func (s stringWrapper) String() string {
2426
}
2527

2628
type tableTest1 struct {
27-
Name string `table:"name,default_sort"`
28-
NotIncluded string // no table tag
29-
Age int `table:"age"`
30-
Roles []string `table:"roles"`
31-
Sub1 tableTest2 `table:"sub_1,recursive"`
32-
Sub2 *tableTest2 `table:"sub_2,recursive"`
33-
Sub3 tableTest3 `table:"sub 3,recursive"`
34-
Sub4 tableTest2 `table:"sub 4"` // not recursive
29+
Name string `table:"name,default_sort"`
30+
AltName *stringWrapper `table:"alt_name"`
31+
NotIncluded string // no table tag
32+
Age int `table:"age"`
33+
Roles []string `table:"roles"`
34+
Sub1 tableTest2 `table:"sub_1,recursive"`
35+
Sub2 *tableTest2 `table:"sub_2,recursive"`
36+
Sub3 tableTest3 `table:"sub 3,recursive"`
37+
Sub4 tableTest2 `table:"sub 4"` // not recursive
3538

3639
// Types with special formatting.
37-
Time time.Time `table:"time"`
38-
TimePtr *time.Time `table:"time_ptr"`
40+
Time time.Time `table:"time"`
41+
TimePtr *time.Time `table:"time_ptr"`
42+
NullTime codersdk.NullTime `table:"null_time"`
3943
}
4044

4145
type tableTest2 struct {
@@ -62,9 +66,10 @@ func Test_DisplayTable(t *testing.T) {
6266
// Not sorted by name or age to test sorting.
6367
in := []tableTest1{
6468
{
65-
Name: "bar",
66-
Age: 20,
67-
Roles: []string{"a"},
69+
Name: "bar",
70+
AltName: &stringWrapper{str: "bar alt"},
71+
Age: 20,
72+
Roles: []string{"a"},
6873
Sub1: tableTest2{
6974
Name: stringWrapper{str: "bar1"},
7075
Age: 21,
@@ -82,6 +87,12 @@ func Test_DisplayTable(t *testing.T) {
8287
},
8388
Time: someTime,
8489
TimePtr: nil,
90+
NullTime: codersdk.NullTime{
91+
NullTime: sql.NullTime{
92+
Time: someTime,
93+
Valid: true,
94+
},
95+
},
8596
},
8697
{
8798
Name: "foo",
@@ -138,10 +149,10 @@ func Test_DisplayTable(t *testing.T) {
138149
t.Parallel()
139150

140151
expected := `
141-
NAME AGE ROLES SUB 1 NAME SUB 1 AGE SUB 2 NAME SUB 2 AGE SUB 3 INNER NAME SUB 3 INNER AGE SUB 4 TIME TIME PTR
142-
bar 20 [a] bar1 21 <nil> <nil> bar3 23 {bar4 24 } 2022-08-02T15:49:10Z <nil>
143-
baz 30 [] baz1 31 <nil> <nil> baz3 33 {baz4 34 } 2022-08-02T15:49:10Z <nil>
144-
foo 10 [a, b, c] foo1 11 foo2 12 foo3 13 {foo4 14 } 2022-08-02T15:49:10Z 2022-08-02T15:49:10Z
152+
NAME ALT NAME AGE ROLES SUB 1 NAME SUB 1 AGE SUB 2 NAME SUB 2 AGE SUB 3 INNER NAME SUB 3 INNER AGE SUB 4 TIME TIME PTR NULL TIME
153+
bar bar alt 20 [a] bar1 21 <nil> <nil> bar3 23 {bar4 24 } 2022-08-02T15:49:10Z <nil> 2022-08-02T15:49:10Z
154+
baz <nil> 30 [] baz1 31 <nil> <nil> baz3 33 {baz4 34 } 2022-08-02T15:49:10Z <nil> <nil>
155+
foo <nil> 10 [a, b, c] foo1 11 foo2 12 foo3 13 {foo4 14 } 2022-08-02T15:49:10Z 2022-08-02T15:49:10Z <nil>
145156
`
146157

147158
// Test with non-pointer values.
@@ -165,10 +176,10 @@ foo 10 [a, b, c] foo1 11 foo2 12 foo3
165176
t.Parallel()
166177

167178
expected := `
168-
NAME AGE ROLES SUB 1 NAME SUB 1 AGE SUB 2 NAME SUB 2 AGE SUB 3 INNER NAME SUB 3 INNER AGE SUB 4 TIME TIME PTR
169-
foo 10 [a, b, c] foo1 11 foo2 12 foo3 13 {foo4 14 } 2022-08-02T15:49:10Z 2022-08-02T15:49:10Z
170-
bar 20 [a] bar1 21 <nil> <nil> bar3 23 {bar4 24 } 2022-08-02T15:49:10Z <nil>
171-
baz 30 [] baz1 31 <nil> <nil> baz3 33 {baz4 34 } 2022-08-02T15:49:10Z <nil>
179+
NAME ALT NAME AGE ROLES SUB 1 NAME SUB 1 AGE SUB 2 NAME SUB 2 AGE SUB 3 INNER NAME SUB 3 INNER AGE SUB 4 TIME TIME PTR NULL TIME
180+
foo <nil> 10 [a, b, c] foo1 11 foo2 12 foo3 13 {foo4 14 } 2022-08-02T15:49:10Z 2022-08-02T15:49:10Z <nil>
181+
bar bar alt 20 [a] bar1 21 <nil> <nil> bar3 23 {bar4 24 } 2022-08-02T15:49:10Z <nil> 2022-08-02T15:49:10Z
182+
baz <nil> 30 [] baz1 31 <nil> <nil> baz3 33 {baz4 34 } 2022-08-02T15:49:10Z <nil> <nil>
172183
`
173184

174185
out, err := cliui.DisplayTable(in, "age", nil)
@@ -235,12 +246,12 @@ Alice 25
235246
t.Run("WithSeparator", func(t *testing.T) {
236247
t.Parallel()
237248
expected := `
238-
NAME AGE ROLES SUB 1 NAME SUB 1 AGE SUB 2 NAME SUB 2 AGE SUB 3 INNER NAME SUB 3 INNER AGE SUB 4 TIME TIME PTR
239-
bar 20 [a] bar1 21 <nil> <nil> bar3 23 {bar4 24 } 2022-08-02T15:49:10Z <nil>
240-
---------------------------------------------------------------------------------------------------------------------------------------------------------------
241-
baz 30 [] baz1 31 <nil> <nil> baz3 33 {baz4 34 } 2022-08-02T15:49:10Z <nil>
242-
---------------------------------------------------------------------------------------------------------------------------------------------------------------
243-
foo 10 [a, b, c] foo1 11 foo2 12 foo3 13 {foo4 14 } 2022-08-02T15:49:10Z 2022-08-02T15:49:10Z
249+
NAME ALT NAME AGE ROLES SUB 1 NAME SUB 1 AGE SUB 2 NAME SUB 2 AGE SUB 3 INNER NAME SUB 3 INNER AGE SUB 4 TIME TIME PTR NULL TIME
250+
bar bar alt 20 [a] bar1 21 <nil> <nil> bar3 23 {bar4 24 } 2022-08-02T15:49:10Z <nil> 2022-08-02T15:49:10Z
251+
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
252+
baz <nil> 30 [] baz1 31 <nil> <nil> baz3 33 {baz4 34 } 2022-08-02T15:49:10Z <nil> <nil>
253+
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
254+
foo <nil> 10 [a, b, c] foo1 11 foo2 12 foo3 13 {foo4 14 } 2022-08-02T15:49:10Z 2022-08-02T15:49:10Z <nil>
244255
`
245256

246257
var inlineIn []any

cli/testdata/coder_templates_plan_--help.golden

-6
This file was deleted.

coderd/apidoc/docs.go

+12-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

+12-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/audit/diff.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package audit
22

33
import (
44
"github.com/coder/coder/v2/coderd/database"
5+
"github.com/coder/coder/v2/coderd/idpsync"
56
)
67

78
// Auditable is mostly a marker interface. It contains a definitive list of all
@@ -26,7 +27,10 @@ type Auditable interface {
2627
database.CustomRole |
2728
database.AuditableOrganizationMember |
2829
database.Organization |
29-
database.NotificationTemplate
30+
database.NotificationTemplate |
31+
idpsync.OrganizationSyncSettings |
32+
idpsync.GroupSyncSettings |
33+
idpsync.RoleSyncSettings
3034
}
3135

3236
// Map is a map of changed fields in an audited resource. It maps field names to

0 commit comments

Comments
 (0)