
























@@ -7,6 +7,7 @@ const mocks = vi.hoisted(() => ({
77callGatewayCli: vi.fn(async (_method: string, _opts: unknown, _params?: unknown) => ({
88ok: true,
99})),
10+emitReachableGatewayAuthDiagnostic: vi.fn(async (_params: unknown) => false),
1011gatewayStatusCommand: vi.fn(async (_opts: unknown, _runtime: unknown) => {}),
1112defaultRuntime: {
1213log: vi.fn(),
@@ -17,7 +18,8 @@ const mocks = vi.hoisted(() => ({
1718},
1819}));
192020-const { callGatewayCli, gatewayStatusCommand, defaultRuntime } = mocks;
21+const { callGatewayCli, emitReachableGatewayAuthDiagnostic, gatewayStatusCommand, defaultRuntime } =
22+mocks;
21232224vi.mock("../cli-utils.js", () => ({
2325runCommandWithRuntime: async (
@@ -59,6 +61,7 @@ vi.mock("./call.js", () => ({
5961vi.mock("./run-command.js", () => ({
6062addGatewayRunCommand: (cmd: Command) =>
6163cmd
64+.option("--port <port>", "Port for the gateway WebSocket")
6265.option("--token <token>", "Gateway token")
6366.option("--password <password>", "Gateway password"),
6467}));
@@ -68,6 +71,8 @@ vi.mock("../daemon-cli/register-service-commands.js", () => ({
6871}));
69727073vi.mock("../../commands/health.js", () => ({
74+emitReachableGatewayAuthDiagnostic: (params: unknown) =>
75+mocks.emitReachableGatewayAuthDiagnostic(params),
7176formatHealthChannelLines: () => [],
7277}));
7378@@ -141,6 +146,7 @@ describe("gateway register option collisions", () => {
141146142147beforeEach(() => {
143148callGatewayCli.mockClear();
149+emitReachableGatewayAuthDiagnostic.mockClear();
144150gatewayStatusCommand.mockClear();
145151defaultRuntime.log.mockClear();
146152defaultRuntime.error.mockClear();
@@ -171,6 +177,58 @@ describe("gateway register option collisions", () => {
171177expect(runtime).toBe(defaultRuntime);
172178},
173179},
180+{
181+name: "forwards --port to gateway probe",
182+argv: ["gateway", "probe", "--port", "19080", "--json"],
183+assert: () => {
184+expect(gatewayStatusCommand).toHaveBeenCalledTimes(1);
185+const [opts] = firstGatewayStatusCall();
186+expect((opts as { port?: string } | undefined)?.port).toBe("19080");
187+},
188+},
189+{
190+name: "inherits parent --port for gateway probe",
191+argv: ["gateway", "--port", "19082", "probe", "--json"],
192+assert: () => {
193+expect(gatewayStatusCommand).toHaveBeenCalledTimes(1);
194+const [opts] = firstGatewayStatusCall();
195+expect((opts as { port?: string } | undefined)?.port).toBe("19082");
196+},
197+},
198+{
199+name: "projects gateway health --port into local config",
200+argv: ["gateway", "health", "--port", "19081", "--json"],
201+assert: () => {
202+expect(defaultRuntime.error.mock.calls).toEqual([]);
203+expect(callGatewayCli).toHaveBeenCalledTimes(1);
204+const [method, opts] = firstGatewayCall();
205+expect(method).toBe("health");
206+const gatewayOpts = opts as
207+| { config?: { gateway?: { port?: number } }; localPortOverride?: number }
208+| undefined;
209+expect(gatewayOpts?.localPortOverride).toBe(19081);
210+expect(gatewayOpts?.config).toEqual({
211+gateway: { mode: "local", port: 19081 },
212+});
213+},
214+},
215+{
216+name: "inherits parent --port for gateway health",
217+argv: ["gateway", "--port", "19083", "health", "--json"],
218+assert: () => {
219+expect(defaultRuntime.error.mock.calls).toEqual([]);
220+expect(callGatewayCli).toHaveBeenCalledTimes(1);
221+const [method, opts] = firstGatewayCall();
222+expect(method).toBe("health");
223+const gatewayOpts = opts as
224+| { config?: { gateway?: { port?: number } }; localPortOverride?: number }
225+| undefined;
226+expect(gatewayOpts?.localPortOverride).toBe(19083);
227+expect(gatewayOpts?.config).toEqual({
228+gateway: { mode: "local", port: 19083 },
229+});
230+},
231+},
174232{
175233name: "passes decimal usage-cost --days values",
176234argv: ["gateway", "usage-cost", "--days", "7", "--json"],
@@ -195,4 +253,28 @@ describe("gateway register option collisions", () => {
195253await sharedProgram.parseAsync(argv, { from: "user" });
196254assert();
197255});
256+257+it("uses the effective local port config for gateway health auth diagnostics", async () => {
258+const authError = new Error("gateway auth required");
259+callGatewayCli.mockRejectedValueOnce(authError);
260+emitReachableGatewayAuthDiagnostic.mockResolvedValueOnce(true);
261+262+await sharedProgram.parseAsync(["gateway", "health", "--port", "19081", "--json"], {
263+from: "user",
264+});
265+266+expect(emitReachableGatewayAuthDiagnostic).toHaveBeenCalledTimes(1);
267+expect(emitReachableGatewayAuthDiagnostic).toHaveBeenCalledWith({
268+error: authError,
269+config: {
270+gateway: { mode: "local", port: 19081 },
271+},
272+runtime: defaultRuntime,
273+timeoutMs: 10000,
274+token: undefined,
275+password: undefined,
276+localPortOverride: 19081,
277+json: true,
278+});
279+});
198280});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。