This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

lexlint: fix panic in breakingDefs when inner schema type changes

The type-change guard compared reflect.TypeOf on the SchemaDef wrapper
structs, which are always the same type. This meant the guard never
triggered, and bare type assertions like remote.Inner.(SchemaString)
would panic when the inner types differed (e.g. SchemaString vs
SchemaObject).

Fix by comparing the Inner field types instead.

+26 -2
+2 -2
lex/lexlint/breaking.go
··· 55 55 issues := []LintIssue{} 56 56 57 57 // NOTE: in some situations this sort of change might actually be allowed? 58 - if reflect.TypeOf(local) != reflect.TypeOf(remote) { 58 + if reflect.TypeOf(local.Inner) != reflect.TypeOf(remote.Inner) { 59 59 issues = append(issues, LintIssue{ 60 60 NSID: nsid, 61 61 LintLevel: "error", 62 62 LintName: "type-change", 63 63 LintDescription: "schema definition type changed", 64 - Message: fmt.Sprintf("schema type changed (%s): %T != %T", name, local, remote), 64 + Message: fmt.Sprintf("schema type changed (%s): %T != %T", name, local.Inner, remote.Inner), 65 65 }) 66 66 return issues 67 67 }
+24
lex/lexlint/breaking_test.go
··· 1 + package lexlint 2 + 3 + import ( 4 + "testing" 5 + 6 + "github.com/bluesky-social/indigo/atproto/lexicon" 7 + 8 + "github.com/stretchr/testify/assert" 9 + ) 10 + 11 + func TestBreakingDefs_InnerTypeChange(t *testing.T) { 12 + assert := assert.New(t) 13 + 14 + // When a field changes type (e.g. string -> object), breakingDefs should 15 + // report a type-change error rather than panicking on a type assertion. 16 + local := lexicon.SchemaDef{Inner: lexicon.SchemaString{}} 17 + remote := lexicon.SchemaDef{Inner: lexicon.SchemaObject{}} 18 + 19 + issues := breakingDefs("com.example.test", "testField", local, remote) 20 + 21 + assert.Len(issues, 1) 22 + assert.Equal("type-change", issues[0].LintName) 23 + assert.Equal("error", issues[0].LintLevel) 24 + }