mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-08 02:14:26 +02:00
53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { createTestPluginApi } from "../../test/helpers/plugins/plugin-api.js";
|
|
|
|
const resolveCopilotApiTokenMock = vi.hoisted(() => vi.fn());
|
|
|
|
vi.mock("./register.runtime.js", () => ({
|
|
DEFAULT_COPILOT_API_BASE_URL: "https://api.githubcopilot.test",
|
|
resolveCopilotApiToken: resolveCopilotApiTokenMock,
|
|
githubCopilotLoginCommand: vi.fn(),
|
|
fetchCopilotUsage: vi.fn(),
|
|
}));
|
|
|
|
import plugin from "./index.js";
|
|
|
|
function registerProvider() {
|
|
return registerProviderWithPluginConfig({});
|
|
}
|
|
|
|
function registerProviderWithPluginConfig(pluginConfig: Record<string, unknown>) {
|
|
const registerProviderMock = vi.fn();
|
|
|
|
plugin.register(
|
|
createTestPluginApi({
|
|
id: "github-copilot",
|
|
name: "GitHub Copilot",
|
|
source: "test",
|
|
config: {},
|
|
pluginConfig,
|
|
runtime: {} as never,
|
|
registerProvider: registerProviderMock,
|
|
}),
|
|
);
|
|
|
|
expect(registerProviderMock).toHaveBeenCalledTimes(1);
|
|
return registerProviderMock.mock.calls[0]?.[0];
|
|
}
|
|
|
|
describe("github-copilot plugin", () => {
|
|
it("skips catalog discovery when plugin discovery is disabled", async () => {
|
|
const provider = registerProviderWithPluginConfig({ discovery: { enabled: false } });
|
|
|
|
const result = await provider.catalog.run({
|
|
config: {},
|
|
agentDir: "/tmp/agent",
|
|
env: { GH_TOKEN: "gh_test_token" },
|
|
resolveProviderApiKey: () => ({ apiKey: "gh_test_token" }),
|
|
} as never);
|
|
|
|
expect(result).toBeNull();
|
|
expect(resolveCopilotApiTokenMock).not.toHaveBeenCalled();
|
|
});
|
|
});
|