Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 33 additions & 19 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,27 @@ linters:
- noctx # Finds sending http request without context.Context
- prealloc # Temporarily disable until slice allocation issues are fixed
enable:
- bodyclose # Checks HTTP response body is closed
- contextcheck # Check whether the function uses a non-inherited context
- dupl # Find duplicate code
- dupword # Find duplicate words in comments and strings
- errcheck
- errorlint # Check error handling
- misspell # Find commonly misspelled English words
- unconvert # Remove unnecessary type conversions
- reassign # Checks that package variables are not reassigned
- tagalign # Check that struct tags are well aligned
- nilerr # Finds code that returns nil even if it checks that the error is not nil
- nolintlint # Checks for invalid or missing nolint directives
- whitespace # Check for unnecessary whitespace
- thelper # Detects test helpers which should start with t.Helper()
- govet # Examines Go source code and reports suspicious constructs
- ineffassign # Detects when assignments to existing variables are not used
- staticcheck # Staticcheck is a go linter
- unused # Checks for unused code
- bodyclose # Ensure HTTP response bodies are closed
- contextcheck # Ensure functions use a non-inherited context
- dupl # Detect duplicate code
- dupword # Detect duplicate words in comments/strings
- errcheck # Check for unchecked errors
- errorlint # Enforce idiomatic error handling
- govet # Report suspicious constructs
- ineffassign # Detect unused variable assignments
- misspell # Detect misspelled English words
- nilerr # Detect returning nil after error checks
- nolintlint # Check for invalid/missing nolint directives
- reassign # Prevent package variable reassignment
- staticcheck # Advanced static analysis
- tagalign # Check struct tag alignment
- tagliatelle # Enforce struct tag formatting
- testifylint # Avoid common testify mistakes
- thelper # Ensure test helpers use t.Helper()
- unconvert # Remove unnecessary type conversions
- usetesting # Detects when some calls can be replaced by methods from the testing package
- unused # Detect unused code
- whitespace # Detect unnecessary whitespace
settings:
errcheck:
check-blank: true
Expand All @@ -41,14 +44,25 @@ linters:
errorf: true
asserts: true
comparison: true
tagalign:
strict: true
order:
- json
- toml
- yaml
- xml
- env_interpolation
usetesting:
os-temp-dir: true
context-background: true
context-todo: true

formatters:
enable:
- gci
- gofmt
- goimports
- gofumpt
- golines

issues:
max-issues-per-linter: 20
Expand Down
11 changes: 0 additions & 11 deletions engines/extism/adapters/sdkAdapters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,6 @@ func TestInterfaceImplementation(t *testing.T) {
// For the sdkCompiledPluginAdapter and sdkPluginAdapter implementations, we rely on
// the Extism SDK's types, so we don't need exhaustive tests for this wrapper code.

func TestAdapterCorrectlyImplementsInterfaces(t *testing.T) {
// These tests verify that the methods of the interfaces correctly match
// the methods of the SDK types. If there's a mismatch, Go won't compile.
//
// We don't need to test the implementation since it's just directly
// calling the SDK's methods. We're just verifying the types at compile time.

// Implicitly test this with the interface check above
assert.True(t, true, "Adapters correctly implement their interfaces")
}

func TestNilPlugin(t *testing.T) {
// Test that NewCompiledPluginAdapter returns nil when given a nil plugin
adapter := NewCompiledPluginAdapter(nil)
Expand Down
10 changes: 5 additions & 5 deletions engines/extism/compiler/internal/compile/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ func testFunctions(t *testing.T, instance adapters.PluginInstance) {
assertFunc: func(t *testing.T, output []byte) {
t.Helper()
var result struct {
RequestID string `json:"request_id"`
ProcessedAt string `json:"processed_at"`
RequestID string `json:"requestId"`
ProcessedAt string `json:"processedAt"`
Results map[string]any `json:"results"`
TagCount int `json:"tag_count"`
MetaCount int `json:"meta_count"`
IsActive bool `json:"is_active"`
TagCount int `json:"tagCount"`
MetaCount int `json:"metaCount"`
IsActive bool `json:"isActive"`
Summary string `json:"summary"`
}
require.NoError(t, json.Unmarshal(output, &result))
Expand Down
4 changes: 2 additions & 2 deletions engines/extism/compiler/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestCompilerOptions_Options(t *testing.T) {

t.Run("empty value", func(t *testing.T) {
c := &Compiler{entryPointName: ""}
require.Equal(t, "", c.GetEntryPointName())
require.Empty(t, c.GetEntryPointName())
})

t.Run("with defaults", func(t *testing.T) {
Expand Down Expand Up @@ -617,7 +617,7 @@ func TestCompilerOptions(t *testing.T) {
c2 := &Compiler{
entryPointName: "",
}
require.Equal(t, "", c2.GetEntryPointName())
require.Empty(t, c2.GetEntryPointName())
})
})

Expand Down
12 changes: 5 additions & 7 deletions engines/extism/evaluator/evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func TestEvaluator_Evaluate(t *testing.T) {
require.Contains(t, resultMap, "result")
require.Equal(t, "success", resultMap["result"])
require.Contains(t, resultMap, "value")
require.Equal(t, float64(42), resultMap["value"])
require.InDelta(t, float64(42), resultMap["value"], 0.0001)
})

// Test successful string response
Expand Down Expand Up @@ -398,8 +398,7 @@ func TestEvaluator_Evaluate(t *testing.T) {
// Call Eval, which should be cancelled during execution
result, err := evaluator.Eval(ctx)

// Should get a cancellation error
assert.Error(t, err)
require.Error(t, err, "Expected cancellation error")
assert.Nil(t, result)
assert.Contains(t, err.Error(), "execution")

Expand Down Expand Up @@ -588,19 +587,18 @@ func TestEvaluator_Evaluate(t *testing.T) {
"Expected the mock instance to be called",
)

// Check for expected errors
if tt.wantErr {
assert.Error(t, err)
require.Error(t, err)
if tt.errContains != "" {
assert.Contains(t, err.Error(), tt.errContains)
}
} else {
assert.NoError(t, err)
require.NoError(t, err)
assert.NotNil(t, result)
}

// Execution time should always be measured
assert.Greater(t, execTime.Nanoseconds(), int64(0))
assert.Positive(t, execTime.Nanoseconds())
})
}
})
Expand Down
2 changes: 1 addition & 1 deletion engines/extism/internal/converters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestConvertToExtismFormat(t *testing.T) {
// Handle type conversions that happen during JSON marshaling
if intVal, isInt := expectedVal.(int); isInt {
// JSON unmarshaling converts numbers to float64
assert.Equal(t, float64(intVal), checkData[k])
assert.InDelta(t, float64(intVal), checkData[k], 0.0001)
} else if _, isIntSlice := expectedVal.([]int); isIntSlice {
// Skip int slice checks (arrays become []any)
} else if _, isSlice := expectedVal.([]any); !isSlice {
Expand Down
14 changes: 7 additions & 7 deletions engines/extism/internal/jsonHelpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ func TestFixJSONNumberTypes(t *testing.T) {
assert.True(t, ok, "Result should be a map")

// Check that the values were converted to float64
assert.Equal(t, float64(19.99), mapResult["price"])
assert.Equal(t, float64(4.5), mapResult["rating"])
assert.Equal(t, float64(75.5), mapResult["percentage"])
assert.InDelta(t, float64(19.99), mapResult["price"], 0.0001)
assert.InDelta(t, float64(4.5), mapResult["rating"], 0.0001)
assert.InDelta(t, float64(75.5), mapResult["percentage"], 0.0001)
assert.IsType(t, float64(0), mapResult["price"])
assert.IsType(t, float64(0), mapResult["rating"])
assert.IsType(t, float64(0), mapResult["percentage"])
Expand Down Expand Up @@ -113,7 +113,7 @@ func TestFixJSONNumberTypes(t *testing.T) {
stats, ok := user["stats"].(map[string]any)
assert.True(t, ok, "stats should be a map")
assert.Equal(t, int(42), stats["login_count"])
assert.Equal(t, float64(95.5), stats["score"])
assert.InDelta(t, float64(95.5), stats["score"], 0.0001)
})

t.Run("handles slices", func(t *testing.T) {
Expand Down Expand Up @@ -142,7 +142,7 @@ func TestFixJSONNumberTypes(t *testing.T) {
itemMap, ok := sliceResult[3].(map[string]any)
assert.True(t, ok, "Item at index 3 should be a map")
assert.Equal(t, int(123), itemMap["item_id"])
assert.Equal(t, float64(9.99), itemMap["price"])
assert.InDelta(t, float64(9.99), itemMap["price"], 0.0001)
})

t.Run("handles nested slices", func(t *testing.T) {
Expand Down Expand Up @@ -177,13 +177,13 @@ func TestFixJSONNumberTypes(t *testing.T) {
product1, ok := products[0].(map[string]any)
assert.True(t, ok, "First product should be a map")
assert.Equal(t, int(1), product1["product_id"])
assert.Equal(t, float64(19.99), product1["price"])
assert.InDelta(t, float64(19.99), product1["price"], 0.0001)

// Check second product
product2, ok := products[1].(map[string]any)
assert.True(t, ok, "Second product should be a map")
assert.Equal(t, int(2), product2["product_id"])
assert.Equal(t, float64(29.99), product2["price"])
assert.InDelta(t, float64(29.99), product2["price"], 0.0001)
})

t.Run("handles invalid numbers gracefully", func(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions engines/extism/wasmdata/examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ type Request struct {

// Response represents a complex output object
type Response struct {
RequestID string `json:"request_id"`
ProcessedAt string `json:"processed_at"`
RequestID string `json:"requestId"`
ProcessedAt string `json:"processedAt"`
Results map[string]any `json:"results"`
TagCount int `json:"tag_count"`
MetaCount int `json:"meta_count"`
IsActive bool `json:"is_active"`
TagCount int `json:"tagCount"`
MetaCount int `json:"metaCount"`
IsActive bool `json:"isActive"`
Summary string `json:"summary"`
}

Expand Down
12 changes: 6 additions & 6 deletions engines/extism/wasmdata/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ func TestExtismWasmIntegration(t *testing.T) {
err = json.Unmarshal(output, &response)
require.NoError(t, err, "Failed to parse complex response")

assert.Equal(t, "test-123", response["request_id"])
assert.NotEmpty(t, response["processed_at"])
assert.Equal(t, float64(3), response["tag_count"]) // JSON numbers are float64
assert.Equal(t, float64(3), response["meta_count"])
assert.Equal(t, "test-123", response["requestId"])
assert.NotEmpty(t, response["processedAt"])
assert.InDelta(t, float64(3), response["tagCount"], 0.0001) // JSON numbers are float64
assert.InDelta(t, float64(3), response["metaCount"], 0.0001)
assert.Contains(t, response["summary"], "test-123")
})

Expand Down Expand Up @@ -245,7 +245,7 @@ func TestExtismWasmIntegration(t *testing.T) {
require.NoError(t, err, "Failed to parse vowel result")

assert.Equal(t, "Hello World", vowelResult["input"])
assert.Equal(t, float64(3), vowelResult["count"]) // 3 vowels in "Hello World"
assert.InDelta(t, float64(3), vowelResult["count"], 0.0001) // 3 vowels in "Hello World"
})

t.Run("reverse_string function", func(t *testing.T) {
Expand Down Expand Up @@ -312,7 +312,7 @@ func TestExtismWasmIntegration(t *testing.T) {
require.NoError(t, err, "Failed to parse vowel result")

assert.Equal(t, "Hello World", vowelResult["input"])
assert.Equal(t, float64(3), vowelResult["count"]) // 3 vowels in "Hello World"
assert.InDelta(t, float64(3), vowelResult["count"], 0.0001) // 3 vowels in "Hello World"
})

t.Run("reverse_string_namespaced function", func(t *testing.T) {
Expand Down
Binary file modified engines/extism/wasmdata/main.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion engines/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ _ = result
// The greet function returns {"greeting": "Hello, <input>!"}
greeting, exists := resultMap["greeting"]
require.True(t, exists)
assert.True(t, strings.Contains(greeting.(string), "World"))
assert.Contains(t, greeting.(string), "World")
})
}

Expand Down
6 changes: 3 additions & 3 deletions engines/risor/compiler/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ main()
execContent, err := comp.Compile(reader)
require.Error(t, err, "Expected an error but got none")
require.Nil(t, execContent, "Expected execContent to be nil")
require.True(t, errors.Is(err, tt.err), "Expected error %v, got %v", tt.err, err)
require.ErrorIs(t, err, tt.err, "Expected error %v, got %v", tt.err, err)

// Verify mock expectations
if mockReader, ok := reader.(*mockScriptReaderCloser); ok {
Expand All @@ -238,7 +238,7 @@ main()
execContent, err := comp.Compile(nil)
require.Error(t, err, "Expected an error but got none")
require.Nil(t, execContent, "Expected execContent to be nil")
require.True(t, errors.Is(err, ErrContentNil), "Expected error to be ErrContentNil")
require.ErrorIs(t, err, ErrContentNil, "Expected error to be ErrContentNil")
})

t.Run("io error", func(t *testing.T) {
Expand Down Expand Up @@ -395,7 +395,7 @@ func TestCompileError(t *testing.T) {
execContent, err := comp.Compile(nil)
require.Error(t, err, "Expected an error but got none")
require.Nil(t, execContent, "Expected execContent to be nil")
require.True(t, errors.Is(err, ErrContentNil), "Expected error to be ErrContentNil")
require.ErrorIs(t, err, ErrContentNil, "Expected error to be ErrContentNil")
}

func TestCompileWithBytecode(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions engines/starlark/compiler/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ main()
execContent, err := comp.Compile(reader)
require.Error(t, err, "Expected an error but got none")
require.Nil(t, execContent, "Expected execContent to be nil")
require.True(t, errors.Is(err, tt.err), "Expected error %v, got %v", tt.err, err)
require.ErrorIs(t, err, tt.err, "Expected error %v, got %v", tt.err, err)

// Verify mock expectations
if mockReader, ok := reader.(*mockScriptReaderCloser); ok {
Expand All @@ -245,7 +245,7 @@ main()
execContent, err := comp.Compile(nil)
require.Error(t, err, "Expected an error but got none")
require.Nil(t, execContent, "Expected execContent to be nil")
require.True(t, errors.Is(err, ErrContentNil), "Expected error to be ErrContentNil")
require.ErrorIs(t, err, ErrContentNil, "Expected error to be ErrContentNil")
})

t.Run("io error", func(t *testing.T) {
Expand Down Expand Up @@ -398,7 +398,7 @@ func TestCompileError(t *testing.T) {
execContent, err := comp.Compile(nil)
require.Error(t, err, "Expected an error but got none")
require.Nil(t, execContent, "Expected execContent to be nil")
require.True(t, errors.Is(err, ErrContentNil), "Expected error to be ErrContentNil")
require.ErrorIs(t, err, ErrContentNil, "Expected error to be ErrContentNil")
}

func TestCompileIOError(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion engines/starlark/internal/converters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func TestConvertToStarlarkFormat(t *testing.T) {
}

require.NoError(t, err)
require.Equal(t, len(tt.expected), len(result))
require.Len(t, result, len(tt.expected))

// Get ctx value and verify it's a dict
ctxVal, ok := result[constants.Ctx].(*starlarkLib.Dict)
Expand Down
6 changes: 3 additions & 3 deletions examples/data-prep/extism/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestPrepareRuntimeData(t *testing.T) {
// Test prepareRuntimeData function
ctx := t.Context()
enrichedCtx, err := prepareRuntimeData(ctx, logger, evaluator)
assert.NoError(t, err, "prepareRuntimeData should not return an error")
require.NoError(t, err, "prepareRuntimeData should not return an error")
assert.NotNil(t, enrichedCtx, "Enriched context should not be nil")
}

Expand All @@ -95,7 +95,7 @@ func TestEvalAndExtractResult(t *testing.T) {

// Test evaluation
result, err := evalAndExtractResult(ctx, logger, evaluator)
assert.NoError(t, err, "evalAndExtractResult should not return an error")
require.NoError(t, err, "evalAndExtractResult should not return an error")
assert.NotNil(t, result, "Result should not be nil")
}

Expand All @@ -110,7 +110,7 @@ func TestFromExtismFileWithData(t *testing.T) {
slog.Default().Handler(),
wasmdata.EntrypointGreet,
)
assert.NoError(t, err, "Should create evaluator without error")
require.NoError(t, err, "Should create evaluator without error")
assert.NotNil(t, evaluator, "Evaluator should not be nil")
}

Expand Down
4 changes: 2 additions & 2 deletions examples/data-prep/risor/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestPrepareRuntimeData(t *testing.T) {
// Test prepareRuntimeData function
ctx := t.Context()
enrichedCtx, err := prepareRuntimeData(ctx, logger, evaluator)
assert.NoError(t, err, "prepareRuntimeData should not return an error")
require.NoError(t, err, "prepareRuntimeData should not return an error")
assert.NotNil(t, enrichedCtx, "Enriched context should not be nil")
}

Expand All @@ -76,7 +76,7 @@ func TestEvalAndExtractResult(t *testing.T) {

// Test evaluation
result, err := evalAndExtractResult(preparedCtx, logger, evaluator)
assert.NoError(t, err, "evalAndExtractResult should not return an error")
require.NoError(t, err, "evalAndExtractResult should not return an error")
assert.NotNil(t, result, "Result should not be nil")

// Check basic result fields
Expand Down
Loading