shouldAdoptActiveProfile() aligned the switcher to the machine-global active_profile whenever it differed from the serving profile, so a dashboard hosted by a named profile (hermes -p demo serve) silently retargeted its banner, chat TUI env and model to another agent on every load. Only the default-hosted machine dashboard aligns now; "custom" (unnamed HERMES_HOME) never does. Co-authored-by: ipriyaaanshu <ipriyaaanshu@users.noreply.github.com>
70 lines
2.6 KiB
TypeScript
70 lines
2.6 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
|
|
import {
|
|
dashboardServingProfile,
|
|
initialProfileScope,
|
|
shouldAdoptActiveProfile,
|
|
} from "./profile-bootstrap";
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
describe("initialProfileScope", () => {
|
|
|
|
it("does not replace a launch profile with the sticky active profile", () => {
|
|
expect(
|
|
shouldAdoptActiveProfile(null, "worker_x", "default", "review"),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("uses the sticky active profile without a URL or launch profile", () => {
|
|
expect(
|
|
shouldAdoptActiveProfile(null, "", "default", "review"),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("keeps a named-profile dashboard on its own profile (#96712)", () => {
|
|
// `hermes -p demo serve` with the machine's sticky active profile on
|
|
// `default`: the dashboard must not retarget chats to the other agent.
|
|
expect(shouldAdoptActiveProfile(null, "", "demo", "default")).toBe(false);
|
|
expect(shouldAdoptActiveProfile(null, "", "custom", "default")).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("dashboardServingProfile", () => {
|
|
it("names no profile when there is no window at all", () => {
|
|
expect(dashboardServingProfile()).toBe("");
|
|
});
|
|
|
|
it.each([
|
|
["an injected serving profile", { __HERMES_DASHBOARD_PROFILE__: "served" }, "served"],
|
|
["a window without one", {}, ""],
|
|
])("reports %s", (_label, windowStub, expected) => {
|
|
vi.stubGlobal("window", windowStub);
|
|
expect(dashboardServingProfile()).toBe(expected);
|
|
});
|
|
});
|
|
|
|
describe("initialProfileScope precedence", () => {
|
|
// URL > bootstrap > serving. The serving profile is the LAST resort: it says
|
|
// out loud what an unnamed request already meant, so it must never override a
|
|
// scope the URL or the bootstrap payload already named.
|
|
it.each([
|
|
["the URL profile outranks bootstrap and serving", "profile=url", "boot", "served", "url"],
|
|
["an explicit empty URL profile still outranks both", "profile=", "boot", "served", ""],
|
|
["the bootstrap profile outranks the serving profile", "resume=s1", "boot", "served", "boot"],
|
|
["the serving profile is used when nothing else names one", "resume=s1", "", "served", "served"],
|
|
["no scope is invented when nothing names one", "resume=s1", "", "", ""],
|
|
])("%s", (_label, query, bootstrap, serving, expected) => {
|
|
expect(
|
|
initialProfileScope(new URLSearchParams(query), bootstrap, serving),
|
|
).toBe(expected);
|
|
});
|
|
|
|
it("defaults the serving profile to the one this backend injected", () => {
|
|
vi.stubGlobal("window", { __HERMES_DASHBOARD_PROFILE__: "served" });
|
|
expect(initialProfileScope(new URLSearchParams("resume=s1"), "")).toBe("served");
|
|
});
|
|
});
|