mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 04:00:43 +00:00
build: exclude private QA from npm package
This commit is contained in:
8
src/cli/program/private-qa-cli.ts
Normal file
8
src/cli/program/private-qa-cli.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export function isPrivateQaCliEnabled(env: NodeJS.ProcessEnv = process.env): boolean {
|
||||
return env.OPENCLAW_ENABLE_PRIVATE_QA_CLI === "1";
|
||||
}
|
||||
|
||||
export function loadPrivateQaCliModule(): Promise<Record<string, unknown>> {
|
||||
const specifier = ["../../plugin-sdk/", "qa", "-lab.js"].join("");
|
||||
return import(specifier) as Promise<Record<string, unknown>>;
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
defineImportedProgramCommandGroupSpecs,
|
||||
type CommandGroupDescriptorSpec,
|
||||
} from "./command-group-descriptors.js";
|
||||
import { loadPrivateQaCliModule } from "./private-qa-cli.js";
|
||||
import {
|
||||
registerCommandGroupByName,
|
||||
registerCommandGroups,
|
||||
@@ -131,7 +132,7 @@ const entrySpecs: readonly CommandGroupDescriptorSpec<SubCliRegistrar>[] = [
|
||||
},
|
||||
{
|
||||
commandNames: ["qa"],
|
||||
loadModule: () => import("../../plugin-sdk/qa-lab.js"),
|
||||
loadModule: loadPrivateQaCliModule,
|
||||
exportName: "registerQaLabCli",
|
||||
},
|
||||
{
|
||||
|
||||
@@ -19,8 +19,7 @@ const { nodesAction, registerNodesCli } = vi.hoisted(() => {
|
||||
return { nodesAction: action, registerNodesCli: register };
|
||||
});
|
||||
|
||||
const { isQaLabCliAvailable, registerQaLabCli } = vi.hoisted(() => ({
|
||||
isQaLabCliAvailable: vi.fn(() => true),
|
||||
const { registerQaLabCli } = vi.hoisted(() => ({
|
||||
registerQaLabCli: vi.fn((program: Command) => {
|
||||
const qa = program.command("qa");
|
||||
qa.command("run").action(() => undefined);
|
||||
@@ -38,11 +37,12 @@ const { inferAction, registerCapabilityCli } = vi.hoisted(() => {
|
||||
vi.mock("../acp-cli.js", () => ({ registerAcpCli }));
|
||||
vi.mock("../nodes-cli.js", () => ({ registerNodesCli }));
|
||||
vi.mock("../capability-cli.js", () => ({ registerCapabilityCli }));
|
||||
vi.mock("../../plugin-sdk/qa-lab.js", () => ({ isQaLabCliAvailable, registerQaLabCli }));
|
||||
vi.mock("../../plugin-sdk/qa-lab.js", () => ({ registerQaLabCli }));
|
||||
|
||||
describe("registerSubCliCommands", () => {
|
||||
const originalArgv = process.argv;
|
||||
const originalDisableLazySubcommands = process.env.OPENCLAW_DISABLE_LAZY_SUBCOMMANDS;
|
||||
const originalEnablePrivateQaCli = process.env.OPENCLAW_ENABLE_PRIVATE_QA_CLI;
|
||||
|
||||
const createRegisteredProgram = (argv: string[], name?: string) => {
|
||||
process.argv = argv;
|
||||
@@ -60,11 +60,11 @@ describe("registerSubCliCommands", () => {
|
||||
} else {
|
||||
process.env.OPENCLAW_DISABLE_LAZY_SUBCOMMANDS = originalDisableLazySubcommands;
|
||||
}
|
||||
process.env.OPENCLAW_ENABLE_PRIVATE_QA_CLI = "1";
|
||||
registerAcpCli.mockClear();
|
||||
acpAction.mockClear();
|
||||
registerNodesCli.mockClear();
|
||||
nodesAction.mockClear();
|
||||
isQaLabCliAvailable.mockReset().mockReturnValue(true);
|
||||
registerQaLabCli.mockClear();
|
||||
registerCapabilityCli.mockClear();
|
||||
inferAction.mockClear();
|
||||
@@ -77,6 +77,11 @@ describe("registerSubCliCommands", () => {
|
||||
} else {
|
||||
process.env.OPENCLAW_DISABLE_LAZY_SUBCOMMANDS = originalDisableLazySubcommands;
|
||||
}
|
||||
if (originalEnablePrivateQaCli === undefined) {
|
||||
delete process.env.OPENCLAW_ENABLE_PRIVATE_QA_CLI;
|
||||
} else {
|
||||
process.env.OPENCLAW_ENABLE_PRIVATE_QA_CLI = originalEnablePrivateQaCli;
|
||||
}
|
||||
});
|
||||
|
||||
it("registers the primary placeholder plus completion and dispatches", async () => {
|
||||
@@ -101,8 +106,8 @@ describe("registerSubCliCommands", () => {
|
||||
expect(registerAcpCli).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("omits the qa placeholder when the private qa bundle is unavailable", () => {
|
||||
isQaLabCliAvailable.mockReturnValue(false);
|
||||
it("omits the qa placeholder when the private qa cli is disabled", () => {
|
||||
delete process.env.OPENCLAW_ENABLE_PRIVATE_QA_CLI;
|
||||
|
||||
const program = createRegisteredProgram(["node", "openclaw"]);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { isQaLabCliAvailable } from "../../plugin-sdk/qa-lab.js";
|
||||
import { defineCommandDescriptorCatalog } from "./command-descriptor-utils.js";
|
||||
import type { NamedCommandDescriptor } from "./command-group-descriptors.js";
|
||||
import { isPrivateQaCliEnabled } from "./private-qa-cli.js";
|
||||
|
||||
export type SubCliDescriptor = NamedCommandDescriptor;
|
||||
|
||||
@@ -164,7 +164,7 @@ export const SUB_CLI_DESCRIPTORS = subCliCommandCatalog.descriptors;
|
||||
|
||||
export function getSubCliEntries(): ReadonlyArray<SubCliDescriptor> {
|
||||
const descriptors = subCliCommandCatalog.getDescriptors();
|
||||
if (isQaLabCliAvailable()) {
|
||||
if (isPrivateQaCliEnabled()) {
|
||||
return descriptors;
|
||||
}
|
||||
return descriptors.filter((descriptor) => descriptor.name !== "qa");
|
||||
@@ -172,7 +172,7 @@ export function getSubCliEntries(): ReadonlyArray<SubCliDescriptor> {
|
||||
|
||||
export function getSubCliCommandsWithSubcommands(): string[] {
|
||||
const commands = subCliCommandCatalog.getCommandsWithSubcommands();
|
||||
if (isQaLabCliAvailable()) {
|
||||
if (isPrivateQaCliEnabled()) {
|
||||
return commands;
|
||||
}
|
||||
return commands.filter((command) => command !== "qa");
|
||||
|
||||
Reference in New Issue
Block a user