



















@@ -173,26 +173,80 @@ describe("agentCliCommand", () => {
173173174174expect(callGateway).toHaveBeenCalledTimes(1);
175175expect(agentCommand).toHaveBeenCalledTimes(1);
176+expect(agentCommand.mock.calls[0]?.[0]).toMatchObject({
177+resultMetaOverrides: {
178+transport: "embedded",
179+fallbackFrom: "gateway",
180+},
181+});
182+expect(runtime.error).toHaveBeenCalledWith(
183+expect.stringContaining("EMBEDDED FALLBACK: Gateway agent failed"),
184+);
176185expect(runtime.log).toHaveBeenCalledWith("local");
177186});
178187});
179188180-it("keeps diagnostics on stderr before JSON embedded fallback", async () => {
189+it("passes fallback metadata into JSON embedded fallback output", async () => {
181190await withTempStore(async () => {
182191callGateway.mockRejectedValue(new Error("gateway not connected"));
183-agentCommand.mockImplementationOnce(async (_opts, rt) => {
192+agentCommand.mockImplementationOnce(async (opts, rt) => {
184193expect(loggingState.forceConsoleToStderr).toBe(true);
185-rt?.log?.("local");
194+const resultMetaOverrides = (
195+opts as {
196+resultMetaOverrides?: { transport?: string; fallbackFrom?: string };
197+}
198+).resultMetaOverrides;
199+const meta = {
200+durationMs: 1,
201+agentMeta: { sessionId: "s", provider: "p", model: "m" },
202+ ...resultMetaOverrides,
203+};
204+rt?.log?.(
205+JSON.stringify(
206+{
207+payloads: [{ text: "local" }],
208+ meta,
209+},
210+null,
211+2,
212+),
213+);
186214return {
187215payloads: [{ text: "local" }],
188-meta: { durationMs: 1, agentMeta: { sessionId: "s", provider: "p", model: "m" } },
216+ meta,
189217} as unknown as Awaited<ReturnType<typeof AgentCommand>>;
190218});
191219192-await agentCliCommand({ message: "hi", to: "+1555", json: true }, jsonRuntime);
220+const result = await agentCliCommand({ message: "hi", to: "+1555", json: true }, jsonRuntime);
193221194222expect(agentCommand).toHaveBeenCalledTimes(1);
223+expect(agentCommand.mock.calls[0]?.[0]).toMatchObject({
224+resultMetaOverrides: {
225+transport: "embedded",
226+fallbackFrom: "gateway",
227+},
228+});
229+expect(jsonRuntime.error).toHaveBeenCalledWith(
230+expect.stringContaining("EMBEDDED FALLBACK: Gateway agent failed"),
231+);
195232expect(loggingState.forceConsoleToStderr).toBe(true);
233+expect(jsonRuntime.log).toHaveBeenCalledTimes(1);
234+const payload = JSON.parse(String(jsonRuntime.log.mock.calls[0]?.[0]));
235+expect(payload).toMatchObject({
236+payloads: [{ text: "local" }],
237+meta: {
238+durationMs: 1,
239+transport: "embedded",
240+fallbackFrom: "gateway",
241+},
242+});
243+expect(result).toMatchObject({
244+meta: {
245+durationMs: 1,
246+transport: "embedded",
247+fallbackFrom: "gateway",
248+},
249+});
196250});
197251});
198252@@ -214,6 +268,7 @@ describe("agentCliCommand", () => {
214268expect(agentCommand.mock.calls[0]?.[0]).toMatchObject({
215269cleanupBundleMcpOnRunEnd: true,
216270});
271+expect(agentCommand.mock.calls[0]?.[0]).not.toHaveProperty("resultMetaOverrides");
217272expect(runtime.log).toHaveBeenCalledWith("local");
218273});
219274});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。