diff --git a/.github/workflows/docs-ci.yml b/.github/workflows/docs-ci.yml index 735bbed33..bfc388f63 100644 --- a/.github/workflows/docs-ci.yml +++ b/.github/workflows/docs-ci.yml @@ -7,12 +7,14 @@ on: - 'docs/**' - 'frontend/public/openapi.json' - 'frontend/src/pages/api-docs/endpoints.ts' + - 'internal/sub/default.json' - '.github/workflows/docs-ci.yml' pull_request: paths: - 'docs/**' - 'frontend/public/openapi.json' - 'frontend/src/pages/api-docs/endpoints.ts' + - 'internal/sub/default.json' - '.github/workflows/docs-ci.yml' permissions: diff --git a/docs/lib/xray/subscription.test.ts b/docs/lib/xray/subscription.test.ts index d28a19cd6..292a04651 100644 --- a/docs/lib/xray/subscription.test.ts +++ b/docs/lib/xray/subscription.test.ts @@ -1,3 +1,4 @@ +import { readFileSync } from 'node:fs'; import { describe, it, expect } from 'vitest'; import { buildSubscriptionUrls, @@ -121,6 +122,16 @@ describe('buildJsonSubscription', () => { expect(cfg.remarks).toBe('HK-01'); }); + // A key the panel drops from its template stays behind in this copy, deprecation warning and all. + it("carries the panel's embedded template around the proxy outbound", () => { + const template = JSON.parse( + readFileSync(new URL('../../../internal/sub/default.json', import.meta.url), 'utf8'), + ); + const cfg = JSON.parse(buildJsonSubscription([vlessClient])); + expect(cfg.outbounds.slice(1)).toEqual(template.outbounds); + expect({ ...cfg, remarks: '', outbounds: template.outbounds }).toEqual(template); + }); + it('keeps the Mihomo-only ML-KEM hint out of the Xray realitySettings', () => { const cfg = JSON.parse(buildJsonSubscription([vlessClient])); expect(cfg.outbounds[0].streamSettings.realitySettings.publicKey).toBe(vlessClient.publicKey); diff --git a/docs/lib/xray/subscription.ts b/docs/lib/xray/subscription.ts index b6d09931a..ea64b0f7e 100644 --- a/docs/lib/xray/subscription.ts +++ b/docs/lib/xray/subscription.ts @@ -182,7 +182,7 @@ function skeletonOutbounds(): Record[] { { tag: 'direct', protocol: 'freedom', - settings: { domainStrategy: 'AsIs', redirect: '', noises: [] }, + settings: { redirect: '' }, }, { tag: 'block', protocol: 'blackhole', settings: { response: { type: 'http' } } }, ]; diff --git a/internal/sub/default.json b/internal/sub/default.json index bd5700c47..2c920dbc0 100644 --- a/internal/sub/default.json +++ b/internal/sub/default.json @@ -49,8 +49,7 @@ "tag": "direct", "protocol": "freedom", "settings": { - "redirect": "", - "noises": [] + "redirect": "" } }, { diff --git a/internal/sub/default_json_test.go b/internal/sub/default_json_test.go index 5b89d98bc..8d547de0a 100644 --- a/internal/sub/default_json_test.go +++ b/internal/sub/default_json_test.go @@ -4,6 +4,9 @@ import ( "encoding/json" "strings" "testing" + + corelog "github.com/xtls/xray-core/common/log" + "github.com/xtls/xray-core/infra/conf" ) // xray-core moves freedom settings.domainStrategy to sockopt with a warning on @@ -37,3 +40,41 @@ func TestDefaultJSON_FreedomOutboundHasNoLegacyDomainStrategy(t *testing.T) { t.Fatal("embedded default.json has no freedom outbound to check") } } + +type coreWarnings struct{ msgs []string } + +func (c *coreWarnings) Handle(msg corelog.Message) { c.msgs = append(c.msgs, msg.String()) } + +type discardCoreLog struct{} + +func (discardCoreLog) Handle(corelog.Message) {} + +// A deprecated key in the document is a warning in every subscriber's client on every +// load, and a hard failure once the core drops the key. +func TestJSONSubscriptionLoadsInCoreWithoutDeprecationWarning(t *testing.T) { + seedSubDB(t) + seedSubInbound(t, "core-load", "core-link", 4933, 1, tcpTLSStream) + body, _, err := NewSubJsonService("", "", "", "", NewSubService("")).GetJson("core-load", "sub.example.com", false) + if err != nil { + t.Fatalf("GetJson: %v", err) + } + var config conf.Config + if err := json.Unmarshal([]byte(body), &config); err != nil { + t.Fatalf("core cannot parse the document: %v\n%s", err, body) + } + if len(config.OutboundConfigs) != 3 { + t.Fatalf("outbounds = %d, want proxy, direct and block\n%s", len(config.OutboundConfigs), body) + } + + warnings := new(coreWarnings) + corelog.RegisterHandler(warnings) + t.Cleanup(func() { corelog.RegisterHandler(discardCoreLog{}) }) + if _, err := config.Build(); err != nil { + t.Fatalf("core rejected the document: %v\n%s", err, body) + } + for _, msg := range warnings.msgs { + if strings.Contains(msg, "deprecated") { + t.Errorf("core warning: %s", msg) + } + } +}