























@@ -73,6 +73,10 @@ function readRuntimeOutput(): string {
7373return runtime.log.mock.calls.map((entry) => readRuntimeCallText(entry)).join("\n");
7474}
757576+function readRuntimeErrorOutput(): string {
77+return runtime.error.mock.calls.map((entry) => readRuntimeCallText(entry)).join("\n");
78+}
79+7680function pendingDevice(overrides: Record<string, unknown> = {}) {
7781return {
7882requestId: "req-1",
@@ -278,9 +282,7 @@ describe("devices cli approve", () => {
278282expect(logOutput).toContain("Device Nine");
279283expect(logOutput).toContain("Approved: roles: operator; scopes: operator.read");
280284expect(logOutput).toContain("Requested scopes exceed the current approval");
281-expect(runtime.error).toHaveBeenCalledWith(
282-expect.stringContaining("openclaw devices approve req-abc"),
283-);
285+expect(readRuntimeErrorOutput()).toContain("openclaw devices approve req-abc");
284286expect(runtime.exit).toHaveBeenCalledWith(1);
285287expect(hasGatewayMethod("device.pair.approve")).toBe(false);
286288});
@@ -343,9 +345,7 @@ describe("devices cli approve", () => {
343345344346expectGatewayCall(0, { method: "device.pair.list" });
345347expect(hasGatewayMethod("device.pair.approve")).toBe(false);
346-expect(runtime.error).toHaveBeenCalledWith(
347-expect.stringContaining(`openclaw devices approve ${expectedRequestId}`),
348-);
348+expect(readRuntimeErrorOutput()).toContain(`openclaw devices approve ${expectedRequestId}`);
349349});
350350351351it("falls back to device id when selected pending display name is blank", async () => {
@@ -364,9 +364,7 @@ describe("devices cli approve", () => {
364364365365const logOutput = runtime.log.mock.calls.map((c) => readRuntimeCallText(c)).join("\n");
366366expect(logOutput).toContain("device-9");
367-expect(runtime.error).toHaveBeenCalledWith(
368-expect.stringContaining("openclaw devices approve req-blank"),
369-);
367+expect(readRuntimeErrorOutput()).toContain("openclaw devices approve req-blank");
370368expect(hasGatewayMethod("device.pair.approve")).toBe(false);
371369});
372370@@ -538,7 +536,7 @@ describe("devices cli local fallback", () => {
538536539537expectGatewayCall(0, { method: "device.pair.list" });
540538expect(listDevicePairing).toHaveBeenCalledTimes(1);
541-expect(runtime.log).toHaveBeenCalledWith(expect.stringContaining(fallbackNotice));
539+expect(readRuntimeOutput()).toContain(fallbackNotice);
542540});
543541544542it("falls back to local approve when gateway returns pairing required on loopback", async () => {
@@ -560,8 +558,8 @@ describe("devices cli local fallback", () => {
560558expect(approveDevicePairing).toHaveBeenCalledWith("req-latest", {
561559callerScopes: ["operator.admin"],
562560});
563-expect(runtime.log).toHaveBeenCalledWith(expect.stringContaining(fallbackNotice));
564-expect(runtime.log).toHaveBeenCalledWith(expect.stringContaining("Approved"));
561+expect(readRuntimeOutput()).toContain(fallbackNotice);
562+expect(readRuntimeOutput()).toContain("Approved");
565563});
566564567565it("falls back to local pairing list when gateway returns a scope upgrade message on loopback", async () => {
@@ -570,7 +568,7 @@ describe("devices cli local fallback", () => {
570568await runDevicesCommand(["list"]);
571569572570expect(listDevicePairing).toHaveBeenCalledTimes(1);
573-expect(runtime.log).toHaveBeenCalledWith(expect.stringContaining(fallbackNotice));
571+expect(readRuntimeOutput()).toContain(fallbackNotice);
574572});
575573576574it("refuses local fallback when the gateway request is absent from local pairing state", async () => {
@@ -584,7 +582,7 @@ describe("devices cli local fallback", () => {
584582await expect(runDevicesCommand(["list"])).rejects.toThrow(
585583"different OPENCLAW_PROFILE or OPENCLAW_STATE_DIR",
586584);
587-expect(runtime.log).not.toHaveBeenCalledWith(expect.stringContaining(fallbackNotice));
585+expect(readRuntimeOutput()).not.toContain(fallbackNotice);
588586});
589587590588it("refuses local approve fallback when the gateway request is absent locally", async () => {
@@ -595,7 +593,7 @@ describe("devices cli local fallback", () => {
595593await expect(runDevicesApprove(["req-profile"])).rejects.toThrow(
596594"local fallback pairing state does not contain the gateway request",
597595);
598-expect(runtime.log).not.toHaveBeenCalledWith(expect.stringContaining(fallbackNotice));
596+expect(readRuntimeOutput()).not.toContain(fallbackNotice);
599597});
600598601599it("refuses local approve fallback before approving a different local request", async () => {
@@ -606,7 +604,7 @@ describe("devices cli local fallback", () => {
606604"local fallback pairing state does not contain the gateway request",
607605);
608606expect(approveDevicePairing).not.toHaveBeenCalled();
609-expect(runtime.log).not.toHaveBeenCalledWith(expect.stringContaining(fallbackNotice));
607+expect(readRuntimeOutput()).not.toContain(fallbackNotice);
610608});
611609612610it("does not use local fallback when an explicit --url is provided", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。