From 57689a302c804a1dd7936be68d8d4280ebaa0d2e Mon Sep 17 00:00:00 2001 From: matiasdaloia <66310421+matiasdaloia@users.noreply.github.com> Date: Tue, 17 Nov 2026 12:16:24 +0100 Subject: [PATCH 1/2] feat(dependencies): declare the Go standard library of a Go module Every Go binary links the standard library, and most Go vulnerabilities land there, but a Go root listed only its required modules. A go.mod now declares pkg:golang/stdlib at the toolchain it builds with: the toolchain directive when set, else the go directive. Both the go command resolver (go mod edit -json, falling back to go list's GoVersion) and the flat go.mod parser emit it. It is named stdlib, as the Go vulnerability database and Syft name it: Grype matches nothing on cyclonedx-gomod's "std". Refs #138 --- pkg/dependencies/parser_test.go | 5 +- pkg/dependencies/parsers/golang.go | 56 ++++++++++ pkg/dependencies/parsers/golang_test.go | 70 +++++++++++- pkg/dependencies/resolve/toolchain/golang.go | 43 ++++++-- .../resolve/toolchain/golang_test.go | 5 + .../testdata/go/graph-fails/graph.golden.json | 9 ++ .../testdata/go/list-error/graph.golden.json | 9 ++ .../go/non-selected/graph.golden.json | 9 ++ .../testdata/go/offline/graph.golden.json | 9 ++ .../go/replace-local/graph.golden.json | 9 ++ .../go/replace-version/graph.golden.json | 9 ++ .../go/toolchain-directive/graph.golden.json | 100 ++++++++++++++++++ .../testdata/go/toolchain-directive/graph.txt | 11 ++ .../testdata/go/toolchain-directive/list.json | 42 ++++++++ .../testdata/go/toolchain-directive/mod.json | 5 + 15 files changed, 380 insertions(+), 11 deletions(-) create mode 100644 pkg/dependencies/resolve/toolchain/testdata/go/toolchain-directive/graph.golden.json create mode 100644 pkg/dependencies/resolve/toolchain/testdata/go/toolchain-directive/graph.txt create mode 100644 pkg/dependencies/resolve/toolchain/testdata/go/toolchain-directive/list.json create mode 100644 pkg/dependencies/resolve/toolchain/testdata/go/toolchain-directive/mod.json diff --git a/pkg/dependencies/parser_test.go b/pkg/dependencies/parser_test.go index 2dedf26..110d9fc 100644 --- a/pkg/dependencies/parser_test.go +++ b/pkg/dependencies/parser_test.go @@ -105,8 +105,9 @@ require ( t.Fatalf("ParseGoMod failed: %v", err) } - if len(result.Purls) != 2 { - t.Errorf("Expected 2 dependencies, got %d", len(result.Purls)) + // The two requirements and the standard library (go 1.22). + if len(result.Purls) != 3 { + t.Errorf("Expected 3 dependencies, got %d", len(result.Purls)) } // Check first dependency diff --git a/pkg/dependencies/parsers/golang.go b/pkg/dependencies/parsers/golang.go index 99c8153..22324e4 100644 --- a/pkg/dependencies/parsers/golang.go +++ b/pkg/dependencies/parsers/golang.go @@ -52,6 +52,7 @@ func ParseGoMod(fileContent []byte, filePath string) (*LocalDependency, error) { scanner := bufio.NewScanner(bytes.NewReader(fileContent)) inRequireBlock := false lineNo := 0 + var goDirective, toolchainDirective directive for scanner.Scan() { lineNo++ @@ -62,6 +63,15 @@ func ParseGoMod(fileContent []byte, filePath string) (*LocalDependency, error) { continue } + if v, ok := strings.CutPrefix(line, "go "); ok && !inRequireBlock { + goDirective = directive{strings.TrimSpace(v), lineNo, strings.TrimSpace(raw)} + continue + } + if v, ok := strings.CutPrefix(line, "toolchain "); ok && !inRequireBlock { + toolchainDirective = directive{strings.TrimSpace(v), lineNo, strings.TrimSpace(raw)} + continue + } + // Check for require block start if strings.HasPrefix(line, "require (") { inRequireBlock = true @@ -110,9 +120,55 @@ func ParseGoMod(fileContent []byte, filePath string) (*LocalDependency, error) { return nil, err } + if v := GoStdVersion(goDirective.value, toolchainDirective.value); v != "" { + d := goDirective + if toolchainDirective.value != "" { + d = toolchainDirective + } + result.Purls = append(result.Purls, LocalPurl{ + Purl: BuildPURL("golang", "", GoStdName, v, nil), + Requirement: v, + Line: d.line, + DeclaredText: d.text, + }) + } + return result, nil } +// GoStdName is the module name of the Go standard library: pkg:golang/stdlib@go1.26.11. +// It is the name the Go vulnerability database files standard library advisories +// under, and the one Syft and Grype use; Grype matches nothing on cyclonedx-gomod's +// "std". +const GoStdName = "stdlib" + +// directive is a go.mod directive's value and where it was declared. +type directive struct { + value string + line int + text string +} + +// GoStdVersion returns the version of the standard library a module is built +// with, from its go.mod directives: the toolchain directive ("go1.26.11") when +// there is one, since that is the toolchain the go command switches to, else the +// go directive ("1.26.11" becomes "go1.26.11"). It returns "" when neither is set. +// +// A go directive without a patch release ("1.26") is kept as it is: it is the +// oldest release the module allows, and a scanner reads it as the first one. +func GoStdVersion(goDirective, toolchainDirective string) string { + if v := strings.TrimSpace(toolchainDirective); v != "" && v != "default" { + if !strings.HasPrefix(v, "go") { + v = "go" + v + } + return v + } + if v := strings.TrimSpace(goDirective); v != "" { + return "go" + v + } + return "" +} + // ParseGoSum parses a go.sum file and extracts dependencies func ParseGoSum(fileContent []byte, filePath string) (*LocalDependency, error) { result := &LocalDependency{ diff --git a/pkg/dependencies/parsers/golang_test.go b/pkg/dependencies/parsers/golang_test.go index 7a9a35a..30377f2 100644 --- a/pkg/dependencies/parsers/golang_test.go +++ b/pkg/dependencies/parsers/golang_test.go @@ -61,6 +61,12 @@ require github.com/foo/bar v1.2.3 Line: 7, DeclaredText: "require github.com/foo/bar v1.2.3", }, + { + Purl: "pkg:golang/stdlib@go1.22", + Requirement: "go1.22", + Line: 3, + DeclaredText: "go 1.22", + }, }, }, { @@ -87,6 +93,12 @@ require ( Line: 7, DeclaredText: "github.com/google/uuid v1.6.0", }, + { + Purl: "pkg:golang/stdlib@go1.22", + Requirement: "go1.22", + Line: 3, + DeclaredText: "go 1.22", + }, }, }, { @@ -102,6 +114,12 @@ require github.com/spf13/pflag v1.0.10 Line: 3, DeclaredText: "require github.com/spf13/pflag v1.0.10", }, + { + Purl: "pkg:golang/stdlib@go1.22", + Requirement: "go1.22", + Line: 2, + DeclaredText: "go 1.22", + }, }, }, } @@ -174,7 +192,57 @@ go 1.22 if err != nil { t.Fatalf("ParseGoMod error: %v", err) } + // The standard library is the only dependency of a module that requires nothing. + if len(result.Purls) != 1 || result.Purls[0].Purl != "pkg:golang/stdlib@go1.22" { + t.Errorf("expected only the standard library for a module-only go.mod, got %+v", result.Purls) + } +} + +// The standard library is declared at the toolchain the module builds with: +// the toolchain directive when there is one, else the go directive. +func TestParseGoModStdlib(t *testing.T) { + t.Parallel() + + for _, tc := range []struct { + name, content, purl string + line int + }{ + {"go directive", "module m\n\ngo 1.26.11\n", "pkg:golang/stdlib@go1.26.11", 3}, + {"toolchain wins over go", "module m\n\ngo 1.26\n\ntoolchain go1.26.11\n", "pkg:golang/stdlib@go1.26.11", 5}, + {"go directive without patch kept as is", "module m\ngo 1.26\n", "pkg:golang/stdlib@go1.26", 2}, + } { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + result, err := ParseGoMod([]byte(tc.content), "go.mod") + if err != nil { + t.Fatalf("ParseGoMod error: %v", err) + } + if len(result.Purls) != 1 || result.Purls[0].Purl != tc.purl || result.Purls[0].Line != tc.line { + t.Errorf("got %+v, want %s at line %d", result.Purls, tc.purl, tc.line) + } + }) + } + + result, err := ParseGoMod([]byte("module m\n"), "go.mod") + if err != nil { + t.Fatalf("ParseGoMod error: %v", err) + } if len(result.Purls) != 0 { - t.Errorf("expected 0 purls for module-only go.mod, got %d", len(result.Purls)) + t.Errorf("a go.mod without a go directive names no toolchain, got %+v", result.Purls) + } +} + +func TestGoStdVersion(t *testing.T) { + t.Parallel() + + for _, tc := range []struct{ goDir, toolchain, want string }{ + {"1.26.11", "", "go1.26.11"}, + {"1.26", "go1.26.11", "go1.26.11"}, + {"1.26", "default", "go1.26"}, + {"", "", ""}, + } { + if got := GoStdVersion(tc.goDir, tc.toolchain); got != tc.want { + t.Errorf("GoStdVersion(%q, %q) = %q, want %q", tc.goDir, tc.toolchain, got, tc.want) + } } } diff --git a/pkg/dependencies/resolve/toolchain/golang.go b/pkg/dependencies/resolve/toolchain/golang.go index 466fc84..393b106 100644 --- a/pkg/dependencies/resolve/toolchain/golang.go +++ b/pkg/dependencies/resolve/toolchain/golang.go @@ -30,6 +30,7 @@ import ( "io" "strings" + "github.com/scanoss/scanoss.go/pkg/dependencies/parsers" "github.com/scanoss/scanoss.go/pkg/dependencies/resolve" "github.com/scanoss/scanoss.go/pkg/dependencies/resolve/internal/build" ) @@ -54,12 +55,13 @@ var goUnreachable = []string{ } type goListModule struct { - Path string - Version string - Main bool - Indirect bool - Replace *struct{ Path, Version string } - Error *struct{ Err string } + Path string + Version string + GoVersion string + Main bool + Indirect bool + Replace *struct{ Path, Version string } + Error *struct{ Err string } } type goSelected struct { @@ -92,11 +94,11 @@ func resolveGo(b *build.Builder, r *build.Root, run runFunc) { mods = append(mods, m) } - main := "" + main, mainGo := "", "" selected := map[string]goSelected{} for _, m := range mods { if m.Main { - main = m.Path + main, mainGo = m.Path, m.GoVersion continue } if m.Error != nil { @@ -123,6 +125,8 @@ func resolveGo(b *build.Builder, r *build.Root, run runFunc) { } } + declareStd(b, r, run, mainGo) + graph := run("go", "mod", "graph") if graph.reason != "" { reason := resolve.ReasonEdgesUnknown @@ -162,3 +166,26 @@ func resolveGo(b *build.Builder, r *build.Root, run runFunc) { } } } + +type goModEdit struct { + Go string + Toolchain string +} + +// declareStd declares the standard library the main module builds with: every +// Go binary links it, and it is where most Go vulnerabilities are. go mod edit +// reads both the go and toolchain directives without the network; if it fails, +// the go directive go list already reported stands in. +func declareStd(b *build.Builder, r *build.Root, run runFunc, goVersion string) { + var mod goModEdit + if out := run("go", "mod", "edit", "-json"); out.reason == "" && json.Unmarshal(out.stdout, &mod) == nil && mod.Go != "" { + goVersion = mod.Go + } + v := parsers.GoStdVersion(goVersion, mod.Toolchain) + if v == "" { + return + } + if id, ok := b.Node("", parsers.GoStdName, v); ok { + r.Declare(id, false) + } +} diff --git a/pkg/dependencies/resolve/toolchain/golang_test.go b/pkg/dependencies/resolve/toolchain/golang_test.go index 96fa215..128b314 100644 --- a/pkg/dependencies/resolve/toolchain/golang_test.go +++ b/pkg/dependencies/resolve/toolchain/golang_test.go @@ -53,6 +53,11 @@ func recorded(t *testing.T, dir string) runFunc { switch strings.Join(append([]string{name}, args...), " ") { case "go list -e -m -json all": return output{stdout: read("list.json")} + case "go mod edit -json": + if _, err := os.Stat(filepath.Join(dir, "mod.json")); err != nil { + return failed("go mod edit", errors.New("exit status 1"), nil) + } + return output{stdout: read("mod.json")} case "go mod graph": if _, err := os.Stat(filepath.Join(dir, "stderr.txt")); err == nil { return failed("go mod graph", errors.New("exit status 1"), read("stderr.txt")) diff --git a/pkg/dependencies/resolve/toolchain/testdata/go/graph-fails/graph.golden.json b/pkg/dependencies/resolve/toolchain/testdata/go/graph-fails/graph.golden.json index 0335551..f7e146a 100644 --- a/pkg/dependencies/resolve/toolchain/testdata/go/graph-fails/graph.golden.json +++ b/pkg/dependencies/resolve/toolchain/testdata/go/graph-fails/graph.golden.json @@ -25,6 +25,11 @@ "id": "pkg:golang/go.yaml.in/yaml/v3@v3.0.5", "purl": "pkg:golang/go.yaml.in/yaml/v3", "version": "v3.0.5" + }, + { + "id": "pkg:golang/stdlib@go1.22", + "purl": "pkg:golang/stdlib", + "version": "go1.22" } ], "roots": [ @@ -56,6 +61,10 @@ { "id": "pkg:golang/go.yaml.in/yaml/v3@v3.0.5", "direct": false + }, + { + "id": "pkg:golang/stdlib@go1.22", + "direct": true } ], "edges": [] diff --git a/pkg/dependencies/resolve/toolchain/testdata/go/list-error/graph.golden.json b/pkg/dependencies/resolve/toolchain/testdata/go/list-error/graph.golden.json index 44d7864..d86eac6 100644 --- a/pkg/dependencies/resolve/toolchain/testdata/go/list-error/graph.golden.json +++ b/pkg/dependencies/resolve/toolchain/testdata/go/list-error/graph.golden.json @@ -9,6 +9,11 @@ "id": "pkg:golang/github.com/google/uuid@v1.6.0", "purl": "pkg:golang/github.com/google/uuid", "version": "v1.6.0" + }, + { + "id": "pkg:golang/stdlib@go1.22", + "purl": "pkg:golang/stdlib", + "version": "go1.22" } ], "roots": [ @@ -28,6 +33,10 @@ { "id": "pkg:golang/github.com/google/uuid@v1.6.0", "direct": true + }, + { + "id": "pkg:golang/stdlib@go1.22", + "direct": true } ], "edges": [] diff --git a/pkg/dependencies/resolve/toolchain/testdata/go/non-selected/graph.golden.json b/pkg/dependencies/resolve/toolchain/testdata/go/non-selected/graph.golden.json index 6391f65..dad1bcb 100644 --- a/pkg/dependencies/resolve/toolchain/testdata/go/non-selected/graph.golden.json +++ b/pkg/dependencies/resolve/toolchain/testdata/go/non-selected/graph.golden.json @@ -14,6 +14,11 @@ "id": "pkg:golang/example.com/d@v1.0.0", "purl": "pkg:golang/example.com/d", "version": "v1.0.0" + }, + { + "id": "pkg:golang/stdlib@go1.22", + "purl": "pkg:golang/stdlib", + "version": "go1.22" } ], "roots": [ @@ -35,6 +40,10 @@ { "id": "pkg:golang/example.com/d@v1.0.0", "direct": false + }, + { + "id": "pkg:golang/stdlib@go1.22", + "direct": true } ], "edges": [ diff --git a/pkg/dependencies/resolve/toolchain/testdata/go/offline/graph.golden.json b/pkg/dependencies/resolve/toolchain/testdata/go/offline/graph.golden.json index eef5c1b..d4dbb6f 100644 --- a/pkg/dependencies/resolve/toolchain/testdata/go/offline/graph.golden.json +++ b/pkg/dependencies/resolve/toolchain/testdata/go/offline/graph.golden.json @@ -20,6 +20,11 @@ "id": "pkg:golang/go.yaml.in/yaml/v3@v3.0.5", "purl": "pkg:golang/go.yaml.in/yaml/v3", "version": "v3.0.5" + }, + { + "id": "pkg:golang/stdlib@go1.22", + "purl": "pkg:golang/stdlib", + "version": "go1.22" } ], "roots": [ @@ -47,6 +52,10 @@ { "id": "pkg:golang/go.yaml.in/yaml/v3@v3.0.5", "direct": false + }, + { + "id": "pkg:golang/stdlib@go1.22", + "direct": true } ], "edges": [] diff --git a/pkg/dependencies/resolve/toolchain/testdata/go/replace-local/graph.golden.json b/pkg/dependencies/resolve/toolchain/testdata/go/replace-local/graph.golden.json index 71d7e68..aaf4382 100644 --- a/pkg/dependencies/resolve/toolchain/testdata/go/replace-local/graph.golden.json +++ b/pkg/dependencies/resolve/toolchain/testdata/go/replace-local/graph.golden.json @@ -25,6 +25,11 @@ "id": "pkg:golang/go.yaml.in/yaml/v3@v3.0.5", "purl": "pkg:golang/go.yaml.in/yaml/v3", "version": "v3.0.5" + }, + { + "id": "pkg:golang/stdlib@go1.22", + "purl": "pkg:golang/stdlib", + "version": "go1.22" } ], "roots": [ @@ -54,6 +59,10 @@ { "id": "pkg:golang/go.yaml.in/yaml/v3@v3.0.5", "direct": false + }, + { + "id": "pkg:golang/stdlib@go1.22", + "direct": true } ], "edges": [ diff --git a/pkg/dependencies/resolve/toolchain/testdata/go/replace-version/graph.golden.json b/pkg/dependencies/resolve/toolchain/testdata/go/replace-version/graph.golden.json index 8923e6a..af0e0d6 100644 --- a/pkg/dependencies/resolve/toolchain/testdata/go/replace-version/graph.golden.json +++ b/pkg/dependencies/resolve/toolchain/testdata/go/replace-version/graph.golden.json @@ -29,6 +29,11 @@ "id": "pkg:golang/gopkg.in/yaml.v3@v3.0.1", "purl": "pkg:golang/gopkg.in/yaml.v3", "version": "v3.0.1" + }, + { + "id": "pkg:golang/stdlib@go1.22", + "purl": "pkg:golang/stdlib", + "version": "go1.22" } ], "roots": [ @@ -62,6 +67,10 @@ { "id": "pkg:golang/gopkg.in/yaml.v3@v3.0.1", "direct": false + }, + { + "id": "pkg:golang/stdlib@go1.22", + "direct": true } ], "edges": [ diff --git a/pkg/dependencies/resolve/toolchain/testdata/go/toolchain-directive/graph.golden.json b/pkg/dependencies/resolve/toolchain/testdata/go/toolchain-directive/graph.golden.json new file mode 100644 index 0000000..20efeb4 --- /dev/null +++ b/pkg/dependencies/resolve/toolchain/testdata/go/toolchain-directive/graph.golden.json @@ -0,0 +1,100 @@ +{ + "nodes": [ + { + "id": "pkg:golang/github.com/davecgh/go-spew@v1.1.1", + "purl": "pkg:golang/github.com/davecgh/go-spew", + "version": "v1.1.1" + }, + { + "id": "pkg:golang/github.com/pmezard/go-difflib@v1.0.0", + "purl": "pkg:golang/github.com/pmezard/go-difflib", + "version": "v1.0.0" + }, + { + "id": "pkg:golang/github.com/stretchr/objx@v0.5.2", + "purl": "pkg:golang/github.com/stretchr/objx", + "version": "v0.5.2" + }, + { + "id": "pkg:golang/github.com/stretchr/testify@v1.11.1", + "purl": "pkg:golang/github.com/stretchr/testify", + "version": "v1.11.1" + }, + { + "id": "pkg:golang/gopkg.in/check.v1@v0.0.0-20161208181325-20d25e280405", + "purl": "pkg:golang/gopkg.in/check.v1", + "version": "v0.0.0-20161208181325-20d25e280405" + }, + { + "id": "pkg:golang/gopkg.in/yaml.v3@v3.0.1", + "purl": "pkg:golang/gopkg.in/yaml.v3", + "version": "v3.0.1" + }, + { + "id": "pkg:golang/stdlib@go1.22.12", + "purl": "pkg:golang/stdlib", + "version": "go1.22.12" + } + ], + "roots": [ + { + "manifest": "go.mod", + "lockfile": "go.mod", + "ecosystem": "golang", + "status": "complete", + "devKnown": false, + "members": [ + { + "id": "pkg:golang/github.com/davecgh/go-spew@v1.1.1", + "direct": false + }, + { + "id": "pkg:golang/github.com/pmezard/go-difflib@v1.0.0", + "direct": false + }, + { + "id": "pkg:golang/github.com/stretchr/objx@v0.5.2", + "direct": false + }, + { + "id": "pkg:golang/github.com/stretchr/testify@v1.11.1", + "direct": true + }, + { + "id": "pkg:golang/gopkg.in/check.v1@v0.0.0-20161208181325-20d25e280405", + "direct": false + }, + { + "id": "pkg:golang/gopkg.in/yaml.v3@v3.0.1", + "direct": false + }, + { + "id": "pkg:golang/stdlib@go1.22.12", + "direct": true + } + ], + "edges": [ + { + "from": "pkg:golang/github.com/stretchr/testify@v1.11.1", + "to": "pkg:golang/github.com/davecgh/go-spew@v1.1.1" + }, + { + "from": "pkg:golang/github.com/stretchr/testify@v1.11.1", + "to": "pkg:golang/github.com/pmezard/go-difflib@v1.0.0" + }, + { + "from": "pkg:golang/github.com/stretchr/testify@v1.11.1", + "to": "pkg:golang/github.com/stretchr/objx@v0.5.2" + }, + { + "from": "pkg:golang/github.com/stretchr/testify@v1.11.1", + "to": "pkg:golang/gopkg.in/yaml.v3@v3.0.1" + }, + { + "from": "pkg:golang/gopkg.in/yaml.v3@v3.0.1", + "to": "pkg:golang/gopkg.in/check.v1@v0.0.0-20161208181325-20d25e280405" + } + ] + } + ] +} diff --git a/pkg/dependencies/resolve/toolchain/testdata/go/toolchain-directive/graph.txt b/pkg/dependencies/resolve/toolchain/testdata/go/toolchain-directive/graph.txt new file mode 100644 index 0000000..e81e35b --- /dev/null +++ b/pkg/dependencies/resolve/toolchain/testdata/go/toolchain-directive/graph.txt @@ -0,0 +1,11 @@ +example.com/app github.com/davecgh/go-spew@v1.1.1 +example.com/app github.com/pmezard/go-difflib@v1.0.0 +example.com/app github.com/stretchr/testify@v1.12.1 +example.com/app go@1.22 +example.com/app gopkg.in/yaml.v3@v3.0.1 +github.com/stretchr/testify@v1.12.1 github.com/davecgh/go-spew@v1.1.1 +github.com/stretchr/testify@v1.12.1 github.com/pmezard/go-difflib@v1.0.0 +github.com/stretchr/testify@v1.12.1 github.com/stretchr/objx@v0.5.2 +github.com/stretchr/testify@v1.12.1 gopkg.in/yaml.v3@v3.0.1 +go@1.22 toolchain@go1.22 +gopkg.in/yaml.v3@v3.0.1 gopkg.in/check.v1@v0.0.0-20161208181325-20d25e280405 diff --git a/pkg/dependencies/resolve/toolchain/testdata/go/toolchain-directive/list.json b/pkg/dependencies/resolve/toolchain/testdata/go/toolchain-directive/list.json new file mode 100644 index 0000000..a522fa1 --- /dev/null +++ b/pkg/dependencies/resolve/toolchain/testdata/go/toolchain-directive/list.json @@ -0,0 +1,42 @@ +{ + "Path": "example.com/app", + "Main": true, + "Dir": "/src/app", + "GoMod": "/src/app/go.mod", + "GoVersion": "1.22" +} +{ + "Path": "github.com/davecgh/go-spew", + "Version": "v1.1.1", + "Indirect": true +} +{ + "Path": "github.com/pmezard/go-difflib", + "Version": "v1.0.0", + "Indirect": true +} +{ + "Path": "github.com/stretchr/objx", + "Version": "v0.5.2", + "Indirect": true +} +{ + "Path": "github.com/stretchr/testify", + "Version": "v1.12.1", + "Replace": { + "Path": "github.com/stretchr/testify", + "Version": "v1.11.1", + "GoVersion": "1.17" + }, + "GoVersion": "1.17" +} +{ + "Path": "gopkg.in/check.v1", + "Version": "v0.0.0-20161208181325-20d25e280405", + "Indirect": true +} +{ + "Path": "gopkg.in/yaml.v3", + "Version": "v3.0.1", + "Indirect": true +} diff --git a/pkg/dependencies/resolve/toolchain/testdata/go/toolchain-directive/mod.json b/pkg/dependencies/resolve/toolchain/testdata/go/toolchain-directive/mod.json new file mode 100644 index 0000000..47166e9 --- /dev/null +++ b/pkg/dependencies/resolve/toolchain/testdata/go/toolchain-directive/mod.json @@ -0,0 +1,5 @@ +{ + "Module": {"Path": "example.com/app"}, + "Go": "1.22", + "Toolchain": "go1.22.12" +} From 58541c892c12bea1e45de14470e194f0e3f0bbe2 Mon Sep 17 00:00:00 2001 From: matiasdaloia <66310421+matiasdaloia@users.noreply.github.com> Date: Tue, 17 Nov 2026 12:19:27 +0100 Subject: [PATCH 2/2] test(dependencies): expect the standard library in the Go integration tests --- pkg/dependencies/resolve/toolchain/integration_test.go | 1 + .../toolchain/testdata/integration/go/graph.golden.json | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/pkg/dependencies/resolve/toolchain/integration_test.go b/pkg/dependencies/resolve/toolchain/integration_test.go index c278b0a..63e065c 100644 --- a/pkg/dependencies/resolve/toolchain/integration_test.go +++ b/pkg/dependencies/resolve/toolchain/integration_test.go @@ -75,6 +75,7 @@ func TestGoIntegrationOffline(t *testing.T) { "pkg:golang/example.com/local", "pkg:golang/github.com/google/uuid@v1.6.0", "pkg:golang/github.com/stretchr/testify@v1.12.1", + "pkg:golang/stdlib@go1.22", // read from go.mod, so known offline } wantIndirect := []resolve.NodeID{"pkg:golang/go.yaml.in/yaml/v3@v3.0.5"} if !slices.Equal(direct, wantDirect) || !slices.Equal(indirect, wantIndirect) { diff --git a/pkg/dependencies/resolve/toolchain/testdata/integration/go/graph.golden.json b/pkg/dependencies/resolve/toolchain/testdata/integration/go/graph.golden.json index 4cee563..655ac2d 100644 --- a/pkg/dependencies/resolve/toolchain/testdata/integration/go/graph.golden.json +++ b/pkg/dependencies/resolve/toolchain/testdata/integration/go/graph.golden.json @@ -25,6 +25,11 @@ "id": "pkg:golang/go.yaml.in/yaml/v3@v3.0.5", "purl": "pkg:golang/go.yaml.in/yaml/v3", "version": "v3.0.5" + }, + { + "id": "pkg:golang/stdlib@go1.22", + "purl": "pkg:golang/stdlib", + "version": "go1.22" } ], "roots": [ @@ -54,6 +59,10 @@ { "id": "pkg:golang/go.yaml.in/yaml/v3@v3.0.5", "direct": false + }, + { + "id": "pkg:golang/stdlib@go1.22", + "direct": true } ], "edges": [