mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-13 15:47:28 +00:00
test: seed plugin auth profiles through sqlite
This commit is contained in:
@@ -4,6 +4,7 @@ import path from "node:path";
|
||||
import {
|
||||
clearRuntimeAuthProfileStoreSnapshots,
|
||||
ensureAuthProfileStore,
|
||||
saveAuthProfileStore,
|
||||
} from "openclaw/plugin-sdk/agent-runtime";
|
||||
import { createTestPluginApi } from "openclaw/plugin-sdk/plugin-test-api";
|
||||
import { afterAll, afterEach, describe, expect, it, vi } from "vitest";
|
||||
@@ -42,6 +43,22 @@ async function createAgentDir() {
|
||||
return dir;
|
||||
}
|
||||
|
||||
function seedGithubCopilotTokenProfile(agentDir: string, token = "existing-token") {
|
||||
saveAuthProfileStore(
|
||||
{
|
||||
version: 1,
|
||||
profiles: {
|
||||
"github-copilot:github": {
|
||||
type: "token",
|
||||
provider: "github-copilot",
|
||||
token,
|
||||
},
|
||||
},
|
||||
},
|
||||
agentDir,
|
||||
);
|
||||
}
|
||||
|
||||
function _registerProvider() {
|
||||
return registerProviderWithPluginConfig({});
|
||||
}
|
||||
@@ -199,19 +216,7 @@ describe("github-copilot plugin", () => {
|
||||
const provider = registerProviderWithPluginConfig({});
|
||||
const method = provider.auth[0];
|
||||
const agentDir = await createAgentDir();
|
||||
await fs.writeFile(
|
||||
path.join(agentDir, "auth-profiles.json"),
|
||||
JSON.stringify({
|
||||
version: 1,
|
||||
profiles: {
|
||||
"github-copilot:github": {
|
||||
type: "token",
|
||||
provider: "github-copilot",
|
||||
token: "existing-token",
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
seedGithubCopilotTokenProfile(agentDir);
|
||||
const prompter = {
|
||||
confirm: vi.fn(async () => false),
|
||||
note: vi.fn(),
|
||||
@@ -256,19 +261,7 @@ describe("github-copilot plugin", () => {
|
||||
const provider = registerProviderWithPluginConfig({});
|
||||
const method = provider.auth[0];
|
||||
const agentDir = await createAgentDir();
|
||||
await fs.writeFile(
|
||||
path.join(agentDir, "auth-profiles.json"),
|
||||
JSON.stringify({
|
||||
version: 1,
|
||||
profiles: {
|
||||
"github-copilot:github": {
|
||||
type: "token",
|
||||
provider: "github-copilot",
|
||||
token: "existing-token",
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
seedGithubCopilotTokenProfile(agentDir);
|
||||
const fetchMock = vi.fn(async (input: unknown) => {
|
||||
const target =
|
||||
typeof input === "string"
|
||||
@@ -513,19 +506,7 @@ describe("github-copilot plugin", () => {
|
||||
const method = provider.auth[0];
|
||||
const agentDir = await createAgentDir();
|
||||
const runtime = { error: vi.fn(), exit: vi.fn() };
|
||||
await fs.writeFile(
|
||||
path.join(agentDir, "auth-profiles.json"),
|
||||
JSON.stringify({
|
||||
version: 1,
|
||||
profiles: {
|
||||
"github-copilot:github": {
|
||||
type: "token",
|
||||
provider: "github-copilot",
|
||||
token: "existing-token",
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
seedGithubCopilotTokenProfile(agentDir);
|
||||
|
||||
const result = await method.runNonInteractive({
|
||||
authChoice: "github-copilot",
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import {
|
||||
clearRuntimeAuthProfileStoreSnapshots,
|
||||
saveAuthProfileStore,
|
||||
} from "openclaw/plugin-sdk/agent-runtime";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const transcodeAudioBufferToOpusMock = vi.hoisted(() => vi.fn());
|
||||
@@ -18,6 +22,22 @@ function clearMinimaxAuthEnv() {
|
||||
delete process.env.MINIMAX_CODING_API_KEY;
|
||||
}
|
||||
|
||||
function seedMinimaxPortalAuthProfile(agentDir: string) {
|
||||
saveAuthProfileStore(
|
||||
{
|
||||
version: 1,
|
||||
profiles: {
|
||||
"minimax-portal:test": {
|
||||
type: "token",
|
||||
provider: "minimax-portal",
|
||||
token: "portal-token",
|
||||
},
|
||||
},
|
||||
},
|
||||
agentDir,
|
||||
);
|
||||
}
|
||||
|
||||
describe("buildMinimaxSpeechProvider", () => {
|
||||
const provider = buildMinimaxSpeechProvider();
|
||||
|
||||
@@ -82,6 +102,7 @@ describe("buildMinimaxSpeechProvider", () => {
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
clearRuntimeAuthProfileStoreSnapshots();
|
||||
process.env = { ...savedEnv };
|
||||
await rm(tempStateDir, { recursive: true, force: true });
|
||||
});
|
||||
@@ -107,19 +128,7 @@ describe("buildMinimaxSpeechProvider", () => {
|
||||
});
|
||||
|
||||
it("returns true when a MiniMax portal auth profile is available", async () => {
|
||||
await writeFile(
|
||||
path.join(tempAgentDir, "auth-profiles.json"),
|
||||
JSON.stringify({
|
||||
version: 1,
|
||||
profiles: {
|
||||
"minimax-portal:test": {
|
||||
type: "token",
|
||||
provider: "minimax-portal",
|
||||
token: "portal-token",
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
seedMinimaxPortalAuthProfile(tempAgentDir);
|
||||
|
||||
expect(provider.isConfigured({ providerConfig: {}, timeoutMs: 30000 })).toBe(true);
|
||||
});
|
||||
@@ -450,19 +459,7 @@ describe("buildMinimaxSpeechProvider", () => {
|
||||
|
||||
it("uses a minimax-portal auth profile before env API keys", async () => {
|
||||
process.env.MINIMAX_API_KEY = "sk-env";
|
||||
await writeFile(
|
||||
path.join(tempAgentDir, "auth-profiles.json"),
|
||||
JSON.stringify({
|
||||
version: 1,
|
||||
profiles: {
|
||||
"minimax-portal:test": {
|
||||
type: "token",
|
||||
provider: "minimax-portal",
|
||||
token: "portal-token",
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
seedMinimaxPortalAuthProfile(tempAgentDir);
|
||||
const hexAudio = Buffer.from("audio").toString("hex");
|
||||
vi.mocked(globalThis.fetch).mockResolvedValueOnce(
|
||||
new Response(JSON.stringify({ data: { audio: hexAudio } }), { status: 200 }),
|
||||
|
||||
Reference in New Issue
Block a user