





















@@ -263,6 +263,10 @@ function createRuntime() {
263263};
264264}
265265266+function parseFirstJsonLog(runtimeLike: { log: Mock }) {
267+return JSON.parse(String(runtimeLike.log.mock.calls.at(0)?.[0]));
268+}
269+266270function requireRecord(value: unknown, label: string): Record<string, unknown> {
267271if (typeof value !== "object" || value === null) {
268272throw new Error(`${label} was not an object`);
@@ -358,7 +362,7 @@ async function withAgentScopeOverrides<T>(
358362describe("modelsStatusCommand auth overview", () => {
359363it("includes masked auth sources in JSON output", async () => {
360364await modelsStatusCommand({ json: true }, runtime as never);
361-const payload = JSON.parse(String((runtime.log as Mock).mock.calls[0]?.[0]));
365+const payload = parseFirstJsonLog(runtime);
362366363367expectResolveAgentDirCalledFor("main");
364368expect(mocks.ensureAuthProfileStore).toHaveBeenCalled();
@@ -425,7 +429,7 @@ describe("modelsStatusCommand auth overview", () => {
425429426430expect(mocks.resolveAgentDir).not.toHaveBeenCalled();
427431expect(mocks.ensureAuthProfileStore).toHaveBeenCalledWith("/tmp/openclaw-isolated-agent");
428-const payload = JSON.parse(String((localRuntime.log as Mock).mock.calls[0]?.[0]));
432+const payload = parseFirstJsonLog(localRuntime);
429433expect(payload.agentDir).toBe("/tmp/openclaw-isolated-agent");
430434expect(payload.auth.storePath).toBe("/tmp/openclaw-isolated-agent/auth-profiles.json");
431435});
@@ -441,7 +445,7 @@ describe("modelsStatusCommand auth overview", () => {
441445async () => {
442446await modelsStatusCommand({ json: true, agent: "Jeremiah" }, localRuntime as never);
443447expectResolveAgentDirCalledFor("jeremiah");
444-const payload = JSON.parse(String((localRuntime.log as Mock).mock.calls[0]?.[0]));
448+const payload = parseFirstJsonLog(localRuntime);
445449expect(payload.agentId).toBe("jeremiah");
446450expect(payload.agentDir).toBe("/tmp/openclaw-agent-custom");
447451expect(payload.defaultModel).toBe("openai/gpt-4");
@@ -493,7 +497,7 @@ describe("modelsStatusCommand auth overview", () => {
493497494498try {
495499await modelsStatusCommand({ json: true, check: true }, localRuntime as never);
496-const payload = JSON.parse(String((localRuntime.log as Mock).mock.calls[0]?.[0]));
500+const payload = parseFirstJsonLog(localRuntime);
497501expect(payload.auth.missingProvidersInUse).toStrictEqual([]);
498502expect(localRuntime.exit).not.toHaveBeenCalledWith(1);
499503} finally {
@@ -586,7 +590,7 @@ describe("modelsStatusCommand auth overview", () => {
586590587591try {
588592await modelsStatusCommand({ json: true, check: true }, localRuntime as never);
589-const payload = JSON.parse(String((localRuntime.log as Mock).mock.calls[0]?.[0]));
593+const payload = parseFirstJsonLog(localRuntime);
590594expect(payload.auth.missingProvidersInUse).toEqual([]);
591595expect(requireProfile(payload.auth.oauth.profiles, "openai-codex:default").status).toBe(
592596"expired",
@@ -666,7 +670,7 @@ describe("modelsStatusCommand auth overview", () => {
666670667671try {
668672await modelsStatusCommand({ json: true, check: true }, localRuntime as never);
669-const payload = JSON.parse(String((localRuntime.log as Mock).mock.calls[0]?.[0]));
673+const payload = parseFirstJsonLog(localRuntime);
670674expect(payload.auth.missingProvidersInUse).toEqual([]);
671675expect(localRuntime.exit).toHaveBeenCalledWith(1);
672676} finally {
@@ -751,7 +755,7 @@ describe("modelsStatusCommand auth overview", () => {
751755752756try {
753757await modelsStatusCommand({ json: true, check: true }, localRuntime as never);
754-const payload = JSON.parse(String((localRuntime.log as Mock).mock.calls[0]?.[0]));
758+const payload = parseFirstJsonLog(localRuntime);
755759expect(payload.resolvedDefault).toBe("anthropic/claude-opus-4-6");
756760expect(localRuntime.exit).toHaveBeenCalledWith(1);
757761} finally {
@@ -821,7 +825,7 @@ describe("modelsStatusCommand auth overview", () => {
821825822826try {
823827await modelsStatusCommand({ json: true, check: true }, localRuntime as never);
824-const payload = JSON.parse(String((localRuntime.log as Mock).mock.calls[0]?.[0]));
828+const payload = parseFirstJsonLog(localRuntime);
825829expect(
826830requireRecord(requireProvider(payload.auth.providers, "anthropic").env, "anthropic env")
827831.source,
@@ -875,7 +879,7 @@ describe("modelsStatusCommand auth overview", () => {
875879876880try {
877881await modelsStatusCommand({ json: true, check: true }, localRuntime as never);
878-const payload = JSON.parse(String((localRuntime.log as Mock).mock.calls[0]?.[0]));
882+const payload = parseFirstJsonLog(localRuntime);
879883expect(payload.auth.missingProvidersInUse).toEqual(["anthropic"]);
880884expect(localRuntime.exit).toHaveBeenCalledWith(1);
881885} finally {
@@ -926,7 +930,7 @@ describe("modelsStatusCommand auth overview", () => {
926930mocks.resolveUsableCustomProviderApiKey.mockImplementation(() => null);
927931try {
928932await modelsStatusCommand({ json: true, check: true }, localRuntime as never);
929-const payload = JSON.parse(String((localRuntime.log as Mock).mock.calls[0]?.[0]));
933+const payload = parseFirstJsonLog(localRuntime);
930934expect(payload.auth.missingProvidersInUse).toEqual(["anthropic"]);
931935expect(
932936mocks.resolveUsableCustomProviderApiKey.mock.calls.some(
@@ -991,7 +995,7 @@ describe("modelsStatusCommand auth overview", () => {
991995992996try {
993997await modelsStatusCommand({ json: true, check: true }, localRuntime as never);
994-const payload = JSON.parse(String((localRuntime.log as Mock).mock.calls[0]?.[0]));
998+const payload = parseFirstJsonLog(localRuntime);
995999expect(payload.auth.missingProvidersInUse).toEqual(["openai"]);
9961000expect(localRuntime.exit).toHaveBeenCalledWith(1);
9971001} finally {
@@ -1025,7 +1029,7 @@ describe("modelsStatusCommand auth overview", () => {
1025102910261030try {
10271031await modelsStatusCommand({ json: true }, localRuntime as never);
1028-const payload = JSON.parse(String((localRuntime.log as Mock).mock.calls[0]?.[0]));
1032+const payload = parseFirstJsonLog(localRuntime);
1029103310301034expect(payload.defaultModel).toBe("openrouter/auto");
10311035expect(payload.resolvedDefault).toBe("openrouter/auto");
@@ -1055,7 +1059,7 @@ describe("modelsStatusCommand auth overview", () => {
1055105910561060try {
10571061await modelsStatusCommand({ json: true }, localRuntime as never);
1058-const payload = JSON.parse(String((localRuntime.log as Mock).mock.calls[0]?.[0]));
1062+const payload = parseFirstJsonLog(localRuntime);
10591063expect(payload.defaultModel).toBe("claude-cli/claude-sonnet-4-6");
10601064expect(payload.auth.missingProvidersInUse).toStrictEqual([]);
10611065@@ -1080,7 +1084,7 @@ describe("modelsStatusCommand auth overview", () => {
10801084return null;
10811085});
10821086await modelsStatusCommand({ json: true }, aliasRuntime as never);
1083-const aliasPayload = JSON.parse(String((aliasRuntime.log as Mock).mock.calls[0]?.[0]));
1087+const aliasPayload = parseFirstJsonLog(aliasRuntime);
10841088const providers = aliasPayload.auth.providers as Array<{ provider: string }>;
10851089expect(
10861090providers.reduce((count, provider) => count + (provider.provider === "zai" ? 1 : 0), 0),
@@ -1134,7 +1138,7 @@ describe("modelsStatusCommand auth overview", () => {
1134113811351139try {
11361140await modelsStatusCommand({ json: true }, localRuntime as never);
1137-const payload = JSON.parse(String((localRuntime.log as Mock).mock.calls[0]?.[0]));
1141+const payload = parseFirstJsonLog(localRuntime);
11381142const providers = payload.auth.providers as Array<{
11391143provider: string;
11401144syntheticAuth?: { value: string; source: string };
@@ -1203,7 +1207,7 @@ describe("modelsStatusCommand auth overview", () => {
1203120712041208try {
12051209await modelsStatusCommand({ json: true, check: true }, localRuntime as never);
1206-const payload = JSON.parse(String((localRuntime.log as Mock).mock.calls[0]?.[0]));
1210+const payload = parseFirstJsonLog(localRuntime);
12071211expect(payload.auth.missingProvidersInUse).toEqual(["codex"]);
12081212expect(localRuntime.exit).toHaveBeenCalledWith(1);
12091213} finally {
@@ -1261,7 +1265,7 @@ describe("modelsStatusCommand auth overview", () => {
1261126512621266try {
12631267await modelsStatusCommand({ json: true }, localRuntime as never);
1264-const payload = JSON.parse(String((localRuntime.log as Mock).mock.calls[0]?.[0]));
1268+const payload = parseFirstJsonLog(localRuntime);
12651269const workspaceProvider = requireProvider(payload.auth.providers, "workspace-cloud");
12661270expect(requireRecord(workspaceProvider.effective, "workspace effective auth").kind).toBe(
12671271"env",
@@ -1303,7 +1307,7 @@ describe("modelsStatusCommand auth overview", () => {
1303130713041308const jsonRuntime = createRuntime();
13051309await modelsStatusCommand({ json: true, agent: "main" }, jsonRuntime as never);
1306-const payload = JSON.parse(String((jsonRuntime.log as Mock).mock.calls[0]?.[0]));
1310+const payload = parseFirstJsonLog(jsonRuntime);
13071311expect(payload.modelConfig).toEqual({
13081312defaultSource: "defaults",
13091313fallbacksSource: "defaults",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。