mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-14 10:41:23 +00:00
fix(ci): restore channel typing and root-help metadata build
This commit is contained in:
@@ -1,6 +1,16 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { renderRootHelpText } from "./root-help.js";
|
||||
|
||||
const getPluginCliCommandDescriptorsMock = vi.fn(
|
||||
async (_config?: unknown, _env?: unknown, _loaderOptions?: unknown) => [
|
||||
{
|
||||
name: "matrix",
|
||||
description: "Matrix channel utilities",
|
||||
hasSubcommands: true,
|
||||
},
|
||||
],
|
||||
);
|
||||
|
||||
vi.mock("./core-command-descriptors.js", () => ({
|
||||
getCoreCliCommandDescriptors: () => [
|
||||
{
|
||||
@@ -24,16 +34,28 @@ vi.mock("./subcli-descriptors.js", () => ({
|
||||
}));
|
||||
|
||||
vi.mock("../../plugins/cli.js", () => ({
|
||||
getPluginCliCommandDescriptors: async () => [
|
||||
{
|
||||
name: "matrix",
|
||||
description: "Matrix channel utilities",
|
||||
hasSubcommands: true,
|
||||
},
|
||||
],
|
||||
getPluginCliCommandDescriptors: (...args: [unknown?, unknown?, unknown?]) =>
|
||||
getPluginCliCommandDescriptorsMock(...args),
|
||||
}));
|
||||
|
||||
describe("root help", () => {
|
||||
it("passes isolated config and env through to plugin CLI descriptor loading", async () => {
|
||||
const config = {
|
||||
agents: {
|
||||
defaults: {
|
||||
workspace: "/tmp/openclaw-root-help-workspace",
|
||||
},
|
||||
},
|
||||
};
|
||||
const env = { OPENCLAW_STATE_DIR: "/tmp/openclaw-root-help-state" } as NodeJS.ProcessEnv;
|
||||
|
||||
await renderRootHelpText({ config, env, pluginSdkResolution: "src" });
|
||||
|
||||
expect(getPluginCliCommandDescriptorsMock).toHaveBeenCalledWith(config, env, {
|
||||
pluginSdkResolution: "src",
|
||||
});
|
||||
});
|
||||
|
||||
it("includes plugin CLI descriptors alongside core and sub-CLI commands", async () => {
|
||||
const text = await renderRootHelpText();
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Command } from "commander";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import { getPluginCliCommandDescriptors } from "../../plugins/cli.js";
|
||||
import type { PluginLoadOptions } from "../../plugins/loader.js";
|
||||
import { VERSION } from "../../version.js";
|
||||
@@ -6,9 +7,12 @@ import { getCoreCliCommandDescriptors } from "./core-command-descriptors.js";
|
||||
import { configureProgramHelp } from "./help.js";
|
||||
import { getSubCliEntries } from "./subcli-descriptors.js";
|
||||
|
||||
type RootHelpLoaderOptions = Pick<PluginLoadOptions, "pluginSdkResolution">;
|
||||
export type RootHelpRenderOptions = Pick<PluginLoadOptions, "pluginSdkResolution"> & {
|
||||
config?: OpenClawConfig;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
};
|
||||
|
||||
async function buildRootHelpProgram(loaderOptions?: RootHelpLoaderOptions): Promise<Command> {
|
||||
async function buildRootHelpProgram(renderOptions?: RootHelpRenderOptions): Promise<Command> {
|
||||
const program = new Command();
|
||||
configureProgramHelp(program, {
|
||||
programVersion: VERSION,
|
||||
@@ -29,7 +33,11 @@ async function buildRootHelpProgram(loaderOptions?: RootHelpLoaderOptions): Prom
|
||||
program.command(command.name).description(command.description);
|
||||
existingCommands.add(command.name);
|
||||
}
|
||||
for (const command of await getPluginCliCommandDescriptors(undefined, undefined, loaderOptions)) {
|
||||
for (const command of await getPluginCliCommandDescriptors(
|
||||
renderOptions?.config,
|
||||
renderOptions?.env,
|
||||
{ pluginSdkResolution: renderOptions?.pluginSdkResolution },
|
||||
)) {
|
||||
if (existingCommands.has(command.name)) {
|
||||
continue;
|
||||
}
|
||||
@@ -40,8 +48,8 @@ async function buildRootHelpProgram(loaderOptions?: RootHelpLoaderOptions): Prom
|
||||
return program;
|
||||
}
|
||||
|
||||
export async function renderRootHelpText(loaderOptions?: RootHelpLoaderOptions): Promise<string> {
|
||||
const program = await buildRootHelpProgram(loaderOptions);
|
||||
export async function renderRootHelpText(renderOptions?: RootHelpRenderOptions): Promise<string> {
|
||||
const program = await buildRootHelpProgram(renderOptions);
|
||||
let output = "";
|
||||
const originalWrite = process.stdout.write.bind(process.stdout);
|
||||
const captureWrite: typeof process.stdout.write = ((chunk: string | Uint8Array) => {
|
||||
@@ -57,6 +65,6 @@ export async function renderRootHelpText(loaderOptions?: RootHelpLoaderOptions):
|
||||
return output;
|
||||
}
|
||||
|
||||
export async function outputRootHelp(loaderOptions?: RootHelpLoaderOptions): Promise<void> {
|
||||
process.stdout.write(await renderRootHelpText(loaderOptions));
|
||||
export async function outputRootHelp(renderOptions?: RootHelpRenderOptions): Promise<void> {
|
||||
process.stdout.write(await renderRootHelpText(renderOptions));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user