

























@@ -1288,7 +1288,7 @@ describe("modelsAuthLoginCommand", () => {
12881288}) as typeof process.exit);
12891289try {
12901290const cancelSymbol = Symbol.for("clack:cancel");
1291-mocks.clackText.mockResolvedValue(cancelSymbol);
1291+mocks.clackPassword.mockResolvedValue(cancelSymbol);
12921292mocks.clackIsCancel.mockImplementation((value: unknown) => value === cancelSymbol);
1293129312941294await expect(modelsAuthPasteTokenCommand({ provider: "openai" }, runtime)).rejects.toThrow(
@@ -1303,9 +1303,24 @@ describe("modelsAuthLoginCommand", () => {
13031303}
13041304});
130513051306+it("reads the pasted token through the masked password prompt", async () => {
1307+const runtime = createRuntime();
1308+mocks.clackPassword.mockResolvedValue("openai-token");
1309+1310+await modelsAuthPasteTokenCommand({ provider: "openai" }, runtime);
1311+1312+expect(mocks.clackPassword).toHaveBeenCalledTimes(1);
1313+expect(mocks.clackText).not.toHaveBeenCalled();
1314+expect(mocks.upsertAuthProfileWithLock).toHaveBeenCalledWith(
1315+expect.objectContaining({
1316+credential: expect.objectContaining({ type: "token", token: "openai-token" }),
1317+}),
1318+);
1319+});
1320+13061321it("writes pasted Anthropic setup-tokens and logs the preference note", async () => {
13071322const runtime = createRuntime();
1308-mocks.clackText.mockResolvedValue(`sk-ant-oat01-${"a".repeat(80)}`);
1323+mocks.clackPassword.mockResolvedValue(`sk-ant-oat01-${"a".repeat(80)}`);
1309132413101325await modelsAuthPasteTokenCommand({ provider: "anthropic" }, runtime);
13111326@@ -1332,7 +1347,7 @@ describe("modelsAuthLoginCommand", () => {
13321347it("writes pasted tokens to the requested agent store", async () => {
13331348const runtime = createRuntime();
13341349useCoderAgentConfig();
1335-mocks.clackText.mockResolvedValue("openai-token");
1350+mocks.clackPassword.mockResolvedValue("openai-token");
1336135113371352await modelsAuthPasteTokenCommand({ provider: "openai", agent: "coder" }, runtime);
13381353@@ -1351,7 +1366,7 @@ describe("modelsAuthLoginCommand", () => {
13511366it("rejects pasted token expiries that cannot fit in the Date timestamp range", async () => {
13521367const runtime = createRuntime();
13531368const nowSpy = vi.spyOn(Date, "now").mockReturnValue(MAX_DATE_TIMESTAMP_MS);
1354-mocks.clackText.mockResolvedValue("openai-token");
1369+mocks.clackPassword.mockResolvedValue("openai-token");
13551370try {
13561371await expect(
13571372modelsAuthPasteTokenCommand({ provider: "openai", expiresIn: "1ms" }, runtime),
@@ -1367,7 +1382,7 @@ describe("modelsAuthLoginCommand", () => {
13671382it("rejects OpenAI API keys pasted as OpenAI Codex token material", async () => {
13681383const runtime = createRuntime();
13691384const validateMessages: string[] = [];
1370-mocks.clackText.mockImplementation(
1385+mocks.clackPassword.mockImplementation(
13711386async (params: { validate?: (value: string) => string | undefined }) => {
13721387const message = params.validate?.("sk-openai-chatgpt-api-key-value");
13731388if (message) {
@@ -1398,7 +1413,7 @@ describe("modelsAuthLoginCommand", () => {
13981413"paste-api-key --provider openai",
13991414);
140014151401-expect(mocks.clackText).not.toHaveBeenCalled();
1416+expect(mocks.clackPassword).not.toHaveBeenCalled();
14021417expect(mocks.upsertAuthProfileWithLock).not.toHaveBeenCalled();
14031418expect(mocks.updateConfig).not.toHaveBeenCalled();
14041419});
@@ -1412,7 +1427,7 @@ describe("modelsAuthLoginCommand", () => {
14121427"paste-api-key --provider openai",
14131428);
141414291415-expect(mocks.clackText).not.toHaveBeenCalled();
1430+expect(mocks.clackPassword).not.toHaveBeenCalled();
14161431expect(mocks.upsertAuthProfileWithLock).not.toHaveBeenCalled();
14171432expect(mocks.updateConfig).not.toHaveBeenCalled();
14181433});
@@ -1523,7 +1538,7 @@ describe("modelsAuthLoginCommand", () => {
15231538'Unknown agent id "missing". Use "openclaw agents list" to see configured agents.',
15241539);
152515401526-expect(mocks.clackText).not.toHaveBeenCalled();
1541+expect(mocks.clackPassword).not.toHaveBeenCalled();
15271542expect(mocks.upsertAuthProfileWithLock).not.toHaveBeenCalled();
15281543expect(mocks.updateConfig).not.toHaveBeenCalled();
15291544});
@@ -1659,10 +1674,8 @@ describe("modelsAuthLoginCommand", () => {
16591674useCoderAgentConfig();
16601675mocks.resolvePluginProviders.mockReturnValue([]);
16611676mocks.clackSelect.mockResolvedValue("custom");
1662-mocks.clackText
1663-.mockResolvedValueOnce("openai")
1664-.mockResolvedValueOnce("openai:manual")
1665-.mockResolvedValueOnce("openai-token");
1677+mocks.clackText.mockResolvedValueOnce("openai").mockResolvedValueOnce("openai:manual");
1678+mocks.clackPassword.mockResolvedValue("openai-token");
16661679mocks.clackConfirm.mockResolvedValue(false);
1667168016681681await modelsAuthAddCommand({ agent: "coder" }, runtime);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。