Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/ci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ python3 -m unittest discover -s .github/ci -p 'test_*.py' -v

`.github/ci/go_tests.py` 从 `go list -tags=unit ./...` 动态发现全部包,再按 `go-test-weights.json` 的历史耗时从重到轻分配。新包按 1 秒估算并自动纳入;无测试包也保留。权重仅影响分配,不筛选测试。初始权重来自 [2026-11-17 的成功运行](https://github.com/ranxi2001/sub2api/actions/runs/44150112506),其中 handler 581.520 秒、service 363.216 秒。包内用例尚未进一步拆分,因此单个重包仍可能决定单元测试关键路径。

单元测试的每个 package 显式使用 `-timeout=20m`,容纳已接近 Go 默认 10 分钟上限的 handler 全量套件;四分片仍运行全部用例,job 的 40 分钟上限继续生效。

运行仍经过 backend Makefile:`test-unit-packages` 接收包列表,嵌套收款模块的 `test-collection` 在第 0 片执行一次;默认 `make test-unit` 仍包含两者。单元测试保留 Go 测试结果缓存。集成测试保留 PostgreSQL/Redis、Docker testcontainers 和 `GOFLAGS=-p=1`,增加 `-count=1` 确保外部服务检查实际执行。原先单独运行的 `TestUsageTrendAggregateTimezone` 已包含在完整集成套件内,不再重复启动仓库集成环境。每个单元分片和集成 runner 都安装并检查 redis-server,分别满足快照适配器和认证缓存跨进程 Pub/Sub 用例;服务容器不能替代这些用例自行启动的独立 Redis 进程。

缓存按 OS、架构、go.mod/go.sum、suite/分片与源码 SHA 分隔,按同一依赖和分片前缀恢复最近的编译缓存;各分片不竞争同一写入 key。相同 key 的成功重跑可直接命中。分片缓存未命中时,使用与 setup-go 相同的绝对路径和键格式,按当前 Go 版本/runner 镜像回退读取 production 已有的共享缓存(先匹配 go.sum,再匹配版本前缀),只向分片 key 写入;避免新 PR 因无法读取其他 PR 的专属缓存而完全冷启动。独立 runner 会增加总资源和冷启动开销;这里不变更 Runner 账户配额,也不使用生产服务器编译。
Expand Down
2 changes: 1 addition & 1 deletion .github/ci/go_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def main():
if args.shard == 0:
report['runs'].append(run_command(['make', 'test-collection', 'TEST_FLAGS=-json'], output, 'collection'))
if shards[args.shard]:
report['runs'].append(run_command(['make', 'test-unit-packages', 'TEST_FLAGS=-json',
report['runs'].append(run_command(['make', 'test-unit-packages', 'TEST_FLAGS=-json -timeout=20m',
'TEST_PACKAGES=' + ' '.join(shards[args.shard])], output, 'unit'))
else:
report['runs'].append(run_command(['make', 'test-integration', 'TEST_FLAGS=-json -count=1'], output, 'integration'))
Expand Down
4 changes: 4 additions & 0 deletions .github/scripts/prepare-ws-owner-red-fixtures.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ exclude_new_fixture backend/internal/service/openai_ws_owner_conflict_test.go
# here; its own RED and every clean candidate GREEN retain both exact files.
exclude_new_fixture backend/internal/handler/openai_issue892_timezone_test.go
exclude_new_fixture backend/internal/service/openai_issue892_timezone_test.go
# Issue914 uses the same newer HTTP/WS harness and replay entry points.
# These tests are unrelated to the old selected defect and remain in GREEN.
exclude_new_fixture backend/internal/handler/openai_issue914_legacy_test.go
exclude_new_fixture backend/internal/service/openai_issue914_legacy_test.go
# Very old Issue805 baselines intentionally exclude the later readable harness.
# Only that dependency absence permits removing its new consumer as well.
if ! test -f "$tree/backend/internal/handler/openai_409_ws_rebuild_test.go"; then
Expand Down
18 changes: 18 additions & 0 deletions .github/scripts/upstream-v0222-red-fixtures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,21 @@ backend/migrations/group_usage_rollup_migration_test.go
# Restore existing profit tests; omit provider-site tests only when absent there.
backend/internal/service/profit_operations_test.go
backend/internal/service/provider_profit_site_test.go

# Later cache-tier, relogin and model-policy tests need their matching production APIs.
# Full old-source overlays use baseline fixtures; current-head GREEN retains them.
backend/internal/service/anthropic_prompt_total_test.go
backend/internal/service/antigravity_gateway_service_test.go
backend/internal/service/channel_pricing_multipliers_test.go
backend/internal/service/codex_account_availability_test.go
backend/internal/service/gateway_cache_compatibility_boundary_test.go
backend/internal/service/gateway_cache_creation_usage_test.go
backend/internal/service/gateway_cache_ttl_override_test.go
backend/internal/service/openai_cache_write_ttl_test.go
backend/internal/service/openai_gateway_native_cache_creation_test.go
backend/internal/service/openai_gpt62_fork_test.go
backend/internal/service/openai_json_object_field_edit_test.go
backend/internal/service/openai_relogin_settings_test.go
backend/internal/service/openai_subscription_long_context_test.go
backend/internal/service/openai_two_fa_login_test.go
backend/internal/service/upstream_batch_whitelist_identity_policy_test.go
14 changes: 12 additions & 2 deletions backend/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1173,8 +1173,12 @@ type GatewayConfig struct {
// DisableEncryptedAgentOwnerBinding permits completed opaque agent history
// on another normally eligible native Responses account. Delivery fences,
// response pointers, authorization and no-replay protections still apply.
DisableEncryptedAgentOwnerBinding bool `mapstructure:"disable_encrypted_agent_owner_binding"`
UpstreamRouting upstreamroute.Config `mapstructure:"upstream_routing"`
DisableEncryptedAgentOwnerBinding bool `mapstructure:"disable_encrypted_agent_owner_binding"`
// OpenAILegacyCompatibilityMode bypasses the post-v2.20 agent recovery
// ownership, immutable projections and no-replay gates. Startup-only; false
// retains the current policy. Explicit history rebuild settings are ignored.
OpenAILegacyCompatibilityMode bool `mapstructure:"openai_legacy_compatibility_mode"`
UpstreamRouting upstreamroute.Config `mapstructure:"upstream_routing"`
// PrismBrowser is the server-managed browser-session adapter for prism.openai.com.
// Account settings only select this route; cookies, sandbox state and the adapter
// API key remain outside account credentials.
Expand Down Expand Up @@ -2332,6 +2336,7 @@ func configureConfigSource(setConfigFile, addConfigPath func(string)) {

func setDefaults() {
viper.SetDefault("gateway.disable_encrypted_agent_owner_binding", false)
viper.SetDefault("gateway.openai_legacy_compatibility_mode", false)
viper.SetDefault("gateway.upstream_routing.enabled", false)
viper.SetDefault("runtime.role", RuntimeRoleFull)
viper.SetDefault("runtime.node_id", "")
Expand Down Expand Up @@ -4373,3 +4378,8 @@ func (c *Config) OpenAIWSClientHistoryRecoveryEnabled() bool {
func (c *Config) OpenAILossyHistoryRestartEnabled() bool {
return c != nil && c.Gateway.OpenAIWS.LossyHistoryRestartEnabled
}

// OpenAILegacyCompatibilityEnabled exposes the startup policy to gateway adapters.
func (c *Config) OpenAILegacyCompatibilityEnabled() bool {
return c != nil && c.Gateway.OpenAILegacyCompatibilityMode
}
37 changes: 37 additions & 0 deletions backend/internal/config/issue914_legacy_compatibility_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package config

import (
"encoding/json"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
)

func TestIssue914LegacyCompatibilityConfiguration(t *testing.T) {
for _, tc := range []struct {
name, yaml, env string
want bool
}{
{"default", "", "", false},
{"yaml", "gateway:\n openai_legacy_compatibility_mode: true\n", "", true},
{"env", "", "true", true},
{"env_over_yaml", "gateway:\n openai_legacy_compatibility_mode: true\n", "false", false},
} {
t.Run(tc.name, func(t *testing.T) {
resetViperWithJWTSecret(t)
path := filepath.Join(t.TempDir(), "config.yaml")
require.NoError(t, os.WriteFile(path, []byte(tc.yaml), 0600))
t.Setenv("CONFIG_FILE", path)
t.Setenv("GATEWAY_OPENAI_LEGACY_COMPATIBILITY_MODE", tc.env)
cfg, err := Load()
require.NoError(t, err)
raw, err := json.Marshal(cfg.Gateway)
require.NoError(t, err)
var got struct{ OpenAILegacyCompatibilityMode bool }
require.NoError(t, json.Unmarshal(raw, &got))
require.Equal(t, tc.want, got.OpenAILegacyCompatibilityMode)
})
}
}
Loading
Loading