Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

laya-go: hookrun refuses a value that is not equal to itself; floor 3868 -> 3869

Adeshina Lasisib5ae1687b3b1
diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
index e4452bf5..1f570c88 100644
--- a/.github/workflows/go.yml
+++ b/.github/workflows/go.yml
@@ -128,11 +128,11 @@ jobs:
LAYA_GO_FIXTURES: ${{ github.workspace }}/.go-goldens
LAYA_CHECKPOINTS: ${{ github.workspace }}/laya-java/.work/checkpoints
run: go test -race -count=1 -json ./... > "$RUNNER_TEMP/go-test.json"
- # Exactly the measured count (3868 tests and subtests, on both Go versions): dropping a
+ # Exactly the measured count (3869 tests and subtests, on both Go versions): dropping a
# case fails here, and adding one means raising this number.
- name: No test was skipped
if: ${{ !cancelled() }}
- run: python laya-go/scripts/check_test_json.py "$RUNNER_TEMP/go-test.json" --min-tests 3868
+ run: python laya-go/scripts/check_test_json.py "$RUNNER_TEMP/go-test.json" --min-tests 3869
# go.mod declares go 1.22, so that is what a consumer may build with.
- name: Run the tests on the oldest supported Go
@@ -144,7 +144,7 @@ jobs:
run: go test -count=1 -json ./... > "$RUNNER_TEMP/go-test-oldest.json"
- name: No test was skipped on the oldest Go either
if: ${{ !cancelled() }}
- run: python laya-go/scripts/check_test_json.py "$RUNNER_TEMP/go-test-oldest.json" --min-tests 3868
+ run: python laya-go/scripts/check_test_json.py "$RUNNER_TEMP/go-test-oldest.json" --min-tests 3869
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
if: ${{ failure() }}
diff --git a/laya-go/internal/hookrun/hookrun.go b/laya-go/internal/hookrun/hookrun.go
index 878eebaf..12564ad0 100644
--- a/laya-go/internal/hookrun/hookrun.go
+++ b/laya-go/internal/hookrun/hookrun.go
@@ -34,8 +34,7 @@ func Comparable(h any) (ok bool) {
ok = false
}
}()
- _ = h == h
- return h != nil
+ return h != nil && h == h
}
// Same compares hooks by identity: equal dynamic types that are comparable and equal. A value
diff --git a/laya-go/internal/hookrun/hookrun_test.go b/laya-go/internal/hookrun/hookrun_test.go
index 0a167c65..aa9275c2 100644
--- a/laya-go/internal/hookrun/hookrun_test.go
+++ b/laya-go/internal/hookrun/hookrun_test.go
@@ -5,6 +5,7 @@ import (
"context"
"errors"
"log"
+ "math"
"strings"
"testing"
"time"
@@ -28,8 +29,9 @@ func TestSameDoesNotPanicOnHiddenNonComparable(t *testing.T) {
func TestZeroValuesAreUsable(t *testing.T) {
var buf bytes.Buffer
+ prev := log.Writer()
log.SetOutput(&buf)
- t.Cleanup(func() { log.SetOutput(nil) })
+ t.Cleanup(func() { log.SetOutput(prev) })
var run Run // zero Policy: Raise false, Warn nil logs; zero Lock field is nil: concurrent
err := run.Dispatch(context.Background(), "on_route", 2, func(i int) string { return "H" }, func(i int) {
if i == 0 {
@@ -71,3 +73,14 @@ func TestNameIsOnlyComputedOnTheErrorPath(t *testing.T) {
t.Fatalf("name called %d times on success", calls)
}
}
+
+type nanHook struct{ v float64 }
+
+func TestComparableRefusesAValueThatIsNotEqualToItself(t *testing.T) {
+ if Comparable(nanHook{math.NaN()}) {
+ t.Fatal("a NaN-holding value can never be removed by equality, so it must be refused")
+ }
+ if !Comparable(&nanHook{math.NaN()}) {
+ t.Fatal("a pointer is always removable by identity")
+ }
+}