




















@@ -735,6 +735,54 @@ describe("gateway bonjour advertiser", () => {
735735await started.stop();
736736});
737737738+it("truncates service name exceeding 63-byte DNS label limit", async () => {
739+const longHostname = "app-41627eae5842473f9e05f139ea307277-7f9477f4d6-lqqzf";
740+enableAdvertiserUnitMode(longHostname);
741+742+const destroy = vi.fn().mockResolvedValue(undefined);
743+const advertise = vi.fn().mockResolvedValue(undefined);
744+mockCiaoService({ advertise, destroy });
745+746+const started = await startAdvertiser({
747+gatewayPort: 18789,
748+sshPort: 2222,
749+});
750+751+const [gatewayCall] = createService.mock.calls as Array<[ServiceCall]>;
752+const serviceName = gatewayCall?.[0]?.name as string;
753+const hostname = gatewayCall?.[0]?.hostname as string;
754+755+// Both name and hostname must be within the 63-byte DNS label limit
756+expect(new TextEncoder().encode(serviceName).byteLength).toBeLessThanOrEqual(63);
757+expect(new TextEncoder().encode(hostname).byteLength).toBeLessThanOrEqual(63);
758+759+await started.stop();
760+});
761+762+it("truncates multi-byte hostname within DNS label byte limit", async () => {
763+// 21 CJK characters = 63 bytes in UTF-8, adding " (OpenClaw)" pushes over
764+const cjkHostname = "你".repeat(21);
765+enableAdvertiserUnitMode(cjkHostname);
766+767+const destroy = vi.fn().mockResolvedValue(undefined);
768+const advertise = vi.fn().mockResolvedValue(undefined);
769+mockCiaoService({ advertise, destroy });
770+771+const started = await startAdvertiser({
772+gatewayPort: 18789,
773+sshPort: 2222,
774+});
775+776+const [gatewayCall] = createService.mock.calls as Array<[ServiceCall]>;
777+const serviceName = gatewayCall?.[0]?.name as string;
778+779+expect(new TextEncoder().encode(serviceName).byteLength).toBeLessThanOrEqual(63);
780+// Should not end with a replacement character from incomplete multi-byte truncation
781+expect(serviceName).not.toMatch(/\uFFFD$/);
782+783+await started.stop();
784+});
785+738786it("uses system hostname when OPENCLAW_MDNS_HOSTNAME is unset", async () => {
739787// Allow advertiser to run in unit tests.
740788delete process.env.VITEST;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。