carlos / platform Public

media: clear SA1019 findings now that main runs the check

Main switched staticcheck's SA1019 on (08b87a29), and the merge brought
eleven findings in this branch's new code. Following main's settlement:

- TestEveryComparedCodeIsKnown parses the package's non-test files one
  by one instead of with go/parser.ParseDir, as main's tests now do; the
  same files, so the same comparisons.
- Line-scoped lint:ignore, each naming its blocker: S3 can still return
  a lifecycle rule's legacy top-level Prefix (canonicalRule and two
  tests, as main does in awsmanaged); four tests run the go command that
  built them via runtime.GOROOT, with PATH's go as the fallback; the
  mediaimage test signs fixture InRelease files with x/crypto/openpgp,
  while release.go verifies with gpgv.

No behaviour changes. Every package touched is outside the root binary,
so the census is unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev c3a6077ae7b4024b7ecd0a1ee99f0ebecb433169 parent 252ca58
7 files changed, +42 −28
  • cmd/mediaimage/mediaimage_test.go +3 −0
  • internal/media/boundary_test.go +1 −0
  • internal/mediaaws/buckets.go +1 −0
  • internal/mediaaws/mediaaws_test.go +34 −28
  • internal/medialocal/e2e_test.go +1 −0
  • internal/medialocal/testonly_test.go +1 −0
  • internal/storecfg/storecfg_test.go +1 −0
diff --git a/cmd/mediaimage/mediaimage_test.go b/cmd/mediaimage/mediaimage_test.go
index f8d7ea045..152d7095f 100644
--- a/cmd/mediaimage/mediaimage_test.go
+++ b/cmd/mediaimage/mediaimage_test.go
@@ -28,8 +28,11 @@ import (
"sync/atomic"
"testing"
+ //lint:ignore SA1019 test only: signs fixture InRelease files; release.go verifies them with gpgv, not with this package
"golang.org/x/crypto/openpgp"
+ //lint:ignore SA1019 test only: signs fixture InRelease files; release.go verifies them with gpgv, not with this package
"golang.org/x/crypto/openpgp/clearsign"
+ //lint:ignore SA1019 test only: signs fixture InRelease files; release.go verifies them with gpgv, not with this package
"golang.org/x/crypto/openpgp/packet"
"github.com/carlosframework/platform/internal/media"
diff --git a/internal/media/boundary_test.go b/internal/media/boundary_test.go
index f82a9ab4a..e4f4133fd 100644
--- a/internal/media/boundary_test.go
+++ b/internal/media/boundary_test.go
@@ -27,6 +27,7 @@ var corePackages = []string{
// off: one import path a line.
func goList(t *testing.T, arch string, patterns ...string) []string {
t.Helper()
+ //lint:ignore SA1019 the go command that built this test (go test also puts it first on PATH, the fallback); go env GOROOT would need a go to ask
gobin := filepath.Join(runtime.GOROOT(), "bin", "go")
if _, err := os.Stat(gobin); err != nil {
if gobin, err = exec.LookPath("go"); err != nil {
diff --git a/internal/mediaaws/buckets.go b/internal/mediaaws/buckets.go
index 7098de931..0f8ff127e 100644
--- a/internal/mediaaws/buckets.go
+++ b/internal/mediaaws/buckets.go
@@ -178,6 +178,7 @@ func (b *buckets) lifecycle(ctx context.Context, bucket string) ([]byte, error)
// canonicalRule is one lifecycle rule in storecfg's canonical form.
func canonicalRule(r s3types.LifecycleRule) storecfg.LifecycleRule {
+ //lint:ignore SA1019 S3 can still return a rule scoped by the legacy top-level Prefix, and the canonical form has to see it
out := storecfg.LifecycleRule{ID: aws.ToString(r.ID), Status: string(r.Status), Prefix: aws.ToString(r.Prefix), Other: unmodelled(r)}
if r.Filter != nil && aws.ToString(r.Filter.Prefix) != "" {
if out.Prefix != "" && out.Prefix != aws.ToString(r.Filter.Prefix) {
diff --git a/internal/mediaaws/mediaaws_test.go b/internal/mediaaws/mediaaws_test.go
index ba2331e72..3ff124a14 100644
--- a/internal/mediaaws/mediaaws_test.go
+++ b/internal/mediaaws/mediaaws_test.go
@@ -1983,6 +1983,7 @@ func TestInspectNamesLifecycleSettingsItDoesNotModel(t *testing.T) {
}
// The deprecated top-level prefix is the same thing as the filter's.
deprecated := platform()
+ //lint:ignore SA1019 S3 can still return the legacy top-level Prefix; this pins how the canonical form reads one
deprecated.Filter, deprecated.Prefix = nil, aws.String("")
if got := storecfg.Hash(inspect(deprecated)); got != own {
t.Fatalf("a deprecated empty prefix differs: %s", inspect(deprecated))
@@ -2012,6 +2013,7 @@ func TestInspectNamesLifecycleSettingsItDoesNotModel(t *testing.T) {
"a prefix": func(r *s3types.LifecycleRule) {
r.Filter = &s3types.LifecycleRuleFilter{Prefix: aws.String("uploads/")}
},
+ //lint:ignore SA1019 S3 can still return the legacy top-level Prefix; this pins how the canonical form reads one
"a deprecated prefix": func(r *s3types.LifecycleRule) { r.Filter, r.Prefix = nil, aws.String("uploads/") },
"disabled": func(r *s3types.LifecycleRule) { r.Status = s3types.ExpirationStatusDisabled },
"another id": func(r *s3types.LifecycleRule) { r.ID = aws.String("theirs") },
@@ -2772,39 +2774,43 @@ func TestHandlerTransfersAgainstASigningStore(t *testing.T) {
// a new comparison would silently lose its diagnostic.
func TestEveryComparedCodeIsKnown(t *testing.T) {
fset := token.NewFileSet()
- pkgs, err := parser.ParseDir(fset, ".", func(fi os.FileInfo) bool {
- return !strings.HasSuffix(fi.Name(), "_test.go")
- }, 0)
+ entries, err := os.ReadDir(".")
if err != nil {
t.Fatal(err)
}
compared := 0
- for _, pkg := range pkgs {
- for _, f := range pkg.Files {
- ast.Inspect(f, func(n ast.Node) bool {
- call, ok := n.(*ast.CallExpr)
- if !ok {
- return true
- }
- if fn, ok := call.Fun.(*ast.Ident); !ok || fn.Name != "isCode" || len(call.Args) != 2 {
- return true
- }
- lit, ok := call.Args[1].(*ast.BasicLit)
- if !ok || lit.Kind != token.STRING {
- t.Errorf("%s: isCode is not given a string literal", fset.Position(call.Pos()))
- return true
- }
- code, err := strconv.Unquote(lit.Value)
- if err != nil {
- t.Fatal(err)
- }
- compared++
- if !knownAPICodes[code] {
- t.Errorf("%s: isCode compares %q, which knownAPICodes does not list", fset.Position(call.Pos()), code)
- }
- return true
- })
+ for _, e := range entries {
+ name := e.Name()
+ if e.IsDir() || !strings.HasSuffix(name, ".go") || strings.HasSuffix(name, "_test.go") {
+ continue
+ }
+ f, err := parser.ParseFile(fset, name, nil, 0)
+ if err != nil {
+ t.Fatal(err)
}
+ ast.Inspect(f, func(n ast.Node) bool {
+ call, ok := n.(*ast.CallExpr)
+ if !ok {
+ return true
+ }
+ if fn, ok := call.Fun.(*ast.Ident); !ok || fn.Name != "isCode" || len(call.Args) != 2 {
+ return true
+ }
+ lit, ok := call.Args[1].(*ast.BasicLit)
+ if !ok || lit.Kind != token.STRING {
+ t.Errorf("%s: isCode is not given a string literal", fset.Position(call.Pos()))
+ return true
+ }
+ code, err := strconv.Unquote(lit.Value)
+ if err != nil {
+ t.Fatal(err)
+ }
+ compared++
+ if !knownAPICodes[code] {
+ t.Errorf("%s: isCode compares %q, which knownAPICodes does not list", fset.Position(call.Pos()), code)
+ }
+ return true
+ })
}
if compared < 10 {
t.Fatalf("found only %d isCode comparisons; the walk no longer sees them", compared)
diff --git a/internal/medialocal/e2e_test.go b/internal/medialocal/e2e_test.go
index 479383a28..8a3cbae14 100644
--- a/internal/medialocal/e2e_test.go
+++ b/internal/medialocal/e2e_test.go
@@ -48,6 +48,7 @@ var e2eFixtures = map[string]string{
// goTool is the go command that built this test.
func goTool(t *testing.T) string {
t.Helper()
+ //lint:ignore SA1019 the go command that built this test (go test also puts it first on PATH, the fallback); go env GOROOT would need a go to ask
gobin := filepath.Join(runtime.GOROOT(), "bin", "go")
if _, err := os.Stat(gobin); err != nil {
if gobin, err = exec.LookPath("go"); err != nil {
diff --git a/internal/medialocal/testonly_test.go b/internal/medialocal/testonly_test.go
index 2abbe2b2f..126a0a58c 100644
--- a/internal/medialocal/testonly_test.go
+++ b/internal/medialocal/testonly_test.go
@@ -60,6 +60,7 @@ func supportedTargets(t *testing.T) []string {
// runner as a production engine needs that containment first, and this
// guard removed on purpose.
func TestMedialocalIsTestOnly(t *testing.T) {
+ //lint:ignore SA1019 the go command that built this test (go test also puts it first on PATH, the fallback); go env GOROOT would need a go to ask
gobin := filepath.Join(runtime.GOROOT(), "bin", "go")
if _, err := os.Stat(gobin); err != nil {
if gobin, err = exec.LookPath("go"); err != nil {
diff --git a/internal/storecfg/storecfg_test.go b/internal/storecfg/storecfg_test.go
index f48154a64..9ef5ca51e 100644
--- a/internal/storecfg/storecfg_test.go
+++ b/internal/storecfg/storecfg_test.go
@@ -196,6 +196,7 @@ func TestFakeUploadsRoundTrip(t *testing.T) {
// Checked on the link graph, not the import lines: importing a package that
// itself imports the SDK (objstore does) links it just the same.
func TestStorecfgLinksNoCloudSDK(t *testing.T) {
+ //lint:ignore SA1019 the go command that built this test (go test also puts it first on PATH, the fallback); go env GOROOT would need a go to ask
gobin := filepath.Join(runtime.GOROOT(), "bin", "go")
if _, err := os.Stat(gobin); err != nil {
if gobin, err = exec.LookPath("go"); err != nil {