test(hermes): share required client lookups (#17350)

This commit is contained in:
Vincent Koc
2026-12-06 09:42:13 +08:00
committed by GitHub
parent 8b2ca551c9
commit eae531c0d3
@@ -38,6 +38,17 @@ const ownedYamlBlock = `command: ${JSON.stringify(command[0])}\n args: ${JSON
beforeEach(clearClientLocationEnvironment);
afterEach(() => vi.unstubAllEnvs());
const requiredHermesClient = (
home: string,
environment: Parameters<typeof supportedClients>[2],
) => {
const client = supportedClients(home, process.platform, environment).find(
({ name }) => name === "hermes",
);
if (client === undefined) throw new Error("missing Hermes client");
return client;
};
const hermesPath = (
env: Parameters<typeof supportedClients>[2],
platform: NodeJS.Platform = "linux",
@@ -57,10 +68,7 @@ describe("Hermes registration source retention", () => {
const original =
"shared: &shared\n mcp_servers:\n other: {command: other-server}\n<<: *shared\n";
await writeFile(path, original);
const client = supportedClients(home, process.platform, {
HERMES_HOME: directory,
}).find(({ name }) => name === "hermes");
if (client === undefined) throw new Error("missing Hermes client");
const client = requiredHermesClient(home, { HERMES_HOME: directory });
expect(
await configureClientConfiguration(client, {}, command),
).toMatchObject({
@@ -97,10 +105,7 @@ describe("Hermes registration source retention", () => {
const path = join(directory, "config.yaml");
const original = `shared: &shared\n mcp_servers:\n rea: ${ownedYamlInline}\n other: {command: other-server}\n<<: *shared\n`;
await writeFile(path, original);
const client = supportedClients(home, process.platform, {
HERMES_HOME: directory,
}).find(({ name }) => name === "hermes");
if (client === undefined) throw new Error("missing Hermes client");
const client = requiredHermesClient(home, { HERMES_HOME: directory });
expect(
await configureClientConfiguration(client, { CUSTOM: "value" }, command),
).toMatchObject({ status: "configured" });
@@ -130,10 +135,7 @@ describe("Hermes inherited registration removal", () => {
const path = join(directory, "config.yaml");
const original = `shared: &shared\n mcp_servers:\n rea: ${ownedYamlInline}\n other: {command: other-server}\n<<: *shared\n`;
await writeFile(path, original);
const client = supportedClients(home, process.platform, {
HERMES_HOME: directory,
}).find(({ name }) => name === "hermes");
if (client === undefined) throw new Error("missing Hermes client");
const client = requiredHermesClient(home, { HERMES_HOME: directory });
expect(
await configureClientConfiguration(client, { CUSTOM: "value" }, command),
).toMatchObject({ status: "configured" });
@@ -160,10 +162,7 @@ describe("Hermes inherited registration removal", () => {
await mkdir(directory);
const path = join(directory, "config.yaml");
await writeFile(path, original);
const client = supportedClients(home, process.platform, {
HERMES_HOME: directory,
}).find(({ name }) => name === "hermes");
if (client === undefined) throw new Error("missing Hermes client");
const client = requiredHermesClient(home, { HERMES_HOME: directory });
expect(
await systemUninstallHost(home).removeClient(client),
).toMatchObject({
@@ -184,10 +183,7 @@ describe("Hermes inherited registration removal", () => {
const path = join(directory, "config.yaml");
const original = `server_name: &server_name rea\nmcp_servers:\n ? *server_name\n :\n command: ${JSON.stringify(command[0])}\n args: ${JSON.stringify(command.slice(1))}\n marker: retained\n`;
await writeFile(path, original);
const client = supportedClients(home, process.platform, {
HERMES_HOME: directory,
}).find(({ name }) => name === "hermes");
if (client === undefined) throw new Error("missing Hermes client");
const client = requiredHermesClient(home, { HERMES_HOME: directory });
expect(
await configureClientConfiguration(client, { CUSTOM: "value" }, command),
).toMatchObject({ status: "configured" });
@@ -210,10 +206,7 @@ describe("Hermes inherited registration removal", () => {
const path = join(directory, "config.yaml");
const original = `defaults: &defaults\n metadata: {marker: old}\nmcp_servers:\n rea:\n <<: *defaults\n command: ${JSON.stringify(command[0])}\n args: ${JSON.stringify(command.slice(1))}\n`;
await writeFile(path, original);
const client = supportedClients(home, process.platform, {
HERMES_HOME: directory,
}).find(({ name }) => name === "hermes");
if (client === undefined) throw new Error("missing Hermes client");
const client = requiredHermesClient(home, { HERMES_HOME: directory });
expect(
await configureClientConfiguration(client, { CUSTOM: "value" }, command),
).toMatchObject({ status: "configured" });
@@ -233,10 +226,7 @@ describe("Hermes inherited registration removal", () => {
const path = join(directory, "config.yaml");
const original = `mcp_servers:\n rea:\n command: ${JSON.stringify(command[0])}\n args: ${JSON.stringify(command.slice(1))}\n 1: numeric\n "1": string\n`;
await writeFile(path, original);
const client = supportedClients(home, process.platform, {
HERMES_HOME: directory,
}).find(({ name }) => name === "hermes");
if (client === undefined) throw new Error("missing Hermes client");
const client = requiredHermesClient(home, { HERMES_HOME: directory });
expect(
await configureClientConfiguration(client, { CUSTOM: "value" }, command),
).toMatchObject({ status: "configured" });
@@ -256,10 +246,7 @@ describe("Hermes inherited registration removal", () => {
const path = join(directory, "config.yaml");
const original = `mcp_servers:\n rea:\n command: ${JSON.stringify(command[0])}\n args: ${JSON.stringify(command.slice(1))}\n metadata:\n${keys}\n`;
await writeFile(path, original);
const client = supportedClients(home, process.platform, {
HERMES_HOME: directory,
}).find(({ name }) => name === "hermes");
if (client === undefined) throw new Error("missing Hermes client");
const client = requiredHermesClient(home, { HERMES_HOME: directory });
const result = await configureClientConfiguration(
client,
{ CUSTOM: "value" },
@@ -282,10 +269,7 @@ describe("Hermes configuration paths", () => {
const original =
"history:\n 2026-10-14T00:00:00.123456Z: first\n 2026-10-14T00:00:00.123457Z: second\n";
await writeFile(path, original);
const client = supportedClients(home, process.platform, {
HERMES_HOME: directory,
}).find(({ name }) => name === "hermes");
if (client === undefined) throw new Error("missing Hermes client");
const client = requiredHermesClient(home, { HERMES_HOME: directory });
expect(
await configureClientConfiguration(client, {}, command),
).toMatchObject({
@@ -308,10 +292,7 @@ describe("Hermes configuration paths", () => {
await writeFile(join(home, "physical", "config.yaml"), original);
await writeFile(join(home, "config.yaml"), decoy);
const environment = { HERMES_HOME: selected };
const client = supportedClients(home, process.platform, environment).find(
({ name }) => name === "hermes",
);
if (client === undefined) throw new Error("missing Hermes client");
const client = requiredHermesClient(home, environment);
expect(client.markerPath).toBe(selected);
expect(client.configPath).toBe(`${selected}/config.yaml`);
expect(
@@ -448,10 +429,7 @@ describe("Hermes unresolved home identity", () => {
await symlink(external, join(native, "alias"));
const selected = join(native, "alias", "new-home");
const environment = { HERMES_HOME: selected };
const client = supportedClients(home, process.platform, environment).find(
({ name }) => name === "hermes",
);
if (client === undefined) throw new Error("missing Hermes client");
const client = requiredHermesClient(home, environment);
expect(client.markerPath).toBe(selected);
expect(
clientSkillDirectories(