mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:40:44 +00:00
test: share channel setup fixtures
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
makeCatalogEntry,
|
||||
makeChannelSetupEntries,
|
||||
makeMeta,
|
||||
} from "./channel-setup.test-helpers.js";
|
||||
|
||||
type ChannelMeta = import("../channels/plugins/types.core.js").ChannelMeta;
|
||||
type ChannelPluginCatalogEntry = import("../channels/plugins/catalog.js").ChannelPluginCatalogEntry;
|
||||
type ListChatChannels = typeof import("../channels/chat-meta.js").listChatChannels;
|
||||
type ResolveChannelSetupEntries =
|
||||
typeof import("../commands/channel-setup/discovery.js").resolveChannelSetupEntries;
|
||||
@@ -13,37 +16,7 @@ type NoteChannelPrimerChannels = Parameters<
|
||||
typeof import("./channel-setup.status.js").noteChannelPrimer
|
||||
>[1];
|
||||
|
||||
function makeMeta(id: string, label: string, overrides: Partial<ChannelMeta> = {}): ChannelMeta {
|
||||
return {
|
||||
id: id as ChannelMeta["id"],
|
||||
label,
|
||||
selectionLabel: overrides.selectionLabel ?? label,
|
||||
docsPath: overrides.docsPath ?? `/channels/${id}`,
|
||||
blurb: overrides.blurb ?? "",
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
function makeCatalogEntry(
|
||||
id: string,
|
||||
label: string,
|
||||
overrides: Partial<ChannelPluginCatalogEntry> = {},
|
||||
): ChannelPluginCatalogEntry {
|
||||
return {
|
||||
id,
|
||||
pluginId: overrides.pluginId ?? id,
|
||||
meta: makeMeta(id, label, overrides.meta),
|
||||
install: overrides.install ?? { npmSpec: `@openclaw/${id}` },
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
const listChatChannels = vi.hoisted(() =>
|
||||
vi.fn<ListChatChannels>(() => [
|
||||
makeMeta("discord", "Discord"),
|
||||
makeMeta("bluebubbles", "BlueBubbles"),
|
||||
]),
|
||||
);
|
||||
const listChatChannels = vi.hoisted(() => vi.fn<ListChatChannels>(() => []));
|
||||
const resolveChannelSetupEntries = vi.hoisted(() =>
|
||||
vi.fn<ResolveChannelSetupEntries>(() => ({
|
||||
entries: [],
|
||||
@@ -102,13 +75,7 @@ describe("resolveChannelSetupSelectionContributions", () => {
|
||||
makeMeta("discord", "Discord"),
|
||||
makeMeta("bluebubbles", "BlueBubbles"),
|
||||
]);
|
||||
resolveChannelSetupEntries.mockReturnValue({
|
||||
entries: [],
|
||||
installedCatalogEntries: [],
|
||||
installableCatalogEntries: [],
|
||||
installedCatalogById: new Map(),
|
||||
installableCatalogById: new Map(),
|
||||
});
|
||||
resolveChannelSetupEntries.mockReturnValue(makeChannelSetupEntries());
|
||||
formatChannelPrimerLine.mockImplementation(
|
||||
(meta: { label: string; blurb: string }) => `${meta.label}: ${meta.blurb}`,
|
||||
);
|
||||
@@ -247,13 +214,12 @@ describe("resolveChannelSetupSelectionContributions", () => {
|
||||
|
||||
it("sanitizes channel labels in status note lines", async () => {
|
||||
listChatChannels.mockReturnValue([makeMeta("discord", "Discord\u001B[31m\nCore\u0007")]);
|
||||
resolveChannelSetupEntries.mockReturnValue({
|
||||
entries: [],
|
||||
installedCatalogEntries: [makeCatalogEntry("matrix", "Matrix\u001B[2K\nPlugin\u0007")],
|
||||
installableCatalogEntries: [makeCatalogEntry("zalo", "Zalo\u001B[2K\nPlugin\u0007")],
|
||||
installedCatalogById: new Map(),
|
||||
installableCatalogById: new Map(),
|
||||
});
|
||||
resolveChannelSetupEntries.mockReturnValue(
|
||||
makeChannelSetupEntries({
|
||||
installedCatalogEntries: [makeCatalogEntry("matrix", "Matrix\u001B[2K\nPlugin\u0007")],
|
||||
installableCatalogEntries: [makeCatalogEntry("zalo", "Zalo\u001B[2K\nPlugin\u0007")],
|
||||
}),
|
||||
);
|
||||
|
||||
const summary = await collectChannelStatus({
|
||||
cfg: {} as never,
|
||||
@@ -297,27 +263,25 @@ describe("resolveChannelSetupSelectionContributions", () => {
|
||||
});
|
||||
|
||||
it("sanitizes channel metadata before selection notes", () => {
|
||||
resolveChannelSetupEntries.mockReturnValue({
|
||||
entries: [
|
||||
{
|
||||
id: "zalo",
|
||||
meta: {
|
||||
resolveChannelSetupEntries.mockReturnValue(
|
||||
makeChannelSetupEntries({
|
||||
entries: [
|
||||
{
|
||||
id: "zalo",
|
||||
label: "Zalo\u001B[31m\nBot\u0007",
|
||||
selectionLabel: "Zalo",
|
||||
docsPath: "/channels/zalo",
|
||||
docsLabel: "Docs\u001B[2K\nLabel",
|
||||
blurb: "Setup\u001B[2K\nhelp\u0007",
|
||||
selectionDocsPrefix: "Docs\u001B[2K\nPrefix",
|
||||
selectionExtras: ["Extra\u001B[2K\nOne", "\u001B[31m\u0007"],
|
||||
meta: {
|
||||
id: "zalo",
|
||||
label: "Zalo\u001B[31m\nBot\u0007",
|
||||
selectionLabel: "Zalo",
|
||||
docsPath: "/channels/zalo",
|
||||
docsLabel: "Docs\u001B[2K\nLabel",
|
||||
blurb: "Setup\u001B[2K\nhelp\u0007",
|
||||
selectionDocsPrefix: "Docs\u001B[2K\nPrefix",
|
||||
selectionExtras: ["Extra\u001B[2K\nOne", "\u001B[31m\u0007"],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
installedCatalogEntries: [],
|
||||
installableCatalogEntries: [],
|
||||
installedCatalogById: new Map(),
|
||||
installableCatalogById: new Map(),
|
||||
});
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
const lines = resolveChannelSelectionNoteLines({
|
||||
cfg: {} as never,
|
||||
|
||||
48
src/flows/channel-setup.test-helpers.ts
Normal file
48
src/flows/channel-setup.test-helpers.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
type ChannelMeta = import("../channels/plugins/types.core.js").ChannelMeta;
|
||||
type ChannelPluginCatalogEntry = import("../channels/plugins/catalog.js").ChannelPluginCatalogEntry;
|
||||
type ResolveChannelSetupEntries =
|
||||
typeof import("../commands/channel-setup/discovery.js").resolveChannelSetupEntries;
|
||||
|
||||
type ChannelSetupEntries = ReturnType<ResolveChannelSetupEntries>;
|
||||
|
||||
export function makeMeta(
|
||||
id: string,
|
||||
label: string,
|
||||
overrides: Partial<ChannelMeta> = {},
|
||||
): ChannelMeta {
|
||||
return {
|
||||
id: id as ChannelMeta["id"],
|
||||
label,
|
||||
selectionLabel: overrides.selectionLabel ?? label,
|
||||
docsPath: overrides.docsPath ?? `/channels/${id}`,
|
||||
blurb: overrides.blurb ?? "",
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
export function makeCatalogEntry(
|
||||
id: string,
|
||||
label: string,
|
||||
overrides: Partial<ChannelPluginCatalogEntry> = {},
|
||||
): ChannelPluginCatalogEntry {
|
||||
return {
|
||||
id,
|
||||
pluginId: overrides.pluginId ?? id,
|
||||
meta: makeMeta(id, label, overrides.meta),
|
||||
install: overrides.install ?? { npmSpec: `@openclaw/${id}` },
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
export function makeChannelSetupEntries(
|
||||
overrides: Partial<ChannelSetupEntries> = {},
|
||||
): ChannelSetupEntries {
|
||||
return {
|
||||
entries: [],
|
||||
installedCatalogEntries: [],
|
||||
installableCatalogEntries: [],
|
||||
installedCatalogById: new Map(),
|
||||
installableCatalogById: new Map(),
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
makeCatalogEntry,
|
||||
makeChannelSetupEntries,
|
||||
makeMeta,
|
||||
} from "./channel-setup.test-helpers.js";
|
||||
|
||||
type ChannelMeta = import("../channels/plugins/types.core.js").ChannelMeta;
|
||||
type ChannelPluginCatalogEntry = import("../channels/plugins/catalog.js").ChannelPluginCatalogEntry;
|
||||
type ChannelSetupPlugin = import("../channels/plugins/setup-wizard-types.js").ChannelSetupPlugin;
|
||||
type ResolveChannelSetupEntries =
|
||||
typeof import("../commands/channel-setup/discovery.js").resolveChannelSetupEntries;
|
||||
@@ -10,31 +13,6 @@ type LoadChannelSetupPluginRegistrySnapshotForChannel =
|
||||
typeof import("../commands/channel-setup/plugin-install.js").loadChannelSetupPluginRegistrySnapshotForChannel;
|
||||
type PluginRegistry = ReturnType<LoadChannelSetupPluginRegistrySnapshotForChannel>;
|
||||
|
||||
function makeMeta(id: string, label: string, overrides: Partial<ChannelMeta> = {}): ChannelMeta {
|
||||
return {
|
||||
id: id as ChannelMeta["id"],
|
||||
label,
|
||||
selectionLabel: overrides.selectionLabel ?? label,
|
||||
docsPath: overrides.docsPath ?? `/channels/${id}`,
|
||||
blurb: overrides.blurb ?? "",
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
function makeCatalogEntry(
|
||||
id: string,
|
||||
label: string,
|
||||
overrides: Partial<ChannelPluginCatalogEntry> = {},
|
||||
): ChannelPluginCatalogEntry {
|
||||
return {
|
||||
id,
|
||||
pluginId: overrides.pluginId ?? id,
|
||||
origin: overrides.origin,
|
||||
meta: makeMeta(id, label, overrides.meta),
|
||||
install: overrides.install ?? { npmSpec: `@openclaw/${id}` },
|
||||
};
|
||||
}
|
||||
|
||||
function makeSetupPlugin(params: {
|
||||
id: string;
|
||||
label: string;
|
||||
@@ -51,6 +29,18 @@ function makeSetupPlugin(params: {
|
||||
};
|
||||
}
|
||||
|
||||
function externalChatSetupEntries(overrides: Partial<ReturnType<ResolveChannelSetupEntries>> = {}) {
|
||||
return makeChannelSetupEntries({
|
||||
entries: [
|
||||
{
|
||||
id: "external-chat",
|
||||
meta: makeMeta("external-chat", "External Chat"),
|
||||
},
|
||||
],
|
||||
...overrides,
|
||||
});
|
||||
}
|
||||
|
||||
function makePluginRegistry(overrides: Partial<PluginRegistry> = {}): PluginRegistry {
|
||||
return {
|
||||
plugins: [],
|
||||
@@ -199,13 +189,7 @@ describe("setupChannels workspace shadow exclusion", () => {
|
||||
listActiveChannelSetupPlugins.mockReturnValue([]);
|
||||
listChannelSetupPlugins.mockReturnValue([]);
|
||||
loadChannelSetupPluginRegistrySnapshotForChannel.mockReturnValue(makePluginRegistry());
|
||||
resolveChannelSetupEntries.mockReturnValue({
|
||||
entries: [],
|
||||
installedCatalogEntries: [],
|
||||
installableCatalogEntries: [],
|
||||
installedCatalogById: new Map(),
|
||||
installableCatalogById: new Map(),
|
||||
});
|
||||
resolveChannelSetupEntries.mockReturnValue(makeChannelSetupEntries());
|
||||
collectChannelStatus.mockResolvedValue({
|
||||
installedPlugins: [],
|
||||
catalogEntries: [],
|
||||
@@ -270,18 +254,7 @@ describe("setupChannels workspace shadow exclusion", () => {
|
||||
});
|
||||
|
||||
it("defers status and setup-plugin loads until a channel is selected", async () => {
|
||||
resolveChannelSetupEntries.mockReturnValue({
|
||||
entries: [
|
||||
{
|
||||
id: "external-chat",
|
||||
meta: makeMeta("external-chat", "External Chat"),
|
||||
},
|
||||
],
|
||||
installedCatalogEntries: [],
|
||||
installableCatalogEntries: [],
|
||||
installedCatalogById: new Map(),
|
||||
installableCatalogById: new Map(),
|
||||
});
|
||||
resolveChannelSetupEntries.mockReturnValue(externalChatSetupEntries());
|
||||
const select = vi.fn(async () => "__done__");
|
||||
|
||||
await setupChannels(
|
||||
@@ -366,18 +339,20 @@ describe("setupChannels workspace shadow exclusion", () => {
|
||||
setupWizard,
|
||||
});
|
||||
listActiveChannelSetupPlugins.mockReturnValue([activePlugin]);
|
||||
resolveChannelSetupEntries.mockReturnValue({
|
||||
entries: [
|
||||
{
|
||||
id: "custom-chat",
|
||||
meta: makeMeta("custom-chat", "Custom Chat"),
|
||||
},
|
||||
],
|
||||
installedCatalogEntries: [],
|
||||
installableCatalogEntries: [],
|
||||
installedCatalogById: new Map(),
|
||||
installableCatalogById: new Map(),
|
||||
});
|
||||
resolveChannelSetupEntries.mockReturnValue(
|
||||
makeChannelSetupEntries({
|
||||
entries: [
|
||||
{
|
||||
id: "custom-chat",
|
||||
meta: makeMeta("custom-chat", "Custom Chat"),
|
||||
},
|
||||
],
|
||||
installedCatalogEntries: [],
|
||||
installableCatalogEntries: [],
|
||||
installedCatalogById: new Map(),
|
||||
installableCatalogById: new Map(),
|
||||
}),
|
||||
);
|
||||
const select = vi.fn().mockResolvedValueOnce("custom-chat").mockResolvedValueOnce("__done__");
|
||||
|
||||
const next = await setupChannels(
|
||||
@@ -435,18 +410,12 @@ describe("setupChannels workspace shadow exclusion", () => {
|
||||
pluginId: "external-chat",
|
||||
origin: "bundled",
|
||||
});
|
||||
resolveChannelSetupEntries.mockReturnValue({
|
||||
entries: [
|
||||
{
|
||||
id: "external-chat",
|
||||
meta: makeMeta("external-chat", "External Chat"),
|
||||
},
|
||||
],
|
||||
installedCatalogEntries: [installedCatalogEntry],
|
||||
installableCatalogEntries: [],
|
||||
installedCatalogById: new Map([["external-chat", installedCatalogEntry]]),
|
||||
installableCatalogById: new Map(),
|
||||
});
|
||||
resolveChannelSetupEntries.mockReturnValue(
|
||||
externalChatSetupEntries({
|
||||
installedCatalogEntries: [installedCatalogEntry],
|
||||
installedCatalogById: new Map([["external-chat", installedCatalogEntry]]),
|
||||
}),
|
||||
);
|
||||
loadChannelSetupPluginRegistrySnapshotForChannel.mockReturnValue(
|
||||
makePluginRegistry({
|
||||
channels: [
|
||||
@@ -507,18 +476,7 @@ describe("setupChannels workspace shadow exclusion", () => {
|
||||
})),
|
||||
configure: vi.fn(),
|
||||
};
|
||||
resolveChannelSetupEntries.mockReturnValue({
|
||||
entries: [
|
||||
{
|
||||
id: "external-chat",
|
||||
meta: makeMeta("external-chat", "External Chat"),
|
||||
},
|
||||
],
|
||||
installedCatalogEntries: [],
|
||||
installableCatalogEntries: [],
|
||||
installedCatalogById: new Map(),
|
||||
installableCatalogById: new Map(),
|
||||
});
|
||||
resolveChannelSetupEntries.mockReturnValue(externalChatSetupEntries());
|
||||
const select = vi.fn().mockResolvedValueOnce("external-chat").mockResolvedValueOnce("__done__");
|
||||
const note = vi.fn(async () => undefined);
|
||||
const cfg = {
|
||||
@@ -556,18 +514,7 @@ describe("setupChannels workspace shadow exclusion", () => {
|
||||
});
|
||||
|
||||
it("honors global plugin disablement before lazy channel setup loads plugins", async () => {
|
||||
resolveChannelSetupEntries.mockReturnValue({
|
||||
entries: [
|
||||
{
|
||||
id: "external-chat",
|
||||
meta: makeMeta("external-chat", "External Chat"),
|
||||
},
|
||||
],
|
||||
installedCatalogEntries: [],
|
||||
installableCatalogEntries: [],
|
||||
installedCatalogById: new Map(),
|
||||
installableCatalogById: new Map(),
|
||||
});
|
||||
resolveChannelSetupEntries.mockReturnValue(externalChatSetupEntries());
|
||||
const select = vi.fn().mockResolvedValueOnce("external-chat").mockResolvedValueOnce("__done__");
|
||||
const note = vi.fn(async () => undefined);
|
||||
const cfg = {
|
||||
|
||||
Reference in New Issue
Block a user