From 217925ca0b19c812c1dd69ed49da75cbecd60180 Mon Sep 17 00:00:00 2001 From: r266-tech Date: Sat, 7 Nov 2026 18:36:52 +0800 Subject: [PATCH] test(gateway): isolate signed-history allocation measurement --- .../gateway_thinking_filter_precheck_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/backend/internal/service/gateway_thinking_filter_precheck_test.go b/backend/internal/service/gateway_thinking_filter_precheck_test.go index b7cb36c4d9..639894e48b 100644 --- a/backend/internal/service/gateway_thinking_filter_precheck_test.go +++ b/backend/internal/service/gateway_thinking_filter_precheck_test.go @@ -3,6 +3,8 @@ package service import ( "bytes" "encoding/json" + "os" + "os/exec" "strings" "testing" @@ -75,6 +77,21 @@ func signedThinkingHistoryBody() []byte { } func TestFilterThinkingBlocksSignedHistorySkipsDecode(t *testing.T) { + // AllocsPerRun reads process-wide counters. Background workers from other + // service tests can otherwise make unchanged signed history fail this check. + const isolatedEnv = "SUB2API_TEST_SIGNED_HISTORY_ALLOCS" + if os.Getenv(isolatedEnv) != "1" { + binary, err := os.Executable() + require.NoError(t, err) + cmd := exec.CommandContext(t.Context(), binary, + "-test.run=^TestFilterThinkingBlocksSignedHistorySkipsDecode$", + "-test.count=1", "-test.timeout=30s") + cmd.Env = append(os.Environ(), isolatedEnv+"=1") + output, err := cmd.CombinedOutput() + require.NoError(t, err, "%s", output) + return + } + body := signedThinkingHistoryBody() allocs := testing.AllocsPerRun(5, func() { got := filterThinkingBlocksInternal(body, false)