Files
reverse-engineering-anything/src/domain/clientRegistrationCommand.test.ts
T
morluto 69630c0362 fix(cli)!: own MCP client registration boundaries (#10102)
* fix(cli)!: own MCP client registration boundaries

* fix(cli): bind registration to native connection facts

* test(cli): isolate registration failure and fixture controls

* test(cli): distinguish native syntax and launcher alignment

* fix(cli): preserve registration selection and cancellation

* fix(cli): honor Goose and Zed native settings paths

* fix(cli): honor registration output controls

* fix(cli): reject disabled Junie global locations
2026-11-11 09:05:21 -05:00

104 lines
2.9 KiB
TypeScript

import { expect, it } from "vitest";
import { parseClientRegistrationCommand } from "./clientRegistrationCommand.js";
it.each([
{
text: '"/fixture/server path" "" --mcp',
command: "/fixture/server path",
args: ["", "--mcp"],
},
{
text: String.raw`'C:\Program Files\server.exe' 'C:\data\file'`,
command: String.raw`C:\Program Files\server.exe`,
args: [String.raw`C:\data\file`],
},
{
text: `fix'ture-'"server" 'a'"'"'b'`,
command: "fixture-server",
args: ["a'b"],
},
{
text: "fixture-server '$TOKEN' ';' 'a\tb'",
command: "fixture-server",
args: ["$TOKEN", ";", "a\tb"],
},
])(
"preserves exact registration words from $text",
({ text, command, args }) => {
expect(parseClientRegistrationCommand(text)).toEqual({
ok: true,
value: { command, args },
});
},
);
it.each([
"",
" ",
'""',
"'' --mcp",
"'unfinished",
'server "unfinished',
null,
[1],
])("refuses a registration without an admitted executable (%j)", (input) =>
expect(parseClientRegistrationCommand(input).ok).toBe(false),
);
it("preserves structured default words without command-text tokenization", () => {
const selected = [
String.raw`C:\fixture\server.exe`,
"",
"a'b",
'x"y',
"tab\there",
"$TOKEN",
];
const parsed = parseClientRegistrationCommand(selected);
expect(parsed).toEqual({
ok: true,
value: { command: selected[0], args: selected.slice(1) },
});
expect(selected[1]).toBe("");
});
it("refuses HTTP transport sources without echoing URL credentials", () => {
for (const source of [
"https://fixture.invalid/mcp",
"HTTPS://fixture.invalid/mcp",
"http://fixture-user:fixture-secret@fixture.invalid/mcp",
]) {
const parsed = parseClientRegistrationCommand(source);
expect(parsed.ok).toBe(false);
if (parsed.ok) throw new Error("Expected an unsupported transport");
expect(parsed.error.kind).toBe("unsupported_transport");
expect(parsed.error.message).toContain("stdio");
expect(parsed.error.message).not.toContain("fixture-secret");
expect(parsed.error.message).not.toContain("fixture-user");
}
expect(
parseClientRegistrationCommand("server https://fixture.invalid/argument"),
).toEqual({
ok: true,
value: { command: "server", args: ["https://fixture.invalid/argument"] },
});
});
it.each([
{ input: "server\0suffix argument" },
{ input: "server 'arg\0suffix'" },
{ input: ["server\0suffix", "argument"] },
{ input: ["server", "arg\0suffix"] },
])(
"refuses OS-unrepresentable NUL in authored command/arguments: $input",
({ input }) => {
const parsed = parseClientRegistrationCommand(input);
expect(parsed).toMatchObject({
ok: false,
error: { kind: "invalid_argument" },
});
if (parsed.ok) throw Error("Expected rejected process arguments");
expect(parsed.error.message).toContain("NUL");
},
);