






















@@ -27,7 +27,9 @@ let lastClientOptions: {
2727token?: string;
2828password?: string;
2929tlsFingerprint?: string;
30+clientName?: string;
3031clientDisplayName?: string;
32+mode?: string;
3133scopes?: string[];
3234deviceIdentity?: unknown;
3335onHelloOk?: (hello: { features?: { methods?: string[] } }) => void | Promise<void>;
@@ -59,7 +61,9 @@ vi.mock("./client.js", () => ({
5961url?: string;
6062token?: string;
6163password?: string;
64+clientName?: string;
6265clientDisplayName?: string;
66+mode?: string;
6367scopes?: string[];
6468onHelloOk?: (hello: { features?: { methods?: string[] } }) => void | Promise<void>;
6569onClose?: (code: number, reason: string) => void;
@@ -97,7 +101,9 @@ class StubGatewayClient {
97101url?: string;
98102token?: string;
99103password?: string;
104+clientName?: string;
100105clientDisplayName?: string;
106+mode?: string;
101107scopes?: string[];
102108onHelloOk?: (hello: { features?: { methods?: string[] } }) => void | Promise<void>;
103109onClose?: (code: number, reason: string) => void;
@@ -303,14 +309,31 @@ describe("callGateway url resolution", () => {
303309expect(lastClientOptions?.token).toBe("test-token");
304310});
305311306-it("keeps device identity enabled for local loopback shared-token auth", async () => {
312+it("keeps direct-local backend shared-token auth independent of paired device state", async () => {
307313setLocalLoopbackGatewayConfig();
308314309315await callGateway({
310316method: "health",
311317token: "explicit-token",
312318});
313319320+expect(lastClientOptions?.url).toBe("ws://127.0.0.1:18789");
321+expect(lastClientOptions?.token).toBe("explicit-token");
322+expect(lastClientOptions?.clientName).toBe(GATEWAY_CLIENT_NAMES.GATEWAY_CLIENT);
323+expect(lastClientOptions?.mode).toBe(GATEWAY_CLIENT_MODES.BACKEND);
324+expect(lastClientOptions?.deviceIdentity).toBeNull();
325+});
326+327+it("keeps device identity enabled for explicit CLI loopback shared-token auth", async () => {
328+setLocalLoopbackGatewayConfig();
329+330+await callGateway({
331+method: "health",
332+token: "explicit-token",
333+clientName: GATEWAY_CLIENT_NAMES.CLI,
334+mode: GATEWAY_CLIENT_MODES.CLI,
335+});
336+314337expect(lastClientOptions?.url).toBe("ws://127.0.0.1:18789");
315338expect(lastClientOptions?.token).toBe("explicit-token");
316339expect(lastClientOptions?.deviceIdentity).toEqual(deviceIdentityState.value);
@@ -331,6 +354,22 @@ describe("callGateway url resolution", () => {
331354expect(lastRequestOptions?.method).toBe("health");
332355});
333356357+it("keeps backend device identity enabled for remote shared-token auth", async () => {
358+loadConfig.mockReturnValue(makeRemotePasswordGatewayConfig("remote-password"));
359+setGatewayNetworkDefaults();
360+361+await callGateway({
362+method: "health",
363+token: "explicit-token",
364+});
365+366+expect(lastClientOptions?.url).toBe("wss://remote.example:18789");
367+expect(lastClientOptions?.token).toBe("explicit-token");
368+expect(lastClientOptions?.clientName).toBe(GATEWAY_CLIENT_NAMES.GATEWAY_CLIENT);
369+expect(lastClientOptions?.mode).toBe(GATEWAY_CLIENT_MODES.BACKEND);
370+expect(lastClientOptions?.deviceIdentity).toEqual(deviceIdentityState.value);
371+});
372+334373it("honors an explicit null device identity override", async () => {
335374setLocalLoopbackGatewayConfig();
336375@@ -470,6 +509,22 @@ describe("callGateway url resolution", () => {
470509expect(lastClientOptions?.scopes).toEqual([]);
471510});
472511512+it("uses backend client metadata for explicit scoped default calls", async () => {
513+setLocalLoopbackGatewayConfig();
514+515+await callGateway({
516+method: "sessions.delete",
517+scopes: ["operator.admin"],
518+token: "explicit-token",
519+});
520+521+expect(lastClientOptions?.clientName).toBe(GATEWAY_CLIENT_NAMES.GATEWAY_CLIENT);
522+expect(lastClientOptions?.mode).toBe(GATEWAY_CLIENT_MODES.BACKEND);
523+expect(lastClientOptions?.clientDisplayName).toBe("gateway:sessions.delete");
524+expect(lastClientOptions?.scopes).toEqual(["operator.admin"]);
525+expect(lastClientOptions?.deviceIdentity).toBeNull();
526+});
527+473528it("labels default backend calls with the requested method", async () => {
474529setLocalLoopbackGatewayConfig();
475530此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。