[PR #6740] [MERGED] fix(sub): append host serverDescription to hysteria links #6438

Closed
opened 2026-11-02 04:08:46 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6740
Author: @AyaseEli-Bing
Created: 10/5/2026
Status: ✅ Merged
Merged: 10/5/2026
Merged by: @MHSanaei

Base: main ← Head: fix/sub-hysteria-server-description


📝 Commits (2)

  • 4bfbcf8 fix(sub): append host serverDescription to hysteria links
  • 1439d59 chore(sub): trim the hysteria serverDescription regression test

📊 Changes

2 files changed (+62 additions, -1 deletions)

View changed files

➕ internal/sub/hysteria_server_description_test.go (+57 -0)
📝 internal/sub/service.go (+5 -1)

📄 Description

Summary

hysteria:// and hysteria2:// subscription links now carry the host's ?serverDescription=<base64> suffix, the same way vless://, trojan:// and ss:// already do. Closes #6738.

AI assistance disclosure: this change was produced by an AI coding agent (Qoder) at the request of the account owner, who reviewed the diff and the test. CLAUDE.md describes itself as an "Operational guide for AI agents working in this repo", so I assumed agent-authored PRs are welcome here — flagging it explicitly so a reviewer can treat it accordingly. The commit itself is authored by the account owner.

Why

A host attached to both a VLESS and a Hysteria2 inbound showed the custom caption on the VLESS line and the client default ("Hysteria | hysteria | TLS") on the Hysteria2 line, so Happ users saw inconsistent names for the same server.

Root cause: genHysteriaLink fans out over externalProxy in its own loop and builds the fragment from s.endpointRemark(...), while the URL-param protocols go through buildEndpointLinks, which appends appendHappServerDescription when the endpoint carries a description (internal/sub/endpoint.go:138-141). The description itself does reach the Hysteria path — host_sub.go:113-115 puts it on the endpoint map — the loop just never read it. escapeLinkFragment was not the problem: it already keeps a valid ?serverDescription= tail intact, which is why #6575's fix did not cover this.

The fix reuses appendHappServerDescription and the ServerDescription the endpoint map is already parsed into, so no key lookup is duplicated. A host without a description emits byte-identical output (appendHappServerDescription returns the remark unchanged for an empty description).

Type of change

  • Bug fix
  • Tests only (new regression test)

Areas affected

  • Subscription (share links / Clash / JSON)

How was this tested?

TDD, following CLAUDE.md (red → green → prove the test can fail):

  1. Added internal/sub/hysteria_server_description_test.go first and ran it against unmodified code — both sub-cases failed with exactly the reported symptom, hysteria2://secret@hy.example.com:443?security=tls#hy-Poland-user missing the suffix.
  2. Applied the fix; both cases pass, each asserting the exact suffix ?serverDescription=V2ktRmk= (base64 of Wi-Fi, taken from the reporter's own subscription output) and the scheme prefix, so a hysteria:// (v1) and a hysteria2:// (v2) link are both covered.
  3. Reverted only internal/sub/service.go and re-ran: the test goes red again with "host serverDescription missing from fragment", then restored it. The test is not a stand-in — it fails without the change.
  4. A second test pins the no-description path: a legacy externalProxy entry with no host description must not gain a serverDescription param and must keep hysteria2://secret@cdn.example.com:8443.

Commands run locally (go1.27.1, CGO_ENABLED=1, macOS arm64):

  • make lint-go → golangci-lint run → 0 issues.
  • make test-go → full Go suite, 49 packages ok, no failures (includes internal/sub's characterization tests, which pin existing hysteria output).
  • CGO_ENABLED=1 go test ./internal/sub/ alone: ok.

Not run locally, and CI covers them: the frontend gates of make verify (gen-check, lint-fe, typecheck) — this change adds no route, model or type, so the generated Zod/OpenAPI artifacts are unaffected; also make race, the Postgres job and the live master+node e2e (XUI_NODE_E2E_BINARY). I did not run a live panel with a real Happ client; the unit tests reproduce the reporter's exact link shape instead.

One thing I deliberately left out

genTuicLink (internal/sub/service.go:912) has the identical gap: its own externalProxy loop renders the fragment through endpointRemark without appending the description, so tuic:// links lose the host description the same way. I kept it out to leave this diff to the reported protocol — say the word and I will fold it into this PR or send a separate one.

Breaking changes

None. Only an added URI fragment on links whose host has a Description set; clients that already parsed the suffix for VLESS parse it the same way here.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally. (make test-go green; go build ./... clean)
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass. — N/A, no frontend files touched.
  • I updated the Wiki / README / API docs if user-facing behavior changed. — N/A: this restores the documented serverDescription behavior rather than changing it; no API surface moved.
  • My commits follow the project's existing message style. (fix(sub): …, conventional commit with a why-body)
  • I have no unrelated changes mixed into this PR. (one 5-line code change + one new test file)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6740 **Author:** [@AyaseEli-Bing](https://github.com/AyaseEli-Bing) **Created:** 10/5/2026 **Status:** ✅ Merged **Merged:** 10/5/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/sub-hysteria-server-description` --- ### 📝 Commits (2) - [`4bfbcf8`](https://github.com/MHSanaei/3x-ui/commit/4bfbcf8e47fe7954558c46dde7a1790ed65af514) fix(sub): append host serverDescription to hysteria links - [`1439d59`](https://github.com/MHSanaei/3x-ui/commit/1439d595d76baea983813c1da4d2f77fe9492a19) chore(sub): trim the hysteria serverDescription regression test ### 📊 Changes **2 files changed** (+62 additions, -1 deletions) <details> <summary>View changed files</summary> ➕ `internal/sub/hysteria_server_description_test.go` (+57 -0) 📝 `internal/sub/service.go` (+5 -1) </details> ### 📄 Description ## Summary `hysteria://` and `hysteria2://` subscription links now carry the host's `?serverDescription=<base64>` suffix, the same way `vless://`, `trojan://` and `ss://` already do. Closes #6738. **AI assistance disclosure:** this change was produced by an AI coding agent (Qoder) at the request of the account owner, who reviewed the diff and the test. `CLAUDE.md` describes itself as an "Operational guide for AI agents working in this repo", so I assumed agent-authored PRs are welcome here — flagging it explicitly so a reviewer can treat it accordingly. The commit itself is authored by the account owner. ## Why A host attached to both a VLESS and a Hysteria2 inbound showed the custom caption on the VLESS line and the client default ("Hysteria | hysteria | TLS") on the Hysteria2 line, so Happ users saw inconsistent names for the same server. Root cause: `genHysteriaLink` fans out over `externalProxy` in its own loop and builds the fragment from `s.endpointRemark(...)`, while the URL-param protocols go through `buildEndpointLinks`, which appends `appendHappServerDescription` when the endpoint carries a description (`internal/sub/endpoint.go:138-141`). The description itself does reach the Hysteria path — `host_sub.go:113-115` puts it on the endpoint map — the loop just never read it. `escapeLinkFragment` was not the problem: it already keeps a valid `?serverDescription=` tail intact, which is why #6575's fix did not cover this. The fix reuses `appendHappServerDescription` and the `ServerDescription` the endpoint map is already parsed into, so no key lookup is duplicated. A host without a description emits byte-identical output (`appendHappServerDescription` returns the remark unchanged for an empty description). ## Type of change - [x] Bug fix - [x] Tests only (new regression test) ## Areas affected - [x] Subscription (share links / Clash / JSON) ## How was this tested? TDD, following `CLAUDE.md` (red → green → prove the test can fail): 1. Added `internal/sub/hysteria_server_description_test.go` first and ran it against unmodified code — both sub-cases failed with exactly the reported symptom, `hysteria2://secret@hy.example.com:443?security=tls#hy-Poland-user` missing the suffix. 2. Applied the fix; both cases pass, each asserting the exact suffix `?serverDescription=V2ktRmk=` (base64 of `Wi-Fi`, taken from the reporter's own subscription output) and the scheme prefix, so a `hysteria://` (v1) and a `hysteria2://` (v2) link are both covered. 3. Reverted only `internal/sub/service.go` and re-ran: the test goes red again with "host serverDescription missing from fragment", then restored it. The test is not a stand-in — it fails without the change. 4. A second test pins the no-description path: a legacy `externalProxy` entry with no host description must not gain a `serverDescription` param and must keep `hysteria2://secret@cdn.example.com:8443`. Commands run locally (go1.27.1, CGO_ENABLED=1, macOS arm64): - `make lint-go` → `golangci-lint run` → `0 issues.` - `make test-go` → full Go suite, 49 packages `ok`, no failures (includes `internal/sub`'s characterization tests, which pin existing hysteria output). - `CGO_ENABLED=1 go test ./internal/sub/` alone: ok. Not run locally, and CI covers them: the frontend gates of `make verify` (`gen-check`, `lint-fe`, `typecheck`) — this change adds no route, model or type, so the generated Zod/OpenAPI artifacts are unaffected; also `make race`, the Postgres job and the live master+node e2e (`XUI_NODE_E2E_BINARY`). I did not run a live panel with a real Happ client; the unit tests reproduce the reporter's exact link shape instead. ## One thing I deliberately left out `genTuicLink` (`internal/sub/service.go:912`) has the identical gap: its own `externalProxy` loop renders the fragment through `endpointRemark` without appending the description, so `tuic://` links lose the host description the same way. I kept it out to leave this diff to the reported protocol — say the word and I will fold it into this PR or send a separate one. ## Breaking changes None. Only an added URI fragment on links whose host has a Description set; clients that already parsed the suffix for VLESS parse it the same way here. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. (`make test-go` green; `go build ./...` clean) - [ ] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. — N/A, no frontend files touched. - [ ] I updated the Wiki / README / API docs if user-facing behavior changed. — N/A: this restores the documented `serverDescription` behavior rather than changing it; no API surface moved. - [x] My commits follow the project's existing message style. (`fix(sub): …`, conventional commit with a why-body) - [x] I have no unrelated changes mixed into this PR. (one 5-line code change + one new test file) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:08:46 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6438
No description provided.