File size: 3,608 Bytes
eb3f11e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { Command } from "commander";
import { afterAll, describe, expect, it, vi } from "vitest";
import {
  itWithFish,
  itWithPowerShell,
  PowerShellCompletionRunner,
  runGeneratedBashCompletion,
  runGeneratedFishCompletion,
} from "../../completion-cli.test-support.js";
import type { MessageCliHelpers } from "./helpers.js";
import { registerMessageReadEditDeleteCommands } from "./register.read-edit-delete.js";

const powerShellCompletion = new PowerShellCompletionRunner();
afterAll(async () => {
  await powerShellCompletion.close();
});

function createReadProgram() {
  const program = new Command().name("openclaw").exitOverride();
  program.configureOutput({ writeErr: () => {} });
  const message = program.command("message");
  const runMessageAction = vi.fn(async () => undefined);
  const helpers: MessageCliHelpers = {
    withMessageBase: (command) => command.option("--channel <channel>"),
    withMessageTarget: (command) => command.option("-t, --target <target>"),
    withRequiredMessageTarget: (command) => command.requiredOption("-t, --target <target>"),
    runMessageAction,
  };
  registerMessageReadEditDeleteCommands(message, helpers);
  return { program, message, runMessageAction };
}

describe("message read legacy option visibility", () => {
  it("keeps the shipped spelling accepted while forwarding supported read options", async () => {
    const { program, runMessageAction } = createReadProgram();
    await program.parseAsync(
      ["message", "read", "--target", "channel:123", "--include-thread", "--around", "42"],
      { from: "user" },
    );
    expect(runMessageAction).toHaveBeenCalledWith(
      "read",
      expect.objectContaining({
        target: "channel:123",
        around: "42",
        includeThread: true,
      }),
    );
  });

  it("rejects an unknown option at the same parser boundary", async () => {
    const { program, runMessageAction } = createReadProgram();
    await expect(
      program.parseAsync(["message", "read", "--target", "channel:123", "--unknown-read-option"], {
        from: "user",
      }),
    ).rejects.toMatchObject({ code: "commander.unknownOption" });
    expect(runMessageAction).not.toHaveBeenCalled();
  });

  it("shows supported read flags while omitting the inert spelling", () => {
    const { message } = createReadProgram();
    const read = message.commands.find((command) => command.name() === "read");
    expect(read).toBeDefined();
    const help = read!.helpInformation();
    expect(help).toContain("--around <id>");
    expect(help).toContain("--thread-id <id>");
    expect(help).not.toContain("--include-thread");
  });

  const engines = [
    {
      name: "Bash",
      test: it.skipIf(process.platform === "win32"),
      complete: (program: Command) =>
        runGeneratedBashCompletion(program, ["openclaw", "message", "read", "--"]),
    },
    {
      name: "Fish",
      test: itWithFish,
      complete: (program: Command) =>
        runGeneratedFishCompletion(program, "openclaw message read --"),
    },
    {
      name: "PowerShell",
      test: itWithPowerShell,
      complete: (program: Command) =>
        powerShellCompletion.complete(program, "openclaw message read --"),
    },
  ];
  for (const engine of engines) {
    engine.test(`hides the inert spelling from real ${engine.name} completions`, async () => {
      const completions = await engine.complete(createReadProgram().program);
      expect(completions).toContain("--around");
      expect(completions).toContain("--thread-id");
      expect(completions).not.toContain("--include-thread");
    });
  }
});