import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { clearRuntimeAuthProfileStoreSnapshots } from "../../../src/agents/auth-profiles/store.js"; import type { AuthProfileStore } from "../../../src/agents/auth-profiles/types.js"; import { createNonExitingRuntime } from "../../../src/runtime.js"; import type {
WizardMultiSelectParams,
WizardPrompter,
WizardProgress,
WizardSelectParams,
} from "../../../src/wizard/prompts.js"; import { registerProviders, requireProvider } from "./contracts-testkit.js";
type LoginOpenAICodexOAuth =
(typeofimport("openclaw/plugin-sdk/provider-auth-login"))["loginOpenAICodexOAuth"];
type GithubCopilotLoginCommand =
(typeofimport("openclaw/plugin-sdk/provider-auth-login"))["githubCopilotLoginCommand"];
type CreateVpsAwareHandlers =
(typeofimport("../../../src/plugins/provider-oauth-flow.js"))["createVpsAwareOAuthHandlers"];
type EnsureAuthProfileStore = typeofimport("openclaw/plugin-sdk/provider-auth").ensureAuthProfileStore;
type ListProfilesForProvider = typeofimport("openclaw/plugin-sdk/provider-auth").listProfilesForProvider;
it("uses a stable fallback id when JWT email is missing", async () => { const access = createJwt({ "https://api.openai.com/auth": {
chatgpt_account_user_id: "user-123__acct-456",
},
}); const expectedStableId = Buffer.from("user-123__acct-456", "utf8").toString("base64url");
await expectStableFallbackProfile({
access,
profileId: `openai-codex:id-${expectedStableId}`,
});
});
it("uses iss and sub to build a stable fallback id when auth claims are missing", async () => { const access = createJwt({
iss: "https://accounts.openai.com",
sub: "user-abc",
}); const expectedStableId = Buffer.from("https://accounts.openai.com|user-abc").toString( "base64url",
);
await expectStableFallbackProfile({
access,
profileId: `openai-codex:id-${expectedStableId}`,
});
});
it("uses sub alone to build a stable fallback id when iss is missing", async () => { const access = createJwt({
sub: "user-abc",
}); const expectedStableId = Buffer.from("user-abc").toString("base64url");
await expectStableFallbackProfile({
access,
profileId: `openai-codex:id-${expectedStableId}`,
});
});
it("falls back to the default profile when JWT parsing yields no identity", async () => { const provider = await getProvider();
loginOpenAICodexOAuthMock.mockResolvedValueOnce({
refresh: "refresh-token",
access: "not-a-jwt-token",
expires: 1_700_000_000_000,
});
const result = await provider.auth[0]?.run(buildAuthContext() as never);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.