diff --git a/backend/internal/service/gateway_thinking_filter_precheck_test.go b/backend/internal/service/gateway_thinking_filter_precheck_test.go index b7cb36c4d9..32b173ce25 100644 --- a/backend/internal/service/gateway_thinking_filter_precheck_test.go +++ b/backend/internal/service/gateway_thinking_filter_precheck_test.go @@ -2,9 +2,14 @@ package service import ( "bytes" + "context" "encoding/json" + "os" + "os/exec" + "regexp" "strings" "testing" + "time" "github.com/Wei-Shaw/sub2api/internal/pkg/antigravity" "github.com/stretchr/testify/require" @@ -75,6 +80,21 @@ func signedThinkingHistoryBody() []byte { } func TestFilterThinkingBlocksSignedHistorySkipsDecode(t *testing.T) { + // AllocsPerRun counts allocations across the process, including background + // goroutines left by other service tests. Measure only this case in a child. + const childEnv = "SUB2API_THINKING_FILTER_ALLOC_TEST_CHILD" + if os.Getenv(childEnv) != "1" { + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + executable, err := os.Executable() + require.NoError(t, err) + cmd := exec.CommandContext(ctx, executable, "-test.run=^"+regexp.QuoteMeta(t.Name())+"$", "-test.count=1") + cmd.Env = append(os.Environ(), childEnv+"=1") + output, err := cmd.CombinedOutput() + require.NoError(t, err, "isolated allocation test failed:\n%s", output) + return + } + body := signedThinkingHistoryBody() allocs := testing.AllocsPerRun(5, func() { got := filterThinkingBlocksInternal(body, false)