跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

提交记录

Merge pull request #20 from Lee-xeo/codex/issue18-websocket-fields

修复旧 WebSocket 订阅字段在实际连接中被忽略

作者
Shihao Li
时间
2026/11/09 23:45
提交
7bc0c13
这个版本的全部文件

这是一个合并提交,下面是和第一个上一提交相比的改动。

修改docs/guide/network.md+2 −0看文件
@@ -26,6 +26,8 @@ keywords: Clash Mihomo YAML SOCKS5 住宅 IP DNS DoH 暂停 断网 代理链 订
2626
2727普通节点参数保留并交给 Cage 随附的 Mihomo 核心校验。例如,从 FlClash 复制的 VLESS 节点可以保留 `xudp: true`,无需手动改成其他字段。内核可能忽略未知字段;配置校验通过后,仍需应用节点并检查实际出口。客机公网 UDP 的阻断规则不受这些协议选项影响。
2828
29新增:VMess、VLESS 和 Trojan 的 WebSocket 节点可以导入旧字段 `ws-path`、`ws-headers`。节点须明确设置 `network: ws`,Cage 会将路径和请求头转换为 `ws-opts.path`、`ws-opts.headers`,已保存的旧节点在应用代理时也会转换。新旧字段可同时存在,路径须一致,请求头按名称合并并忽略名称的字母大小写。相同请求头的值冲突、字段写法重复或旧字段用于其他传输方式时,来源会显示具体原因,需要修改该节点后重新导入。
30新增:
2931Hysteria2 节点可使用 `mport` 指定端口跳跃范围、`pinSHA256` 指定证书指纹,导入时会转换为核心支持的字段并保留功能。若节点使用不支持的协议、引用本机文件或网卡、管理字段重复、别名参数冲突或代理链不可用,会跳过该节点,并在来源下显示导入数量、跳过数量和原因。点击「查看原因」可展开具体节点;依赖失败节点的代理链也会跳过。若所有节点均被跳过,导入失败;更新影响当前出口或中转节点时保留原配置,请先应用其他节点再更新。其余节点还须整体通过核心配置校验,校验失败时原配置保持不变,可在设置的「日志与诊断」中导出诊断包查看校验记录。
3032
3133同一个订阅地址可能按请求的客户端身份返回不同格式。Cage 下载时使用 Clash 客户端身份,服务商返回 YAML 时可以导入;若返回 Base64 或分享链接列表,仍需向服务商获取 Clash/Mihomo YAML。
修改internal/managedproxy/import.go+95 −3看文件
@@ -5,10 +5,13 @@ import (
55 "encoding/hex"
66 "errors"
77 "fmt"
8新增: "maps"
9新增: "net/http"
810 "strconv"
911 "strings"
1012
1113 "go.yaml.in/yaml/v3"
14新增: "golang.org/x/net/http/httpguts"
1215)
1316
1417// NodeIssue contains display metadata only, never node credentials or field values.
@@ -85,10 +88,12 @@ func parseNodes(data []byte, sourceID string) ([]Node, []NodeIssue, error) {
8588 issue.Reason = "节点协议暂不支持"
8689 case server == "" || len(server) > 253:
8790 issue.Reason = "节点服务器缺失或过长"
88删除: case unsafeOption(p):
89删除: issue.Reason = "节点不能引用本机文件、网络接口或额外路由"
9091 default:
91删除: if typ == "hysteria2" {
92新增: if err := normalizeWebSocket(p); err != nil {
93新增: issue.Reason = err.Error()
94新增: } else if unsafeOption(p) {
95新增: issue.Reason = "节点不能引用本机文件、网络接口或额外路由"
96新增: } else if typ == "hysteria2" {
9297 if err := normalizeHysteria2(p); err != nil {
9398 issue.Reason = err.Error()
9499 }
@@ -221,6 +226,93 @@ func normalizeHysteria2(p map[string]any) error {
221226 return nil
222227}
223228
229新增:// Legacy WebSocket fields are accepted by the core but ignored by its transport.
230新增:// Normalize only nodes carrying aliases, leaving other protocol options alone.
231新增:func normalizeWebSocket(p map[string]any) error {
232新增: legacy := false
233新增: for key := range p {
234新增: if optionKey(key) == "ws-path" || optionKey(key) == "ws-headers" {
235新增: legacy = true
236新增: }
237新增: }
238新增: if !legacy {
239新增: return nil
240新增: }
241新增: if err := normalizeImportKeys(p, "ws-path", "ws-headers", "ws-opts", "network"); err != nil {
242新增: return err
243新增: }
244新增: if p["type"] != "vmess" && p["type"] != "vless" && p["type"] != "trojan" {
245新增: return errors.New("旧 WebSocket 字段仅适用于 VMess、VLESS 或 Trojan 节点")
246新增: }
247新增: if p["network"] != "ws" {
248新增: return errors.New("旧 WebSocket 字段需要显式设置 network: ws,请核对节点传输方式")
249新增: }
250新增: opts := map[string]any{}
251新增: if raw, exists := p["ws-opts"]; exists {
252新增: current, ok := raw.(map[string]any)
253新增: if !ok {
254新增: return errors.New("WebSocket 字段 ws-opts 无效,未忽略旧字段")
255新增: }
256新增: opts = maps.Clone(current)
257新增: }
258新增: if err := normalizeImportKeys(opts, "path", "headers"); err != nil {
259新增: return err
260新增: }
261新增: if raw, exists := p["ws-path"]; exists {
262新增: path, ok := raw.(string)
263新增: if !ok {
264新增: return errors.New("WebSocket 字段 ws-path 无效,未忽略该字段")
265新增: }
266新增: if current, exists := opts["path"]; exists && current != path {
267新增: return errors.New("WebSocket 字段 ws-path 与 ws-opts.path 冲突")
268新增: }
269新增: opts["path"] = path
270新增: delete(p, "ws-path")
271新增: }
272新增: if raw, exists := p["ws-headers"]; exists {
273新增: headers, err := webSocketHeaders(raw)
274新增: if err != nil {
275新增: return err
276新增: }
277新增: if current, exists := opts["headers"]; exists {
278新增: modern, err := webSocketHeaders(current)
279新增: if err != nil {
280新增: return err
281新增: }
282新增: for key, value := range modern {
283新增: if previous, exists := headers[key]; exists && previous != value {
284新增: return errors.New("WebSocket 字段 ws-headers 与 ws-opts.headers 冲突")
285新增: }
286新增: headers[key] = value
287新增: }
288新增: }
289新增: opts["headers"] = headers
290新增: delete(p, "ws-headers")
291新增: }
292新增: p["ws-opts"] = opts
293新增: return nil
294新增:}
295新增:
296新增:func webSocketHeaders(raw any) (map[string]any, error) {
297新增: input, ok := raw.(map[string]any)
298新增: if !ok {
299新增: return nil, errors.New("WebSocket 请求头必须为字符串映射,未忽略该字段")
300新增: }
301新增: headers := make(map[string]any, len(input))
302新增: for key, rawValue := range input {
303新增: value, ok := rawValue.(string)
304新增: if !ok || !httpguts.ValidHeaderFieldName(key) || !httpguts.ValidHeaderFieldValue(value) {
305新增: return nil, errors.New("WebSocket 请求头无效,未忽略该字段")
306新增: }
307新增: key = http.CanonicalHeaderKey(key)
308新增: if previous, exists := headers[key]; exists && previous != value {
309新增: return nil, errors.New("WebSocket 请求头存在大小写不同的冲突写法")
310新增: }
311新增: headers[key] = value
312新增: }
313新增: return headers, nil
314新增:}
315新增:
224316func hysteria2Ports(raw any) (string, error) {
225317 var ports string
226318 switch v := raw.(type) {
修改internal/managedproxy/store.go+4 −0看文件
@@ -283,6 +283,10 @@ func (s Store) Runtime(profile string) ([]byte, error) {
283283 for key, value := range n.Config {
284284 config[key] = value
285285 }
286新增: // Older stores may contain legacy headers accepted before normalization.
287新增: if err := normalizeWebSocket(config); err != nil {
288新增: return nil, fmt.Errorf("节点 %q:%w", n.Name, err)
289新增: }
286290 if via, overridden := dialers[n.ID]; overridden {
287291 delete(config, "dialer-proxy")
288292 if via != "" {
新增internal/managedproxy/websocket_core_test.go+148 −0看文件
@@ -0,0 +1,148 @@
1新增:package managedproxy
2新增:
3新增:import (
4新增: "context"
5新增: "fmt"
6新增: "net"
7新增: "net/http"
8新增: "net/http/httptest"
9新增: "net/url"
10新增: "os"
11新增: "os/exec"
12新增: "path/filepath"
13新增: "testing"
14新增: "time"
15新增:
16新增: "github.com/gorilla/websocket"
17新增:)
18新增:
19新增:// Configuration validation alone accepts legacy fields that the transport ignores.
20新增:// Observe a real local upgrade after importing, saving and reloading each protocol.
21新增:func TestCoreWebSocketAliasesReachHandshake(t *testing.T) {
22新增: if os.Getenv("CAGE_PROXY_INTEGRATION") != "1" {
23新增: t.Skip("requires a test binary beside the bundled Mihomo")
24新增: }
25新增: for _, protocol := range []string{"vmess", "vless", "trojan"} {
26新增: for _, pathField := range []string{"WS_PATH", "ws-opts.path"} {
27新增: t.Run(protocol+"/"+pathField, func(t *testing.T) {
28新增: type observation struct {
29新增: path, host, token, underscore, modern string
30新增: upgraded bool
31新增: }
32新增: requests := make(chan observation, 8)
33新增: upgrader := websocket.Upgrader{}
34新增: upstream := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, request *http.Request) {
35新增: observed := observation{
36新增: path: request.URL.RequestURI(), host: request.Host,
37新增: token: request.Header.Get("X-Legacy"), underscore: request.Header.Get("X_Underscore"),
38新增: modern: request.Header.Get("X-Modern"),
39新增: }
40新增: connection, err := upgrader.Upgrade(w, request, nil)
41新增: if err == nil {
42新增: observed.upgraded = true
43新增: _ = connection.Close()
44新增: }
45新增: select {
46新增: case requests <- observed:
47新增: default:
48新增: }
49新增: }))
50新增: t.Cleanup(upstream.Close)
51新增: _, port, err := net.SplitHostPort(upstream.Listener.Addr().String())
52新增: if err != nil {
53新增: t.Fatal(err)
54新增: }
55新增: profile := t.TempDir()
56新增: store, err := Load(profile)
57新增: if err != nil {
58新增: t.Fatal(err)
59新增: }
60新增: pathOptions := `WS_PATH: "/legacy?source=cage", ws-opts: {headers: {HOST: edge.example, X-Modern: retained}}`
61新增: if pathField == "ws-opts.path" {
62新增: pathOptions = `ws-opts: {path: "/legacy?source=cage", headers: {X-Modern: retained}}`
63新增: }
64新增: data := fmt.Sprintf(`proxies: [{name: local, type: %s, server: 127.0.0.1, port: %s, uuid: 00000000-0000-4000-8000-000000000000, password: local-test-password, alterId: 0, cipher: auto, tls: true, skip-cert-verify: true, network: ws, WS_HEADERS: {host: edge.example, X-Legacy: local-token, X_Underscore: preserved}, %s}]`, protocol, port, pathOptions)
65新增: if err := store.Import("local", "", []byte(data), "local", 0, ""); err != nil {
66新增: t.Fatal(err)
67新增: }
68新增: store.Selected = store.Sources[0].Nodes[0].ID
69新增: if err := store.Save(profile); err != nil {
70新增: t.Fatal(err)
71新增: }
72新增: store, err = Load(profile)
73新增: if err != nil {
74新增: t.Fatal(err)
75新增: }
76新增: if err := Validate(context.Background(), profile, store); err != nil {
77新增: t.Fatal(err)
78新增: }
79新增: store.Port = 0
80新增: runtime, err := store.Runtime(profile)
81新增: if err != nil {
82新增: t.Fatal(err)
83新增: }
84新增: interfaces, err := net.Interfaces()
85新增: if err != nil {
86新增: t.Fatal(err)
87新增: }
88新增: loopback := ""
89新增: for _, iface := range interfaces {
90新增: if iface.Flags&net.FlagLoopback != 0 {
91新增: loopback = iface.Name
92新增: break
93新增: }
94新增: }
95新增: runtime, err = BindInterface(runtime, loopback)
96新增: if err != nil {
97新增: t.Fatal(err)
98新增: }
99新增: config := filepath.Join(Dir(profile), "config.yaml")
100新增: if err := Write(config, runtime); err != nil {
101新增: t.Fatal(err)
102新增: }
103新增: if err := os.MkdirAll(filepath.Dir(Socket(profile)), 0700); err != nil {
104新增: t.Fatal(err)
105新增: }
106新增: t.Cleanup(func() { _ = os.RemoveAll(filepath.Dir(Socket(profile))) })
107新增: core, err := CorePath()
108新增: if err != nil {
109新增: t.Fatal(err)
110新增: }
111新增: log, err := os.Create(filepath.Join(profile, "core.log"))
112新增: if err != nil {
113新增: t.Fatal(err)
114新增: }
115新增: command := exec.Command(core, "-d", Dir(profile), "-f", config)
116新增: command.Env, command.Stdout, command.Stderr = coreEnvironment(Dir(profile)), log, log
117新增: if err := command.Start(); err != nil {
118新增: _ = log.Close()
119新增: t.Fatal(err)
120新增: }
121新增: t.Cleanup(func() { _ = command.Process.Kill(); _ = command.Wait(); _ = log.Close() })
122新增: ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
123新增: defer cancel()
124新增: ticker := time.NewTicker(20 * time.Millisecond)
125新增: defer ticker.Stop()
126新增: for !Running(ctx, profile, store) {
127新增: select {
128新增: case <-ctx.Done():
129新增: t.Fatal("generated core did not become ready")
130新增: case <-ticker.C:
131新增: }
132新增: }
133新增: // The local server closes after the WebSocket upgrade. The protocol tunnel
134新增: // then fails, while the observed HTTP request proves transport parameters.
135新增: _ = API(ctx, profile, "GET", "/proxies/"+store.Selected+"/delay?timeout=2000&url="+url.QueryEscape("http://127.0.0.1:1/"), nil, nil)
136新增: select {
137新增: case observed := <-requests:
138新增: if observed.path != "/legacy?source=cage" || observed.host != "edge.example" || observed.token != "local-token" || observed.underscore != "preserved" || observed.modern != "retained" || !observed.upgraded {
139新增: t.Fatalf("imported WebSocket parameters did not reach the server: %+v", observed)
140新增: }
141新增: t.Logf("%s WebSocket upgrade preserved path, Host and both header formats", protocol)
142新增: case <-ctx.Done():
143新增: t.Fatal("core never reached local WebSocket server")
144新增: }
145新增: })
146新增: }
147新增: }
148新增:}
新增internal/managedproxy/websocket_test.go+182 −0看文件
@@ -0,0 +1,182 @@
1新增:package managedproxy
2新增:
3新增:import (
4新增: "encoding/json"
5新增: "fmt"
6新增: "reflect"
7新增: "strings"
8新增: "testing"
9新增:
10新增: "go.yaml.in/yaml/v3"
11新增:)
12新增:
13新增:func TestWebSocketAliasesSurviveImportStoreAndRuntime(t *testing.T) {
14新增: for _, protocol := range []string{"vmess", "vless", "trojan"} {
15新增: for _, tc := range []struct {
16新增: name, fields, path string
17新增: headers map[string]any
18新增: }{
19新增: {"legacy", `ws-path: "/legacy?token=example", ws-headers: {host: edge.example, X-Token: example, X_Underscore: preserved}`, "/legacy?token=example", map[string]any{"Host": "edge.example", "X-Token": "example", "X_underscore": "preserved"}},
20新增: {"variants", `WS_PATH: /variants, WS_HEADERS: {HOST: edge.example}, WS_OPTS: {max-early-data: 64}`, "/variants", map[string]any{"Host": "edge.example"}},
21新增: {"equivalent", `ws-path: /same, ws-headers: {host: edge.example, HOST: edge.example}, ws-opts: {PATH: /same, HEADERS: {Host: edge.example}}`, "/same", map[string]any{"Host": "edge.example"}},
22新增: {"merged-headers", `ws-path: /merged, ws-headers: {host: edge.example, X-Legacy: old}, ws-opts: {headers: {HOST: edge.example, X-Modern: new}}`, "/merged", map[string]any{"Host": "edge.example", "X-Legacy": "old", "X-Modern": "new"}},
23新增: {"path-only", `ws-path: /path`, "/path", nil},
24新增: {"headers-only", `ws-headers: {Host: edge.example}, ws-opts: {path: /modern}`, "/modern", map[string]any{"Host": "edge.example"}},
25新增: {"empty-defaults", `ws-path: "", ws-headers: {}`, "", map[string]any{}},
26新增: } {
27新增: t.Run(protocol+"/"+tc.name, func(t *testing.T) {
28新增: profile := t.TempDir()
29新增: store, err := Load(profile)
30新增: if err != nil {
31新增: t.Fatal(err)
32新增: }
33新增: data := fmt.Sprintf(`proxies: [{name: local, type: %s, server: 127.0.0.1, port: 443, network: ws, %s}]`, protocol, tc.fields)
34新增: if err := store.Import("websocket", "", []byte(data), "websocket", 0, ""); err != nil {
35新增: t.Fatal(err)
36新增: }
37新增: store.Selected = store.Sources[0].Nodes[0].ID
38新增: if err := store.Save(profile); err != nil {
39新增: t.Fatal(err)
40新增: }
41新增: loaded, err := Load(profile)
42新增: if err != nil {
43新增: t.Fatal(err)
44新增: }
45新增: runtime, err := loaded.Runtime(profile)
46新增: if err != nil {
47新增: t.Fatal(err)
48新增: }
49新增: var generated struct{ Proxies []map[string]any }
50新增: if err := yaml.Unmarshal(runtime, &generated); err != nil {
51新增: t.Fatal(err)
52新增: }
53新增: for _, config := range []map[string]any{loaded.Sources[0].Nodes[0].Config, generated.Proxies[0]} {
54新增: for key := range config {
55新增: if optionKey(key) == "ws-path" || optionKey(key) == "ws-headers" {
56新增: t.Fatal("runtime retained an ignored WebSocket alias")
57新增: }
58新增: }
59新增: opts := config["ws-opts"].(map[string]any)
60新增: headers, _ := opts["headers"].(map[string]any)
61新增: if opts["path"] != tc.path || !reflect.DeepEqual(headers, tc.headers) {
62新增: t.Fatalf("WebSocket transport changed across import, store or runtime: %#v", opts)
63新增: }
64新增: if config["udp"] != false || config["network"] != "ws" {
65新增: t.Fatal("conversion changed Cage UDP policy or transport")
66新增: }
67新增: }
68新增: if tc.name == "variants" && generated.Proxies[0]["ws-opts"].(map[string]any)["max-early-data"] != 64 {
69新增: t.Fatal("conversion lost unrelated WebSocket settings")
70新增: }
71新增: })
72新增: }
73新增: }
74新增:}
75新增:
76新增:func TestWebSocketInvalidAliasesSkipNodeAndDependentWithoutLeakingValues(t *testing.T) {
77新增: for _, fields := range []string{
78新增: `ws-path: /private-path, WS_PATH: /private-path`,
79新增: `ws-headers: {}, WS_HEADERS: {}`,
80新增: `ws-path: /private-path, NETWORK: ws`,
81新增: `ws-path: /private-path, ws-opts: {}, WS_OPTS: {}`,
82新增: `ws-path: /private-path, ws-opts: {path: /private-path, PATH: /private-path}`,
83新增: `ws-headers: {}, ws-opts: {headers: {}, HEADERS: {}}`,
84新增: `ws-path: /private-path, ws-opts: {path: /other-private-path}`,
85新增: `ws-path: 12`,
86新增: `ws-path: {private-key: private-value}`,
87新增: `ws-path: /private-path, ws-opts: private-value`,
88新增: `ws-path: /private-path, ws-opts: {path: [private-value]}`,
89新增: `ws-headers: private-value`,
90新增: `ws-headers: null`,
91新增: `ws-headers: {Host: 123}`,
92新增: `ws-headers: {Host: [private-value]}`,
93新增: `ws-headers: {host: private-value, HOST: different-private-value}`,
94新增: `ws-headers: {Host: private-value}, ws-opts: {headers: {host: different-private-value}}`,
95新增: `ws-headers: {Host: private-value}, ws-opts: {headers: private-value}`,
96新增: `ws-headers: {"invalid header": private-value}`,
97新增: `ws-headers: {Host: "private-value\r\nInjected: private-value"}`,
98新增: `ws-path: /private-path, ws-opts: {PRIVATE_KEY: /private/key}`,
99新增: `ws-path: /private-path, future-options: {CA_PATH: /private/ca}`,
100新增: `ws-headers: {certificate: /private/certificate}`,
101新增: } {
102新增: t.Run(fields, func(t *testing.T) {
103新增: store, _ := Load(t.TempDir())
104新增: data := `proxies:
105新增: - {name: good, type: http, server: 127.0.0.1, port: 8080}
106新增: - {name: bad, type: vless, server: example.com, port: 443, network: ws, ` + fields + `}
107新增: - {name: dependent, type: socks5, server: example.com, port: 1080, dialer-proxy: bad}
108新增:`
109新增: if err := store.Import("websocket", "", []byte(data), "websocket", 0, ""); err != nil {
110新增: t.Fatal(err)
111新增: }
112新增: if store.Count() != 1 || store.Sources[0].Nodes[0].Name != "good" || len(store.Sources[0].Skipped) != 2 {
113新增: t.Fatal("invalid WebSocket node or dependent survived import")
114新增: }
115新增: report, _ := json.Marshal(store.Sources[0].Skipped)
116新增: if strings.Contains(string(report), "private-") || strings.Contains(string(report), "/private/") {
117新增: t.Fatal("import report leaked a field value")
118新增: }
119新增: })
120新增: }
121新增:}
122新增:
123新增:func TestWebSocketAliasesRequireAnApplicableTransport(t *testing.T) {
124新增: for _, fields := range []string{
125新增: `type: http, network: ws`, `type: ss, network: ws`,
126新增: `type: vless, network: tcp`, `type: vmess, network: grpc`, `type: trojan`,
127新增: } {
128新增: if _, err := Parse([]byte(`proxies: [{name: example, server: example.com, port: 443, ws-headers: {Host: example.com}, `+fields+`}]`), "test"); err == nil {
129新增: t.Fatalf("ignored fields survived incompatible transport: %s", fields)
130新增: }
131新增: }
132新增: data := `proxies: [{name: example, type: http, server: example.com, port: 8080, network: grpc, ws-opts: {PATH: /retained, headers: {x_custom: example}}}]`
133新增: nodes, err := Parse([]byte(data), "test")
134新增: if err != nil {
135新增: t.Fatal(err)
136新增: }
137新增: opts := nodes[0].Config["ws-opts"].(map[string]any)
138新增: if opts["PATH"] != "/retained" || opts["headers"].(map[string]any)["x_custom"] != "example" {
139新增: t.Fatal("normalization rewrote unrelated protocol data")
140新增: }
141新增:}
142新增:
143新增:func TestWebSocketRuntimeNormalizesOlderStoresWithoutMutatingThem(t *testing.T) {
144新增: profile := t.TempDir()
145新增: store, _ := Load(profile)
146新增: if err := store.Import("websocket", "", []byte(`proxies: [{name: old, type: vless, server: example.com, port: 443, network: ws}]`), "test", 0, ""); err != nil {
147新增: t.Fatal(err)
148新增: }
149新增: store.Selected = store.Sources[0].Nodes[0].ID
150新增: config := store.Sources[0].Nodes[0].Config
151新增: config["ws-path"] = "/stored"
152新增: config["ws-headers"] = map[string]any{"host": "edge.example"}
153新增: config["ws-opts"] = map[string]any{"PATH": "/stored", "headers": map[string]any{"X-Modern": "retained"}}
154新增: if err := store.Save(profile); err != nil {
155新增: t.Fatal(err)
156新增: }
157新增: loaded, err := Load(profile)
158新增: if err != nil {
159新增: t.Fatal(err)
160新增: }
161新增: before, _ := json.Marshal(loaded)
162新增: runtime, err := loaded.Runtime(profile)
163新增: if err != nil {
164新增: t.Fatal(err)
165新增: }
166新增: var generated struct{ Proxies []map[string]any }
167新增: if err := yaml.Unmarshal(runtime, &generated); err != nil {
168新增: t.Fatal(err)
169新增: }
170新增: opts := generated.Proxies[0]["ws-opts"].(map[string]any)
171新增: if opts["path"] != "/stored" || !reflect.DeepEqual(opts["headers"], map[string]any{"Host": "edge.example", "X-Modern": "retained"}) {
172新增: t.Fatal("older persisted aliases were not converted")
173新增: }
174新增: after, _ := json.Marshal(loaded)
175新增: if string(before) != string(after) {
176新增: t.Fatal("runtime generation mutated stored source")
177新增: }
178新增: loaded.Sources[0].Nodes[0].Config["ws-path"] = "/conflict"
179新增: if _, err := loaded.Runtime(profile); err == nil {
180新增: t.Fatal("ambiguous older store silently selected one path")
181新增: }
182新增:}