test(hermes): share REA registration fixture edits (#15998)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-02 14:07:59 +00:00
1 parent 6e689d2627
commit 3ed912944c
1 file changed
+46 -79
+46 -79
View File
@@ -17,10 +17,13 @@ import {
stringifyHermesConfigurationYaml,
} from "./HermesConfigurationYaml.js";
const editReaRegistration = (source: string, value: unknown): string =>
editHermesConfigurationYaml(source, ["mcp_servers", "rea"], value);
it("uses the first inherited mapping when creating an override", () => {
const source =
"first: &first\n mcp_servers:\n one: {command: first}\nsecond: &second\n mcp_servers:\n two: {command: second}\n<<: [*first, *second]\n";
const updated = editHermesConfigurationYaml(source, ["mcp_servers", "rea"], {
const updated = editReaRegistration(source, {
command: "rea",
});
const parsed = parseHermesConfigurationYaml(updated) as {
@@ -43,7 +46,7 @@ it("refuses an inherited override when an existing anchor name is shadowed", ()
const source =
"shared: &shared\n mcp_servers: &table\n other: {command: first}\nshadow: &table {other: {command: second}}\n<<: *shared\n";
expect(() =>
editHermesConfigurationYaml(source, ["mcp_servers", "rea"], {
editReaRegistration(source, {
command: "rea",
}),
).toThrow(/anchor is shadowed/);
@@ -55,7 +58,7 @@ it("retains inherited YAML settings when updating a registration", () => {
const parsed = parseHermesConfigurationYaml(source) as {
mcp_servers: { rea: Record<string, unknown> };
};
const updated = editHermesConfigurationYaml(source, ["mcp_servers", "rea"], {
const updated = editReaRegistration(source, {
...parsed.mcp_servers.rea,
command: "rea",
});
@@ -64,17 +67,17 @@ it("retains inherited YAML settings when updating a registration", () => {
expect(parseHermesConfigurationYaml(changedDefault)).toMatchObject({
mcp_servers: { rea: { command: "rea", enabled: true } },
});
const overridden = editHermesConfigurationYaml(
source,
["mcp_servers", "rea"],
{ ...parsed.mcp_servers.rea, command: "rea", enabled: true },
);
const overridden = editReaRegistration(source, {
...parsed.mcp_servers.rea,
command: "rea",
enabled: true,
});
expect(overridden).toContain("<<: *defaults");
expect(parseHermesConfigurationYaml(overridden)).toMatchObject({
mcp_servers: { rea: { command: "rea", enabled: true } },
});
expect(() =>
editHermesConfigurationYaml(source, ["mcp_servers", "rea"], {
editReaRegistration(source, {
command: "rea",
}),
).toThrow(/Cannot remove inherited YAML setting/);
@@ -83,7 +86,7 @@ it("retains inherited YAML settings when updating a registration", () => {
it("preserves annotations on changed registration mappings and scalar fields", () => {
const source =
"mcp_servers:\n rea: # registration note\n command: old # command note\n env: # environment note\n MODE: old # mode note\n args: # arguments note\n - old # argument note\n";
const updated = editHermesConfigurationYaml(source, ["mcp_servers", "rea"], {
const updated = editReaRegistration(source, {
command: "new",
env: { MODE: "new" },
args: ["new"],
@@ -107,7 +110,7 @@ it("preserves annotations on changed registration mappings and scalar fields", (
it("refreshes an anchored entry without changing another server's resolved value", () => {
const source =
"mcp_servers:\n rea: &server\n command: old\n enabled: false\n other: *server # Independent server\n";
const updated = editHermesConfigurationYaml(source, ["mcp_servers", "rea"], {
const updated = editReaRegistration(source, {
command: "rea",
enabled: true,
});
@@ -123,7 +126,7 @@ it("refreshes an anchored entry without changing another server's resolved value
it("keeps comments once when an updated anchored entry has a surviving consumer", () => {
const source =
"mcp_servers:\n rea: &server # registration note\n # command key note\n command: old # command note\n enabled: true # enabled note\n env: # environment note\n MODE: old # mode note\n other: *server\n";
const updated = editHermesConfigurationYaml(source, ["mcp_servers", "rea"], {
const updated = editReaRegistration(source, {
command: "new",
enabled: true,
env: { MODE: "new" },
@@ -156,9 +159,7 @@ describe("Hermes surviving anchor definitions", () => {
"defaults: &settings {MODE: 'off'}\nmcp_servers:\n rea: &server\n command: old\n env: *settings\n" +
(shadowed ? "later: &settings {MODE: 'later'}\n" : "") +
"observer: *server\npeer: *settings\n";
const result = parse(
editHermesConfigurationYaml(source, ["mcp_servers", "rea"], entry),
);
const result = parse(editReaRegistration(source, entry));
expect(result.defaults).toEqual({ MODE: "off" });
expect(result.mcp_servers).toEqual(
entry === undefined ? {} : { rea: entry },
@@ -180,9 +181,7 @@ describe("Hermes surviving anchor definitions", () => {
"still refuses a surviving %s dependency that cannot be retained",
(reference, refusal) => {
const source = `defaults: &settings {dependency: *${reference}}\nmcp_servers:\n rea: &server {env: *settings}\nobserver: *server\n`;
expect(() =>
editHermesConfigurationYaml(source, ["mcp_servers", "rea"], undefined),
).toThrow(refusal);
expect(() => editReaRegistration(source, undefined)).toThrow(refusal);
},
);
});
@@ -193,11 +192,7 @@ describe("Hermes copied anchor comments", () => {
(entry) => {
const source =
"mcp_servers:\n rea:\n # Definition leading note\n &server {command: old} # Definition trailing note\n other:\n # Consumer leading note\n *server # Consumer trailing note\nobserver: *server # Later consumer note\n";
const updated = editHermesConfigurationYaml(
source,
["mcp_servers", "rea"],
entry,
);
const updated = editReaRegistration(source, entry);
const result = parse(updated);
expect(result).toEqual({
mcp_servers: {
@@ -225,11 +220,7 @@ describe("Hermes anchored-entry consumers", () => {
(entry) => {
const source =
"mcp_servers:\n &server_name rea: {command: old}\nobserver: *server_name # Keep registration name\n";
const updated = editHermesConfigurationYaml(
source,
["mcp_servers", "rea"],
entry,
);
const updated = editReaRegistration(source, entry);
expect(parseHermesConfigurationYaml(updated)).toEqual({
mcp_servers: entry === undefined ? {} : { rea: entry },
observer: "rea",
@@ -246,9 +237,7 @@ describe("Hermes anchored-entry consumers", () => {
const source =
"mcp_servers:\n &server_name rea: &server {command: old}\n other: *server\nobserver: *server_name\nlater: &server_name later\nlater_observer: *server_name\n";
expect(
parseHermesConfigurationYaml(
editHermesConfigurationYaml(source, ["mcp_servers", "rea"], undefined),
),
parseHermesConfigurationYaml(editReaRegistration(source, undefined)),
).toEqual({
mcp_servers: { other: { command: "old" } },
observer: "rea",
@@ -263,7 +252,7 @@ describe("Hermes anchored-entry consumers", () => {
const source =
"mcp_servers:\n rea:\n command: old\n env: &settings\n MODE: 'off'\n other:\n command: other\n env: *settings\n";
const result = parseHermesConfigurationYaml(
editHermesConfigurationYaml(source, ["mcp_servers", "rea"], entry),
editReaRegistration(source, entry),
);
expect(result).toEqual({
mcp_servers: {
@@ -279,11 +268,7 @@ describe("Hermes anchored-entry consumers", () => {
(entry) => {
const source =
"defaults: &settings {MODE: 'old'}\nmcp_servers:\n rea: &entry\n command: old\n env:\n # Keep nested leading comment\n *settings # Keep nested reference comment\n other: *entry # Keep external reference comment\n";
const updated = editHermesConfigurationYaml(
source,
["mcp_servers", "rea"],
entry,
);
const updated = editReaRegistration(source, entry);
expect(parseHermesConfigurationYaml(updated)).toEqual({
defaults: { MODE: "old" },
mcp_servers: {
@@ -301,9 +286,7 @@ describe("Hermes anchored-entry consumers", () => {
const source =
"mcp_servers:\n rea: &server {command: old}\n other: *server\nlater: &server {command: later}\nobserver: *server\n";
expect(
parseHermesConfigurationYaml(
editHermesConfigurationYaml(source, ["mcp_servers", "rea"], undefined),
),
parseHermesConfigurationYaml(editReaRegistration(source, undefined)),
).toEqual({
mcp_servers: { other: { command: "old" } },
later: { command: "later" },
@@ -319,9 +302,7 @@ describe("Hermes anchored-entry consumers", () => {
const source =
"mcp_servers:\n rea: &entry\n command: old\n env: &settings {MODE: 'off'}\n" +
(childFirst ? child + parent : parent + child);
const result = parse(
editHermesConfigurationYaml(source, ["mcp_servers", "rea"], undefined),
);
const result = parse(editReaRegistration(source, undefined));
expect(result).toEqual({
mcp_servers: {},
child: { MODE: "off" },
@@ -335,11 +316,7 @@ describe("Hermes anchored-entry consumers", () => {
const source =
"mcp_servers:\n rea: &server {command: old}\nobservers:\n" +
" - *server\n".repeat(50);
const updated = editHermesConfigurationYaml(
source,
["mcp_servers", "rea"],
undefined,
);
const updated = editReaRegistration(source, undefined);
expect(parseHermesConfigurationYaml(updated)).toEqual({
mcp_servers: {},
observers: Array.from({ length: 50 }, () => ({ command: "old" })),
@@ -354,9 +331,7 @@ describe("Hermes anchored-entry consumers", () => {
"still refuses a copied %s dependency that cannot be retained",
(reference, refusal) => {
const source = `mcp_servers:\n rea: &server\n command: old\n dependency: *${reference}\nobserver: *server\n`;
expect(() =>
editHermesConfigurationYaml(source, ["mcp_servers", "rea"], undefined),
).toThrow(refusal);
expect(() => editReaRegistration(source, undefined)).toThrow(refusal);
},
);
});
@@ -371,9 +346,8 @@ it.each([
`${version === "1.2" ? "%YAML 1.2\n---\n" : ""}` +
"mcp_servers:\n rea: &server\n command: old-rea\n args: [mcp]\n env: &environment {MODE: 'on'}\n other: *server # caller binding\nobserver: *server\nenvironment: *environment\n";
const before = parse(original, { version });
const updated = editHermesConfigurationYaml(
const updated = editReaRegistration(
original,
["mcp_servers", "rea"],
operation === "refresh"
? { command: "new-rea", args: ["mcp"] }
: undefined,
@@ -390,9 +364,8 @@ it.each([
});
expect(updated).toContain("# caller binding");
expect(
editHermesConfigurationYaml(
editReaRegistration(
updated,
["mcp_servers", "rea"],
operation === "refresh"
? { command: "new-rea", args: ["mcp"] }
: undefined,
@@ -445,9 +418,7 @@ describe("Hermes YAML deletion", () => {
]) {
it(`still refuses deletion through a table containing a ${name} alias`, () => {
const source = `defaults: &servers\n rea: {command: rea}\n other: *${reference}\nmcp_servers: *servers\n`;
expect(() =>
editHermesConfigurationYaml(source, ["mcp_servers", "rea"], undefined),
).toThrow(TypeError);
expect(() => editReaRegistration(source, undefined)).toThrow(TypeError);
});
}
});
@@ -457,7 +428,7 @@ describe("Hermes configuration YAML", () => {
const source =
"mcp_servers:\n rea:\n command: old\n args:\n - 'mcp'\n";
expect(
editHermesConfigurationYaml(source, ["mcp_servers", "rea"], {
editReaRegistration(source, {
command: "rea",
args: ["mcp"],
}),
@@ -467,14 +438,10 @@ describe("Hermes configuration YAML", () => {
it("retains explicit string tags on unchanged keys and values", () => {
const source =
"%YAML 1.2\n---\nmcp_servers:\n rea:\n command: old\n env:\n !!str ON: !!str off\n";
const written = editHermesConfigurationYaml(
source,
["mcp_servers", "rea"],
{
command: "rea",
env: { ON: "off" },
},
);
const written = editReaRegistration(source, {
command: "rea",
env: { ON: "off" },
});
expect(written).toBe(source.replace("command: old", 'command: "rea"'));
expect(
parse(written.slice("%YAML 1.2\n---\n".length), { version: "1.1" }),
@@ -658,7 +625,7 @@ it("retains exact integer settings through a parsed Hermes launcher refresh", ()
it("keeps argument annotations with unique values and retains removed annotations on the list", () => {
const source =
"mcp_servers:\n rea:\n args:\n - mcp # mcp note\n - old # removed note\n - dup # first duplicate\n - dup # second duplicate\n";
const updated = editHermesConfigurationYaml(source, ["mcp_servers", "rea"], {
const updated = editReaRegistration(source, {
args: ["script", "mcp", "dup"],
});
expect(parseHermesConfigurationYaml(updated)).toEqual({
@@ -679,7 +646,7 @@ describe("Hermes registration refresh around anchors and merges", () => {
it("keeps an alias's value when an earlier same-name anchor would capture it", () => {
const source =
"defaults: &launcher /other/rea\nmcp_servers:\n rea:\n command: &launcher /old/rea\n env: {REA_LAUNCHER: *launcher}\n";
const out = editHermesConfigurationYaml(source, ["mcp_servers", "rea"], {
const out = editReaRegistration(source, {
command: "/new/rea",
env: { REA_LAUNCHER: "/old/rea" },
});
@@ -694,7 +661,7 @@ describe("Hermes registration refresh around anchors and merges", () => {
it("keeps the comment on an alias the refresh materializes", () => {
const source =
"mcp_servers:\n rea:\n command: &launcher /old/rea\n env:\n REA_LAUNCHER: *launcher # explanation\n";
const out = editHermesConfigurationYaml(source, ["mcp_servers", "rea"], {
const out = editReaRegistration(source, {
command: "/new/rea",
env: { REA_LAUNCHER: "/old/rea" },
});
@@ -707,7 +674,7 @@ describe("Hermes registration refresh around anchors and merges", () => {
it("keeps an alias to a sibling anchor that survives the refresh", () => {
const source =
"mcp_servers:\n rea:\n command: old\n setting: &setting keep\n metadata: {nested: *setting}\n";
const out = editHermesConfigurationYaml(source, ["mcp_servers", "rea"], {
const out = editReaRegistration(source, {
command: "new",
setting: "keep",
metadata: { nested: "keep" },
@@ -728,7 +695,7 @@ describe("Hermes registration refresh through inherited merges", () => {
const source =
"remote: &remote\n url: https://example.invalid\n transport: sse\nmcp_servers:\n rea:\n <<: *remote\n url: https://local.invalid\n transport: sse\n";
expect(() =>
editHermesConfigurationYaml(source, ["mcp_servers", "rea"], {
editReaRegistration(source, {
command: "rea",
args: ["mcp"],
}),
@@ -738,7 +705,7 @@ describe("Hermes registration refresh through inherited merges", () => {
it("replaces an inherited remote registration without its remote selectors", () => {
const source =
"shared: &shared\n rea: {url: https://example.invalid, transport: sse}\nmcp_servers:\n <<: *shared\n";
const out = editHermesConfigurationYaml(source, ["mcp_servers", "rea"], {
const out = editReaRegistration(source, {
command: "rea",
args: ["mcp"],
});
@@ -752,7 +719,7 @@ describe("Hermes registration refresh through inherited merges", () => {
const source =
"field: &field env\nmcp_servers:\n rea:\n command: rea\n *field : {A: first}\n env: {A: second}\n";
expect(() =>
editHermesConfigurationYaml(source, ["mcp_servers", "rea"], {
editReaRegistration(source, {
command: "rea",
env: { A: "third" },
}),
@@ -762,7 +729,7 @@ describe("Hermes registration refresh through inherited merges", () => {
it("edits a field whose key is an alias to a shared string, keeping the alias", () => {
const source =
"field: &field env\nmcp_servers:\n rea:\n command: rea\n *field : {A: '1'}\n";
const out = editHermesConfigurationYaml(source, ["mcp_servers", "rea"], {
const out = editReaRegistration(source, {
command: "rea",
env: { A: "2" },
});
@@ -776,7 +743,7 @@ describe("Hermes registration refresh through inherited merges", () => {
it("writes a plain key when an aliased key's anchor is rebuilt by the same edit", () => {
const source =
"mcp_servers:\n rea:\n command: &field env\n *field : {A: '1'}\n";
const out = editHermesConfigurationYaml(source, ["mcp_servers", "rea"], {
const out = editReaRegistration(source, {
command: "rea",
env: { A: "2" },
});
@@ -789,7 +756,7 @@ describe("Hermes registration refresh through inherited merges", () => {
it("materializes an alias whose sibling anchor the refresh replaces", () => {
const source =
"mcp_servers:\n rea:\n command: &launcher /old/rea\n env: {REA_LAUNCHER: *launcher}\n";
const out = editHermesConfigurationYaml(source, ["mcp_servers", "rea"], {
const out = editReaRegistration(source, {
command: "/new/rea",
env: { REA_LAUNCHER: "/old/rea" },
});
@@ -803,7 +770,7 @@ describe("Hermes registration refresh through inherited merges", () => {
it("materializes an alias to an anchor moved to an outside consumer", () => {
const source =
"mcp_servers:\n rea:\n command: rea\n setting: &setting keep\n metadata: {nested: *setting}\nobserver: *setting\n";
const out = editHermesConfigurationYaml(source, ["mcp_servers", "rea"], {
const out = editReaRegistration(source, {
command: "rea2",
setting: "changed",
metadata: { nested: "keep" },
@@ -860,7 +827,7 @@ describe("Hermes registration refresh through inherited merges", () => {
it("overrides an inherited registration with only its changed fields", () => {
const source =
"shared: &shared\n rea: {command: rea, metadata: {marker: old}}\nmcp_servers:\n <<: *shared\n";
const out = editHermesConfigurationYaml(source, ["mcp_servers", "rea"], {
const out = editReaRegistration(source, {
command: "rea",
metadata: { marker: "old" },
env: { A: "1" },