diff --git a/cmd/depviz/main.go b/cmd/depviz/main.go index 9b9310009..9f9d373e7 100644 --- a/cmd/depviz/main.go +++ b/cmd/depviz/main.go @@ -11,6 +11,12 @@ import ( "os/signal" "time" + "github.com/cayleygraph/cayley" + "github.com/cayleygraph/cayley/graph" + _ "github.com/cayleygraph/cayley/graph/kv/bolt" + "github.com/cayleygraph/cayley/schema" + "github.com/oklog/run" + "github.com/peterbourgon/ff/v3/ffcli" "go.uber.org/zap" "moul.io/banner" "moul.io/depviz/v3/pkg/dvcore" @@ -20,13 +26,6 @@ import ( "moul.io/srand" "moul.io/u" "moul.io/zapconfig" - - "github.com/cayleygraph/cayley" - "github.com/cayleygraph/cayley/graph" - _ "github.com/cayleygraph/cayley/graph/kv/bolt" - "github.com/cayleygraph/cayley/schema" - "github.com/oklog/run" - "github.com/peterbourgon/ff/v3/ffcli" ) var ( @@ -436,6 +435,8 @@ func execGenCSV(ctx context.Context, args []string) error { HideIsolated: *genHideIsolated, HidePRs: *genHidePRs, HideExternalDeps: *genHideExternalDeps, + Scope: *genScope, + ScopeSize: *genScopeSize, Format: "csv", } diff --git a/go.mod b/go.mod index ac7b0890f..cf8000648 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module moul.io/depviz/v3 go 1.19 require ( + github.com/Doozers/gl v0.0.0-20230526153138-d7477da16375 github.com/cayleygraph/cayley v0.7.7 github.com/cayleygraph/quad v1.2.4 github.com/go-chi/chi v1.5.4 @@ -19,7 +20,7 @@ require ( github.com/patrickmn/go-cache v2.1.0+incompatible github.com/peterbourgon/ff/v3 v3.3.0 github.com/rs/cors v1.8.3 - github.com/stretchr/testify v1.8.2 + github.com/stretchr/testify v1.8.3 github.com/tailscale/depaware v0.0.0-20210622194025-720c4b409502 github.com/treastech/logger v0.0.0-20180705232552-e381e9ecf2e3 github.com/xhit/go-str2duration/v2 v2.1.0 diff --git a/go.sum b/go.sum index 315fb8e17..8c125f9c0 100644 --- a/go.sum +++ b/go.sum @@ -42,6 +42,8 @@ github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOv github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/Doozers/gl v0.0.0-20230526153138-d7477da16375 h1:eX3dshrL6eaedzgzgvjKQqDPvJWmmUyWu++kfla6/3s= +github.com/Doozers/gl v0.0.0-20230526153138-d7477da16375/go.mod h1:PlImHWfE2dwwNrn6e7+oMeMCJyPpYa7EO+ZI/2Smb6E= github.com/Microsoft/go-winio v0.4.12/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA= github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= @@ -473,18 +475,14 @@ github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/y github.com/spf13/viper v1.8.1/go.mod h1:o0Pch8wJ9BVSWGQMbra6iw0oQ5oktSIBaujf1rJH9Ns= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= +github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= github.com/tailscale/depaware v0.0.0-20201214215404-77d1e9757027/go.mod h1:p9lPsd+cx33L3H9nNoecRRxPssFKUwwI50I3pZ0yT+8= diff --git a/pkg/dvcore/gen.go b/pkg/dvcore/gen.go index cc7813664..2b0dcfc27 100644 --- a/pkg/dvcore/gen.go +++ b/pkg/dvcore/gen.go @@ -7,6 +7,9 @@ import ( "os" "sync" + "github.com/cayleygraph/cayley" + "github.com/cayleygraph/cayley/graph" + "github.com/cayleygraph/cayley/schema" "go.uber.org/zap" yaml "gopkg.in/yaml.v2" "moul.io/depviz/v3/pkg/dvmodel" @@ -16,10 +19,6 @@ import ( "moul.io/depviz/v3/pkg/multipmuri" "moul.io/godev" "moul.io/graphman" - - "github.com/cayleygraph/cayley" - "github.com/cayleygraph/cayley/graph" - "github.com/cayleygraph/cayley/schema" ) type GenOpts struct { @@ -57,7 +56,7 @@ func Gen(h *cayley.Handle, args []string, opts GenOpts) error { if opts.Scope != "" { scope, err = dvparser.ParseTarget(opts.Scope) if err != nil { - return fmt.Errorf("parse scope: %w", err) + return fmt.Errorf("load tasks: %w", err) } } diff --git a/pkg/dvstore/query.go b/pkg/dvstore/query.go index e6f79c734..d0a4b5c0f 100644 --- a/pkg/dvstore/query.go +++ b/pkg/dvstore/query.go @@ -6,14 +6,13 @@ import ( "sort" "time" - "go.uber.org/zap" - "moul.io/depviz/v3/pkg/dvmodel" - "moul.io/depviz/v3/pkg/multipmuri" - "github.com/cayleygraph/cayley" "github.com/cayleygraph/cayley/graph/path" "github.com/cayleygraph/cayley/schema" "github.com/cayleygraph/quad" + "go.uber.org/zap" + "moul.io/depviz/v3/pkg/dvmodel" + "moul.io/depviz/v3/pkg/multipmuri" ) func LastUpdatedIssueInRepo(ctx context.Context, h *cayley.Handle, entity multipmuri.Entity) (time.Time, error) { // nolint:interfacer diff --git a/pkg/dvstore/query_test.go b/pkg/dvstore/query_test.go index e18f9b80f..5e7a6ab09 100644 --- a/pkg/dvstore/query_test.go +++ b/pkg/dvstore/query_test.go @@ -6,13 +6,13 @@ import ( "strings" "testing" + _ "github.com/cayleygraph/quad/json" + "github.com/stretchr/testify/assert" "moul.io/depviz/v3/pkg/dvmodel" "moul.io/depviz/v3/pkg/dvparser" "moul.io/depviz/v3/pkg/multipmuri" "moul.io/depviz/v3/pkg/testutil" "moul.io/godev" - - "github.com/stretchr/testify/assert" ) func TestLoadTasks(t *testing.T) { diff --git a/pkg/dvstore/scope.go b/pkg/dvstore/scope.go index 00697b570..209245e87 100644 --- a/pkg/dvstore/scope.go +++ b/pkg/dvstore/scope.go @@ -5,13 +5,13 @@ import ( "github.com/cayleygraph/quad" ) -func generateCombinationsWithRepetition[T interface{}](n int, elements []T, currentCombination []T, combinations *[][]T) { +func genCombWithRep[T interface{}](n int, elements []T, currentCombination []T, combinations *[][]T) { if n == 0 { *combinations = append(*combinations, append([]T(nil), currentCombination...)) } else { for _, element := range elements { currentCombination = append(currentCombination, element) - generateCombinationsWithRepetition(n-1, elements, currentCombination, combinations) + genCombWithRep(n-1, elements, currentCombination, combinations) currentCombination = currentCombination[:len(currentCombination)-1] } } @@ -30,7 +30,7 @@ func scopeIssue(p *path.Path, scopeSize int, possibilities []quad.IRI) *path.Pat } var perms [][]quad.IRI var currentPerms []quad.IRI - generateCombinationsWithRepetition(scopeSize, possibilities, currentPerms, &perms) + genCombWithRep(scopeSize, possibilities, currentPerms, &perms) for _, perm := range perms { p = p.Or(fold(p, perm, func(_path *path.Path, _link quad.IRI) *path.Path { return _path.Both(_link) })) diff --git a/pkg/dvstore/scope_test.go b/pkg/dvstore/scope_test.go index adf6e8455..04de3899a 100644 --- a/pkg/dvstore/scope_test.go +++ b/pkg/dvstore/scope_test.go @@ -1,27 +1,27 @@ package dvstore import ( + "fmt" "testing" - "moul.io/depviz/v3/pkg/dvparser" - - "github.com/stretchr/testify/assert" + "github.com/Doozers/gl/pkg/funct" + "github.com/cayleygraph/quad" "golang.org/x/exp/slices" - "moul.io/depviz/v3/pkg/dvmodel" + "moul.io/depviz/v3/pkg/dvparser" "moul.io/depviz/v3/pkg/testutil" ) +type recFunc func(task dvmodel.Task, remaining uint8, target string) bool + func TestScopeIssue(t *testing.T) { tests := []struct { - target string - golden string - name string - filters dvmodel.Filters - expectedDependency []string + target string + golden string + name string + filters dvmodel.Filters }{ - { "https://github.com/moul/depviz-test/issues/6", "all-depviz-test", @@ -36,21 +36,14 @@ func TestScopeIssue(t *testing.T) { WithFetch: false, ScopeSize: 1, }, - []string{ - "", - "", - "", - "", - "", - "", - }}, + }, } logger := testutil.Logger(t) for _, testptr := range tests { test := testptr - store, close := TestingGoldenStore(t, test.golden) - defer close() + store, closeFunc := TestingGoldenStore(t, test.golden) + defer closeFunc() targetEntity, err := dvparser.ParseTarget(test.target) if err != nil { t.Fatal(err) @@ -63,8 +56,44 @@ func TestScopeIssue(t *testing.T) { return } + mtasks := map[string]dvmodel.Task{} + for _, task := range tasks { + fmt.Println("TASK: ", task.ID.String()) + mtasks[task.ID.String()] = task + } + + var rec recFunc + rec = func(_task dvmodel.Task, _remaining uint8, _target string) bool { + if _task.ID.String() == _target { + return true + } + + if _remaining == 0 { + return false + } + + if slices.Contains(funct.Map(_task.IsDependingOn, func(t quad.IRI) string { + return t.String() + }), _target) { + return true + } + for _, dep := range _task.IsDependingOn { + if t, ok := mtasks[dep.String()]; ok { + if rec(t, _remaining-1, _target) { + return true + } + } + } + return false + } + for _, task := range tasks { - assert.Equal(t, true, slices.Contains(test.expectedDependency, task.ID.String()), "unexpected dependency %q", task.ID.String()) + rec1 := rec(task, uint8(test.filters.ScopeSize), "<"+test.target+">") + rec2 := rec(mtasks["<"+test.target+">"], uint8(test.filters.ScopeSize), task.ID.String()) + + if rec1 == false && rec2 == false { + t.Errorf("task %s should be in the scope of %s", task.ID.String(), test.target) + } } } }