Download cmd/server/cn_chat_base_test.go from a3216/gcli2api: direct link, hf CLI and curl.
- Browser
- Download file 1.42 kB
-
https://huggingface.co/spaces/a3216/gcli2api/resolve/main/cmd/server/cn_chat_base_test.go
- Command line
-
hf download hf://spaces/a3216/gcli2api/cmd/server/cn_chat_base_test.go
-
curl -L -o cn_chat_base_test.go https://huggingface.co/spaces/a3216/gcli2api/resolve/main/cmd/server/cn_chat_base_test.go
1.42 kB
| package main | |
| import ( | |
| "slices" | |
| "testing" | |
| "github.com/misakano7545/workbuddy2api-panel/internal/upstream" | |
| ) | |
| // 老配置(无 cn 段)必须保留内置 CN base,零回归。 | |
| func TestCNChatBaseDefaultKeepsBuiltin(t *testing.T) { | |
| cfg, err := ParseConfig([]byte(`{}`)) | |
| if err != nil { | |
| t.Fatalf("parse: %v", err) | |
| } | |
| up := upstream.New() | |
| want := up.ChatBaseCN | |
| applyCNChatBase(up, cfg) | |
| if up.ChatBaseCN != want { | |
| t.Fatalf("ChatBaseCN=%q want builtin %q", up.ChatBaseCN, want) | |
| } | |
| } | |
| func TestCNChatBaseOverride(t *testing.T) { | |
| cfg, err := ParseConfig([]byte(`{"cn":{"chat_base":"https://www.workbuddy.cn"}}`)) | |
| if err != nil { | |
| t.Fatalf("parse: %v", err) | |
| } | |
| up := upstream.New() | |
| applyCNChatBase(up, cfg) | |
| if up.ChatBaseCN != "https://www.workbuddy.cn" { | |
| t.Fatalf("ChatBaseCN=%q want override", up.ChatBaseCN) | |
| } | |
| // global base 不受 cn 覆盖影响。 | |
| if up.ChatBaseGlobal != "" { | |
| t.Fatalf("ChatBaseGlobal=%q want untouched", up.ChatBaseGlobal) | |
| } | |
| } | |
| // cn.chat_base 只在装配期生效,面板保存后须提示重启。 | |
| func TestCNChatBaseRequiresRestart(t *testing.T) { | |
| cfg := Default() | |
| // 本 fork 的 restartRequiredFields 比较「运行值 vs 新值」,故造一个差异。 | |
| next := Default() | |
| next.CN.ChatBase = "https://example.invalid" | |
| if !slices.Contains(restartRequiredFields(cfg, next), "cn.chat_base") { | |
| t.Fatal("cn.chat_base missing from restart-required fields") | |
| } | |
| } | |