test: tighten assertions and harness coverage

This commit is contained in:
Peter Steinberger
2026-05-08 05:27:57 +01:00
parent f62618f805
commit 9ef37d1907
822 changed files with 8918 additions and 6533 deletions

View File

@@ -99,11 +99,11 @@ describe("command-registry", () => {
const program = createProgram();
const found = await registerCoreCliByName(program, testProgramContext, "agents");
expect(found).toBe(true);
const agentsCmd = program.commands.find((c) => c.name() === "agents");
expect(agentsCmd).toBeDefined();
// The registrar also installs the singular "agent" command from the same entry.
const agentCmd = program.commands.find((c) => c.name() === "agent");
expect(agentCmd).toBeDefined();
expect(program.commands.map((command) => command.name()).toSorted()).toEqual([
"agent",
"agents",
]);
});
it("registerCoreCliByName returns false for unknown commands", async () => {

View File

@@ -87,8 +87,7 @@ function expectNoAccountFieldInPassedOptions() {
const passedOpts = (
messageCommandMock.mock.calls as unknown as Array<[Record<string, unknown>]>
)?.[0]?.[0];
expect(passedOpts).toBeTruthy();
if (!passedOpts) {
if (passedOpts === undefined) {
throw new Error("expected message command call");
}
expect(passedOpts).not.toHaveProperty("account");

View File

@@ -51,7 +51,7 @@ describe("private-qa-cli", () => {
});
});
it("rejects non-source package roots even when private QA is enabled", async () => {
it("rejects non-source package roots even when private QA is enabled", () => {
process.env.OPENCLAW_ENABLE_PRIVATE_QA_CLI = "1";
const root = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-private-qa-"));
tempDirs.push(root);
@@ -67,7 +67,7 @@ describe("private-qa-cli", () => {
expect(importModule).not.toHaveBeenCalled();
});
it("rejects when the private QA env flag is disabled", async () => {
it("rejects when the private QA env flag is disabled", () => {
delete process.env.OPENCLAW_ENABLE_PRIVATE_QA_CLI;
const importModule = vi.fn(async () => ({}));

View File

@@ -33,6 +33,14 @@ const registerMessageEmojiCommandsMock = mocks.registerMessageEmojiCommandsMock;
const registerMessageStickerCommandsMock = mocks.registerMessageStickerCommandsMock;
const registerMessageDiscordAdminCommandsMock = mocks.registerMessageDiscordAdminCommandsMock;
function requireProgramCommand(program: Command, name: string): Command {
const command = program.commands.find((entry) => entry.name() === name);
if (!command) {
throw new Error(`expected ${name} command`);
}
return command;
}
vi.mock("./message/helpers.js", () => ({
createMessageCliHelpers: mocks.createMessageCliHelpersMock,
}));
@@ -96,8 +104,7 @@ describe("registerMessageCommands", () => {
const program = new Command();
registerMessageCommands(program, ctx);
const message = program.commands.find((command) => command.name() === "message");
expect(message).toBeDefined();
const message = requireProgramCommand(program, "message");
expect(createMessageCliHelpersMock).toHaveBeenCalledWith(message, "telegram|discord");
const expectedRegistrars = [
@@ -122,9 +129,8 @@ describe("registerMessageCommands", () => {
it("shows command help when root message command is invoked", async () => {
const program = new Command().exitOverride();
registerMessageCommands(program, ctx);
const message = program.commands.find((command) => command.name() === "message");
expect(message).toBeDefined();
const helpSpy = vi.spyOn(message as Command, "help").mockImplementation(() => {
const message = requireProgramCommand(program, "message");
const helpSpy = vi.spyOn(message, "help").mockImplementation(() => {
throw new Error("help-called");
});