build: exclude private QA from npm package

This commit is contained in:
Peter Steinberger
2026-04-15 09:38:45 -07:00
parent 78ac118427
commit 229eb72cf6
30 changed files with 539 additions and 86 deletions

View 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>>;
}

View File

@@ -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",
},
{

View File

@@ -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"]);

View File

@@ -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");