Fix check type errors

This commit is contained in:
Gustavo Madeira Santana
2026-04-17 14:16:58 -04:00
parent c0a9b694f3
commit 462074c4c2
4 changed files with 83 additions and 27 deletions

View File

@@ -1,7 +1,8 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { CodexCliCredential } from "./cli-credentials.js";
const { readCodexCliCredentialsCachedMock } = vi.hoisted(() => ({
readCodexCliCredentialsCachedMock: vi.fn(() => null),
readCodexCliCredentialsCachedMock: vi.fn((): CodexCliCredential | null => null),
}));
vi.mock("./cli-credentials.js", () => ({

View File

@@ -16,9 +16,20 @@ type ConfiguredChannelRemovalChoice = {
};
type ChannelRemovalSelectValue = { kind: "channel"; id: string } | { kind: "done" };
type ChannelRemovalSelectOption =
| {
value: { kind: "channel"; id: string };
label: string;
hint?: string;
}
| {
value: { kind: "done" };
label: string;
hint?: string;
};
const RESERVED_CHANNEL_CONFIG_KEYS = new Set(["defaults", "modelByChannel"]);
const DONE_VALUE: ChannelRemovalSelectValue = { kind: "done" };
const DONE_VALUE = { kind: "done" } as const;
function listConfiguredChannelRemovalChoices(
cfg: OpenClawConfig,
@@ -77,17 +88,18 @@ export async function removeChannelConfigWizard(
return next;
}
const options: ChannelRemovalSelectOption[] = [
...configured.map((meta) => ({
value: { kind: "channel" as const, id: meta.id },
label: meta.label,
hint: "Deletes tokens + settings from config (credentials stay on disk)",
})),
{ value: DONE_VALUE, label: "Done" },
];
const choice = guardCancel(
await select<ChannelRemovalSelectValue>({
message: "Remove which channel config?",
options: [
...configured.map((meta) => ({
value: { kind: "channel" as const, id: meta.id },
label: meta.label,
hint: "Deletes tokens + settings from config (credentials stay on disk)",
})),
{ value: DONE_VALUE, label: "Done" },
],
options,
}),
runtime,
);

View File

@@ -1,5 +1,31 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
type MockChannelSetupEntry = {
id: string;
pluginId?: string;
meta: {
id: string;
label: string;
selectionLabel?: string;
docsPath?: string;
docsLabel?: string;
blurb?: string;
selectionDocsPrefix?: string;
selectionExtras?: readonly string[];
exposure?: { setup?: boolean };
showInSetup?: boolean;
quickstartAllowFrom?: boolean;
};
};
type MockChannelSetupEntries = {
entries: MockChannelSetupEntry[];
installedCatalogEntries: MockChannelSetupEntry[];
installableCatalogEntries: MockChannelSetupEntry[];
installedCatalogById: Map<unknown, unknown>;
installableCatalogById: Map<unknown, unknown>;
};
const listChatChannels = vi.hoisted(() =>
vi.fn(() => [
{ id: "discord", label: "Discord" },
@@ -7,21 +33,29 @@ const listChatChannels = vi.hoisted(() =>
]),
);
const resolveChannelSetupEntries = vi.hoisted(() =>
vi.fn(() => ({
entries: [],
installedCatalogEntries: [],
installableCatalogEntries: [],
installedCatalogById: new Map(),
installableCatalogById: new Map(),
})),
vi.fn(
(_params?: unknown): MockChannelSetupEntries => ({
entries: [],
installedCatalogEntries: [],
installableCatalogEntries: [],
installedCatalogById: new Map(),
installableCatalogById: new Map(),
}),
),
);
const formatChannelPrimerLine = vi.hoisted(() =>
vi.fn((meta: { label: string; blurb: string }) => `${meta.label}: ${meta.blurb}`),
vi.fn((meta: unknown) => {
const channel = meta as { label: string; blurb: string };
return `${channel.label}: ${channel.blurb}`;
}),
);
const formatChannelSelectionLine = vi.hoisted(() =>
vi.fn((meta: { label: string; blurb: string }) => `${meta.label}${meta.blurb}`),
vi.fn((meta: unknown, _docsLink?: unknown) => {
const channel = meta as { label: string; blurb: string };
return `${channel.label}${channel.blurb}`;
}),
);
const isChannelConfigured = vi.hoisted(() => vi.fn(() => false));
const isChannelConfigured = vi.hoisted(() => vi.fn((_cfg?: unknown, _channelId?: string) => false));
vi.mock("../channels/chat-meta.js", () => ({
listChatChannels: () => listChatChannels(),
@@ -64,12 +98,14 @@ describe("resolveChannelSetupSelectionContributions", () => {
installedCatalogById: new Map(),
installableCatalogById: new Map(),
});
formatChannelPrimerLine.mockImplementation(
(meta: { label: string; blurb: string }) => `${meta.label}: ${meta.blurb}`,
);
formatChannelSelectionLine.mockImplementation(
(meta: { label: string; blurb: string }) => `${meta.label}${meta.blurb}`,
);
formatChannelPrimerLine.mockImplementation((meta: unknown) => {
const channel = meta as { label: string; blurb: string };
return `${channel.label}: ${channel.blurb}`;
});
formatChannelSelectionLine.mockImplementation((meta: unknown) => {
const channel = meta as { label: string; blurb: string };
return `${channel.label}${channel.blurb}`;
});
isChannelConfigured.mockReturnValue(false);
});

View File

@@ -11,7 +11,14 @@ const getChannelSetupPlugin = vi.hoisted(() => vi.fn((_channel?: unknown) => und
const listChannelSetupPlugins = vi.hoisted(() => vi.fn((): unknown[] => []));
const listActiveChannelSetupPlugins = vi.hoisted(() => vi.fn((): unknown[] => []));
const loadChannelSetupPluginRegistrySnapshotForChannel = vi.hoisted(() =>
vi.fn((_params?: unknown) => ({ channels: [], channelSetups: [] })),
vi.fn(
(
_params?: unknown,
): {
channels: unknown[];
channelSetups: unknown[];
} => ({ channels: [], channelSetups: [] }),
),
);
const resolveChannelSetupEntries = vi.hoisted(() =>
vi.fn(