mirror of
https://github.com/morluto/rea.git
synced 2026-11-23 23:15:58 +00:00
perf(setup): index YAML alias bindings in document order (#13295)
This commit is contained in:
1 parent
825afe019c
commit
560e2ef267
4 files changed
+303
-421
No files matched your search
@@ -145,24 +145,32 @@ it("keeps comments once when an updated anchored entry has a surviving consumer"
|
||||
});
|
||||
|
||||
describe("Hermes surviving anchor definitions", () => {
|
||||
for (const shadowed of [false, true]) {
|
||||
it.each([undefined, { command: "rea" }])(
|
||||
`retains surviving shared target identity with shadowed=${shadowed} when writing %j`,
|
||||
(entry) => {
|
||||
const source =
|
||||
"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),
|
||||
);
|
||||
expect(result.defaults).toEqual({ MODE: "off" });
|
||||
expect(result.observer.env).toBe(result.defaults);
|
||||
expect(result.peer).toBe(shadowed ? result.later : result.defaults);
|
||||
if (shadowed) expect(result.peer).not.toBe(result.defaults);
|
||||
},
|
||||
);
|
||||
}
|
||||
it.each([
|
||||
[false, { command: "rea" }],
|
||||
[true, undefined],
|
||||
] as const)(
|
||||
"retains the original shared target with a later redefinition=%s",
|
||||
(shadowed, entry) => {
|
||||
const source =
|
||||
"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),
|
||||
);
|
||||
expect(result.defaults).toEqual({ MODE: "off" });
|
||||
expect(result.mcp_servers).toEqual(
|
||||
entry === undefined ? {} : { rea: entry },
|
||||
);
|
||||
expect(result.observer).toEqual({ command: "old", env: { MODE: "off" } });
|
||||
expect(result.observer.env).toBe(result.defaults);
|
||||
expect(result.peer).toBe(shadowed ? result.later : result.defaults);
|
||||
if (shadowed) {
|
||||
expect(result.later).toEqual({ MODE: "later" });
|
||||
expect(result.peer).not.toBe(result.defaults);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["settings", "missing"])(
|
||||
"still refuses a surviving %s dependency that cannot be retained",
|
||||
@@ -176,20 +184,6 @@ describe("Hermes surviving anchor definitions", () => {
|
||||
});
|
||||
|
||||
describe("Hermes copied anchor comments", () => {
|
||||
it("retains the removed anchor definition comment at its surviving consumer", () => {
|
||||
const source =
|
||||
"mcp_servers:\n rea: &server {command: old} # Keep definition explanation\n other: *server\n";
|
||||
const updated = editHermesConfigurationYaml(
|
||||
source,
|
||||
["mcp_servers", "rea"],
|
||||
undefined,
|
||||
);
|
||||
expect(parseHermesConfigurationYaml(updated)).toEqual({
|
||||
mcp_servers: { other: { command: "old" } },
|
||||
});
|
||||
expect(updated).toContain("# Keep definition explanation");
|
||||
});
|
||||
|
||||
it.each([undefined, { command: "rea" }])(
|
||||
"combines definition and consumer comments without copying shared definitions twice when writing %j",
|
||||
(entry) => {
|
||||
@@ -299,22 +293,6 @@ describe("Hermes anchored-entry consumers", () => {
|
||||
},
|
||||
);
|
||||
|
||||
it("binds copied nested aliases before a later anchor reuses their name", () => {
|
||||
const source =
|
||||
"defaults: &settings {MODE: 'old'}\nmcp_servers:\n rea: &entry\n command: old\n env: *settings\nlater: &settings {MODE: 'later'}\nobserver: *entry\n";
|
||||
const result = parseHermesConfigurationYaml(
|
||||
editHermesConfigurationYaml(source, ["mcp_servers", "rea"], {
|
||||
command: "rea",
|
||||
}),
|
||||
);
|
||||
expect(result).toEqual({
|
||||
defaults: { MODE: "old" },
|
||||
mcp_servers: { rea: { command: "rea" } },
|
||||
later: { MODE: "later" },
|
||||
observer: { command: "old", env: { MODE: "old" } },
|
||||
});
|
||||
});
|
||||
|
||||
it("changes only consumers of the removed definition when an anchor name repeats", () => {
|
||||
const source =
|
||||
"mcp_servers:\n rea: &server {command: old}\n other: *server\nlater: &server {command: later}\nobserver: *server\n";
|
||||
@@ -376,43 +354,45 @@ describe("Hermes anchored-entry consumers", () => {
|
||||
);
|
||||
});
|
||||
|
||||
for (const version of ["1.1", "1.2"] as const)
|
||||
it.each(["refresh", "remove"] as const)(
|
||||
`preserves YAML ${version} consumers of a replaced REA anchor during %s`,
|
||||
(operation) => {
|
||||
const original =
|
||||
`${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(
|
||||
original,
|
||||
it.each([
|
||||
["1.1", "remove"],
|
||||
["1.2", "refresh"],
|
||||
] as const)(
|
||||
"preserves YAML %s consumers of a replaced REA anchor during %s",
|
||||
(version, operation) => {
|
||||
const original =
|
||||
`${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(
|
||||
original,
|
||||
["mcp_servers", "rea"],
|
||||
operation === "refresh"
|
||||
? { command: "new-rea", args: ["mcp"] }
|
||||
: undefined,
|
||||
);
|
||||
expect(parse(updated, { version })).toEqual({
|
||||
mcp_servers: {
|
||||
...(operation === "refresh"
|
||||
? { rea: { command: "new-rea", args: ["mcp"] } }
|
||||
: {}),
|
||||
other: before.mcp_servers.other,
|
||||
},
|
||||
observer: before.observer,
|
||||
environment: before.environment,
|
||||
});
|
||||
expect(updated).toContain("# caller binding");
|
||||
expect(
|
||||
editHermesConfigurationYaml(
|
||||
updated,
|
||||
["mcp_servers", "rea"],
|
||||
operation === "refresh"
|
||||
? { command: "new-rea", args: ["mcp"] }
|
||||
: undefined,
|
||||
);
|
||||
expect(parse(updated, { version })).toEqual({
|
||||
mcp_servers: {
|
||||
...(operation === "refresh"
|
||||
? { rea: { command: "new-rea", args: ["mcp"] } }
|
||||
: {}),
|
||||
other: before.mcp_servers.other,
|
||||
},
|
||||
observer: before.observer,
|
||||
environment: before.environment,
|
||||
});
|
||||
expect(updated).toContain("# caller binding");
|
||||
expect(
|
||||
editHermesConfigurationYaml(
|
||||
updated,
|
||||
["mcp_servers", "rea"],
|
||||
operation === "refresh"
|
||||
? { command: "new-rea", args: ["mcp"] }
|
||||
: undefined,
|
||||
),
|
||||
).toBe(updated);
|
||||
},
|
||||
);
|
||||
),
|
||||
).toBe(updated);
|
||||
},
|
||||
);
|
||||
|
||||
describe("Hermes YAML deletion", () => {
|
||||
for (const version of ["1.1", "1.2"] as const) {
|
||||
|
||||
@@ -171,16 +171,17 @@ export const preserveYamlAliasValues = (
|
||||
});
|
||||
if (removed.size === 0) return new Set();
|
||||
const targets = new Map<Alias, Node | undefined>();
|
||||
const names = new Set<string>();
|
||||
const anchors = new Map<string, Node>();
|
||||
const reusedNames = new Set<string>();
|
||||
visit(document, {
|
||||
Alias: (_key, node) => {
|
||||
targets.set(node, node.resolve(document));
|
||||
// YAML binds an alias to the last preceding definition of its name.
|
||||
targets.set(node, anchors.get(node.source));
|
||||
},
|
||||
Value: (_key, node) => {
|
||||
if (node.anchor === undefined) return;
|
||||
if (names.has(node.anchor)) reusedNames.add(node.anchor);
|
||||
names.add(node.anchor);
|
||||
if (anchors.has(node.anchor)) reusedNames.add(node.anchor);
|
||||
anchors.set(node.anchor, node);
|
||||
},
|
||||
});
|
||||
const context: AliasCopies = {
|
||||
@@ -191,7 +192,7 @@ export const preserveYamlAliasValues = (
|
||||
survivingNames: new Map(),
|
||||
visiting: new Set(),
|
||||
validated: new Set(),
|
||||
names,
|
||||
names: new Set(anchors.keys()),
|
||||
reusedNames,
|
||||
};
|
||||
const replacements = new Map<Node, Node>();
|
||||
|
||||
@@ -1,40 +1,42 @@
|
||||
import {
|
||||
access,
|
||||
mkdir,
|
||||
readFile,
|
||||
readdir,
|
||||
rm,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { access, mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { join, resolve } from "node:path";
|
||||
import { parse, stringify } from "yaml";
|
||||
import { afterAll, beforeAll, beforeEach, expect } from "vitest";
|
||||
import { expect } from "vitest";
|
||||
|
||||
import { currentClientRegistrationCommand } from "../../../src/application/ClientRegistrationIdentity.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
import {
|
||||
createTestWorkspace,
|
||||
removeTestWorkspace,
|
||||
} from "../../support/workspace/workspaceFixture.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { cliTest, type TestCli } from "../../support/cli/cliFixture.js";
|
||||
|
||||
let sharedHermesHome = "";
|
||||
const setup = [
|
||||
"setup",
|
||||
"--client",
|
||||
"hermes",
|
||||
"--skill=false",
|
||||
"--yes",
|
||||
"--json",
|
||||
];
|
||||
const uninstall = ["uninstall", "--json"];
|
||||
|
||||
beforeAll(async () => {
|
||||
sharedHermesHome = (await createTestWorkspace("rea-hermes-alias-shared-"))
|
||||
.root;
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
for (const entry of await readdir(sharedHermesHome)) {
|
||||
await rm(join(sharedHermesHome, entry), { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
if (sharedHermesHome !== "") {
|
||||
await removeTestWorkspace(sharedHermesHome);
|
||||
}
|
||||
});
|
||||
const hermesProfile = async (cli: TestCli) => {
|
||||
const home = await createTestTempDirectory("rea-hermes-aliased-table-");
|
||||
const profile = join(home, "profile");
|
||||
await mkdir(profile);
|
||||
return {
|
||||
home,
|
||||
config: join(profile, "config.yaml"),
|
||||
run: (arguments_: readonly string[], overrides?: NodeJS.ProcessEnv) =>
|
||||
cli.run({
|
||||
arguments: arguments_,
|
||||
cwd: home,
|
||||
environment: {
|
||||
USERPROFILE: home,
|
||||
HERMES_HOME: profile,
|
||||
HOPPER_LAUNCHER_PATH: process.execPath,
|
||||
...overrides,
|
||||
},
|
||||
}),
|
||||
};
|
||||
};
|
||||
|
||||
const configuration = (
|
||||
version: "1.1" | "1.2",
|
||||
@@ -59,141 +61,92 @@ const configuration = (
|
||||
};
|
||||
};
|
||||
|
||||
for (const version of ["1.1", "1.2"] as const) {
|
||||
for (const existing of [false, true]) {
|
||||
cliTest(
|
||||
`Hermes YAML ${version} ${existing ? "refreshes" : "adds"} REA in an aliased table without changing its source`,
|
||||
async ({ cli }) => {
|
||||
const home = sharedHermesHome;
|
||||
const ghidra = join(home, "missing-ghidra");
|
||||
const java = join(home, "missing-java");
|
||||
const profile = join(home, "profile");
|
||||
const config = join(profile, "config.yaml");
|
||||
const original = configuration(version, existing);
|
||||
const before = parse(original.text, { version });
|
||||
await mkdir(profile);
|
||||
await writeFile(config, original.text);
|
||||
const run = (arguments_: readonly string[]) =>
|
||||
cli.run({
|
||||
arguments: arguments_,
|
||||
cwd: home,
|
||||
environment: {
|
||||
USERPROFILE: home,
|
||||
HERMES_HOME: profile,
|
||||
HOPPER_LAUNCHER_PATH: process.execPath,
|
||||
GHIDRA_INSTALL_DIR: ghidra,
|
||||
JAVA_HOME: java,
|
||||
},
|
||||
});
|
||||
const setup = [
|
||||
"setup",
|
||||
"--client",
|
||||
"hermes",
|
||||
"--skill=false",
|
||||
"--yes",
|
||||
"--json",
|
||||
];
|
||||
const applied = await run(setup);
|
||||
expect(applied.exitCode).toBe(0);
|
||||
expect(applied.json).toMatchObject({ status: "ready" });
|
||||
const configured = await readFile(config, "utf8");
|
||||
const parsed = parse(configured, { version });
|
||||
expect(parsed.server_defaults).toEqual(before.server_defaults);
|
||||
expect(parsed.observer).toEqual(before.observer);
|
||||
expect(parsed.mcp_servers.other).toEqual(before.mcp_servers.other);
|
||||
expect(parsed.mcp_servers.rea).toMatchObject({ enabled: true });
|
||||
if (existing)
|
||||
expect(parsed.mcp_servers.rea.env).toEqual({
|
||||
FLAG: "on",
|
||||
HOPPER_LAUNCHER_PATH: process.execPath,
|
||||
GHIDRA_INSTALL_DIR: ghidra,
|
||||
JAVA_HOME: java,
|
||||
});
|
||||
expect(configured.startsWith(original.defaults)).toBe(true);
|
||||
expect(configured).toContain("# Selected table");
|
||||
expect(configured.match(/&servers\b/gu)).toHaveLength(1);
|
||||
expect(configured.match(/&server\b/gu)).toHaveLength(1);
|
||||
expect(await readFile(`${config}.rea.backup`, "utf8")).toBe(
|
||||
original.text,
|
||||
);
|
||||
const doctor = await run(["doctor", "--client", "hermes", "--json"]);
|
||||
expect(doctor.exitCode).toBe(0);
|
||||
expect(doctor.json).toMatchObject({
|
||||
healthy: true,
|
||||
identity: { registrations: [{ client: "hermes", state: "aligned" }] },
|
||||
});
|
||||
const repeat = await run(setup);
|
||||
expect(repeat.exitCode).toBe(0);
|
||||
expect(repeat.json).toMatchObject({
|
||||
status: "ready",
|
||||
plannedActions: [],
|
||||
appliedActions: [],
|
||||
});
|
||||
expect(await readFile(config, "utf8")).toBe(configured);
|
||||
const removed = await run(["uninstall", "--json"]);
|
||||
expect(removed.exitCode).toBe(0);
|
||||
const remaining = parse(await readFile(config, "utf8"), { version });
|
||||
expect(remaining.mcp_servers).toEqual({
|
||||
other: before.mcp_servers.other,
|
||||
});
|
||||
expect(remaining.server_defaults).toEqual(before.server_defaults);
|
||||
expect(remaining.observer).toEqual(before.observer);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (const version of ["1.1", "1.2"] as const) {
|
||||
for (const [version, existing] of [
|
||||
["1.1", false],
|
||||
["1.2", true],
|
||||
] as const) {
|
||||
cliTest(
|
||||
`Hermes YAML ${version} uninstall preserves an aliased table without REA`,
|
||||
`Hermes YAML ${version} ${existing ? "refreshes" : "adds"} REA in an aliased table without changing its source`,
|
||||
async ({ cli }) => {
|
||||
const home = sharedHermesHome;
|
||||
const profile = join(home, "profile");
|
||||
const config = join(profile, "config.yaml");
|
||||
const original = configuration(version, false).text;
|
||||
await mkdir(profile);
|
||||
await writeFile(config, original);
|
||||
const removed = await cli.run({
|
||||
arguments: ["uninstall", "--json"],
|
||||
cwd: home,
|
||||
environment: {
|
||||
USERPROFILE: home,
|
||||
HERMES_HOME: profile,
|
||||
const { home, config, run } = await hermesProfile(cli);
|
||||
const ghidra = join(home, "missing-ghidra");
|
||||
const java = join(home, "missing-java");
|
||||
const environment = { GHIDRA_INSTALL_DIR: ghidra, JAVA_HOME: java };
|
||||
const original = configuration(version, existing);
|
||||
const before = parse(original.text, { version });
|
||||
await writeFile(config, original.text);
|
||||
const applied = await run(setup, environment);
|
||||
expect(applied.exitCode).toBe(0);
|
||||
expect(applied.json).toMatchObject({ status: "ready" });
|
||||
const configured = await readFile(config, "utf8");
|
||||
const parsed = parse(configured, { version });
|
||||
expect(parsed.server_defaults).toEqual(before.server_defaults);
|
||||
expect(parsed.observer).toEqual(before.observer);
|
||||
expect(parsed.mcp_servers.other).toEqual(before.mcp_servers.other);
|
||||
expect(parsed.mcp_servers.rea).toMatchObject({ enabled: true });
|
||||
if (existing)
|
||||
expect(parsed.mcp_servers.rea.env).toEqual({
|
||||
FLAG: "on",
|
||||
HOPPER_LAUNCHER_PATH: process.execPath,
|
||||
},
|
||||
GHIDRA_INSTALL_DIR: ghidra,
|
||||
JAVA_HOME: java,
|
||||
});
|
||||
expect(configured.startsWith(original.defaults)).toBe(true);
|
||||
expect(configured).toContain("# Selected table");
|
||||
expect(configured.match(/&servers\b/gu)).toHaveLength(1);
|
||||
expect(configured.match(/&server\b/gu)).toHaveLength(1);
|
||||
expect(await readFile(`${config}.rea.backup`, "utf8")).toBe(
|
||||
original.text,
|
||||
);
|
||||
const doctor = await run(
|
||||
["doctor", "--client", "hermes", "--json"],
|
||||
environment,
|
||||
);
|
||||
expect(doctor.exitCode).toBe(0);
|
||||
expect(doctor.json).toMatchObject({
|
||||
healthy: true,
|
||||
identity: { registrations: [{ client: "hermes", state: "aligned" }] },
|
||||
});
|
||||
const repeat = await run(setup, environment);
|
||||
expect(repeat.exitCode).toBe(0);
|
||||
expect(repeat.json).toMatchObject({
|
||||
status: "ready",
|
||||
plannedActions: [],
|
||||
appliedActions: [],
|
||||
});
|
||||
expect(await readFile(config, "utf8")).toBe(configured);
|
||||
const removed = await run(uninstall, environment);
|
||||
expect(removed.exitCode).toBe(0);
|
||||
expect(await readFile(config, "utf8")).toBe(original);
|
||||
await expect(access(`${config}.rea.backup`)).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
const remaining = parse(await readFile(config, "utf8"), { version });
|
||||
expect(remaining.mcp_servers).toEqual({
|
||||
other: before.mcp_servers.other,
|
||||
});
|
||||
expect(remaining.server_defaults).toEqual(before.server_defaults);
|
||||
expect(remaining.observer).toEqual(before.observer);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
cliTest(
|
||||
"Hermes uninstall preserves an aliased table without REA under YAML 1.2",
|
||||
async ({ cli }) => {
|
||||
const { config, run } = await hermesProfile(cli);
|
||||
const original = configuration("1.2", false).text;
|
||||
await writeFile(config, original);
|
||||
const removed = await run(uninstall);
|
||||
expect(removed.exitCode).toBe(0);
|
||||
expect(await readFile(config, "utf8")).toBe(original);
|
||||
await expect(access(`${config}.rea.backup`)).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
cliTest("Hermes still registers into an explicit table", async ({ cli }) => {
|
||||
const home = sharedHermesHome;
|
||||
const profile = join(home, "profile");
|
||||
const config = join(profile, "config.yaml");
|
||||
const { config, run } = await hermesProfile(cli);
|
||||
const original = configuration("1.1", false, false);
|
||||
await mkdir(profile);
|
||||
await writeFile(config, original.text);
|
||||
const applied = await cli.run({
|
||||
arguments: [
|
||||
"setup",
|
||||
"--client",
|
||||
"hermes",
|
||||
"--skill=false",
|
||||
"--yes",
|
||||
"--json",
|
||||
],
|
||||
cwd: home,
|
||||
environment: {
|
||||
USERPROFILE: home,
|
||||
HERMES_HOME: profile,
|
||||
HOPPER_LAUNCHER_PATH: process.execPath,
|
||||
},
|
||||
});
|
||||
const applied = await run(setup);
|
||||
expect(applied.exitCode).toBe(0);
|
||||
expect(applied.json).toMatchObject({ status: "ready" });
|
||||
const parsed = parse(await readFile(config, "utf8"));
|
||||
@@ -204,65 +157,34 @@ cliTest("Hermes still registers into an explicit table", async ({ cli }) => {
|
||||
expect(await readFile(`${config}.rea.backup`, "utf8")).toBe(original.text);
|
||||
});
|
||||
|
||||
for (const version of ["1.1", "1.2"] as const) {
|
||||
cliTest(
|
||||
`Hermes YAML ${version} preserves shadowed alias bindings`,
|
||||
async ({ cli }) => {
|
||||
const home = sharedHermesHome;
|
||||
const profile = join(home, "profile");
|
||||
const config = join(profile, "config.yaml");
|
||||
const original =
|
||||
(version === "1.2" ? "%YAML 1.2\n---\n" : "") +
|
||||
"first: &server\n command: original-server\n" +
|
||||
"server_defaults: &servers\n other: *server\n" +
|
||||
"replacement: &server\n command: replacement-server\n" +
|
||||
"mcp_servers: *servers\nobserver: *server\n";
|
||||
const before = parse(original, { version });
|
||||
await mkdir(profile);
|
||||
await writeFile(config, original);
|
||||
const applied = await cli.run({
|
||||
arguments: [
|
||||
"setup",
|
||||
"--client",
|
||||
"hermes",
|
||||
"--skill=false",
|
||||
"--yes",
|
||||
"--json",
|
||||
],
|
||||
cwd: home,
|
||||
environment: {
|
||||
USERPROFILE: home,
|
||||
HERMES_HOME: profile,
|
||||
HOPPER_LAUNCHER_PATH: process.execPath,
|
||||
},
|
||||
});
|
||||
expect(applied.exitCode).toBe(0);
|
||||
const configured = parse(await readFile(config, "utf8"), { version });
|
||||
expect(configured.mcp_servers.other).toEqual(before.mcp_servers.other);
|
||||
expect(configured.server_defaults).toEqual(before.server_defaults);
|
||||
expect(configured.observer).toEqual(before.observer);
|
||||
expect(await readFile(`${config}.rea.backup`, "utf8")).toBe(original);
|
||||
},
|
||||
);
|
||||
}
|
||||
cliTest(
|
||||
"Hermes detaches the selected table with each shadowed alias still bound",
|
||||
async ({ cli }) => {
|
||||
const { config, run } = await hermesProfile(cli);
|
||||
const original =
|
||||
"%YAML 1.2\n---\n" +
|
||||
"first: &server\n command: original-server\n" +
|
||||
"server_defaults: &servers\n other: *server\n" +
|
||||
"replacement: &server\n command: replacement-server\n" +
|
||||
"mcp_servers: *servers\nobserver: *server\n";
|
||||
const before = parse(original, { version: "1.2" });
|
||||
await writeFile(config, original);
|
||||
const applied = await run(setup);
|
||||
expect(applied.exitCode).toBe(0);
|
||||
const configured = parse(await readFile(config, "utf8"), {
|
||||
version: "1.2",
|
||||
});
|
||||
expect(configured.mcp_servers.other).toEqual(before.mcp_servers.other);
|
||||
expect(configured.server_defaults).toEqual(before.server_defaults);
|
||||
expect(configured.observer).toEqual(before.observer);
|
||||
expect(await readFile(`${config}.rea.backup`, "utf8")).toBe(original);
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"Hermes uninstall detaches an aliased table before deleting REA",
|
||||
async ({ cli }) => {
|
||||
const home = sharedHermesHome;
|
||||
const profile = join(home, "profile");
|
||||
const config = join(profile, "config.yaml");
|
||||
await mkdir(profile);
|
||||
const run = (arguments_: readonly string[]) =>
|
||||
cli.run({
|
||||
arguments: arguments_,
|
||||
cwd: home,
|
||||
environment: {
|
||||
USERPROFILE: home,
|
||||
HERMES_HOME: profile,
|
||||
HOPPER_LAUNCHER_PATH: process.execPath,
|
||||
},
|
||||
});
|
||||
const { config, run } = await hermesProfile(cli);
|
||||
const [command, ...args] = currentClientRegistrationCommand({
|
||||
entrypointPath: resolve("scripts/rea.mjs"),
|
||||
});
|
||||
@@ -299,7 +221,7 @@ cliTest(
|
||||
]),
|
||||
},
|
||||
});
|
||||
const removed = await run(["uninstall", "--json"]);
|
||||
const removed = await run(uninstall);
|
||||
expect(removed.exitCode).toBe(0);
|
||||
const remaining = parse(await readFile(config, "utf8"));
|
||||
expect(remaining.mcp_servers).toEqual({ other: defaults.other });
|
||||
@@ -307,7 +229,7 @@ cliTest(
|
||||
expect(remaining.observer).toEqual(defaults);
|
||||
const configured = await readFile(config, "utf8");
|
||||
expect(await readFile(`${config}.rea.backup`, "utf8")).toBe(original);
|
||||
expect((await run(["uninstall", "--json"])).exitCode).toBe(0);
|
||||
expect((await run(uninstall)).exitCode).toBe(0);
|
||||
expect(await readFile(config, "utf8")).toBe(configured);
|
||||
expect(await readFile(`${config}.rea.backup`, "utf8")).toBe(original);
|
||||
},
|
||||
@@ -320,27 +242,9 @@ for (const original of [
|
||||
cliTest(
|
||||
`Hermes refuses an invalid aliased table: ${original.trim()}`,
|
||||
async ({ cli }) => {
|
||||
const home = sharedHermesHome;
|
||||
const profile = join(home, "profile");
|
||||
const config = join(profile, "config.yaml");
|
||||
await mkdir(profile);
|
||||
const { config, run } = await hermesProfile(cli);
|
||||
await writeFile(config, original);
|
||||
const rejected = await cli.run({
|
||||
arguments: [
|
||||
"setup",
|
||||
"--client",
|
||||
"hermes",
|
||||
"--skill=false",
|
||||
"--yes",
|
||||
"--json",
|
||||
],
|
||||
cwd: home,
|
||||
environment: {
|
||||
USERPROFILE: home,
|
||||
HERMES_HOME: profile,
|
||||
HOPPER_LAUNCHER_PATH: process.execPath,
|
||||
},
|
||||
});
|
||||
const rejected = await run(setup);
|
||||
expect(rejected.exitCode).not.toBe(0);
|
||||
expect(rejected.json).toMatchObject({
|
||||
status: "needs_human",
|
||||
|
||||
@@ -13,11 +13,6 @@ import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { cliTest, type TestCli } from "../../support/cli/cliFixture.js";
|
||||
|
||||
const cliLifecycle = (cli: TestCli, home: string, profile: string) => {
|
||||
const client = supportedClients(home, process.platform, {
|
||||
HERMES_HOME: profile,
|
||||
}).find(({ name }) => name === "hermes");
|
||||
if (client?.configPath !== join(profile, "config.yaml"))
|
||||
throw new Error("Hermes profile did not resolve to the test config");
|
||||
const run = (arguments_: readonly string[]) =>
|
||||
cli.run({
|
||||
arguments: arguments_,
|
||||
@@ -47,7 +42,15 @@ const cliLifecycle = (cli: TestCli, home: string, profile: string) => {
|
||||
expect(doctor.exitCode, JSON.stringify(doctor)).toBe(0);
|
||||
expect(doctor.json).toMatchObject({
|
||||
healthy: true,
|
||||
identity: { registrations: [{ client: "hermes", state: "aligned" }] },
|
||||
identity: {
|
||||
registrations: [
|
||||
{
|
||||
client: "hermes",
|
||||
state: "aligned",
|
||||
config_path: join(profile, "config.yaml"),
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
const repeated = await run(setup);
|
||||
expect(repeated.exitCode, JSON.stringify(repeated)).toBe(0);
|
||||
@@ -155,105 +158,99 @@ const anchoredConfiguration = (
|
||||
return { original, other, hasDefaults };
|
||||
};
|
||||
|
||||
for (const version of ["1.1", "1.2"] as const) {
|
||||
for (const style of [
|
||||
"entry",
|
||||
"child",
|
||||
"shadowed",
|
||||
"key",
|
||||
"external",
|
||||
] as const) {
|
||||
const publicCli = style === "entry" || style === "shadowed";
|
||||
cliTest(
|
||||
`Hermes ${version} preserves ${style} anchor consumers through ${publicCli ? "CLI" : "configuration boundary"} setup and uninstall`,
|
||||
async ({ cli }) => {
|
||||
// Exercise both YAML versions through the CLI, including the shadowed
|
||||
// anchor case; the other styles retain the full registration lifecycle
|
||||
// at the production configuration and uninstall boundary.
|
||||
const home = await createTestTempDirectory(
|
||||
"rea-hermes-anchored-entry-",
|
||||
const scenarios = [
|
||||
["1.1", "entry", true],
|
||||
["1.2", "shadowed", true],
|
||||
["1.2", "child", false],
|
||||
["1.1", "key", false],
|
||||
["1.1", "external", false],
|
||||
] as const;
|
||||
|
||||
for (const [version, style, publicCli] of scenarios) {
|
||||
cliTest(
|
||||
`Hermes ${version} preserves ${style} anchor consumers through ${publicCli ? "CLI" : "configuration boundary"} setup and uninstall`,
|
||||
async ({ cli }) => {
|
||||
const home = await createTestTempDirectory("rea-hermes-anchored-entry-");
|
||||
const profile = join(home, "hermes");
|
||||
const config = join(profile, "config.yaml");
|
||||
const command = publicCli
|
||||
? [process.execPath, resolve("scripts/rea.mjs"), "mcp"]
|
||||
: currentClientRegistrationCommand({ platform: process.platform });
|
||||
if (command[0] === undefined) throw new Error("Missing REA entrypoint");
|
||||
const server = {
|
||||
command: command[0],
|
||||
args: command.slice(1),
|
||||
env: { KEEP: "off" },
|
||||
enabled: false,
|
||||
};
|
||||
const { original, other, hasDefaults } = anchoredConfiguration(
|
||||
version,
|
||||
style,
|
||||
server,
|
||||
);
|
||||
await mkdir(profile);
|
||||
await writeFile(config, original);
|
||||
const lifecycle = publicCli
|
||||
? cliLifecycle(cli, home, profile)
|
||||
: configurationLifecycle(home, profile, config, command);
|
||||
await lifecycle.configure();
|
||||
const configured = await readFile(config, "utf8");
|
||||
const configuredValues = parse(configured, { version });
|
||||
expect(configuredValues).toMatchObject({
|
||||
model: "custom",
|
||||
mcp_servers: { rea: { enabled: true, env: { KEEP: "off" } }, other },
|
||||
...(style === "shadowed"
|
||||
? { observer: server, later: { KEEP: "later" } }
|
||||
: {}),
|
||||
...(style === "key" ? { observer: "rea" } : {}),
|
||||
});
|
||||
if (hasDefaults)
|
||||
expect(configuredValues.mcp_servers.other.env).toBe(
|
||||
configuredValues.defaults,
|
||||
);
|
||||
const profile = join(home, "hermes");
|
||||
const config = join(profile, "config.yaml");
|
||||
const command = publicCli
|
||||
? [process.execPath, resolve("scripts/rea.mjs"), "mcp"]
|
||||
: currentClientRegistrationCommand({ platform: process.platform });
|
||||
if (command[0] === undefined) throw new Error("Missing REA entrypoint");
|
||||
const server = {
|
||||
command: command[0],
|
||||
args: command.slice(1),
|
||||
env: { KEEP: "off" },
|
||||
enabled: false,
|
||||
};
|
||||
const { original, other, hasDefaults } = anchoredConfiguration(
|
||||
version,
|
||||
style,
|
||||
server,
|
||||
expect(configured).toContain("# Keep this user setting");
|
||||
if (style === "entry")
|
||||
expect(configured).toContain("# Keep anchor definition comment");
|
||||
expect(configured).toContain(
|
||||
style === "child"
|
||||
? "# Shared environment"
|
||||
: style === "key"
|
||||
? "# Registration name"
|
||||
: "# Independent server",
|
||||
);
|
||||
if (hasDefaults)
|
||||
expect(configured).toContain("# Keep nested reference comment");
|
||||
expect(await readFile(`${config}.rea.backup`, "utf8")).toBe(original);
|
||||
await lifecycle.verifyAndRepeat();
|
||||
expect(await readFile(config, "utf8")).toBe(configured);
|
||||
await lifecycle.remove();
|
||||
const removedValues = parse(await readFile(config, "utf8"), {
|
||||
version,
|
||||
});
|
||||
expect(removedValues).toEqual({
|
||||
model: "custom",
|
||||
mcp_servers: { other },
|
||||
...(hasDefaults ? { defaults: { KEEP: "off" } } : {}),
|
||||
...(style === "shadowed"
|
||||
? {
|
||||
later: { KEEP: "later" },
|
||||
observer: server,
|
||||
}
|
||||
: {}),
|
||||
...(style === "key" ? { observer: "rea" } : {}),
|
||||
});
|
||||
if (hasDefaults)
|
||||
expect(removedValues.mcp_servers.other.env).toBe(
|
||||
removedValues.defaults,
|
||||
);
|
||||
await mkdir(profile);
|
||||
await writeFile(config, original);
|
||||
const lifecycle = publicCli
|
||||
? cliLifecycle(cli, home, profile)
|
||||
: configurationLifecycle(home, profile, config, command);
|
||||
await lifecycle.configure();
|
||||
const configured = await readFile(config, "utf8");
|
||||
const configuredValues = parse(configured, { version });
|
||||
expect(configuredValues).toMatchObject({
|
||||
model: "custom",
|
||||
mcp_servers: { rea: { enabled: true, env: { KEEP: "off" } }, other },
|
||||
...(style === "shadowed"
|
||||
? { observer: server, later: { KEEP: "later" } }
|
||||
: {}),
|
||||
...(style === "key" ? { observer: "rea" } : {}),
|
||||
});
|
||||
if (hasDefaults)
|
||||
expect(configuredValues.mcp_servers.other.env).toBe(
|
||||
configuredValues.defaults,
|
||||
);
|
||||
expect(configured).toContain("# Keep this user setting");
|
||||
if (style === "entry")
|
||||
expect(configured).toContain("# Keep anchor definition comment");
|
||||
expect(configured).toContain(
|
||||
style === "child"
|
||||
? "# Shared environment"
|
||||
: style === "key"
|
||||
? "# Registration name"
|
||||
: "# Independent server",
|
||||
);
|
||||
if (hasDefaults)
|
||||
expect(configured).toContain("# Keep nested reference comment");
|
||||
expect(await readFile(`${config}.rea.backup`, "utf8")).toBe(original);
|
||||
await lifecycle.verifyAndRepeat();
|
||||
expect(await readFile(config, "utf8")).toBe(configured);
|
||||
await lifecycle.remove();
|
||||
const removedValues = parse(await readFile(config, "utf8"), {
|
||||
version,
|
||||
});
|
||||
expect(removedValues).toEqual({
|
||||
model: "custom",
|
||||
mcp_servers: { other },
|
||||
...(hasDefaults ? { defaults: { KEEP: "off" } } : {}),
|
||||
...(style === "shadowed"
|
||||
? {
|
||||
later: { KEEP: "later" },
|
||||
observer: server,
|
||||
}
|
||||
: {}),
|
||||
...(style === "key" ? { observer: "rea" } : {}),
|
||||
});
|
||||
if (hasDefaults)
|
||||
expect(removedValues.mcp_servers.other.env).toBe(
|
||||
removedValues.defaults,
|
||||
);
|
||||
expect(await readFile(`${config}.rea.backup`, "utf8")).toBe(original);
|
||||
const remaining = await readFile(config, "utf8");
|
||||
if (style === "entry")
|
||||
expect(remaining).toContain("# Keep anchor definition comment");
|
||||
if (hasDefaults)
|
||||
expect(remaining).toContain("# Keep nested reference comment");
|
||||
await lifecycle.removeAgain();
|
||||
expect(await readFile(config, "utf8")).toBe(remaining);
|
||||
},
|
||||
);
|
||||
}
|
||||
expect(await readFile(`${config}.rea.backup`, "utf8")).toBe(original);
|
||||
const remaining = await readFile(config, "utf8");
|
||||
if (style === "entry")
|
||||
expect(remaining).toContain("# Keep anchor definition comment");
|
||||
if (hasDefaults)
|
||||
expect(remaining).toContain("# Keep nested reference comment");
|
||||
await lifecycle.removeAgain();
|
||||
expect(await readFile(config, "utf8")).toBe(remaining);
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user