From 95ba7ec6683b8b3f51a1b4db3ec7159b43aaea04 Mon Sep 17 00:00:00 2001 From: Samuel Littley Date: Thu, 29 Jan 2026 16:29:20 +0000 Subject: [PATCH] Reduce the set of linters run, and fix existing findings --- .golangci.yaml | 4 +- binder.go | 10 ++- binder_test.go | 25 +++++-- example_test.go | 4 +- graph.go | 77 +++++++++++++++----- graph_test.go | 9 ++- key.go | 8 ++- reflect.go | 41 +++++++++-- task.go | 30 ++++++-- task_test.go | 128 +++++++++++++++++++++++---------- taskgraphtest/taskgraphtest.go | 30 ++++++-- util_test.go | 1 - 12 files changed, 277 insertions(+), 90 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 77b9fde..f1cda23 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,6 +1,8 @@ version: "2" linters: - default: all + default: none + enable: + - revive formatters: enable: - gci diff --git a/binder.go b/binder.go index 0f59420..eea4a4f 100644 --- a/binder.go +++ b/binder.go @@ -8,12 +8,10 @@ import ( set "github.com/deckarep/golang-set/v2" ) -var ( - // ErrDuplicateBinding is returned when Binder.Store is called with a binding whose ID has already - // been stored (which implies that the graph being executed contains multiple tasks producing - // bindings for the same Key). - ErrDuplicateBinding = errors.New("duplicate binding") -) +// ErrDuplicateBinding is returned when Binder.Store is called with a binding whose ID has already +// been stored (which implies that the graph being executed contains multiple tasks producing +// bindings for the same Key). +var ErrDuplicateBinding = errors.New("duplicate binding") // BindStatus represents the tristate of a Binding. type BindStatus int diff --git a/binder_test.go b/binder_test.go index 4a8f9e0..aabc946 100644 --- a/binder_test.go +++ b/binder_test.go @@ -7,7 +7,6 @@ import ( set "github.com/deckarep/golang-set/v2" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - tg "github.com/thought-machine/taskgraph" tgt "github.com/thought-machine/taskgraph/taskgraphtest" ) @@ -45,7 +44,11 @@ func TestBindersBindingsAndKeys(t *testing.T) { } if err := b.Store(key2.Bind(456)); !errors.Is(err, tg.ErrDuplicateBinding) { - t.Errorf("Expected b.Store(key2.Bind(456)) to return error %v; got %v", tg.ErrDuplicateBinding, err) + t.Errorf( + "Expected b.Store(key2.Bind(456)) to return error %v; got %v", + tg.ErrDuplicateBinding, + err, + ) } tgt.DiffPresent[string](t, b, key1, "foo") @@ -144,7 +147,11 @@ func TestOverlayBinder(t *testing.T) { tgt.ExpectPending[int](t, ob, key2) if err := ob.Store(key1.Bind(123)); !errors.Is(err, tg.ErrDuplicateBinding) { - t.Errorf("Expected ob.Store(key1.Bind(123)) to return error %v; got %v", tg.ErrDuplicateBinding, err) + t.Errorf( + "Expected ob.Store(key1.Bind(123)) to return error %v; got %v", + tg.ErrDuplicateBinding, + err, + ) } if err := ob.Store(key2.Bind(456)); err != nil { @@ -194,10 +201,18 @@ func TestGraphTaskBinder(t *testing.T) { }) if err := gtb.Store(key1.Bind(456)); !errors.Is(err, tg.ErrDuplicateBinding) { - t.Errorf("Expected gtb.Store(key1.Bind(456)) to return error %v; got %v", tg.ErrDuplicateBinding, err) + t.Errorf( + "Expected gtb.Store(key1.Bind(456)) to return error %v; got %v", + tg.ErrDuplicateBinding, + err, + ) } if err := gtb.Store(key2.Bind(123)); !errors.Is(err, tg.ErrDuplicateBinding) { - t.Errorf("Expected gtb.Store(key2.Bind(123)) to return error %v; got %v", tg.ErrDuplicateBinding, err) + t.Errorf( + "Expected gtb.Store(key2.Bind(123)) to return error %v; got %v", + tg.ErrDuplicateBinding, + err, + ) } } diff --git a/example_test.go b/example_test.go index d371af0..5c276d6 100644 --- a/example_test.go +++ b/example_test.go @@ -36,7 +36,9 @@ var taskIsPalindrome = tg.Reflect[bool]{ Depends: []any{keyInput, keyReversed}, }.Locate() -var graphIsPalindrome = tg.Must(tg.New("example_graph", tg.WithTasks(taskReverseInput, taskIsPalindrome))) +var graphIsPalindrome = tg.Must( + tg.New("example_graph", tg.WithTasks(taskReverseInput, taskIsPalindrome)), +) func Example() { res, err := graphIsPalindrome.Run(context.Background(), keyInput.Bind("racecar")) diff --git a/graph.go b/graph.go index 2589384..2f791c6 100644 --- a/graph.go +++ b/graph.go @@ -175,7 +175,8 @@ func (gn *graphNode) execute(ctx context.Context, rs *runState) (err error) { "task %s: mismatch between task Provides declaration and returned bindings: missing bindings [%s], got extra bindings [%s]", gn.task.Name(), strings.Join(missing, ", "), - strings.Join(extra, ", ")) + strings.Join(extra, ", "), + ) } for _, dependent := range gn.dependents { @@ -263,7 +264,8 @@ func (g *graph) Run(ctx context.Context, inputs ...Binding) (b Binder, err error if err != nil { result = "error" } - executionLatency.WithLabelValues(g.name, result).Observe(float64(time.Since(startTime) / time.Millisecond)) + executionLatency.WithLabelValues(g.name, result). + Observe(float64(time.Since(startTime) / time.Millisecond)) }() base, err := g.buildInputBinder(inputs...) if err != nil { @@ -352,7 +354,10 @@ func (g *graph) AsTask(exposeKeys ...ID) (Task, error) { } } if len(missing) > 0 { - return nil, wrapStackErrorf("exposed key(s) not bound after graph execution: %s", strings.Join(missing, ", ")) + return nil, wrapStackErrorf( + "exposed key(s) not bound after graph execution: %s", + strings.Join(missing, ", "), + ) } // The exposed keys are added to the external binder via the graphTaskBinder, so we don't return @@ -371,7 +376,10 @@ func (g *graph) Graphviz(includeInputs bool) string { for _, dep := range n.task.Depends() { if !g.allProvided.Contains(dep) { inputID := fmt.Sprintf("%s_input_%s", n.id, dep.id) - nodes = append(nodes, fmt.Sprintf(" %s [label=\"Input - %s\", shape=diamond];", inputID, dep)) + nodes = append( + nodes, + fmt.Sprintf(" %s [label=\"Input - %s\", shape=diamond];", inputID, dep), + ) edges = append(edges, fmt.Sprintf(" %s -> %s;", inputID, n.id)) } } @@ -384,8 +392,14 @@ func (g *graph) Graphviz(includeInputs bool) string { for _, dep := range n.task.Provides() { if !g.allDependencies.Contains(dep) { outputID := fmt.Sprintf("%s_output_%s", n.id, dep) - nodes = append(nodes, fmt.Sprintf(" %s [label=\"Output\", shape=diamond];", outputID)) - edges = append(edges, fmt.Sprintf(" %s -> %s [label=\"%s\"];", n.id, outputID, dep)) + nodes = append( + nodes, + fmt.Sprintf(" %s [label=\"Output\", shape=diamond];", outputID), + ) + edges = append( + edges, + fmt.Sprintf(" %s -> %s [label=\"%s\"];", n.id, outputID, dep), + ) } } } @@ -402,15 +416,17 @@ func (g *graph) Graphviz(includeInputs bool) string { return buf.String() } -type GraphOptions struct { +type graphOptions struct { tasks []Task tracer trace.Tracer } -type GraphOption func(opts *GraphOptions) error +// A GraphOption is used to configure a new Graph. +type GraphOption func(opts *graphOptions) error +// WithTasks sets the tasks which form the graph. func WithTasks(tasks ...TaskSet) GraphOption { - return func(opts *GraphOptions) error { + return func(opts *graphOptions) error { opts.tasks = taskset(tasks).Tasks() if len(opts.tasks) > taskLimit { @@ -421,8 +437,9 @@ func WithTasks(tasks ...TaskSet) GraphOption { } } +// WithTracer sets a tracer to record graph execution. func WithTracer(tracer trace.Tracer) GraphOption { - return func(opts *GraphOptions) error { + return func(opts *graphOptions) error { opts.tracer = tracer return nil @@ -433,7 +450,7 @@ func WithTracer(tracer trace.Tracer) GraphOption { // // Ideally, Graphs should be created on program startup, rather than creating them dynamically. func New(name string, opts ...GraphOption) (Graph, error) { - o := &GraphOptions{ + o := &graphOptions{ tracer: noop.NewTracerProvider().Tracer("github.com/thought-machine/taskgraph"), } @@ -458,7 +475,10 @@ func New(name string, opts ...GraphOption) (Graph, error) { var badTaskErrs error for _, t := range g.tasks { if t.Name() == "" || t.Location() == "" { - badTaskErrs = errors.Join(badTaskErrs, fmt.Errorf("tasks must have a name and location: (%s, %s)", t.Name(), t.Location())) + badTaskErrs = errors.Join( + badTaskErrs, + fmt.Errorf("tasks must have a name and location: (%s, %s)", t.Name(), t.Location()), + ) } node := &graphNode{ id: sanitizeTaskName(t.Name()), @@ -477,7 +497,10 @@ func New(name string, opts ...GraphOption) (Graph, error) { g.allProvided.Append(t.Provides()...) for _, id := range t.Provides() { - provideTasks[id.String()] = append(provideTasks[id.String()], fmt.Sprintf("%s - %s", t.Name(), t.Location())) + provideTasks[id.String()] = append( + provideTasks[id.String()], + fmt.Sprintf("%s - %s", t.Name(), t.Location()), + ) } } if badTaskErrs != nil { @@ -486,20 +509,34 @@ func New(name string, opts ...GraphOption) (Graph, error) { var duplicateTaskNames []string for name, locations := range taskLocations { if len(locations) > 1 { - duplicateTaskNames = append(duplicateTaskNames, fmt.Sprintf("%s (%s)", name, strings.Join(locations, ", "))) + duplicateTaskNames = append( + duplicateTaskNames, + fmt.Sprintf("%s (%s)", name, strings.Join(locations, ", ")), + ) } } if len(duplicateTaskNames) > 0 { - return nil, wrapStackErrorf("%w: %s", ErrDuplicateTaskNames, strings.Join(duplicateTaskNames, ", ")) + return nil, wrapStackErrorf( + "%w: %s", + ErrDuplicateTaskNames, + strings.Join(duplicateTaskNames, ", "), + ) } var duplicateProvides []string for id, tasks := range provideTasks { if len(tasks) > 1 { - duplicateProvides = append(duplicateProvides, fmt.Sprintf("%s (%s)", id, strings.Join(tasks, ", "))) + duplicateProvides = append( + duplicateProvides, + fmt.Sprintf("%s (%s)", id, strings.Join(tasks, ", ")), + ) } } if len(duplicateProvides) > 0 { - return nil, wrapStackErrorf("%w: %s", ErrDuplicateProvidedKeys, strings.Join(duplicateProvides, ", ")) + return nil, wrapStackErrorf( + "%w: %s", + ErrDuplicateProvidedKeys, + strings.Join(duplicateProvides, ", "), + ) } for _, node := range g.nodes { @@ -543,7 +580,11 @@ func sanitizeTaskName(name string) string { func checkCycle(node *graphNode, path []string) error { for i := len(path) - 1; i >= 0; i-- { if path[i] == node.task.Name() { - return wrapStackErrorf("%w: %s", ErrGraphCycle, strings.Join(append(path[i:], path[i]), " -> ")) + return wrapStackErrorf( + "%w: %s", + ErrGraphCycle, + strings.Join(append(path[i:], path[i]), " -> "), + ) } } path = append(path, node.task.Name()) diff --git a/graph_test.go b/graph_test.go index fe5d47c..b31d696 100644 --- a/graph_test.go +++ b/graph_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/google/go-cmp/cmp" - tg "github.com/thought-machine/taskgraph" tgt "github.com/thought-machine/taskgraph/taskgraphtest" ) @@ -172,7 +171,13 @@ func TestGraphErrors(t *testing.T) { for i := 0; i <= 1000; i++ { tasks = append(tasks, tg.NewTask("task", tgt.DummyTaskFunc(), nil, nil)) } - if _, err := tg.New("test_graph", tg.WithTasks(tasks...)); !errors.Is(err, tg.ErrTooManyTasks) { + if _, err := tg.New( + "test_graph", + tg.WithTasks(tasks...), + ); !errors.Is( + err, + tg.ErrTooManyTasks, + ) { t.Errorf("expected error %v; got %v", tg.ErrTooManyTasks, err) } }) diff --git a/key.go b/key.go index 7ffa435..9a8146e 100644 --- a/key.go +++ b/key.go @@ -82,7 +82,13 @@ func (k *key[T]) Get(b Binder) (T, error) { typed, ok := binding.Value().(T) if !ok { var want T - return empty, wrapStackErrorf("cannot get key %q: %w (got %T, want %T)", k.id, ErrWrongType, binding.Value(), want) + return empty, wrapStackErrorf( + "cannot get key %q: %w (got %T, want %T)", + k.id, + ErrWrongType, + binding.Value(), + want, + ) } return typed, nil default: diff --git a/reflect.go b/reflect.go index ab39eeb..f565064 100644 --- a/reflect.go +++ b/reflect.go @@ -42,7 +42,10 @@ func (rk *reflectKey) Get(b Binder) (reflect.Value, error) { if !outs[1].IsNil() { err, ok := outs[1].Interface().(error) if !ok { - return reflect.Value{}, wrapStackErrorf("could not convert output 1 to error; got %T", outs[1].Interface()) + return reflect.Value{}, wrapStackErrorf( + "could not convert output 1 to error; got %T", + outs[1].Interface(), + ) } return reflect.Value{}, err } @@ -163,14 +166,21 @@ func newReflectFn(fn any, resultType reflect.Type, deps ...any) (rf *reflectFn, if !outs[1].IsNil() { err, ok := outs[1].Interface().(error) if !ok { - return nil, wrapStackErrorf("could not convert function output 1 to error; got %T", outs[1].Interface()) + return nil, wrapStackErrorf( + "could not convert function output 1 to error; got %T", + outs[1].Interface(), + ) } return nil, err } return outs[0].Interface(), nil } } else { - return nil, wrapStackErrorf("function should return %s or (%s, error)", resultType, resultType) + return nil, wrapStackErrorf( + "function should return %s or (%s, error)", + resultType, + resultType, + ) } hasContext := fnType.NumIn() > 0 && fnType.In(0).Implements(contextType) @@ -181,7 +191,11 @@ func newReflectFn(fn any, resultType reflect.Type, deps ...any) (rf *reflectFn, offset++ } if argCount != len(deps) { - return nil, wrapStackErrorf("function takes %d arguments (excluding any initial context), but %d deps were provided", argCount, len(deps)) + return nil, wrapStackErrorf( + "function takes %d arguments (excluding any initial context), but %d deps were provided", + argCount, + len(deps), + ) } var keys []*reflectKey @@ -192,7 +206,12 @@ func newReflectFn(fn any, resultType reflect.Type, deps ...any) (rf *reflectFn, return nil, wrapStackErrorf("dependency %d: %w", i, err) } if !rk.valueType.AssignableTo(fnType.In(i + offset)) { - return nil, wrapStackErrorf("dependency %d is Key[%v]; want Key[%v]", i, rk.valueType, fnType.In(i+offset)) + return nil, wrapStackErrorf( + "dependency %d is Key[%v]; want Key[%v]", + i, + rk.valueType, + fnType.In(i+offset), + ) } keys = append(keys, rk) id, err := rk.ID() @@ -272,7 +291,11 @@ func (r Reflect[T]) Build() (Task, error) { } typed, ok := res.(T) if !ok { - return nil, wrapStackErrorf("%s: could not convert function result to T; got %T", r.errorPrefix(), res) + return nil, wrapStackErrorf( + "%s: could not convert function result to T; got %T", + r.errorPrefix(), + res, + ) } return []Binding{r.ResultKey.Bind(typed)}, nil }, @@ -341,7 +364,11 @@ func (r ReflectMulti) Build() (Task, error) { } typed, ok := res.([]Binding) if !ok { - return nil, wrapStackErrorf("%s: could not convert function result to []Binding; got %T", r.errorPrefix(), res) + return nil, wrapStackErrorf( + "%s: could not convert function result to []Binding; got %T", + r.errorPrefix(), + res, + ) } return typed, nil }, diff --git a/task.go b/task.go index f866af6..7ef3502 100644 --- a/task.go +++ b/task.go @@ -81,7 +81,11 @@ func (t *task) Location() string { } // NewTask builds a task with any number of inputs and outputs. -func NewTask(name string, fn func(context.Context, Binder) ([]Binding, error), depends, provides []ID) Task { +func NewTask( + name string, + fn func(context.Context, Binder) ([]Binding, error), + depends, provides []ID, +) Task { return &task{ name: name, depends: depends, @@ -104,7 +108,12 @@ func NoOutputTask(name string, fn func(ctx context.Context, b Binder) error, dep } // SimpleTask builds a task which produces a single output binding. -func SimpleTask[T any](name string, key Key[T], fn func(ctx context.Context, b Binder) (T, error), depends ...ID) Task { +func SimpleTask[T any]( + name string, + key Key[T], + fn func(ctx context.Context, b Binder) (T, error), + depends ...ID, +) Task { return &task{ name: name, depends: depends, @@ -121,7 +130,12 @@ func SimpleTask[T any](name string, key Key[T], fn func(ctx context.Context, b B } // SimpleTask1 builds a task from a function taking a single argument and returning a single value plus an error. -func SimpleTask1[A1, Res any](name string, resKey Key[Res], fn func(ctx context.Context, arg1 A1) (Res, error), depKey1 ReadOnlyKey[A1]) Task { +func SimpleTask1[A1, Res any]( + name string, + resKey Key[Res], + fn func(ctx context.Context, arg1 A1) (Res, error), + depKey1 ReadOnlyKey[A1], +) Task { return &task{ name: name, depends: []ID{depKey1.ID()}, @@ -142,7 +156,13 @@ func SimpleTask1[A1, Res any](name string, resKey Key[Res], fn func(ctx context. } // SimpleTask2 builds a task from a function taking two arguments and returning a single value plus an error. -func SimpleTask2[A1, A2, Res any](name string, resKey Key[Res], fn func(ctx context.Context, arg1 A1, arg2 A2) (Res, error), depKey1 ReadOnlyKey[A1], depKey2 ReadOnlyKey[A2]) Task { +func SimpleTask2[A1, A2, Res any]( + name string, + resKey Key[Res], + fn func(ctx context.Context, arg1 A1, arg2 A2) (Res, error), + depKey1 ReadOnlyKey[A1], + depKey2 ReadOnlyKey[A2], +) Task { return &task{ name: name, depends: []ID{depKey1.ID(), depKey2.ID()}, @@ -298,7 +318,7 @@ func AllBound(name string, result Key[bool], deps ...ID) Task { name: name, depends: deps, provides: []ID{result.ID()}, - fn: func(ctx context.Context, b Binder) ([]Binding, error) { + fn: func(_ context.Context, _ Binder) ([]Binding, error) { return []Binding{result.Bind(true)}, nil }, location: getLocation(), diff --git a/task_test.go b/task_test.go index 07a12ee..7184f6e 100644 --- a/task_test.go +++ b/task_test.go @@ -21,15 +21,20 @@ func TestTasks(t *testing.T) { Tests: []tgt.Test{ { Description: "NewTask", - Task: tg.NewTask("task", func(_ context.Context, b tg.Binder) ([]tg.Binding, error) { - val, err := key1.Get(b) - if err != nil { - return nil, err - } - return []tg.Binding{ - key2.Bind(val + val), - }, nil - }, []tg.ID{key1.ID()}, []tg.ID{key2.ID()}), + Task: tg.NewTask( + "task", + func(_ context.Context, b tg.Binder) ([]tg.Binding, error) { + val, err := key1.Get(b) + if err != nil { + return nil, err + } + return []tg.Binding{ + key2.Bind(val + val), + }, nil + }, + []tg.ID{key1.ID()}, + []tg.ID{key2.ID()}, + ), Inputs: []tg.Binding{ key1.Bind("bar"), }, @@ -40,9 +45,14 @@ func TestTasks(t *testing.T) { }, { Description: "NewTask with error", - Task: tg.NewTask("task", func(_ context.Context, _ tg.Binder) ([]tg.Binding, error) { - return nil, sentinelError - }, []tg.ID{key1.ID()}, []tg.ID{key2.ID()}), + Task: tg.NewTask( + "task", + func(_ context.Context, _ tg.Binder) ([]tg.Binding, error) { + return nil, sentinelError + }, + []tg.ID{key1.ID()}, + []tg.ID{key2.ID()}, + ), Inputs: []tg.Binding{ key1.Bind("bar"), }, @@ -71,9 +81,14 @@ func TestTasks(t *testing.T) { }, { Description: "SimpleTask", - Task: tg.SimpleTask("task", key2, func(_ context.Context, b tg.Binder) (string, error) { - return key1.Get(b) - }, key1.ID()), + Task: tg.SimpleTask( + "task", + key2, + func(_ context.Context, b tg.Binder) (string, error) { + return key1.Get(b) + }, + key1.ID(), + ), Inputs: []tg.Binding{ key1.Bind("bar"), }, @@ -84,9 +99,14 @@ func TestTasks(t *testing.T) { }, { Description: "SimpleTask with error", - Task: tg.SimpleTask("task", key2, func(_ context.Context, b tg.Binder) (string, error) { - return "", sentinelError - }, key1.ID()), + Task: tg.SimpleTask( + "task", + key2, + func(_ context.Context, _ tg.Binder) (string, error) { + return "", sentinelError + }, + key1.ID(), + ), Inputs: []tg.Binding{ key1.Bind("bar"), }, @@ -94,9 +114,14 @@ func TestTasks(t *testing.T) { }, { Description: "SimpleTask1", - Task: tg.SimpleTask1[string, string]("task", key2, func(_ context.Context, arg1 string) (string, error) { - return arg1 + arg1, nil - }, key1), + Task: tg.SimpleTask1[string, string]( + "task", + key2, + func(_ context.Context, arg1 string) (string, error) { + return arg1 + arg1, nil + }, + key1, + ), Inputs: []tg.Binding{ key1.Bind("bar"), }, @@ -107,9 +132,14 @@ func TestTasks(t *testing.T) { }, { Description: "SimpleTask1 with error", - Task: tg.SimpleTask1[string, string]("task", key2, func(_ context.Context, arg1 string) (string, error) { - return "", sentinelError - }, key1), + Task: tg.SimpleTask1[string, string]( + "task", + key2, + func(_ context.Context, _ string) (string, error) { + return "", sentinelError + }, + key1, + ), Inputs: []tg.Binding{ key1.Bind("bar"), }, @@ -117,9 +147,15 @@ func TestTasks(t *testing.T) { }, { Description: "SimpleTask2", - Task: tg.SimpleTask2[string, string, string]("task", key3, func(_ context.Context, arg1, arg2 string) (string, error) { - return arg1 + arg2, nil - }, key1, key2), + Task: tg.SimpleTask2[string, string, string]( + "task", + key3, + func(_ context.Context, arg1, arg2 string) (string, error) { + return arg1 + arg2, nil + }, + key1, + key2, + ), Inputs: []tg.Binding{ key1.Bind("foo"), key2.Bind("bar"), @@ -131,9 +167,15 @@ func TestTasks(t *testing.T) { }, { Description: "SimpleTask2 with error", - Task: tg.SimpleTask2[string, string, string]("task", key3, func(_ context.Context, arg1, arg2 string) (string, error) { - return "", sentinelError - }, key1, key2), + Task: tg.SimpleTask2[string, string, string]( + "task", + key3, + func(_ context.Context, _, _ string) (string, error) { + return "", sentinelError + }, + key1, + key2, + ), Inputs: []tg.Binding{ key1.Bind("foo"), key2.Bind("bar"), @@ -144,9 +186,14 @@ func TestTasks(t *testing.T) { Description: "Conditional, condition met", Task: tg.Conditional{ NamePrefix: "cond_", - Wrapped: tg.SimpleTask1[string, string]("task", key2, func(_ context.Context, arg1 string) (string, error) { - return arg1 + arg1, nil - }, key1), + Wrapped: tg.SimpleTask1[string, string]( + "task", + key2, + func(_ context.Context, arg1 string) (string, error) { + return arg1 + arg1, nil + }, + key1, + ), Condition: tg.ConditionAnd{boolKey}, }.Locate(), Inputs: []tg.Binding{ @@ -162,9 +209,14 @@ func TestTasks(t *testing.T) { Description: "Conditional, condition not met", Task: tg.Conditional{ NamePrefix: "cond_", - Wrapped: tg.SimpleTask1[string, string]("task", key2, func(_ context.Context, arg1 string) (string, error) { - return arg1 + arg1, nil - }, key1), + Wrapped: tg.SimpleTask1[string, string]( + "task", + key2, + func(_ context.Context, arg1 string) (string, error) { + return arg1 + arg1, nil + }, + key1, + ), Condition: tg.ConditionOr{boolKey}, }.Locate(), Inputs: []tg.Binding{ @@ -219,7 +271,7 @@ func TestTasks(t *testing.T) { Task: tgt.Must[tg.Task](t)(tg.Reflect[string]{ Name: "task", ResultKey: key3, - Fn: func(arg1, arg2 string) (string, error) { + Fn: func(_, _ string) (string, error) { return "", sentinelError }, Depends: []any{key1, key2}, @@ -278,7 +330,7 @@ func TestTasks(t *testing.T) { Description: "ReflectMulti with error", Task: tgt.Must[tg.Task](t)(tg.ReflectMulti{ Name: "task", - Fn: func(arg1 string) ([]tg.Binding, error) { + Fn: func(_ string) ([]tg.Binding, error) { return nil, sentinelError }, Provides: []tg.ID{key2.ID(), key3.ID()}, diff --git a/taskgraphtest/taskgraphtest.go b/taskgraphtest/taskgraphtest.go index f73e84d..b783131 100644 --- a/taskgraphtest/taskgraphtest.go +++ b/taskgraphtest/taskgraphtest.go @@ -13,7 +13,6 @@ import ( set "github.com/deckarep/golang-set/v2" "github.com/google/go-cmp/cmp" - tg "github.com/thought-machine/taskgraph" ) @@ -34,7 +33,13 @@ func TransformMaybe[T any]() cmp.Option { } // ExpectPresent asserts that b contains key bound to want. -func ExpectPresent[T any](t *testing.T, b tg.Binder, key tg.ReadOnlyKey[T], want T, opts ...cmp.Option) { +func ExpectPresent[T any]( + t *testing.T, + b tg.Binder, + key tg.ReadOnlyKey[T], + want T, + opts ...cmp.Option, +) { t.Helper() // Use key.Get so that this works with virtual keys like tg.Presence(). @@ -50,7 +55,13 @@ func ExpectPresent[T any](t *testing.T, b tg.Binder, key tg.ReadOnlyKey[T], want // DiffPresent asserts that b contains key bound to want, and produces a diff if the value is not // correct. -func DiffPresent[T any](t *testing.T, b tg.Binder, key tg.ReadOnlyKey[T], want T, opts ...cmp.Option) { +func DiffPresent[T any]( + t *testing.T, + b tg.Binder, + key tg.ReadOnlyKey[T], + want T, + opts ...cmp.Option, +) { t.Helper() // Use key.Get so that this works with virtual keys like tg.Presence(). @@ -145,7 +156,12 @@ func MatchDiff(want tg.Binding, opts ...cmp.Option) BindingMatcher { func MatchFunc[T any](want tg.Binding, compareFn func(got, want T) error) BindingMatcher { return bindingMatcher{want.ID(), func(got tg.Binding) error { if got.Status() != want.Status() { - err := fmt.Errorf("difference in binding %s status: got %s; want %s", want.ID(), got.Status(), want.Status()) + err := fmt.Errorf( + "difference in binding %s status: got %s; want %s", + want.ID(), + got.Status(), + want.Status(), + ) if got.Status() == tg.Absent { err = fmt.Errorf("%w - absent binding error: %w", err, got.Error()) } @@ -168,7 +184,11 @@ func MatchFunc[T any](want tg.Binding, compareFn func(got, want T) error) Bindin } case tg.Absent: if !errors.Is(got.Error(), want.Error()) { - return fmt.Errorf("difference in binding error: got %v; want %v", got.Error(), want.Error()) + return fmt.Errorf( + "difference in binding error: got %v; want %v", + got.Error(), + want.Error(), + ) } } return nil diff --git a/util_test.go b/util_test.go index 14d027b..1a04a71 100644 --- a/util_test.go +++ b/util_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/stretchr/testify/assert" - tg "github.com/thought-machine/taskgraph" )