惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

月光博客
月光博客
人人都是产品经理
人人都是产品经理
博客园 - 聂微东
WordPress大学
WordPress大学
S
SegmentFault 最新的问题
博客园 - Franky
V
V2EX
Y
Y Combinator Blog
Google DeepMind News
Google DeepMind News
J
Java Code Geeks
T
The Blog of Author Tim Ferriss
罗磊的独立博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Jina AI
Jina AI
博客园 - 叶小钗
F
Fortinet All Blogs
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
A
About on SuperTechFans
M
MIT News - Artificial intelligence
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
D
Docker
博客园 - 【当耐特】
阮一峰的网络日志
阮一峰的网络日志

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
feat(models): list auth profiles · openclaw/openclaw@23eb44b
vincentkoc · 2026-05-04 · via Recent Commits to openclaw:main

@@ -0,0 +1,127 @@

1+

import { beforeEach, describe, expect, it, vi } from "vitest";

2+

import type { AuthProfileStore } from "../../agents/auth-profiles.js";

3+

import type { OpenClawConfig } from "../../config/types.openclaw.js";

4+

import type { OutputRuntimeEnv } from "../../runtime.js";

5+

import { modelsAuthListCommand } from "./auth-list.js";

6+7+

const mocks = vi.hoisted(() => ({

8+

ensureAuthProfileStore: vi.fn(),

9+

externalCliDiscoveryForProviderAuth: vi.fn(() => ({ kind: "none" })),

10+

loadModelsConfig: vi.fn(),

11+

resolveAuthProfileDisplayLabel: vi.fn(({ profileId }: { profileId: string }) => profileId),

12+

resolveKnownAgentId: vi.fn(({ rawAgentId }: { rawAgentId?: string }) => rawAgentId ?? undefined),

13+

}));

14+15+

vi.mock("../../agents/agent-scope.js", () => ({

16+

resolveAgentDir: (_cfg: OpenClawConfig, agentId: string) => `/tmp/openclaw/agents/${agentId}`,

17+

resolveDefaultAgentId: () => "main",

18+

}));

19+20+

vi.mock("../../agents/auth-profiles.js", () => ({

21+

ensureAuthProfileStore: mocks.ensureAuthProfileStore,

22+

externalCliDiscoveryForProviderAuth: mocks.externalCliDiscoveryForProviderAuth,

23+

resolveAuthProfileDisplayLabel: mocks.resolveAuthProfileDisplayLabel,

24+

resolveAuthStatePathForDisplay: (agentDir: string) => `${agentDir}/auth-state.json`,

25+

}));

26+27+

vi.mock("./load-config.js", () => ({

28+

loadModelsConfig: mocks.loadModelsConfig,

29+

}));

30+31+

vi.mock("./shared.js", () => ({

32+

resolveKnownAgentId: mocks.resolveKnownAgentId,

33+

}));

34+35+

function createRuntime(): OutputRuntimeEnv & { logs: string[]; jsonPayloads: unknown[] } {

36+

const logs: string[] = [];

37+

const jsonPayloads: unknown[] = [];

38+

return {

39+

logs,

40+

jsonPayloads,

41+

log: (...args: unknown[]) => {

42+

logs.push(args.map((value) => String(value)).join(" "));

43+

},

44+

error: vi.fn(),

45+

exit: vi.fn((code: number) => {

46+

throw new Error(`exit ${code}`);

47+

}),

48+

writeStdout: vi.fn(),

49+

writeJson: (value: unknown) => {

50+

jsonPayloads.push(value);

51+

},

52+

};

53+

}

54+55+

describe("modelsAuthListCommand", () => {

56+

beforeEach(() => {

57+

mocks.loadModelsConfig.mockReset().mockResolvedValue({} as OpenClawConfig);

58+

mocks.ensureAuthProfileStore.mockReset();

59+

mocks.externalCliDiscoveryForProviderAuth.mockClear();

60+

mocks.resolveAuthProfileDisplayLabel.mockClear();

61+

mocks.resolveKnownAgentId.mockClear();

62+

});

63+64+

it("filters profiles by provider and redacts credential material in JSON output", async () => {

65+

const store: AuthProfileStore = {

66+

version: 1,

67+

profiles: {

68+

"openai-codex:user@example.com": {

69+

type: "oauth",

70+

provider: "openai-codex",

71+

access: "access-secret",

72+

refresh: "refresh-secret",

73+

expires: 1_800_000_000_000,

74+

email: "user@example.com",

75+

},

76+

"anthropic:manual": {

77+

type: "token",

78+

provider: "anthropic",

79+

token: "token-secret",

80+

},

81+

},

82+

usageStats: {

83+

"openai-codex:user@example.com": {

84+

cooldownUntil: 1_800_000_010_000,

85+

},

86+

},

87+

};

88+

mocks.ensureAuthProfileStore.mockReturnValue(store);

89+

const runtime = createRuntime();

90+91+

await modelsAuthListCommand({ provider: "OpenAI-Codex", agent: "coder", json: true }, runtime);

92+93+

expect(mocks.externalCliDiscoveryForProviderAuth).toHaveBeenCalledWith({

94+

cfg: {},

95+

provider: "openai-codex",

96+

});

97+

expect(runtime.jsonPayloads).toHaveLength(1);

98+

expect(JSON.stringify(runtime.jsonPayloads[0])).not.toContain("secret");

99+

expect(runtime.jsonPayloads[0]).toMatchObject({

100+

agentId: "coder",

101+

provider: "openai-codex",

102+

profiles: [

103+

{

104+

id: "openai-codex:user@example.com",

105+

provider: "openai-codex",

106+

type: "oauth",

107+

email: "user@example.com",

108+

expiresAt: "2027-01-15T08:00:00.000Z",

109+

cooldownUntil: "2027-01-15T08:00:10.000Z",

110+

},

111+

],

112+

});

113+

});

114+115+

it("prints an empty profile list without failing", async () => {

116+

mocks.ensureAuthProfileStore.mockReturnValue({ version: 1, profiles: {} });

117+

const runtime = createRuntime();

118+119+

await modelsAuthListCommand({}, runtime);

120+121+

expect(runtime.logs).toEqual([

122+

"Agent: main",

123+

"Auth state file: /tmp/openclaw/agents/main/auth-state.json",

124+

"Profiles: (none)",

125+

]);

126+

});

127+

});