From 1fbab57f641748d054eb6b80bdbeef5698352b82 Mon Sep 17 00:00:00 2001 From: ranxi2001 Date: Mon, 16 Nov 2026 20:09:13 +0800 Subject: [PATCH 1/5] fix(bps): wrap direct search calls in native continuation history --- .../service/basispoints/web_search_stream.go | 12 + .../openai_excel_bps_search_business_test.go | 309 ++++++++++++++++++ 2 files changed, 321 insertions(+) create mode 100644 backend/internal/service/openai_excel_bps_search_business_test.go diff --git a/backend/internal/service/basispoints/web_search_stream.go b/backend/internal/service/basispoints/web_search_stream.go index a6a9fb273275..d1d05df1f7de 100644 --- a/backend/internal/service/basispoints/web_search_stream.go +++ b/backend/internal/service/basispoints/web_search_stream.go @@ -171,6 +171,17 @@ func (b *Bridge) searchRounds(ctx context.Context, upstream io.ReadCloser, wire if query == "" || len(query) > 4096 { return NewSearchFailure("tool_validation", "invalid_query", 0) } + // Direct catalog calls are accepted by translateCall, but their + // private names are not BPS-native tools. Use the same history + // wrapper as ordinary direct client calls before continuing. + // Genuine run_officejs calls retain their original wire fields. + name := text(item["name"]) + if name != "run_officejs" && name != "functions.run_officejs" { + item, translateErr = check.rebuildNativeHistoryCall(translated) + if translateErr != nil { + return searchFailureAt(translateErr, "tool_validation", "invalid_tool_response") + } + } nativeSearch = append(nativeSearch, item) searchIndexes = append(searchIndexes, i) queries = append(queries, query) @@ -203,6 +214,7 @@ func (b *Bridge) searchRounds(ctx context.Context, upstream io.ReadCloser, wire } index := searchIndexes[0] nativeOutput := append([]any(nil), output...) + nativeOutput[index] = nativeSearch[0] // Intermediate prose is not the final structured answer. It remains only // in the native continuation and never enters the validated final JSON. if b.structured != nil { diff --git a/backend/internal/service/openai_excel_bps_search_business_test.go b/backend/internal/service/openai_excel_bps_search_business_test.go new file mode 100644 index 000000000000..80f16819df9a --- /dev/null +++ b/backend/internal/service/openai_excel_bps_search_business_test.go @@ -0,0 +1,309 @@ +package service + +import ( + "encoding/json" + "errors" + "fmt" + "io" + "net/http" + "net/http/httptest" + "strings" + "sync" + "testing" + "time" + + "github.com/gin-gonic/gin" + "github.com/stretchr/testify/require" + "github.com/tidwall/gjson" +) + +const issue871BusinessQuery = "synthetic \"search\"\n第二行" +const issue871BusinessResult = `{"output":"Synthetic result","results":[{"url":"https://example.invalid/source","title":"Synthetic source"}]}` +const issue871BusinessAnswer = "见 https://example.invalid/source" + +func issue871BusinessCall(form string, round int) map[string]any { + query, _ := json.Marshal(map[string]any{"query": issue871BusinessQuery}) + call := issue871Call(fmt.Sprintf("fc_search_%d", round), fmt.Sprintf("call_search_%d", round), "__sub2api_web_search") + if strings.HasPrefix(form, "direct") { + call["name"], call["arguments"] = "__sub2api_web_search", string(query) + } else { + code, _ := json.Marshal(map[string]any{"name": "__sub2api_web_search", "arguments": json.RawMessage(query)}) + args, _ := json.Marshal(map[string]any{"code": string(code), "summary": "Search", "extended_summary": "{}", "destructive": false, "references": []any{}}) + call["arguments"] = string(args) + } + if strings.HasSuffix(form, "_prefixed") { + call["name"] = "functions." + call["name"].(string) + } + return call +} + +// This supplier enforces the existing bridge's native history contract. It is +// an offline fixture, not evidence of the current live alpha endpoint contract. +// No assertions run on the bridge/search goroutines; requests are copied under +// a lock and checked by the test after Forward returns. +type issue871BusinessSupplier struct { + mu sync.Mutex + bodies [][]byte + requests []*http.Request + proxies []string + form string + failure string +} + +func (s *issue871BusinessSupplier) send(req *http.Request, proxy string) (*http.Response, error) { + raw, err := io.ReadAll(req.Body) + _ = req.Body.Close() + if err != nil { + return nil, err + } + s.mu.Lock() + defer s.mu.Unlock() + s.bodies = append(s.bodies, raw) + s.requests = append(s.requests, req) + s.proxies = append(s.proxies, proxy) + n := len(s.bodies) + if n == 1 { + call := issue871BusinessCall(s.form, 0) + if s.failure == "invalid_arguments" { + call["arguments"] = `{"query":123}` + } + if s.failure == "unknown_tool" { + call["name"] = "undeclared_search" + } + return issue871Round("resp_business", call), nil + } + if n == 2 || n == 4 { + if req.URL.Path != "/backend-api/codex/alpha/search" || gjson.GetBytes(raw, "commands.search_query.0.q").String() != issue871BusinessQuery { + return issue871HTTP(400, `{"error":"invalid synthetic search request"}`), nil + } + switch s.failure { + case "search_transport": + return nil, errors.New(issue871Private) + case "search_403": + return issue871HTTP(403, issue871Private), nil + case "search_429": + return issue871HTTP(429, issue871Private), nil + case "search_parse": + return issue871HTTP(200, `{"results":{},"output":"PRIVATE_BODY"}`), nil + } + return issue871HTTP(200, issue871BusinessResult), nil + } + if n != 3 && n != 5 { + return nil, errors.New("unexpected synthetic supplier submission") + } + // Fail the business request when a server-only name is sent as a native + // tool. The old implementation reaches this rejection after a valid search. + for _, item := range gjson.GetBytes(raw, "input").Array() { + if item.Get("type").String() == "function_call" { + name := item.Get("name").String() + if name != "run_officejs" && name != "functions.run_officejs" { + return issue871HTTP(400, `{"error":"non-native tool in continuation"}`), nil + } + } + } + switch s.failure { + case "continuation_403": + return issue871HTTP(403, issue871Private), nil + case "continuation_eof": + return issue871HTTP(200, ""), nil + case "repeated_call": + call := issue871BusinessCall(s.form, 1) + call["call_id"] = "call_search_0" + return issue871Round("resp_repeat", call), nil + } + if n == 3 { + return issue871Round("resp_second_search", issue871BusinessCall(s.form, 1)), nil + } + return issue871Round("resp_answer", map[string]any{"type": "message", "id": "msg_answer", "role": "assistant", "content": []any{map[string]any{"type": "output_text", "text": issue871BusinessAnswer}}}), nil +} + +func issue871BusinessForward(t *testing.T, supplier *issue871BusinessSupplier, mode string) (*OpenAIGatewayService, *Account, *gin.Context, *httptest.ResponseRecorder, *OpenAIForwardResult, error) { + t.Helper() + svc := openAIClientToolsTestService(nil) + svc.httpUpstream = &bpsTestUpstream{send: supplier.send} + account := excelAccount() + account.Extra[ExcelBPSWebSearchKey] = true + account.Extra["openai_excel_bps_auto_disable_on_403"] = true + account.Extra["openai_excel_bps_mihomo"] = false + account.Proxy = &Proxy{Protocol: "http", Host: "127.0.0.1", Port: 7890} + body := []byte(fmt.Sprintf(`{"model":"gpt-6-astra","stream":%t,"input":[{"role":"user","content":"Search synthetic sources"}],"tools":[{"type":"web_search","search_context_size":"high"}],"tool_choice":{"type":"web_search"}}`, mode == "sse")) + rec := httptest.NewRecorder() + c, _ := gin.CreateTestContext(rec) + c.Request = httptest.NewRequest(http.MethodPost, "/v1/responses", strings.NewReader(string(body))) + c.Request.Header.Set("Cookie", "PRIVATE_COOKIE") + c.Request.Header.Set("x-codex-turn-state", "PRIVATE_TICKET") + if mode == "compact_keepalive" { + MarkOpenAICompactClientStream(c) + stop := StartOpenAICompactSSEKeepalive(c, time.Hour) + defer stop() + value, ok := c.Get(openAICompactSSEKeepaliveKey) + require.True(t, ok) + keepalive, ok := value.(*openAICompactSSEKeepalive) + require.True(t, ok) + require.True(t, keepalive.beat()) + } + result, err := svc.Forward(c.Request.Context(), c, account, body) + return svc, account, c, rec, result, err +} + +func TestExcelBPSSearchBusinessThroughForward(t *testing.T) { + for _, form := range []string{"wrapped", "wrapped_prefixed", "direct", "direct_prefixed"} { + for _, mode := range []string{"json", "sse"} { + t.Run(form+"/"+mode, func(t *testing.T) { + supplier := &issue871BusinessSupplier{form: form} + _, account, _, rec, result, err := issue871BusinessForward(t, supplier, mode) + supplier.mu.Lock() + defer supplier.mu.Unlock() + require.GreaterOrEqual(t, len(supplier.bodies), 3, "must reach continuation after a real mock search") + first := gjson.GetBytes(supplier.bodies[2], "input").Array() + require.GreaterOrEqual(t, len(first), 2) + wantName := "run_officejs" + if form == "wrapped_prefixed" { + wantName = "functions.run_officejs" + } + // The remote RED gate accepts only this precise wire regression. + if got := first[len(first)-2].Get("name").String(); got != wantName { + t.Fatalf("issue871_expected_native_search_history: got %q; want %q", got, wantName) + } + require.NoError(t, err) + require.NotNil(t, result) + require.Len(t, supplier.requests, 5, "two searches and two continuations, without replay") + require.Equal(t, http.StatusOK, rec.Code) + require.Equal(t, 30, result.Usage.InputTokens) + require.Equal(t, 6, result.Usage.OutputTokens) + require.Equal(t, "response.completed", result.UpstreamTerminalEvent) + initialInput := gjson.GetBytes(supplier.bodies[0], "input").Array() + require.Contains(t, string(supplier.bodies[0]), "__sub2api_web_search") + require.False(t, gjson.GetBytes(supplier.bodies[0], "tools").Exists(), "hosted declaration was normalized") + for i, req := range supplier.requests { + require.Equal(t, http.MethodPost, req.Method) + require.Equal(t, "Bearer test-token", req.Header.Get("Authorization")) + require.Equal(t, "test-account", req.Header.Get("Chatgpt-Account-Id")) + require.Empty(t, req.Header.Get("Cookie")) + require.Empty(t, req.Header.Get("x-codex-turn-state")) + require.True(t, HTTPUpstreamRedirectsDisabled(req.Context())) + require.Equal(t, account.Proxy.URL(), supplier.proxies[i]) + require.Equal(t, "gpt-6-astra", gjson.GetBytes(supplier.bodies[i], "model").String()) + if i == 1 || i == 3 { + require.Equal(t, "chatgpt.com", req.URL.Host) + require.Equal(t, "long", gjson.GetBytes(supplier.bodies[i], "commands.response_length").String()) + require.NotEmpty(t, gjson.GetBytes(supplier.bodies[i], "id").String()) + continue + } + require.Equal(t, "/basispoints/api/responses", req.URL.Path) + if i == 0 { + continue + } + rounds := (i + 1) / 2 + input := gjson.GetBytes(supplier.bodies[i], "input").Array() + require.Len(t, input, len(initialInput)+2*rounds) + for j, original := range initialInput { + require.JSONEq(t, original.Raw, input[j].Raw, "preserve complete prepared history and search instructions") + } + require.Equal(t, fmt.Sprint(rounds+1), gjson.GetBytes(supplier.bodies[i], "metadata.agent_iteration").String()) + for _, key := range []string{"task_id", "turn_id"} { + require.Equal(t, gjson.GetBytes(supplier.bodies[0], "metadata."+key).String(), gjson.GetBytes(supplier.bodies[i], "metadata."+key).String()) + } + for round := 0; round < rounds; round++ { + call, output := input[len(initialInput)+2*round], input[len(initialInput)+2*round+1] + require.Equal(t, wantName, call.Get("name").String()) + require.Equal(t, "function_call", call.Get("type").String()) + require.Equal(t, fmt.Sprintf("fc_search_%d", round), call.Get("id").String()) + require.Equal(t, fmt.Sprintf("call_search_%d", round), call.Get("call_id").String()) + require.Equal(t, "function_call_output", output.Get("type").String()) + require.Equal(t, call.Get("call_id").String(), output.Get("call_id").String()) + code := gjson.Get(call.Get("arguments").String(), "code").String() + require.Equal(t, "__sub2api_web_search", gjson.Get(code, "name").String()) + require.Equal(t, issue871BusinessQuery, gjson.Get(code, "arguments.query").String()) + data := gjson.Get(output.Get("output").String(), "untrusted_search_data") + require.JSONEq(t, gjson.Get(issue871BusinessResult, "results").Raw, data.Get("results").Raw) + require.Equal(t, "Synthetic result", data.Get("output").String()) + if strings.HasPrefix(form, "wrapped") { + exact, marshalErr := json.Marshal(issue871BusinessCall(form, round)) + require.NoError(t, marshalErr) + require.JSONEq(t, string(exact), call.Raw, "genuine native calls must remain verbatim") + } + } + } + require.NotEqual(t, gjson.GetBytes(supplier.bodies[1], "id").String(), gjson.GetBytes(supplier.bodies[3], "id").String()) + response := gjson.Parse(rec.Body.String()) + if mode == "sse" { + for _, line := range strings.Split(rec.Body.String(), "\n") { + if strings.HasPrefix(line, "data: ") { + event := gjson.Parse(strings.TrimPrefix(line, "data: ")) + if event.Get("type").String() == "response.completed" { + response = event.Get("response") + } + } + } + } + require.Equal(t, "completed", response.Get("status").String()) + require.Equal(t, "resp_business", response.Get("id").String()) + output := response.Get("output").Array() + require.Len(t, output, 3) + for _, item := range output[:2] { + require.Equal(t, "web_search_call", item.Get("type").String()) + require.Equal(t, issue871BusinessQuery, item.Get("action.query").String()) + require.Equal(t, "https://example.invalid/source", item.Get("action.sources.0.url").String()) + } + require.NotEqual(t, output[0].Get("id").String(), output[1].Get("id").String()) + require.Equal(t, issue871BusinessAnswer, output[2].Get("content.0.text").String()) + citation := output[2].Get("content.0.annotations.0") + require.Equal(t, "url_citation", citation.Get("type").String()) + require.Equal(t, "https://example.invalid/source", citation.Get("url").String()) + require.Equal(t, int64(2), citation.Get("start_index").Int()) + require.Equal(t, int64(len([]rune(issue871BusinessAnswer))), citation.Get("end_index").Int()) + require.NotContains(t, rec.Body.String(), "__sub2api_web_search") + require.NotContains(t, rec.Body.String(), "run_officejs") + }) + } + } +} + +func TestExcelBPSSearchBusinessFailuresThroughForward(t *testing.T) { + for _, tc := range []struct { + failure, phase, reason string + sends int + }{ + {"invalid_arguments", "tool_validation", "invalid_tool_response", 1}, + {"unknown_tool", "tool_validation", "invalid_tool_response", 1}, + {"search_transport", "search_http", "transport_failed", 2}, + {"search_403", "search_http", "http_rejected", 2}, + {"search_429", "search_http", "http_rejected", 2}, + {"search_parse", "search_result", "parse_failed", 2}, + {"continuation_403", "model_continuation", "http_rejected", 3}, + {"continuation_eof", "model_continuation", "unexpected_eof", 3}, + {"repeated_call", "tool_validation", "duplicate_call_id", 3}, + } { + for _, mode := range []string{"json", "sse", "compact_keepalive"} { + t.Run(tc.failure+"/"+mode, func(t *testing.T) { + supplier := &issue871BusinessSupplier{form: "direct", failure: tc.failure} + svc, account, c, rec, result, err := issue871BusinessForward(t, supplier, mode) + supplier.mu.Lock() + defer supplier.mu.Unlock() + require.Error(t, err) + require.NotNil(t, result) + require.Len(t, supplier.requests, tc.sends, "no repair, search replay, or extra continuation") + wantStatus := http.StatusOK + if mode == "json" { + wantStatus = http.StatusBadGateway + } + require.Equal(t, wantStatus, rec.Code, "preserve an already committed HTTP status") + require.NotContains(t, rec.Body.String(), "response.completed") + detail := issue871Error(t, rec.Body.String(), mode != "json") + require.Equal(t, "basispoints_search_failed", detail.Get("code").String()) + require.Contains(t, detail.Get("message").String(), "phase="+tc.phase+"; reason="+tc.reason) + ops, ok := GetOpsStreamError(c) + require.True(t, ok) + require.Equal(t, 502, ops.IntendedStatus) + for _, private := range []string{"PRIVATE_BODY", "PRIVATE_TOKEN", "PRIVATE_KEY", "PRIVATE_QUERY", issue871BusinessQuery, "test-token", "test-account"} { + require.NotContains(t, detail.Raw+ops.Message+ops.UpstreamDetail, private) + } + require.True(t, account.IsExcelBPSEnabled()) + require.True(t, account.Schedulable) + require.False(t, svc.isExcelBPSCoolingDown(account, "gpt-6-astra")) + require.False(t, svc.isOpenAIAccountRuntimeBlocked(account)) + }) + } + } +} From eb753cd34e8094ffaf9c994e3d73fb279945dbc8 Mon Sep 17 00:00:00 2001 From: ranxi2001 Date: Mon, 16 Nov 2026 20:13:00 +0800 Subject: [PATCH 2/5] test(bps): gate search continuation regression against pinned baseline --- .github/scripts/issue871-evidence.py | 40 +++++++++++----- .github/scripts/test_issue871_evidence.py | 44 +++++++++++++++-- .github/workflows/bps-search.yml | 47 +++++++++++++++++++ .../openai_excel_bps_search_business_test.go | 3 ++ 4 files changed, 116 insertions(+), 18 deletions(-) diff --git a/.github/scripts/issue871-evidence.py b/.github/scripts/issue871-evidence.py index c4f121e7c43f..b78e8023012c 100644 --- a/.github/scripts/issue871-evidence.py +++ b/.github/scripts/issue871-evidence.py @@ -1,4 +1,4 @@ -"""Accept only the named diagnosis assertion as the remote behavioral RED.""" +"""Accept only the named diagnosis or business assertion as behavioral RED.""" import json import sys @@ -10,9 +10,20 @@ NODES = {ROOT, LEAF} MARKER = "issue871_expected_search_diagnosis" ASSERTION = 'does not contain "phase=search_http; reason=http_rejected"' +BUSINESS_ROOT = "TestExcelBPSSearchBusinessThroughForward" +BUSINESS_LEAF = BUSINESS_ROOT + "/direct/json" +BUSINESS_MARKER = "issue871_expected_native_search_history" +BUSINESS_ASSERTION = BUSINESS_MARKER + ': got "__sub2api_web_search"; want "run_officejs"' -def validate(phase, status, raw, stderr=""): +def validate(phase, status, raw, stderr="", contract="diagnosis"): + if contract == "diagnosis": + nodes, leaf, marker, assertion = NODES, LEAF, MARKER, ASSERTION + elif contract == "business": + nodes = {BUSINESS_ROOT, BUSINESS_LEAF} + leaf, marker, assertion = BUSINESS_LEAF, BUSINESS_MARKER, BUSINESS_ASSERTION + else: + raise ValueError("unknown evidence contract") if phase not in {"RED", "GREEN"} or status != (1 if phase == "RED" else 0): raise ValueError("unexpected phase or test exit status") combined = (raw + stderr).lower() @@ -24,8 +35,8 @@ def validate(phase, status, raw, stderr=""): if forbidden in combined: raise ValueError("invalid behavioral evidence: " + forbidden) events = [json.loads(line) for line in raw.splitlines() if line.strip()] - runs = {name: 0 for name in NODES} - terminals = {name: [] for name in NODES} + runs = {name: 0 for name in nodes} + terminals = {name: [] for name in nodes} packages = [] output = "" for event in events: @@ -35,26 +46,29 @@ def validate(phase, status, raw, stderr=""): if action not in {"start", "run", "pause", "cont", "output", "pass", "fail"}: raise ValueError("skip/build/unknown event") if test: - if test not in NODES: + if test not in nodes: raise ValueError("unexpected test: " + test) if action == "run": runs[test] += 1 if action in {"pass", "fail"}: terminals[test].append(action) - if action == "output" and test == LEAF: + if action == "output" and test == leaf: output += event.get("Output", "") elif action in {"pass", "fail"}: packages.append(action) expected = "fail" if phase == "RED" else "pass" - if runs != {name: 1 for name in NODES}: + if runs != {name: 1 for name in nodes}: raise ValueError("missing or repeated named test execution") - if terminals != {name: [expected] for name in NODES} or packages != [expected]: + if terminals != {name: [expected] for name in nodes} or packages != [expected]: raise ValueError("unexpected test/package terminal") - if phase == "RED" and (output.count(MARKER) != 1 or ASSERTION not in output): - raise ValueError("RED did not fail at the intended diagnosis assertion") + if phase == "RED" and (output.count(marker) != 1 or assertion not in output): + raise ValueError("RED did not fail at the intended " + contract + " assertion") if __name__ == "__main__": - phase, status, log, stderr = sys.argv[1:] - validate(phase, int(status), Path(log).read_text(), Path(stderr).read_text()) - print(phase + " named search diagnosis evidence accepted") + phase, status, log, stderr, *extra = sys.argv[1:] + if len(extra) > 1: + raise ValueError("expected at most one evidence contract") + contract = extra[0] if extra else "diagnosis" + validate(phase, int(status), Path(log).read_text(), Path(stderr).read_text(), contract) + print(phase + " named search " + contract + " evidence accepted") diff --git a/.github/scripts/test_issue871_evidence.py b/.github/scripts/test_issue871_evidence.py index c4cb21780e79..1896288b7740 100644 --- a/.github/scripts/test_issue871_evidence.py +++ b/.github/scripts/test_issue871_evidence.py @@ -8,21 +8,55 @@ spec.loader.exec_module(gate) -def transcript(phase): +def transcript(phase, contract="diagnosis"): + root, leaf, marker, assertion = gate.ROOT, gate.LEAF, gate.MARKER, gate.ASSERTION + if contract == "business": + root, leaf = gate.BUSINESS_ROOT, gate.BUSINESS_LEAF + marker, assertion = "", gate.BUSINESS_ASSERTION terminal = "fail" if phase == "RED" else "pass" events = [dict(Action="start", Package=gate.PACKAGE)] - for name in (gate.ROOT, gate.LEAF): + for name in (root, leaf): events.append(dict(Action="run", Package=gate.PACKAGE, Test=name)) if phase == "RED": - events.append(dict(Action="output", Package=gate.PACKAGE, Test=gate.LEAF, - Output=gate.MARKER + "\n" + gate.ASSERTION + "\n")) - for name in (gate.LEAF, gate.ROOT): + events.append(dict(Action="output", Package=gate.PACKAGE, Test=leaf, + Output=marker + "\n" + assertion + "\n")) + for name in (leaf, root): events.append(dict(Action=terminal, Package=gate.PACKAGE, Test=name)) events.append(dict(Action=terminal, Package=gate.PACKAGE)) return "\n".join(json.dumps(event) for event in events) class Issue871EvidenceTest(unittest.TestCase): + def test_business_named_red_and_green(self): + for phase, code in (("RED", 1), ("GREEN", 0)): + raw = transcript(phase, "business") + gate.validate(phase, code, raw, contract="business") + with self.assertRaises(ValueError): + gate.validate(phase, code, raw) + with self.assertRaises(ValueError): + gate.validate(phase, code, transcript(phase), contract="business") + with self.assertRaises(ValueError): + gate.validate(phase, 2, raw, contract="business") + for noise in ("panic: fixture", "build failed", "setup failed", "no tests to run", + "DATA RACE", "--- SKIP: fixture", "test timed out", "fatal error"): + with self.subTest(phase=phase, noise=noise), self.assertRaises(ValueError): + gate.validate(phase, code, raw, noise, "business") + + def test_business_rejects_wrong_assertion_or_test(self): + red = transcript("RED", "business") + for invalid in ( + "", red.replace(gate.BUSINESS_MARKER, "unrelated_assertion"), + red.replace('__sub2api_web_search', 'different_tool'), + red.replace('"Action": "run"', '"Action": "skip"', 1), + red.replace(gate.BUSINESS_LEAF, gate.BUSINESS_ROOT + "/wrapped/json"), + red + "\n" + red, red + "\nnot JSON", + red.replace(gate.PACKAGE, "other/package"), + ): + with self.subTest(invalid=invalid), self.assertRaises(ValueError): + gate.validate("RED", 1, invalid, contract="business") + with self.assertRaises(ValueError): + gate.validate("RED", 1, red, contract="typo") + def test_named_red_and_green(self): for phase, code in (("RED", 1), ("GREEN", 0)): gate.validate(phase, code, transcript(phase)) diff --git a/.github/workflows/bps-search.yml b/.github/workflows/bps-search.yml index d154be177e5e..7f8c2ace4375 100644 --- a/.github/workflows/bps-search.yml +++ b/.github/workflows/bps-search.yml @@ -92,6 +92,53 @@ jobs: test "$(git rev-parse HEAD)" = "$CANDIDATE_SHA" git diff --exit-code HEAD test -z "$(git status --porcelain)" + - name: RED business continuation on pinned current production baseline + shell: bash + run: | + set -euo pipefail + evidence_dir="$RUNNER_TEMP/issue871-evidence" + baseline_sha=da526bfbab47efd40549cab98f1069f9b2b45b9f + fixture_path=backend/internal/service/openai_excel_bps_search_business_test.go + red_dir="$RUNNER_TEMP/issue871-business-red" + git worktree add --detach "$red_dir" "$baseline_sha" + test "$(git -C "$red_dir" rev-parse HEAD)" = "$baseline_sha" + git rev-parse "$baseline_sha" "$baseline_sha^{tree}" > "$evidence_dir/business-baseline.txt" + git ls-tree -r "$baseline_sha" -- backend > "$evidence_dir/business-baseline-blobs.txt" + git show "HEAD:$fixture_path" > "$red_dir/$fixture_path" + git rev-parse "HEAD:$fixture_path" > "$evidence_dir/business-fixture-blob.txt" + test "$(git hash-object "$red_dir/$fixture_path")" = "$(git rev-parse "HEAD:$fixture_path")" + cp "$red_dir/$fixture_path" "$evidence_dir/business_test.go" + git -C "$red_dir" status --short > "$evidence_dir/business-red-status.txt" + test "$(git -C "$red_dir" status --porcelain)" = "?? $fixture_path" + git -C "$red_dir" diff --exit-code HEAD + set +e + (cd "$red_dir/backend" && go test -tags=unit ./internal/service -run '^TestExcelBPSSearchBusinessThroughForward$/^direct$/^json$' -count=1 -json -timeout=5m) > "$evidence_dir/business-red.jsonl" 2> "$evidence_dir/business-red.stderr" + test_status=$? + set -e + printf '%s\n' "$test_status" > "$evidence_dir/business-red-exit.txt" + python3 .github/scripts/issue871-evidence.py RED "$test_status" "$evidence_dir/business-red.jsonl" "$evidence_dir/business-red.stderr" business + test "$(git -C "$red_dir" rev-parse HEAD)" = "$baseline_sha" + git -C "$red_dir" diff --exit-code HEAD + test "$(git -C "$red_dir" status --porcelain)" = "?? $fixture_path" + - name: GREEN business continuation on exact candidate + env: + CANDIDATE_SHA: ${{ github.event.pull_request.head.sha }} + shell: bash + run: | + set -euo pipefail + evidence_dir="$RUNNER_TEMP/issue871-evidence" + test "$(git rev-parse HEAD)" = "$CANDIDATE_SHA" + git diff --exit-code HEAD + test -z "$(git status --porcelain)" + set +e + (cd backend && go test -race -tags=unit ./internal/service -run '^TestExcelBPSSearchBusinessThroughForward$/^direct$/^json$' -count=1 -json -timeout=5m) > "$evidence_dir/business-green.jsonl" 2> "$evidence_dir/business-green.stderr" + test_status=$? + set -e + printf '%s\n' "$test_status" > "$evidence_dir/business-green-exit.txt" + python3 .github/scripts/issue871-evidence.py GREEN "$test_status" "$evidence_dir/business-green.jsonl" "$evidence_dir/business-green.stderr" business + test "$(git rev-parse HEAD)" = "$CANDIDATE_SHA" + git diff --exit-code HEAD + test -z "$(git status --porcelain)" - name: Repeat real Forward repair ownership and provenance with race detection working-directory: backend shell: bash diff --git a/backend/internal/service/openai_excel_bps_search_business_test.go b/backend/internal/service/openai_excel_bps_search_business_test.go index 80f16819df9a..f16cd5be9eea 100644 --- a/backend/internal/service/openai_excel_bps_search_business_test.go +++ b/backend/internal/service/openai_excel_bps_search_business_test.go @@ -239,6 +239,8 @@ func TestExcelBPSSearchBusinessThroughForward(t *testing.T) { } require.Equal(t, "completed", response.Get("status").String()) require.Equal(t, "resp_business", response.Get("id").String()) + require.Equal(t, int64(30), response.Get("usage.input_tokens").Int()) + require.Equal(t, int64(6), response.Get("usage.output_tokens").Int()) output := response.Get("output").Array() require.Len(t, output, 3) for _, item := range output[:2] { @@ -251,6 +253,7 @@ func TestExcelBPSSearchBusinessThroughForward(t *testing.T) { citation := output[2].Get("content.0.annotations.0") require.Equal(t, "url_citation", citation.Get("type").String()) require.Equal(t, "https://example.invalid/source", citation.Get("url").String()) + require.Equal(t, "Synthetic source", citation.Get("title").String()) require.Equal(t, int64(2), citation.Get("start_index").Int()) require.Equal(t, int64(len([]rune(issue871BusinessAnswer))), citation.Get("end_index").Int()) require.NotContains(t, rec.Body.String(), "__sub2api_web_search") From c34168b003b92690c78ed1b37a13123d22fe7d57 Mon Sep 17 00:00:00 2001 From: ranxi2001 Date: Mon, 16 Nov 2026 21:04:55 +0800 Subject: [PATCH 3/5] test(bps): check search fixture tool name assertion --- .../openai_excel_bps_search_business_test.go | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/backend/internal/service/openai_excel_bps_search_business_test.go b/backend/internal/service/openai_excel_bps_search_business_test.go index f16cd5be9eea..465f07fbc9f5 100644 --- a/backend/internal/service/openai_excel_bps_search_business_test.go +++ b/backend/internal/service/openai_excel_bps_search_business_test.go @@ -21,7 +21,8 @@ const issue871BusinessQuery = "synthetic \"search\"\n第二行" const issue871BusinessResult = `{"output":"Synthetic result","results":[{"url":"https://example.invalid/source","title":"Synthetic source"}]}` const issue871BusinessAnswer = "见 https://example.invalid/source" -func issue871BusinessCall(form string, round int) map[string]any { +func issue871BusinessCall(t *testing.T, form string, round int) map[string]any { + t.Helper() query, _ := json.Marshal(map[string]any{"query": issue871BusinessQuery}) call := issue871Call(fmt.Sprintf("fc_search_%d", round), fmt.Sprintf("call_search_%d", round), "__sub2api_web_search") if strings.HasPrefix(form, "direct") { @@ -32,7 +33,9 @@ func issue871BusinessCall(form string, round int) map[string]any { call["arguments"] = string(args) } if strings.HasSuffix(form, "_prefixed") { - call["name"] = "functions." + call["name"].(string) + name, ok := call["name"].(string) + require.True(t, ok, "search fixture tool name must be a string") + call["name"] = "functions." + name } return call } @@ -48,6 +51,7 @@ type issue871BusinessSupplier struct { proxies []string form string failure string + calls [2]map[string]any } func (s *issue871BusinessSupplier) send(req *http.Request, proxy string) (*http.Response, error) { @@ -63,7 +67,7 @@ func (s *issue871BusinessSupplier) send(req *http.Request, proxy string) (*http. s.proxies = append(s.proxies, proxy) n := len(s.bodies) if n == 1 { - call := issue871BusinessCall(s.form, 0) + call := s.calls[0] if s.failure == "invalid_arguments" { call["arguments"] = `{"query":123}` } @@ -107,18 +111,22 @@ func (s *issue871BusinessSupplier) send(req *http.Request, proxy string) (*http. case "continuation_eof": return issue871HTTP(200, ""), nil case "repeated_call": - call := issue871BusinessCall(s.form, 1) + call := s.calls[1] call["call_id"] = "call_search_0" return issue871Round("resp_repeat", call), nil } if n == 3 { - return issue871Round("resp_second_search", issue871BusinessCall(s.form, 1)), nil + return issue871Round("resp_second_search", s.calls[1]), nil } return issue871Round("resp_answer", map[string]any{"type": "message", "id": "msg_answer", "role": "assistant", "content": []any{map[string]any{"type": "output_text", "text": issue871BusinessAnswer}}}), nil } func issue871BusinessForward(t *testing.T, supplier *issue871BusinessSupplier, mode string) (*OpenAIGatewayService, *Account, *gin.Context, *httptest.ResponseRecorder, *OpenAIForwardResult, error) { t.Helper() + // Build and assert fixtures on the test goroutine before Forward starts. + for round := range supplier.calls { + supplier.calls[round] = issue871BusinessCall(t, supplier.form, round) + } svc := openAIClientToolsTestService(nil) svc.httpUpstream = &bpsTestUpstream{send: supplier.send} account := excelAccount() @@ -219,7 +227,7 @@ func TestExcelBPSSearchBusinessThroughForward(t *testing.T) { require.JSONEq(t, gjson.Get(issue871BusinessResult, "results").Raw, data.Get("results").Raw) require.Equal(t, "Synthetic result", data.Get("output").String()) if strings.HasPrefix(form, "wrapped") { - exact, marshalErr := json.Marshal(issue871BusinessCall(form, round)) + exact, marshalErr := json.Marshal(issue871BusinessCall(t, form, round)) require.NoError(t, marshalErr) require.JSONEq(t, string(exact), call.Raw, "genuine native calls must remain verbatim") } From 9dc66846a16609fb75b59a643563fae3284944cf Mon Sep 17 00:00:00 2001 From: ranxi2001 Date: Mon, 16 Nov 2026 21:18:54 +0800 Subject: [PATCH 4/5] fix(ws): preserve pending proof refusal when its read hits the wait deadline --- .github/scripts/issue871-evidence.py | 7 ++ .github/scripts/test_issue871_evidence.py | 23 +++++ .github/workflows/ws-tool-provenance.yml | 86 +++++++++++++++++ .../service/openai_tool_provenance.go | 7 ++ .../service/openai_ws_owner_conflict_test.go | 94 +++++++++++++++++++ 5 files changed, 217 insertions(+) diff --git a/.github/scripts/issue871-evidence.py b/.github/scripts/issue871-evidence.py index b78e8023012c..6cbee4ea51b8 100644 --- a/.github/scripts/issue871-evidence.py +++ b/.github/scripts/issue871-evidence.py @@ -14,6 +14,10 @@ BUSINESS_LEAF = BUSINESS_ROOT + "/direct/json" BUSINESS_MARKER = "issue871_expected_native_search_history" BUSINESS_ASSERTION = BUSINESS_MARKER + ': got "__sub2api_web_search"; want "run_officejs"' +PENDING_ROOT = "TestOpenAIToolProvenancePendingDeadline" +PENDING_LEAF = PENDING_ROOT + "/function/pending_deadline" +PENDING_MARKER = "WS_PENDING_DEADLINE_CLASSIFICATION" +PENDING_ASSERTION = PENDING_MARKER + ': got "encrypted_agent_recovery_store_unavailable"; want "encrypted_agent_recovery_owner_conflict"' def validate(phase, status, raw, stderr="", contract="diagnosis"): @@ -22,6 +26,9 @@ def validate(phase, status, raw, stderr="", contract="diagnosis"): elif contract == "business": nodes = {BUSINESS_ROOT, BUSINESS_LEAF} leaf, marker, assertion = BUSINESS_LEAF, BUSINESS_MARKER, BUSINESS_ASSERTION + elif contract == "pending_deadline": + nodes = {PENDING_ROOT, PENDING_LEAF} + leaf, marker, assertion = PENDING_LEAF, PENDING_MARKER, PENDING_ASSERTION else: raise ValueError("unknown evidence contract") if phase not in {"RED", "GREEN"} or status != (1 if phase == "RED" else 0): diff --git a/.github/scripts/test_issue871_evidence.py b/.github/scripts/test_issue871_evidence.py index 1896288b7740..bcc1f4330cbe 100644 --- a/.github/scripts/test_issue871_evidence.py +++ b/.github/scripts/test_issue871_evidence.py @@ -13,6 +13,9 @@ def transcript(phase, contract="diagnosis"): if contract == "business": root, leaf = gate.BUSINESS_ROOT, gate.BUSINESS_LEAF marker, assertion = "", gate.BUSINESS_ASSERTION + elif contract == "pending_deadline": + root, leaf = gate.PENDING_ROOT, gate.PENDING_LEAF + marker, assertion = "", gate.PENDING_ASSERTION terminal = "fail" if phase == "RED" else "pass" events = [dict(Action="start", Package=gate.PACKAGE)] for name in (root, leaf): @@ -27,6 +30,26 @@ def transcript(phase, contract="diagnosis"): class Issue871EvidenceTest(unittest.TestCase): + def test_pending_deadline_contract(self): + for phase, code in (("RED", 1), ("GREEN", 0)): + raw = transcript(phase, "pending_deadline") + gate.validate(phase, code, raw, contract="pending_deadline") + for noise in ("panic: fixture", "build failed", "setup failed", "no tests to run", + "DATA RACE", "--- SKIP: fixture", "test timed out", "fatal error"): + with self.subTest(phase=phase, noise=noise), self.assertRaises(ValueError): + gate.validate(phase, code, raw, noise, "pending_deadline") + for invalid in ("", raw + "\n" + raw, raw.replace(gate.PENDING_LEAF, gate.PENDING_ROOT + "/wrong"), + raw.replace('"Action": "run"', '"Action": "skip"', 1), transcript(phase)): + with self.subTest(phase=phase, invalid=invalid), self.assertRaises(ValueError): + gate.validate(phase, code, invalid, contract="pending_deadline") + with self.assertRaises(ValueError): + gate.validate(phase, 2, raw, contract="pending_deadline") + red = transcript("RED", "pending_deadline") + for invalid in (red.replace(gate.PENDING_MARKER, "other_assertion"), + red.replace("encrypted_agent_recovery_store_unavailable", "other_error")): + with self.assertRaises(ValueError): + gate.validate("RED", 1, invalid, contract="pending_deadline") + def test_business_named_red_and_green(self): for phase, code in (("RED", 1), ("GREEN", 0)): raw = transcript(phase, "business") diff --git a/.github/workflows/ws-tool-provenance.yml b/.github/workflows/ws-tool-provenance.yml index 8b9b458216e6..beb679192003 100644 --- a/.github/workflows/ws-tool-provenance.yml +++ b/.github/workflows/ws-tool-provenance.yml @@ -9,12 +9,98 @@ on: - .github/workflows/ws-tool-provenance.yml - .github/scripts/ws-owner-conflict-evidence.py - .github/scripts/ws-tool-provenance-evidence.py + - .github/scripts/issue871-evidence.py + - .github/scripts/test_issue871_evidence.py - backend/internal/repository/gateway_cache_tool_provenance.go permissions: contents: read jobs: + pending-deadline: + runs-on: ubuntu-latest + timeout-minutes: 40 + env: + CANDIDATE: ${{ github.event.pull_request.head.sha }} + PENDING_BASELINE: eb2addba4de284f2844eb7450a9e872efbce03b0 + PYTHONDONTWRITEBYTECODE: '1' + steps: + - uses: actions/checkout@v6 + with: + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 0 + - uses: actions/setup-go@v6 + with: + go-version-file: backend/go.mod + cache-dependency-path: backend/go.sum + - name: Validate named behavioral evidence gates + run: python3 -m unittest discover -s .github/scripts -p 'test_issue871_evidence.py' + - name: Pending wait RED on exact baseline with identical candidate tests + shell: bash + run: | + set -euo pipefail + evidence_dir="$RUNNER_TEMP/ws-pending-evidence" + red_dir="$RUNNER_TEMP/ws-pending-red" + fixture=backend/internal/service/openai_ws_owner_conflict_test.go + mkdir -p "$evidence_dir" + test "$(git rev-parse HEAD)" = "$CANDIDATE" + test -z "$(git status --porcelain)" + git rev-parse HEAD HEAD^{tree} > "$evidence_dir/candidate.txt" + git rev-parse "$PENDING_BASELINE" "$PENDING_BASELINE^{tree}" > "$evidence_dir/baseline.txt" + git worktree add --detach "$red_dir" "$PENDING_BASELINE" + git show "$CANDIDATE:$fixture" > "$red_dir/$fixture" + test "$(git hash-object "$red_dir/$fixture")" = "$(git rev-parse "$CANDIDATE:$fixture")" + git rev-parse "$CANDIDATE:$fixture" > "$evidence_dir/fixture-blob.txt" + cp "$red_dir/$fixture" "$evidence_dir/pending_test.go" + git -C "$red_dir" diff --exit-code "$PENDING_BASELINE" -- . ":(exclude)$fixture" + git -C "$red_dir" diff --stat > "$evidence_dir/red-diff.txt" + git ls-tree -r "$PENDING_BASELINE" -- backend > "$evidence_dir/baseline-blobs.txt" + set +e + (cd "$red_dir/backend" && go test -tags=unit,ownerconflict ./internal/service -run '^TestOpenAIToolProvenancePendingDeadline$/^function$/^pending_deadline$' -count=1 -json -timeout=5m) > "$evidence_dir/red.jsonl" 2> "$evidence_dir/red.stderr" + status=$? + set -e + printf '%s\n' "$status" > "$evidence_dir/red-exit.txt" + python3 .github/scripts/issue871-evidence.py RED "$status" "$evidence_dir/red.jsonl" "$evidence_dir/red.stderr" pending_deadline + test "$(git -C "$red_dir" rev-parse HEAD)" = "$PENDING_BASELINE" + git -C "$red_dir" diff --exit-code "$PENDING_BASELINE" -- . ":(exclude)$fixture" + - name: Pending wait GREEN and deterministic backend error controls with race detection + shell: bash + run: | + set -euo pipefail + evidence_dir="$RUNNER_TEMP/ws-pending-evidence" + test "$(git rev-parse HEAD)" = "$CANDIDATE" + test -z "$(git status --porcelain)" + set +e + (cd backend && go test -race -tags=unit,ownerconflict ./internal/service -run '^TestOpenAIToolProvenancePendingDeadline$/^function$/^pending_deadline$' -count=1 -json -timeout=5m) > "$evidence_dir/green.jsonl" 2> "$evidence_dir/green.stderr" + status=$? + set -e + printf '%s\n' "$status" > "$evidence_dir/green-exit.txt" + python3 .github/scripts/issue871-evidence.py GREEN "$status" "$evidence_dir/green.jsonl" "$evidence_dir/green.stderr" pending_deadline + (cd backend && go test -race -tags=unit,ownerconflict ./internal/service -run '^TestOpenAIToolProvenancePendingDeadline$' -count=1 -json -timeout=5m) > "$evidence_dir/controls.jsonl" 2>&1 + python3 .github/scripts/assert-readable-continuation.py --clean-log "$evidence_dir/controls.jsonl" + python3 - "$evidence_dir/controls.jsonl" <<'PY' + import json,sys + rows=[json.loads(line) for line in open(sys.argv[1]) if line.startswith('{')] + for kind in ('function','custom'): + for case in ('pending_deadline','initial_deadline','initial_store_failure','initial_backend_deadline','pending_store_failure','pending_backend_deadline','pending_store_failure_at_deadline'): + name=f'TestOpenAIToolProvenancePendingDeadline/{kind}/{case}' + assert sum(r.get('Action')=='pass' and r.get('Test')==name for r in rows)==1,name + assert not any(r.get('Action') in ('fail','skip') for r in rows) + PY + - name: Build production server at exact candidate + working-directory: backend + shell: bash + run: | + set -euo pipefail + test "$(git rev-parse HEAD)" = "$CANDIDATE" + CGO_ENABLED=0 go build -trimpath -o "$RUNNER_TEMP/ws-pending-server" ./cmd/server + sha256sum "$RUNNER_TEMP/ws-pending-server" > "$RUNNER_TEMP/ws-pending-evidence/server-sha256.txt" + test -z "$(git status --porcelain)" + - uses: actions/upload-artifact@v7 + if: always() + with: + name: ws-pending-deadline-${{ github.event.pull_request.head.sha }} + path: ${{ runner.temp }}/ws-pending-evidence behavior: runs-on: ubuntu-latest timeout-minutes: 45 diff --git a/backend/internal/service/openai_tool_provenance.go b/backend/internal/service/openai_tool_provenance.go index 611dd2c21bfd..08a8029edc30 100644 --- a/backend/internal/service/openai_tool_provenance.go +++ b/backend/internal/service/openai_tool_provenance.go @@ -5,6 +5,7 @@ import ( "crypto/sha256" "encoding/hex" "encoding/json" + "errors" "strings" "time" @@ -462,6 +463,12 @@ func (s *OpenAIGatewayService) verifyOpenAIToolInputs(ctx context.Context, r *op case <-timer.C: } raw, err = s.toolProofGet(ctx, key) + // Once a pending proof was observed, exhausting this wait is the + // same ownership refusal whether the timer or GET sees the deadline. + // An independent backend timeout/error remains a store failure. + if ctx.Err() == context.DeadlineExceeded && errors.Is(err, context.DeadlineExceeded) { + return openAIRecoveryDiagnosticError("owner_conflict", "tool_provenance_unknown", r) + } } if err != nil { return openAIRecoveryDiagnosticError("store_unavailable", "tool_provenance_unavailable", r) diff --git a/backend/internal/service/openai_ws_owner_conflict_test.go b/backend/internal/service/openai_ws_owner_conflict_test.go index d29aa0fa1857..b25c1af14247 100644 --- a/backend/internal/service/openai_ws_owner_conflict_test.go +++ b/backend/internal/service/openai_ws_owner_conflict_test.go @@ -7,9 +7,12 @@ import ( "context" "encoding/json" "errors" + "fmt" "net/http" "strings" "testing" + "testing/synctest" + "time" "github.com/Wei-Shaw/sub2api/internal/config" "github.com/Wei-Shaw/sub2api/internal/pkg/logger" @@ -20,6 +23,97 @@ import ( "go.uber.org/zap/zaptest/observer" ) +type pendingDeadlineToolProofCache struct { + GatewayCache + get func(context.Context, string) (string, error) + writes int +} + +func (c *pendingDeadlineToolProofCache) GetOpenAIToolProvenance(ctx context.Context, key string) (string, error) { + return c.get(ctx, key) +} + +func (c *pendingDeadlineToolProofCache) ReserveOpenAIToolProvenance(context.Context, string, string, time.Duration) error { + c.writes++ + return errors.New("unexpected proof reservation") +} + +func (c *pendingDeadlineToolProofCache) FinishOpenAIToolProvenance(context.Context, string, string, string, bool, time.Duration) error { + c.writes++ + return errors.New("unexpected proof completion") +} + +func TestOpenAIToolProvenancePendingDeadline(t *testing.T) { + backendErr := errors.New("PRIVATE_BACKEND_ERROR") + for _, kind := range []string{"function", "custom"} { + for _, tc := range []struct { + name string + pending, wait bool + readErr error + wantReason string + }{ + {"pending_deadline", true, true, context.DeadlineExceeded, "owner_conflict"}, + {"initial_deadline", false, true, context.DeadlineExceeded, "store_unavailable"}, + {"initial_store_failure", false, false, backendErr, "store_unavailable"}, + {"initial_backend_deadline", false, false, context.DeadlineExceeded, "store_unavailable"}, + {"pending_store_failure", true, false, backendErr, "store_unavailable"}, + {"pending_backend_deadline", true, false, context.DeadlineExceeded, "store_unavailable"}, + {"pending_store_failure_at_deadline", true, true, backendErr, "store_unavailable"}, + } { + t.Run(kind+"/"+tc.name, func(t *testing.T) { + synctest.Test(t, func(t *testing.T) { + callType, field := "function_call", "arguments" + if kind == "custom" { + callType, field = "custom_tool_call", "input" + } + body := []byte(fmt.Sprintf(`{"input":[{"type":%q,"call_id":"fixture-call","name":"fixture-tool",%q:"{}"},{"type":%q,"call_id":"fixture-call","output":"fixture-result"}]}`, callType, field, callType+"_output")) + request := &openAIAgentRecoveryRequest{userID: 1, keyID: 2, model: "fixture-model"} + var keys []string + var readContextErr error + cache := &pendingDeadlineToolProofCache{get: func(ctx context.Context, key string) (string, error) { + keys = append(keys, key) + if tc.pending && len(keys) == 1 { + return "pending:fixture-unconfirmed", nil + } + if tc.wait { + // The second GET has already started. Virtual time now + // exhausts the real wait context, never a scheduling race + // between the polling timer and the deadline select. + <-ctx.Done() + } + readContextErr = ctx.Err() + return "", fmt.Errorf("synthetic cache read: %w", tc.readErr) + }} + svc := &OpenAIGatewayService{cache: cache} + err := svc.verifyOpenAIToolInputs(context.Background(), request, body) + wantReads := 1 + if tc.pending { + wantReads = 2 + } + require.Len(t, keys, wantReads, "exercise the intended GET, without replay") + for _, key := range keys { + require.Equal(t, request.toolKey("fixture-call"), key) + } + if tc.wait { + require.ErrorIs(t, readContextErr, context.DeadlineExceeded) + } else { + require.NoError(t, readContextErr, "independent backend errors precede wait expiry") + } + var refusal *OpenAIAgentRecoveryError + require.ErrorAs(t, err, &refusal) + wantCode := "encrypted_agent_recovery_" + tc.wantReason + if got := refusal.ClientCode(); got != wantCode { + t.Fatalf("WS_PENDING_DEADLINE_CLASSIFICATION: got %q; want %q", got, wantCode) + } + require.Empty(t, request.toolProofs, "an incomplete proof must not grant permission") + require.Zero(t, cache.writes, "verification must not publish ownership") + require.NotContains(t, err.Error(), "PRIVATE_BACKEND_ERROR") + }) + }) + } + } +} + // Calls are learned only from the real response observer and successful write // completion; the client input below cannot populate the proof store. func learnF1DeliveredCalls(t *testing.T, svc *OpenAIGatewayService, account *Account, opaque, call string) { From 8835bed21ee150efa55ce08fbed9f2e48bbac756 Mon Sep 17 00:00:00 2001 From: ranxi2001 Date: Mon, 16 Nov 2026 22:00:56 +0800 Subject: [PATCH 5/5] test(ci): align residual WS red fixtures with historical APIs --- .github/workflows/ws-readable-continuation.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ws-readable-continuation.yml b/.github/workflows/ws-readable-continuation.yml index e14b97898a5f..3beabf291eb3 100644 --- a/.github/workflows/ws-readable-continuation.yml +++ b/.github/workflows/ws-readable-continuation.yml @@ -218,9 +218,12 @@ jobs: # PR855 route-evidence types and later production BPS search APIs # are absent in this baseline. Their unselected tests follow the # pinned historical APIs too; the selected ticket oracle stays current. + # Later UltraFast fields and the search-business helper dependency + # are absent too. Restore only these unrelated fixtures; never the + # selected ticket oracle or any candidate GREEN fixture. # BPS search is already excluded with blob/contract proofs by the # shared helpers above, so do not inspect/remove it a second time. - for target in backend/internal/service/temp_unsched_pending_test.go backend/internal/service/temp_unsched_stream_timing_test.go backend/internal/service/temp_unsched_ws_forward_test.go backend/internal/service/openai_auth_connection_status_test.go backend/internal/service/openai_auth_connections_account_type_test.go backend/internal/service/account_ops_balance_test.go backend/internal/service/openai_excel_bps_bridge_failure_test.go backend/internal/service/quality_5xx_immediate_test.go backend/internal/service/openai_ws_agent_recovery_test.go; do + for target in backend/internal/service/temp_unsched_pending_test.go backend/internal/service/temp_unsched_stream_timing_test.go backend/internal/service/temp_unsched_ws_forward_test.go backend/internal/service/openai_auth_connection_status_test.go backend/internal/service/openai_auth_connections_account_type_test.go backend/internal/service/account_ops_balance_test.go backend/internal/service/openai_excel_bps_bridge_failure_test.go backend/internal/service/quality_5xx_immediate_test.go backend/internal/service/openai_ws_agent_recovery_test.go backend/internal/service/admin_group_duplicate_test.go backend/internal/service/admin_service_group_test.go backend/internal/service/api_key_auth_cache_openai_fast_test.go backend/internal/service/free_ultrafast_customer_cost_test.go backend/internal/service/openai_excel_bps_search_business_test.go; do candidate_blob=$(git rev-parse "$CANDIDATE_SHA:$target") test "$(git hash-object "$tested_tree/$target")" = "$candidate_blob" if git cat-file -e "$baseline:$target" 2>/dev/null; then