refactor(core): reduce generated and duplicate code

This commit is contained in:
zarzet
2026-08-30 11:57:47 +07:00
parent 7141ca980f
commit e931d5e2b0
23 changed files with 18 additions and 73100 deletions
@@ -118,16 +118,11 @@ func TestLifecycleTimeoutQuarantinesUnresponsiveCleanupVM(t *testing.T) {
func TestSignedSessionGrantRetryHonorsCancellationAndReleasesCoordinator(t *testing.T) {
previousWait := signedSessionRetryWaitContext
previousLegacyWait := signedSessionRetryWait
signedSessionRetryWait = nil
signedSessionRetryWaitContext = func(ctx context.Context, _ time.Duration) error {
<-ctx.Done()
return ctx.Err()
}
t.Cleanup(func() {
signedSessionRetryWait = previousLegacyWait
signedSessionRetryWaitContext = previousWait
})
t.Cleanup(func() { signedSessionRetryWaitContext = previousWait })
var calls atomic.Int32
transport := roundTripFunc(func(req *http.Request) (*http.Response, error) {
-4
View File
@@ -780,10 +780,6 @@ func (r *extensionRuntime) RegisterAPIs(vm *goja.Runtime) {
logObj.Set("error", r.logError)
vm.Set("log", logObj)
gobackendObj := vm.NewObject()
gobackendObj.Set("sanitizeFilename", r.sanitizeFilenameWrapper)
vm.Set("gobackend", gobackendObj)
vm.Set("fetch", r.fetchPolyfill)
vm.Set("atob", r.atobPolyfill)
@@ -1144,9 +1144,6 @@ func TestExtensionRuntimeUtilityAPIs(t *testing.T) {
runtime.logInfo(goja.FunctionCall{Arguments: []goja.Value{vm.ToValue("info")}})
runtime.logWarn(goja.FunctionCall{Arguments: []goja.Value{vm.ToValue("warn")}})
runtime.logError(goja.FunctionCall{Arguments: []goja.Value{vm.ToValue("error")}})
if clean := runtime.sanitizeFilenameWrapper(goja.FunctionCall{Arguments: []goja.Value{vm.ToValue("A/B?")}}).String(); strings.ContainsAny(clean, "/?") {
t.Fatalf("sanitize wrapper = %q", clean)
}
}
func TestClassifySignedSessionExpiredAsVerification(t *testing.T) {
-8
View File
@@ -372,14 +372,6 @@ func (r *extensionRuntime) formatLogArgs(args []goja.Value) string {
return strings.Join(parts, " ")
}
func (r *extensionRuntime) sanitizeFilenameWrapper(call goja.FunctionCall) goja.Value {
if len(call.Arguments) < 1 {
return r.vm.ToValue("")
}
input := call.Arguments[0].String()
return r.vm.ToValue(sanitizeFilename(input))
}
func (r *extensionRuntime) RegisterGoBackendAPIs(vm *goja.Runtime) {
gobackendObj := vm.Get("gobackend")
if gobackendObj == nil || goja.IsUndefined(gobackendObj) {
+3 -23
View File
@@ -36,13 +36,9 @@ const (
)
var (
pendingSignedSessionGrants = make(map[string]string)
pendingSignedSessionGrantsMu sync.Mutex
signedSessionCoordinators sync.Map
// signedSessionRetryWait is retained as a test hook for callers that used
// the old duration-only seam. Production waits use the context-aware hook
// below; a non-nil legacy hook short-circuits the delay in tests.
signedSessionRetryWait func(time.Duration)
pendingSignedSessionGrants = make(map[string]string)
pendingSignedSessionGrantsMu sync.Mutex
signedSessionCoordinators sync.Map
signedSessionRetryWaitContext = sleepRetry
signedSessionProviderWait = sleepRetry
signedSessionRequestNow = time.Now
@@ -654,22 +650,6 @@ func waitSignedSessionRetry(ctx context.Context, delay time.Duration) error {
if ctx == nil {
ctx = context.Background()
}
// Keep the old duration-only hook useful for existing package tests without
// allowing production to fall back to an uninterruptible time.Sleep. The
// default hook is nil; tests install an immediate recorder/no-op here.
if legacyWait := signedSessionRetryWait; legacyWait != nil {
done := make(chan struct{})
go func() {
legacyWait(delay)
close(done)
}()
select {
case <-done:
return nil
case <-ctx.Done():
return ctx.Err()
}
}
return signedSessionRetryWaitContext(ctx, delay)
}
+9 -6
View File
@@ -1836,12 +1836,13 @@ func TestExchangeSignedSessionGrant(t *testing.T) {
pendingSignedSessionGrantsMu.Lock()
pendingSignedSessionGrants = make(map[string]string)
pendingSignedSessionGrantsMu.Unlock()
previousWait := signedSessionRetryWait
previousWait := signedSessionRetryWaitContext
var waits []time.Duration
signedSessionRetryWait = func(delay time.Duration) {
signedSessionRetryWaitContext = func(_ context.Context, delay time.Duration) error {
waits = append(waits, delay)
return nil
}
t.Cleanup(func() { signedSessionRetryWait = previousWait })
t.Cleanup(func() { signedSessionRetryWaitContext = previousWait })
calls := 0
transport := roundTripFunc(func(req *http.Request) (*http.Response, error) {
@@ -1895,9 +1896,11 @@ func TestExchangeSignedSessionGrant(t *testing.T) {
pendingSignedSessionGrantsMu.Lock()
pendingSignedSessionGrants = make(map[string]string)
pendingSignedSessionGrantsMu.Unlock()
previousWait := signedSessionRetryWait
signedSessionRetryWait = func(time.Duration) {}
t.Cleanup(func() { signedSessionRetryWait = previousWait })
previousWait := signedSessionRetryWaitContext
signedSessionRetryWaitContext = func(context.Context, time.Duration) error {
return nil
}
t.Cleanup(func() { signedSessionRetryWaitContext = previousWait })
calls := 0
transport := roundTripFunc(func(req *http.Request) (*http.Response, error) {